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 /* This file provides the easiest, turn-key interface to the authication
13 #include <afsconfig.h>
15 #include "afs/param.h"
17 #include <afs/param.h>
24 #include "afs/sysincludes.h"
25 #include "afsincludes.h"
27 #include "afs/com_err.h"
28 #include "afs/cellconfig.h"
30 #include "afs/ptint.h"
31 #include "afs/pterror.h"
32 #include "afs/ptserver.h"
34 #include "rx/rx_globals.h"
36 #include "afs/kauth.h"
37 #include "afs/kautils.h"
38 #include "afs/afsutil.h"
39 #else /* defined(UKERNEL) */
42 #include <afs/com_err.h>
46 #include <netinet/in.h>
49 #include <afs/cellconfig.h>
51 #include <afs/ptint.h>
52 #include <afs/pterror.h>
53 #include <afs/ptserver.h>
54 #include <afs/afsutil.h>
56 #include <rx/rx_globals.h>
57 #include <rx/rxkad.h> /* max ticket lifetime */
60 #endif /* defined(UKERNEL) */
64 GetTickets(char *name, char *instance, char *realm,
65 struct ktc_encryptionKey * key, Date lifetime,
66 afs_int32 * pwexpires, afs_int32 flags)
69 struct ktc_token token;
71 code = ka_GetAuthToken(name, instance, realm, key, lifetime, pwexpires);
72 memset(key, 0, sizeof(*key));
75 code = ka_GetAFSTicket(name, instance, realm, lifetime, flags);
80 * Requires that you already possess a TGT.
83 ka_GetAFSTicket(char *name, char *instance, char *realm, Date lifetime,
87 struct ktc_token token;
88 struct ktc_principal server, client;
90 code = ka_GetServerToken("afs", "", realm, lifetime, &token, /*new */ 1,
94 if (ktc_OldPioctl()) {
96 char username[MAXKTCNAMELEN];
99 char *whoami = "UserAuthenticate: ptserver";
101 strcpy(server.name, "afs");
102 strcpy(server.instance, "");
103 code = ka_ExpandCell(realm, server.cell, &local);
106 code = pr_Initialize(0, AFSDIR_CLIENT_ETC_DIRPATH, server.cell);
108 afs_com_err(whoami, code, "initializing ptserver in cell '%s'",
114 len += strlen(instance) + 1;
115 if (len >= sizeof(username)) {
116 fprintf(stderr, "user's name '%s'.'%s' would be too large\n",
120 strcpy(username, name);
122 strcat(username, ".");
123 strcat(username, instance);
125 code = pr_SNameToId(username, &viceId);
126 /* Before going further, shutdown the pr ubik connection */
128 if ((code == 0) && (viceId == ANONYMOUSID))
131 afs_com_err(whoami, code, "translating %s to id", username);
135 sprintf(client.name, "AFS ID %d", viceId);
136 strcpy(client.instance, "");
137 strcpy(client.cell, server.cell);
138 code = ktc_SetToken(&server, &token, &client, /*dosetpag */ 0);
145 #ifdef ka_UserAuthenticate
146 #undef ka_UserAuthenticate
150 ka_UserAuthenticateGeneral(afs_int32 flags, char *name, char *instance, char *realm, char *password, Date lifetime, afs_int32 * password_expires, /* days 'til, or don't change if not set */
151 afs_int32 spare2, char **reasonP)
153 int remainingTime = 0;
154 struct ktc_encryptionKey key;
155 afs_int32 code, dosetpag = 0;
160 if ((flags & KA_USERAUTH_VERSION_MASK) != KA_USERAUTH_VERSION)
161 return KAOLDINTERFACE;
162 if ((strcmp(name, "root") == 0) && (instance == 0)) {
164 *reasonP = "root is only authenticated locally";
171 ka_StringToKey(password, realm, &key);
174 * alarm is set by klogin and kpasswd only so ignore for
179 { /* Rx uses timers, save to be safe */
181 /* don't reset alarms, rx already running */
184 remainingTime = alarm(0);
188 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_USR_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
189 /* handle smoothly the case where no AFS system calls exists (yet) */
190 old = (int (*)())signal(SIGSYS, SIG_IGN);
192 #ifdef AFS_DECOSF_ENV
193 (void)signal(SIGTRAP, SIG_IGN);
194 #endif /* AFS_DECOSF_ENV */
197 if (flags & KA_USERAUTH_ONLY_VERIFY) {
198 code = ka_VerifyUserToken(name, instance, realm, &key);
199 if (code == KABADREQUEST) {
200 des_string_to_key(password, &key);
201 code = ka_VerifyUserToken(name, instance, realm, &key);
205 if (flags & KA_USERAUTH_DOSETPAG)
208 #if !defined(UKERNEL) && !defined(AFS_NT40_ENV)
209 if (flags & KA_USERAUTH_DOSETPAG)
213 if (flags & KA_USERAUTH_DOSETPAG2)
215 #ifdef AFS_KERBEROS_ENV
216 if ((flags & KA_USERAUTH_DOSETPAG) || dosetpag)
220 lifetime = MAXKTCTICKETLIFETIME;
222 GetTickets(name, instance, realm, &key, lifetime,
223 password_expires, dosetpag);
224 if (code == KABADREQUEST) {
225 des_string_to_key(password, &key);
227 GetTickets(name, instance, realm, &key, lifetime,
228 password_expires, dosetpag);
231 /* By the time 3.3 comes out, these "old-style" passwd programs should be
232 * well and truly obsolete. Any passwords set with such a program
233 * OUGHT to have been changed years ago. Having 2 -or- 3
234 * authentication RPCs generated for every klog plays hob with the
235 * "failed login limits" code in the kaserver, and it's hard to
236 * explain to admins just how to set the limit properly. By removing
237 * this function, we can just double it internally in the kaserver, and
238 * not document anything. kpasswd had the TRUNCATEPASSWORD "feature"
239 * disabled on 10/02/90.
242 if ((code == KABADREQUEST) && (strlen(password) > 8)) {
243 /* try with only the first 8 characters incase they set their password
244 * with an old style passwd program. */
246 strncpy(pass8, password, 8);
248 ka_StringToKey(pass8, realm, &key);
249 memset(pass8, 0, sizeof(pass8));
251 GetTickets(name, instance, realm, &key, lifetime,
252 password_expires, dosetpag);
254 fprintf(stderr, "%s %s\n%s %s\n%s\n",
255 "Warning: you have typed a password longer than 8",
256 "characters, but only the",
257 "first 8 characters were actually significant. If",
258 "you change your password",
259 "again this warning message will go away.\n");
262 #endif /* OLDCRUFT */
269 alarm(remainingTime); /* restore timer, if any */
276 *reasonP = "password was incorrect";
279 *reasonP = "Authentication Server was unavailable";
282 *reasonP = (char *)afs_error_message(code);
287 /* For backward compatibility */
289 ka_UserAuthenticate(char *name, char *instance, char *realm, char *password,
290 int doSetPAG, char **reasonP)
292 return ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION +
293 ((doSetPAG) ? KA_USERAUTH_DOSETPAG : 0),
294 name, instance, realm, password,
295 /*lifetime */ 0, /*spare1,2 */ 0, 0,
299 #if !defined(UKERNEL)
301 ka_UserReadPassword(char *prompt, char *password, int plen, char **reasonP)
310 code = read_pw_string(password, plen, prompt, 0);
313 else if (strlen(password) == 0)
314 code = KANULLPASSWORD;
319 *reasonP = (char *)afs_error_message(code);
323 #endif /* !defined(UKERNEL) */
326 ka_VerifyUserPassword(afs_int32 version, char *name, char *instance,
327 char *realm, char *password, int spare, char **reasonP)
331 version &= KA_USERAUTH_VERSION_MASK;
332 return ka_UserAuthenticateGeneral(version | KA_USERAUTH_ONLY_VERIFY, name,
333 instance, realm, password, 0,
334 &pwexpires, spare, reasonP);