+Fri Apr 7 15:03:10 1995 Keith Vetter (keithv@fusion.com)
+
+ * cns.c, cns.h, cns.rc: added option dialog widget allowing user
+ to specify where the ccache lives. Also, default name and realm
+ is now pulled from the ccache everytime you select one.
+ * cns.c: fixed memory leak in k5_dest_tkt.
+
Wed Apr 5 16:01:16 1995 Keith Vetter (keithv@fusion.com)
* cns.h, cns.rc, cns.c: GUI changes: re-order and resize
#include "krbini.h"
#include "com_err.h"
- #define DEFAULT_TKT_LIFE 120
+ #define DEFAULT_TKT_LIFE 120 // In 5 minute units
#define ANAME_SZ 40
#define REALM_SZ 40
#define SNAME_SZ 40
static HFONT hfonticon = NULL; /* Font for icon label */
static HINSTANCE hinstance;
static int dlgncmdshow; /* ncmdshow from WinMain */
-static char confname[FILENAME_MAX]; /* current krb.conf location */
-static char realmsname[FILENAME_MAX]; /* current krb.realms location */
static UINT wm_kerberos_changed; /* Registered message for cache changing */
static int action; /* After login actions */
static UINT kwin_timer_id; /* Timer being used for update */
#ifdef KRB5
krb5_context k5_context;
krb5_ccache k5_ccache;
+ static char ccname[FILENAME_MAX]; /* ccache file location */
#endif
/*+
LPARAM lparam)
{
char defname[FILENAME_MAX];
+ char newname[FILENAME_MAX];
UINT rc;
int lifetime;
center_dialog(hwnd);
set_dialog_font(hwnd, hfontdialog);
- /* krb.conf file */
+/* krb.conf file */
rc = GetWindowsDirectory(defname, sizeof(defname));
assert(rc > 0);
strcat(defname, "\\");
strcat(defname, DEF_KRB_CONF);
GetPrivateProfileString(INI_FILES, INI_KRB_CONF, defname,
- confname, sizeof(confname), KERBEROS_INI);
- _strupr(confname);
- SetDlgItemText(hwnd, IDD_CONF, confname);
+ newname, sizeof(newname), KERBEROS_INI);
+ _strupr(newname);
+ SetDlgItemText(hwnd, IDD_CONF, newname);
- /* krb.realms file */
+/* krb.realms file */
rc = GetWindowsDirectory(defname, sizeof(defname));
assert(rc > 0);
strcat(defname, "\\");
strcat(defname, DEF_KRB_REALMS);
GetPrivateProfileString(INI_FILES, INI_KRB_REALMS, defname,
- realmsname, sizeof(realmsname), KERBEROS_INI);
- _strupr(realmsname);
- SetDlgItemText(hwnd, IDD_REALMS, realmsname);
+ newname, sizeof(newname), KERBEROS_INI);
+ _strupr(newname);
+ SetDlgItemText(hwnd, IDD_REALMS, newname);
- /* Ticket duration */
+/* Credential cache file */
+ #ifdef KRB5
+ rc = GetWindowsDirectory(defname, sizeof(defname));
+ assert(rc > 0);
+
+ strcat(defname, "\\");
+ strcat(defname, "krb5cc");
+ GetPrivateProfileString(INI_FILES, INI_KRB_CCACHE, defname,
+ ccname, sizeof(ccname), KERBEROS_INI);
+ _strupr(ccname);
+ SetDlgItemText(hwnd, IDD_CCACHE, ccname);
+ #endif /* KRB5 */
+
+/* Ticket duration */
lifetime = GetPrivateProfileInt(INI_OPTIONS, INI_DURATION,
DEFAULT_TKT_LIFE * 5, KERBEROS_INI);
SetDlgItemInt(hwnd, IDD_LIFETIME, lifetime, FALSE);
- /* Expiration action */
+/* Expiration action */
GetPrivateProfileString(INI_EXPIRATION, INI_ALERT, "No",
defname, sizeof(defname), KERBEROS_INI);
alert = _stricmp(defname, "Yes") == 0;
LPARAM lparam)
{
char defname[FILENAME_MAX];
+ char newname[FILENAME_MAX];
char *p;
BOOL b;
int lifetime;
int rc;
switch (wparam) {
-
case IDOK:
- /* Ticket duration */
+/* Ticket duration */
lifetime = GetDlgItemInt(hwnd, IDD_LIFETIME, &b, FALSE);
if (!b) {
MessageBox(hwnd, "Lifetime must be a number!", "", MB_OK | MB_ICONEXCLAMATION);
-
return TRUE;
}
b = WritePrivateProfileString(INI_OPTIONS, INI_DURATION, defname, KERBEROS_INI);
assert(b);
- /* krb.conf file */
- GetDlgItemText(hwnd, IDD_CONF, confname, sizeof(confname));
- trim(confname);
+/* krb.conf file */
+ GetDlgItemText(hwnd, IDD_CONF, newname, sizeof(newname));
+ trim(newname);
rc = GetWindowsDirectory(defname, sizeof(defname));
assert(rc > 0);
strcat(defname, "\\");
strcat(defname, DEF_KRB_CONF);
- if (_stricmp(confname, defname) == 0 || !confname[0])
+ if (_stricmp(newname, defname) == 0 || !newname[0])
p = NULL;
else
- p = confname;
+ p = newname;
b = WritePrivateProfileString(INI_FILES, INI_KRB_CONF, p, KERBEROS_INI);
assert(b);
- /* krb.realms file */
- GetDlgItemText(hwnd, IDD_REALMS, realmsname, sizeof(realmsname));
- trim(realmsname);
+/* krb.realms file */
+ GetDlgItemText(hwnd, IDD_REALMS, newname, sizeof(newname));
+ trim(newname);
rc = GetWindowsDirectory(defname, sizeof(defname));
assert(rc > 0);
strcat(defname, "\\");
strcat(defname, DEF_KRB_REALMS);
- if (_stricmp(realmsname, defname) == 0 || !realmsname[0])
+ if (_stricmp(newname, defname) == 0 || !newname[0])
p = NULL;
else
- p = realmsname;
+ p = newname;
b = WritePrivateProfileString(INI_FILES, INI_KRB_REALMS, p, KERBEROS_INI);
assert(b);
- /* Expiration action */
+/* Credential cache file */
+ #ifdef KRB5
+ GetDlgItemText(hwnd, IDD_CCACHE, newname, sizeof(newname));
+ trim(newname);
+ rc = GetWindowsDirectory(defname, sizeof(defname));
+ assert(rc > 0);
+
+ strcat(defname, "\\");
+ strcat(defname, "krb5cc");
+ if (*newname == '\0')
+ strcpy (newname, defname);
+ if (_stricmp(newname, defname) == 0 || *newname == '\0')
+ p = NULL;
+ else
+ p = newname;
+ b = WritePrivateProfileString(INI_FILES, INI_KRB_CCACHE, p, KERBEROS_INI);
+ assert(b);
+
+ if (strcmp (ccname, newname)) { // Did we change ccache file?
+ krb5_error_code code;
+ krb5_ccache cctemp;
+
+ code = k5_init_ccache (&cctemp);
+ if (code) { // Problem opening new one?
+ com_err (NULL, code,
+ "while changing ccache.\r\nRestoring old ccache.");
+ b = WritePrivateProfileString(INI_FILES, INI_KRB_CCACHE,
+ ccname, KERBEROS_INI);
+ } else {
+ code = krb5_cc_close (k5_context, k5_ccache);
+ k5_ccache = cctemp; // Copy new into old
+ if (k5_name_from_ccache (k5_ccache)) {
+ kwin_init_name (GetParent(hwnd), "");
+ kwin_set_default_focus(GetParent(hwnd));
+ }
+ ticket_init_list (GetDlgItem (GetParent(hwnd),
+ IDD_TICKET_LIST));
+ }
+ }
+
+ #endif /* KRB5 */
+
+/* Expiration action */
alert = (BOOL) SendDlgItemMessage(hwnd, IDD_ALERT, BM_GETCHECK, 0, 0);
p = (alert) ? "Yes" : "No";
b = WritePrivateProfileString(INI_EXPIRATION, INI_ALERT, p, KERBEROS_INI);
krc = krb_get_lrealm(realm, 1);
if (krc != KSUCCESS)
realm[0] = 0;
+ GetPrivateProfileString(INI_DEFAULTS, INI_REALM, realm,
+ realm, sizeof(realm), KERBEROS_INI);
#endif
GetPrivateProfileString (INI_DEFAULTS, INI_USER, "",
name, sizeof(name), KERBEROS_INI);
- //GetPrivateProfileString(INI_DEFAULTS, INI_INSTANCE, "",
- // instance, sizeof(instance), KERBEROS_INI);
- *instance = '\0';
*realm = '\0';
code = krb5_get_default_realm (k5_context, &ptr);
strcpy (realm, ptr);
free (ptr);
}
+ GetPrivateProfileString(INI_DEFAULTS, INI_REALM, realm,
+ realm, sizeof(realm), KERBEROS_INI);
}
#endif
- GetPrivateProfileString(INI_DEFAULTS, INI_REALM, realm,
- realm, sizeof(realm), KERBEROS_INI);
} else {
#ifdef KRB4
kname_parse(name, instance, realm, fullname);
+ SetDlgItemText(hwnd, IDD_LOGIN_INSTANCE, instance);
#endif
#ifdef KRB5
}
SetDlgItemText(hwnd, IDD_LOGIN_NAME, name);
- name[0] = 0;
- GetDlgItemText(hwnd, IDD_LOGIN_NAME, name, sizeof(name));
SetDlgItemText(hwnd, IDD_LOGIN_REALM, realm);
- #ifdef KRB4
- SetDlgItemText(hwnd, IDD_LOGIN_INSTANCE, instance);
- #endif
-
} /* kwin_init_name */
creds.client = principal;
creds.server = server;
- //code = krb5_timeofday(k5_context, &now);
- //if (code) break;
code = krb5_us_timeofday(k5_context, &sec, &usec);
if (code) break;
-//if (labs(now-sec) > 60*60) { // Off by more than an hour
-// MessageBox (NULL, "DEBUG: timeofday != us_timeofday", NULL, 0);
-// now = sec;
-//}
+ code = krb5_timeofday(k5_context, &now);
+ if (code) break;
+ if (labs(now-sec) > 60*60) { // Off by more than an hour
+ MessageBox (NULL, "DEBUG: timeofday != us_timeofday", NULL, 0);
+ now = sec;
+ }
creds.times.starttime = 0;
- creds.times.endtime = now + 60L * lifetime;
+ creds.times.endtime = sec + 60L * lifetime;
creds.times.renew_till = 0;
code = krb5_get_in_tkt_with_password(k5_context, 0, NULL,
return TRUE;
case IDM_ABOUT:
+ ticket_init_list(GetDlgItem(hwnd, IDD_TICKET_LIST));
if (isblocking)
return TRUE;
#endif
#ifdef KRB5
- krb5_init_context(&k5_context);
- krb5_init_ets(k5_context);
- krb5_cc_default(k5_context, &k5_ccache);
-
- i = k5_get_num_cred (0); /* Test integrity */
- if (i == -1) {
- remove (krb5_cc_get_name(k5_context, k5_ccache));
- i = k5_get_num_cred (1);
- if (i == -1)
+ {
+ krb5_error_code code;
+
+ code = krb5_init_context(&k5_context);
+ if (! code) {
+ krb5_init_ets(k5_context);
+ code = k5_init_ccache (&k5_ccache);
+ }
+ if (code) {
+ com_err (NULL, code, "while initializing program");
return FALSE;
+ }
+ k5_name_from_ccache (k5_ccache);
}
#endif
k5_dest_tkt (void) {
krb5_error_code code;
krb5_principal princ;
- char *defname; /* Name of cache */
if (code = krb5_cc_get_principal(k5_context, k5_ccache, &princ)) {
com_err (NULL, code, "while retrieving principal name");
return code;
}
- if (code = krb5_unparse_name(k5_context, princ, &defname)) {
- com_err (NULL, code, "while unparsing principal name");
- return code;
- }
code = krb5_cc_initialize (k5_context, k5_ccache, princ);
if (code != 0) {
com_err (NULL, code, "when re-initializing cache");
+ krb5_free_principal (k5_context, princ);
return code;
}
+ krb5_free_principal (k5_context, princ);
return code;
}
return 0;
}
+/*+
+ * Function: Initializes ccache and catches illegal caches such as
+ * bad format or no permissions.
+ *
+ * Parameters:
+ * ccache - credential cache structure to use
+ *
+ * Returns: krb5_error_code
+ */
+static krb5_error_code
+k5_init_ccache (krb5_ccache *ccache) {
+ krb5_error_code code;
+ krb5_principal princ;
+ FILE *fp;
+
+ code = krb5_cc_default (k5_context, ccache); // Initialize the ccache
+ if (code)
+ return code;
+
+ code = krb5_cc_get_principal (k5_context, *ccache, &princ);
+ if (code == KRB5_FCC_NOFILE) { // Doesn't exist yet
+ fp = fopen (krb5_cc_get_name(k5_context, *ccache), "w");
+ if (fp == NULL) // Can't open it
+ return KRB5_FCC_PERM;
+ fclose (fp);
+ }
+
+ if (code) { // Bad, delete and try again
+ remove (krb5_cc_get_name(k5_context, *ccache));
+ code = krb5_cc_get_principal (k5_context, *ccache, &princ);
+ if (code == KRB5_FCC_NOFILE) // Doesn't exist yet
+ return 0;
+ if (code)
+ return code;
+ }
+
+ krb5_free_principal (k5_context, princ);
+ return 0;
+}
+/*+
+ *
+ * Function: Reads the name and realm out of the ccache.
+ *
+ * Parameters:
+ * ccache - credentials cache to get info from
+ *
+ * name - buffer to hold user name
+ *
+ * realm - buffer to hold the realm
+ *
+ *
+ * Returns: TRUE if read names, FALSE if not
+ *
+ */
+static int
+k5_name_from_ccache (krb5_ccache k5_ccache) {
+ krb5_error_code code;
+ krb5_principal princ;
+ char name[ANAME_SZ];
+ char realm[REALM_SZ];
+ char *defname;
+
+ if (code = krb5_cc_get_principal(k5_context, k5_ccache, &princ))
+ return FALSE;
+
+ code = krb5_unparse_name(k5_context, princ, &defname);
+ if (code) {
+ krb5_free_principal (k5_context, princ);
+ return FALSE;
+ }
+
+ k5_kname_parse(name, realm, defname); // Extract the components
+ WritePrivateProfileString(INI_DEFAULTS, INI_USER, name, KERBEROS_INI);
+ WritePrivateProfileString(INI_DEFAULTS, INI_REALM, realm, KERBEROS_INI);
+
+ krb5_free_principal(k5_context, princ);
+ free (defname);
+
+ return TRUE;
+}
#endif /* KRB5 */
#define IDD_LIFETIME 303
#define IDD_BEEP 304
#define IDD_ALERT 305
-
+ #define IDD_CCACHE 306
/*
* Dialog dimensions
*/
* Prototypes
*/
+static void kwin_init_name (HWND hwnd, char *fullname);
+void kwin_set_default_focus (HWND hwnd);
time_t kwin_get_epoch(void);
+
#ifdef KRB5
static krb5_error_code k5_dest_tkt (void);
static int k5_get_num_cred (int verbose);
static int k5_kname_parse (char *name, char *realm, char *fullname);
static int k5_get_lrealm (char *realm);
+ static krb5_error_code k5_init_ccache (krb5_ccache *ccache);
+ static int k5_name_from_ccache (krb5_ccache k5_ccache);
#endif
HICON kwin_get_icon(time_t expiration);
END
#endif /* KRB5 */
-ID_OPTS DIALOG 97, 52, 148, 107
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Kerberos Options"
-FONT 8, "Arial"
-BEGIN
- CONTROL "&Conf file:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 9, 40, 8
- CONTROL "", IDD_CONF, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 60, 6, 82, 12
- CONTROL "&Realms file:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 26, 40, 8
- CONTROL "", IDD_REALMS, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 60, 23, 82, 12
- CONTROL "&Ticket lifetime:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 43, 53, 8
- CONTROL "", IDD_LIFETIME, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 60, 40, 20, 12
- CONTROL "minutes", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 85, 43, 46, 8
- CONTROL "Action when login expires", 209, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 56, 138, 23
- CONTROL "&Alert ", IDD_ALERT, "BUTTON", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 31, 65, 28, 12
- CONTROL "&Beep", IDD_BEEP, "BUTTON", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 80, 65, 39, 12
- CONTROL "OK", IDOK, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 17, 87, 52, 14
- CONTROL "Cancel", IDCANCEL, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 81, 87, 52, 14
-END
+#ifdef KRB4
+ ID_OPTS DIALOG 97, 52, 148, 107
+ STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+ CAPTION "Kerberos Options"
+ FONT 8, "Arial"
+ BEGIN
+ CONTROL "&Conf file:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 9, 40, 8
+ CONTROL "", IDD_CONF, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 60, 6, 82, 12
+ CONTROL "&Realms file:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 26, 40, 8
+ CONTROL "", IDD_REALMS, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 60, 23, 82, 12
+ CONTROL "&Ticket lifetime:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 43, 53, 8
+ CONTROL "", IDD_LIFETIME, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 60, 40, 20, 12
+ CONTROL "minutes", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 85, 43, 46, 8
+ CONTROL "Action when login expires", 209, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 56, 138, 23
+ CONTROL "&Alert ", IDD_ALERT, "BUTTON", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 31, 65, 28, 12
+ CONTROL "&Beep", IDD_BEEP, "BUTTON", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 80, 65, 39, 12
+ CONTROL "OK", IDOK, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 17, 87, 52, 14
+ CONTROL "Cancel", IDCANCEL, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 81, 87, 52, 14
+ END
+#endif /* KRB4 */
+
+#ifdef KRB5
+ ID_OPTS DIALOG 97, 52, 158, 124
+ STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+ CAPTION "Kerberos Options"
+ FONT 8, "Arial"
+ BEGIN
+ CONTROL "&Conf file:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 9, 40, 8
+ CONTROL "", IDD_CONF, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 70, 6, 82, 12
+ CONTROL "&Realms file:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 26, 40, 8
+ CONTROL "", IDD_REALMS, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 70, 23, 82, 12
+ CONTROL "Cre&dential cache:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 43, 58, 8
+ CONTROL "", IDD_CCACHE, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 70, 40, 82, 12
+ CONTROL "&Ticket lifetime:", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 5, 60, 53, 8
+ CONTROL "", IDD_LIFETIME, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 70, 57, 20, 12
+ CONTROL "minutes", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE, 95, 60, 46, 8
+ CONTROL "Action when login expires", 209, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE | WS_GROUP, 5, 73, 148, 23
+ CONTROL "&Alert ", IDD_ALERT, "BUTTON", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 36, 82, 28, 12
+ CONTROL "&Beep", IDD_BEEP, "BUTTON", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 85, 82, 39, 12
+ CONTROL "OK", IDOK, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 22, 104, 52, 14
+ CONTROL "Cancel", IDCANCEL, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 86, 104, 52, 14
+ END
+#endif /* KRB5 */
+
+Fri Apr 7 15:14:07 1995 Keith Vetter (keithv@fusion.com)
+
+ * telnet.c, wt-proto.h: port numbers better supported. You can
+ now specify '<host> <port>' in the initial dialog. This gets
+ saved in the ini file.
+
Wed Apr 5 16:18:30 1995 Keith Vetter (keithv@fusion.com)
* screen.c, screen.h, dialog.h, telnet.rc: added an about
char __near strTmp[1024]; // Scratch buffer
BOOL bAutoConnection = FALSE;
-char szAutoHostName[64];
int port_no = 23;
-char szUserName[64];
+char szUserName[64]; // Used in auth.c
char szHostName[64];
#ifdef KRB4
/* Perform initializations that apply to a specific instance */
- parse_cmdline (lpCmdLine);
+ bAutoConnection = parse_cmdline (lpCmdLine);
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
/*+***************************************************************************
- FUNCTION: SaveHostName(hostname)
+ FUNCTION: SaveHostName(hostname, port)
- PURPOSE: Saves the currently selected host name in the KERBEROS.INI file
- and returns the preferred backspace setting if one exists for
- that host.
+ PURPOSE: Saves the currently selected host name and port number
+ in the KERBEROS.INI file and returns the preferred backspace
+ setting if one exists for that host.
RETURNS: VK_BACK or 0x7f depending on the desired backspace setting.
****************************************************************************/
int
-SaveHostName(char *host)
+SaveHostName (char *host, int port)
{
- char buf[128];
- char hostName[10][128];
- char *tmpCommaLoc;
- char tmpName[128];
- char tmpBuf[80];
- int nhosts;
- int n;
- int iHostNum;
- int bs;
-
- nhosts = 0;
- for (iHostNum = 0; iHostNum < 10; iHostNum++) {
- wsprintf(tmpBuf, INI_HOST "%d", iHostNum);
- GetPrivateProfileString(INI_HOSTS, tmpBuf, "", hostName[iHostNum],
+ char buf[128]; // Scratch buffer
+ char fullhost[128]; // Host & port combination
+ char hostName[10][128]; // Entries from INI files
+ char *comma; // For parsing del/bs info
+ int len; // Length of fullhost
+ int n; // Number of items written
+ int i; // Index
+ int bs; // What we return
+
+ if (port == 23) // Default telnet port
+ strcpy (fullhost, host); // ...then don't add it on
+ else
+ wsprintf (fullhost, "%s %d", host, port);
+ len = strlen (fullhost);
+
+ comma = NULL;
+ for (i = 0; i < 10; i++) {
+ wsprintf(buf, INI_HOST "%d", i); // INI item to fetch
+ GetPrivateProfileString(INI_HOSTS, buf, "", hostName[i],
128, TELNET_INI);
- strcpy(tmpName, hostName[iHostNum]);
- tmpCommaLoc = strchr(tmpName, ',');
- if (tmpCommaLoc) {
- *tmpCommaLoc = '\0';
- while (tmpCommaLoc[1] == ' ')
- tmpCommaLoc++;
- }
- if (!hostName[iHostNum][0])
- break;
- nhosts++;
- if (strcmp(tmpName, host) == 0)
- break;
- }
- for (iHostNum++; iHostNum < 10; iHostNum++) {
- wsprintf(tmpBuf, INI_HOST "%d", iHostNum);
- GetPrivateProfileString(INI_HOSTS, tmpBuf, "", hostName[iHostNum],
- 128, TELNET_INI);
- if (!hostName[iHostNum][0])
+ if (!hostName[i][0])
break;
- nhosts++;
- }
- if (tmpCommaLoc)
- tmpCommaLoc++;
+ if (strncmp (hostName[i], fullhost, len)) // A match??
+ continue; // Nope, keep going
+ comma = strchr (hostName[i], ',');
+ }
- if (tmpName[0] && tmpCommaLoc) {
- if (_stricmp(tmpCommaLoc, INI_HOST_DEL) == 0)
+ if (comma) {
+ while (*comma == ' ') // Past leading white space
+ ++comma;
+ bs = VK_BACK; // Default for unknown entry
+ if (_stricmp(comma, INI_HOST_DEL) == 0)
bs = 0x7f;
- else if (_stricmp(tmpCommaLoc, INI_HOST_BS) == 0)
- bs = VK_BACK;
}
- else {
+ else { // No matching entry
GetPrivateProfileString(INI_TELNET, INI_BACKSPACE, INI_BACKSPACE_BS,
- tmpBuf, sizeof(tmpBuf), TELNET_INI);
- if (_stricmp(tmpBuf, INI_BACKSPACE_DEL) == 0)
+ buf, sizeof(buf), TELNET_INI);
+ bs = VK_BACK; // Default value
+ if (_stricmp(buf, INI_BACKSPACE_DEL) == 0)
bs = 0x7f;
- else
- bs = VK_BACK;
}
- strcpy(buf, tmpConfig->title);
+ /*
+ ** Build up default host name
+ */
+ strcpy(buf, fullhost);
strcat(buf, ", ");
- if (bs == VK_BACK)
- strcat(buf, INI_BACKSPACE_BS);
- else
- strcat(buf, INI_BACKSPACE_DEL);
-
+ strcat(buf, (bs == VK_BACK) ? INI_BACKSPACE_BS : INI_BACKSPACE_DEL);
WritePrivateProfileString(INI_HOSTS, INI_HOST "0", buf, TELNET_INI);
- n = 1;
- for (iHostNum = 0; iHostNum < nhosts; iHostNum++) {
- strcpy(tmpName, hostName[iHostNum]);
- tmpCommaLoc = strchr(tmpName, ',');
- if (tmpCommaLoc) {
- *tmpCommaLoc = '\0';
- while (tmpCommaLoc[1] == ' ')
- tmpCommaLoc++;
- }
- if (strcmp(tmpName, host) != 0) {
- wsprintf(tmpBuf, INI_HOST "%d", n++);
- WritePrivateProfileString(INI_HOSTS, tmpBuf, hostName[iHostNum],
+
+ n = 0;
+ for (i = 0; i < 10; i++) {
+ if (!hostName[i][0]) // End of the list?
+ break;
+ if (strncmp(hostName[i], fullhost, len) != 0) {
+ wsprintf(buf, INI_HOST "%d", ++n);
+ WritePrivateProfileString(INI_HOSTS, buf, hostName[i],
TELNET_INI);
}
}
- return (bs);
+ return bs;
}
/*+*/
tmpConfig = (CONFIG *) GlobalLock(hGlobalMem);
if (bAutoConnection) {
- hTitleMem = GlobalAlloc(GPTR, lstrlen(szAutoHostName));
+ hTitleMem = GlobalAlloc(GPTR, lstrlen(szHostName));
tmpConfig->title = (char *) GlobalLock(hTitleMem);
- lstrcpy(tmpConfig->title, (char *) szAutoHostName);
+ lstrcpy(tmpConfig->title, (char *) szHostName);
} else {
nReturn = DoDialog("OPENTELNETDLG", OpenTelnetDlg);
if (nReturn == FALSE) return(FALSE);
con->width = tmpConfig->width;
con->height = tmpConfig->height;
- con->backspace = SaveHostName(tmpConfig->title);
+ con->backspace = SaveHostName(tmpConfig->title, port_no);
if (con->backspace == VK_BACK) {
tmpConfig->backspace = TRUE;
int xExt, yExt;
DWORD Ext;
HWND hEdit;
- int nLen;
+ int n;
int iHostNum = 0;
char tmpName[128], tmpBuf[80];
char *tmpCommaLoc;
case WM_COMMAND: /* message: received a command */
switch (wParam) {
- case TEL_CANCEL:
- EndDialog(hDlg, FALSE); /* Exits the dialog box */
- break;
+ case TEL_CANCEL:
+ EndDialog(hDlg, FALSE); /* Exits the dialog box */
+ break;
- case TEL_OK:
- GetDlgItemText(hDlg, TEL_CONNECT_NAME, szConnectName, 256);
- nLen = lstrlen(szConnectName);
- if (nLen == 0) {
- MessageBox(hDlg, "You must enter a session name!",
- NULL, MB_OK);
- break;
- }
- hTitleMem = GlobalAlloc(GPTR, nLen);
- tmpConfig->title = (char *) GlobalLock(hTitleMem);
- lstrcpy(tmpConfig->title, szConnectName);
- EndDialog(hDlg, TRUE);
- break;
+ case TEL_OK:
+ GetDlgItemText(hDlg, TEL_CONNECT_NAME, szConnectName, 256);
+
+ n = parse_cmdline (szConnectName);
+ if (! n) {
+ MessageBox(hDlg, "You must enter a session name!",
+ NULL, MB_OK);
+ break;
+ }
+
+ hTitleMem = GlobalAlloc(GPTR, lstrlen(szHostName)+1);
+ tmpConfig->title = (char *) GlobalLock(hTitleMem);
+ lstrcpy(tmpConfig->title, szConnectName);
+ EndDialog(hDlg, TRUE);
+ break;
}
return (FALSE);
}
** telnet <host> <port no>
** telnet -p <port no>
**
+** Returns: TRUE if we have a hostname
*/
-void
+BOOL
parse_cmdline (char *cmdline) {
char *ptr;
- bAutoConnection = FALSE; // Initialize to off
+ *szHostName = '\0'; // Nothing yet
if (*cmdline == '\0') // Empty command line?
- return;
+ return FALSE;
trim (cmdline); // Remove excess spaces
ptr = strchr (cmdline, ' '); // Find 2nd token
}
if (*cmdline != '-' && *cmdline != '/') { // Host name given
- bAutoConnection = TRUE;
- lstrcpy (szAutoHostName, cmdline);
+ lstrcpy (szHostName, cmdline);
+ return TRUE;
}
+
+ return FALSE;
}
int OpenTelnetConnection(void);
int NEAR DoDialog(char *szDialog, FARPROC lpfnDlgProc);
-void parse_cmdline (char *cmdline);
+BOOL parse_cmdline (char *cmdline);
///HCONNECTION FindConnectionFromPortNum(int ID);
///HCONNECTION FindConnectionFromTelstate(int telstate);