1 /* internal.h --- Internal header file for Shishi.
2  * Copyright (C) 2002-2013 Simon Josefsson
3  *
4  * This file is part of Shishi.
5  *
6  * Shishi is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Shishi is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Shishi; if not, see http://www.gnu.org/licenses or write
18  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19  * Floor, Boston, MA 02110-1301, USA
20  *
21  */
22 
23 #ifndef _INTERNAL_H
24 #define _INTERNAL_H
25 
26 #if HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <ctype.h>
34 #include <string.h>
35 #include <stdbool.h>
36 #include <stdint.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <sys/select.h>
40 #include <sys/stat.h>
41 #include <unistd.h>
42 #include <sys/time.h>
43 #include <time.h>
44 #include <signal.h>
45 
46 #ifdef HAVE_SYS_IOCTL_H
47 #include <sys/ioctl.h>
48 #endif
49 
50 #include <netdb.h>
51 
52 #if !HAVE_DECL_H_ERRNO
53 /*extern int h_errno;*/
54 #endif
55 
56 #include <fcntl.h>
57 
58 #include <errno.h>
59 
60 #include <netinet/in.h>
61 #ifdef HAVE_NETINET_IN6_H
62 #include <netinet/in6.h>
63 #endif
64 #include <arpa/inet.h>
65 
66 #ifdef HAVE_SYSLOG_H
67 #include <syslog.h>
68 #endif
69 
70 #include "gettext.h"
71 
72 #include "xvasprintf.h"
73 #include "base64.h"
74 #include "parse-datetime.h"
75 #include "read-file.h"
76 #include "timespec.h"
77 #include "xalloc.h"
78 #include "xgethostname.h"
79 #include "xgetdomainname.h"
80 #include "xstrndup.h"
81 
82 #include "shishi.h"
83 
84 #define _(String) dgettext (PACKAGE, String)
85 #define gettext_noop(String) String
86 #define N_(String) gettext_noop (String)
87 
88 #define MAX_KEY_LEN 32
89 #define MAX_RANDOM_LEN 32
90 #define MAX_HASH_LEN 32
91 #define MAX_CKSUM_LEN 32
92 
93 #define SHISHI_VERBOSE_NOISE		(1<<1)
94 #define SHISHI_VERBOSE_ASN1		(1<<2)
95 #define SHISHI_VERBOSE_CRYPTO		(1<<3)
96 #define SHISHI_VERBOSE_CRYPTO_NOISE	(1<<4)
97 
98 #define KRBTGT "krbtgt"
99 #define PRINCIPAL_DELIMITER "/"
100 
101 #define VERBOSENOISE(h) (h->verbose & SHISHI_VERBOSE_NOISE)
102 #define VERBOSEASN1(h) (h->verbose & SHISHI_VERBOSE_ASN1)
103 #define VERBOSECRYPTO(h) (h->verbose & SHISHI_VERBOSE_CRYPTO)
104 #define VERBOSECRYPTONOISE(h) (h->verbose & SHISHI_VERBOSE_CRYPTO_NOISE)
105 #define VERBOSES (SHISHI_VERBOSE_ASN1 |		\
106 		  SHISHI_VERBOSE_CRYPTO |	\
107 		  SHISHI_VERBOSE_NOISE |	\
108 		  SHISHI_VERBOSE_CRYPTO_NOISE)
109 #define VERBOSE(h) (h->verbose & ~VERBOSES)
110 
111 /* Transports */
112 enum
113 {
114   UDP,
115   TCP,
116   TLS
117 };
118 
119 struct Shishi_kdcinfo
120 {
121   int transport;
122   char *hostname;
123   char *port;
124 };
125 
126 struct Shishi_realminfo
127 {
128   char *name;
129   struct Shishi_kdcinfo *kdcaddresses;
130   size_t nkdcaddresses;
131   char **serverwildcards;
132   size_t nserverwildcards;
133 };
134 
135 struct Shishi
136 {
137   Shishi_asn1 asn1;
138   int verbose;
139   int outputtype;
140   char *default_realm;
141   char *default_principal;
142   size_t kdctimeout;
143   size_t kdcretries;
144   int ticketlife;
145   int renewlife;
146   int32_t *clientkdcetypes;
147   size_t nclientkdcetypes;
148   int32_t *authorizationtypes;
149   size_t nauthorizationtypes;
150   struct Shishi_realminfo *realminfos;
151   size_t nrealminfos;
152   char error[1024];
153   char gztime_buf[40];
154   char *userdirectory;
155   char *usercfgfile;
156   char *tktsdefaultfile;
157   char *ccachedefault;
158   char *hostkeysdefaultfile;
159   char *x509cafile;
160   char *x509certfile;
161   char *x509keyfile;
162   char *stringprocess;
163   Shishi_tkts *tkts;
164   shishi_prompt_password_func prompt_passwd;
165 };
166 
167 #define TICKETLIFE (60*60*8)	/* Work day */
168 #define RENEWLIFE (60*60*24*7)	/* Week */
169 
170 #endif /* _INTERNAL_H */
171