return(retstr);
}
+/*
+ * LeashKRB5GetTickets() treats krbv5Context as an in/out variable.
+ * If the caller does not provide a krb5_context, one will be allocated.
+ * It is up to the caller to ensure that the context is eventually freed.
+ * A context can be returned even if the function returns an error.
+ */
+
long
not_an_API_LeashKRB5GetTickets(
TICKETINFO * ticketinfo,
#ifdef NO_KRB5
return(0);
#else
- krb5_context ctx;
- krb5_ccache cache;
+ krb5_context ctx = 0;
+ krb5_ccache cache = 0;
krb5_error_code code;
krb5_principal KRBv5Principal;
krb5_flags flags = 0;
int StartDay;
int EndDay;
int RenewDay;
- int freeContextFlag;
char StartTimeString[256];
char EndTimeString[256];
char RenewTimeString[256];
char *sPtr;
char *ticketFlag;
LPCSTR functionName;
+ TicketList *list = NULL;
- TicketList* list = NULL;
-
- ctx = NULL;
- cache = NULL;
if ( ticketinfo ) {
ticketinfo->btickets = NO_TICKETS;
ticketinfo->principal[0] = '\0';
if (code != KRB5_FCC_NOFILE && code != KRB5_CC_NOTFOUND)
Leash_krb5_error(code, "krb5_cc_set_flags()", 0, &ctx,
&cache);
- else if ((code == KRB5_FCC_NOFILE || code == KRB5_CC_NOTFOUND) && ctx != NULL)
+ else if ((code == KRB5_FCC_NOFILE || code == KRB5_CC_NOTFOUND))
{
if (cache != NULL)
pkrb5_cc_close(ctx, cache);
{
if (code != KRB5_FCC_NOFILE && code != KRB5_CC_NOTFOUND)
Leash_krb5_error(code, "krb5_cc_get_principal()", 0, &ctx, &cache);
- else if ((code == KRB5_FCC_NOFILE || code == KRB5_CC_NOTFOUND) && ctx != NULL)
+ else if ((code == KRB5_FCC_NOFILE || code == KRB5_CC_NOTFOUND))
{
if (cache != NULL)
pkrb5_cc_close(ctx, cache);
if ((code = pkrb5_cc_start_seq_get(ctx, cache, &KRBv5Cursor)))
{
functionName = "krb5_cc_start_seq_get()";
- freeContextFlag = 1;
goto on_error;
}
list->theTicket = (char*) calloc(1, strlen(Buffer)+1);
if (!list->theTicket)
{
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
strcpy(list->theTicket, Buffer);
list->tktEncType = (char*) calloc(1, strlen(Buffer)+1);
if (!list->tktEncType)
{
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
strcpy(list->tktEncType, Buffer);
list->keyEncType = (char*) calloc(1, strlen(Buffer)+1);
if (!list->keyEncType)
{
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
strcpy(list->keyEncType, Buffer);
n++;
list->addrList = calloc(1, n * sizeof(char *));
if (!list->addrList) {
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
list->addrCount = n;
list->addrList[n] = (char*) calloc(1, strlen(Buffer)+1);
if (!list->addrList[n])
{
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
strcpy(list->addrList[n], Buffer);
if ((code = pkrb5_cc_end_seq_get(ctx, cache, &KRBv5Cursor)))
{
functionName = "krb5_cc_end_seq_get()";
- freeContextFlag = 1;
goto on_error;
}
if ((code = pkrb5_cc_set_flags(ctx, cache, flags)))
{
functionName = "krb5_cc_set_flags()";
- freeContextFlag = 1;
goto on_error;
}
}
else
{
functionName = "krb5_cc_next_cred()";
- freeContextFlag = 1;
goto on_error;
}
return(code);
on_error:
-
- Leash_krb5_error(code, functionName, freeContextFlag, &(*krbv5Context), &cache);
+ Leash_krb5_error(code, functionName, 0, &(*krbv5Context), &cache);
return(code);
#endif //!NO_KER5
}
return(0);
#else
- LPCSTR functionName;
- int freeContextFlag;
+ LPCSTR functionName = NULL;
+ int freeContextFlag = 0;
krb5_error_code rc;
krb5_flags flags;
if (pkrb5_init_context == NULL)
return 1;
- if (*ctx == 0 && (rc = (*pkrb5_init_context)(ctx)))
+ if (*ctx == 0) {
+ if (rc = (*pkrb5_init_context)(ctx))
{
functionName = "krb5_init_context()";
- freeContextFlag = 0;
goto on_error;
}
+ freeContextFlag = 1;
+ }
if (*cache == 0 && (rc = pkrb5_cc_default(*ctx, cache)))
{
functionName = "krb5_cc_default()";
- freeContextFlag = 1;
goto on_error;
}
#ifdef KRB5_TC_NOTICKET
#ifdef NO_KRB5
return 0;
#else
+#ifdef USE_MESSAGE_BOX
char message[256];
const char *errText;
int krb5Error = ((int)(rc & 255));
MessageBox(NULL, message, "Kerberos Five", MB_OK | MB_ICONERROR |
MB_TASKMODAL |
MB_SETFOREGROUND);
- if (FreeContextFlag == 1)
- {
+#endif /* USE_MESSAGE_BOX */
+
if (*ctx != NULL)
{
if (*cache != NULL) {
*cache = NULL;
}
+ if (FreeContextFlag) {
pkrb5_free_context(*ctx);
*ctx = NULL;
}
p += n;
size -= n;
}
+#ifdef USE_MESSAGE_BOX
if ( displayMB )
MessageBox(NULL, message, "Leash", MB_OK | MB_ICONERROR | MB_TASKMODAL |
MB_SETFOREGROUND);
-
+#endif /* USE_MESSAGE_BOX */
if (rc5) return rc5;
if (rc4) return rc4;
if (rcL) return rcL;
list->theTicket = (char*) calloc(1, sizeof(buf));
if (!list->theTicket)
{
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
ticketinfo->btickets = newtickets;
+#ifdef USE_MESSAGE_BOX
if (k_errno)
{
CHAR message[256];
MessageBox(NULL, message, "Kerberos Four",
MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND);
}
+#endif /* USE_MESSAGE_BOX */
return k_errno;
#endif
}
ccname[cclen-1] = '\0';
}
- if ( ccname && strcmp(ccachename,ccname) ) {
+ if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
SetEnvironmentVariable("KRB5CCNAME",ccname);
}
}
}
- if ( ccname && strcmp(ccachename,ccname) ) {
+ if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
SetEnvironmentVariable("KRB5CCNAME",ccname);
}