svn rev #25248: trunk/src/windows/leashdll/
hartmans@MIT.EDU
hartmans at MIT.EDU
Wed Sep 28 16:54:41 EDT 2011
http://src.mit.edu/fisheye/changelog/krb5/?cs=25248
Commit By: hartmans
Log Message:
miscellaneous leash32.dll corrections
do not build leash32.dll with MessageBox() calls. Doing
so produces a library that on error must display a dialog
box to the end user. If this library is called from a
service (via gssapi32.dll) the service will block forever
while awaiting the dialog box to clear.
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.
Make sure that 'ctx' and 'cache' are properly initialized so that
it is possible to tell the difference. Do not free the context if
it was locally allocated.
In acquire_tkt_no_princ() do not set the KRB5CCNAME environment
variable if 'ccname' is an empty string.
Combination of 2 patches by Jeffrey Altman
From: Alexey Melnikov <alexey.melnikov at isode.com>
Changed Files:
U trunk/src/windows/leashdll/AFSroutines.c
U trunk/src/windows/leashdll/krb5routines.c
U trunk/src/windows/leashdll/lshfunc.c
U trunk/src/windows/leashdll/timesync.c
U trunk/src/windows/leashdll/winerr.c
Modified: trunk/src/windows/leashdll/AFSroutines.c
===================================================================
--- trunk/src/windows/leashdll/AFSroutines.c 2011-09-28 20:54:37 UTC (rev 25247)
+++ trunk/src/windows/leashdll/AFSroutines.c 2011-09-28 20:54:41 UTC (rev 25248)
@@ -197,7 +197,9 @@
list->theTicket = (char*) calloc(1, sizeof(Buffer));
if (!list->theTicket)
{
+#ifdef USE_MESSAGE_BOX
MessageBox(NULL, "Memory Error", "Error", MB_OK);
+#endif /* USE_MESSAGE_BOX */
return ENOMEM;
}
@@ -742,6 +744,7 @@
#ifdef NO_AFS
return;
#else
+#ifdef USE_MESSAGE_BOX
char message[256];
const char *errText;
@@ -769,6 +772,7 @@
sprintf(message, "%s\n(%s failed)", errText, FailedFunctionName);
MessageBox(NULL, message, "AFS", MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND);
+#endif /* USE_MESSAGE_BOX */
return;
#endif
Modified: trunk/src/windows/leashdll/krb5routines.c
===================================================================
--- trunk/src/windows/leashdll/krb5routines.c 2011-09-28 20:54:37 UTC (rev 25247)
+++ trunk/src/windows/leashdll/krb5routines.c 2011-09-28 20:54:41 UTC (rev 25248)
@@ -315,6 +315,13 @@
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,
@@ -325,8 +332,8 @@
#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;
@@ -339,7 +346,6 @@
int StartDay;
int EndDay;
int RenewDay;
- int freeContextFlag;
char StartTimeString[256];
char EndTimeString[256];
char RenewTimeString[256];
@@ -356,11 +362,8 @@
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';
@@ -379,7 +382,7 @@
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);
@@ -391,7 +394,7 @@
{
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);
@@ -440,7 +443,6 @@
if ((code = pkrb5_cc_start_seq_get(ctx, cache, &KRBv5Cursor)))
{
functionName = "krb5_cc_start_seq_get()";
- freeContextFlag = 1;
goto on_error;
}
@@ -583,7 +585,9 @@
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);
@@ -596,7 +600,9 @@
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);
@@ -611,7 +617,9 @@
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);
@@ -622,7 +630,9 @@
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;
@@ -631,7 +641,9 @@
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);
@@ -673,7 +685,6 @@
if ((code = pkrb5_cc_end_seq_get(ctx, cache, &KRBv5Cursor)))
{
functionName = "krb5_cc_end_seq_get()";
- freeContextFlag = 1;
goto on_error;
}
@@ -684,14 +695,12 @@
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;
}
@@ -704,8 +713,7 @@
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
}
@@ -1011,25 +1019,26 @@
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
@@ -1066,6 +1075,7 @@
#ifdef NO_KRB5
return 0;
#else
+#ifdef USE_MESSAGE_BOX
char message[256];
const char *errText;
int krb5Error = ((int)(rc & 255));
@@ -1090,8 +1100,8 @@
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) {
@@ -1099,6 +1109,7 @@
*cache = NULL;
}
+ if (FreeContextFlag) {
pkrb5_free_context(*ctx);
*ctx = NULL;
}
Modified: trunk/src/windows/leashdll/lshfunc.c
===================================================================
--- trunk/src/windows/leashdll/lshfunc.c 2011-09-28 20:54:37 UTC (rev 25247)
+++ trunk/src/windows/leashdll/lshfunc.c 2011-09-28 20:54:41 UTC (rev 25248)
@@ -135,10 +135,11 @@
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;
@@ -1270,7 +1271,9 @@
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;
}
@@ -1306,6 +1309,7 @@
ticketinfo->btickets = newtickets;
+#ifdef USE_MESSAGE_BOX
if (k_errno)
{
CHAR message[256];
@@ -1321,6 +1325,7 @@
MessageBox(NULL, message, "Kerberos Four",
MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND);
}
+#endif /* USE_MESSAGE_BOX */
return k_errno;
#endif
}
@@ -3562,7 +3567,7 @@
ccname[cclen-1] = '\0';
}
- if ( ccname && strcmp(ccachename,ccname) ) {
+ if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
SetEnvironmentVariable("KRB5CCNAME",ccname);
}
@@ -3659,7 +3664,7 @@
}
}
- if ( ccname && strcmp(ccachename,ccname) ) {
+ if ( ccname && ccname[0] && strcmp(ccachename,ccname) ) {
SetEnvironmentVariable("KRB5CCNAME",ccname);
}
Modified: trunk/src/windows/leashdll/timesync.c
===================================================================
--- trunk/src/windows/leashdll/timesync.c 2011-09-28 20:54:37 UTC (rev 25247)
+++ trunk/src/windows/leashdll/timesync.c 2011-09-28 20:54:41 UTC (rev 25248)
@@ -159,7 +159,6 @@
LONG Leash_timesync(int MessageP)
{
char tmpstr[2048];
- char tmpstr1[2048];
char hostname[128];
int Port;
int rc;
@@ -197,6 +196,7 @@
rc = ProcessTimeSync(hostname, Port, tmpstr);
+#ifdef USE_MESSAGE_BOX
if(MessageP != 0)
{
if (rc && !*tmpstr)
@@ -204,6 +204,8 @@
strcpy(tmpstr, "Unable to syncronize time!\n\n");
if (*hostname)
{
+ char tmpstr1[2048];
+
memset(tmpstr1, '\0', sizeof(tmpstr1));
sprintf(tmpstr1, "Unreachable server: %s\n", hostname);
strcat(tmpstr, tmpstr1);
@@ -213,6 +215,7 @@
MessageBox(NULL, tmpstr, "Time Server",
MB_ICONERROR | MB_OK);
}
+#endif /* USE_MESSAGE_BOX */
WSACleanup();
return(rc);
}
Modified: trunk/src/windows/leashdll/winerr.c
===================================================================
--- trunk/src/windows/leashdll/winerr.c 2011-09-28 20:54:37 UTC (rev 25247)
+++ trunk/src/windows/leashdll/winerr.c 2011-09-28 20:54:41 UTC (rev 25248)
@@ -81,6 +81,7 @@
int _export lsh_com_err_proc (LPSTR whoami, long code,
LPSTR fmt, va_list args)
{
+#ifdef USE_MESSAGE_BOX
int retval;
HWND hOldFocus;
char buf[1024], *cp; /* changed to 512 by jms 8/23/93 */
@@ -118,4 +119,7 @@
mbformat | MB_ICONHAND | MB_TASKMODAL);
SetFocus(hOldFocus);
return retval;
+#else
+ return IDOK;
+#endif /* USE_MESSAGE_BOX */
}
More information about the cvs-krb5
mailing list