2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #if defined(AFS_AIX41_ENV)
17 #include <sys/types.h>
18 #include <sys/param.h>
24 #include <sys/socket.h>
29 #include <afs/kauth.h>
30 #include <afs/kautils.h>
33 afs_authenticate(char *userName, char *response, int *reenter, char **message)
35 char *reason, *pword, prompt[256];
37 int code, unixauthneeded, password_expires = -1;
44 sprintf(prompt, "Enter AFS password for %s: ", userName);
45 pword = getpass(prompt);
46 if (strlen(pword) == 0) {
48 ("Unable to read password because zero length passord is illegal\n");
49 *message = (char *)malloc(256);
51 "Unable to read password because zero length passord is illegal\n");
55 if ((pwd = getpwnam(userName)) == NULL) {
56 *message = (char *)malloc(256);
57 sprintf(*message, "getpwnam for user failed\n");
61 ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION + KA_USERAUTH_DOSETPAG,
62 userName, (char *)0, (char *)0, pword, 0,
63 &password_expires, 0, &reason)) {
66 *message = (char *)malloc(1024);
67 sprintf(*message, "Unable to authenticate to AFS because %s.\n",
71 #if defined(AFS_KERBEROS_ENV)
72 setup_ticket_file(userName);
78 afs_chpass(char *userName, char *oldPasswd, char *newPasswd, char **message)
84 afs_passwdexpired(char *userName, char **message)
90 afs_passwdrestrictions(char *userName, char *newPasswd, char *oldPasswd,
97 afs_getgrset(char *userName)
106 static char name[64];
107 static char passwd[64];
108 static struct group grp;
112 while ((g = getgrent()) != NULL) {
113 if (g->gr_gid == id) {
114 strncpy(&name, g->gr_name, sizeof(name));
115 strncpy(&passwd, g->gr_passwd, sizeof(passwd));
117 grp.gr_passwd = &passwd;
118 grp.gr_gid = g->gr_gid;
131 afs_getgrnam(char *name)
138 afs_getpwnam(char *user)
140 static char name[64];
141 static char passwd[64];
142 static char gecos[256];
143 static char dir[256];
144 static char shell[256];
145 static struct passwd pwd;
148 while ((p = getpwent()) != NULL) {
149 if (!strcmp(p->pw_name, user)) {
150 strncpy(&name, p->pw_name, sizeof(name));
151 strncpy(&passwd, p->pw_passwd, sizeof(passwd));
152 strncpy(&gecos, p->pw_gecos, sizeof(gecos));
153 strncpy(&dir, p->pw_dir, sizeof(dir));
154 strncpy(&shell, p->pw_shell, sizeof(shell));
156 pwd.pw_passwd = &passwd;
157 pwd.pw_uid = p->pw_uid;
158 pwd.pw_gid = p->pw_gid;
159 pwd.pw_gecos = &gecos;
161 pwd.pw_shell = &shell;
178 afs_getpwuid(uid_t uid)
184 afs_getpwuid(char *name)
191 afs_initialize(struct secmethod_table *meths)
194 * Initialize kauth package here so we don't have to call it
195 * each time we call the authenticate routine.
198 memset(meths, 0, sizeof(struct secmethod_table));
200 * Initialize the exported interface routines. Except the authenticate one
201 * the others are currently mainly noops.
203 meths->method_chpass = afs_chpass;
204 meths->method_authenticate = afs_authenticate;
205 meths->method_passwdexpired = afs_passwdexpired;
206 meths->method_passwdrestrictions = afs_passwdrestrictions;
208 * These we need to bring in because, for afs users, /etc/security/user's
209 * "registry" must non-local (i.e. DCE) since otherwise it assumes it's a
210 * local domain and uses valid_crypt(passwd) to validate the afs passwd
211 * which, of course, will fail. NULL return from these routine simply
212 * means use the local version ones after all.
214 meths->method_getgrgid = afs_getgrgid;
215 meths->method_getgrset = afs_getgrset;
216 meths->method_getgrnam = afs_getgrnam;
217 meths->method_getpwnam = afs_getpwnam;
218 meths->method_getpwuid = afs_getpwuid;
222 #if defined(AFS_KERBEROS_ENV)
224 setup_ticket_file(userName)
227 extern char *ktc_tkt_string();
230 setpwent(); /* open the pwd database */
231 pwd = getpwnam(userName);
233 if (chown(ktc_tkt_string(), pwd->pw_uid, pwd->pw_gid) < 0)
236 perror("getpwnam : ");
237 endpwent(); /* close the pwd database */
239 #endif /* AFS_KERBEROS_ENV */