1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <security/pam_impl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <syslog.h>
#include <libintl.h>
#include <k5-int.h>
#include "profile/prof_int.h"
#include <netdb.h>
#include <ctype.h>
#include "utils.h"
#include "krb5_repository.h"
#define KRB5_DEFAULT_OPTIONS 0
int forwardable_flag = 0;
int renewable_flag = 0;
int proxiable_flag = 0;
int no_address_flag = 0;
profile_options_boolean config_option[] = {
{ "forwardable", &forwardable_flag, 0 },
{ "renewable", &renewable_flag, 0 },
{ "proxiable", &proxiable_flag, 0 },
{ "no_addresses", &no_address_flag, 0 },
{ NULL, NULL, 0 }
};
char *renew_timeval;
char *life_timeval;
profile_option_strings config_times[] = {
{ "max_life", &life_timeval, 0 },
{ "max_renewable_life", &renew_timeval, 0 },
{ NULL, NULL, 0 }
};
char *realmdef[] = { "realms", NULL, NULL, NULL };
char *appdef[] = { "appdefaults", "kinit", NULL };
#define krb_realm (*(realmdef + 1))
int attempt_krb5_auth(void *, krb5_module_data_t *, char *, char **,
boolean_t);
void krb5_cleanup(pam_handle_t *, void *, int);
extern errcode_t profile_get_options_boolean();
extern errcode_t profile_get_options_string();
extern int krb5_verifypw(pam_handle_t *, char *, char *, boolean_t, int);
extern krb5_error_code krb5_verify_init_creds(krb5_context,
krb5_creds *, krb5_principal, krb5_keytab, krb5_ccache *,
krb5_verify_init_creds_opt *);
/*
* pam_sm_authenticate - Authenticate user
*/
int
pam_sm_authenticate(
pam_handle_t *pamh,
int flags,
int argc,
const char **argv)
{
char *user = NULL;
int err;
int result = PAM_AUTH_ERR;
/* pam.conf options */
int debug = 0;
int warn = 1;
/* return an error on password expire */
int err_on_exp = 0;
int i;
char *password = NULL;
uid_t pw_uid;
krb5_module_data_t *kmd = NULL;
krb5_repository_data_t *krb5_data = NULL;
pam_repository_t *rep_data = NULL;
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "debug") == 0) {
debug = 1;
} else if (strcmp(argv[i], "nowarn") == 0) {
warn = 0;
} else if (strcmp(argv[i], "err_on_exp") == 0) {
err_on_exp = 1;
} else {
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth) unrecognized option %s"),
argv[i]);
}
}
if (flags & PAM_SILENT) warn = 0;
if (debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): pam_sm_authenticate flags=%d",
flags);
(void) pam_get_item(pamh, PAM_USER, (void**) &user);
if (user == NULL || *user == '\0') {
if (debug)
syslog(LOG_DEBUG, "PAM-KRB5 (auth): user empty "
"or null");
return (PAM_USER_UNKNOWN);
}
/* make sure a password entry exists for this user */
if (!get_pw_uid(user, &pw_uid))
return (PAM_USER_UNKNOWN);
/*
* pam_get_data could fail if we are being called for the first time
* or if the module is not found, PAM_NO_MODULE_DATA is not an error
*/
err = pam_get_data(pamh, KRB5_DATA, (const void**)&kmd);
if (!(err == PAM_SUCCESS || err == PAM_NO_MODULE_DATA))
return (PAM_AUTH_ERR);
if (kmd == NULL) {
kmd = calloc(1, sizeof (krb5_module_data_t));
if (kmd == NULL) {
result = PAM_BUF_ERR;
goto out;
}
err = pam_set_data(pamh, KRB5_DATA, kmd, &krb5_cleanup);
if (err != PAM_SUCCESS) {
free(kmd);
result = err;
goto out;
}
}
if (!kmd->env) {
char buffer[512];
if (snprintf(buffer, sizeof (buffer),
"%s=FILE:/tmp/krb5cc_%d",
KRB5_ENV_CCNAME, (int)pw_uid) >= sizeof (buffer)) {
result = PAM_SYSTEM_ERR;
goto out;
}
/* we MUST copy this to the heap for the putenv to work! */
kmd->env = strdup(buffer);
if (!kmd->env) {
result = PAM_BUF_ERR;
goto out;
} else {
if (putenv(kmd->env)) {
result = PAM_SYSTEM_ERR;
goto out;
}
}
}
kmd->auth_status = PAM_AUTH_ERR;
kmd->debug = debug;
kmd->warn = warn;
kmd->err_on_exp = err_on_exp;
kmd->ccache = NULL;
kmd->kcontext = NULL;
kmd->password = NULL;
kmd->age_status = PAM_SUCCESS;
(void) memset((char *)&kmd->initcreds, 0, sizeof (krb5_creds));
/*
* For apps that already did krb5 auth exchange...
* Now that we've created the kmd structure, we can
* return SUCCESS. 'kmd' may be needed later by other
* PAM functions, thats why we wait until this point to
* return.
*/
(void) pam_get_item(pamh, PAM_REPOSITORY, (void **)&rep_data);
if (rep_data != NULL) {
if (strcmp(rep_data->type, KRB5_REPOSITORY_NAME) != 0) {
if (debug)
syslog(LOG_DEBUG, "PAM-KRB5 (auth): wrong"
"repository found (%s), returning "
"PAM_IGNORE", rep_data->type);
return (PAM_IGNORE);
}
if (rep_data->scope_len == sizeof (krb5_repository_data_t)) {
krb5_data = (krb5_repository_data_t *)rep_data->scope;
if (krb5_data->flags ==
SUNW_PAM_KRB5_ALREADY_AUTHENTICATED &&
krb5_data->principal != NULL &&
strlen(krb5_data->principal)) {
if (debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): Principal "
"%s already authenticated",
krb5_data->principal);
kmd->auth_status = PAM_SUCCESS;
return (PAM_SUCCESS);
}
}
}
/*
* if root key exists in the keytab, it's a random key so no
* need to prompt for pw and we just return IGNORE.
*
* note we don't need to force a prompt for pw as authtok_get
* is required to be stacked above this module.
*/
if ((strcmp(user, ROOT_UNAME) == 0) &&
key_in_keytab(user, debug)) {
if (debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): "
"key for '%s' in keytab, returning IGNORE", user);
result = PAM_IGNORE;
goto out;
}
(void) pam_get_item(pamh, PAM_AUTHTOK, (void **)&password);
result = attempt_krb5_auth(pamh, kmd, user, &password, 1);
out:
if (kmd) {
if (debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): pam_sm_auth finalize"
" ccname env, result =%d, env ='%s',"
" age = %d, status = %d",
result, kmd->env ? kmd->env : "<null>",
kmd->age_status, kmd->auth_status);
if (kmd->env &&
!(kmd->age_status == PAM_NEW_AUTHTOK_REQD &&
kmd->auth_status == PAM_SUCCESS)) {
if (result == PAM_SUCCESS) {
/*
* Put ccname into the pamh so that login
* apps can pick this up when they run
* pam_getenvlist().
*/
if ((result = pam_putenv(pamh, kmd->env))
!= PAM_SUCCESS) {
/* should not happen but... */
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth):"
" pam_putenv failed: result: %d"),
result);
goto cleanupccname;
}
} else {
cleanupccname:
/* for lack of a Solaris unputenv() */
krb5_unsetenv(KRB5_ENV_CCNAME);
free(kmd->env);
kmd->env = NULL;
}
}
kmd->auth_status = result;
}
if (debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): end: %s", pam_strerror(pamh, result));
return (result);
}
int
attempt_krb5_auth(
void *pamh,
krb5_module_data_t *kmd,
char *user,
char **krb5_pass,
boolean_t verify_tik)
{
krb5_principal me = NULL;
krb5_principal server = NULL;
krb5_creds *my_creds;
krb5_timestamp now;
krb5_error_code code = 0;
char kuser[2*MAXHOSTNAMELEN];
krb5_deltat lifetime;
krb5_deltat rlife;
krb5_deltat krb5_max_duration;
int options = KRB5_DEFAULT_OPTIONS;
krb5_data tgtname = {
0,
KRB5_TGS_NAME_SIZE,
KRB5_TGS_NAME
};
krb5_get_init_creds_opt opts;
/*
* "result" should not be assigned PAM_SUCCESS unless
* authentication has succeeded and there are no other errors.
*
* "code" is sometimes used for PAM codes, sometimes for krb5
* codes. Be careful.
*/
int result = PAM_AUTH_ERR;
if (kmd->debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): attempt_krb5_auth: start: user='%s'",
user ? user : "<null>");
krb5_get_init_creds_opt_init(&opts);
/* need to free context with krb5_free_context */
if (code = krb5_init_context(&kmd->kcontext)) {
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): Error initializing "
"krb5: %s"),
error_message(code));
return (PAM_SYSTEM_ERR);
}
if ((code = get_kmd_kuser(kmd->kcontext, (const char *)user, kuser,
2*MAXHOSTNAMELEN)) != 0) {
/* get_kmd_kuser returns proper PAM error statuses */
return (code);
}
if ((code = krb5_parse_name(kmd->kcontext, kuser, &me)) != 0) {
krb5_free_context(kmd->kcontext);
kmd->kcontext = NULL;
return (PAM_AUTH_ERR);
}
/* call krb5_free_cred_contents() on error */
my_creds = &kmd->initcreds;
if ((code = krb5_copy_principal(kmd->kcontext, me, &my_creds->client)))
goto out_err;
if (code = krb5_build_principal_ext(kmd->kcontext, &server,
krb5_princ_realm(kmd->kcontext, me)->length,
krb5_princ_realm(kmd->kcontext, me)->data,
tgtname.length, tgtname.data,
krb5_princ_realm(kmd->kcontext, me)->length,
krb5_princ_realm(kmd->kcontext, me)->data, 0)) {
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): attempt_krb5_auth: "
"krb5_build_princ_ext failed: %s"),
error_message(code));
goto out;
}
if (code = krb5_copy_principal(kmd->kcontext, server,
&my_creds->server)) {
goto out_err;
}
if (code = krb5_timeofday(kmd->kcontext, &now)) {
syslog(LOG_ERR, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): attempt_krb5_auth: "
"krb5_timeofday failed: %s"),
error_message(code));
goto out;
}
/*
* set the values for lifetime and rlife to be the maximum
* possible
*/
krb5_max_duration = KRB5_KDB_EXPIRATION - now - 60*60;
lifetime = krb5_max_duration;
rlife = krb5_max_duration;
/*
* Let us get the values for various options
* from Kerberos configuration file
*/
krb_realm = krb5_princ_realm(kmd->kcontext, me)->data;
profile_get_options_boolean(kmd->kcontext->profile,
realmdef, config_option);
profile_get_options_boolean(kmd->kcontext->profile,
appdef, config_option);
profile_get_options_string(kmd->kcontext->profile,
realmdef, config_times);
profile_get_options_string(kmd->kcontext->profile,
appdef, config_times);
if (renew_timeval) {
code = krb5_string_to_deltat(renew_timeval, &rlife);
if (code != 0 || rlife == 0 || rlife > krb5_max_duration) {
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): Bad max_renewable_life "
" value '%s' in Kerberos config file"),
renew_timeval);
result = PAM_SYSTEM_ERR;
goto out;
}
}
if (life_timeval) {
code = krb5_string_to_deltat(life_timeval, &lifetime);
if (code != 0 || lifetime == 0 ||
lifetime > krb5_max_duration) {
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN, "PAM-KRB5 (auth): Bad "
"lifetime value '%s' in Kerberos config file"),
life_timeval);
result = PAM_SYSTEM_ERR;
goto out;
}
}
/* start timer when request gets to KDC */
my_creds->times.starttime = 0;
my_creds->times.endtime = now + lifetime;
if (options & KDC_OPT_RENEWABLE) {
my_creds->times.renew_till = now + rlife;
} else
my_creds->times.renew_till = 0;
krb5_get_init_creds_opt_set_tkt_life(&opts, lifetime);
if (proxiable_flag) { /* Set in config file */
if (kmd->debug)
syslog(LOG_DEBUG, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): Proxiable tickets "
"requested"));
krb5_get_init_creds_opt_set_proxiable(&opts, TRUE);
}
if (forwardable_flag) {
if (kmd->debug)
syslog(LOG_DEBUG, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): Forwardable tickets "
"requested"));
krb5_get_init_creds_opt_set_forwardable(&opts, TRUE);
}
if (renewable_flag) {
if (kmd->debug)
syslog(LOG_DEBUG, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): Renewable tickets "
"requested"));
krb5_get_init_creds_opt_set_renew_life(&opts, rlife);
}
if (no_address_flag) {
if (kmd->debug)
syslog(LOG_DEBUG, dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): Addressless tickets "
"requested"));
krb5_get_init_creds_opt_set_address_list(&opts, NULL);
}
/*
* mech_krb5 interprets empty passwords as NULL passwords
* and tries to read a password from stdin. Since we are in
* pam this is bad and should not be allowed.
*/
if (*krb5_pass == NULL || strlen(*krb5_pass) == 0) {
code = KRB5KRB_AP_ERR_BAD_INTEGRITY;
} else {
code = krb5_get_init_creds_password(kmd->kcontext,
my_creds,
me,
*krb5_pass, /* clear text passwd */
NULL, /* prompter */
NULL, /* data */
0, /* start time */
NULL, /* defaults to krbtgt@REALM */
&opts);
}
if (kmd->debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): attempt_krb5_auth: "
"krb5_get_init_creds_password returns: %s",
code == 0 ? "SUCCESS" : error_message(code));
switch (code) {
case 0:
/* got a tgt, let's verify it */
if (verify_tik) {
krb5_verify_init_creds_opt vopts;
krb5_principal sp = NULL;
char kt_name[MAX_KEYTAB_NAME_LEN];
char *fqdn;
krb5_verify_init_creds_opt_init(&vopts);
code = krb5_verify_init_creds(kmd->kcontext,
my_creds,
NULL, /* defaults to host/localhost@REALM */
NULL,
NULL,
&vopts);
if (code) {
result = PAM_SYSTEM_ERR;
/*
* Give a better error message when the
* keytable entry isn't found or the keytab
* file cannot be found.
*/
if (krb5_sname_to_principal(kmd->kcontext, NULL,
NULL, KRB5_NT_SRV_HST, &sp))
fqdn = "<fqdn>";
else
fqdn = sp->data[1].data;
if (krb5_kt_default_name(kmd->kcontext, kt_name,
sizeof (kt_name)))
(void) strncpy(kt_name,
"default keytab",
sizeof (kt_name));
switch (code) {
case KRB5_KT_NOTFOUND:
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): "
"krb5_verify_init_creds failed:"
" Key table entry \"host/%s\""
" not found in %s"),
fqdn, kt_name);
break;
case ENOENT:
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): "
"krb5_verify_init_creds failed:"
" Keytab file \"%s\""
" does not exist.\n"),
kt_name);
break;
default:
syslog(LOG_ERR,
dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): "
"krb5_verify_init_creds failed:"
" %s"),
error_message(code));
break;
}
if (sp)
krb5_free_principal(kmd->kcontext, sp);
}
}
break;
case KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN:
/*
* Since this principal is not part of the local
* Kerberos realm, we just return PAM_USER_UNKNOWN.
*/
result = PAM_USER_UNKNOWN;
if (kmd->debug)
syslog(LOG_DEBUG, "PAM-KRB5 (auth): attempt_krb5_auth:"
" User is not part of the local Kerberos"
" realm: %s", error_message(code));
break;
case KRB5KDC_ERR_PREAUTH_FAILED:
case KRB5KRB_AP_ERR_BAD_INTEGRITY:
/*
* We could be trying the password from a previous
* pam authentication module, but we don't want to
* generate an error if the unix password is different
* than the Kerberos password...
*/
break;
case KRB5KDC_ERR_KEY_EXP:
if (!kmd->err_on_exp) {
/*
* Request a tik for changepw service
* and it will tell us if pw is good or not.
*/
code = krb5_verifypw(pamh, kuser, *krb5_pass,
0, kmd->debug);
if (kmd->debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): attempt_krb5_auth: "
"verifypw %s", error_message(code));
if (code == 0) {
/* pw is good, set age status for acct_mgmt */
kmd->age_status = PAM_NEW_AUTHTOK_REQD;
}
}
break;
default:
result = PAM_SYSTEM_ERR;
if (kmd->debug)
syslog(LOG_DEBUG, "PAM-KRB5 (auth): error %d - %s",
code, error_message(code));
break;
}
if (code == 0) {
/*
* success for the entered pw
*
* we can't rely on the pw in PAM_AUTHTOK
* to be the (correct) krb5 one so
* store krb5 pw in module data for
* use in acct_mgmt
*/
if (!(kmd->password = strdup(*krb5_pass))) {
syslog(LOG_ERR, "Cannot strdup password");
result = PAM_BUF_ERR;
goto out_err;
}
result = PAM_SUCCESS;
goto out;
}
out_err:
/* jump (or reach) here if error and cred cache has been init */
if (kmd->debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): clearing initcreds in "
"pam_authenticate()");
krb5_free_cred_contents(kmd->kcontext, &kmd->initcreds);
(void) memset((char *)&kmd->initcreds, 0, sizeof (krb5_creds));
out:
if (server)
krb5_free_principal(kmd->kcontext, server);
if (me)
krb5_free_principal(kmd->kcontext, me);
if (kmd->kcontext) {
krb5_free_context(kmd->kcontext);
kmd->kcontext = NULL;
}
if (kmd->debug)
syslog(LOG_DEBUG,
"PAM-KRB5 (auth): attempt_krb5_auth returning %d",
result);
return (kmd->auth_status = result);
}
/*ARGSUSED*/
void
krb5_cleanup(pam_handle_t *pamh, void *data, int pam_status)
{
krb5_module_data_t *kmd = (krb5_module_data_t *)data;
if (kmd == NULL)
return;
if (kmd->debug) {
syslog(LOG_DEBUG,
dgettext(TEXT_DOMAIN,
"PAM-KRB5 (auth): krb5_cleanup auth_status = %d"),
kmd->auth_status);
}
/*
* if pam_status is PAM_SUCCESS, clean up based on value in
* auth_status, otherwise just purge the context
*/
if ((pam_status == PAM_SUCCESS) &&
(kmd->auth_status == PAM_SUCCESS) && kmd->ccache)
krb5_cc_close(kmd->kcontext, kmd->ccache);
if (kmd->password) {
(void) memset(kmd->password, 0, strlen(kmd->password));
free(kmd->password);
}
if ((pam_status != PAM_SUCCESS) ||
(kmd->auth_status != PAM_SUCCESS)) {
krb5_free_cred_contents(kmd->kcontext, &kmd->initcreds);
(void) memset((char *)&kmd->initcreds, 0, sizeof (krb5_creds));
}
free(kmd);
}
|