1 /* init.c initialization functions
2 * Copyright (C) 2002 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but 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.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define WARNSTR "libshishi: warning: "
29 _shishi_gettext (const char *str
)
31 return dgettext (PACKAGE
, str
);
35 _shishi_gettext_init ()
37 bindtextdomain (PACKAGE
, LOCALEDIR
);
38 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
39 bind_textdomain_codeset (PACKAGE
, "UTF-8");
43 #endif /* ENABLE_NLS */
45 extern const ASN1_ARRAY_TYPE shishi_asn1_tab
[];
50 ASN1_TYPE definitions
= ASN1_TYPE_EMPTY
;
51 int asn1_result
= ASN1_SUCCESS
;
52 char errorDescription
[MAX_ERROR_DESCRIPTION_SIZE
];
54 asn1_result
= asn1_array2tree (shishi_asn1_tab
,
55 &definitions
, errorDescription
);
56 if (asn1_result
!= ASN1_SUCCESS
)
58 fprintf (stderr
, "libshishi: error: %s\n", errorDescription
);
59 fprintf (stderr
, "libshishi: error: %s\n",
60 libtasn1_strerror (asn1_result
));
61 return ASN1_TYPE_EMPTY
;
70 * Initializes the Shishi library. If this function fails, it may print
71 * diagnostic errors to stderr.
73 * Return Value: Returns Shishi library handle, or %NULL on error.
83 handle
= (Shishi
*) malloc (sizeof (*handle
));
86 fprintf(stderr
, "libshishi: error: %s\n",
87 shishi_strerror (SHISHI_MALLOC_ERROR
));
90 memset ((void *) handle
, 0, sizeof (*handle
));
93 res
= gcry_control (GCRYCTL_INIT_SECMEM
, 512, 0);
94 if (res
!= GCRYERR_SUCCESS
)
96 fprintf(stderr
, "libshishi: error: %s\n",
97 shishi_strerror (SHISHI_GCRYPT_ERROR
));
101 gcry_control (GCRYCTL_DISABLE_SECMEM
, NULL
, 0);
104 handle
->asn1
= read_asn1 ();
105 if (handle
->asn1
== ASN1_TYPE_EMPTY
)
107 fprintf(stderr
, "libshishi: error: %s\n",
108 shishi_strerror (SHISHI_ASN1_ERROR
));
112 handle
->kdctimeout
= 5;
113 handle
->kdcretries
= 3;
115 handle
->nclientkdcetypes
= 1;
116 handle
->clientkdcetypes
= malloc (sizeof (*handle
->clientkdcetypes
) *
117 handle
->nclientkdcetypes
);
118 if (handle
->clientkdcetypes
== NULL
)
120 fprintf(stderr
, "libshishi: error: %s\n",
121 shishi_strerror (SHISHI_MALLOC_ERROR
));
124 handle
->clientkdcetypes
[0] = SHISHI_AES256_CTS_HMAC_SHA1_96
;
126 tmp
= shishi_realm_default_guess ();
127 shishi_realm_default_set (handle
, tmp
);
130 tmp
= shishi_principal_default_guess ();
133 shishi_principal_default_set (handle
, tmp
);
141 _shishi_init_read (Shishi
* handle
,
142 const char *ticketsetfile
,
143 const char *systemcfgfile
,
144 const char *usercfgfile
)
149 ticketsetfile
= shishi_ticketset_default_file (handle
);
152 systemcfgfile
= shishi_cfg_default_systemfile (handle
);
155 usercfgfile
= shishi_cfg_default_userfile (handle
);
157 if (!handle
->ticketset
)
158 rc
= shishi_ticketset_init (handle
, &handle
->ticketset
);
164 shishi_ticketset_from_file (handle
, handle
->ticketset
, ticketsetfile
);
165 if (rc
== SHISHI_FOPEN_ERROR
)
166 fprintf (stderr
, WARNSTR
"%s: %s\n", ticketsetfile
, strerror(errno
));
167 if (rc
!= SHISHI_OK
&& rc
!= SHISHI_FOPEN_ERROR
)
171 rc
= shishi_cfg_from_file (handle
, systemcfgfile
);
172 if (rc
== SHISHI_FOPEN_ERROR
)
173 fprintf (stderr
, WARNSTR
"%s: %s\n", systemcfgfile
, strerror(errno
));
174 if (rc
!= SHISHI_OK
&& rc
!= SHISHI_FOPEN_ERROR
)
178 rc
= shishi_cfg_from_file (handle
, usercfgfile
);
179 if (rc
== SHISHI_FOPEN_ERROR
)
180 fprintf (stderr
, WARNSTR
"%s: %s\n", usercfgfile
, strerror(errno
));
181 if (rc
!= SHISHI_OK
&& rc
!= SHISHI_FOPEN_ERROR
)
184 if (VERBOSE (handle
))
185 shishi_cfg_print (handle
, stdout
);
192 * @handle: pointer to handle to be created.
194 * Create a Shishi library handle and read the system configuration
195 * file, user configuration file and user tickets from the defaul
196 * paths. The paths to the system configuration file is decided at
197 * compile time, and is $sysconfdir/shishi.conf. The user
198 * configuration file is $HOME/.shishi/config, and the user ticket
199 * file is $HOME/.shishi/ticket. The handle is allocated regardless
200 * of return values, except for SHISHI_HANDLE_ERROR which indicates a
201 * problem allocating the handle. (The other error conditions comes
202 * from reading the files.)
204 * Return value: Returns SHISHI_OK iff successful.
207 shishi_init (Shishi
** handle
)
209 if (!handle
|| !(*handle
= shishi ()))
210 return SHISHI_HANDLE_ERROR
;
212 return _shishi_init_read (*handle
, shishi_ticketset_default_file (*handle
),
213 shishi_cfg_default_systemfile (*handle
),
214 shishi_cfg_default_userfile (*handle
));
218 * shishi_init_with_paths:
219 * @handle: pointer to handle to be created.
220 * @ticketsetfile: Filename of ticket file, or NULL.
221 * @systemcfgfile: Filename of system configuration, or NULL.
222 * @usercfgfile: Filename of user configuration, or NULL.
224 * Like shishi_init() but use explicit paths. Like shishi_init(), the
225 * handle is allocated regardless of return values, except for
226 * SHISHI_HANDLE_ERROR which indicates a problem allocating the
227 * handle. (The other error conditions comes from reading the files.)
229 * Return value: Returns SHISHI_OK iff successful.
232 shishi_init_with_paths (Shishi
** handle
,
233 const char *ticketsetfile
,
234 const char *systemcfgfile
,
235 const char *usercfgfile
)
237 if (!handle
|| !(*handle
= shishi ()))
238 return SHISHI_HANDLE_ERROR
;
240 shishi_ticketset_default_file_set (*handle
, ticketsetfile
);
242 return _shishi_init_read (*handle
, ticketsetfile
,
243 systemcfgfile
, usercfgfile
);
246 /* XXX remove these: */
249 shishi_last_authenticator (Shishi
* handle
)
251 return handle
->lastauthenticator
;
255 shishi_last_apreq (Shishi
* handle
)
257 return handle
->lastapreq
;
261 shishi_last_aprep (Shishi
* handle
)
263 return handle
->lastaprep
;
267 shishi_last_encapreppart (Shishi
* handle
)
269 return handle
->lastencapreppart
;
273 shishi_warn (Shishi
* handle
, char *fmt
, ...)
277 if (VERBOSE (handle
))
279 fprintf (stderr
, WARNSTR
);
280 vfprintf (stderr
, fmt
, ap
);
281 fprintf (stderr
, "\n");