]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Restructured to dynamically allocate room for the nis password instead
authorhno <>
Thu, 15 Nov 2001 05:11:48 +0000 (05:11 +0000)
committerhno <>
Thu, 15 Nov 2001 05:11:48 +0000 (05:11 +0000)
of relying on a local array that may get overflowed.

helpers/basic_auth/YP/nis_support.c
helpers/basic_auth/YP/nis_support.h [new file with mode: 0644]
helpers/basic_auth/YP/yp_auth.c

index 48a82c07fba92bdbdadf76edb481a7dfac8d5769..ec724475fac8fb0bc60bdb0aa9438a21506b36b5 100644 (file)
 #include <rpcsvc/ypclnt.h>
 #include <rpcsvc/yp_prot.h>
 
+#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 (file)
index 0000000..2f42585
--- /dev/null
@@ -0,0 +1 @@
+extern char * get_nis_password(char *user, char *nisdomain, char *nismap);
index 2b54e051e02a46881093f4172f8095b22b452a22..bb2ce8fc4f62e1a39b607d065f874a2df18d4f02 100644 (file)
 #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);