From: hno <> Date: Thu, 15 Nov 2001 05:11:48 +0000 (+0000) Subject: Restructured to dynamically allocate room for the nis password instead X-Git-Tag: SQUID_3_0_PRE1~1295 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=686e91cdec346a49a80c8cd93dabaf9e9ba991e3;p=thirdparty%2Fsquid.git Restructured to dynamically allocate room for the nis password instead of relying on a local array that may get overflowed. --- diff --git a/helpers/basic_auth/YP/nis_support.c b/helpers/basic_auth/YP/nis_support.c index 48a82c07fb..ec724475fa 100644 --- a/helpers/basic_auth/YP/nis_support.c +++ b/helpers/basic_auth/YP/nis_support.c @@ -11,13 +11,15 @@ #include #include +#include "nis_support.h" + #define NO_YPERR 0 /* There is no error */ -int -get_nis_password(char *user, char *passwd, char *nisdomain, char *nismap) +char * +get_nis_password(char *user, char *nisdomain, char *nismap) { - char *val = NULL; - char *username = NULL; + static char *val = NULL; + char *password = NULL; int vallen, res; #ifdef DEBUG @@ -25,22 +27,26 @@ get_nis_password(char *user, char *passwd, char *nisdomain, char *nismap) printf("YP Map is set to %s\n", nismap); #endif + /* Free last entry */ + if (val) { + free(val); + val = NULL; + } + /* Get NIS entry */ res = yp_match(nisdomain, nismap, user, strlen(user), &val, &vallen); switch (res) { case NO_YPERR: - username = strtok(val, ":"); - strcpy(passwd, strtok(NULL, ":")); - free(val); - break; + /* username = */ (void) strtok(val, ":"); + password = strtok(NULL, ",:"); + return password; case YPERR_YPBIND: syslog(LOG_ERR, "Squid Authentication through ypbind failure: can't communicate with ypbind"); - return 1; + return NULL; case YPERR_KEY: /* No such key in map */ - return 1; + return NULL; default: - return 1; + return NULL; } - return 0; } diff --git a/helpers/basic_auth/YP/nis_support.h b/helpers/basic_auth/YP/nis_support.h new file mode 100644 index 0000000000..2f42585aab --- /dev/null +++ b/helpers/basic_auth/YP/nis_support.h @@ -0,0 +1 @@ +extern char * get_nis_password(char *user, char *nisdomain, char *nismap); diff --git a/helpers/basic_auth/YP/yp_auth.c b/helpers/basic_auth/YP/yp_auth.c index 2b54e051e0..bb2ce8fc4f 100644 --- a/helpers/basic_auth/YP/yp_auth.c +++ b/helpers/basic_auth/YP/yp_auth.c @@ -29,18 +29,17 @@ #include "util.h" #include "hash.h" -int get_nis_password(); - +#include "nis_support.h" int main(int argc, char **argv) { char buf[256]; - char nispasswd[15]; char *nisdomain; char *nismap; char *user, *passwd, *p; - int res; + char *nispasswd; + setbuf(stdout, NULL); if (argc != 3) { @@ -64,17 +63,17 @@ main(int argc, char **argv) printf("ERR\n"); continue; } - res = get_nis_password(user, nispasswd, nisdomain, nismap); + nispasswd = get_nis_password(user, nisdomain, nismap); - if (res) { + if (!nispasswd) { /* User does not exist */ printf("ERR\n"); - } else if (strcmp(nispasswd, (char *) crypt(passwd, nispasswd))) { - /* Password incorrect */ - printf("ERR\n"); - } else { + } else if (strcmp(nispasswd, (char *) crypt(passwd, nispasswd)) == 0) { /* All ok !, thanks... */ printf("OK\n"); + } else { + /* Password incorrect */ + printf("ERR\n"); } } exit(0);