#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
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;
}
#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) {
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);