SetLastError(0);
GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
gle = GetLastError();
- if ( (gle == ERROR_ENVVAR_NOT_FOUND) && context ) {
- SetEnvironmentVariable("KRB5CCNAME", pkrb5_cc_default_name(ctx));
+ if ( ((gle == ERROR_ENVVAR_NOT_FOUND) || !ccachename[0]) && context ) {
+ char * ccdef = pkrb5_cc_default_name(ctx);
+ SetEnvironmentVariable("KRB5CCNAME", ccdef ? ccdef : NULL);
GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
}
if ( prompt && ticketinfo.btickets != GOOD_TICKETS ) {
acquire_tkt_send_msg(ctx, NULL, ccachename, NULL, ccname, cclen);
+ /*
+ * If the ticket manager returned an alternative credential cache
+ * remember it as the default for this process.
+ */
+ if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
+ SetEnvironmentVariable("KRB5CCNAME",ccname);
+ }
+
} else if (ccachename[0] && ccname) {
strncpy(ccname, ccachename, cclen);
ccname[cclen-1] = '\0';
}
- if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
- SetEnvironmentVariable("KRB5CCNAME",ccname);
- }
-
if ( !context )
pkrb5_free_context(ctx);
}
SetLastError(0);
GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
gle = GetLastError();
- if ( (gle == ERROR_ENVVAR_NOT_FOUND) && context ) {
- SetEnvironmentVariable("KRB5CCNAME", pkrb5_cc_default_name(ctx));
+ if ( ((gle == ERROR_ENVVAR_NOT_FOUND) || !ccachename[0]) && context ) {
+ char * ccdef = pkrb5_cc_default_name(ctx);
+ SetEnvironmentVariable("KRB5CCNAME", ccdef ? ccdef : NULL);
GetEnvironmentVariable("KRB5CCNAME", ccachename, sizeof(ccachename));
}
if (prompt) {
if (ticketinfo.btickets != GOOD_TICKETS || strcmp(name,ticketinfo.principal)) {
acquire_tkt_send_msg(ctx, NULL, ccachename, desiredPrincipal, ccname, cclen);
+ /*
+ * If the ticket manager returned an alternative credential cache
+ * remember it as the default for this process.
+ */
+ if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
+ SetEnvironmentVariable("KRB5CCNAME",ccname);
+ }
} else if (ccachename[0] && ccname) {
strncpy(ccname, ccachename, cclen);
ccname[cclen-1] = '\0';
}
}
- if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
- SetEnvironmentVariable("KRB5CCNAME",ccname);
- }
-
-
if (name)
pkrb5_free_unparsed_name(ctx, name);