2 Copyright (c) 1995-1998 by Cisco systems, Inc.
4 Permission to use, copy, modify, and distribute this software for
5 any purpose and without fee is hereby granted, provided that this
6 copyright and permission notice appear on all copies of the
7 software and supporting documentation, the name of Cisco Systems,
8 Inc. not be used in advertising or publicity pertaining to
9 distribution of the program without specific prior permission, and
10 notice be given in supporting documentation that modification,
11 copying and distribution is by permission of Cisco Systems, Inc.
13 Cisco Systems, Inc. makes no representations about the suitability
14 of this software for any purpose. THIS SOFTWARE IS PROVIDED ``AS
15 IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16 WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS FOR A PARTICULAR PURPOSE.
20 /* Tacacs+ password lookup routine for those systems which don't have
21 setpwfile. Not for use on /etc/passwd files */
35 static struct passwd pw_passwd;
37 struct passwd *tac_passwd_lookup TAC_ARGS((const char *name, const char *file));
40 tac_passwd_lookup(name, file)
44 FILE *passwd_fp = NULL;
46 static char uname[512];
47 static char password[1024];
48 static char gecos[1024];
49 static char homedir[1024];
50 static char shell[1024];
54 passwd_fp = fopen(file, "r");
57 if (debug & DEBUG_PASSWD_FLAG)
58 report(LOG_DEBUG, "tac_passwd_lookup: open %s %d",
59 file, fileno(passwd_fp));
61 report(LOG_ERR, "tac_passwd_lookup: cannot open file %s for reading",
66 while (fgets(buf, sizeof(buf), passwd_fp)) {
68 /* uname, password, uid, gid, gecos, homedir, shell */
75 strncpy(uname, s, e - s);
79 if (strcmp(uname, name))
87 strncpy(password, s, e - s);
88 password[e - s] = '\0';
95 pw_passwd.pw_uid = atoi(s);
99 pw_passwd.pw_gid = atoi(s);
106 strncpy(gecos, s, e - s);
114 strncpy(homedir, s, e - s);
115 homedir[e - s] = '\0';
122 strncpy(shell, s, e - s);
125 pw_passwd.pw_name = uname;
126 pw_passwd.pw_passwd = password;
127 #ifdef HAVE_PASSWD_PW_AGE
128 pw_passwd.pw_age = NULL;
130 #ifdef HAVE_PASSWD_PW_COMMENT
131 pw_passwd.pw_comment = NULL;
133 pw_passwd.pw_gecos = gecos;
134 pw_passwd.pw_dir = homedir;
135 pw_passwd.pw_shell = shell;
137 if (debug & DEBUG_PASSWD_FLAG)
138 report(LOG_DEBUG, "tac_passwd_lookup: close %s %d",
139 file, fileno(passwd_fp));
145 if (debug & DEBUG_PASSWD_FLAG)
146 report(LOG_DEBUG, "tac_passwd_lookup: close %s %d",
147 file, fileno(passwd_fp));