From 748eaae393eb90ad6aa519835d37e05bc4ad3be8 Mon Sep 17 00:00:00 2001 From: Keith Vetter Date: Sat, 29 Apr 1995 00:09:05 +0000 Subject: [PATCH] Windows gssapi demo now works. The UI isn't great but hey git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5648 dc483132-0cff-0310-8789-dd5450dbe970 --- src/windows/gss/changelo | 7 + src/windows/gss/gss-clie.c | 4 +- src/windows/gss/gss-misc.c | 28 +++- src/windows/gss/gss.c | 265 +++++++++++++++++++++++++++---------- src/windows/gss/gss.h | 2 +- src/windows/gss/gss.rc | 4 +- 6 files changed, 229 insertions(+), 81 deletions(-) diff --git a/src/windows/gss/changelo b/src/windows/gss/changelo index 2bf618c97..174327a7c 100644 --- a/src/windows/gss/changelo +++ b/src/windows/gss/changelo @@ -1,3 +1,8 @@ +Fri Apr 28 17:07:01 1995 Keith Vetter (keithv@fusion.com) + + * gss-misc.c: bug with reading 4 bytes into a 2 byte entity. + * *.c, *.h, *.rc: changed UI -- not great but better. + Fri Apr 28 11:45:23 1995 Keith Vetter (keithv@fusion.com) * gss.rc: added an icon for the program. @@ -5,3 +10,5 @@ Fri Apr 28 11:45:23 1995 Keith Vetter (keithv@fusion.com) Fri Apr 28 11:20:38 1995 Keith Vetter (keithv@fusion.com) * Initial release + + diff --git a/src/windows/gss/gss-clie.c b/src/windows/gss/gss-clie.c index c567855c0..696b49a2e 100644 --- a/src/windows/gss/gss-clie.c +++ b/src/windows/gss/gss-clie.c @@ -9,7 +9,7 @@ * in advertising or publicity pertaining to distribution of the software * without specific, written prior permission. OpenVision makes no * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. + * purpose. It is provided "as is" without express or implied warranty. * * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO @@ -35,7 +35,7 @@ const_gss_OID gss_nt_string_uid_name = oids+2; const_gss_OID gss_nt_service_name = oids+3; int -gss (char *host, char *name, char *msg, u_short port) +gss (char *host, char *name, char *msg, int port) { if (port == 0 || port == -1) port = 4444; diff --git a/src/windows/gss/gss-misc.c b/src/windows/gss/gss-misc.c index fc41a834d..592ecc7c0 100644 --- a/src/windows/gss/gss-misc.c +++ b/src/windows/gss/gss-misc.c @@ -50,7 +50,8 @@ int send_token(int s, gss_buffer_t tok) { ret = send (s, (char *) &len, 4, 0); // Send length over the socket if (ret < 0) { - my_perror("sending token length"); + errno = WSAGetLastError(); + my_perror("sending token length"); return -1; } else if (ret != 4) { OkMsgBox ("sending token length: %d of %d bytes written\n", @@ -60,6 +61,7 @@ int send_token(int s, gss_buffer_t tok) { ret = send (s, tok->value, tok->length, 0); // Send the data if (ret < 0) { + errno = WSAGetLastError(); my_perror("sending token data"); return -1; } else if (ret != tok->length) { @@ -97,8 +99,9 @@ recv_token (int s, gss_buffer_t tok) { int ret; unsigned long len; - ret = recv (s, (char *) &tok->length, 4, 0); + ret = recv (s, (char *) &len, 4, 0); if (ret < 0) { + errno = WSAGetLastError(); my_perror("reading token length"); return -1; } else if (ret != 4) { @@ -107,7 +110,7 @@ recv_token (int s, gss_buffer_t tok) { return -1; } - len = ntohl(tok->length); + len = ntohl(len); tok->length = (size_t) len; tok->value = (char *) malloc(tok->length); if (tok->value == NULL) { @@ -117,6 +120,7 @@ recv_token (int s, gss_buffer_t tok) { ret = recv (s, (char *) tok->value, tok->length, 0); if (ret < 0) { + errno = WSAGetLastError(); my_perror("reading token data"); free(tok->value); return -1; @@ -172,7 +176,13 @@ display_status_1(char *m, OM_uint32 code, int type) { break; } } - +/*+************************************************************************* +** +** OkMsgBox +** +** A MessageBox version of printf +** +***************************************************************************/ void OkMsgBox (char *format, ...) { char buf[256]; // Message goes into here @@ -180,9 +190,15 @@ OkMsgBox (char *format, ...) { args = (char *) &format + sizeof(format); vsprintf (buf, format, args); - MessageBox(NULL, buf, NULL, MB_OK); + MessageBox(NULL, buf, "", MB_OK); } - +/*+************************************************************************* +** +** My_perror +** +** A windows conversion of perror displaying the output into a MessageBox. +** +***************************************************************************/ void my_perror (char *msg) { char *err; diff --git a/src/windows/gss/gss.c b/src/windows/gss/gss.c index 9a8e12237..9708a8568 100644 --- a/src/windows/gss/gss.c +++ b/src/windows/gss/gss.c @@ -3,10 +3,9 @@ ** GSS test - Windows scaffolding to test the gssapi dll ** ** Given a hostname it does the equivalent of the Unix command -** ./gss-client host@ "msg" +** ./gss-client [-port ] host@ "msg" ** ***************************************************************************/ - #include #include #include "gss.h" @@ -15,65 +14,95 @@ #define GSS_OK 100 #define GSS_CANCEL 101 -char szConnectName[256]; -char szServiceName[256]; +#define GSSAPI_INI "kerberos.ini" // Which INI file +#define INI_HOSTS "GSSAPI Hosts" // INI file section +#define INI_HOST "Host" // INI file line label + +#define MAX_HOSTS 9 +char hosts[MAX_HOSTS][128]; + +char szHost[128]; // GSSAPI Host to connect to +char szServiceName[128]; // Service to do +int port = 0; // Which port to use -int PASCAL +static void do_gssapi_test (char *name); +static void parse_name (char *name); +static int read_hosts(void); +static void write_hosts (void); +static void update_hosts (char *name); +static void fill_combo (HWND hDlg); + +/*+************************************************************************* +** +** WinMain +** +** Sets up the Dialog that drives our program +** +***************************************************************************/ +int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow) HANDLE hInstance, hPrevInstance; LPSTR lpszCmdLine; int nCmdShow; { - int n; // Return value FARPROC lpfnDlgProc; lpfnDlgProc = MakeProcInstance(OpenGssapiDlg, hInstance); - n = DialogBox (hInstance, "OPENGSSAPIDLG", NULL, lpfnDlgProc); + DialogBox (hInstance, "OPENGSSAPIDLG", NULL, lpfnDlgProc); FreeProcInstance(lpfnDlgProc); - if (n) { - strcpy (szServiceName, "host@"); - strcat (szServiceName, szConnectName); - n = gss (szConnectName, szServiceName, "Test Gssapi Message", 0); - if (n) - MessageBox (NULL, "gss failed", "", IDOK | MB_ICONINFORMATION); - } - return 0; } +/*+************************************************************************* +** +** Do_gssapi_test +** +** Does the actual call to GSS-client +** +***************************************************************************/ +void +do_gssapi_test (char *name) { + int n; // Return value + HCURSOR hcursor; // For the hourglass cursor -/*+*************************************************************************** - - FUNCTION: OpenGssapiDlg(HWND, unsigned, WORD, LONG) - - PURPOSE: Processes messages for "Open Gssapi Connection" dialog box - - MESSAGES: + parse_name(name); // Get host, service and port - WM_INITDIALOG - initialize dialog box - WM_COMMAND - Input received + hcursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); + n = gss (szHost, szServiceName, "Test Gssapi Message", port); + SetCursor(hcursor); -****************************************************************************/ + if (n) + MessageBox (NULL, "gss failed", "", IDOK | MB_ICONINFORMATION); +} -BOOL FAR PASCAL OpenGssapiDlg( +/*+************************************************************************* +** +** OpenGssapiDlg(HWND, unsigned, WORD, LONG) +** +** Processes messages for "Open Gssapi Connection" dialog box +** +** Messages: +** WM_INITDIALOG - initialize dialog box +** WM_COMMAND - Input received +** +***************************************************************************/ +BOOL FAR PASCAL +OpenGssapiDlg( HWND hDlg, WORD message, WORD wParam, LONG lParam) { - HDC hDC; - int xExt, yExt; - DWORD Ext; -// HWND hEdit; -// int n; -// int iHostNum = 0; -// char tmpName[128]; -// char tmpBuf[80]; -// char *tmpCommaLoc; - - switch (message) { + HDC hDC; // For getting graphic info + DWORD Ext; // Size of dialog + int xExt, yExt; // Size broken apart + char hostname[128]; // What the user typed + switch (message) { case WM_INITDIALOG: + /* + ** First center the dialog + */ hDC = GetDC(hDlg); Ext = GetDialogBaseUnits(); xExt = (190 *LOWORD(Ext)) /4 ; @@ -82,51 +111,147 @@ BOOL FAR PASCAL OpenGssapiDlg( (GetSystemMetrics(SM_CXSCREEN)/2)-(xExt/2), (GetSystemMetrics(SM_CYSCREEN)/2)-(yExt/2), 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); - ReleaseDC(hDlg, hDC); -// GetPrivateProfileString(INI_HOSTS, INI_HOST "0", "", tmpName, -// 128, TELNET_INI); -// if (tmpName[0]) { -// tmpCommaLoc = strchr(tmpName, ','); -// if (tmpCommaLoc) -// *tmpCommaLoc = '\0'; -// SetDlgItemText(hDlg, GSS_CONNECT_NAME, tmpName); -// } -// hEdit = GetWindow(GetDlgItem(hDlg, GSS_CONNECT_NAME), GW_CHILD); -// while (TRUE) { -// wsprintf(tmpBuf, INI_HOST "%d", iHostNum++); -// GetPrivateProfileString(INI_HOSTS, tmpBuf, "", tmpName, -// 128, TELNET_INI); -// tmpCommaLoc = strchr(tmpName, ','); -// if (tmpCommaLoc) -// *tmpCommaLoc = '\0'; -// if (tmpName[0]) -// SendDlgItemMessage(hDlg, GSS_CONNECT_NAME, CB_ADDSTRING, 0, -// (LPARAM) ((LPSTR) tmpName)); -// else -// break; -// } -// SendMessage(hEdit, WM_USER+1, NULL, NULL); + ReleaseDC(hDlg, hDC); + + read_hosts (); // Get the host list + fill_combo (hDlg); // Put into combo box + SendMessage(hDlg, WM_SETFOCUS, NULL, NULL); return (TRUE); case WM_COMMAND: switch (wParam) { - case GSS_CANCEL: + case GSS_CANCEL: // Only way out of the dialog + case IDCANCEL: // From the menu EndDialog(hDlg, FALSE); break; - + case GSS_OK: - GetDlgItemText(hDlg, GSS_CONNECT_NAME, szConnectName, 256); - if (! *szConnectName) { + GetDlgItemText(hDlg, GSS_CONNECT_NAME, hostname, 128); + SendDlgItemMessage(hDlg, GSS_CONNECT_NAME, CB_SHOWDROPDOWN, + FALSE, NULL); + + if (! *hostname) { MessageBox(hDlg, "You must enter a host name", NULL, MB_OK); break; } - EndDialog(hDlg, TRUE); + do_gssapi_test (hostname); // Test GSSAPI + update_hosts (hostname); // Add it to the host list + fill_combo (hDlg); // Update the combo box + + //EndDialog(hDlg, TRUE); break; - } - return (FALSE); + } + return FALSE; } - return(FALSE); + return FALSE; + +} +/*+************************************************************************* +** +** Parse_name +** +** Turns NAME which the user entered into host, service and port. +** The host is up to first space, port is after that and service is made +** from host. +** +***************************************************************************/ +static void +parse_name (char *name) { + char *ptr; -} /* OpenGssapiDlg */ + strcpy (szHost, name); + ptr = strchr (szHost, ' '); // Is there a port??? + if (ptr) { // Yep, start parsing it + port = atoi (ptr+1); + *ptr = '\0'; + } + wsprintf (szServiceName, "host@%s", szHost); // Make the service name +} +/*+************************************************************************* +** +** Read_hosts +** +** Reads all the hosts listed in the INI file. +** +***************************************************************************/ +static int +read_hosts (void) { + int i; // Index + char buff[10]; + + for (i = 0; MAX_HOSTS; ++i) { // Read this many entries + wsprintf (buff, INI_HOST "%d", i); + GetPrivateProfileString(INI_HOSTS, buff, "", hosts[i], 128, GSSAPI_INI); + if (*hosts[i] == '\0') // No more entries??? + break; + } + + return i; +} +/*+************************************************************************* +** +** Write_hosts +** +** Writes the hosts list back to the ini file. +** +***************************************************************************/ +static void +write_hosts () { + int i; // Index + char buff[10]; + + for (i = 0; i < MAX_HOSTS; ++i) { + if (*hosts[i] == '\0') // End of the list? + break; + wsprintf (buff, INI_HOST "%d", i); + WritePrivateProfileString(INI_HOSTS, buff, hosts[i], GSSAPI_INI); + } +} +/*+************************************************************************* +** +** Update_hosts +** +** Updates the host list with the new NAME the user typed. +** +***************************************************************************/ +static void +update_hosts (char *name) { + int i; // Index + + for (i = 0; i < MAX_HOSTS-1; ++i) { // Find it in the list + if (! _stricmp (name, hosts[i])) // A match + break; + if (*hosts[i] == '\0') // End of the list + break; + } + memmove (hosts[1], hosts[0], i * sizeof(hosts[0])); // Move the data down + strcpy (hosts[0], name); // Insert this item + + write_hosts (); +} +/*+************************************************************************* +** +** Fill_combo +** +** Fills the combo box with the contents of the host list. Item 0 goes +** into the edit portion and the rest go into the libt box. +** +***************************************************************************/ +static void +fill_combo (HWND hDlg) { + int i; // Index + + SendDlgItemMessage(hDlg, GSS_CONNECT_NAME, CB_RESETCONTENT, NULL, NULL); + + SetDlgItemText(hDlg, GSS_CONNECT_NAME, hosts[0]); + SendDlgItemMessage(hDlg, GSS_CONNECT_NAME, CB_SETEDITSEL, NULL, NULL); + + for (i = 1; i < MAX_HOSTS; ++i) { // Fill in the list box + if (*hosts[i] == '\0') + break; + SendDlgItemMessage(hDlg, GSS_CONNECT_NAME, CB_ADDSTRING, 0, + (LPARAM) ((LPSTR) hosts[i])); + } +} diff --git a/src/windows/gss/gss.h b/src/windows/gss/gss.h index 5a943fb10..1a3778a95 100644 --- a/src/windows/gss/gss.h +++ b/src/windows/gss/gss.h @@ -23,7 +23,7 @@ void OkMsgBox (char *format, ...); void my_perror (char *msg); // gss-client.c -int gss (char *host, char *name, char *msg, u_short port); +int gss (char *host, char *name, char *msg, int port); int call_server(char *host, u_short port, char *service_name, char *msg); int connect_to_server(char *host, u_short port); int client_establish_context(int s, char *service_name, gss_ctx_id_t *gss_context); diff --git a/src/windows/gss/gss.rc b/src/windows/gss/gss.rc index 697978df4..f7c829d07 100644 --- a/src/windows/gss/gss.rc +++ b/src/windows/gss/gss.rc @@ -21,8 +21,8 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "To Host:", -1, "STATIC", NOT WS_GROUP, 3, 10, 33, 10 CONTROL "", GSS_CONNECT_NAME, "COMBOBOX", CBS_DROPDOWN | WS_VSCROLL | WS_GROUP | WS_TABSTOP, 42, 9, 128, 60 - CONTROL "OK", GSS_OK, "BUTTON", WS_GROUP | WS_TABSTOP | BS_DEFPUSHBUTTON, 27, 30, 51, 14 - CONTROL "Cancel", GSS_CANCEL, "BUTTON", WS_TABSTOP, 97, 30, 51, 14 + CONTROL "Test", GSS_OK, "BUTTON", WS_GROUP | WS_TABSTOP | BS_DEFPUSHBUTTON, 27, 30, 51, 14 + CONTROL "Exit", GSS_CANCEL, "BUTTON", WS_TABSTOP, 97, 30, 51, 14 END -- 2.26.2