From eac84f862cc258b9515196d9c30777a7e261b872 Mon Sep 17 00:00:00 2001 From: Keith Vetter Date: Thu, 23 Mar 1995 03:46:07 +0000 Subject: Work around of fscanf which is not available in a windows DLL git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5202 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 5 ++++ src/lib/krb5/os/hst_realm.c | 62 +++++++++++++++++++++++++++++++++++++++++++-- src/lib/krb5/os/realm_dom.c | 59 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 122 insertions(+), 4 deletions(-) (limited to 'src/lib/krb5') diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index d6a791e5f..d8363b65a 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 22 18:59:47 1995 Keith Vetter (keithv@fusion.com) + + * hst_realm.c, realm_dom.c: windows DLL can't use fscanf so had + to write a couple of routines to read what we need from the file. + Wed Mar 22 13:30:35 1995 Keith Vetter (keithv@fusion.com) * an_to_ln.c, kuserok.c: last two os routines ported to the PC. diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index 00c46ca93..b05f013c3 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -81,6 +81,56 @@ extern char *krb5_trans_file; +#ifdef _WINDOWS +/* + * Windows DLL can't use the fscanf routine. We need fscanf to read + * in the host and realm. Read_2str with read_1str duplicate the needed + * functionality. See also realm_dom.c. + */ +static int +read_1str (FILE *fp, char *buf, int buflen) { + int c; + + while (1) { + c = fgetc (fp); /* Past leading whitespace */ + if (c == EOF) + return 0; + if (! isspace (c)) + break; + } + + while (1) { + if (buflen > 0) { /* Store the character */ + *buf++ = (char) c; + --buflen; + } + if (buflen <= 0) /* Fscanf stops scanning... */ + break; /* ...when buffer is full */ + + c = fgetc (fp); /* Get next character */ + if (c == EOF || isspace (c)) + break; + } + + if (buflen) /* Make ASCIIZ if room */ + *buf = '\0'; + + return 1; +} + +static int +read_2str (FILE *fp, char *b1, int l1, char *b2, int l2) { + int n; + + n = read_1str (fp, b1, l1); /* Read first string */ + if (!n) return EOF; + n = read_1str (fp, b2, l2); /* Read second string */ + if (!n) return 1; + return 2; +} + +#endif /* _WINDOWS */ + krb5_error_code INTERFACE krb5_get_host_realm(context, host, realmsp) krb5_context context; @@ -136,8 +186,13 @@ krb5_get_host_realm(context, host, realmsp) (void) sprintf(scanstring, "%%%ds %%%ds", sizeof(trans_host)-1,sizeof(trans_realm)-1); while (1) { - if ((scanval = fscanf(trans_file, scanstring, - trans_host, trans_realm)) != 2) { + #ifdef _WINDOWS + scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, + trans_realm, sizeof(trans_realm)-1); + #else + scanval = fscanf(trans_file, scanstring, trans_host, trans_realm)); + #endif + if (scanval != 2) { if (scanval == EOF) { fclose(trans_file); goto out; @@ -175,3 +230,6 @@ krb5_get_host_realm(context, host, realmsp) *realmsp = retrealms; return 0; } + + + diff --git a/src/lib/krb5/os/realm_dom.c b/src/lib/krb5/os/realm_dom.c index 4550bfbca..be25e8d02 100644 --- a/src/lib/krb5/os/realm_dom.c +++ b/src/lib/krb5/os/realm_dom.c @@ -51,6 +51,56 @@ extern char *krb5_trans_file; +#ifdef _WINDOWS +/* + * Windows DLL can't use the fscanf routine. We need fscanf to read + * in the host and realm. Read_2str with read_1str duplicate the needed + * functionality. See also host_realm.c + */ +static int +read_1str (FILE *fp, char *buf, int buflen) { + int c; + + while (1) { + c = fgetc (fp); /* Past leading whitespace */ + if (c == EOF) + return 0; + if (! isspace (c)) + break; + } + + while (1) { + if (buflen > 0) { /* Store the character */ + *buf++ = (char) c; + --buflen; + } + if (buflen <= 0) /* Fscanf stops scanning... */ + break; /* ...when buffer is full */ + + c = fgetc (fp); /* Get next character */ + if (c == EOF || isspace (c)) + break; + } + + if (buflen) /* Make ASCIIZ if room */ + *buf = '\0'; + + return 1; +} + +static int +read_2str (FILE *fp, char *b1, int l1, char *b2, int l2) { + int n; + + n = read_1str (fp, b1, l1); /* Read first string */ + if (!n) return EOF; + n = read_1str (fp, b2, l2); /* Read second string */ + if (!n) return 1; + return 2; +} + +#endif /* _WINDOWS */ + krb5_error_code INTERFACE krb5_get_realm_domain(context, realm, domain) krb5_context context; @@ -82,8 +132,13 @@ krb5_get_realm_domain(context, realm, domain) (void) sprintf(scanstring, "%%%ds %%%ds", sizeof(trans_host)-1,sizeof(trans_realm)-1); while (1) { - if ((scanval = fscanf(trans_file, scanstring, - trans_host, trans_realm)) != 2) { + #ifdef _WINDOWS + scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, + trans_realm, sizeof(trans_realm)-1); + #else + scanval = fscanf(trans_file, scanstring, trans_host, trans_realm)); + #endif + if (scanval != 2) { if (scanval == EOF) { fclose(trans_file); if (realmlist != NULL) { -- cgit