pull-prototypes-to-head-20020821
[openafs.git] / src / tsm41 / aix41_auth.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID("$Header$");
14
15 #if defined(AFS_AIX41_ENV)
16 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <stdio.h>
19 #include <locale.h>
20 #include <nl_types.h>
21 #include <pwd.h>
22 #include <netdb.h>
23 #include <sys/socket.h>
24 #include <sys/file.h>
25 #include <errno.h>
26 #include <usersec.h>
27
28 #include <afs/kauth.h>
29 #include <afs/kautils.h>
30
31
32 int afs_authenticate (char *userName, char *response, int  *reenter, char **message) {
33     char *reason, *pword, prompt[256];
34     struct passwd *pwd;
35     int code, unixauthneeded, password_expires = -1;
36
37     *reenter = 0;
38     *message = NULL;
39     if (response) {
40         pword = response;
41     } else {
42         sprintf(prompt,"Enter AFS password for %s: ",userName);
43         pword=getpass(prompt);
44         if(strlen(pword)==0) {
45             printf("Unable to read password because zero length passord is illegal\n");
46             *message = (char *)malloc(256);
47             sprintf(*message, "Unable to read password because zero length passord is illegal\n");          
48             return AUTH_FAILURE;
49         }
50     }
51     if ((pwd = getpwnam(userName)) == NULL){
52         *message = (char *)malloc(256);
53         sprintf(*message, "getpwnam for user failed\n");
54         return AUTH_FAILURE;
55     }
56     if (code = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION + KA_USERAUTH_DOSETPAG, userName, 
57                                           NULL, NULL, pword, 0, &password_expires, 0, &reason)) {
58         if (code == KANOENT) 
59             return AUTH_NOTFOUND;       
60         *message = (char *)malloc(1024);
61         sprintf(*message, "Unable to authenticate to AFS because %s.\n", reason);
62         return AUTH_FAILURE;
63     }
64 #if defined(AFS_KERBEROS_ENV)
65         setup_ticket_file(userName);
66 #endif
67     return AUTH_SUCCESS;
68 }
69  
70 int afs_chpass (char *userName, char *oldPasswd, char *newPasswd, char **message) {
71     return AUTH_SUCCESS;
72 }
73
74 int afs_passwdexpired (char *userName, char **message) {
75     return AUTH_SUCCESS;
76 }
77
78 int afs_passwdrestrictions (char *userName, char *newPasswd, char *oldPasswd, char **message) {
79     return AUTH_SUCCESS;
80 }
81
82 int afs_getgrset (char *userName) {
83     return NULL;
84 }
85
86 int afs_getgrgid (int id) {
87     return NULL;
88 }
89
90 int afs_getgrnam (char *name) {
91     return NULL;
92 }
93
94 int afs_getpwnam(int id)
95 {
96     return NULL;
97 }
98
99 int afs_getpwuid(char *name)
100 {
101     return NULL;
102 }
103
104 int afs_initialize(struct secmethod_table *meths) {
105     /*
106      * Initialize kauth package here so we don't have to call it
107      * each time we call the authenticate routine.      
108      */
109     ka_Init(0);
110     memset(meths, 0, sizeof(struct secmethod_table));
111     /*
112      * Initialize the exported interface routines. Except the authenticate one
113      * the others are currently mainly noops.
114      */
115     meths->method_chpass = afs_chpass;
116     meths->method_authenticate = afs_authenticate;
117     meths->method_passwdexpired = afs_passwdexpired;
118     meths->method_passwdrestrictions = afs_passwdrestrictions;
119     /*
120      * These we need to bring in because, for afs users, /etc/security/user's
121      * "registry" must non-local (i.e. DCE) since otherwise it assumes it's a
122      * local domain and uses valid_crypt(passwd) to validate the afs passwd
123      * which, of course, will fail. NULL return from these routine simply
124      * means use the local version ones after all.
125      */
126     meths->method_getgrgid  = afs_getgrgid;
127     meths->method_getgrset  = afs_getgrset;
128     meths->method_getgrnam  = afs_getgrnam;
129     meths->method_getpwnam  = afs_getpwnam;
130     meths->method_getpwuid  = afs_getpwuid;
131     return(0);
132 }
133
134 #if defined(AFS_KERBEROS_ENV)
135
136 setup_ticket_file(userName)
137 char*   userName;
138 {
139         extern char*    ktc_tkt_string();
140         struct passwd*  pwd;    
141         
142         setpwent();             /* open the pwd database */
143         pwd = getpwnam(userName);
144         if (pwd)
145         {
146                 if ( chown(ktc_tkt_string(), pwd->pw_uid, pwd->pw_gid) < 0 )
147                         perror("chown: ");
148         }
149         else perror("getpwnam : ");
150         endpwent();             /* close the pwd database */
151 }
152 #endif /* AFS_KERBEROS_ENV */
153
154 #endif
155
156