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>
55 #include <afs/cellconfig.h>
57 #include <afs/ptint.h>
58 #include <afs/pterror.h>
59 #include <afs/ptserver.h>
60 #include <afs/afsutil.h>
62 #include <rx/rx_globals.h>
63 #include <rx/rxkad.h> /* max ticket lifetime */
66 #endif /* defined(UKERNEL) */
70 GetTickets(char *name, char *instance, char *realm,
71 struct ktc_encryptionKey * key, Date lifetime,
72 afs_int32 * pwexpires, afs_int32 flags)
75 struct ktc_token token;
77 code = ka_GetAuthToken(name, instance, realm, key, lifetime, pwexpires);
78 memset(key, 0, sizeof(*key));
81 code = ka_GetAFSTicket(name, instance, realm, lifetime, flags);
86 * Requires that you already possess a TGT.
89 ka_GetAFSTicket(char *name, char *instance, char *realm, Date lifetime,
93 struct ktc_token token;
94 struct ktc_principal server, client;
96 code = ka_GetServerToken("afs", "", realm, lifetime, &token, /*new */ 1,
100 if (ktc_OldPioctl()) {
102 char username[MAXKTCNAMELEN];
105 char *whoami = "UserAuthenticate: ptserver";
107 strcpy(server.name, "afs");
108 strcpy(server.instance, "");
109 code = ka_ExpandCell(realm, server.cell, &local);
112 code = pr_Initialize(0, AFSDIR_CLIENT_ETC_DIRPATH, server.cell);
114 com_err(whoami, code, "initializing ptserver in cell '%s'",
120 len += strlen(instance) + 1;
121 if (len >= sizeof(username)) {
122 fprintf(stderr, "user's name '%s'.'%s' would be too large\n",
126 strcpy(username, name);
128 strcat(username, ".");
129 strcat(username, instance);
131 code = pr_SNameToId(username, &viceId);
132 /* Before going further, shutdown the pr ubik connection */
134 if ((code == 0) && (viceId == ANONYMOUSID))
137 com_err(whoami, code, "translating %s to id", username);
141 sprintf(client.name, "AFS ID %d", viceId);
142 strcpy(client.instance, "");
143 strcpy(client.cell, server.cell);
144 code = ktc_SetToken(&server, &token, &client, /*dosetpag */ 0);
151 #ifdef ka_UserAuthenticate
152 #undef ka_UserAuthenticate
156 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 */
157 afs_int32 spare2, char **reasonP)
159 int remainingTime = 0;
160 struct ktc_encryptionKey key;
161 afs_int32 code, dosetpag = 0;
166 if ((flags & KA_USERAUTH_VERSION_MASK) != KA_USERAUTH_VERSION)
167 return KAOLDINTERFACE;
168 if ((strcmp(name, "root") == 0) && (instance == 0)) {
170 *reasonP = "root is only authenticated locally";
177 ka_StringToKey(password, realm, &key);
180 * alarm is set by klogin and kpasswd only so ignore for
185 { /* Rx uses timers, save to be safe */
187 /* don't reset alarms, rx already running */
190 remainingTime = alarm(0);
194 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_USR_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
195 /* handle smoothly the case where no AFS system calls exists (yet) */
196 old = (int (*)())signal(SIGSYS, SIG_IGN);
198 #ifdef AFS_DECOSF_ENV
199 (void)signal(SIGTRAP, SIG_IGN);
200 #endif /* AFS_DECOSF_ENV */
203 if (flags & KA_USERAUTH_ONLY_VERIFY) {
204 code = ka_VerifyUserToken(name, instance, realm, &key);
205 if (code == KABADREQUEST) {
206 des_string_to_key(password, &key);
207 code = ka_VerifyUserToken(name, instance, realm, &key);
211 if (flags & KA_USERAUTH_DOSETPAG)
214 #if !defined(UKERNEL) && !defined(AFS_NT40_ENV)
215 if (flags & KA_USERAUTH_DOSETPAG)
219 if (flags & KA_USERAUTH_DOSETPAG2)
221 #ifdef AFS_KERBEROS_ENV
222 if ((flags & KA_USERAUTH_DOSETPAG) || dosetpag)
226 lifetime = MAXKTCTICKETLIFETIME;
228 GetTickets(name, instance, realm, &key, lifetime,
229 password_expires, dosetpag);
230 if (code == KABADREQUEST) {
231 des_string_to_key(password, &key);
233 GetTickets(name, instance, realm, &key, lifetime,
234 password_expires, dosetpag);
237 /* By the time 3.3 comes out, these "old-style" passwd programs should be
238 * well and truly obsolete. Any passwords set with such a program
239 * OUGHT to have been changed years ago. Having 2 -or- 3
240 * authentication RPCs generated for every klog plays hob with the
241 * "failed login limits" code in the kaserver, and it's hard to
242 * explain to admins just how to set the limit properly. By removing
243 * this function, we can just double it internally in the kaserver, and
244 * not document anything. kpasswd had the TRUNCATEPASSWORD "feature"
245 * disabled on 10/02/90.
248 if ((code == KABADREQUEST) && (strlen(password) > 8)) {
249 /* try with only the first 8 characters incase they set their password
250 * with an old style passwd program. */
252 strncpy(pass8, password, 8);
254 ka_StringToKey(pass8, realm, &key);
255 memset(pass8, 0, sizeof(pass8));
257 GetTickets(name, instance, realm, &key, lifetime,
258 password_expires, dosetpag);
260 fprintf(stderr, "%s %s\n%s %s\n%s\n",
261 "Warning: you have typed a password longer than 8",
262 "characters, but only the",
263 "first 8 characters were actually significant. If",
264 "you change your password",
265 "again this warning message will go away.\n");
268 #endif /* OLDCRUFT */
275 alarm(remainingTime); /* restore timer, if any */
282 *reasonP = "password was incorrect";
285 *reasonP = "Authentication Server was unavailable";
288 *reasonP = (char *)error_message(code);
293 /* For backward compatibility */
295 ka_UserAuthenticate(char *name, char *instance, char *realm, char *password,
296 int doSetPAG, char **reasonP)
298 return ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION +
299 ((doSetPAG) ? KA_USERAUTH_DOSETPAG : 0),
300 name, instance, realm, password,
301 /*lifetime */ 0, /*spare1,2 */ 0, 0,
305 #if !defined(UKERNEL)
307 ka_UserReadPassword(char *prompt, char *password, int plen, char **reasonP)
316 code = read_pw_string(password, plen, prompt, 0);
319 else if (strlen(password) == 0)
320 code = KANULLPASSWORD;
325 *reasonP = (char *)error_message(code);
329 #endif /* !defined(UKERNEL) */
332 ka_VerifyUserPassword(afs_int32 version, char *name, char *instance,
333 char *realm, char *password, int spare, char **reasonP)
337 version &= KA_USERAUTH_VERSION_MASK;
338 return ka_UserAuthenticateGeneral(version | KA_USERAUTH_ONLY_VERIFY, name,
339 instance, realm, password, 0,
340 &pwexpires, spare, reasonP);