1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*
* Adapted By Rabellino Sergio (rabellino@di.unito.it) For Solaris 2.x
* From NCSA Authentication module
*/
#include "config.h"
#if HAVE_STDIO_H
#include <stdio.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_CRYPT_H
#include <crypt.h>
#endif
#include "util.h"
#include "hash.h"
#include "nis_support.h"
int
main(int argc, char **argv)
{
char buf[256];
char *nisdomain;
char *nismap;
char *user, *passwd, *p;
char *nispasswd;
setbuf(stdout, NULL);
if (argc != 3) {
fprintf(stderr, "Usage: yp_auth <domainname> <nis map for password>\n");
fprintf(stderr, "\n");
fprintf(stderr, "Example yp_auth mydomain.com passwd.byname\n");
exit(1);
}
nisdomain = argv[1];
nismap = argv[2];
while (fgets(buf, 256, stdin) != NULL) {
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0'; /* strip \n */
if ((user = strtok(buf, " ")) == NULL) {
printf("ERR\n");
continue;
}
if ((passwd = strtok(NULL, "")) == NULL) {
printf("ERR\n");
continue;
}
rfc1738_unescape(user);
rfc1738_unescape(passwd);
nispasswd = get_nis_password(user, nisdomain, nismap);
if (!nispasswd) {
/* User does not exist */
printf("ERR No such user\n");
} else if (strcmp(nispasswd, (char *) crypt(passwd, nispasswd)) == 0) {
/* All ok !, thanks... */
printf("OK\n");
} else {
/* Password incorrect */
printf("ERR Wrong password\n");
}
}
exit(0);
}
|