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 implements configuration functions in the following categories:
11 * cfg_Host*() - manipulate static server configuration information.
14 #include <afsconfig.h>
15 #include <afs/param.h>
26 #include <sys/types.h>
33 #include <WINNT/vptab.h>
34 #include <WINNT/afsreg.h>
39 #endif /* AFS_NT40_ENV */
41 #include <afs/afs_Admin.h>
42 #include <afs/afs_AdminErrors.h>
43 #include <afs/afs_utilAdmin.h>
44 #include <afs/afs_bosAdmin.h>
45 #include <afs/afs_clientAdmin.h>
46 #include <afs/afs_kasAdmin.h>
47 #include <afs/afs_ptsAdmin.h>
50 #include <afs/kautils.h>
51 #include <afs/bnode.h>
52 #include <afs/prerror.h>
54 #include <afs/dirpath.h>
55 #include <afs/cellconfig.h>
57 #include "cfginternal.h"
58 #include "afs_cfgAdmin.h"
59 #include "../adminutil/afs_AdminInternal.h"
63 /* Local declarations and definitions */
66 KasKeyIsZero(kas_encryptionKey_t *kasKey);
69 KasKeyEmbeddedInString(const char *keyString, kas_encryptionKey_t *kasKey);
74 /* ---------------- Exported Server Host functions ------------------ */
78 * cfg_HostQueryStatus() -- Query status of static server configuration
79 * on host, i.e., status of required configuration files, etc.
80 * Upon successful completion *configStP is set to the server
81 * configuration status, with a value of zero (0) indicating that
82 * the configuration is valid.
84 * If server configuration is not valid then *cellNameP is set to NULL;
85 * otherwise, *cellNameP is an allocated buffer containing server cell.
87 * Warning: in determining if server configuration is valid, no check
88 * is made for consistency with other servers in cell; also, the
89 * internal consistency of configuration files may not be verified.
92 cfg_HostQueryStatus(const char *hostName, /* name of host */
93 afs_status_p configStP, /* server config status */
94 char **cellNameP, /* server's cell */
95 afs_status_p st) /* completion status */
98 afs_status_t tst2, tst = 0;
99 afs_status_t serverSt = 0;
100 char *serverCellName = NULL;
102 /* validate parameters */
104 if (hostName == NULL || *hostName == '\0') {
105 tst = ADMCFGHOSTNAMENULL;
106 } else if (strlen(hostName) > (MAXHOSTCHARS - 1)) {
107 tst = ADMCFGHOSTNAMETOOLONG;
108 } else if (configStP == NULL) {
109 tst = ADMCFGCONFIGSTATUSPNULL;
110 } else if (cellNameP == NULL) {
111 tst = ADMCFGCELLNAMEPNULL;
114 /* remote configuration not yet supported; hostName must be local host */
119 if (!cfgutil_HostNameIsLocal(hostName, &isLocal, &tst2)) {
121 } else if (!isLocal) {
122 tst = ADMCFGNOTSUPPORTED;
126 /* check for existence and readability of required server config files */
130 const char *cfgfile[4];
132 cfgfile[0] = AFSDIR_SERVER_THISCELL_FILEPATH;
133 cfgfile[1] = AFSDIR_SERVER_CELLSERVDB_FILEPATH;
134 cfgfile[2] = AFSDIR_SERVER_KEY_FILEPATH;
135 cfgfile[3] = AFSDIR_SERVER_ULIST_FILEPATH;
137 for (i = 0; i < 4; i++) {
139 if ((fd = open(cfgfile[i], O_RDONLY)) < 0) {
146 if (errno == EACCES) {
149 serverSt = ADMCFGSERVERBASICINFOINVALID;
154 /* verify the required server config files to the degree possible */
156 if (tst == 0 && serverSt == 0) {
157 struct afsconf_dir *confdir;
159 if ((confdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH)) == NULL) {
160 /* one or more config files appears to be invalid */
161 serverSt = ADMCFGSERVERBASICINFOINVALID;
163 struct afsconf_entry *cellentry;
165 if (confdir->cellName == NULL || *confdir->cellName == '\0') {
166 /* no cell set for server */
167 serverSt = ADMCFGSERVERNOTINCELL;
168 } else if (confdir->keystr == NULL ||
169 confdir->keystr->nkeys == 0) {
171 serverSt = ADMCFGSERVERNOKEYS;
173 for (cellentry = confdir->entries;
175 cellentry = cellentry->next) {
176 if (!strcasecmp(confdir->cellName,
177 cellentry->cellInfo.name)) {
182 if (cellentry == NULL) {
183 serverSt = ADMCFGSERVERCELLNOTINDB;
184 } else if (cellentry->cellInfo.numServers <= 0) {
185 serverSt = ADMCFGSERVERCELLHASNODBENTRIES;
189 if (tst == 0 && serverSt == 0) {
190 /* everything looks good; malloc cell name buffer to return */
192 (char *) malloc(strlen(cellentry->cellInfo.name) + 1);
193 if (serverCellName == NULL) {
196 strcpy(serverCellName, cellentry->cellInfo.name);
200 (void)afsconf_Close(confdir);
205 /* return server status and cell name */
206 *configStP = serverSt;
209 *cellNameP = serverCellName;
214 /* indicate failure */
217 /* free cell name if allocated before failure */
218 if (serverCellName != NULL) {
219 free(serverCellName);
230 * cfg_HostOpen() -- Obtain host configuration handle.
233 cfg_HostOpen(void *cellHandle, /* cell handle */
234 const char *hostName, /* name of host to configure */
235 void **hostHandleP, /* host config handle */
236 afs_status_p st) /* completion status */
239 afs_status_t tst2, tst = 0;
241 char fullHostName[MAXHOSTCHARS];
243 /* validate parameters and resolve host name to fully qualified name */
245 if (!CellHandleIsValid(cellHandle, &tst2)) {
247 } else if (hostName == NULL || *hostName == '\0') {
248 tst = ADMCFGHOSTNAMENULL;
249 } else if (strlen(hostName) > (MAXHOSTCHARS - 1)) {
250 tst = ADMCFGHOSTNAMETOOLONG;
251 } else if (hostHandleP == NULL) {
252 tst = ADMCFGHOSTHANDLEPNULL;
253 } else if (!cfgutil_HostNameGetFull(hostName, fullHostName, &tst2)) {
257 /* remote configuration not yet supported; hostName must be local host */
262 if (!cfgutil_HostNameIsLocal(hostName, &isLocal, &tst2)) {
264 } else if (!isLocal) {
265 tst = ADMCFGNOTSUPPORTED;
269 /* allocate a host configuration handle */
274 if ((cfg_host = (cfg_host_p)malloc(sizeof(cfg_host_t))) == NULL) {
276 } else if ((localHostName =
277 (char *)malloc(strlen(fullHostName) + 1)) == NULL) {
281 /* initialize handle */
282 cfg_host->begin_magic = BEGIN_MAGIC;
283 cfg_host->is_valid = 1;
284 cfg_host->hostName = localHostName;
285 cfg_host->is_local = 1; /* not yet supporting remote config */
286 cfg_host->cellHandle = cellHandle;
287 cfg_host->bosHandle = NULL;
288 cfg_host->end_magic = END_MAGIC;
290 strcpy(localHostName, fullHostName);
292 if (!afsclient_CellNameGet(cfg_host->cellHandle,
293 &cfg_host->cellName, &tst2)) {
295 } else if (pthread_mutex_init(&cfg_host->mutex, NULL)) {
300 /* cell name lookup or mutex initialization failed */
308 /* success; return host config handle to user */
309 *hostHandleP = cfg_host;
311 /* indicate failure */
322 * cfg_HostClose() -- Release host configuration handle.
325 cfg_HostClose(void *hostHandle, /* host config handle */
326 afs_status_p st) /* completion status */
329 afs_status_t tst2, tst = 0;
330 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
332 /* validate parameters */
334 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
338 /* free handle; can assume no other thread using this handle */
341 /* mark cfg handle invalid in case use after free (bug catcher) */
342 cfg_host->is_valid = 0;
344 if (cfg_host->bosHandle != NULL) {
345 if (!bos_ServerClose(cfg_host->bosHandle, &tst2)) {
349 free(cfg_host->hostName);
350 (void)pthread_mutex_destroy(&cfg_host->mutex);
365 * cfg_HostSetCell() -- Define server cell membership for host.
367 * The cellDbHosts argument is a multistring containing the names of
368 * the existing database servers already configured in the cell; this
369 * multistring list can be obtained via cfg_CellServDbEnumerate().
370 * If configuring the first server in a new cell then the cellDbHosts
371 * list contains only the name of that host.
373 * Note: The names in cellDbHosts MUST exactly match those in the
374 * cell-wide server CellServDB; using cfg_CellServDbEnumerate()
375 * is highly recommended.
378 cfg_HostSetCell(void *hostHandle, /* host config handle */
379 const char *cellName, /* cell name */
380 const char *cellDbHosts, /* cell database hosts */
381 afs_status_p st) /* completion status */
384 afs_status_t tst2, tst = 0;
385 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
387 /* validate parameters */
389 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
391 } else if (cellName == NULL || *cellName == '\0') {
392 tst = ADMCFGCELLNAMENULL;
393 } else if (strlen(cellName) > (MAXCELLCHARS - 1)) {
394 tst = ADMCFGCELLNAMETOOLONG;
395 } else if (!cfgutil_HostHandleCellNameCompatible(cfg_host, cellName)) {
396 tst = ADMCFGCELLNAMECONFLICT;
397 } else if (cellDbHosts == NULL || *cellDbHosts == '\0') {
398 tst = ADMCFGCELLDBHOSTSNULL;
401 /* remote configuration not yet supported in this function */
404 if (!cfg_host->is_local) {
405 tst = ADMCFGNOTSUPPORTED;
409 /* define server cell and cell database hosts */
412 const char *dbHost = cellDbHosts;
413 struct afsconf_cell hostCell;
414 memset(&hostCell, 0, sizeof(hostCell));
416 strcpy(hostCell.name, cellName);
417 hostCell.numServers = 0;
419 while (*dbHost != '\0' && tst == 0) {
420 /* fill in each database host */
421 size_t dbHostLen = strlen(dbHost);
423 if (dbHostLen > (MAXHOSTCHARS - 1)) {
424 tst = ADMCFGHOSTNAMETOOLONG;
425 } else if (hostCell.numServers >= MAXHOSTSPERCELL) {
426 tst = ADMCFGCELLDBHOSTCOUNTTOOLARGE;
428 strcpy(hostCell.hostName[hostCell.numServers++], dbHost);
429 dbHost += dbHostLen + 1;
434 /* create server ThisCell/CellServDB dir if it does not exist */
436 (void) mkdir(AFSDIR_USR_DIRPATH);
437 (void) mkdir(AFSDIR_SERVER_AFS_DIRPATH);
438 (void) mkdir(AFSDIR_SERVER_ETC_DIRPATH);
440 (void) mkdir(AFSDIR_USR_DIRPATH, 0755);
441 (void) mkdir(AFSDIR_SERVER_AFS_DIRPATH, 0755);
442 (void) mkdir(AFSDIR_SERVER_ETC_DIRPATH, 0755);
444 if (afsconf_SetCellInfo(NULL,
445 AFSDIR_SERVER_ETC_DIRPATH, &hostCell)) {
446 /* failed; most likely cause is bad host name */
447 tst = ADMCFGSERVERSETCELLFAILED;
463 * cfg_HostSetAfsPrincipal() -- Put AFS server principal (afs) key in
464 * host's KeyFile; principal is created if it does not exist.
466 * If first server host in cell, passwd must be initial password for
467 * the afs principal; the afs principal is created.
469 * If additional server host, passwd can be specified or NULL; the
470 * afs principal must already exist by definition. If passwd is NULL
471 * then an attempt is made to fetch the afs key. If the key fetch fails
472 * because pre 3.5 database servers are in use (which will only return a
473 * key checksum) then the function fails with a return status of
474 * ADMCFGAFSKEYNOTAVAILABLE; in this case the function should be called
475 * again with passwd specified. If passwd is specified (not NULL) but the
476 * password key fails a checksum comparison with the current afs key
477 * then the function fails with a return status of ADMCFGAFSPASSWDINVALID.
479 * ASSUMPTIONS: Client configured and BOS server started; if first host in
480 * cell then Authentication server must be started as well.
483 cfg_HostSetAfsPrincipal(void *hostHandle, /* host config handle */
484 short isFirst, /* first server in cell flag */
485 const char *passwd, /* afs initial password */
486 afs_status_p st) /* completion status */
489 afs_status_t tst2, tst = 0;
490 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
492 /* validate parameters */
494 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
496 } else if ((isFirst && passwd == NULL) ||
497 (passwd != NULL && *passwd == '\0')) {
498 tst = ADMCFGPASSWDNULL;
501 /* put afs key in host's KeyFile */
504 kas_identity_t afsIdentity;
505 kas_encryptionKey_t afsKey;
508 strcpy(afsIdentity.principal, "afs");
509 afsIdentity.instance[0] = '\0';
512 /* create afs principal */
513 if (!kas_PrincipalCreate(cfg_host->cellHandle,
519 /* failed to create principal (and not because existed) */
525 /* retrive afs principal information to verify or obtain key */
526 kas_principalEntry_t afsEntry;
528 if (!kas_PrincipalGet(cfg_host->cellHandle,
535 if (passwd != NULL) {
536 /* password given; form key and verify as most recent */
537 kas_encryptionKey_t passwdKey;
538 unsigned int passwdKeyCksum;
540 if (!kas_StringToKey(cfg_host->cellName,
545 !kas_KeyCheckSum(&passwdKey, &passwdKeyCksum, &tst2)) {
546 /* failed to form key or key checksum */
549 } else if (passwdKeyCksum != afsEntry.keyCheckSum) {
550 /* passwd string does not generate most recent key;
551 * check if passwd string embeds key directly.
553 if (KasKeyEmbeddedInString(passwd, &passwdKey)) {
554 /* passwd string embeds kas key */
555 if (!kas_KeyCheckSum(&passwdKey,
556 &passwdKeyCksum, &tst2)) {
558 } else if (passwdKeyCksum !=
559 afsEntry.keyCheckSum) {
560 /* passwd string does not embed valid key */
561 tst = ADMCFGAFSPASSWDINVALID;
564 /* passwd string does NOT embed key */
565 tst = ADMCFGAFSPASSWDINVALID;
570 /* passwd seems to generate/embed most recent key */
572 afsKvno = afsEntry.keyVersion;
576 /* password NOT given; check if key retrieved since
577 * pre 3.5 database servers only return key checksum
579 if (KasKeyIsZero(&afsEntry.key)) {
580 tst = ADMCFGAFSKEYNOTAVAILABLE;
582 afsKey = afsEntry.key;
583 afsKvno = afsEntry.keyVersion;
590 /* add key to host's KeyFile; RPC must be unauthenticated;
591 * bosserver is presumed to be in noauth mode.
593 void *cellHandle, *bosHandle;
595 if (!afsclient_NullCellOpen(&cellHandle, &tst2)) {
598 if (!bos_ServerOpen(cellHandle,
599 cfg_host->hostName, &bosHandle, &tst2)) {
602 if (!bos_KeyCreate(bosHandle, afsKvno, &afsKey, &tst2) &&
603 tst2 != BZKEYINUSE) {
604 /* failed to add key (and not because existed) */
608 if (!bos_ServerClose(bosHandle, &tst2)) {
613 if (!afsclient_CellClose(cellHandle, &tst2)) {
631 * cfg_HostSetAdminPrincipal() -- Put generic administrator principal in
632 * host's UserList; principal is created if it does not exist.
634 * If first server host in cell, passwd and afsUid must be the initial
635 * password and the AFS UID for the admin principal; the admin principal
638 * If additional server host, passwd and afsUid are ignored; the admin
639 * principal is assumed to exist.
641 * ASSUMPTIONS: Client configured and BOS server started; if first host in
642 * cell then Authentication and Protection servers must be started as well.
645 cfg_HostSetAdminPrincipal(void *hostHandle, /* host config handle */
646 short isFirst, /* first server in cell flag */
647 const char *admin, /* admin principal name */
648 const char *passwd, /* admin initial password */
649 unsigned int afsUid, /* admin AFS UID */
650 afs_status_p st) /* completion status */
653 afs_status_t tst2, tst = 0;
654 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
656 /* validate parameters and prepare host handle for bos functions */
658 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
660 } else if (admin == NULL || *admin == '\0') {
661 tst = ADMCFGADMINPRINCIPALNULL;
662 } else if (strlen(admin) > (KAS_MAX_NAME_LEN - 1)) {
663 tst = ADMCFGADMINPRINCIPALTOOLONG;
664 } else if (isFirst && (passwd == NULL || *passwd == '\0')) {
665 tst = ADMCFGPASSWDNULL;
666 } else if (!cfgutil_HostHandleBosInit(cfg_host, &tst2)) {
670 /* put admin in host's UserList */
674 /* first server host in cell; create admin principal */
675 kas_identity_t adminIdentity;
676 int adminUid = afsUid;
677 kas_admin_t adminFlag = KAS_ADMIN;
679 strcpy(adminIdentity.principal, admin);
680 adminIdentity.instance[0] = '\0';
682 if (!kas_PrincipalCreate(cfg_host->cellHandle,
688 /* failed to create principal (and not because existed) */
691 } else if (!kas_PrincipalFieldsSet(cfg_host->cellHandle,
695 NULL, NULL, NULL, NULL,
696 NULL, NULL, NULL, NULL, NULL,
698 /* failed to set admin attributes */
701 } else if (!pts_UserCreate(cfg_host->cellHandle,
706 /* failed to create user (and not because existed) */
709 } else if (!pts_GroupMemberAdd(cfg_host->cellHandle,
711 "system:administrators",
714 /* failed to add to group (not because already there) */
720 /* add admin to host's UserList */
721 if (!bos_AdminCreate(cfg_host->bosHandle, admin, &tst2) &&
723 /* failed to add admin (and not because existed) */
724 /* DANGER: platform-specific errno values being returned */
741 * cfg_HostInvalidate() -- Invalidate static server configuration on host.
743 * Server configuration invalidated only if BOS server is not running.
746 cfg_HostInvalidate(void *hostHandle, /* host config handle */
747 afs_status_p st) /* completion status */
750 afs_status_t tst2, tst = 0;
751 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
753 /* validate parameters */
755 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
759 /* remote configuration not yet supported in this function */
762 if (!cfg_host->is_local) {
763 tst = ADMCFGNOTSUPPORTED;
767 /* make sure bosserver is not running on host */
770 /* Windows - bosserver is controlled via the BOS control service */
774 if (!cfgutil_WindowsServiceQuery(AFSREG_SVR_SVC_NAME,
778 } else if (svcState != SERVICE_STOPPED) {
779 tst = ADMCFGBOSSERVERACTIVE;
784 /* function not yet implemented for Unix */
785 tst = ADMCFGNOTSUPPORTED;
787 #endif /* AFS_NT40_ENV */
790 /* remove server state files */
794 const char *cfgdir[3];
796 cfgdir[0] = AFSDIR_SERVER_ETC_DIRPATH;
797 cfgdir[1] = AFSDIR_SERVER_DB_DIRPATH;
798 cfgdir[2] = AFSDIR_SERVER_LOCAL_DIRPATH;
800 for (i = 0; i < 3 && tst == 0; i++) {
801 if (!cfgutil_CleanDirectory(cfgdir[i], &tst2)) {
807 /* remove all vice partition table entries */
811 struct vpt_iter vpiter;
812 struct vptab vpentry;
814 /* note: ignore errors except from removal attempts */
816 if (!vpt_Start(&vpiter)) {
817 while (!vpt_NextEntry(&vpiter, &vpentry)) {
818 if (vpt_RemoveEntry(vpentry.vp_name)) {
819 /* ENOENT implies entry does not exist; consider removed */
820 if (errno != ENOENT) {
821 if (errno == EACCES) {
824 tst = ADMCFGVPTABLEWRITEFAILED;
829 (void)vpt_Finish(&vpiter);
833 /* function not yet implemented for unix */
835 tst = ADMCFGNOTSUPPORTED;
837 #endif /* AFS_NT40_ENV */
851 * cfg_HostPartitionTableEnumerate() -- Enumerate AFS partition table entries.
853 * If the partition table is empty (or does not exist) then *tablePP
854 * is set to NULL and *nEntriesP is set to zero (0).
856 * Partitions in table are not necessarily those being exported; a table
857 * entry may have been added or removed since the fileserver last started.
860 cfg_HostPartitionTableEnumerate(void *hostHandle, /* host config handle */
861 cfg_partitionEntry_t **tablePP, /* table */
862 int *nEntriesP, /* table entry count */
863 afs_status_p st) /* completion status */
866 afs_status_t tst2, tst = 0;
867 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
869 /* validate parameters */
871 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
873 } else if (tablePP == NULL) {
874 tst = ADMCFGVPTABLEPNULL;
875 } else if (nEntriesP == NULL) {
876 tst = ADMCFGVPTABLECOUNTPNULL;
879 /* remote configuration not yet supported in this function */
882 if (!cfg_host->is_local) {
883 tst = ADMCFGNOTSUPPORTED;
887 /* enumerate the vice partition table */
891 struct vpt_iter vpiter;
892 struct vptab vpentry;
893 int vpentryCountMax = 0;
895 /* count table entries */
897 if (vpt_Start(&vpiter)) {
898 /* ENOENT implies table does not exist (which is OK) */
899 if (errno != ENOENT) {
900 if (errno == EACCES) {
903 tst = ADMCFGVPTABLEREADFAILED;
907 while (!vpt_NextEntry(&vpiter, &vpentry)) {
910 if (errno != ENOENT) {
911 tst = ADMCFGVPTABLEREADFAILED;
913 (void)vpt_Finish(&vpiter);
916 /* alloc storage for table entries; handle any entry count change */
919 if (vpentryCountMax == 0) {
923 /* return a two-part table; first points into second */
925 size_t metaTableSize;
928 vpentryCountMax * (sizeof(cfg_partitionEntry_t) +
929 sizeof(struct vptab));
931 if ((metaTablep = (void *)malloc(metaTableSize)) == NULL) {
935 cfg_partitionEntry_t *cpePart;
936 struct vptab *vptPart;
937 int vpentryCount = 0;
939 cpePart = (cfg_partitionEntry_t *)metaTablep;
940 vptPart = (struct vptab *)(&cpePart[vpentryCountMax]);
942 for (i = 0; i < vpentryCountMax; i++) {
943 cpePart[i].partitionName = vptPart[i].vp_name;
944 cpePart[i].deviceName = vptPart[i].vp_dev;
947 if (vpt_Start(&vpiter)) {
948 /* ENOENT implies table does not exist (which is OK) */
949 if (errno != ENOENT) {
950 if (errno == EACCES) {
953 tst = ADMCFGVPTABLEREADFAILED;
957 for (i = 0; i < vpentryCountMax; i++) {
958 if (vpt_NextEntry(&vpiter, &vptPart[i])) {
963 if (i < vpentryCountMax && errno != ENOENT) {
964 tst = ADMCFGVPTABLEREADFAILED;
968 (void)vpt_Finish(&vpiter);
972 *nEntriesP = vpentryCount;
974 if (vpentryCount != 0) {
975 *tablePP = (cfg_partitionEntry_t *)metaTablep;
989 /* function not yet implemented for Unix */
991 tst = ADMCFGNOTSUPPORTED;
993 #endif /* AFS_NT40_ENV */
1006 * cfg_HostPartitionTableAddEntry() -- Add or update AFS partition table entry.
1009 cfg_HostPartitionTableAddEntry(void *hostHandle, /* host config handle */
1010 const char *partName, /* partition name */
1011 const char *devName, /* device name */
1012 afs_status_p st) /* completion status */
1015 afs_status_t tst2, tst = 0;
1016 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
1019 /* validate parameters */
1021 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
1023 } else if (partName == NULL) {
1024 tst = ADMCFGPARTITIONNAMENULL;
1025 } else if (!vpt_PartitionNameValid(partName)) {
1026 tst = ADMCFGPARTITIONNAMEBAD;
1027 } else if (devName == NULL) {
1028 tst = ADMCFGDEVICENAMENULL;
1029 } else if (!vpt_DeviceNameValid(devName)) {
1030 tst = ADMCFGDEVICENAMEBAD;
1033 /* remote configuration not yet supported in this function */
1036 if (!cfg_host->is_local) {
1037 tst = ADMCFGNOTSUPPORTED;
1041 /* add entry to table */
1044 struct vptab vpentry;
1046 strcpy(vpentry.vp_name, partName);
1047 strcpy(vpentry.vp_dev, devName);
1049 if (vpt_AddEntry(&vpentry)) {
1050 if (errno == EACCES) {
1052 } else if (errno == EINVAL) {
1053 /* shouldn't happen since checked partition/dev names */
1054 tst = ADMCFGVPTABLEENTRYBAD;
1056 tst = ADMCFGVPTABLEWRITEFAILED;
1062 /* function not yet implemented for unix */
1064 tst = ADMCFGNOTSUPPORTED;
1066 #endif /* AFS_NT40_ENV */
1079 * cfg_HostPartitionTableRemoveEntry() -- Remove AFS partition table entry.
1082 cfg_HostPartitionTableRemoveEntry(void *hostHandle, /* host config handle */
1083 const char *partName, /* partition name */
1084 afs_status_p st) /* completion status */
1087 afs_status_t tst2, tst = 0;
1088 cfg_host_p cfg_host = (cfg_host_p)hostHandle;
1091 /* validate parameters */
1093 if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) {
1095 } else if (partName == NULL) {
1096 tst = ADMCFGPARTITIONNAMENULL;
1097 } else if (!vpt_PartitionNameValid(partName)) {
1098 tst = ADMCFGPARTITIONNAMEBAD;
1101 /* remote configuration not yet supported in this function */
1104 if (!cfg_host->is_local) {
1105 tst = ADMCFGNOTSUPPORTED;
1109 /* remove entry from table */
1112 if (vpt_RemoveEntry(partName)) {
1113 /* ENOENT implies entry does not exist; consider to be removed */
1114 if (errno != ENOENT) {
1115 if (errno == EACCES) {
1117 } else if (errno == EINVAL) {
1118 /* shouldn't happen since checked partition/dev names */
1119 tst = ADMCFGPARTITIONNAMEBAD;
1121 tst = ADMCFGVPTABLEWRITEFAILED;
1128 /* function not yet implemented for unix */
1130 tst = ADMCFGNOTSUPPORTED;
1132 #endif /* AFS_NT40_ENV */
1145 * cfg_HostPartitionNameValid() -- check partition name syntax.
1148 cfg_HostPartitionNameValid(const char *partName, /* partition name */
1149 short *isValidP, /* syntax is valid */
1150 afs_status_p st) /* completion status */
1153 afs_status_t tst = 0;
1155 /* validate parameters */
1157 if (partName == NULL) {
1158 tst = ADMCFGPARTITIONNAMENULL;
1159 } else if (isValidP == NULL) {
1160 tst = ADMCFGVALIDFLAGPNULL;
1163 /* check name syntax */
1167 *isValidP = vpt_PartitionNameValid(partName);
1170 /* function not yet implemented for Unix */
1172 tst = ADMCFGNOTSUPPORTED;
1188 * cfg_HostDeviceNameValid() -- check device name syntax.
1191 cfg_HostDeviceNameValid(const char *devName, /* device name */
1192 short *isValidP, /* syntax is valid */
1193 afs_status_p st) /* completion status */
1196 afs_status_t tst = 0;
1198 /* validate parameters */
1200 if (devName == NULL) {
1201 tst = ADMCFGDEVICENAMENULL;
1202 } else if (isValidP == NULL) {
1203 tst = ADMCFGVALIDFLAGPNULL;
1206 /* check name syntax */
1210 *isValidP = vpt_DeviceNameValid(devName);
1213 /* function not yet implemented for Unix */
1215 tst = ADMCFGNOTSUPPORTED;
1230 /* ---------------- Exported Utility functions ------------------ */
1234 * cfg_StringDeallocate() -- Deallocate (multi)string returned by library.
1237 cfg_StringDeallocate(char *stringDataP, /* (multi)string to deallocate */
1238 afs_status_p st) /* completion status */
1240 free((void *)stringDataP);
1249 * cfg_PartitionListDeallocate() -- Deallocate partition table enumeration
1250 * returned by library.
1253 cfg_PartitionListDeallocate(cfg_partitionEntry_t *partitionListDataP,
1256 free((void *)partitionListDataP);
1266 /* ---------------- Local functions ------------------ */
1270 * KasKeyIsZero() -- determine if kas key is zero
1272 * RETURN CODES: 1 if zero, 0 otherwise
1275 KasKeyIsZero(kas_encryptionKey_t *kasKey)
1277 char *keyp = (char *)kasKey;
1280 for (i = 0; i < sizeof(*kasKey); i++) {
1290 * KasKeyEmbeddedInString() -- determine if kas key is embedded in string
1291 * and return key if extant.
1293 * RETURN CODES: 1 if embedded key found, 0 otherwise
1296 KasKeyEmbeddedInString(const char *keyString, kas_encryptionKey_t *kasKey)
1298 char *octalDigits = "01234567";
1300 /* keyString format is exactly 24 octal digits if embeds kas key */
1301 if (strlen(keyString) == 24 &&
1302 strspn(keyString, octalDigits) == 24) {
1303 /* kas key is embedded in keyString; extract it */
1306 for (i = 0; i < 24; i += 3) {
1308 unsigned char keyPieceVal;
1310 keyPiece[0] = keyString[i];
1311 keyPiece[1] = keyString[i + 1];
1312 keyPiece[2] = keyString[i + 2];
1315 keyPieceVal = (unsigned char)strtoul(keyPiece, NULL, 8);
1317 *((unsigned char *)kasKey + (i / 3)) = keyPieceVal;
1321 /* key NOT embedded in keyString */