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>
14 #include <afs/param.h>
19 #include <hcrypto/des.h>
20 #include <hcrypto/ui.h>
22 #include <afs/com_err.h>
23 #include <afs/cellconfig.h>
25 #include <afs/ptint.h>
26 #include <afs/pterror.h>
27 #include <afs/ptuser.h>
28 #include <afs/ptserver.h>
29 #include <afs/afsutil.h>
30 #include <afs/sys_prototypes.h>
33 #include <rx/rx_globals.h>
34 #include <rx/rxkad.h> /* max ticket lifetime */
35 #include <rx/rxkad_convert.h>
42 GetTickets(char *name
, char *instance
, char *realm
,
43 struct ktc_encryptionKey
* key
, Date lifetime
,
44 afs_int32
* pwexpires
, afs_int32 flags
)
48 code
= ka_GetAuthToken(name
, instance
, realm
, key
, lifetime
, pwexpires
);
49 memset(key
, 0, sizeof(*key
));
52 code
= ka_GetAFSTicket(name
, instance
, realm
, lifetime
, flags
);
57 * Requires that you already possess a TGT.
60 ka_GetAFSTicket(char *name
, char *instance
, char *realm
, Date lifetime
,
64 struct ktc_token token
;
65 struct ktc_principal server
, client
;
67 code
= ka_GetServerToken("afs", "", realm
, lifetime
, &token
, /*new */ 1,
71 if (ktc_OldPioctl()) {
73 char username
[MAXKTCNAMELEN
];
76 char *whoami
= "UserAuthenticate: ptserver";
78 strcpy(server
.name
, "afs");
79 strcpy(server
.instance
, "");
80 code
= ka_ExpandCell(realm
, server
.cell
, &local
);
83 code
= pr_Initialize(0, AFSDIR_CLIENT_ETC_DIRPATH
, server
.cell
);
85 afs_com_err(whoami
, code
, "initializing ptserver in cell '%s'",
91 len
+= strlen(instance
) + 1;
92 if (len
>= sizeof(username
)) {
93 fprintf(stderr
, "user's name '%s'.'%s' would be too large\n",
97 strcpy(username
, name
);
99 strcat(username
, ".");
100 strcat(username
, instance
);
102 code
= pr_SNameToId(username
, &viceId
);
103 /* Before going further, shutdown the pr ubik connection */
105 if ((code
== 0) && (viceId
== ANONYMOUSID
))
108 afs_com_err(whoami
, code
, "translating %s to id", username
);
112 sprintf(client
.name
, "AFS ID %d", viceId
);
113 strcpy(client
.instance
, "");
114 strcpy(client
.cell
, server
.cell
);
115 code
= ktc_SetToken(&server
, &token
, &client
, /*dosetpag */ 0);
122 #ifdef ka_UserAuthenticate
123 #undef ka_UserAuthenticate
127 ka_UserAuthenticateGeneral(afs_int32 flags
, char *name
, char *instance
,
128 char *realm
, char *password
, Date lifetime
,
129 afs_int32
* password_expires
, /* days 'til, or don't change if not set */
130 afs_int32 spare2
, char **reasonP
)
132 int remainingTime
= 0;
133 struct ktc_encryptionKey key
;
134 afs_int32 code
, dosetpag
= 0;
138 if ((flags
& KA_USERAUTH_VERSION_MASK
) != KA_USERAUTH_VERSION
)
139 return KAOLDINTERFACE
;
140 if ((strcmp(name
, "root") == 0) && (instance
== 0)) {
142 *reasonP
= "root is only authenticated locally";
149 ka_StringToKey(password
, realm
, &key
);
152 * alarm is set by kpasswd only so ignore for
157 { /* Rx uses timers, save to be safe */
159 /* don't reset alarms, rx already running */
162 remainingTime
= alarm(0);
166 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_USR_LINUX20_ENV) && (!defined(AFS_XBSD_ENV) || defined(AFS_FBSD_ENV))
167 /* handle smoothly the case where no AFS system calls exists (yet) */
168 (void)signal(SIGSYS
, SIG_IGN
);
170 #ifdef AFS_DECOSF_ENV
171 (void)signal(SIGTRAP
, SIG_IGN
);
172 #endif /* AFS_DECOSF_ENV */
175 if (flags
& KA_USERAUTH_ONLY_VERIFY
) {
176 code
= ka_VerifyUserToken(name
, instance
, realm
, &key
);
177 if (code
== KABADREQUEST
) {
178 DES_string_to_key(password
, ktc_to_cblockptr(&key
));
179 code
= ka_VerifyUserToken(name
, instance
, realm
, &key
);
183 if (flags
& KA_USERAUTH_DOSETPAG
)
186 #if !defined(AFS_NT40_ENV)
187 if (flags
& KA_USERAUTH_DOSETPAG
)
191 if (flags
& KA_USERAUTH_DOSETPAG2
)
193 #ifdef AFS_KERBEROS_ENV
194 if ((flags
& KA_USERAUTH_DOSETPAG
) || dosetpag
)
198 lifetime
= MAXKTCTICKETLIFETIME
;
200 GetTickets(name
, instance
, realm
, &key
, lifetime
,
201 password_expires
, dosetpag
);
202 if (code
== KABADREQUEST
) {
203 DES_string_to_key(password
, ktc_to_cblockptr(&key
));
205 GetTickets(name
, instance
, realm
, &key
, lifetime
,
206 password_expires
, dosetpag
);
214 alarm(remainingTime
); /* restore timer, if any */
221 *reasonP
= "password was incorrect";
224 *reasonP
= "Authentication Server was unavailable";
227 *reasonP
= (char *)afs_error_message(code
);
232 /* For backward compatibility */
234 ka_UserAuthenticate(char *name
, char *instance
, char *realm
, char *password
,
235 int doSetPAG
, char **reasonP
)
237 return ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION
+
238 ((doSetPAG
) ? KA_USERAUTH_DOSETPAG
: 0),
239 name
, instance
, realm
, password
,
240 /*lifetime */ 0, /*spare1,2 */ 0, 0,
245 ka_UserReadPassword(char *prompt
, char *password
, int plen
, char **reasonP
)
254 code
= UI_UTIL_read_pw_string(password
, plen
, prompt
, 0);
257 else if (strlen(password
) == 0)
258 code
= KANULLPASSWORD
;
263 *reasonP
= (char *)afs_error_message(code
);
269 ka_VerifyUserPassword(afs_int32 version
, char *name
, char *instance
,
270 char *realm
, char *password
, int spare
, char **reasonP
)
274 version
&= KA_USERAUTH_VERSION_MASK
;
275 return ka_UserAuthenticateGeneral(version
| KA_USERAUTH_ONLY_VERIFY
, name
,
276 instance
, realm
, password
, 0,
277 &pwexpires
, spare
, reasonP
);