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>
27 #include "afs_kasAdmin.h"
28 #include "../adminutil/afs_AdminInternal.h"
29 #include <afs/afs_AdminErrors.h>
30 #include <afs/afs_utilAdmin.h>
31 #include <afs/kauth.h>
32 #include <afs/kautils.h>
33 #include <afs/kaport.h>
38 extern int ubik_Call();
39 extern int ubik_CallIter();
44 struct ubik_client *servers;
47 } kas_server_t, *kas_server_p;
50 * IsValidServerHandle - verify the validity of a kas_server_t handle.
54 * IN serverHandle - the handle to be verified.
58 * No locks are obtained or released by this function
62 * Returns != 0 upon successful completion.
66 IsValidServerHandle(const kas_server_p serverHandle, afs_status_p st)
72 * Validate input parameters
75 if (serverHandle == NULL) {
76 tst = ADMKASSERVERHANDLENULL;
77 goto fail_IsValidServerHandle;
80 if ((serverHandle->begin_magic != BEGIN_MAGIC)
81 || (serverHandle->end_magic != END_MAGIC)) {
82 tst = ADMKASSERVERHANDLEBADMAGIC;
83 goto fail_IsValidServerHandle;
86 if (!serverHandle->is_valid) {
87 tst = ADMKASSERVERHANDLENOTVALID;
88 goto fail_IsValidServerHandle;
91 if (serverHandle->servers == NULL) {
92 tst = ADMKASSERVERHANDLENOSERVERS;
93 goto fail_IsValidServerHandle;
97 fail_IsValidServerHandle:
106 * IsValidCellHandle - verify the validity of a afs_cell_handle_t handle
107 * for doing kas related functions.
111 * IN cellHandle - the handle to be verified.
115 * No locks are obtained or released by this function
119 * Returns != 0 upon successful completion.
123 IsValidCellHandle(const afs_cell_handle_p cellHandle, afs_status_p st)
126 afs_status_t tst = 0;
129 * Validate input parameters
132 if (!CellHandleIsValid((void *)cellHandle, &tst)) {
133 goto fail_IsValidCellHandle;
136 if (!cellHandle->kas_valid) {
137 tst = ADMCLIENTCELLKASINVALID;
138 goto fail_IsValidCellHandle;
141 if (cellHandle->kas == NULL) {
142 tst = ADMCLIENTCELLKASNULL;
143 goto fail_IsValidCellHandle;
147 fail_IsValidCellHandle:
156 * For all kas admin functions that take a cellHandle and a serverHandle,
157 * the intention is that is the cellHandle is not NULL, we should use
158 * it. Otherwise, we use the serverHandle. It is an error for both
159 * of these parameters to be non-NULL.
163 * ChooseValidServer - given a serverHandle and a cellHandle, choose the
164 * one that is non-NULL, validate it, and return a ubik_client structure
169 * IN cellHandle - the cell where kas calls are to be made
171 * IN serverHandle - the group of server(s) that should be used to satisfy
176 * No locks are obtained or released by this function
180 * Returns != 0 upon successful completion.
184 ChooseValidServer(const afs_cell_handle_p cellHandle,
185 const kas_server_p serverHandle, kas_server_p kasHandle,
189 afs_status_t tst = 0;
192 * Validate input parameters
195 if (kasHandle == NULL) {
196 tst = ADMKASKASHANDLENULL;
197 goto fail_ChooseValidServer;
201 * Only one of the input handle parameters to this function should
204 if ((cellHandle == NULL) && (serverHandle == NULL)) {
205 tst = ADMKASCELLHANDLEANDSERVERHANDLENULL;
206 goto fail_ChooseValidServer;
209 if ((cellHandle != NULL) && (serverHandle != NULL)) {
210 tst = ADMKASCELLHANDLEANDSERVERHANDLENOTNULL;
211 goto fail_ChooseValidServer;
215 * Validate the non-NULL handle
218 if (cellHandle != NULL) {
219 if (IsValidCellHandle(cellHandle, &tst)) {
220 kasHandle->servers = cellHandle->kas;
221 kasHandle->cell = cellHandle->working_cell;
223 goto fail_ChooseValidServer;
226 if (IsValidServerHandle(serverHandle, &tst)) {
227 kasHandle->servers = serverHandle->servers;
228 kasHandle->cell = serverHandle->cell;
230 goto fail_ChooseValidServer;
234 kasHandle->begin_magic = BEGIN_MAGIC;
235 kasHandle->end_magic = END_MAGIC;
236 kasHandle->is_valid = 1;
239 fail_ChooseValidServer:
249 kaentryinfo_to_kas_principalEntry_t(struct kaentryinfo *from,
250 kas_principalEntry_p to, afs_status_p st)
253 afs_status_t tst = 0;
255 unsigned char misc_stuff[4];
258 tst = ADMKASFROMNULL;
259 goto fail_kaentryinfo_to_kas_principalEntry_t;
264 goto fail_kaentryinfo_to_kas_principalEntry_t;
267 if (from->flags & KAFADMIN) {
268 to->adminSetting = KAS_ADMIN;
270 to->adminSetting = NO_KAS_ADMIN;
273 if (from->flags & KAFNOTGS) {
274 to->tgsSetting = NO_TGS;
276 to->tgsSetting = TGS;
279 if (from->flags & KAFNOSEAL) {
280 to->encSetting = NO_ENCRYPT;
282 to->encSetting = ENCRYPT;
285 if (from->flags & KAFNOCPW) {
286 to->cpwSetting = NO_CHANGE_PASSWORD;
288 to->cpwSetting = CHANGE_PASSWORD;
291 reuse = (short)from->reserved3;
293 to->rpwSetting = REUSE_PASSWORD;
295 to->rpwSetting = NO_REUSE_PASSWORD;
299 if (from->user_expiration == NEVERDATE) {
300 to->userExpiration = 0;
302 to->userExpiration = from->user_expiration;
305 to->lastModTime = from->modification_time;
306 strcpy(to->lastModPrincipal.principal, from->modification_user.name);
307 strcpy(to->lastModPrincipal.instance, from->modification_user.instance);
308 to->lastChangePasswordTime = from->change_password_time;
309 to->maxTicketLifetime = from->max_ticket_lifetime;
310 to->keyVersion = from->key_version;
311 memcpy(&to->key, &from->key, sizeof(to->key));
312 to->keyCheckSum = from->keyCheckSum;
314 unpack_long(from->misc_auth_bytes, misc_stuff);
315 to->daysToPasswordExpire = misc_stuff[0];
316 to->failLoginCount = misc_stuff[2];
317 to->lockTime = misc_stuff[3] << 9;
320 fail_kaentryinfo_to_kas_principalEntry_t:
329 * kas_ServerOpen - open a handle to a set of kaserver's.
333 * IN cellHandle - a previously opened cellHandle that corresponds
334 * to the cell where the server(s) live.
336 * IN serverList - a NULL terminated list (a la argv) of server's that
339 * OUT serverHandleP - a pointer to a void pointer that upon successful
340 * completion contains serverHandle that can be used in other kas functions.
344 * No locks are obtained or released by this function
348 * Returns != 0 upon successful completion.
352 * This function make some assumptions about the afsconf_cell used by
353 * ka_AuthSpecificServersConn (since I just wrote ka_AuthSpecificServersConn).
354 * It only fills in the fields that are required.
356 * Also we assume that the servers listed are members of the cell in
357 * cellHandle without verifying that this is in fact the case. kas itself
358 * always assumes that the -servers parameter lists servers in the current
359 * cell without verifying, so I am no worse than the current
360 * implementation. In fact I'm actually a little more flexible since you
361 * can actually use my serverList to play with servers in another cell.
362 * You can't do that with kas. For certain functions in kas the same
363 * cell assumption can cause things to fail (the ka_StringToKey function in
368 kas_ServerOpen(const void *cellHandle, const char **serverList,
369 void **serverHandleP, afs_status_p st)
372 afs_status_t tst = 0;
373 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
374 int server_count = 0, server_addr;
375 struct afsconf_cell server_info;
376 kas_server_p k_handle = (kas_server_p) malloc(sizeof(kas_server_t));
379 * Validate input parameters
382 if (c_handle == NULL) {
383 tst = ADMCLIENTCELLHANDLENULL;
384 goto fail_kas_ServerOpen;
387 if (c_handle->kas_valid == 0) {
388 tst = ADMCLIENTCELLKASINVALID;
389 goto fail_kas_ServerOpen;
392 if (serverList == NULL) {
393 tst = ADMKASSERVERLISTNULL;
394 goto fail_kas_ServerOpen;
397 if (serverHandleP == NULL) {
398 tst = ADMKASSERVERHANDLEPNULL;
399 goto fail_kas_ServerOpen;
402 if (k_handle == NULL) {
404 goto fail_kas_ServerOpen;
407 k_handle->begin_magic = BEGIN_MAGIC;
408 k_handle->end_magic = END_MAGIC;
409 k_handle->is_valid = 0;
410 k_handle->servers = NULL;
413 * Convert serverList to numeric addresses
416 for (server_count = 0; serverList[server_count] != NULL; server_count++) {
417 if (server_count >= MAXHOSTSPERCELL) {
418 tst = ADMKASSERVERLISTTOOLONG;
419 goto fail_kas_ServerOpen;
421 if (util_AdminServerAddressGetFromName
422 (serverList[server_count], &server_addr, &tst)) {
423 server_info.hostAddr[server_count].sin_addr.s_addr =
425 server_info.hostAddr[server_count].sin_port =
426 htons(AFSCONF_KAUTHPORT);
428 goto fail_kas_ServerOpen;
432 if (server_count == 0) {
433 tst = ADMKASSERVERLISTEMPTY;
434 goto fail_kas_ServerOpen;
438 * Get a ubik_client handle for the specified servers
440 server_info.numServers = server_count;
443 ka_AuthSpecificServersConn(KA_MAINTENANCE_SERVICE,
444 &c_handle->tokens->kas_token,
445 &server_info, &k_handle->servers))) {
446 k_handle->is_valid = 1;
447 k_handle->cell = c_handle->working_cell;
448 *serverHandleP = (void *)k_handle;
450 goto fail_kas_ServerOpen;
456 if ((rc == 0) && (k_handle != NULL)) {
467 * kas_ServerClose - close a serverHandle.
471 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
475 * No locks are obtained or released by this function
479 * Returns != 0 upon successful completion.
483 kas_ServerClose(const void *serverHandle, afs_status_p st)
486 afs_status_t tst = 0;
487 kas_server_p k_handle = (kas_server_p) serverHandle;
489 if (!IsValidServerHandle(k_handle, &tst)) {
490 goto fail_kas_ServerClose;
493 tst = ubik_ClientDestroy(k_handle->servers);
495 goto fail_kas_ServerClose;
498 k_handle->is_valid = 0;
502 fail_kas_ServerClose:
511 * kas_PrincipalCreate - create a new principal.
515 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
517 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
519 * IN who - a kas_identity_p containing the identity of the new principal
522 * IN password - the new principal's initial password.
526 * No locks are obtained or released by this function
530 * Returns != 0 upon successful completion.
534 kas_PrincipalCreate(const void *cellHandle, const void *serverHandle,
535 const kas_identity_p who, const char *password,
539 afs_status_t tst = 0;
540 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
541 kas_server_p k_handle = (kas_server_p) serverHandle;
542 kas_server_t kaserver;
543 struct kas_encryptionKey key;
546 * Validate input arguments and make rpc.
551 goto fail_kas_PrincipalCreate;
554 if (password == NULL) {
555 tst = ADMKASPASSWORDNULL;
556 goto fail_kas_PrincipalCreate;
559 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
560 goto fail_kas_PrincipalCreate;
563 if (!kas_StringToKey(kaserver.cell, password, &key, &tst)) {
564 goto fail_kas_PrincipalCreate;
568 ubik_Call(KAM_CreateUser, kaserver.servers, 0, who->principal,
571 goto fail_kas_PrincipalCreate;
576 fail_kas_PrincipalCreate:
585 * kas_PrincipalDelete - delete an existing principal.
589 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
591 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
593 * IN who - a kas_identity_p containing the identity of the principal
598 * No locks are obtained or released by this function
602 * Returns != 0 upon successful completion.
606 kas_PrincipalDelete(const void *cellHandle, const void *serverHandle,
607 const kas_identity_p who, afs_status_p st)
610 afs_status_t tst = 0;
611 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
612 kas_server_p k_handle = (kas_server_p) serverHandle;
613 kas_server_t kaserver;
616 * Validate input arguments and make rpc.
621 goto fail_kas_PrincipalDelete;
624 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
625 goto fail_kas_PrincipalDelete;
628 ubik_Call(KAM_DeleteUser, kaserver.servers, 0, who->principal,
631 goto fail_kas_PrincipalDelete;
635 fail_kas_PrincipalDelete:
644 * GetPrincipalLockStatus - get the lock status of a principal.
648 * IN kaserver - a valid kaserver handle previously returned by
651 * IN who - a kas_identity_p containing the identity of the principal
654 * OUT lockedUntil - the remaining number of seconds the principal is locked.
658 * No locks are obtained or released by this function
662 * Returns != 0 upon successful completion.
666 GetPrincipalLockStatus(const kas_server_p kaserver, const kas_identity_p who,
667 unsigned int *lockedUntil, afs_status_p st)
670 afs_status_t tst = 0;
676 * Validate input arguments and make rpc.
679 if (kaserver == NULL) {
680 tst = ADMKASKASERVERNULL;
681 goto fail_GetPrincipalLockStatus;
686 goto fail_GetPrincipalLockStatus;
689 if (lockedUntil == NULL) {
690 tst = ADMKASLOCKEDUNTILNULL;
691 goto fail_GetPrincipalLockStatus;
695 * Unlike every other kas rpc we make here, the lock/unlock rpc's
696 * aren't ubik based. So instead of calling ubik_Call, we use
697 * ubik_CallIter. ubik_CallIter steps through the list of hosts
698 * in the ubik_client and calls them one at a time. Since there's
699 * no synchronization of this data across the servers we have to
700 * manually keep track of the shortest time to unlock the user ourselves.
702 * The original inspiration for this function is ka_islocked
703 * in admin_tools.c. I think that function is totally bogus so I'm
706 * This function should contact all the kaservers and request the lock
707 * status of the principal. If any of the servers say the principal is
708 * unlocked, we report it as unlocked. If all the servers say the
709 * principal is locked, we find the server with the shortest lock time
710 * remaining on the principal and return that time.
712 * This is different than kas, but I think kas is buggy.
719 ubik_CallIter(KAM_LockStatus, kaserver->servers, UPUBIKONLY,
720 &count, who->principal, who->instance, &locked, 0,
721 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
724 if ((locked < *lockedUntil) || !once) {
725 *lockedUntil = locked;
730 } while ((tst != UNOSERVERS) && (locked != 0));
733 * Check to see if any server reported this principal unlocked.
736 if ((tst == 0) && (locked == 0)) {
739 if ((tst == 0) || (tst == UNOSERVERS)) {
743 fail_GetPrincipalLockStatus:
752 * kas_PrincipalGet - retrieve information about a single principal.
756 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
758 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
760 * IN who - a kas_identity_p containing the identity of the principal
763 * OUT principal - upon successful completion contains information
768 * No locks are obtained or released by this function
772 * Returns != 0 upon successful completion.
776 kas_PrincipalGet(const void *cellHandle, const void *serverHandle,
777 const kas_identity_p who, kas_principalEntry_p principal,
781 afs_status_t tst = 0;
782 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
783 kas_server_p k_handle = (kas_server_p) serverHandle;
784 kas_server_t kaserver;
785 struct kaentryinfo entry;
788 * Validate input arguments and make rpc.
793 goto fail_kas_PrincipalGet;
796 if (principal == NULL) {
797 tst = ADMKASPRINCIPALNULL;
798 goto fail_kas_PrincipalGet;
801 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
802 goto fail_kas_PrincipalGet;
806 ubik_Call(KAM_GetEntry, kaserver.servers, 0, who->principal,
807 who->instance, KAMAJORVERSION, &entry);
809 goto fail_kas_PrincipalGet;
813 * copy the kaentryinfo structure to our kas_principalEntry_t
816 if (!kaentryinfo_to_kas_principalEntry_t(&entry, principal, &tst)) {
817 goto fail_kas_PrincipalGet;
821 fail_kas_PrincipalGet:
829 typedef struct principal_get {
833 kas_server_t kaserver;
834 kas_identity_t principal[CACHED_ITEMS];
835 } principal_get_t, *principal_get_p;
838 DeletePrincipalSpecificData(void *rpc_specific, afs_status_p st)
841 afs_status_t tst = 0;
842 principal_get_p prin = (principal_get_p) rpc_specific;
844 prin->kaserver.is_valid = 0;
854 GetPrincipalRPC(void *rpc_specific, int slot, int *last_item,
855 int *last_item_contains_data, afs_status_p st)
858 afs_status_t tst = 0;
859 principal_get_p prin = (principal_get_p) rpc_specific;
862 ubik_Call(KAM_ListEntry, prin->kaserver.servers, 0, prin->current,
863 &prin->next, &prin->count, &prin->principal[slot]);
865 prin->current = prin->next;
866 if (prin->next == 0) {
868 *last_item_contains_data = 0;
880 GetPrincipalFromCache(void *rpc_specific, int slot, void *dest,
884 afs_status_t tst = 0;
885 principal_get_p prin = (principal_get_p) rpc_specific;
887 memcpy(dest, &prin->principal[slot], sizeof(kas_identity_t));
897 * kas_PrincipalGetBegin - start the process of iterating over the entire
902 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
904 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
906 * OUT iterationIdP - upon successful completion contains a iterator that
907 * can be passed to kas_PrincipalGetNext.
911 * No locks are obtained or released by this function
915 * Returns != 0 upon successful completion.
921 kas_PrincipalGetBegin(const void *cellHandle, const void *serverHandle,
922 void **iterationIdP, afs_status_p st)
925 afs_status_t tst = 0;
926 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
927 kas_server_p k_handle = (kas_server_p) serverHandle;
928 afs_admin_iterator_p iter =
929 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
930 principal_get_p principal =
931 (principal_get_p) malloc(sizeof(principal_get_t));
939 goto fail_kas_PrincipalGetBegin;
942 if (principal == NULL) {
944 goto fail_kas_PrincipalGetBegin;
947 if (iterationIdP == NULL) {
948 tst = ADMITERATIONIDPNULL;
949 goto fail_kas_PrincipalGetBegin;
952 if (!ChooseValidServer(c_handle, k_handle, &principal->kaserver, &tst)) {
953 goto fail_kas_PrincipalGetBegin;
957 * Initialize the iterator structure
960 principal->current = 0;
962 principal->count = 0;
964 (iter, (void *)principal, GetPrincipalRPC, GetPrincipalFromCache,
965 NULL, DeletePrincipalSpecificData, &tst)) {
966 *iterationIdP = (void *)iter;
970 fail_kas_PrincipalGetBegin:
976 if (principal != NULL) {
988 * kas_PrincipalGetNext - retrieve the next principal from the kaserver.
992 * IN iterationId - an iterator previously returned by kas_PrincipalGetBegin
994 * OUT who - upon successful completion contains the next principal from the
999 * Hold the iterator mutex across the call to the kaserver.
1003 * Returns != 0 upon successful completion.
1004 * Returns 0 and st == ADMITERATORDONE when the last entry is returned.
1008 kas_PrincipalGetNext(const void *iterationId, kas_identity_p who,
1012 afs_status_t tst = 0;
1013 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1016 * Validate arguments
1020 tst = ADMKASWHONULL;
1021 goto fail_kas_PrincipalGetNext;
1025 tst = ADMITERATORNULL;
1026 goto fail_kas_PrincipalGetNext;
1029 rc = IteratorNext(iter, (void *)who, &tst);
1031 fail_kas_PrincipalGetNext:
1040 * kas_PrincipalGetDone - finish using a principal iterator
1044 * IN iterationId - an iterator previously returned by kas_PrincipalGetBegin
1048 * No locks are held by this function.
1052 * Returns != 0 upon successful completion.
1056 * It is the user's responsibility to make sure kas_PrincipalGetDone
1057 * is called only once for each iterator.
1061 kas_PrincipalGetDone(const void *iterationIdP, afs_status_p st)
1064 afs_status_t tst = 0;
1065 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationIdP;
1072 tst = ADMITERATORNULL;
1073 goto fail_kas_PrincipalGetDone;
1076 rc = IteratorDone(iter, &tst);
1078 fail_kas_PrincipalGetDone:
1087 * kas_PrincipalKeySet - set a principal's password to a known value.
1091 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1093 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1095 * IN who - the principal for whom the password is being set.
1097 * IN keyVersion - the version number of the new key.
1099 * IN key - the new password.
1103 * No locks are held by this function.
1107 * Returns != 0 upon successful completion.
1111 kas_PrincipalKeySet(const void *cellHandle, const void *serverHandle,
1112 const kas_identity_p who, int keyVersion,
1113 const kas_encryptionKey_p key, afs_status_p st)
1116 afs_status_t tst = 0;
1117 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1118 kas_server_p k_handle = (kas_server_p) serverHandle;
1119 kas_server_t kaserver;
1122 * Validate input arguments and make rpc.
1126 tst = ADMKASWHONULL;
1127 goto fail_kas_PrincipalKeySet;
1131 tst = ADMKASKEYNULL;
1132 goto fail_kas_PrincipalKeySet;
1135 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1136 goto fail_kas_PrincipalKeySet;
1140 ubik_Call(KAM_SetPassword, kaserver.servers, 0, who->principal,
1141 who->instance, keyVersion, *key);
1143 goto fail_kas_PrincipalKeySet;
1146 /* If we failed to fail we must have succeeded */
1149 fail_kas_PrincipalKeySet:
1158 * kas_PrincipalLockStatusGet - determine a principal's lock status.
1162 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1164 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1166 * IN who - the principal whose lock status is being checked.
1168 * OUT lock_end_timeP - the number of seconds until the principal is unlocked.
1169 * If 0 => user is unlocked.
1173 * No locks are held by this function.
1177 * Returns != 0 upon successful completion.
1181 * See the comments in GetPrincipalLockStatus regarding how the locking data
1182 * is kept INconsistently between servers.
1186 kas_PrincipalLockStatusGet(const void *cellHandle, const void *serverHandle,
1187 const kas_identity_p who,
1188 unsigned int *lock_end_timeP, afs_status_p st)
1191 afs_status_t tst = 0;
1192 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1193 kas_server_p k_handle = (kas_server_p) serverHandle;
1194 kas_server_t kaserver;
1197 * Validate input arguments and make rpc.
1201 tst = ADMKASWHONULL;
1202 goto fail_kas_PrincipalLockStatusGet;
1205 if (lock_end_timeP == NULL) {
1206 tst = ADMKASLOCKENDTIMEPNULL;
1207 goto fail_kas_PrincipalLockStatusGet;
1210 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1211 goto fail_kas_PrincipalLockStatusGet;
1214 rc = GetPrincipalLockStatus(&kaserver, who, lock_end_timeP, &tst);
1216 fail_kas_PrincipalLockStatusGet:
1225 * kas_PrincipalUnlock - unlock a principal.
1229 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1231 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1233 * IN who - the principal who is being unlocked.
1237 * No locks are held by this function.
1241 * Returns != 0 upon successful completion.
1245 * See the comments in GetPrincipalLockStatus regarding how the locking data
1246 * is kept INconsistently between servers.
1250 kas_PrincipalUnlock(const void *cellHandle, const void *serverHandle,
1251 const kas_identity_p who, afs_status_p st)
1254 afs_status_t tst = 0;
1255 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1256 kas_server_p k_handle = (kas_server_p) serverHandle;
1257 kas_server_t kaserver;
1259 afs_status_t save_tst = 0;
1262 * Validate input arguments and make rpc.
1266 tst = ADMKASWHONULL;
1267 goto fail_kas_PrincipalUnlock;
1270 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1271 goto fail_kas_PrincipalUnlock;
1276 ubik_CallIter(KAM_Unlock, kaserver.servers, 0, &count,
1277 who->principal, who->instance, 0, 0, 0, 0);
1278 if (tst && (tst != UNOSERVERS)) {
1279 if (save_tst == 0) {
1280 save_tst = tst; /* save the first failure */
1283 } while (tst != UNOSERVERS);
1285 if ((tst == 0) || (tst == UNOSERVERS)) {
1289 fail_kas_PrincipalUnlock:
1298 getPrincipalFlags(const void *cellHandle, const void *serverHandle,
1299 const kas_identity_p who, afs_int32 * cur_flags,
1303 afs_status_t tst = 0;
1304 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1305 kas_server_p k_handle = (kas_server_p) serverHandle;
1306 kas_server_t kaserver;
1307 struct kaentryinfo tentry;
1309 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1310 goto fail_getPrincipalFlags;
1314 ubik_Call(KAM_GetEntry, kaserver.servers, 0, who->principal,
1315 who->instance, KAMAJORVERSION, &tentry);
1317 *cur_flags = tentry.flags;
1321 fail_getPrincipalFlags:
1330 * kas_PrincipalFieldsSet - modify an existing principal.
1334 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1336 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1338 * IN who - the principal who is being modified.
1340 * IN isAdmin - the admin status of the principal.
1342 * IN grantTickets - should the TGS issue tickets for the principal.
1344 * IN canEncrypt - should the TGS allow the use of encryption via the
1347 * IN canChangePassword - should the principal be allowed to change their
1350 * IN expirationDate - the date when the principal will expire.
1352 * IN maxTicketLifetime - the maximum lifetime of a ticket issued for
1355 * IN passwordExpires - the maximum number of days a particular
1356 * password can be used. The limit is 255, 0 => no expiration.
1358 * IN passwordReuse - can a password be reused by this principal.
1360 * IN failedPasswordAttempts - number of failed login attempts before
1361 * a principal is locked. The limit is 255, 0 => no limit.
1363 * IN failedPasswordLockTime - the number of seconds a principal is
1364 * locked once failedPasswordAttempts is reached. Some bizarre rounding
1365 * occurs for this value, see kas for more details.
1369 * No locks are held by this function.
1373 * Returns != 0 upon successful completion.
1377 * See the comments in GetPrincipalLockStatus regarding how the locking data
1378 * is kept INconsistently between servers.
1382 kas_PrincipalFieldsSet(const void *cellHandle, const void *serverHandle,
1383 const kas_identity_p who, const kas_admin_p isAdmin,
1384 const kas_tgs_p grantTickets,
1385 const kas_enc_p canEncrypt,
1386 const kas_cpw_p canChangePassword,
1387 const unsigned int *expirationDate,
1388 const unsigned int *maxTicketLifetime,
1389 const unsigned int *passwordExpires,
1390 const kas_rpw_p passwordReuse,
1391 const unsigned int *failedPasswordAttempts,
1392 const unsigned int *failedPasswordLockTime,
1396 afs_status_t tst = 0;
1397 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1398 kas_server_p k_handle = (kas_server_p) serverHandle;
1399 kas_server_t kaserver;
1400 afs_int32 flags = 0;
1401 Date expiration = 0;
1402 afs_int32 lifetime = 0;
1404 char spare_bytes[4] = { 0, 0, 0, 0 };
1405 int somethings_changing = 0;
1408 * Validate input arguments.
1412 tst = ADMKASWHONULL;
1413 goto fail_kas_PrincipalFieldsSet;
1417 * set flags based upon input
1419 * If we're changing the flags, we need to get the current value of
1420 * the flags first and then make the changes
1423 if ((isAdmin != NULL) || (grantTickets != NULL) || (canEncrypt != NULL)
1424 || (canChangePassword != NULL)) {
1425 if (!getPrincipalFlags(cellHandle, serverHandle, who, &flags, &tst)) {
1426 goto fail_kas_PrincipalFieldsSet;
1430 if (isAdmin != NULL) {
1431 somethings_changing = 1;
1432 if (*isAdmin == KAS_ADMIN) {
1439 if (grantTickets != NULL) {
1440 somethings_changing = 1;
1441 if (*grantTickets == NO_TGS) {
1448 if (canEncrypt != NULL) {
1449 somethings_changing = 1;
1450 if (*canEncrypt == NO_ENCRYPT) {
1453 flags &= ~KAFNOSEAL;
1457 if (canChangePassword != NULL) {
1458 somethings_changing = 1;
1459 if (*canChangePassword == NO_CHANGE_PASSWORD) {
1466 flags = (flags & KAF_SETTABLE_FLAGS) | KAFNORMAL;
1468 if (expirationDate != NULL) {
1469 somethings_changing = 1;
1470 expiration = *expirationDate;
1473 if (maxTicketLifetime != NULL) {
1474 somethings_changing = 1;
1475 lifetime = *maxTicketLifetime;
1478 if (passwordExpires != NULL) {
1479 if (*passwordExpires > 255) {
1480 tst = ADMKASPASSWORDEXPIRESTOOBIG;
1481 goto fail_kas_PrincipalFieldsSet;
1483 somethings_changing = 1;
1484 spare_bytes[0] = *passwordExpires + 1;
1487 if (passwordReuse != NULL) {
1488 somethings_changing = 1;
1489 if (*passwordReuse == REUSE_PASSWORD) {
1490 spare_bytes[1] = KA_REUSEPW;
1492 spare_bytes[1] = KA_NOREUSEPW;
1496 if (failedPasswordAttempts != NULL) {
1497 if (*failedPasswordAttempts > 255) {
1498 tst = ADMKASFAILEDPASSWORDATTEMPTSTOOBIG;
1499 goto fail_kas_PrincipalFieldsSet;
1501 somethings_changing = 1;
1502 spare_bytes[2] = *failedPasswordAttempts + 1;
1505 if (failedPasswordLockTime != NULL) {
1506 if (*failedPasswordLockTime > 36 * 60 * 60) {
1507 tst = ADMKASFAILEDPASSWORDLOCKTIME;
1508 goto fail_kas_PrincipalFieldsSet;
1510 somethings_changing = 1;
1511 spare_bytes[3] = ((*failedPasswordLockTime + 511) >> 9) + 1;
1514 was_spare = pack_long(spare_bytes);
1516 if (somethings_changing) {
1517 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1518 goto fail_kas_PrincipalFieldsSet;
1521 ubik_Call(KAM_SetFields, kaserver.servers, 0, who->principal,
1522 who->instance, flags, expiration, lifetime, -1,
1528 tst = ADMKASPRINCIPALFIELDSNOCHANGE;
1531 fail_kas_PrincipalFieldsSet:
1540 * kas_ServerStatsGet - get server statistics.
1544 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1546 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1548 * OUT stats - the statistics retrieved.
1552 * No locks are held by this function.
1556 * Returns != 0 upon successful completion.
1560 kas_ServerStatsGet(const void *cellHandle, const void *serverHandle,
1561 kas_serverStats_p stats, afs_status_p st)
1564 afs_status_t tst = 0;
1565 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1566 kas_server_p k_handle = (kas_server_p) serverHandle;
1567 kas_server_t kaserver;
1574 * Validate input arguments and make rpc.
1577 if (stats == NULL) {
1578 tst = ADMKASSTATSNULL;
1579 goto fail_kas_ServerStatsGet;
1582 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1583 goto fail_kas_ServerStatsGet;
1587 ubik_Call(KAM_GetStats, kaserver.servers, 0, KAMAJORVERSION, &admins,
1588 &statics, &dynamics);
1590 goto fail_kas_ServerStatsGet;
1593 stats->allocations = statics.allocs;
1594 stats->frees = statics.frees;
1595 stats->changePasswordRequests = statics.cpws;
1596 stats->adminAccounts = admins;
1597 stats->host = dynamics.host;
1598 stats->serverStartTime = dynamics.start_time;
1599 stats->hashTableUtilization = dynamics.hashTableUtilization;
1601 i = sizeof(kas_serverProcStats_t);
1602 memcpy(&stats->authenticate, &dynamics.Authenticate, i);
1603 memcpy(&stats->changePassword, &dynamics.ChangePassword, i);
1604 memcpy(&stats->getTicket, &dynamics.GetTicket, i);
1605 memcpy(&stats->createUser, &dynamics.CreateUser, i);
1606 memcpy(&stats->setPassword, &dynamics.SetPassword, i);
1607 memcpy(&stats->setFields, &dynamics.SetFields, i);
1608 memcpy(&stats->deleteUser, &dynamics.DeleteUser, i);
1609 memcpy(&stats->getEntry, &dynamics.GetEntry, i);
1610 memcpy(&stats->listEntry, &dynamics.ListEntry, i);
1611 memcpy(&stats->getStats, &dynamics.GetStats, i);
1612 memcpy(&stats->getPassword, &dynamics.GetPassword, i);
1613 memcpy(&stats->getRandomKey, &dynamics.GetRandomKey, i);
1614 memcpy(&stats->debug, &dynamics.Debug, i);
1615 memcpy(&stats->udpAuthenticate, &dynamics.UAuthenticate, i);
1616 memcpy(&stats->udpGetTicket, &dynamics.UGetTicket, i);
1617 memcpy(&stats->unlock, &dynamics.Unlock, i);
1618 memcpy(&stats->lockStatus, &dynamics.LockStatus, i);
1620 stats->stringChecks = dynamics.string_checks;
1623 fail_kas_ServerStatsGet:
1632 * kas_ServerDebugGet - get server debug info.
1636 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1638 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1640 * OUT stats - the debug info retrieved.
1644 * No locks are held by this function.
1648 * Returns != 0 upon successful completion.
1652 kas_ServerDebugGet(const void *cellHandle, const void *serverHandle,
1653 kas_serverDebugInfo_p debug, afs_status_p st)
1656 afs_status_t tst = 0;
1657 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1658 kas_server_p k_handle = (kas_server_p) serverHandle;
1659 kas_server_t kaserver;
1660 struct ka_debugInfo info;
1664 * Validate input arguments and make rpc.
1667 if (debug == NULL) {
1668 tst = ADMKASDEBUGNULL;
1669 goto fail_kas_ServerDebugGet;
1672 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1673 goto fail_kas_ServerDebugGet;
1675 tst = ubik_Call(KAM_Debug, kaserver.servers, 0, KAMAJORVERSION, 0, &info);
1677 goto fail_kas_ServerDebugGet;
1679 debug->host = info.host;
1680 debug->serverStartTime = info.startTime;
1681 debug->currentTime = info.reserved1;
1682 debug->noAuth = info.noAuth;
1683 debug->lastTransaction = info.lastTrans;
1684 strcpy(debug->lastOperation, info.lastOperation);
1685 strcpy(debug->lastPrincipalAuth, info.lastAuth);
1686 strcpy(debug->lastPrincipalUDPAuth, info.lastUAuth);
1687 strcpy(debug->lastPrincipalTGS, info.lastTGS);
1688 strcpy(debug->lastPrincipalUDPTGS, info.lastUTGS);
1689 strcpy(debug->lastPrincipalAdmin, info.lastAdmin);
1690 strcpy(debug->lastServerTGS, info.lastTGSServer);
1691 strcpy(debug->lastServerUDPTGS, info.lastUTGSServer);
1692 debug->nextAutoCheckPointWrite = info.nextAutoCPW;
1693 debug->updatesRemainingBeforeAutoCheckPointWrite = info.updatesRemaining;
1694 debug->dbHeaderRead = info.dbHeaderRead;
1695 debug->dbVersion = info.dbVersion;
1696 debug->dbFreePtr = info.dbFreePtr;
1697 debug->dbEOFPtr = info.dbEofPtr;
1698 debug->dbKvnoPtr = info.dbKvnoPtr;
1699 debug->dbSpecialKeysVersion = info.dbSpecialKeysVersion;
1700 debug->dbHeaderLock = info.cheader_lock;
1701 debug->keyCacheLock = info.keycache_lock;
1702 debug->keyCacheVersion = info.kcVersion;
1703 debug->keyCacheSize = info.kcSize;
1704 debug->keyCacheUsed = info.kcUsed;
1705 for (i = 0; i < info.kcUsed; i++) {
1706 debug->keyCache[i].lastUsed = info.kcInfo[i].used;
1707 debug->keyCache[i].keyVersionNumber = info.kcInfo[i].kvno;
1708 debug->keyCache[i].primary = info.kcInfo[i].primary;
1709 debug->keyCache[i].keyCheckSum = info.kcInfo[i].keycksum;
1710 strcpy(debug->keyCache[i].principal, info.kcInfo[i].principal);
1714 fail_kas_ServerDebugGet:
1723 * kas_ServerRandomKeyGet - get a random key from a server.
1727 * IN cellHandle - a cellHandle previously returned by afsclient_CellOpen.
1729 * IN serverHandle - a serverHandle previously returned by kas_ServerOpen.
1731 * OUT key - a random key.
1735 * No locks are held by this function.
1739 * Returns != 0 upon successful completion.
1743 kas_ServerRandomKeyGet(const void *cellHandle, const void *serverHandle,
1744 kas_encryptionKey_p key, afs_status_p st)
1747 afs_status_t tst = 0;
1748 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1749 kas_server_p k_handle = (kas_server_p) serverHandle;
1750 kas_server_t kaserver;
1753 * Validate input arguments and make rpc.
1757 tst = ADMKASKEYNULL;
1758 goto fail_kas_ServerRandomKeyGet;
1761 if (!ChooseValidServer(c_handle, k_handle, &kaserver, &tst)) {
1762 goto fail_kas_ServerRandomKeyGet;
1765 tst = ubik_Call(KAM_GetRandomKey, kaserver.servers, 0, key);
1767 goto fail_kas_ServerRandomKeyGet;
1771 fail_kas_ServerRandomKeyGet:
1780 * kas_StringToKey - turn a string key into a key.
1784 * IN cellName - the name of the cell where the key will be used.
1786 * IN string - the string to be converted.
1788 * OUT key - the encryption key.
1792 * No locks are held by this function.
1796 * Returns != 0 upon successful completion.
1800 kas_StringToKey(const char *cellName, const char *string,
1801 kas_encryptionKey_p key, afs_status_p st)
1804 afs_status_t tst = 0;
1806 ka_StringToKey(string, cellName, (struct ktc_encryptionKey *)key);
1817 * kas_KeyCheckSum - compute the checksum of an encryption key.
1821 * IN key - the encryption key.
1823 * OUT cksumP - key checksum
1827 * No locks are held by this function.
1831 * Returns != 0 upon successful completion.
1835 kas_KeyCheckSum(const kas_encryptionKey_p key, unsigned int *cksumP,
1839 afs_status_t tst = 0;
1842 if ((tst = ka_KeyCheckSum((char *)key, &cksum32)) == 0) {