1*7f2fe78bSCy Schubert #include <windows.h>
2*7f2fe78bSCy Schubert #include <stdio.h>
3*7f2fe78bSCy Schubert #include <sys/types.h>
4*7f2fe78bSCy Schubert #include <winsock2.h>
5*7f2fe78bSCy Schubert #include "leashdll.h"
6*7f2fe78bSCy Schubert #include <time.h>
7*7f2fe78bSCy Schubert
8*7f2fe78bSCy Schubert #include <leashwin.h>
9*7f2fe78bSCy Schubert #include "leasherr.h"
10*7f2fe78bSCy Schubert #include "leash-int.h"
11*7f2fe78bSCy Schubert #include "leashids.h"
12*7f2fe78bSCy Schubert
13*7f2fe78bSCy Schubert #include "reminder.h"
14*7f2fe78bSCy Schubert
15*7f2fe78bSCy Schubert static char FAR *err_context;
16*7f2fe78bSCy Schubert
17*7f2fe78bSCy Schubert char KRB_HelpFile[_MAX_PATH] = HELPFILE;
18*7f2fe78bSCy Schubert
19*7f2fe78bSCy Schubert #define LEN 64 /* Maximum Hostname Length */
20*7f2fe78bSCy Schubert
21*7f2fe78bSCy Schubert #define LIFE DEFAULT_TKT_LIFE /* lifetime of ticket in 5-minute units */
22*7f2fe78bSCy Schubert
23*7f2fe78bSCy Schubert static
24*7f2fe78bSCy Schubert char*
clean_string(char * s)25*7f2fe78bSCy Schubert clean_string(
26*7f2fe78bSCy Schubert char* s
27*7f2fe78bSCy Schubert )
28*7f2fe78bSCy Schubert {
29*7f2fe78bSCy Schubert char* p = s;
30*7f2fe78bSCy Schubert char* b = s;
31*7f2fe78bSCy Schubert
32*7f2fe78bSCy Schubert if (!s) return s;
33*7f2fe78bSCy Schubert
34*7f2fe78bSCy Schubert for (p = s; *p; p++) {
35*7f2fe78bSCy Schubert switch (*p) {
36*7f2fe78bSCy Schubert case '\007':
37*7f2fe78bSCy Schubert /* Add more cases here */
38*7f2fe78bSCy Schubert break;
39*7f2fe78bSCy Schubert default:
40*7f2fe78bSCy Schubert *b = *p;
41*7f2fe78bSCy Schubert b++;
42*7f2fe78bSCy Schubert }
43*7f2fe78bSCy Schubert }
44*7f2fe78bSCy Schubert *b = *p;
45*7f2fe78bSCy Schubert return s;
46*7f2fe78bSCy Schubert }
47*7f2fe78bSCy Schubert
48*7f2fe78bSCy Schubert static
49*7f2fe78bSCy Schubert int
leash_error_message(const char * error,int rcL,int rc5,int rcA,char * result_string,int displayMB)50*7f2fe78bSCy Schubert leash_error_message(
51*7f2fe78bSCy Schubert const char *error,
52*7f2fe78bSCy Schubert int rcL,
53*7f2fe78bSCy Schubert int rc5,
54*7f2fe78bSCy Schubert int rcA,
55*7f2fe78bSCy Schubert char* result_string,
56*7f2fe78bSCy Schubert int displayMB
57*7f2fe78bSCy Schubert )
58*7f2fe78bSCy Schubert {
59*7f2fe78bSCy Schubert char message[2048];
60*7f2fe78bSCy Schubert char *p = message;
61*7f2fe78bSCy Schubert int size = sizeof(message) - 1; /* -1 to leave room for NULL terminator */
62*7f2fe78bSCy Schubert int n;
63*7f2fe78bSCy Schubert
64*7f2fe78bSCy Schubert if (!rc5 && !rcL)
65*7f2fe78bSCy Schubert return 0;
66*7f2fe78bSCy Schubert
67*7f2fe78bSCy Schubert n = _snprintf(p, size, "%s\n\n", error);
68*7f2fe78bSCy Schubert p += n;
69*7f2fe78bSCy Schubert size -= n;
70*7f2fe78bSCy Schubert
71*7f2fe78bSCy Schubert if (rc5 && !result_string)
72*7f2fe78bSCy Schubert {
73*7f2fe78bSCy Schubert n = _snprintf(p, size,
74*7f2fe78bSCy Schubert "Kerberos 5: %s (error %ld)\n",
75*7f2fe78bSCy Schubert perror_message(rc5),
76*7f2fe78bSCy Schubert rc5
77*7f2fe78bSCy Schubert );
78*7f2fe78bSCy Schubert p += n;
79*7f2fe78bSCy Schubert size -= n;
80*7f2fe78bSCy Schubert }
81*7f2fe78bSCy Schubert if (rcL)
82*7f2fe78bSCy Schubert {
83*7f2fe78bSCy Schubert char buffer[1024];
84*7f2fe78bSCy Schubert n = _snprintf(p, size,
85*7f2fe78bSCy Schubert "\n%s\n",
86*7f2fe78bSCy Schubert err_describe(buffer, rcL)
87*7f2fe78bSCy Schubert );
88*7f2fe78bSCy Schubert p += n;
89*7f2fe78bSCy Schubert size -= n;
90*7f2fe78bSCy Schubert }
91*7f2fe78bSCy Schubert if (result_string)
92*7f2fe78bSCy Schubert {
93*7f2fe78bSCy Schubert n = _snprintf(p, size,
94*7f2fe78bSCy Schubert "%s\n",
95*7f2fe78bSCy Schubert result_string);
96*7f2fe78bSCy Schubert p += n;
97*7f2fe78bSCy Schubert size -= n;
98*7f2fe78bSCy Schubert }
99*7f2fe78bSCy Schubert #ifdef USE_MESSAGE_BOX
100*7f2fe78bSCy Schubert *p = 0; /* ensure NULL termination of message */
101*7f2fe78bSCy Schubert if ( displayMB )
102*7f2fe78bSCy Schubert MessageBox(NULL, message, "MIT Kerberos",
103*7f2fe78bSCy Schubert MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND);
104*7f2fe78bSCy Schubert #endif /* USE_MESSAGE_BOX */
105*7f2fe78bSCy Schubert if (rc5) return rc5;
106*7f2fe78bSCy Schubert if (rcL) return rcL;
107*7f2fe78bSCy Schubert return 0;
108*7f2fe78bSCy Schubert }
109*7f2fe78bSCy Schubert
110*7f2fe78bSCy Schubert
111*7f2fe78bSCy Schubert static
112*7f2fe78bSCy Schubert char *
make_postfix(const char * base,const char * postfix,char ** rcopy)113*7f2fe78bSCy Schubert make_postfix(
114*7f2fe78bSCy Schubert const char * base,
115*7f2fe78bSCy Schubert const char * postfix,
116*7f2fe78bSCy Schubert char ** rcopy
117*7f2fe78bSCy Schubert )
118*7f2fe78bSCy Schubert {
119*7f2fe78bSCy Schubert int base_size;
120*7f2fe78bSCy Schubert int ret_size;
121*7f2fe78bSCy Schubert char * copy = 0;
122*7f2fe78bSCy Schubert char * ret = 0;
123*7f2fe78bSCy Schubert
124*7f2fe78bSCy Schubert base_size = strlen(base) + 1;
125*7f2fe78bSCy Schubert ret_size = base_size + strlen(postfix) + 1;
126*7f2fe78bSCy Schubert copy = malloc(base_size);
127*7f2fe78bSCy Schubert ret = malloc(ret_size);
128*7f2fe78bSCy Schubert
129*7f2fe78bSCy Schubert if (!copy || !ret)
130*7f2fe78bSCy Schubert goto cleanup;
131*7f2fe78bSCy Schubert
132*7f2fe78bSCy Schubert strncpy(copy, base, base_size);
133*7f2fe78bSCy Schubert copy[base_size - 1] = 0;
134*7f2fe78bSCy Schubert
135*7f2fe78bSCy Schubert strncpy(ret, base, base_size);
136*7f2fe78bSCy Schubert strncpy(ret + (base_size - 1), postfix, ret_size - (base_size - 1));
137*7f2fe78bSCy Schubert ret[ret_size - 1] = 0;
138*7f2fe78bSCy Schubert
139*7f2fe78bSCy Schubert cleanup:
140*7f2fe78bSCy Schubert if (!copy || !ret) {
141*7f2fe78bSCy Schubert if (copy)
142*7f2fe78bSCy Schubert free(copy);
143*7f2fe78bSCy Schubert if (ret)
144*7f2fe78bSCy Schubert free(ret);
145*7f2fe78bSCy Schubert copy = ret = 0;
146*7f2fe78bSCy Schubert }
147*7f2fe78bSCy Schubert // INVARIANT: (ret ==> copy) && (copy ==> ret)
148*7f2fe78bSCy Schubert *rcopy = copy;
149*7f2fe78bSCy Schubert return ret;
150*7f2fe78bSCy Schubert }
151*7f2fe78bSCy Schubert
152*7f2fe78bSCy Schubert static
153*7f2fe78bSCy Schubert long
make_temp_cache_v5(const char * postfix,krb5_context * pctx)154*7f2fe78bSCy Schubert make_temp_cache_v5(
155*7f2fe78bSCy Schubert const char * postfix,
156*7f2fe78bSCy Schubert krb5_context * pctx
157*7f2fe78bSCy Schubert )
158*7f2fe78bSCy Schubert {
159*7f2fe78bSCy Schubert static krb5_context ctx = 0;
160*7f2fe78bSCy Schubert static char * old_cache = 0;
161*7f2fe78bSCy Schubert
162*7f2fe78bSCy Schubert // INVARIANT: old_cache ==> ctx && ctx ==> old_cache
163*7f2fe78bSCy Schubert
164*7f2fe78bSCy Schubert if (pctx)
165*7f2fe78bSCy Schubert *pctx = 0;
166*7f2fe78bSCy Schubert
167*7f2fe78bSCy Schubert if (!pkrb5_init_context || !pkrb5_free_context || !pkrb5_cc_resolve ||
168*7f2fe78bSCy Schubert !pkrb5_cc_default_name || !pkrb5_cc_set_default_name)
169*7f2fe78bSCy Schubert return 0;
170*7f2fe78bSCy Schubert
171*7f2fe78bSCy Schubert if (old_cache) {
172*7f2fe78bSCy Schubert krb5_ccache cc = 0;
173*7f2fe78bSCy Schubert if (!pkrb5_cc_resolve(ctx, pkrb5_cc_default_name(ctx), &cc))
174*7f2fe78bSCy Schubert pkrb5_cc_destroy(ctx, cc);
175*7f2fe78bSCy Schubert pkrb5_cc_set_default_name(ctx, old_cache);
176*7f2fe78bSCy Schubert free(old_cache);
177*7f2fe78bSCy Schubert old_cache = 0;
178*7f2fe78bSCy Schubert }
179*7f2fe78bSCy Schubert if (ctx) {
180*7f2fe78bSCy Schubert pkrb5_free_context(ctx);
181*7f2fe78bSCy Schubert ctx = 0;
182*7f2fe78bSCy Schubert }
183*7f2fe78bSCy Schubert
184*7f2fe78bSCy Schubert if (postfix)
185*7f2fe78bSCy Schubert {
186*7f2fe78bSCy Schubert char * tmp_cache = 0;
187*7f2fe78bSCy Schubert krb5_error_code rc = 0;
188*7f2fe78bSCy Schubert
189*7f2fe78bSCy Schubert rc = pkrb5_init_context(&ctx);
190*7f2fe78bSCy Schubert if (rc) goto cleanup;
191*7f2fe78bSCy Schubert
192*7f2fe78bSCy Schubert tmp_cache = make_postfix(pkrb5_cc_default_name(ctx), postfix,
193*7f2fe78bSCy Schubert &old_cache);
194*7f2fe78bSCy Schubert
195*7f2fe78bSCy Schubert if (!tmp_cache) {
196*7f2fe78bSCy Schubert rc = ENOMEM;
197*7f2fe78bSCy Schubert goto cleanup;
198*7f2fe78bSCy Schubert }
199*7f2fe78bSCy Schubert
200*7f2fe78bSCy Schubert rc = pkrb5_cc_set_default_name(ctx, tmp_cache);
201*7f2fe78bSCy Schubert
202*7f2fe78bSCy Schubert cleanup:
203*7f2fe78bSCy Schubert if (rc && ctx) {
204*7f2fe78bSCy Schubert pkrb5_free_context(ctx);
205*7f2fe78bSCy Schubert ctx = 0;
206*7f2fe78bSCy Schubert }
207*7f2fe78bSCy Schubert if (tmp_cache)
208*7f2fe78bSCy Schubert free(tmp_cache);
209*7f2fe78bSCy Schubert if (pctx)
210*7f2fe78bSCy Schubert *pctx = ctx;
211*7f2fe78bSCy Schubert return rc;
212*7f2fe78bSCy Schubert }
213*7f2fe78bSCy Schubert return 0;
214*7f2fe78bSCy Schubert }
215*7f2fe78bSCy Schubert
216*7f2fe78bSCy Schubert long
Leash_checkpwd(char * principal,char * password)217*7f2fe78bSCy Schubert Leash_checkpwd(
218*7f2fe78bSCy Schubert char *principal,
219*7f2fe78bSCy Schubert char *password
220*7f2fe78bSCy Schubert )
221*7f2fe78bSCy Schubert {
222*7f2fe78bSCy Schubert return Leash_int_checkpwd(principal, password, 0);
223*7f2fe78bSCy Schubert }
224*7f2fe78bSCy Schubert
225*7f2fe78bSCy Schubert long
Leash_int_checkpwd(char * principal,char * password,int displayErrors)226*7f2fe78bSCy Schubert Leash_int_checkpwd(
227*7f2fe78bSCy Schubert char * principal,
228*7f2fe78bSCy Schubert char * password,
229*7f2fe78bSCy Schubert int displayErrors
230*7f2fe78bSCy Schubert )
231*7f2fe78bSCy Schubert {
232*7f2fe78bSCy Schubert long rc = 0;
233*7f2fe78bSCy Schubert krb5_context ctx = 0; // statically allocated in make_temp_cache_v5
234*7f2fe78bSCy Schubert // XXX - we ignore errors in make_temp_cache_v? This is BAD!!!
235*7f2fe78bSCy Schubert make_temp_cache_v5("_checkpwd", &ctx);
236*7f2fe78bSCy Schubert rc = Leash_int_kinit_ex( ctx, 0,
237*7f2fe78bSCy Schubert principal, password, 0, 0, 0, 0,
238*7f2fe78bSCy Schubert Leash_get_default_noaddresses(),
239*7f2fe78bSCy Schubert Leash_get_default_publicip(),
240*7f2fe78bSCy Schubert displayErrors
241*7f2fe78bSCy Schubert );
242*7f2fe78bSCy Schubert make_temp_cache_v5(0, &ctx);
243*7f2fe78bSCy Schubert return rc;
244*7f2fe78bSCy Schubert }
245*7f2fe78bSCy Schubert
246*7f2fe78bSCy Schubert static
247*7f2fe78bSCy Schubert long
Leash_changepwd_v5(char * principal,char * password,char * newpassword,char ** error_str)248*7f2fe78bSCy Schubert Leash_changepwd_v5(
249*7f2fe78bSCy Schubert char * principal,
250*7f2fe78bSCy Schubert char * password,
251*7f2fe78bSCy Schubert char * newpassword,
252*7f2fe78bSCy Schubert char** error_str
253*7f2fe78bSCy Schubert )
254*7f2fe78bSCy Schubert {
255*7f2fe78bSCy Schubert krb5_error_code rc = 0;
256*7f2fe78bSCy Schubert int result_code;
257*7f2fe78bSCy Schubert krb5_data result_code_string, result_string;
258*7f2fe78bSCy Schubert krb5_context context = 0;
259*7f2fe78bSCy Schubert krb5_principal princ = 0;
260*7f2fe78bSCy Schubert krb5_get_init_creds_opt opts;
261*7f2fe78bSCy Schubert krb5_creds creds;
262*7f2fe78bSCy Schubert DWORD addressless = 0;
263*7f2fe78bSCy Schubert
264*7f2fe78bSCy Schubert result_string.data = 0;
265*7f2fe78bSCy Schubert result_code_string.data = 0;
266*7f2fe78bSCy Schubert
267*7f2fe78bSCy Schubert if ( !pkrb5_init_context )
268*7f2fe78bSCy Schubert goto cleanup;
269*7f2fe78bSCy Schubert
270*7f2fe78bSCy Schubert if (rc = pkrb5_init_context(&context))
271*7f2fe78bSCy Schubert goto cleanup;
272*7f2fe78bSCy Schubert
273*7f2fe78bSCy Schubert if (rc = pkrb5_parse_name(context, principal, &princ))
274*7f2fe78bSCy Schubert goto cleanup;
275*7f2fe78bSCy Schubert
276*7f2fe78bSCy Schubert pkrb5_get_init_creds_opt_init(&opts);
277*7f2fe78bSCy Schubert pkrb5_get_init_creds_opt_set_tkt_life(&opts, 5*60);
278*7f2fe78bSCy Schubert pkrb5_get_init_creds_opt_set_renew_life(&opts, 0);
279*7f2fe78bSCy Schubert pkrb5_get_init_creds_opt_set_forwardable(&opts, 0);
280*7f2fe78bSCy Schubert pkrb5_get_init_creds_opt_set_proxiable(&opts, 0);
281*7f2fe78bSCy Schubert
282*7f2fe78bSCy Schubert addressless = Leash_get_default_noaddresses();
283*7f2fe78bSCy Schubert if (addressless)
284*7f2fe78bSCy Schubert pkrb5_get_init_creds_opt_set_address_list(&opts,NULL);
285*7f2fe78bSCy Schubert
286*7f2fe78bSCy Schubert
287*7f2fe78bSCy Schubert if (rc = pkrb5_get_init_creds_password(context, &creds, princ, password,
288*7f2fe78bSCy Schubert 0, 0, 0, "kadmin/changepw", &opts))
289*7f2fe78bSCy Schubert goto cleanup;
290*7f2fe78bSCy Schubert
291*7f2fe78bSCy Schubert if (rc = pkrb5_change_password(context, &creds, newpassword,
292*7f2fe78bSCy Schubert &result_code, &result_code_string,
293*7f2fe78bSCy Schubert &result_string))
294*7f2fe78bSCy Schubert goto cleanup;
295*7f2fe78bSCy Schubert
296*7f2fe78bSCy Schubert if (result_code) {
297*7f2fe78bSCy Schubert int len = result_code_string.length +
298*7f2fe78bSCy Schubert (result_string.length ? (sizeof(": ") - 1) : 0) +
299*7f2fe78bSCy Schubert result_string.length;
300*7f2fe78bSCy Schubert if (len && error_str) {
301*7f2fe78bSCy Schubert *error_str = malloc(len + 1);
302*7f2fe78bSCy Schubert if (*error_str)
303*7f2fe78bSCy Schubert _snprintf(*error_str, len + 1,
304*7f2fe78bSCy Schubert "%.*s%s%.*s",
305*7f2fe78bSCy Schubert result_code_string.length, result_code_string.data,
306*7f2fe78bSCy Schubert result_string.length?": ":"",
307*7f2fe78bSCy Schubert result_string.length, result_string.data);
308*7f2fe78bSCy Schubert }
309*7f2fe78bSCy Schubert rc = result_code;
310*7f2fe78bSCy Schubert goto cleanup;
311*7f2fe78bSCy Schubert }
312*7f2fe78bSCy Schubert
313*7f2fe78bSCy Schubert cleanup:
314*7f2fe78bSCy Schubert if (result_string.data)
315*7f2fe78bSCy Schubert pkrb5_free_data_contents(context, &result_string);
316*7f2fe78bSCy Schubert
317*7f2fe78bSCy Schubert if (result_code_string.data)
318*7f2fe78bSCy Schubert pkrb5_free_data_contents(context, &result_code_string);
319*7f2fe78bSCy Schubert
320*7f2fe78bSCy Schubert if (princ)
321*7f2fe78bSCy Schubert pkrb5_free_principal(context, princ);
322*7f2fe78bSCy Schubert
323*7f2fe78bSCy Schubert if (context)
324*7f2fe78bSCy Schubert pkrb5_free_context(context);
325*7f2fe78bSCy Schubert
326*7f2fe78bSCy Schubert return rc;
327*7f2fe78bSCy Schubert }
328*7f2fe78bSCy Schubert
329*7f2fe78bSCy Schubert /*
330*7f2fe78bSCy Schubert * Leash_changepwd
331*7f2fe78bSCy Schubert *
332*7f2fe78bSCy Schubert * Try to change the password using krb5.
333*7f2fe78bSCy Schubert */
334*7f2fe78bSCy Schubert long
Leash_changepwd(char * principal,char * password,char * newpassword,char ** result_string)335*7f2fe78bSCy Schubert Leash_changepwd(
336*7f2fe78bSCy Schubert char * principal,
337*7f2fe78bSCy Schubert char * password,
338*7f2fe78bSCy Schubert char * newpassword,
339*7f2fe78bSCy Schubert char** result_string
340*7f2fe78bSCy Schubert )
341*7f2fe78bSCy Schubert {
342*7f2fe78bSCy Schubert return Leash_int_changepwd(principal, password, newpassword, result_string, 0);
343*7f2fe78bSCy Schubert }
344*7f2fe78bSCy Schubert
345*7f2fe78bSCy Schubert long
Leash_int_changepwd(char * principal,char * password,char * newpassword,char ** result_string,int displayErrors)346*7f2fe78bSCy Schubert Leash_int_changepwd(
347*7f2fe78bSCy Schubert char * principal,
348*7f2fe78bSCy Schubert char * password,
349*7f2fe78bSCy Schubert char * newpassword,
350*7f2fe78bSCy Schubert char** result_string,
351*7f2fe78bSCy Schubert int displayErrors
352*7f2fe78bSCy Schubert )
353*7f2fe78bSCy Schubert {
354*7f2fe78bSCy Schubert char* v5_error_str = 0;
355*7f2fe78bSCy Schubert char* error_str = 0;
356*7f2fe78bSCy Schubert int rc5 = 0;
357*7f2fe78bSCy Schubert int rc = 0;
358*7f2fe78bSCy Schubert if (hKrb5)
359*7f2fe78bSCy Schubert rc = rc5 = Leash_changepwd_v5(principal, password, newpassword,
360*7f2fe78bSCy Schubert &v5_error_str);
361*7f2fe78bSCy Schubert if (!rc)
362*7f2fe78bSCy Schubert return 0;
363*7f2fe78bSCy Schubert if (v5_error_str) {
364*7f2fe78bSCy Schubert int len = 0;
365*7f2fe78bSCy Schubert char v5_prefix[] = "Kerberos 5: ";
366*7f2fe78bSCy Schubert char sep[] = "\n";
367*7f2fe78bSCy Schubert
368*7f2fe78bSCy Schubert clean_string(v5_error_str);
369*7f2fe78bSCy Schubert
370*7f2fe78bSCy Schubert if (v5_error_str)
371*7f2fe78bSCy Schubert len += sizeof(sep) + sizeof(v5_prefix) + strlen(v5_error_str) +
372*7f2fe78bSCy Schubert sizeof(sep);
373*7f2fe78bSCy Schubert error_str = malloc(len + 1);
374*7f2fe78bSCy Schubert if (error_str) {
375*7f2fe78bSCy Schubert char* p = error_str;
376*7f2fe78bSCy Schubert int size = len + 1;
377*7f2fe78bSCy Schubert int n;
378*7f2fe78bSCy Schubert if (v5_error_str) {
379*7f2fe78bSCy Schubert n = _snprintf(p, size, "%s%s%s%s",
380*7f2fe78bSCy Schubert sep, v5_prefix, v5_error_str, sep);
381*7f2fe78bSCy Schubert p += n;
382*7f2fe78bSCy Schubert size -= n;
383*7f2fe78bSCy Schubert }
384*7f2fe78bSCy Schubert if (result_string)
385*7f2fe78bSCy Schubert *result_string = error_str;
386*7f2fe78bSCy Schubert }
387*7f2fe78bSCy Schubert }
388*7f2fe78bSCy Schubert return leash_error_message("Error while changing password.",
389*7f2fe78bSCy Schubert 0, rc5, 0, error_str,
390*7f2fe78bSCy Schubert displayErrors
391*7f2fe78bSCy Schubert );
392*7f2fe78bSCy Schubert }
393*7f2fe78bSCy Schubert
394*7f2fe78bSCy Schubert int (*Lcom_err)(LPSTR,long,LPSTR,...);
395*7f2fe78bSCy Schubert LPSTR (*Lerror_message)(long);
396*7f2fe78bSCy Schubert LPSTR (*Lerror_table_name)(long);
397*7f2fe78bSCy Schubert
398*7f2fe78bSCy Schubert
399*7f2fe78bSCy Schubert long
Leash_kinit(char * principal,char * password,int lifetime)400*7f2fe78bSCy Schubert Leash_kinit(
401*7f2fe78bSCy Schubert char * principal,
402*7f2fe78bSCy Schubert char * password,
403*7f2fe78bSCy Schubert int lifetime
404*7f2fe78bSCy Schubert )
405*7f2fe78bSCy Schubert {
406*7f2fe78bSCy Schubert return Leash_int_kinit_ex( 0, 0,
407*7f2fe78bSCy Schubert principal,
408*7f2fe78bSCy Schubert password,
409*7f2fe78bSCy Schubert lifetime,
410*7f2fe78bSCy Schubert Leash_get_default_forwardable(),
411*7f2fe78bSCy Schubert Leash_get_default_proxiable(),
412*7f2fe78bSCy Schubert Leash_get_default_renew_till(),
413*7f2fe78bSCy Schubert Leash_get_default_noaddresses(),
414*7f2fe78bSCy Schubert Leash_get_default_publicip(),
415*7f2fe78bSCy Schubert 0
416*7f2fe78bSCy Schubert );
417*7f2fe78bSCy Schubert }
418*7f2fe78bSCy Schubert
419*7f2fe78bSCy Schubert long
Leash_kinit_ex(char * principal,char * password,int lifetime,int forwardable,int proxiable,int renew_life,int addressless,unsigned long publicip)420*7f2fe78bSCy Schubert Leash_kinit_ex(
421*7f2fe78bSCy Schubert char * principal,
422*7f2fe78bSCy Schubert char * password,
423*7f2fe78bSCy Schubert int lifetime,
424*7f2fe78bSCy Schubert int forwardable,
425*7f2fe78bSCy Schubert int proxiable,
426*7f2fe78bSCy Schubert int renew_life,
427*7f2fe78bSCy Schubert int addressless,
428*7f2fe78bSCy Schubert unsigned long publicip
429*7f2fe78bSCy Schubert )
430*7f2fe78bSCy Schubert {
431*7f2fe78bSCy Schubert return Leash_int_kinit_ex( 0, /* krb5 context */
432*7f2fe78bSCy Schubert 0, /* parent window */
433*7f2fe78bSCy Schubert principal,
434*7f2fe78bSCy Schubert password,
435*7f2fe78bSCy Schubert lifetime,
436*7f2fe78bSCy Schubert forwardable,
437*7f2fe78bSCy Schubert proxiable,
438*7f2fe78bSCy Schubert renew_life,
439*7f2fe78bSCy Schubert addressless,
440*7f2fe78bSCy Schubert publicip,
441*7f2fe78bSCy Schubert 0
442*7f2fe78bSCy Schubert );
443*7f2fe78bSCy Schubert }
444*7f2fe78bSCy Schubert
445*7f2fe78bSCy Schubert long
Leash_int_kinit_ex(krb5_context ctx,HWND hParent,char * principal,char * password,int lifetime,int forwardable,int proxiable,int renew_life,int addressless,unsigned long publicip,int displayErrors)446*7f2fe78bSCy Schubert Leash_int_kinit_ex(
447*7f2fe78bSCy Schubert krb5_context ctx,
448*7f2fe78bSCy Schubert HWND hParent,
449*7f2fe78bSCy Schubert char * principal,
450*7f2fe78bSCy Schubert char * password,
451*7f2fe78bSCy Schubert int lifetime,
452*7f2fe78bSCy Schubert int forwardable,
453*7f2fe78bSCy Schubert int proxiable,
454*7f2fe78bSCy Schubert int renew_life,
455*7f2fe78bSCy Schubert int addressless,
456*7f2fe78bSCy Schubert unsigned long publicip,
457*7f2fe78bSCy Schubert int displayErrors
458*7f2fe78bSCy Schubert )
459*7f2fe78bSCy Schubert {
460*7f2fe78bSCy Schubert char aname[ANAME_SZ];
461*7f2fe78bSCy Schubert char inst[INST_SZ];
462*7f2fe78bSCy Schubert char realm[REALM_SZ];
463*7f2fe78bSCy Schubert char first_part[256];
464*7f2fe78bSCy Schubert char second_part[256];
465*7f2fe78bSCy Schubert char temp[1024];
466*7f2fe78bSCy Schubert char* custom_msg;
467*7f2fe78bSCy Schubert int count;
468*7f2fe78bSCy Schubert int i;
469*7f2fe78bSCy Schubert int rc5 = 0;
470*7f2fe78bSCy Schubert int rcA = 0;
471*7f2fe78bSCy Schubert int rcB = 0;
472*7f2fe78bSCy Schubert int rcL = 0;
473*7f2fe78bSCy Schubert
474*7f2fe78bSCy Schubert if (lifetime < 5)
475*7f2fe78bSCy Schubert lifetime = 1;
476*7f2fe78bSCy Schubert else
477*7f2fe78bSCy Schubert lifetime /= 5;
478*7f2fe78bSCy Schubert
479*7f2fe78bSCy Schubert if (renew_life > 0 && renew_life < 5)
480*7f2fe78bSCy Schubert renew_life = 1;
481*7f2fe78bSCy Schubert else
482*7f2fe78bSCy Schubert renew_life /= 5;
483*7f2fe78bSCy Schubert
484*7f2fe78bSCy Schubert /* This should be changed if the maximum ticket lifetime */
485*7f2fe78bSCy Schubert /* changes */
486*7f2fe78bSCy Schubert
487*7f2fe78bSCy Schubert if (lifetime > 255)
488*7f2fe78bSCy Schubert lifetime = 255;
489*7f2fe78bSCy Schubert
490*7f2fe78bSCy Schubert err_context = "parsing principal";
491*7f2fe78bSCy Schubert
492*7f2fe78bSCy Schubert memset(temp, '\0', sizeof(temp));
493*7f2fe78bSCy Schubert memset(inst, '\0', sizeof(inst));
494*7f2fe78bSCy Schubert memset(realm, '\0', sizeof(realm));
495*7f2fe78bSCy Schubert memset(first_part, '\0', sizeof(first_part));
496*7f2fe78bSCy Schubert memset(second_part, '\0', sizeof(second_part));
497*7f2fe78bSCy Schubert
498*7f2fe78bSCy Schubert sscanf(principal, "%[/0-9a-zA-Z._-]@%[/0-9a-zA-Z._-]", first_part, second_part);
499*7f2fe78bSCy Schubert strcpy(temp, first_part);
500*7f2fe78bSCy Schubert strcpy(realm, second_part);
501*7f2fe78bSCy Schubert memset(first_part, '\0', sizeof(first_part));
502*7f2fe78bSCy Schubert memset(second_part, '\0', sizeof(second_part));
503*7f2fe78bSCy Schubert if (sscanf(temp, "%[@0-9a-zA-Z._-]/%[@0-9a-zA-Z._-]", first_part, second_part) == 2)
504*7f2fe78bSCy Schubert {
505*7f2fe78bSCy Schubert strcpy(aname, first_part);
506*7f2fe78bSCy Schubert strcpy(inst, second_part);
507*7f2fe78bSCy Schubert }
508*7f2fe78bSCy Schubert else
509*7f2fe78bSCy Schubert {
510*7f2fe78bSCy Schubert count = 0;
511*7f2fe78bSCy Schubert i = 0;
512*7f2fe78bSCy Schubert for (i = 0; temp[i]; i++)
513*7f2fe78bSCy Schubert {
514*7f2fe78bSCy Schubert if (temp[i] == '.')
515*7f2fe78bSCy Schubert ++count;
516*7f2fe78bSCy Schubert }
517*7f2fe78bSCy Schubert if (count > 1)
518*7f2fe78bSCy Schubert {
519*7f2fe78bSCy Schubert strcpy(aname, temp);
520*7f2fe78bSCy Schubert }
521*7f2fe78bSCy Schubert else
522*7f2fe78bSCy Schubert {
523*7f2fe78bSCy Schubert {
524*7f2fe78bSCy Schubert strcpy(aname, temp);
525*7f2fe78bSCy Schubert }
526*7f2fe78bSCy Schubert }
527*7f2fe78bSCy Schubert }
528*7f2fe78bSCy Schubert
529*7f2fe78bSCy Schubert memset(temp, '\0', sizeof(temp));
530*7f2fe78bSCy Schubert strcpy(temp, aname);
531*7f2fe78bSCy Schubert if (strlen(inst) != 0)
532*7f2fe78bSCy Schubert {
533*7f2fe78bSCy Schubert strcat(temp, "/");
534*7f2fe78bSCy Schubert strcat(temp, inst);
535*7f2fe78bSCy Schubert }
536*7f2fe78bSCy Schubert if (strlen(realm) != 0)
537*7f2fe78bSCy Schubert {
538*7f2fe78bSCy Schubert strcat(temp, "@");
539*7f2fe78bSCy Schubert strcat(temp, realm);
540*7f2fe78bSCy Schubert }
541*7f2fe78bSCy Schubert
542*7f2fe78bSCy Schubert rc5 = Leash_krb5_kinit(ctx, hParent,
543*7f2fe78bSCy Schubert temp, password, lifetime,
544*7f2fe78bSCy Schubert forwardable,
545*7f2fe78bSCy Schubert proxiable,
546*7f2fe78bSCy Schubert renew_life,
547*7f2fe78bSCy Schubert addressless,
548*7f2fe78bSCy Schubert publicip
549*7f2fe78bSCy Schubert );
550*7f2fe78bSCy Schubert custom_msg = (rc5 == KRB5KRB_AP_ERR_BAD_INTEGRITY) ? "Password incorrect" : NULL;
551*7f2fe78bSCy Schubert return leash_error_message("Ticket initialization failed.",
552*7f2fe78bSCy Schubert rcL, rc5, rcA, custom_msg,
553*7f2fe78bSCy Schubert displayErrors);
554*7f2fe78bSCy Schubert }
555*7f2fe78bSCy Schubert
556*7f2fe78bSCy Schubert long FAR
Leash_renew(void)557*7f2fe78bSCy Schubert Leash_renew(void)
558*7f2fe78bSCy Schubert {
559*7f2fe78bSCy Schubert if ( hKrb5 && !LeashKRB5_renew() ) {
560*7f2fe78bSCy Schubert int lifetime;
561*7f2fe78bSCy Schubert lifetime = Leash_get_default_lifetime() / 5;
562*7f2fe78bSCy Schubert return 1;
563*7f2fe78bSCy Schubert }
564*7f2fe78bSCy Schubert return 0;
565*7f2fe78bSCy Schubert }
566*7f2fe78bSCy Schubert
567*7f2fe78bSCy Schubert BOOL
GetSecurityLogonSessionData(PSECURITY_LOGON_SESSION_DATA * ppSessionData)568*7f2fe78bSCy Schubert GetSecurityLogonSessionData(PSECURITY_LOGON_SESSION_DATA * ppSessionData)
569*7f2fe78bSCy Schubert {
570*7f2fe78bSCy Schubert NTSTATUS Status = 0;
571*7f2fe78bSCy Schubert HANDLE TokenHandle;
572*7f2fe78bSCy Schubert TOKEN_STATISTICS Stats;
573*7f2fe78bSCy Schubert DWORD ReqLen;
574*7f2fe78bSCy Schubert BOOL Success;
575*7f2fe78bSCy Schubert PSECURITY_LOGON_SESSION_DATA pSessionData;
576*7f2fe78bSCy Schubert
577*7f2fe78bSCy Schubert if (!ppSessionData)
578*7f2fe78bSCy Schubert return FALSE;
579*7f2fe78bSCy Schubert *ppSessionData = NULL;
580*7f2fe78bSCy Schubert
581*7f2fe78bSCy Schubert Success = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &TokenHandle );
582*7f2fe78bSCy Schubert if ( !Success )
583*7f2fe78bSCy Schubert return FALSE;
584*7f2fe78bSCy Schubert
585*7f2fe78bSCy Schubert Success = GetTokenInformation( TokenHandle, TokenStatistics, &Stats, sizeof(TOKEN_STATISTICS), &ReqLen );
586*7f2fe78bSCy Schubert CloseHandle( TokenHandle );
587*7f2fe78bSCy Schubert if ( !Success )
588*7f2fe78bSCy Schubert return FALSE;
589*7f2fe78bSCy Schubert
590*7f2fe78bSCy Schubert Status = pLsaGetLogonSessionData( &Stats.AuthenticationId, &pSessionData );
591*7f2fe78bSCy Schubert if ( FAILED(Status) || !pSessionData )
592*7f2fe78bSCy Schubert return FALSE;
593*7f2fe78bSCy Schubert
594*7f2fe78bSCy Schubert *ppSessionData = pSessionData;
595*7f2fe78bSCy Schubert return TRUE;
596*7f2fe78bSCy Schubert }
597*7f2fe78bSCy Schubert
598*7f2fe78bSCy Schubert // IsKerberosLogon() does not validate whether or not there are valid tickets in the
599*7f2fe78bSCy Schubert // cache. It validates whether or not it is reasonable to assume that if we
600*7f2fe78bSCy Schubert // attempted to retrieve valid tickets we could do so. Microsoft does not
601*7f2fe78bSCy Schubert // automatically renew expired tickets. Therefore, the cache could contain
602*7f2fe78bSCy Schubert // expired or invalid tickets. Microsoft also caches the user's password
603*7f2fe78bSCy Schubert // and will use it to retrieve new TGTs if the cache is empty and tickets
604*7f2fe78bSCy Schubert // are requested.
605*7f2fe78bSCy Schubert
606*7f2fe78bSCy Schubert BOOL
IsKerberosLogon(VOID)607*7f2fe78bSCy Schubert IsKerberosLogon(VOID)
608*7f2fe78bSCy Schubert {
609*7f2fe78bSCy Schubert PSECURITY_LOGON_SESSION_DATA pSessionData = NULL;
610*7f2fe78bSCy Schubert BOOL Success = FALSE;
611*7f2fe78bSCy Schubert
612*7f2fe78bSCy Schubert if ( GetSecurityLogonSessionData(&pSessionData) ) {
613*7f2fe78bSCy Schubert if ( pSessionData->AuthenticationPackage.Buffer ) {
614*7f2fe78bSCy Schubert WCHAR buffer[256];
615*7f2fe78bSCy Schubert WCHAR *usBuffer;
616*7f2fe78bSCy Schubert int usLength;
617*7f2fe78bSCy Schubert
618*7f2fe78bSCy Schubert Success = FALSE;
619*7f2fe78bSCy Schubert usBuffer = (pSessionData->AuthenticationPackage).Buffer;
620*7f2fe78bSCy Schubert usLength = (pSessionData->AuthenticationPackage).Length;
621*7f2fe78bSCy Schubert if (usLength < 256)
622*7f2fe78bSCy Schubert {
623*7f2fe78bSCy Schubert lstrcpynW (buffer, usBuffer, usLength);
624*7f2fe78bSCy Schubert lstrcatW (buffer,L"");
625*7f2fe78bSCy Schubert if ( !lstrcmpW(L"Kerberos",buffer) )
626*7f2fe78bSCy Schubert Success = TRUE;
627*7f2fe78bSCy Schubert }
628*7f2fe78bSCy Schubert }
629*7f2fe78bSCy Schubert pLsaFreeReturnBuffer(pSessionData);
630*7f2fe78bSCy Schubert }
631*7f2fe78bSCy Schubert return Success;
632*7f2fe78bSCy Schubert }
633*7f2fe78bSCy Schubert
634*7f2fe78bSCy Schubert static BOOL
IsWindowsVista(void)635*7f2fe78bSCy Schubert IsWindowsVista (void)
636*7f2fe78bSCy Schubert {
637*7f2fe78bSCy Schubert static BOOL fChecked = FALSE;
638*7f2fe78bSCy Schubert static BOOL fIsVista = FALSE;
639*7f2fe78bSCy Schubert
640*7f2fe78bSCy Schubert if (!fChecked)
641*7f2fe78bSCy Schubert {
642*7f2fe78bSCy Schubert OSVERSIONINFO Version;
643*7f2fe78bSCy Schubert
644*7f2fe78bSCy Schubert memset (&Version, 0x00, sizeof(Version));
645*7f2fe78bSCy Schubert Version.dwOSVersionInfoSize = sizeof(Version);
646*7f2fe78bSCy Schubert
647*7f2fe78bSCy Schubert if (GetVersionEx (&Version))
648*7f2fe78bSCy Schubert {
649*7f2fe78bSCy Schubert if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT && Version.dwMajorVersion >= 6)
650*7f2fe78bSCy Schubert fIsVista = TRUE;
651*7f2fe78bSCy Schubert }
652*7f2fe78bSCy Schubert fChecked = TRUE;
653*7f2fe78bSCy Schubert }
654*7f2fe78bSCy Schubert
655*7f2fe78bSCy Schubert return fIsVista;
656*7f2fe78bSCy Schubert }
657*7f2fe78bSCy Schubert
658*7f2fe78bSCy Schubert static BOOL
IsProcessUacLimited(void)659*7f2fe78bSCy Schubert IsProcessUacLimited (void)
660*7f2fe78bSCy Schubert {
661*7f2fe78bSCy Schubert static BOOL fChecked = FALSE;
662*7f2fe78bSCy Schubert static BOOL fIsUAC = FALSE;
663*7f2fe78bSCy Schubert
664*7f2fe78bSCy Schubert if (!fChecked)
665*7f2fe78bSCy Schubert {
666*7f2fe78bSCy Schubert NTSTATUS Status = 0;
667*7f2fe78bSCy Schubert HANDLE TokenHandle;
668*7f2fe78bSCy Schubert DWORD ElevationLevel;
669*7f2fe78bSCy Schubert DWORD ReqLen;
670*7f2fe78bSCy Schubert BOOL Success;
671*7f2fe78bSCy Schubert
672*7f2fe78bSCy Schubert if (IsWindowsVista()) {
673*7f2fe78bSCy Schubert Success = OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &TokenHandle );
674*7f2fe78bSCy Schubert if ( Success ) {
675*7f2fe78bSCy Schubert Success = GetTokenInformation( TokenHandle,
676*7f2fe78bSCy Schubert TokenOrigin+1 /* ElevationLevel */,
677*7f2fe78bSCy Schubert &ElevationLevel, sizeof(DWORD), &ReqLen );
678*7f2fe78bSCy Schubert CloseHandle( TokenHandle );
679*7f2fe78bSCy Schubert if ( Success && ElevationLevel == 3 /* Limited */ )
680*7f2fe78bSCy Schubert fIsUAC = TRUE;
681*7f2fe78bSCy Schubert }
682*7f2fe78bSCy Schubert }
683*7f2fe78bSCy Schubert fChecked = TRUE;
684*7f2fe78bSCy Schubert }
685*7f2fe78bSCy Schubert return fIsUAC;
686*7f2fe78bSCy Schubert
687*7f2fe78bSCy Schubert }
688*7f2fe78bSCy Schubert
689*7f2fe78bSCy Schubert long FAR
Leash_importable(void)690*7f2fe78bSCy Schubert Leash_importable(void)
691*7f2fe78bSCy Schubert {
692*7f2fe78bSCy Schubert /* Import functionality has been removed. */
693*7f2fe78bSCy Schubert return FALSE;
694*7f2fe78bSCy Schubert }
695*7f2fe78bSCy Schubert
696*7f2fe78bSCy Schubert long FAR
Leash_import(void)697*7f2fe78bSCy Schubert Leash_import(void)
698*7f2fe78bSCy Schubert {
699*7f2fe78bSCy Schubert /* Import functionality has been removed. */
700*7f2fe78bSCy Schubert return 0;
701*7f2fe78bSCy Schubert }
702*7f2fe78bSCy Schubert
703*7f2fe78bSCy Schubert long
Leash_kdestroy(void)704*7f2fe78bSCy Schubert Leash_kdestroy(void)
705*7f2fe78bSCy Schubert {
706*7f2fe78bSCy Schubert Leash_krb5_kdestroy();
707*7f2fe78bSCy Schubert
708*7f2fe78bSCy Schubert return 0;
709*7f2fe78bSCy Schubert }
710*7f2fe78bSCy Schubert
Leash_klist(HWND hlist,TICKETINFO FAR * ticketinfo)711*7f2fe78bSCy Schubert long FAR Leash_klist(HWND hlist, TICKETINFO FAR *ticketinfo)
712*7f2fe78bSCy Schubert {
713*7f2fe78bSCy Schubert return(255);
714*7f2fe78bSCy Schubert }
715*7f2fe78bSCy Schubert
716*7f2fe78bSCy Schubert
717*7f2fe78bSCy Schubert // This function can be used to set the help file that will be
718*7f2fe78bSCy Schubert // referenced the DLL's PasswordProcDLL function and err_describe
719*7f2fe78bSCy Schubert // function. Returns true if the help file has been set to the
720*7f2fe78bSCy Schubert // argument or the environment variable KERB_HELP. Returns FALSE if
721*7f2fe78bSCy Schubert // the default helpfile as defined in by HELPFILE in lsh_pwd.h is
722*7f2fe78bSCy Schubert // used.
Leash_set_help_file(char * szHelpFile)723*7f2fe78bSCy Schubert BOOL Leash_set_help_file( char *szHelpFile )
724*7f2fe78bSCy Schubert {
725*7f2fe78bSCy Schubert char tmpHelpFile[256];
726*7f2fe78bSCy Schubert BOOL ret = 0;
727*7f2fe78bSCy Schubert
728*7f2fe78bSCy Schubert if( szHelpFile == NULL ){
729*7f2fe78bSCy Schubert GetEnvironmentVariable("KERB_HELP", tmpHelpFile, sizeof(tmpHelpFile));
730*7f2fe78bSCy Schubert } else {
731*7f2fe78bSCy Schubert strcpy( KRB_HelpFile, szHelpFile );
732*7f2fe78bSCy Schubert ret++;
733*7f2fe78bSCy Schubert }
734*7f2fe78bSCy Schubert
735*7f2fe78bSCy Schubert if( !ret && tmpHelpFile[0] ){
736*7f2fe78bSCy Schubert strcpy( KRB_HelpFile, tmpHelpFile );
737*7f2fe78bSCy Schubert ret++;
738*7f2fe78bSCy Schubert }
739*7f2fe78bSCy Schubert
740*7f2fe78bSCy Schubert if( !ret){
741*7f2fe78bSCy Schubert strcpy( KRB_HelpFile, HELPFILE );
742*7f2fe78bSCy Schubert }
743*7f2fe78bSCy Schubert
744*7f2fe78bSCy Schubert return(ret);
745*7f2fe78bSCy Schubert }
746*7f2fe78bSCy Schubert
747*7f2fe78bSCy Schubert
748*7f2fe78bSCy Schubert
Leash_get_help_file(void)749*7f2fe78bSCy Schubert LPSTR Leash_get_help_file(void)
750*7f2fe78bSCy Schubert {
751*7f2fe78bSCy Schubert return( KRB_HelpFile);
752*7f2fe78bSCy Schubert }
753*7f2fe78bSCy Schubert
754*7f2fe78bSCy Schubert int
Leash_debug(int class,int priority,char * fmt,...)755*7f2fe78bSCy Schubert Leash_debug(
756*7f2fe78bSCy Schubert int class,
757*7f2fe78bSCy Schubert int priority,
758*7f2fe78bSCy Schubert char* fmt, ...
759*7f2fe78bSCy Schubert )
760*7f2fe78bSCy Schubert {
761*7f2fe78bSCy Schubert
762*7f2fe78bSCy Schubert return 0;
763*7f2fe78bSCy Schubert }
764*7f2fe78bSCy Schubert
765*7f2fe78bSCy Schubert
766*7f2fe78bSCy Schubert static int
get_profile_file(LPSTR confname,UINT szConfname)767*7f2fe78bSCy Schubert get_profile_file(LPSTR confname, UINT szConfname)
768*7f2fe78bSCy Schubert {
769*7f2fe78bSCy Schubert char **configFile = NULL;
770*7f2fe78bSCy Schubert if (hKrb5) {
771*7f2fe78bSCy Schubert if (pkrb5_get_default_config_files(&configFile) || !configFile[0])
772*7f2fe78bSCy Schubert {
773*7f2fe78bSCy Schubert GetWindowsDirectory(confname,szConfname);
774*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
775*7f2fe78bSCy Schubert strncat(confname,"\\KRB5.INI",szConfname-strlen(confname));
776*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
777*7f2fe78bSCy Schubert return FALSE;
778*7f2fe78bSCy Schubert }
779*7f2fe78bSCy Schubert
780*7f2fe78bSCy Schubert *confname = 0;
781*7f2fe78bSCy Schubert
782*7f2fe78bSCy Schubert if (configFile)
783*7f2fe78bSCy Schubert {
784*7f2fe78bSCy Schubert strncpy(confname, *configFile, szConfname);
785*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
786*7f2fe78bSCy Schubert pkrb5_free_config_files(configFile);
787*7f2fe78bSCy Schubert }
788*7f2fe78bSCy Schubert }
789*7f2fe78bSCy Schubert
790*7f2fe78bSCy Schubert if (!*confname)
791*7f2fe78bSCy Schubert {
792*7f2fe78bSCy Schubert GetWindowsDirectory(confname,szConfname);
793*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
794*7f2fe78bSCy Schubert strncat(confname,"\\KRB5.INI",szConfname-strlen(confname));
795*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
796*7f2fe78bSCy Schubert }
797*7f2fe78bSCy Schubert
798*7f2fe78bSCy Schubert return FALSE;
799*7f2fe78bSCy Schubert }
800*7f2fe78bSCy Schubert
801*7f2fe78bSCy Schubert static const char *const conf_yes[] = {
802*7f2fe78bSCy Schubert "y", "yes", "true", "t", "1", "on",
803*7f2fe78bSCy Schubert 0,
804*7f2fe78bSCy Schubert };
805*7f2fe78bSCy Schubert
806*7f2fe78bSCy Schubert static const char *const conf_no[] = {
807*7f2fe78bSCy Schubert "n", "no", "false", "nil", "0", "off",
808*7f2fe78bSCy Schubert 0,
809*7f2fe78bSCy Schubert };
810*7f2fe78bSCy Schubert
811*7f2fe78bSCy Schubert int
config_boolean_to_int(const char * s)812*7f2fe78bSCy Schubert config_boolean_to_int(const char *s)
813*7f2fe78bSCy Schubert {
814*7f2fe78bSCy Schubert const char *const *p;
815*7f2fe78bSCy Schubert
816*7f2fe78bSCy Schubert for(p=conf_yes; *p; p++) {
817*7f2fe78bSCy Schubert if (!strcasecmp(*p,s))
818*7f2fe78bSCy Schubert return 1;
819*7f2fe78bSCy Schubert }
820*7f2fe78bSCy Schubert
821*7f2fe78bSCy Schubert for(p=conf_no; *p; p++) {
822*7f2fe78bSCy Schubert if (!strcasecmp(*p,s))
823*7f2fe78bSCy Schubert return 0;
824*7f2fe78bSCy Schubert }
825*7f2fe78bSCy Schubert
826*7f2fe78bSCy Schubert /* Default to "no" */
827*7f2fe78bSCy Schubert return 0;
828*7f2fe78bSCy Schubert }
829*7f2fe78bSCy Schubert
830*7f2fe78bSCy Schubert /*
831*7f2fe78bSCy Schubert * Leash_get_default_lifetime:
832*7f2fe78bSCy Schubert *
833*7f2fe78bSCy Schubert * This function is used to get the default ticket lifetime for this
834*7f2fe78bSCy Schubert * process in minutes. A return value of 0 indicates no setting or
835*7f2fe78bSCy Schubert * "default" setting obtained.
836*7f2fe78bSCy Schubert *
837*7f2fe78bSCy Schubert * Here is where we look in order:
838*7f2fe78bSCy Schubert *
839*7f2fe78bSCy Schubert * - LIFETIME environment variable
840*7f2fe78bSCy Schubert * - HKCU\Software\MIT\Leash,lifetime
841*7f2fe78bSCy Schubert * - HKLM\Software\MIT\Leash,lifetime
842*7f2fe78bSCy Schubert * - string resource in the leash DLL
843*7f2fe78bSCy Schubert */
844*7f2fe78bSCy Schubert
845*7f2fe78bSCy Schubert static BOOL
get_DWORD_from_registry(HKEY hBaseKey,char * key,char * value,DWORD * result)846*7f2fe78bSCy Schubert get_DWORD_from_registry(
847*7f2fe78bSCy Schubert HKEY hBaseKey,
848*7f2fe78bSCy Schubert char * key,
849*7f2fe78bSCy Schubert char * value,
850*7f2fe78bSCy Schubert DWORD * result
851*7f2fe78bSCy Schubert )
852*7f2fe78bSCy Schubert {
853*7f2fe78bSCy Schubert HKEY hKey;
854*7f2fe78bSCy Schubert DWORD dwCount;
855*7f2fe78bSCy Schubert LONG rc;
856*7f2fe78bSCy Schubert
857*7f2fe78bSCy Schubert rc = RegOpenKeyEx(hBaseKey, key, 0, KEY_QUERY_VALUE, &hKey);
858*7f2fe78bSCy Schubert if (rc)
859*7f2fe78bSCy Schubert return FALSE;
860*7f2fe78bSCy Schubert
861*7f2fe78bSCy Schubert dwCount = sizeof(DWORD);
862*7f2fe78bSCy Schubert rc = RegQueryValueEx(hKey, value, 0, 0, (LPBYTE) result, &dwCount);
863*7f2fe78bSCy Schubert RegCloseKey(hKey);
864*7f2fe78bSCy Schubert
865*7f2fe78bSCy Schubert return rc?FALSE:TRUE;
866*7f2fe78bSCy Schubert }
867*7f2fe78bSCy Schubert
868*7f2fe78bSCy Schubert static
869*7f2fe78bSCy Schubert BOOL
get_default_lifetime_from_registry(HKEY hBaseKey,DWORD * result)870*7f2fe78bSCy Schubert get_default_lifetime_from_registry(
871*7f2fe78bSCy Schubert HKEY hBaseKey,
872*7f2fe78bSCy Schubert DWORD * result
873*7f2fe78bSCy Schubert )
874*7f2fe78bSCy Schubert {
875*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
876*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
877*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_LIFETIME,
878*7f2fe78bSCy Schubert result);
879*7f2fe78bSCy Schubert }
880*7f2fe78bSCy Schubert
881*7f2fe78bSCy Schubert DWORD
Leash_reset_default_lifetime()882*7f2fe78bSCy Schubert Leash_reset_default_lifetime(
883*7f2fe78bSCy Schubert )
884*7f2fe78bSCy Schubert {
885*7f2fe78bSCy Schubert HKEY hKey;
886*7f2fe78bSCy Schubert LONG rc;
887*7f2fe78bSCy Schubert
888*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
889*7f2fe78bSCy Schubert if (rc)
890*7f2fe78bSCy Schubert return rc;
891*7f2fe78bSCy Schubert
892*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_LIFETIME);
893*7f2fe78bSCy Schubert RegCloseKey(hKey);
894*7f2fe78bSCy Schubert
895*7f2fe78bSCy Schubert return rc;
896*7f2fe78bSCy Schubert }
897*7f2fe78bSCy Schubert
898*7f2fe78bSCy Schubert DWORD
Leash_set_default_lifetime(DWORD minutes)899*7f2fe78bSCy Schubert Leash_set_default_lifetime(
900*7f2fe78bSCy Schubert DWORD minutes
901*7f2fe78bSCy Schubert )
902*7f2fe78bSCy Schubert {
903*7f2fe78bSCy Schubert HKEY hKey;
904*7f2fe78bSCy Schubert LONG rc;
905*7f2fe78bSCy Schubert
906*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
907*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
908*7f2fe78bSCy Schubert if (rc)
909*7f2fe78bSCy Schubert return rc;
910*7f2fe78bSCy Schubert
911*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_LIFETIME, 0, REG_DWORD,
912*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
913*7f2fe78bSCy Schubert RegCloseKey(hKey);
914*7f2fe78bSCy Schubert
915*7f2fe78bSCy Schubert return rc;
916*7f2fe78bSCy Schubert }
917*7f2fe78bSCy Schubert
918*7f2fe78bSCy Schubert DWORD
Leash_get_default_lifetime()919*7f2fe78bSCy Schubert Leash_get_default_lifetime(
920*7f2fe78bSCy Schubert )
921*7f2fe78bSCy Schubert {
922*7f2fe78bSCy Schubert HMODULE hmLeash;
923*7f2fe78bSCy Schubert char env[32];
924*7f2fe78bSCy Schubert DWORD result;
925*7f2fe78bSCy Schubert
926*7f2fe78bSCy Schubert
927*7f2fe78bSCy Schubert if (GetEnvironmentVariable("LIFETIME",env,sizeof(env)))
928*7f2fe78bSCy Schubert {
929*7f2fe78bSCy Schubert return atoi(env);
930*7f2fe78bSCy Schubert }
931*7f2fe78bSCy Schubert
932*7f2fe78bSCy Schubert
933*7f2fe78bSCy Schubert if (get_default_lifetime_from_registry(HKEY_CURRENT_USER, &result) ||
934*7f2fe78bSCy Schubert get_default_lifetime_from_registry(HKEY_LOCAL_MACHINE, &result))
935*7f2fe78bSCy Schubert {
936*7f2fe78bSCy Schubert return result;
937*7f2fe78bSCy Schubert }
938*7f2fe78bSCy Schubert
939*7f2fe78bSCy Schubert if ( hKrb5 ) {
940*7f2fe78bSCy Schubert CHAR confname[MAX_PATH];
941*7f2fe78bSCy Schubert
942*7f2fe78bSCy Schubert if (!get_profile_file(confname, sizeof(confname)))
943*7f2fe78bSCy Schubert {
944*7f2fe78bSCy Schubert profile_t profile;
945*7f2fe78bSCy Schubert const char *filenames[2];
946*7f2fe78bSCy Schubert long retval;
947*7f2fe78bSCy Schubert
948*7f2fe78bSCy Schubert filenames[0] = confname;
949*7f2fe78bSCy Schubert filenames[1] = NULL;
950*7f2fe78bSCy Schubert if (!pprofile_init(filenames, &profile)) {
951*7f2fe78bSCy Schubert char * value = NULL;
952*7f2fe78bSCy Schubert
953*7f2fe78bSCy Schubert retval = pprofile_get_string(profile, "libdefaults", "ticket_lifetime", NULL, NULL, &value);
954*7f2fe78bSCy Schubert if (retval == 0 && value) {
955*7f2fe78bSCy Schubert krb5_deltat d;
956*7f2fe78bSCy Schubert
957*7f2fe78bSCy Schubert retval = pkrb5_string_to_deltat(value, &d);
958*7f2fe78bSCy Schubert
959*7f2fe78bSCy Schubert if (retval == KRB5_DELTAT_BADFORMAT) {
960*7f2fe78bSCy Schubert /* Historically some sites use relations of
961*7f2fe78bSCy Schubert the form 'ticket_lifetime = 24000' where
962*7f2fe78bSCy Schubert the unit is left out but is assumed to be
963*7f2fe78bSCy Schubert seconds. Then there are other sites which
964*7f2fe78bSCy Schubert use the form 'ticket_lifetime = 600' where
965*7f2fe78bSCy Schubert the unit is assumed to be minutes. While
966*7f2fe78bSCy Schubert these are technically wrong (a unit needs
967*7f2fe78bSCy Schubert to be specified), we try to accommodate for
968*7f2fe78bSCy Schubert this using the safe assumption that the
969*7f2fe78bSCy Schubert unit is seconds and tack an 's' to the end
970*7f2fe78bSCy Schubert and see if that works. */
971*7f2fe78bSCy Schubert
972*7f2fe78bSCy Schubert /* Of course, Leash is one of the platforms
973*7f2fe78bSCy Schubert that historically assumed no units and minutes
974*7f2fe78bSCy Schubert so this change is going to break some people
975*7f2fe78bSCy Schubert but its better to be consistent. */
976*7f2fe78bSCy Schubert size_t cch;
977*7f2fe78bSCy Schubert char buf[256];
978*7f2fe78bSCy Schubert
979*7f2fe78bSCy Schubert do {
980*7f2fe78bSCy Schubert cch = strlen(value) + 2; /* NUL and new 's' */
981*7f2fe78bSCy Schubert if (cch > sizeof(buf))
982*7f2fe78bSCy Schubert break;
983*7f2fe78bSCy Schubert
984*7f2fe78bSCy Schubert strcpy(buf, value);
985*7f2fe78bSCy Schubert strcat(buf, "s");
986*7f2fe78bSCy Schubert
987*7f2fe78bSCy Schubert retval = pkrb5_string_to_deltat(buf, &d);
988*7f2fe78bSCy Schubert
989*7f2fe78bSCy Schubert if (retval == 0) {
990*7f2fe78bSCy Schubert result = d / 60;
991*7f2fe78bSCy Schubert }
992*7f2fe78bSCy Schubert } while(0);
993*7f2fe78bSCy Schubert } else if (retval == 0) {
994*7f2fe78bSCy Schubert result = d / 60;
995*7f2fe78bSCy Schubert }
996*7f2fe78bSCy Schubert
997*7f2fe78bSCy Schubert pprofile_release_string(value);
998*7f2fe78bSCy Schubert }
999*7f2fe78bSCy Schubert pprofile_release(profile);
1000*7f2fe78bSCy Schubert /* value has been released but we can still use a check for
1001*7f2fe78bSCy Schubert * non-NULL to see if we were able to read a value.
1002*7f2fe78bSCy Schubert */
1003*7f2fe78bSCy Schubert if (retval == 0 && value)
1004*7f2fe78bSCy Schubert return result;
1005*7f2fe78bSCy Schubert }
1006*7f2fe78bSCy Schubert }
1007*7f2fe78bSCy Schubert }
1008*7f2fe78bSCy Schubert
1009*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1010*7f2fe78bSCy Schubert if (hmLeash)
1011*7f2fe78bSCy Schubert {
1012*7f2fe78bSCy Schubert char lifetime[80];
1013*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_LIFE,
1014*7f2fe78bSCy Schubert lifetime, sizeof(lifetime)))
1015*7f2fe78bSCy Schubert {
1016*7f2fe78bSCy Schubert lifetime[sizeof(lifetime) - 1] = 0;
1017*7f2fe78bSCy Schubert return atoi(lifetime);
1018*7f2fe78bSCy Schubert }
1019*7f2fe78bSCy Schubert }
1020*7f2fe78bSCy Schubert return 0;
1021*7f2fe78bSCy Schubert }
1022*7f2fe78bSCy Schubert
1023*7f2fe78bSCy Schubert static
1024*7f2fe78bSCy Schubert BOOL
get_default_renew_till_from_registry(HKEY hBaseKey,DWORD * result)1025*7f2fe78bSCy Schubert get_default_renew_till_from_registry(
1026*7f2fe78bSCy Schubert HKEY hBaseKey,
1027*7f2fe78bSCy Schubert DWORD * result
1028*7f2fe78bSCy Schubert )
1029*7f2fe78bSCy Schubert {
1030*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1031*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1032*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_RENEW_TILL,
1033*7f2fe78bSCy Schubert result);
1034*7f2fe78bSCy Schubert }
1035*7f2fe78bSCy Schubert
1036*7f2fe78bSCy Schubert DWORD
Leash_reset_default_renew_till()1037*7f2fe78bSCy Schubert Leash_reset_default_renew_till(
1038*7f2fe78bSCy Schubert )
1039*7f2fe78bSCy Schubert {
1040*7f2fe78bSCy Schubert HKEY hKey;
1041*7f2fe78bSCy Schubert LONG rc;
1042*7f2fe78bSCy Schubert
1043*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1044*7f2fe78bSCy Schubert if (rc)
1045*7f2fe78bSCy Schubert return rc;
1046*7f2fe78bSCy Schubert
1047*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_RENEW_TILL);
1048*7f2fe78bSCy Schubert RegCloseKey(hKey);
1049*7f2fe78bSCy Schubert
1050*7f2fe78bSCy Schubert return rc;
1051*7f2fe78bSCy Schubert }
1052*7f2fe78bSCy Schubert
1053*7f2fe78bSCy Schubert DWORD
Leash_set_default_renew_till(DWORD minutes)1054*7f2fe78bSCy Schubert Leash_set_default_renew_till(
1055*7f2fe78bSCy Schubert DWORD minutes
1056*7f2fe78bSCy Schubert )
1057*7f2fe78bSCy Schubert {
1058*7f2fe78bSCy Schubert HKEY hKey;
1059*7f2fe78bSCy Schubert LONG rc;
1060*7f2fe78bSCy Schubert
1061*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1062*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1063*7f2fe78bSCy Schubert if (rc)
1064*7f2fe78bSCy Schubert return rc;
1065*7f2fe78bSCy Schubert
1066*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_RENEW_TILL, 0, REG_DWORD,
1067*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1068*7f2fe78bSCy Schubert RegCloseKey(hKey);
1069*7f2fe78bSCy Schubert
1070*7f2fe78bSCy Schubert return rc;
1071*7f2fe78bSCy Schubert }
1072*7f2fe78bSCy Schubert
1073*7f2fe78bSCy Schubert DWORD
Leash_get_default_renew_till()1074*7f2fe78bSCy Schubert Leash_get_default_renew_till(
1075*7f2fe78bSCy Schubert )
1076*7f2fe78bSCy Schubert {
1077*7f2fe78bSCy Schubert HMODULE hmLeash;
1078*7f2fe78bSCy Schubert char env[32];
1079*7f2fe78bSCy Schubert DWORD result;
1080*7f2fe78bSCy Schubert
1081*7f2fe78bSCy Schubert if(GetEnvironmentVariable("RENEW_TILL",env,sizeof(env)))
1082*7f2fe78bSCy Schubert {
1083*7f2fe78bSCy Schubert return atoi(env);
1084*7f2fe78bSCy Schubert }
1085*7f2fe78bSCy Schubert
1086*7f2fe78bSCy Schubert if (get_default_renew_till_from_registry(HKEY_CURRENT_USER, &result) ||
1087*7f2fe78bSCy Schubert get_default_renew_till_from_registry(HKEY_LOCAL_MACHINE, &result))
1088*7f2fe78bSCy Schubert {
1089*7f2fe78bSCy Schubert return result;
1090*7f2fe78bSCy Schubert }
1091*7f2fe78bSCy Schubert
1092*7f2fe78bSCy Schubert if ( hKrb5 ) {
1093*7f2fe78bSCy Schubert CHAR confname[MAX_PATH];
1094*7f2fe78bSCy Schubert if (!get_profile_file(confname, sizeof(confname)))
1095*7f2fe78bSCy Schubert {
1096*7f2fe78bSCy Schubert profile_t profile;
1097*7f2fe78bSCy Schubert const char *filenames[2];
1098*7f2fe78bSCy Schubert int value=0;
1099*7f2fe78bSCy Schubert long retval;
1100*7f2fe78bSCy Schubert filenames[0] = confname;
1101*7f2fe78bSCy Schubert filenames[1] = NULL;
1102*7f2fe78bSCy Schubert
1103*7f2fe78bSCy Schubert if (!pprofile_init(filenames, &profile)) {
1104*7f2fe78bSCy Schubert char * value = NULL;
1105*7f2fe78bSCy Schubert
1106*7f2fe78bSCy Schubert retval = pprofile_get_string(profile, "libdefaults", "renew_lifetime", NULL, NULL, &value);
1107*7f2fe78bSCy Schubert if (retval == 0 && value) {
1108*7f2fe78bSCy Schubert krb5_deltat d;
1109*7f2fe78bSCy Schubert
1110*7f2fe78bSCy Schubert retval = pkrb5_string_to_deltat(value, &d);
1111*7f2fe78bSCy Schubert if (retval == KRB5_DELTAT_BADFORMAT) {
1112*7f2fe78bSCy Schubert /* Historically some sites use relations of
1113*7f2fe78bSCy Schubert the form 'ticket_lifetime = 24000' where
1114*7f2fe78bSCy Schubert the unit is left out but is assumed to be
1115*7f2fe78bSCy Schubert seconds. Then there are other sites which
1116*7f2fe78bSCy Schubert use the form 'ticket_lifetime = 600' where
1117*7f2fe78bSCy Schubert the unit is assumed to be minutes. While
1118*7f2fe78bSCy Schubert these are technically wrong (a unit needs
1119*7f2fe78bSCy Schubert to be specified), we try to accommodate for
1120*7f2fe78bSCy Schubert this using the safe assumption that the
1121*7f2fe78bSCy Schubert unit is seconds and tack an 's' to the end
1122*7f2fe78bSCy Schubert and see if that works. */
1123*7f2fe78bSCy Schubert
1124*7f2fe78bSCy Schubert /* Of course, Leash is one of the platforms
1125*7f2fe78bSCy Schubert that historically assumed no units and minutes
1126*7f2fe78bSCy Schubert so this change is going to break some people
1127*7f2fe78bSCy Schubert but its better to be consistent. */
1128*7f2fe78bSCy Schubert size_t cch;
1129*7f2fe78bSCy Schubert char buf[256];
1130*7f2fe78bSCy Schubert do {
1131*7f2fe78bSCy Schubert cch = strlen(value) + 2; /* NUL and new 's' */
1132*7f2fe78bSCy Schubert if (cch > sizeof(buf))
1133*7f2fe78bSCy Schubert break;
1134*7f2fe78bSCy Schubert
1135*7f2fe78bSCy Schubert strcpy(buf, value);
1136*7f2fe78bSCy Schubert strcat(buf, "s");
1137*7f2fe78bSCy Schubert
1138*7f2fe78bSCy Schubert retval = pkrb5_string_to_deltat(buf, &d);
1139*7f2fe78bSCy Schubert if (retval == 0) {
1140*7f2fe78bSCy Schubert result = d / 60;
1141*7f2fe78bSCy Schubert }
1142*7f2fe78bSCy Schubert } while(0);
1143*7f2fe78bSCy Schubert } else if (retval == 0) {
1144*7f2fe78bSCy Schubert result = d / 60;
1145*7f2fe78bSCy Schubert }
1146*7f2fe78bSCy Schubert pprofile_release_string(value);
1147*7f2fe78bSCy Schubert }
1148*7f2fe78bSCy Schubert pprofile_release(profile);
1149*7f2fe78bSCy Schubert /* value has been released but we can still use a check for
1150*7f2fe78bSCy Schubert * non-NULL to see if we were able to read a value.
1151*7f2fe78bSCy Schubert */
1152*7f2fe78bSCy Schubert if (retval == 0 && value)
1153*7f2fe78bSCy Schubert return result;
1154*7f2fe78bSCy Schubert
1155*7f2fe78bSCy Schubert pprofile_release(profile);
1156*7f2fe78bSCy Schubert }
1157*7f2fe78bSCy Schubert }
1158*7f2fe78bSCy Schubert }
1159*7f2fe78bSCy Schubert
1160*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1161*7f2fe78bSCy Schubert if (hmLeash)
1162*7f2fe78bSCy Schubert {
1163*7f2fe78bSCy Schubert char renew_till[80];
1164*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_RENEW_TILL,
1165*7f2fe78bSCy Schubert renew_till, sizeof(renew_till)))
1166*7f2fe78bSCy Schubert {
1167*7f2fe78bSCy Schubert renew_till[sizeof(renew_till) - 1] = 0;
1168*7f2fe78bSCy Schubert return atoi(renew_till);
1169*7f2fe78bSCy Schubert }
1170*7f2fe78bSCy Schubert }
1171*7f2fe78bSCy Schubert return 0;
1172*7f2fe78bSCy Schubert }
1173*7f2fe78bSCy Schubert
1174*7f2fe78bSCy Schubert static
1175*7f2fe78bSCy Schubert BOOL
get_default_forwardable_from_registry(HKEY hBaseKey,DWORD * result)1176*7f2fe78bSCy Schubert get_default_forwardable_from_registry(
1177*7f2fe78bSCy Schubert HKEY hBaseKey,
1178*7f2fe78bSCy Schubert DWORD * result
1179*7f2fe78bSCy Schubert )
1180*7f2fe78bSCy Schubert {
1181*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1182*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1183*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_FORWARDABLE,
1184*7f2fe78bSCy Schubert result);
1185*7f2fe78bSCy Schubert }
1186*7f2fe78bSCy Schubert
1187*7f2fe78bSCy Schubert DWORD
Leash_reset_default_forwardable()1188*7f2fe78bSCy Schubert Leash_reset_default_forwardable(
1189*7f2fe78bSCy Schubert )
1190*7f2fe78bSCy Schubert {
1191*7f2fe78bSCy Schubert HKEY hKey;
1192*7f2fe78bSCy Schubert LONG rc;
1193*7f2fe78bSCy Schubert
1194*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1195*7f2fe78bSCy Schubert if (rc)
1196*7f2fe78bSCy Schubert return rc;
1197*7f2fe78bSCy Schubert
1198*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_FORWARDABLE);
1199*7f2fe78bSCy Schubert RegCloseKey(hKey);
1200*7f2fe78bSCy Schubert
1201*7f2fe78bSCy Schubert return rc;
1202*7f2fe78bSCy Schubert }
1203*7f2fe78bSCy Schubert
1204*7f2fe78bSCy Schubert DWORD
Leash_set_default_forwardable(DWORD minutes)1205*7f2fe78bSCy Schubert Leash_set_default_forwardable(
1206*7f2fe78bSCy Schubert DWORD minutes
1207*7f2fe78bSCy Schubert )
1208*7f2fe78bSCy Schubert {
1209*7f2fe78bSCy Schubert HKEY hKey;
1210*7f2fe78bSCy Schubert LONG rc;
1211*7f2fe78bSCy Schubert
1212*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1213*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1214*7f2fe78bSCy Schubert if (rc)
1215*7f2fe78bSCy Schubert return rc;
1216*7f2fe78bSCy Schubert
1217*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_FORWARDABLE, 0, REG_DWORD,
1218*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1219*7f2fe78bSCy Schubert RegCloseKey(hKey);
1220*7f2fe78bSCy Schubert
1221*7f2fe78bSCy Schubert return rc;
1222*7f2fe78bSCy Schubert }
1223*7f2fe78bSCy Schubert
1224*7f2fe78bSCy Schubert DWORD
Leash_get_default_forwardable()1225*7f2fe78bSCy Schubert Leash_get_default_forwardable(
1226*7f2fe78bSCy Schubert )
1227*7f2fe78bSCy Schubert {
1228*7f2fe78bSCy Schubert HMODULE hmLeash;
1229*7f2fe78bSCy Schubert
1230*7f2fe78bSCy Schubert char env[32];
1231*7f2fe78bSCy Schubert DWORD result;
1232*7f2fe78bSCy Schubert
1233*7f2fe78bSCy Schubert if(GetEnvironmentVariable("FORWARDABLE",env,sizeof(env)))
1234*7f2fe78bSCy Schubert {
1235*7f2fe78bSCy Schubert return atoi(env);
1236*7f2fe78bSCy Schubert }
1237*7f2fe78bSCy Schubert
1238*7f2fe78bSCy Schubert if (get_default_forwardable_from_registry(HKEY_CURRENT_USER, &result) ||
1239*7f2fe78bSCy Schubert get_default_forwardable_from_registry(HKEY_LOCAL_MACHINE, &result))
1240*7f2fe78bSCy Schubert {
1241*7f2fe78bSCy Schubert return result;
1242*7f2fe78bSCy Schubert }
1243*7f2fe78bSCy Schubert
1244*7f2fe78bSCy Schubert if ( hKrb5 ) {
1245*7f2fe78bSCy Schubert CHAR confname[MAX_PATH];
1246*7f2fe78bSCy Schubert if (!get_profile_file(confname, sizeof(confname)))
1247*7f2fe78bSCy Schubert {
1248*7f2fe78bSCy Schubert profile_t profile;
1249*7f2fe78bSCy Schubert const char *filenames[2];
1250*7f2fe78bSCy Schubert char *value=0;
1251*7f2fe78bSCy Schubert long retval;
1252*7f2fe78bSCy Schubert filenames[0] = confname;
1253*7f2fe78bSCy Schubert filenames[1] = NULL;
1254*7f2fe78bSCy Schubert if (!pprofile_init(filenames, &profile)) {
1255*7f2fe78bSCy Schubert retval = pprofile_get_string(profile, "libdefaults","forwardable", 0, 0, &value);
1256*7f2fe78bSCy Schubert if ( value ) {
1257*7f2fe78bSCy Schubert result = config_boolean_to_int(value);
1258*7f2fe78bSCy Schubert pprofile_release_string(value);
1259*7f2fe78bSCy Schubert pprofile_release(profile);
1260*7f2fe78bSCy Schubert return result;
1261*7f2fe78bSCy Schubert }
1262*7f2fe78bSCy Schubert pprofile_release(profile);
1263*7f2fe78bSCy Schubert }
1264*7f2fe78bSCy Schubert }
1265*7f2fe78bSCy Schubert }
1266*7f2fe78bSCy Schubert
1267*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1268*7f2fe78bSCy Schubert if (hmLeash)
1269*7f2fe78bSCy Schubert {
1270*7f2fe78bSCy Schubert char forwardable[80];
1271*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_FORWARD,
1272*7f2fe78bSCy Schubert forwardable, sizeof(forwardable)))
1273*7f2fe78bSCy Schubert {
1274*7f2fe78bSCy Schubert forwardable[sizeof(forwardable) - 1] = 0;
1275*7f2fe78bSCy Schubert return atoi(forwardable);
1276*7f2fe78bSCy Schubert }
1277*7f2fe78bSCy Schubert }
1278*7f2fe78bSCy Schubert return 0;
1279*7f2fe78bSCy Schubert }
1280*7f2fe78bSCy Schubert
1281*7f2fe78bSCy Schubert static
1282*7f2fe78bSCy Schubert BOOL
get_default_renewable_from_registry(HKEY hBaseKey,DWORD * result)1283*7f2fe78bSCy Schubert get_default_renewable_from_registry(
1284*7f2fe78bSCy Schubert HKEY hBaseKey,
1285*7f2fe78bSCy Schubert DWORD * result
1286*7f2fe78bSCy Schubert )
1287*7f2fe78bSCy Schubert {
1288*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1289*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1290*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_RENEWABLE,
1291*7f2fe78bSCy Schubert result);
1292*7f2fe78bSCy Schubert }
1293*7f2fe78bSCy Schubert
1294*7f2fe78bSCy Schubert DWORD
Leash_reset_default_renewable()1295*7f2fe78bSCy Schubert Leash_reset_default_renewable(
1296*7f2fe78bSCy Schubert )
1297*7f2fe78bSCy Schubert {
1298*7f2fe78bSCy Schubert HKEY hKey;
1299*7f2fe78bSCy Schubert LONG rc;
1300*7f2fe78bSCy Schubert
1301*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1302*7f2fe78bSCy Schubert if (rc)
1303*7f2fe78bSCy Schubert return rc;
1304*7f2fe78bSCy Schubert
1305*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_RENEWABLE);
1306*7f2fe78bSCy Schubert RegCloseKey(hKey);
1307*7f2fe78bSCy Schubert
1308*7f2fe78bSCy Schubert return rc;
1309*7f2fe78bSCy Schubert }
1310*7f2fe78bSCy Schubert
1311*7f2fe78bSCy Schubert DWORD
Leash_set_default_renewable(DWORD minutes)1312*7f2fe78bSCy Schubert Leash_set_default_renewable(
1313*7f2fe78bSCy Schubert DWORD minutes
1314*7f2fe78bSCy Schubert )
1315*7f2fe78bSCy Schubert {
1316*7f2fe78bSCy Schubert HKEY hKey;
1317*7f2fe78bSCy Schubert LONG rc;
1318*7f2fe78bSCy Schubert
1319*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1320*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1321*7f2fe78bSCy Schubert if (rc)
1322*7f2fe78bSCy Schubert return rc;
1323*7f2fe78bSCy Schubert
1324*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_RENEWABLE, 0, REG_DWORD,
1325*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1326*7f2fe78bSCy Schubert RegCloseKey(hKey);
1327*7f2fe78bSCy Schubert
1328*7f2fe78bSCy Schubert return rc;
1329*7f2fe78bSCy Schubert }
1330*7f2fe78bSCy Schubert
1331*7f2fe78bSCy Schubert DWORD
Leash_get_default_renewable()1332*7f2fe78bSCy Schubert Leash_get_default_renewable(
1333*7f2fe78bSCy Schubert )
1334*7f2fe78bSCy Schubert {
1335*7f2fe78bSCy Schubert HMODULE hmLeash;
1336*7f2fe78bSCy Schubert char env[32];
1337*7f2fe78bSCy Schubert DWORD result;
1338*7f2fe78bSCy Schubert
1339*7f2fe78bSCy Schubert if(GetEnvironmentVariable("RENEWABLE",env,sizeof(env)))
1340*7f2fe78bSCy Schubert {
1341*7f2fe78bSCy Schubert return atoi(env);
1342*7f2fe78bSCy Schubert }
1343*7f2fe78bSCy Schubert
1344*7f2fe78bSCy Schubert if (get_default_renewable_from_registry(HKEY_CURRENT_USER, &result) ||
1345*7f2fe78bSCy Schubert get_default_renewable_from_registry(HKEY_LOCAL_MACHINE, &result))
1346*7f2fe78bSCy Schubert {
1347*7f2fe78bSCy Schubert return result;
1348*7f2fe78bSCy Schubert }
1349*7f2fe78bSCy Schubert
1350*7f2fe78bSCy Schubert if ( hKrb5 ) {
1351*7f2fe78bSCy Schubert CHAR confname[MAX_PATH];
1352*7f2fe78bSCy Schubert if (!get_profile_file(confname, sizeof(confname)))
1353*7f2fe78bSCy Schubert {
1354*7f2fe78bSCy Schubert profile_t profile;
1355*7f2fe78bSCy Schubert const char *filenames[2];
1356*7f2fe78bSCy Schubert char *value=0;
1357*7f2fe78bSCy Schubert long retval;
1358*7f2fe78bSCy Schubert filenames[0] = confname;
1359*7f2fe78bSCy Schubert filenames[1] = NULL;
1360*7f2fe78bSCy Schubert if (!pprofile_init(filenames, &profile)) {
1361*7f2fe78bSCy Schubert retval = pprofile_get_string(profile, "libdefaults","renewable", 0, 0, &value);
1362*7f2fe78bSCy Schubert if ( value ) {
1363*7f2fe78bSCy Schubert result = config_boolean_to_int(value);
1364*7f2fe78bSCy Schubert pprofile_release_string(value);
1365*7f2fe78bSCy Schubert pprofile_release(profile);
1366*7f2fe78bSCy Schubert return result;
1367*7f2fe78bSCy Schubert }
1368*7f2fe78bSCy Schubert pprofile_release(profile);
1369*7f2fe78bSCy Schubert }
1370*7f2fe78bSCy Schubert }
1371*7f2fe78bSCy Schubert }
1372*7f2fe78bSCy Schubert
1373*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1374*7f2fe78bSCy Schubert if (hmLeash)
1375*7f2fe78bSCy Schubert {
1376*7f2fe78bSCy Schubert char renewable[80];
1377*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_RENEW,
1378*7f2fe78bSCy Schubert renewable, sizeof(renewable)))
1379*7f2fe78bSCy Schubert {
1380*7f2fe78bSCy Schubert renewable[sizeof(renewable) - 1] = 0;
1381*7f2fe78bSCy Schubert return atoi(renewable);
1382*7f2fe78bSCy Schubert }
1383*7f2fe78bSCy Schubert }
1384*7f2fe78bSCy Schubert return 0;
1385*7f2fe78bSCy Schubert }
1386*7f2fe78bSCy Schubert
1387*7f2fe78bSCy Schubert static
1388*7f2fe78bSCy Schubert BOOL
get_default_noaddresses_from_registry(HKEY hBaseKey,DWORD * result)1389*7f2fe78bSCy Schubert get_default_noaddresses_from_registry(
1390*7f2fe78bSCy Schubert HKEY hBaseKey,
1391*7f2fe78bSCy Schubert DWORD * result
1392*7f2fe78bSCy Schubert )
1393*7f2fe78bSCy Schubert {
1394*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1395*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1396*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_NOADDRESSES,
1397*7f2fe78bSCy Schubert result);
1398*7f2fe78bSCy Schubert }
1399*7f2fe78bSCy Schubert
1400*7f2fe78bSCy Schubert DWORD
Leash_reset_default_noaddresses()1401*7f2fe78bSCy Schubert Leash_reset_default_noaddresses(
1402*7f2fe78bSCy Schubert )
1403*7f2fe78bSCy Schubert {
1404*7f2fe78bSCy Schubert HKEY hKey;
1405*7f2fe78bSCy Schubert LONG rc;
1406*7f2fe78bSCy Schubert
1407*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1408*7f2fe78bSCy Schubert if (rc)
1409*7f2fe78bSCy Schubert return rc;
1410*7f2fe78bSCy Schubert
1411*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_NOADDRESSES);
1412*7f2fe78bSCy Schubert RegCloseKey(hKey);
1413*7f2fe78bSCy Schubert
1414*7f2fe78bSCy Schubert return rc;
1415*7f2fe78bSCy Schubert }
1416*7f2fe78bSCy Schubert
1417*7f2fe78bSCy Schubert DWORD
Leash_set_default_noaddresses(DWORD minutes)1418*7f2fe78bSCy Schubert Leash_set_default_noaddresses(
1419*7f2fe78bSCy Schubert DWORD minutes
1420*7f2fe78bSCy Schubert )
1421*7f2fe78bSCy Schubert {
1422*7f2fe78bSCy Schubert HKEY hKey;
1423*7f2fe78bSCy Schubert LONG rc;
1424*7f2fe78bSCy Schubert
1425*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1426*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1427*7f2fe78bSCy Schubert if (rc)
1428*7f2fe78bSCy Schubert return rc;
1429*7f2fe78bSCy Schubert
1430*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_NOADDRESSES, 0, REG_DWORD,
1431*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1432*7f2fe78bSCy Schubert RegCloseKey(hKey);
1433*7f2fe78bSCy Schubert
1434*7f2fe78bSCy Schubert return rc;
1435*7f2fe78bSCy Schubert }
1436*7f2fe78bSCy Schubert
1437*7f2fe78bSCy Schubert DWORD
Leash_get_default_noaddresses()1438*7f2fe78bSCy Schubert Leash_get_default_noaddresses(
1439*7f2fe78bSCy Schubert )
1440*7f2fe78bSCy Schubert {
1441*7f2fe78bSCy Schubert HMODULE hmLeash;
1442*7f2fe78bSCy Schubert char env[32];
1443*7f2fe78bSCy Schubert DWORD result;
1444*7f2fe78bSCy Schubert
1445*7f2fe78bSCy Schubert if ( hKrb5 ) {
1446*7f2fe78bSCy Schubert // if the profile file cannot be opened then the value will be true
1447*7f2fe78bSCy Schubert // if the noaddresses name cannot be found then the value will be true
1448*7f2fe78bSCy Schubert // if true in the library, we can't alter it by other means
1449*7f2fe78bSCy Schubert CHAR confname[MAX_PATH];
1450*7f2fe78bSCy Schubert result = 1;
1451*7f2fe78bSCy Schubert if (!get_profile_file(confname, sizeof(confname)))
1452*7f2fe78bSCy Schubert {
1453*7f2fe78bSCy Schubert profile_t profile;
1454*7f2fe78bSCy Schubert const char *filenames[2];
1455*7f2fe78bSCy Schubert char *value=0;
1456*7f2fe78bSCy Schubert long retval;
1457*7f2fe78bSCy Schubert filenames[0] = confname;
1458*7f2fe78bSCy Schubert filenames[1] = NULL;
1459*7f2fe78bSCy Schubert if (!pprofile_init(filenames, &profile)) {
1460*7f2fe78bSCy Schubert retval = pprofile_get_string(profile, "libdefaults","noaddresses", 0, "true", &value);
1461*7f2fe78bSCy Schubert if ( value ) {
1462*7f2fe78bSCy Schubert result = config_boolean_to_int(value);
1463*7f2fe78bSCy Schubert pprofile_release_string(value);
1464*7f2fe78bSCy Schubert }
1465*7f2fe78bSCy Schubert pprofile_release(profile);
1466*7f2fe78bSCy Schubert }
1467*7f2fe78bSCy Schubert }
1468*7f2fe78bSCy Schubert
1469*7f2fe78bSCy Schubert if ( result )
1470*7f2fe78bSCy Schubert return 1;
1471*7f2fe78bSCy Schubert }
1472*7f2fe78bSCy Schubert
1473*7f2fe78bSCy Schubert // The library default is false, check other locations
1474*7f2fe78bSCy Schubert
1475*7f2fe78bSCy Schubert if(GetEnvironmentVariable("NOADDRESSES",env,sizeof(env)))
1476*7f2fe78bSCy Schubert {
1477*7f2fe78bSCy Schubert return atoi(env);
1478*7f2fe78bSCy Schubert }
1479*7f2fe78bSCy Schubert
1480*7f2fe78bSCy Schubert if (get_default_noaddresses_from_registry(HKEY_CURRENT_USER, &result) ||
1481*7f2fe78bSCy Schubert get_default_noaddresses_from_registry(HKEY_LOCAL_MACHINE, &result))
1482*7f2fe78bSCy Schubert {
1483*7f2fe78bSCy Schubert return result;
1484*7f2fe78bSCy Schubert }
1485*7f2fe78bSCy Schubert
1486*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1487*7f2fe78bSCy Schubert if (hmLeash)
1488*7f2fe78bSCy Schubert {
1489*7f2fe78bSCy Schubert char noaddresses[80];
1490*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_NOADDRESS,
1491*7f2fe78bSCy Schubert noaddresses, sizeof(noaddresses)))
1492*7f2fe78bSCy Schubert {
1493*7f2fe78bSCy Schubert noaddresses[sizeof(noaddresses) - 1] = 0;
1494*7f2fe78bSCy Schubert }
1495*7f2fe78bSCy Schubert }
1496*7f2fe78bSCy Schubert return 1;
1497*7f2fe78bSCy Schubert }
1498*7f2fe78bSCy Schubert
1499*7f2fe78bSCy Schubert static
1500*7f2fe78bSCy Schubert BOOL
get_default_proxiable_from_registry(HKEY hBaseKey,DWORD * result)1501*7f2fe78bSCy Schubert get_default_proxiable_from_registry(
1502*7f2fe78bSCy Schubert HKEY hBaseKey,
1503*7f2fe78bSCy Schubert DWORD * result
1504*7f2fe78bSCy Schubert )
1505*7f2fe78bSCy Schubert {
1506*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1507*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1508*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_PROXIABLE,
1509*7f2fe78bSCy Schubert result);
1510*7f2fe78bSCy Schubert }
1511*7f2fe78bSCy Schubert
1512*7f2fe78bSCy Schubert DWORD
Leash_reset_default_proxiable()1513*7f2fe78bSCy Schubert Leash_reset_default_proxiable(
1514*7f2fe78bSCy Schubert )
1515*7f2fe78bSCy Schubert {
1516*7f2fe78bSCy Schubert HKEY hKey;
1517*7f2fe78bSCy Schubert LONG rc;
1518*7f2fe78bSCy Schubert
1519*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1520*7f2fe78bSCy Schubert if (rc)
1521*7f2fe78bSCy Schubert return rc;
1522*7f2fe78bSCy Schubert
1523*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_PROXIABLE);
1524*7f2fe78bSCy Schubert RegCloseKey(hKey);
1525*7f2fe78bSCy Schubert
1526*7f2fe78bSCy Schubert return rc;
1527*7f2fe78bSCy Schubert }
1528*7f2fe78bSCy Schubert
1529*7f2fe78bSCy Schubert DWORD
Leash_set_default_proxiable(DWORD minutes)1530*7f2fe78bSCy Schubert Leash_set_default_proxiable(
1531*7f2fe78bSCy Schubert DWORD minutes
1532*7f2fe78bSCy Schubert )
1533*7f2fe78bSCy Schubert {
1534*7f2fe78bSCy Schubert HKEY hKey;
1535*7f2fe78bSCy Schubert LONG rc;
1536*7f2fe78bSCy Schubert
1537*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1538*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1539*7f2fe78bSCy Schubert if (rc)
1540*7f2fe78bSCy Schubert return rc;
1541*7f2fe78bSCy Schubert
1542*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_PROXIABLE, 0, REG_DWORD,
1543*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1544*7f2fe78bSCy Schubert RegCloseKey(hKey);
1545*7f2fe78bSCy Schubert
1546*7f2fe78bSCy Schubert return rc;
1547*7f2fe78bSCy Schubert }
1548*7f2fe78bSCy Schubert
1549*7f2fe78bSCy Schubert DWORD
Leash_get_default_proxiable()1550*7f2fe78bSCy Schubert Leash_get_default_proxiable(
1551*7f2fe78bSCy Schubert )
1552*7f2fe78bSCy Schubert {
1553*7f2fe78bSCy Schubert HMODULE hmLeash;
1554*7f2fe78bSCy Schubert char env[32];
1555*7f2fe78bSCy Schubert DWORD result;
1556*7f2fe78bSCy Schubert
1557*7f2fe78bSCy Schubert if(GetEnvironmentVariable("PROXIABLE",env,sizeof(env)))
1558*7f2fe78bSCy Schubert {
1559*7f2fe78bSCy Schubert return atoi(env);
1560*7f2fe78bSCy Schubert }
1561*7f2fe78bSCy Schubert
1562*7f2fe78bSCy Schubert if (get_default_proxiable_from_registry(HKEY_CURRENT_USER, &result) ||
1563*7f2fe78bSCy Schubert get_default_proxiable_from_registry(HKEY_LOCAL_MACHINE, &result))
1564*7f2fe78bSCy Schubert {
1565*7f2fe78bSCy Schubert return result;
1566*7f2fe78bSCy Schubert }
1567*7f2fe78bSCy Schubert
1568*7f2fe78bSCy Schubert if ( hKrb5 ) {
1569*7f2fe78bSCy Schubert CHAR confname[MAX_PATH];
1570*7f2fe78bSCy Schubert if (!get_profile_file(confname, sizeof(confname)))
1571*7f2fe78bSCy Schubert {
1572*7f2fe78bSCy Schubert profile_t profile;
1573*7f2fe78bSCy Schubert const char *filenames[2];
1574*7f2fe78bSCy Schubert char *value=0;
1575*7f2fe78bSCy Schubert long retval;
1576*7f2fe78bSCy Schubert filenames[0] = confname;
1577*7f2fe78bSCy Schubert filenames[1] = NULL;
1578*7f2fe78bSCy Schubert if (!pprofile_init(filenames, &profile)) {
1579*7f2fe78bSCy Schubert retval = pprofile_get_string(profile, "libdefaults","proxiable", 0, 0, &value);
1580*7f2fe78bSCy Schubert if ( value ) {
1581*7f2fe78bSCy Schubert result = config_boolean_to_int(value);
1582*7f2fe78bSCy Schubert pprofile_release_string(value);
1583*7f2fe78bSCy Schubert pprofile_release(profile);
1584*7f2fe78bSCy Schubert return result;
1585*7f2fe78bSCy Schubert }
1586*7f2fe78bSCy Schubert pprofile_release(profile);
1587*7f2fe78bSCy Schubert }
1588*7f2fe78bSCy Schubert }
1589*7f2fe78bSCy Schubert }
1590*7f2fe78bSCy Schubert
1591*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1592*7f2fe78bSCy Schubert if (hmLeash)
1593*7f2fe78bSCy Schubert {
1594*7f2fe78bSCy Schubert char proxiable[80];
1595*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_PROXIABLE,
1596*7f2fe78bSCy Schubert proxiable, sizeof(proxiable)))
1597*7f2fe78bSCy Schubert {
1598*7f2fe78bSCy Schubert proxiable[sizeof(proxiable) - 1] = 0;
1599*7f2fe78bSCy Schubert return atoi(proxiable);
1600*7f2fe78bSCy Schubert }
1601*7f2fe78bSCy Schubert }
1602*7f2fe78bSCy Schubert return 0;
1603*7f2fe78bSCy Schubert }
1604*7f2fe78bSCy Schubert
1605*7f2fe78bSCy Schubert static
1606*7f2fe78bSCy Schubert BOOL
get_default_publicip_from_registry(HKEY hBaseKey,DWORD * result)1607*7f2fe78bSCy Schubert get_default_publicip_from_registry(
1608*7f2fe78bSCy Schubert HKEY hBaseKey,
1609*7f2fe78bSCy Schubert DWORD * result
1610*7f2fe78bSCy Schubert )
1611*7f2fe78bSCy Schubert {
1612*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1613*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1614*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_PUBLICIP,
1615*7f2fe78bSCy Schubert result);
1616*7f2fe78bSCy Schubert }
1617*7f2fe78bSCy Schubert
1618*7f2fe78bSCy Schubert DWORD
Leash_reset_default_publicip()1619*7f2fe78bSCy Schubert Leash_reset_default_publicip(
1620*7f2fe78bSCy Schubert )
1621*7f2fe78bSCy Schubert {
1622*7f2fe78bSCy Schubert HKEY hKey;
1623*7f2fe78bSCy Schubert LONG rc;
1624*7f2fe78bSCy Schubert
1625*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1626*7f2fe78bSCy Schubert if (rc)
1627*7f2fe78bSCy Schubert return rc;
1628*7f2fe78bSCy Schubert
1629*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_PUBLICIP);
1630*7f2fe78bSCy Schubert RegCloseKey(hKey);
1631*7f2fe78bSCy Schubert
1632*7f2fe78bSCy Schubert return rc;
1633*7f2fe78bSCy Schubert }
1634*7f2fe78bSCy Schubert
1635*7f2fe78bSCy Schubert DWORD
Leash_set_default_publicip(DWORD minutes)1636*7f2fe78bSCy Schubert Leash_set_default_publicip(
1637*7f2fe78bSCy Schubert DWORD minutes
1638*7f2fe78bSCy Schubert )
1639*7f2fe78bSCy Schubert {
1640*7f2fe78bSCy Schubert HKEY hKey;
1641*7f2fe78bSCy Schubert LONG rc;
1642*7f2fe78bSCy Schubert
1643*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1644*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1645*7f2fe78bSCy Schubert if (rc)
1646*7f2fe78bSCy Schubert return rc;
1647*7f2fe78bSCy Schubert
1648*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_PUBLICIP, 0, REG_DWORD,
1649*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1650*7f2fe78bSCy Schubert RegCloseKey(hKey);
1651*7f2fe78bSCy Schubert
1652*7f2fe78bSCy Schubert return rc;
1653*7f2fe78bSCy Schubert }
1654*7f2fe78bSCy Schubert
1655*7f2fe78bSCy Schubert DWORD
Leash_get_default_publicip()1656*7f2fe78bSCy Schubert Leash_get_default_publicip(
1657*7f2fe78bSCy Schubert )
1658*7f2fe78bSCy Schubert {
1659*7f2fe78bSCy Schubert HMODULE hmLeash;
1660*7f2fe78bSCy Schubert char env[32];
1661*7f2fe78bSCy Schubert DWORD result;
1662*7f2fe78bSCy Schubert
1663*7f2fe78bSCy Schubert if(GetEnvironmentVariable("PUBLICIP",env,sizeof(env)))
1664*7f2fe78bSCy Schubert {
1665*7f2fe78bSCy Schubert return atoi(env);
1666*7f2fe78bSCy Schubert }
1667*7f2fe78bSCy Schubert
1668*7f2fe78bSCy Schubert if (get_default_publicip_from_registry(HKEY_CURRENT_USER, &result) ||
1669*7f2fe78bSCy Schubert get_default_publicip_from_registry(HKEY_LOCAL_MACHINE, &result))
1670*7f2fe78bSCy Schubert {
1671*7f2fe78bSCy Schubert return result;
1672*7f2fe78bSCy Schubert }
1673*7f2fe78bSCy Schubert
1674*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1675*7f2fe78bSCy Schubert if (hmLeash)
1676*7f2fe78bSCy Schubert {
1677*7f2fe78bSCy Schubert char publicip[80];
1678*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_TICKET_PUBLICIP,
1679*7f2fe78bSCy Schubert publicip, sizeof(publicip)))
1680*7f2fe78bSCy Schubert {
1681*7f2fe78bSCy Schubert publicip[sizeof(publicip) - 1] = 0;
1682*7f2fe78bSCy Schubert return atoi(publicip);
1683*7f2fe78bSCy Schubert }
1684*7f2fe78bSCy Schubert }
1685*7f2fe78bSCy Schubert return 0;
1686*7f2fe78bSCy Schubert }
1687*7f2fe78bSCy Schubert
1688*7f2fe78bSCy Schubert static
1689*7f2fe78bSCy Schubert BOOL
get_hide_kinit_options_from_registry(HKEY hBaseKey,DWORD * result)1690*7f2fe78bSCy Schubert get_hide_kinit_options_from_registry(
1691*7f2fe78bSCy Schubert HKEY hBaseKey,
1692*7f2fe78bSCy Schubert DWORD * result
1693*7f2fe78bSCy Schubert )
1694*7f2fe78bSCy Schubert {
1695*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1696*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1697*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_KINIT_OPT,
1698*7f2fe78bSCy Schubert result);
1699*7f2fe78bSCy Schubert }
1700*7f2fe78bSCy Schubert
1701*7f2fe78bSCy Schubert DWORD
Leash_reset_hide_kinit_options()1702*7f2fe78bSCy Schubert Leash_reset_hide_kinit_options(
1703*7f2fe78bSCy Schubert )
1704*7f2fe78bSCy Schubert {
1705*7f2fe78bSCy Schubert HKEY hKey;
1706*7f2fe78bSCy Schubert LONG rc;
1707*7f2fe78bSCy Schubert
1708*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1709*7f2fe78bSCy Schubert if (rc)
1710*7f2fe78bSCy Schubert return rc;
1711*7f2fe78bSCy Schubert
1712*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_KINIT_OPT);
1713*7f2fe78bSCy Schubert RegCloseKey(hKey);
1714*7f2fe78bSCy Schubert
1715*7f2fe78bSCy Schubert return rc;
1716*7f2fe78bSCy Schubert }
1717*7f2fe78bSCy Schubert
1718*7f2fe78bSCy Schubert DWORD
Leash_set_hide_kinit_options(DWORD minutes)1719*7f2fe78bSCy Schubert Leash_set_hide_kinit_options(
1720*7f2fe78bSCy Schubert DWORD minutes
1721*7f2fe78bSCy Schubert )
1722*7f2fe78bSCy Schubert {
1723*7f2fe78bSCy Schubert HKEY hKey;
1724*7f2fe78bSCy Schubert LONG rc;
1725*7f2fe78bSCy Schubert
1726*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1727*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1728*7f2fe78bSCy Schubert if (rc)
1729*7f2fe78bSCy Schubert return rc;
1730*7f2fe78bSCy Schubert
1731*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_KINIT_OPT, 0, REG_DWORD,
1732*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1733*7f2fe78bSCy Schubert RegCloseKey(hKey);
1734*7f2fe78bSCy Schubert
1735*7f2fe78bSCy Schubert return rc;
1736*7f2fe78bSCy Schubert }
1737*7f2fe78bSCy Schubert
1738*7f2fe78bSCy Schubert DWORD
Leash_get_hide_kinit_options()1739*7f2fe78bSCy Schubert Leash_get_hide_kinit_options(
1740*7f2fe78bSCy Schubert )
1741*7f2fe78bSCy Schubert {
1742*7f2fe78bSCy Schubert HMODULE hmLeash;
1743*7f2fe78bSCy Schubert DWORD result;
1744*7f2fe78bSCy Schubert
1745*7f2fe78bSCy Schubert if (get_hide_kinit_options_from_registry(HKEY_CURRENT_USER, &result) ||
1746*7f2fe78bSCy Schubert get_hide_kinit_options_from_registry(HKEY_LOCAL_MACHINE, &result))
1747*7f2fe78bSCy Schubert {
1748*7f2fe78bSCy Schubert return result;
1749*7f2fe78bSCy Schubert }
1750*7f2fe78bSCy Schubert
1751*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1752*7f2fe78bSCy Schubert if (hmLeash)
1753*7f2fe78bSCy Schubert {
1754*7f2fe78bSCy Schubert char hide_kinit_options[80];
1755*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_DIALOG_KINIT_OPT,
1756*7f2fe78bSCy Schubert hide_kinit_options, sizeof(hide_kinit_options)))
1757*7f2fe78bSCy Schubert {
1758*7f2fe78bSCy Schubert hide_kinit_options[sizeof(hide_kinit_options) - 1] = 0;
1759*7f2fe78bSCy Schubert return atoi(hide_kinit_options);
1760*7f2fe78bSCy Schubert }
1761*7f2fe78bSCy Schubert }
1762*7f2fe78bSCy Schubert return 0; /* hide unless otherwise indicated */
1763*7f2fe78bSCy Schubert }
1764*7f2fe78bSCy Schubert
1765*7f2fe78bSCy Schubert
1766*7f2fe78bSCy Schubert
1767*7f2fe78bSCy Schubert static
1768*7f2fe78bSCy Schubert BOOL
get_default_life_min_from_registry(HKEY hBaseKey,DWORD * result)1769*7f2fe78bSCy Schubert get_default_life_min_from_registry(
1770*7f2fe78bSCy Schubert HKEY hBaseKey,
1771*7f2fe78bSCy Schubert DWORD * result
1772*7f2fe78bSCy Schubert )
1773*7f2fe78bSCy Schubert {
1774*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1775*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1776*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_LIFE_MIN,
1777*7f2fe78bSCy Schubert result);
1778*7f2fe78bSCy Schubert }
1779*7f2fe78bSCy Schubert
1780*7f2fe78bSCy Schubert DWORD
Leash_reset_default_life_min()1781*7f2fe78bSCy Schubert Leash_reset_default_life_min(
1782*7f2fe78bSCy Schubert )
1783*7f2fe78bSCy Schubert {
1784*7f2fe78bSCy Schubert HKEY hKey;
1785*7f2fe78bSCy Schubert LONG rc;
1786*7f2fe78bSCy Schubert
1787*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1788*7f2fe78bSCy Schubert if (rc)
1789*7f2fe78bSCy Schubert return rc;
1790*7f2fe78bSCy Schubert
1791*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_LIFE_MIN);
1792*7f2fe78bSCy Schubert RegCloseKey(hKey);
1793*7f2fe78bSCy Schubert
1794*7f2fe78bSCy Schubert return rc;
1795*7f2fe78bSCy Schubert }
1796*7f2fe78bSCy Schubert
1797*7f2fe78bSCy Schubert DWORD
Leash_set_default_life_min(DWORD minutes)1798*7f2fe78bSCy Schubert Leash_set_default_life_min(
1799*7f2fe78bSCy Schubert DWORD minutes
1800*7f2fe78bSCy Schubert )
1801*7f2fe78bSCy Schubert {
1802*7f2fe78bSCy Schubert HKEY hKey;
1803*7f2fe78bSCy Schubert LONG rc;
1804*7f2fe78bSCy Schubert
1805*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1806*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1807*7f2fe78bSCy Schubert if (rc)
1808*7f2fe78bSCy Schubert return rc;
1809*7f2fe78bSCy Schubert
1810*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_LIFE_MIN, 0, REG_DWORD,
1811*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1812*7f2fe78bSCy Schubert RegCloseKey(hKey);
1813*7f2fe78bSCy Schubert
1814*7f2fe78bSCy Schubert return rc;
1815*7f2fe78bSCy Schubert }
1816*7f2fe78bSCy Schubert
1817*7f2fe78bSCy Schubert DWORD
Leash_get_default_life_min()1818*7f2fe78bSCy Schubert Leash_get_default_life_min(
1819*7f2fe78bSCy Schubert )
1820*7f2fe78bSCy Schubert {
1821*7f2fe78bSCy Schubert HMODULE hmLeash;
1822*7f2fe78bSCy Schubert DWORD result;
1823*7f2fe78bSCy Schubert
1824*7f2fe78bSCy Schubert if (get_default_life_min_from_registry(HKEY_CURRENT_USER, &result) ||
1825*7f2fe78bSCy Schubert get_default_life_min_from_registry(HKEY_LOCAL_MACHINE, &result))
1826*7f2fe78bSCy Schubert {
1827*7f2fe78bSCy Schubert return result;
1828*7f2fe78bSCy Schubert }
1829*7f2fe78bSCy Schubert
1830*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1831*7f2fe78bSCy Schubert if (hmLeash)
1832*7f2fe78bSCy Schubert {
1833*7f2fe78bSCy Schubert char life_min[80];
1834*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_DIALOG_LIFE_MIN,
1835*7f2fe78bSCy Schubert life_min, sizeof(life_min)))
1836*7f2fe78bSCy Schubert {
1837*7f2fe78bSCy Schubert life_min[sizeof(life_min) - 1] = 0;
1838*7f2fe78bSCy Schubert return atoi(life_min);
1839*7f2fe78bSCy Schubert }
1840*7f2fe78bSCy Schubert }
1841*7f2fe78bSCy Schubert return 5; /* 5 minutes */
1842*7f2fe78bSCy Schubert }
1843*7f2fe78bSCy Schubert
1844*7f2fe78bSCy Schubert static
1845*7f2fe78bSCy Schubert BOOL
get_default_life_max_from_registry(HKEY hBaseKey,DWORD * result)1846*7f2fe78bSCy Schubert get_default_life_max_from_registry(
1847*7f2fe78bSCy Schubert HKEY hBaseKey,
1848*7f2fe78bSCy Schubert DWORD * result
1849*7f2fe78bSCy Schubert )
1850*7f2fe78bSCy Schubert {
1851*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1852*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1853*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_LIFE_MAX,
1854*7f2fe78bSCy Schubert result);
1855*7f2fe78bSCy Schubert }
1856*7f2fe78bSCy Schubert
1857*7f2fe78bSCy Schubert DWORD
Leash_reset_default_life_max()1858*7f2fe78bSCy Schubert Leash_reset_default_life_max(
1859*7f2fe78bSCy Schubert )
1860*7f2fe78bSCy Schubert {
1861*7f2fe78bSCy Schubert HKEY hKey;
1862*7f2fe78bSCy Schubert LONG rc;
1863*7f2fe78bSCy Schubert
1864*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1865*7f2fe78bSCy Schubert if (rc)
1866*7f2fe78bSCy Schubert return rc;
1867*7f2fe78bSCy Schubert
1868*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_LIFE_MAX);
1869*7f2fe78bSCy Schubert RegCloseKey(hKey);
1870*7f2fe78bSCy Schubert
1871*7f2fe78bSCy Schubert return rc;
1872*7f2fe78bSCy Schubert }
1873*7f2fe78bSCy Schubert
1874*7f2fe78bSCy Schubert DWORD
Leash_set_default_life_max(DWORD minutes)1875*7f2fe78bSCy Schubert Leash_set_default_life_max(
1876*7f2fe78bSCy Schubert DWORD minutes
1877*7f2fe78bSCy Schubert )
1878*7f2fe78bSCy Schubert {
1879*7f2fe78bSCy Schubert HKEY hKey;
1880*7f2fe78bSCy Schubert LONG rc;
1881*7f2fe78bSCy Schubert
1882*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1883*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1884*7f2fe78bSCy Schubert if (rc)
1885*7f2fe78bSCy Schubert return rc;
1886*7f2fe78bSCy Schubert
1887*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_LIFE_MAX, 0, REG_DWORD,
1888*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1889*7f2fe78bSCy Schubert RegCloseKey(hKey);
1890*7f2fe78bSCy Schubert
1891*7f2fe78bSCy Schubert return rc;
1892*7f2fe78bSCy Schubert }
1893*7f2fe78bSCy Schubert
1894*7f2fe78bSCy Schubert DWORD
Leash_get_default_life_max()1895*7f2fe78bSCy Schubert Leash_get_default_life_max(
1896*7f2fe78bSCy Schubert )
1897*7f2fe78bSCy Schubert {
1898*7f2fe78bSCy Schubert HMODULE hmLeash;
1899*7f2fe78bSCy Schubert DWORD result;
1900*7f2fe78bSCy Schubert
1901*7f2fe78bSCy Schubert if (get_default_life_max_from_registry(HKEY_CURRENT_USER, &result) ||
1902*7f2fe78bSCy Schubert get_default_life_max_from_registry(HKEY_LOCAL_MACHINE, &result))
1903*7f2fe78bSCy Schubert {
1904*7f2fe78bSCy Schubert return result;
1905*7f2fe78bSCy Schubert }
1906*7f2fe78bSCy Schubert
1907*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1908*7f2fe78bSCy Schubert if (hmLeash)
1909*7f2fe78bSCy Schubert {
1910*7f2fe78bSCy Schubert char life_max[80];
1911*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_DIALOG_LIFE_MAX,
1912*7f2fe78bSCy Schubert life_max, sizeof(life_max)))
1913*7f2fe78bSCy Schubert {
1914*7f2fe78bSCy Schubert life_max[sizeof(life_max) - 1] = 0;
1915*7f2fe78bSCy Schubert return atoi(life_max);
1916*7f2fe78bSCy Schubert }
1917*7f2fe78bSCy Schubert }
1918*7f2fe78bSCy Schubert return 1440;
1919*7f2fe78bSCy Schubert }
1920*7f2fe78bSCy Schubert
1921*7f2fe78bSCy Schubert static
1922*7f2fe78bSCy Schubert BOOL
get_default_renew_min_from_registry(HKEY hBaseKey,DWORD * result)1923*7f2fe78bSCy Schubert get_default_renew_min_from_registry(
1924*7f2fe78bSCy Schubert HKEY hBaseKey,
1925*7f2fe78bSCy Schubert DWORD * result
1926*7f2fe78bSCy Schubert )
1927*7f2fe78bSCy Schubert {
1928*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
1929*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
1930*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_RENEW_MIN,
1931*7f2fe78bSCy Schubert result);
1932*7f2fe78bSCy Schubert }
1933*7f2fe78bSCy Schubert
1934*7f2fe78bSCy Schubert DWORD
Leash_reset_default_renew_min()1935*7f2fe78bSCy Schubert Leash_reset_default_renew_min(
1936*7f2fe78bSCy Schubert )
1937*7f2fe78bSCy Schubert {
1938*7f2fe78bSCy Schubert HKEY hKey;
1939*7f2fe78bSCy Schubert LONG rc;
1940*7f2fe78bSCy Schubert
1941*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
1942*7f2fe78bSCy Schubert if (rc)
1943*7f2fe78bSCy Schubert return rc;
1944*7f2fe78bSCy Schubert
1945*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_RENEW_MIN);
1946*7f2fe78bSCy Schubert RegCloseKey(hKey);
1947*7f2fe78bSCy Schubert
1948*7f2fe78bSCy Schubert return rc;
1949*7f2fe78bSCy Schubert }
1950*7f2fe78bSCy Schubert
1951*7f2fe78bSCy Schubert DWORD
Leash_set_default_renew_min(DWORD minutes)1952*7f2fe78bSCy Schubert Leash_set_default_renew_min(
1953*7f2fe78bSCy Schubert DWORD minutes
1954*7f2fe78bSCy Schubert )
1955*7f2fe78bSCy Schubert {
1956*7f2fe78bSCy Schubert HKEY hKey;
1957*7f2fe78bSCy Schubert LONG rc;
1958*7f2fe78bSCy Schubert
1959*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
1960*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
1961*7f2fe78bSCy Schubert if (rc)
1962*7f2fe78bSCy Schubert return rc;
1963*7f2fe78bSCy Schubert
1964*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_RENEW_MIN, 0, REG_DWORD,
1965*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
1966*7f2fe78bSCy Schubert RegCloseKey(hKey);
1967*7f2fe78bSCy Schubert
1968*7f2fe78bSCy Schubert return rc;
1969*7f2fe78bSCy Schubert }
1970*7f2fe78bSCy Schubert
1971*7f2fe78bSCy Schubert DWORD
Leash_get_default_renew_min()1972*7f2fe78bSCy Schubert Leash_get_default_renew_min(
1973*7f2fe78bSCy Schubert )
1974*7f2fe78bSCy Schubert {
1975*7f2fe78bSCy Schubert HMODULE hmLeash;
1976*7f2fe78bSCy Schubert DWORD result;
1977*7f2fe78bSCy Schubert
1978*7f2fe78bSCy Schubert if (get_default_renew_min_from_registry(HKEY_CURRENT_USER, &result) ||
1979*7f2fe78bSCy Schubert get_default_renew_min_from_registry(HKEY_LOCAL_MACHINE, &result))
1980*7f2fe78bSCy Schubert {
1981*7f2fe78bSCy Schubert return result;
1982*7f2fe78bSCy Schubert }
1983*7f2fe78bSCy Schubert
1984*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
1985*7f2fe78bSCy Schubert if (hmLeash)
1986*7f2fe78bSCy Schubert {
1987*7f2fe78bSCy Schubert char renew_min[80];
1988*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_DIALOG_RENEW_MIN,
1989*7f2fe78bSCy Schubert renew_min, sizeof(renew_min)))
1990*7f2fe78bSCy Schubert {
1991*7f2fe78bSCy Schubert renew_min[sizeof(renew_min) - 1] = 0;
1992*7f2fe78bSCy Schubert return atoi(renew_min);
1993*7f2fe78bSCy Schubert }
1994*7f2fe78bSCy Schubert }
1995*7f2fe78bSCy Schubert return 600; /* 10 hours */
1996*7f2fe78bSCy Schubert }
1997*7f2fe78bSCy Schubert
1998*7f2fe78bSCy Schubert static
1999*7f2fe78bSCy Schubert BOOL
get_default_renew_max_from_registry(HKEY hBaseKey,DWORD * result)2000*7f2fe78bSCy Schubert get_default_renew_max_from_registry(
2001*7f2fe78bSCy Schubert HKEY hBaseKey,
2002*7f2fe78bSCy Schubert DWORD * result
2003*7f2fe78bSCy Schubert )
2004*7f2fe78bSCy Schubert {
2005*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
2006*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
2007*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_RENEW_MAX,
2008*7f2fe78bSCy Schubert result);
2009*7f2fe78bSCy Schubert }
2010*7f2fe78bSCy Schubert
2011*7f2fe78bSCy Schubert DWORD
Leash_reset_default_renew_max()2012*7f2fe78bSCy Schubert Leash_reset_default_renew_max(
2013*7f2fe78bSCy Schubert )
2014*7f2fe78bSCy Schubert {
2015*7f2fe78bSCy Schubert HKEY hKey;
2016*7f2fe78bSCy Schubert LONG rc;
2017*7f2fe78bSCy Schubert
2018*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
2019*7f2fe78bSCy Schubert if (rc)
2020*7f2fe78bSCy Schubert return rc;
2021*7f2fe78bSCy Schubert
2022*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_RENEW_MAX);
2023*7f2fe78bSCy Schubert RegCloseKey(hKey);
2024*7f2fe78bSCy Schubert
2025*7f2fe78bSCy Schubert return rc;
2026*7f2fe78bSCy Schubert }
2027*7f2fe78bSCy Schubert
2028*7f2fe78bSCy Schubert DWORD
Leash_set_default_renew_max(DWORD minutes)2029*7f2fe78bSCy Schubert Leash_set_default_renew_max(
2030*7f2fe78bSCy Schubert DWORD minutes
2031*7f2fe78bSCy Schubert )
2032*7f2fe78bSCy Schubert {
2033*7f2fe78bSCy Schubert HKEY hKey;
2034*7f2fe78bSCy Schubert LONG rc;
2035*7f2fe78bSCy Schubert
2036*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
2037*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
2038*7f2fe78bSCy Schubert if (rc)
2039*7f2fe78bSCy Schubert return rc;
2040*7f2fe78bSCy Schubert
2041*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_RENEW_MAX, 0, REG_DWORD,
2042*7f2fe78bSCy Schubert (LPBYTE) &minutes, sizeof(DWORD));
2043*7f2fe78bSCy Schubert RegCloseKey(hKey);
2044*7f2fe78bSCy Schubert
2045*7f2fe78bSCy Schubert return rc;
2046*7f2fe78bSCy Schubert }
2047*7f2fe78bSCy Schubert
2048*7f2fe78bSCy Schubert DWORD
Leash_get_default_renew_max()2049*7f2fe78bSCy Schubert Leash_get_default_renew_max(
2050*7f2fe78bSCy Schubert )
2051*7f2fe78bSCy Schubert {
2052*7f2fe78bSCy Schubert HMODULE hmLeash;
2053*7f2fe78bSCy Schubert DWORD result;
2054*7f2fe78bSCy Schubert
2055*7f2fe78bSCy Schubert if (get_default_renew_max_from_registry(HKEY_CURRENT_USER, &result) ||
2056*7f2fe78bSCy Schubert get_default_renew_max_from_registry(HKEY_LOCAL_MACHINE, &result))
2057*7f2fe78bSCy Schubert {
2058*7f2fe78bSCy Schubert return result;
2059*7f2fe78bSCy Schubert }
2060*7f2fe78bSCy Schubert
2061*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
2062*7f2fe78bSCy Schubert if (hmLeash)
2063*7f2fe78bSCy Schubert {
2064*7f2fe78bSCy Schubert char renew_max[80];
2065*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_DIALOG_RENEW_MAX,
2066*7f2fe78bSCy Schubert renew_max, sizeof(renew_max)))
2067*7f2fe78bSCy Schubert {
2068*7f2fe78bSCy Schubert renew_max[sizeof(renew_max) - 1] = 0;
2069*7f2fe78bSCy Schubert return atoi(renew_max);
2070*7f2fe78bSCy Schubert }
2071*7f2fe78bSCy Schubert }
2072*7f2fe78bSCy Schubert return 60 * 24 * 30;
2073*7f2fe78bSCy Schubert }
2074*7f2fe78bSCy Schubert
2075*7f2fe78bSCy Schubert static
2076*7f2fe78bSCy Schubert BOOL
get_default_uppercaserealm_from_registry(HKEY hBaseKey,DWORD * result)2077*7f2fe78bSCy Schubert get_default_uppercaserealm_from_registry(
2078*7f2fe78bSCy Schubert HKEY hBaseKey,
2079*7f2fe78bSCy Schubert DWORD * result
2080*7f2fe78bSCy Schubert )
2081*7f2fe78bSCy Schubert {
2082*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
2083*7f2fe78bSCy Schubert LEASH_SETTINGS_REGISTRY_KEY_NAME,
2084*7f2fe78bSCy Schubert LEASH_SETTINGS_REGISTRY_VALUE_UPPERCASEREALM,
2085*7f2fe78bSCy Schubert result);
2086*7f2fe78bSCy Schubert }
2087*7f2fe78bSCy Schubert
2088*7f2fe78bSCy Schubert DWORD
Leash_reset_default_uppercaserealm()2089*7f2fe78bSCy Schubert Leash_reset_default_uppercaserealm(
2090*7f2fe78bSCy Schubert )
2091*7f2fe78bSCy Schubert {
2092*7f2fe78bSCy Schubert HKEY hKey;
2093*7f2fe78bSCy Schubert LONG rc;
2094*7f2fe78bSCy Schubert
2095*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_SETTINGS_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
2096*7f2fe78bSCy Schubert if (rc)
2097*7f2fe78bSCy Schubert return rc;
2098*7f2fe78bSCy Schubert
2099*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_SETTINGS_REGISTRY_VALUE_UPPERCASEREALM);
2100*7f2fe78bSCy Schubert RegCloseKey(hKey);
2101*7f2fe78bSCy Schubert
2102*7f2fe78bSCy Schubert return rc;
2103*7f2fe78bSCy Schubert }
2104*7f2fe78bSCy Schubert
2105*7f2fe78bSCy Schubert DWORD
Leash_set_default_uppercaserealm(DWORD onoff)2106*7f2fe78bSCy Schubert Leash_set_default_uppercaserealm(
2107*7f2fe78bSCy Schubert DWORD onoff
2108*7f2fe78bSCy Schubert )
2109*7f2fe78bSCy Schubert {
2110*7f2fe78bSCy Schubert HKEY hKey;
2111*7f2fe78bSCy Schubert LONG rc;
2112*7f2fe78bSCy Schubert
2113*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_SETTINGS_REGISTRY_KEY_NAME, 0,
2114*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
2115*7f2fe78bSCy Schubert if (rc)
2116*7f2fe78bSCy Schubert return rc;
2117*7f2fe78bSCy Schubert
2118*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_SETTINGS_REGISTRY_VALUE_UPPERCASEREALM, 0, REG_DWORD,
2119*7f2fe78bSCy Schubert (LPBYTE) &onoff, sizeof(DWORD));
2120*7f2fe78bSCy Schubert RegCloseKey(hKey);
2121*7f2fe78bSCy Schubert
2122*7f2fe78bSCy Schubert return rc;
2123*7f2fe78bSCy Schubert }
2124*7f2fe78bSCy Schubert
2125*7f2fe78bSCy Schubert DWORD
Leash_get_default_uppercaserealm()2126*7f2fe78bSCy Schubert Leash_get_default_uppercaserealm(
2127*7f2fe78bSCy Schubert )
2128*7f2fe78bSCy Schubert {
2129*7f2fe78bSCy Schubert HMODULE hmLeash;
2130*7f2fe78bSCy Schubert DWORD result;
2131*7f2fe78bSCy Schubert
2132*7f2fe78bSCy Schubert if (get_default_uppercaserealm_from_registry(HKEY_CURRENT_USER, &result) ||
2133*7f2fe78bSCy Schubert get_default_uppercaserealm_from_registry(HKEY_LOCAL_MACHINE, &result))
2134*7f2fe78bSCy Schubert {
2135*7f2fe78bSCy Schubert return result;
2136*7f2fe78bSCy Schubert }
2137*7f2fe78bSCy Schubert
2138*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
2139*7f2fe78bSCy Schubert if (hmLeash)
2140*7f2fe78bSCy Schubert {
2141*7f2fe78bSCy Schubert char uppercaserealm[80];
2142*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_UPPERCASEREALM,
2143*7f2fe78bSCy Schubert uppercaserealm, sizeof(uppercaserealm)))
2144*7f2fe78bSCy Schubert {
2145*7f2fe78bSCy Schubert uppercaserealm[sizeof(uppercaserealm) - 1] = 0;
2146*7f2fe78bSCy Schubert return atoi(uppercaserealm);
2147*7f2fe78bSCy Schubert }
2148*7f2fe78bSCy Schubert }
2149*7f2fe78bSCy Schubert return 1;
2150*7f2fe78bSCy Schubert }
2151*7f2fe78bSCy Schubert
2152*7f2fe78bSCy Schubert DWORD
Leash_reset_default_mslsa_import()2153*7f2fe78bSCy Schubert Leash_reset_default_mslsa_import(
2154*7f2fe78bSCy Schubert )
2155*7f2fe78bSCy Schubert {
2156*7f2fe78bSCy Schubert return ERROR_INVALID_FUNCTION;
2157*7f2fe78bSCy Schubert }
2158*7f2fe78bSCy Schubert
2159*7f2fe78bSCy Schubert DWORD
Leash_set_default_mslsa_import(DWORD onoffmatch)2160*7f2fe78bSCy Schubert Leash_set_default_mslsa_import(
2161*7f2fe78bSCy Schubert DWORD onoffmatch
2162*7f2fe78bSCy Schubert )
2163*7f2fe78bSCy Schubert {
2164*7f2fe78bSCy Schubert return ERROR_INVALID_FUNCTION;
2165*7f2fe78bSCy Schubert }
2166*7f2fe78bSCy Schubert
2167*7f2fe78bSCy Schubert DWORD
Leash_get_default_mslsa_import()2168*7f2fe78bSCy Schubert Leash_get_default_mslsa_import(
2169*7f2fe78bSCy Schubert )
2170*7f2fe78bSCy Schubert {
2171*7f2fe78bSCy Schubert return 0;
2172*7f2fe78bSCy Schubert }
2173*7f2fe78bSCy Schubert
2174*7f2fe78bSCy Schubert
2175*7f2fe78bSCy Schubert static
2176*7f2fe78bSCy Schubert BOOL
get_default_preserve_kinit_settings_from_registry(HKEY hBaseKey,DWORD * result)2177*7f2fe78bSCy Schubert get_default_preserve_kinit_settings_from_registry(
2178*7f2fe78bSCy Schubert HKEY hBaseKey,
2179*7f2fe78bSCy Schubert DWORD * result
2180*7f2fe78bSCy Schubert )
2181*7f2fe78bSCy Schubert {
2182*7f2fe78bSCy Schubert return get_DWORD_from_registry(hBaseKey,
2183*7f2fe78bSCy Schubert LEASH_REGISTRY_KEY_NAME,
2184*7f2fe78bSCy Schubert LEASH_REGISTRY_VALUE_PRESERVE_KINIT,
2185*7f2fe78bSCy Schubert result);
2186*7f2fe78bSCy Schubert }
2187*7f2fe78bSCy Schubert
2188*7f2fe78bSCy Schubert DWORD
Leash_reset_default_preserve_kinit_settings()2189*7f2fe78bSCy Schubert Leash_reset_default_preserve_kinit_settings(
2190*7f2fe78bSCy Schubert )
2191*7f2fe78bSCy Schubert {
2192*7f2fe78bSCy Schubert HKEY hKey;
2193*7f2fe78bSCy Schubert LONG rc;
2194*7f2fe78bSCy Schubert
2195*7f2fe78bSCy Schubert rc = RegOpenKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0, KEY_WRITE, &hKey);
2196*7f2fe78bSCy Schubert if (rc)
2197*7f2fe78bSCy Schubert return rc;
2198*7f2fe78bSCy Schubert
2199*7f2fe78bSCy Schubert rc = RegDeleteValue(hKey, LEASH_REGISTRY_VALUE_PRESERVE_KINIT);
2200*7f2fe78bSCy Schubert RegCloseKey(hKey);
2201*7f2fe78bSCy Schubert
2202*7f2fe78bSCy Schubert return rc;
2203*7f2fe78bSCy Schubert }
2204*7f2fe78bSCy Schubert
2205*7f2fe78bSCy Schubert DWORD
Leash_set_default_preserve_kinit_settings(DWORD onoff)2206*7f2fe78bSCy Schubert Leash_set_default_preserve_kinit_settings(
2207*7f2fe78bSCy Schubert DWORD onoff
2208*7f2fe78bSCy Schubert )
2209*7f2fe78bSCy Schubert {
2210*7f2fe78bSCy Schubert HKEY hKey;
2211*7f2fe78bSCy Schubert LONG rc;
2212*7f2fe78bSCy Schubert
2213*7f2fe78bSCy Schubert rc = RegCreateKeyEx(HKEY_CURRENT_USER, LEASH_REGISTRY_KEY_NAME, 0,
2214*7f2fe78bSCy Schubert 0, 0, KEY_WRITE, 0, &hKey, 0);
2215*7f2fe78bSCy Schubert if (rc)
2216*7f2fe78bSCy Schubert return rc;
2217*7f2fe78bSCy Schubert
2218*7f2fe78bSCy Schubert rc = RegSetValueEx(hKey, LEASH_REGISTRY_VALUE_PRESERVE_KINIT, 0, REG_DWORD,
2219*7f2fe78bSCy Schubert (LPBYTE) &onoff, sizeof(DWORD));
2220*7f2fe78bSCy Schubert RegCloseKey(hKey);
2221*7f2fe78bSCy Schubert
2222*7f2fe78bSCy Schubert return rc;
2223*7f2fe78bSCy Schubert }
2224*7f2fe78bSCy Schubert
2225*7f2fe78bSCy Schubert DWORD
Leash_get_default_preserve_kinit_settings()2226*7f2fe78bSCy Schubert Leash_get_default_preserve_kinit_settings(
2227*7f2fe78bSCy Schubert )
2228*7f2fe78bSCy Schubert {
2229*7f2fe78bSCy Schubert HMODULE hmLeash;
2230*7f2fe78bSCy Schubert DWORD result;
2231*7f2fe78bSCy Schubert
2232*7f2fe78bSCy Schubert if (get_default_preserve_kinit_settings_from_registry(HKEY_CURRENT_USER, &result) ||
2233*7f2fe78bSCy Schubert get_default_preserve_kinit_settings_from_registry(HKEY_LOCAL_MACHINE, &result))
2234*7f2fe78bSCy Schubert {
2235*7f2fe78bSCy Schubert return result;
2236*7f2fe78bSCy Schubert }
2237*7f2fe78bSCy Schubert
2238*7f2fe78bSCy Schubert hmLeash = GetModuleHandle(LEASH_DLL);
2239*7f2fe78bSCy Schubert if (hmLeash)
2240*7f2fe78bSCy Schubert {
2241*7f2fe78bSCy Schubert char preserve_kinit_settings[80];
2242*7f2fe78bSCy Schubert if (LoadString(hmLeash, LSH_DEFAULT_PRESERVE_KINIT,
2243*7f2fe78bSCy Schubert preserve_kinit_settings, sizeof(preserve_kinit_settings)))
2244*7f2fe78bSCy Schubert {
2245*7f2fe78bSCy Schubert preserve_kinit_settings[sizeof(preserve_kinit_settings) - 1] = 0;
2246*7f2fe78bSCy Schubert return atoi(preserve_kinit_settings);
2247*7f2fe78bSCy Schubert }
2248*7f2fe78bSCy Schubert }
2249*7f2fe78bSCy Schubert return 1;
2250*7f2fe78bSCy Schubert }
2251*7f2fe78bSCy Schubert
2252*7f2fe78bSCy Schubert void
Leash_reset_defaults(void)2253*7f2fe78bSCy Schubert Leash_reset_defaults(void)
2254*7f2fe78bSCy Schubert {
2255*7f2fe78bSCy Schubert Leash_reset_default_lifetime();
2256*7f2fe78bSCy Schubert Leash_reset_default_renew_till();
2257*7f2fe78bSCy Schubert Leash_reset_default_renewable();
2258*7f2fe78bSCy Schubert Leash_reset_default_forwardable();
2259*7f2fe78bSCy Schubert Leash_reset_default_noaddresses();
2260*7f2fe78bSCy Schubert Leash_reset_default_proxiable();
2261*7f2fe78bSCy Schubert Leash_reset_default_publicip();
2262*7f2fe78bSCy Schubert Leash_reset_hide_kinit_options();
2263*7f2fe78bSCy Schubert Leash_reset_default_life_min();
2264*7f2fe78bSCy Schubert Leash_reset_default_life_max();
2265*7f2fe78bSCy Schubert Leash_reset_default_renew_min();
2266*7f2fe78bSCy Schubert Leash_reset_default_renew_max();
2267*7f2fe78bSCy Schubert Leash_reset_default_uppercaserealm();
2268*7f2fe78bSCy Schubert Leash_reset_default_preserve_kinit_settings();
2269*7f2fe78bSCy Schubert }
2270*7f2fe78bSCy Schubert
2271*7f2fe78bSCy Schubert static void
acquire_tkt_send_msg_leash(const char * title,const char * ccachename,const char * name,const char * realm)2272*7f2fe78bSCy Schubert acquire_tkt_send_msg_leash(const char *title,
2273*7f2fe78bSCy Schubert const char *ccachename,
2274*7f2fe78bSCy Schubert const char *name,
2275*7f2fe78bSCy Schubert const char *realm)
2276*7f2fe78bSCy Schubert {
2277*7f2fe78bSCy Schubert DWORD leashProcessId = 0;
2278*7f2fe78bSCy Schubert DWORD bufsize = 4096;
2279*7f2fe78bSCy Schubert DWORD step;
2280*7f2fe78bSCy Schubert HANDLE hLeashProcess = NULL;
2281*7f2fe78bSCy Schubert HANDLE hMapFile = NULL;
2282*7f2fe78bSCy Schubert HANDLE hTarget = NULL;
2283*7f2fe78bSCy Schubert HWND hLeashWnd = FindWindow("LEASH.0WNDCLASS", NULL);
2284*7f2fe78bSCy Schubert char *strs;
2285*7f2fe78bSCy Schubert void *view;
2286*7f2fe78bSCy Schubert if (!hLeashWnd)
2287*7f2fe78bSCy Schubert // no leash window
2288*7f2fe78bSCy Schubert return;
2289*7f2fe78bSCy Schubert
2290*7f2fe78bSCy Schubert GetWindowThreadProcessId(hLeashWnd, &leashProcessId);
2291*7f2fe78bSCy Schubert hLeashProcess = OpenProcess(PROCESS_DUP_HANDLE,
2292*7f2fe78bSCy Schubert FALSE,
2293*7f2fe78bSCy Schubert leashProcessId);
2294*7f2fe78bSCy Schubert if (!hLeashProcess)
2295*7f2fe78bSCy Schubert // can't get process handle; use GetLastError() for more info
2296*7f2fe78bSCy Schubert return;
2297*7f2fe78bSCy Schubert
2298*7f2fe78bSCy Schubert hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file
2299*7f2fe78bSCy Schubert NULL, // default security
2300*7f2fe78bSCy Schubert PAGE_READWRITE, // read/write access
2301*7f2fe78bSCy Schubert 0, // max size (high 32)
2302*7f2fe78bSCy Schubert bufsize, // max size (low 32)
2303*7f2fe78bSCy Schubert NULL); // name
2304*7f2fe78bSCy Schubert if (!hMapFile) {
2305*7f2fe78bSCy Schubert // GetLastError() for more info
2306*7f2fe78bSCy Schubert CloseHandle(hLeashProcess);
2307*7f2fe78bSCy Schubert return;
2308*7f2fe78bSCy Schubert }
2309*7f2fe78bSCy Schubert
2310*7f2fe78bSCy Schubert SetForegroundWindow(hLeashWnd);
2311*7f2fe78bSCy Schubert
2312*7f2fe78bSCy Schubert view = MapViewOfFile(hMapFile,
2313*7f2fe78bSCy Schubert FILE_MAP_ALL_ACCESS,
2314*7f2fe78bSCy Schubert 0,
2315*7f2fe78bSCy Schubert 0,
2316*7f2fe78bSCy Schubert bufsize);
2317*7f2fe78bSCy Schubert if (view != NULL) {
2318*7f2fe78bSCy Schubert /* construct a marshalling of data
2319*7f2fe78bSCy Schubert * <title><principal><realm><ccache>
2320*7f2fe78bSCy Schubert * then send to Leash
2321*7f2fe78bSCy Schubert */
2322*7f2fe78bSCy Schubert strs = (char *)view;
2323*7f2fe78bSCy Schubert // first reserve space for three more NULLs (4 strings total)
2324*7f2fe78bSCy Schubert bufsize -= 3;
2325*7f2fe78bSCy Schubert // Dialog title
2326*7f2fe78bSCy Schubert if (title != NULL)
2327*7f2fe78bSCy Schubert strcpy_s(strs, bufsize, title);
2328*7f2fe78bSCy Schubert else if (name != NULL && realm != NULL)
2329*7f2fe78bSCy Schubert sprintf_s(strs, bufsize,
2330*7f2fe78bSCy Schubert "MIT Kerberos: Get Ticket for %s@%s", name, realm);
2331*7f2fe78bSCy Schubert else
2332*7f2fe78bSCy Schubert strcpy_s(strs, bufsize, "MIT Kerberos: Get Ticket");
2333*7f2fe78bSCy Schubert step = strlen(strs);
2334*7f2fe78bSCy Schubert strs += step + 1;
2335*7f2fe78bSCy Schubert bufsize -= step;
2336*7f2fe78bSCy Schubert // name and realm
2337*7f2fe78bSCy Schubert if (name != NULL) {
2338*7f2fe78bSCy Schubert strcpy_s(strs, bufsize, name);
2339*7f2fe78bSCy Schubert step = strlen(strs);
2340*7f2fe78bSCy Schubert strs += step + 1;
2341*7f2fe78bSCy Schubert bufsize -= step;
2342*7f2fe78bSCy Schubert if (realm != NULL) {
2343*7f2fe78bSCy Schubert strcpy_s(strs, bufsize, realm);
2344*7f2fe78bSCy Schubert step = strlen(strs);
2345*7f2fe78bSCy Schubert strs += step + 1;
2346*7f2fe78bSCy Schubert bufsize -= step;
2347*7f2fe78bSCy Schubert } else {
2348*7f2fe78bSCy Schubert *strs = 0;
2349*7f2fe78bSCy Schubert strs++;
2350*7f2fe78bSCy Schubert }
2351*7f2fe78bSCy Schubert } else {
2352*7f2fe78bSCy Schubert *strs = 0;
2353*7f2fe78bSCy Schubert strs++;
2354*7f2fe78bSCy Schubert *strs = 0;
2355*7f2fe78bSCy Schubert strs++;
2356*7f2fe78bSCy Schubert }
2357*7f2fe78bSCy Schubert
2358*7f2fe78bSCy Schubert /* Append the ccache name */
2359*7f2fe78bSCy Schubert if (ccachename != NULL)
2360*7f2fe78bSCy Schubert strcpy_s(strs, bufsize, ccachename);
2361*7f2fe78bSCy Schubert else
2362*7f2fe78bSCy Schubert *strs = 0;
2363*7f2fe78bSCy Schubert
2364*7f2fe78bSCy Schubert UnmapViewOfFile(view);
2365*7f2fe78bSCy Schubert }
2366*7f2fe78bSCy Schubert // Duplicate the file mapping handle to one leash can use
2367*7f2fe78bSCy Schubert if (DuplicateHandle(GetCurrentProcess(),
2368*7f2fe78bSCy Schubert hMapFile,
2369*7f2fe78bSCy Schubert hLeashProcess,
2370*7f2fe78bSCy Schubert &hTarget,
2371*7f2fe78bSCy Schubert PAGE_READWRITE,
2372*7f2fe78bSCy Schubert FALSE,
2373*7f2fe78bSCy Schubert DUPLICATE_SAME_ACCESS |
2374*7f2fe78bSCy Schubert DUPLICATE_CLOSE_SOURCE)) {
2375*7f2fe78bSCy Schubert /* 32809 = ID_OBTAIN_TGT_WITH_LPARAM in src/windows/leash/resource.h */
2376*7f2fe78bSCy Schubert SendMessage(hLeashWnd, 32809, 0, (LPARAM) hTarget);
2377*7f2fe78bSCy Schubert } else {
2378*7f2fe78bSCy Schubert // GetLastError()
2379*7f2fe78bSCy Schubert }
2380*7f2fe78bSCy Schubert }
2381*7f2fe78bSCy Schubert
2382*7f2fe78bSCy Schubert static int
acquire_tkt_send_msg(krb5_context ctx,const char * title,const char * ccachename,krb5_principal desiredKrb5Principal,char * out_ccname,int out_cclen)2383*7f2fe78bSCy Schubert acquire_tkt_send_msg(krb5_context ctx, const char * title,
2384*7f2fe78bSCy Schubert const char * ccachename,
2385*7f2fe78bSCy Schubert krb5_principal desiredKrb5Principal,
2386*7f2fe78bSCy Schubert char * out_ccname, int out_cclen)
2387*7f2fe78bSCy Schubert {
2388*7f2fe78bSCy Schubert krb5_error_code err;
2389*7f2fe78bSCy Schubert HWND hNetIdMgr;
2390*7f2fe78bSCy Schubert HWND hForeground;
2391*7f2fe78bSCy Schubert char *desiredName = 0;
2392*7f2fe78bSCy Schubert char *desiredRealm = 0;
2393*7f2fe78bSCy Schubert
2394*7f2fe78bSCy Schubert /* do we want a specific client principal? */
2395*7f2fe78bSCy Schubert if (desiredKrb5Principal != NULL) {
2396*7f2fe78bSCy Schubert err = pkrb5_unparse_name (ctx, desiredKrb5Principal, &desiredName);
2397*7f2fe78bSCy Schubert if (!err) {
2398*7f2fe78bSCy Schubert char * p;
2399*7f2fe78bSCy Schubert for (p = desiredName; *p && *p != '@'; p++);
2400*7f2fe78bSCy Schubert if ( *p == '@' ) {
2401*7f2fe78bSCy Schubert *p = '\0';
2402*7f2fe78bSCy Schubert desiredRealm = ++p;
2403*7f2fe78bSCy Schubert }
2404*7f2fe78bSCy Schubert }
2405*7f2fe78bSCy Schubert }
2406*7f2fe78bSCy Schubert
2407*7f2fe78bSCy Schubert hForeground = GetForegroundWindow();
2408*7f2fe78bSCy Schubert hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");
2409*7f2fe78bSCy Schubert if (hNetIdMgr != NULL) {
2410*7f2fe78bSCy Schubert HANDLE hMap;
2411*7f2fe78bSCy Schubert DWORD tid = GetCurrentThreadId();
2412*7f2fe78bSCy Schubert char mapname[256];
2413*7f2fe78bSCy Schubert NETID_DLGINFO *dlginfo;
2414*7f2fe78bSCy Schubert
2415*7f2fe78bSCy Schubert sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);
2416*7f2fe78bSCy Schubert
2417*7f2fe78bSCy Schubert hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
2418*7f2fe78bSCy Schubert 0, 4096, mapname);
2419*7f2fe78bSCy Schubert if (hMap == NULL) {
2420*7f2fe78bSCy Schubert return -1;
2421*7f2fe78bSCy Schubert } else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
2422*7f2fe78bSCy Schubert CloseHandle(hMap);
2423*7f2fe78bSCy Schubert return -1;
2424*7f2fe78bSCy Schubert }
2425*7f2fe78bSCy Schubert
2426*7f2fe78bSCy Schubert dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,
2427*7f2fe78bSCy Schubert 0, 0, 4096, NULL);
2428*7f2fe78bSCy Schubert if (dlginfo == NULL) {
2429*7f2fe78bSCy Schubert CloseHandle(hMap);
2430*7f2fe78bSCy Schubert return -1;
2431*7f2fe78bSCy Schubert }
2432*7f2fe78bSCy Schubert
2433*7f2fe78bSCy Schubert memset(dlginfo, 0, sizeof(NETID_DLGINFO));
2434*7f2fe78bSCy Schubert
2435*7f2fe78bSCy Schubert dlginfo->size = sizeof(NETID_DLGINFO);
2436*7f2fe78bSCy Schubert dlginfo->dlgtype = NETID_DLGTYPE_TGT;
2437*7f2fe78bSCy Schubert dlginfo->in.use_defaults = 1;
2438*7f2fe78bSCy Schubert
2439*7f2fe78bSCy Schubert if (title) {
2440*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
2441*7f2fe78bSCy Schubert title, -1,
2442*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
2443*7f2fe78bSCy Schubert } else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {
2444*7f2fe78bSCy Schubert char mytitle[NETID_TITLE_SZ];
2445*7f2fe78bSCy Schubert sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);
2446*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
2447*7f2fe78bSCy Schubert mytitle, -1,
2448*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
2449*7f2fe78bSCy Schubert } else {
2450*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
2451*7f2fe78bSCy Schubert "Obtain Kerberos TGT", -1,
2452*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
2453*7f2fe78bSCy Schubert }
2454*7f2fe78bSCy Schubert if (desiredName)
2455*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
2456*7f2fe78bSCy Schubert desiredName, -1,
2457*7f2fe78bSCy Schubert dlginfo->in.username, NETID_USERNAME_SZ);
2458*7f2fe78bSCy Schubert if (desiredRealm)
2459*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
2460*7f2fe78bSCy Schubert desiredRealm, -1,
2461*7f2fe78bSCy Schubert dlginfo->in.realm, NETID_REALM_SZ);
2462*7f2fe78bSCy Schubert if (ccachename)
2463*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
2464*7f2fe78bSCy Schubert ccachename, -1,
2465*7f2fe78bSCy Schubert dlginfo->in.ccache, NETID_CCACHE_NAME_SZ);
2466*7f2fe78bSCy Schubert SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);
2467*7f2fe78bSCy Schubert
2468*7f2fe78bSCy Schubert if (out_ccname && out_cclen > 0) {
2469*7f2fe78bSCy Schubert WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, dlginfo->out.ccache, -1,
2470*7f2fe78bSCy Schubert out_ccname, out_cclen, NULL, NULL);
2471*7f2fe78bSCy Schubert }
2472*7f2fe78bSCy Schubert
2473*7f2fe78bSCy Schubert UnmapViewOfFile(dlginfo);
2474*7f2fe78bSCy Schubert CloseHandle(hMap);
2475*7f2fe78bSCy Schubert } else {
2476*7f2fe78bSCy Schubert acquire_tkt_send_msg_leash(title,
2477*7f2fe78bSCy Schubert ccachename, desiredName, desiredRealm);
2478*7f2fe78bSCy Schubert }
2479*7f2fe78bSCy Schubert
2480*7f2fe78bSCy Schubert SetForegroundWindow(hForeground);
2481*7f2fe78bSCy Schubert if (desiredName != NULL)
2482*7f2fe78bSCy Schubert pkrb5_free_unparsed_name(ctx, desiredName);
2483*7f2fe78bSCy Schubert
2484*7f2fe78bSCy Schubert return 0;
2485*7f2fe78bSCy Schubert }
2486*7f2fe78bSCy Schubert
cc_have_tickets(krb5_context ctx,krb5_ccache cache)2487*7f2fe78bSCy Schubert static BOOL cc_have_tickets(krb5_context ctx, krb5_ccache cache)
2488*7f2fe78bSCy Schubert {
2489*7f2fe78bSCy Schubert krb5_cc_cursor cur = NULL;
2490*7f2fe78bSCy Schubert krb5_creds creds;
2491*7f2fe78bSCy Schubert krb5_flags flags;
2492*7f2fe78bSCy Schubert krb5_error_code code;
2493*7f2fe78bSCy Schubert BOOL have_tickets = FALSE;
2494*7f2fe78bSCy Schubert
2495*7f2fe78bSCy Schubert // Don't need the actual ticket.
2496*7f2fe78bSCy Schubert flags = KRB5_TC_NOTICKET;
2497*7f2fe78bSCy Schubert code = pkrb5_cc_set_flags(ctx, cache, flags);
2498*7f2fe78bSCy Schubert if (code)
2499*7f2fe78bSCy Schubert goto cleanup;
2500*7f2fe78bSCy Schubert code = pkrb5_cc_start_seq_get(ctx, cache, &cur);
2501*7f2fe78bSCy Schubert if (code)
2502*7f2fe78bSCy Schubert goto cleanup;
2503*7f2fe78bSCy Schubert
2504*7f2fe78bSCy Schubert _tzset();
2505*7f2fe78bSCy Schubert while (!(code = pkrb5_cc_next_cred(ctx, cache, &cur, &creds))) {
2506*7f2fe78bSCy Schubert if ((!pkrb5_is_config_principal(ctx, creds.server)) &&
2507*7f2fe78bSCy Schubert ((time_t)(DWORD)creds.times.endtime - time(0) > 0))
2508*7f2fe78bSCy Schubert have_tickets = TRUE;
2509*7f2fe78bSCy Schubert
2510*7f2fe78bSCy Schubert pkrb5_free_cred_contents(ctx, &creds);
2511*7f2fe78bSCy Schubert }
2512*7f2fe78bSCy Schubert if (code == KRB5_CC_END) {
2513*7f2fe78bSCy Schubert code = pkrb5_cc_end_seq_get(ctx, cache, &cur);
2514*7f2fe78bSCy Schubert if (code)
2515*7f2fe78bSCy Schubert goto cleanup;
2516*7f2fe78bSCy Schubert flags = 0;
2517*7f2fe78bSCy Schubert code = pkrb5_cc_set_flags(ctx, cache, flags);
2518*7f2fe78bSCy Schubert if (code)
2519*7f2fe78bSCy Schubert goto cleanup;
2520*7f2fe78bSCy Schubert }
2521*7f2fe78bSCy Schubert cleanup:
2522*7f2fe78bSCy Schubert return have_tickets;
2523*7f2fe78bSCy Schubert }
2524*7f2fe78bSCy Schubert
2525*7f2fe78bSCy Schubert static BOOL
cc_have_tickets_for_princ(krb5_context ctx,krb5_ccache cache,krb5_principal princ)2526*7f2fe78bSCy Schubert cc_have_tickets_for_princ(krb5_context ctx,
2527*7f2fe78bSCy Schubert krb5_ccache cache,
2528*7f2fe78bSCy Schubert krb5_principal princ)
2529*7f2fe78bSCy Schubert {
2530*7f2fe78bSCy Schubert krb5_error_code code;
2531*7f2fe78bSCy Schubert krb5_principal cc_princ = NULL;
2532*7f2fe78bSCy Schubert BOOL have_tickets = FALSE;
2533*7f2fe78bSCy Schubert code = pkrb5_cc_get_principal(ctx, cache, &cc_princ);
2534*7f2fe78bSCy Schubert if (code)
2535*7f2fe78bSCy Schubert goto cleanup;
2536*7f2fe78bSCy Schubert
2537*7f2fe78bSCy Schubert if (pkrb5_principal_compare(ctx, princ, cc_princ))
2538*7f2fe78bSCy Schubert have_tickets = cc_have_tickets(ctx, cache);
2539*7f2fe78bSCy Schubert
2540*7f2fe78bSCy Schubert cleanup:
2541*7f2fe78bSCy Schubert if (cc_princ != NULL)
2542*7f2fe78bSCy Schubert pkrb5_free_principal(ctx, cc_princ);
2543*7f2fe78bSCy Schubert return have_tickets;
2544*7f2fe78bSCy Schubert }
2545*7f2fe78bSCy Schubert
cc_default_have_tickets(krb5_context ctx)2546*7f2fe78bSCy Schubert static BOOL cc_default_have_tickets(krb5_context ctx)
2547*7f2fe78bSCy Schubert {
2548*7f2fe78bSCy Schubert krb5_ccache cache = NULL;
2549*7f2fe78bSCy Schubert BOOL have_tickets = FALSE;
2550*7f2fe78bSCy Schubert if (pkrb5_cc_default(ctx, &cache) == 0)
2551*7f2fe78bSCy Schubert have_tickets = cc_have_tickets(ctx, cache);
2552*7f2fe78bSCy Schubert if (cache != NULL)
2553*7f2fe78bSCy Schubert pkrb5_cc_close(ctx, cache);
2554*7f2fe78bSCy Schubert return have_tickets;
2555*7f2fe78bSCy Schubert }
2556*7f2fe78bSCy Schubert
2557*7f2fe78bSCy Schubert static BOOL
cccol_have_tickets_for_princ(krb5_context ctx,krb5_principal princ,char * ccname,int cclen)2558*7f2fe78bSCy Schubert cccol_have_tickets_for_princ(krb5_context ctx,
2559*7f2fe78bSCy Schubert krb5_principal princ,
2560*7f2fe78bSCy Schubert char *ccname,
2561*7f2fe78bSCy Schubert int cclen)
2562*7f2fe78bSCy Schubert {
2563*7f2fe78bSCy Schubert krb5_error_code code;
2564*7f2fe78bSCy Schubert krb5_ccache cache;
2565*7f2fe78bSCy Schubert krb5_cccol_cursor cursor;
2566*7f2fe78bSCy Schubert BOOL have_tickets = FALSE;
2567*7f2fe78bSCy Schubert char *ccfullname;
2568*7f2fe78bSCy Schubert
2569*7f2fe78bSCy Schubert code = pkrb5_cccol_cursor_new(ctx, &cursor);
2570*7f2fe78bSCy Schubert if (code)
2571*7f2fe78bSCy Schubert goto cleanup;
2572*7f2fe78bSCy Schubert
2573*7f2fe78bSCy Schubert while (!have_tickets &&
2574*7f2fe78bSCy Schubert !(code = pkrb5_cccol_cursor_next(ctx, cursor, &cache)) &&
2575*7f2fe78bSCy Schubert cache != NULL) {
2576*7f2fe78bSCy Schubert if (cc_have_tickets_for_princ(ctx, cache, princ)) {
2577*7f2fe78bSCy Schubert if (pkrb5_cc_get_full_name(ctx, cache, &ccfullname)==0) {
2578*7f2fe78bSCy Schubert strcpy_s(ccname, cclen, ccfullname);
2579*7f2fe78bSCy Schubert pkrb5_free_string(ctx, ccfullname);
2580*7f2fe78bSCy Schubert have_tickets = TRUE;
2581*7f2fe78bSCy Schubert }
2582*7f2fe78bSCy Schubert }
2583*7f2fe78bSCy Schubert pkrb5_cc_close(ctx, cache);
2584*7f2fe78bSCy Schubert }
2585*7f2fe78bSCy Schubert pkrb5_cccol_cursor_free(ctx, &cursor);
2586*7f2fe78bSCy Schubert cleanup:
2587*7f2fe78bSCy Schubert
2588*7f2fe78bSCy Schubert return have_tickets;
2589*7f2fe78bSCy Schubert }
2590*7f2fe78bSCy Schubert
2591*7f2fe78bSCy Schubert static void
acquire_tkt_no_princ(krb5_context context,char * ccname,int cclen)2592*7f2fe78bSCy Schubert acquire_tkt_no_princ(krb5_context context, char * ccname, int cclen)
2593*7f2fe78bSCy Schubert {
2594*7f2fe78bSCy Schubert krb5_context ctx;
2595*7f2fe78bSCy Schubert DWORD gle;
2596*7f2fe78bSCy Schubert char ccachename[272]="";
2597*7f2fe78bSCy Schubert char loginenv[16];
2598*7f2fe78bSCy Schubert BOOL prompt;
2599*7f2fe78bSCy Schubert BOOL haveTickets;
2600*7f2fe78bSCy Schubert
2601*7f2fe78bSCy Schubert GetEnvironmentVariable("KERBEROSLOGIN_NEVER_PROMPT", loginenv, sizeof(loginenv));
2602*7f2fe78bSCy Schubert prompt = (GetLastError() == ERROR_ENVVAR_NOT_FOUND);
2603*7f2fe78bSCy Schubert
2604*7f2fe78bSCy Schubert ctx = context;
2605*7f2fe78bSCy Schubert
2606*7f2fe78bSCy Schubert SetLastError(0);
2607*7f2fe78bSCy Schubert GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
2608*7f2fe78bSCy Schubert gle = GetLastError();
2609*7f2fe78bSCy Schubert if ( ((gle == ERROR_ENVVAR_NOT_FOUND) || !ccachename[0]) && context ) {
2610*7f2fe78bSCy Schubert const char * ccdef = pkrb5_cc_default_name(ctx);
2611*7f2fe78bSCy Schubert SetEnvironmentVariable("KRB5CCNAME", ccdef ? ccdef : NULL);
2612*7f2fe78bSCy Schubert GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
2613*7f2fe78bSCy Schubert }
2614*7f2fe78bSCy Schubert
2615*7f2fe78bSCy Schubert haveTickets = cc_default_have_tickets(ctx);
2616*7f2fe78bSCy Schubert
2617*7f2fe78bSCy Schubert if ( prompt && !haveTickets ) {
2618*7f2fe78bSCy Schubert acquire_tkt_send_msg(ctx, NULL, ccachename, NULL, ccname, cclen);
2619*7f2fe78bSCy Schubert /*
2620*7f2fe78bSCy Schubert * If the ticket manager returned an alternative credential cache
2621*7f2fe78bSCy Schubert * remember it as the default for this process.
2622*7f2fe78bSCy Schubert */
2623*7f2fe78bSCy Schubert if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
2624*7f2fe78bSCy Schubert SetEnvironmentVariable("KRB5CCNAME",ccname);
2625*7f2fe78bSCy Schubert }
2626*7f2fe78bSCy Schubert
2627*7f2fe78bSCy Schubert } else if (ccachename[0] && ccname) {
2628*7f2fe78bSCy Schubert strncpy(ccname, ccachename, cclen);
2629*7f2fe78bSCy Schubert ccname[cclen-1] = '\0';
2630*7f2fe78bSCy Schubert }
2631*7f2fe78bSCy Schubert if ( !context )
2632*7f2fe78bSCy Schubert pkrb5_free_context(ctx);
2633*7f2fe78bSCy Schubert }
2634*7f2fe78bSCy Schubert
2635*7f2fe78bSCy Schubert
2636*7f2fe78bSCy Schubert static void
acquire_tkt_for_princ(krb5_context ctx,krb5_principal desiredPrincipal,char * ccname,int cclen)2637*7f2fe78bSCy Schubert acquire_tkt_for_princ(krb5_context ctx, krb5_principal desiredPrincipal,
2638*7f2fe78bSCy Schubert char * ccname, int cclen)
2639*7f2fe78bSCy Schubert {
2640*7f2fe78bSCy Schubert DWORD gle;
2641*7f2fe78bSCy Schubert char ccachename[272]="";
2642*7f2fe78bSCy Schubert char loginenv[16];
2643*7f2fe78bSCy Schubert BOOL prompt;
2644*7f2fe78bSCy Schubert
2645*7f2fe78bSCy Schubert GetEnvironmentVariable("KERBEROSLOGIN_NEVER_PROMPT", loginenv, sizeof(loginenv));
2646*7f2fe78bSCy Schubert prompt = (GetLastError() == ERROR_ENVVAR_NOT_FOUND);
2647*7f2fe78bSCy Schubert
2648*7f2fe78bSCy Schubert SetLastError(0);
2649*7f2fe78bSCy Schubert GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
2650*7f2fe78bSCy Schubert gle = GetLastError();
2651*7f2fe78bSCy Schubert if ((gle == ERROR_ENVVAR_NOT_FOUND || !ccachename[0]) && ctx != NULL) {
2652*7f2fe78bSCy Schubert const char * ccdef = pkrb5_cc_default_name(ctx);
2653*7f2fe78bSCy Schubert SetEnvironmentVariable("KRB5CCNAME", ccdef ? ccdef : NULL);
2654*7f2fe78bSCy Schubert GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
2655*7f2fe78bSCy Schubert }
2656*7f2fe78bSCy Schubert if (!cccol_have_tickets_for_princ(ctx, desiredPrincipal, ccname, cclen)) {
2657*7f2fe78bSCy Schubert if (prompt) {
2658*7f2fe78bSCy Schubert acquire_tkt_send_msg(ctx, NULL,
2659*7f2fe78bSCy Schubert ccachename, desiredPrincipal, ccname, cclen);
2660*7f2fe78bSCy Schubert /*
2661*7f2fe78bSCy Schubert * If the ticket manager returned an alternative credential cache
2662*7f2fe78bSCy Schubert * remember it as the default for this process.
2663*7f2fe78bSCy Schubert */
2664*7f2fe78bSCy Schubert if (ccname != NULL && ccname[0] &&
2665*7f2fe78bSCy Schubert strcmp(ccachename, ccname)) {
2666*7f2fe78bSCy Schubert SetEnvironmentVariable("KRB5CCNAME",ccname);
2667*7f2fe78bSCy Schubert }
2668*7f2fe78bSCy Schubert }
2669*7f2fe78bSCy Schubert }
2670*7f2fe78bSCy Schubert }
2671*7f2fe78bSCy Schubert
2672*7f2fe78bSCy Schubert
2673*7f2fe78bSCy Schubert void FAR
not_an_API_Leash_AcquireInitialTicketsIfNeeded(krb5_context context,krb5_principal desiredKrb5Principal,char * ccname,int cclen)2674*7f2fe78bSCy Schubert not_an_API_Leash_AcquireInitialTicketsIfNeeded(krb5_context context,
2675*7f2fe78bSCy Schubert krb5_principal desiredKrb5Principal,
2676*7f2fe78bSCy Schubert char * ccname, int cclen)
2677*7f2fe78bSCy Schubert {
2678*7f2fe78bSCy Schubert if (!desiredKrb5Principal) {
2679*7f2fe78bSCy Schubert acquire_tkt_no_princ(context, ccname, cclen);
2680*7f2fe78bSCy Schubert } else {
2681*7f2fe78bSCy Schubert acquire_tkt_for_princ(context, desiredKrb5Principal, ccname, cclen);
2682*7f2fe78bSCy Schubert }
2683*7f2fe78bSCy Schubert return;
2684*7f2fe78bSCy Schubert }
2685