auth: retire writeconfig.c 75/14075/5
authorMichael Meffie <mmeffie@sinenomine.net>
Thu, 20 Feb 2020 20:58:27 +0000 (15:58 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 6 Mar 2020 02:33:27 +0000 (21:33 -0500)
Move the afsconf_SetCellInfo() and afsconf_SetExtendedCellInfo() to the
cellconfig.c file with the other afsconf_dir functions.

Retire the now empty writeconfig.c file.  At one point in the distant
past afsconf_SetCellInfo() did not have a afsconf_dir argument, so it
probably made sense to have a separate file to write the configuration.
Later, the afsconf_dir argument was added to afsconf_SetCellInfo() and
afsconf_SetExtendedInfo() to reset the auth cache, so these functions
are now better placed in cellconfig.c.

Note the contents of writeconfig.c were moved verbatim (including
comments), so this commit should have no functional changes.

Change-Id: Idff76f0d2dfa2383a8617373f0e38235a94f20f1
Reviewed-on: https://gerrit.openafs.org/14075
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/auth/Makefile.in
src/auth/NTMakefile
src/auth/cellconfig.c
src/auth/cellconfig.p.h
src/auth/writeconfig.c [deleted file]
src/libafsauthent/NTMakefile

index eacf426..1d12db3 100644 (file)
@@ -10,7 +10,7 @@ include @TOP_OBJDIR@/src/config/Makefile.config
 include @TOP_OBJDIR@/src/config/Makefile.lwp
 include @TOP_OBJDIR@/src/config/Makefile.lwptool
 
-BASE_objs= cellconfig.lo keys.lo userok.lo writeconfig.lo authcon.lo \
+BASE_objs= cellconfig.lo keys.lo userok.lo authcon.lo \
         acfg_errors.lo ktc_errors.lo netrestrict.lo token.xdr.lo token.lo \
         realms.lo
 
@@ -77,7 +77,6 @@ ${TOP_LIBDIR}/libauth.krb.a: libauth.krb.a
 cellconfig.lo: cellconfig.c ${INCLS}
 keys.lo: keys.c ${INCLS}
 ktc.lo: ktc.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
-writeconfig.lo: writeconfig.c ${INCLS}
 authcon.lo: authcon.c ${INCLS}
 userok.lo: userok.c ${INCLS}
 cellconfig.lo: cellconfig.c ${INCLS}
@@ -129,7 +128,6 @@ netrestrict.lo: cellconfig.h
 realms.lo: cellconfig.h
 setkey.o: cellconfig.h
 userok.lo: cellconfig.h
-writeconfig.lo: cellconfig.h
 
 ktc_errors.c: ktc_errors.et
        ${COMPILE_ET_C} -p ${srcdir} ktc_errors
index 1c306b8..c680d31 100644 (file)
@@ -39,7 +39,6 @@ AFSAUTH_LIBOBJS =\
        $(OUT)\cellconfig.obj \
        $(OUT)\keys.obj \
        $(OUT)\userok.obj \
-       $(OUT)\writeconfig.obj \
        $(OUT)\authcon.obj \
        $(OUT)\realms.obj \
        $(OUT)\acfg_errors.obj \
@@ -67,7 +66,6 @@ AFSAUTH_KRB_LIBFILE = $(DESTDIR)\lib\afs\afsauth.krb.lib
 AFSAUTH_KRB_LIBOBJS =\
        $(OUT)\cellconfig.obj \
        $(OUT)\userok.obj \
-       $(OUT)\writeconfig.obj \
        $(OUT)\authcon.obj \
        $(OUT)\realms.obj \
        $(OUT)\acfg_errors.obj \
index b2fe227..bc81423 100644 (file)
@@ -1684,3 +1684,163 @@ afsconf_Reopen(struct afsconf_dir *adir)
     code = LoadConfig(adir);
     return code;
 }
+
+/* write ThisCell and CellServDB containing exactly one cell's info specified
+    by acellInfo parm.   Useful only on the server (which describes only one cell).
+*/
+
+static int
+VerifyEntries(struct afsconf_cell *aci)
+{
+    int i;
+    struct hostent *th;
+
+    for (i = 0; i < aci->numServers; i++) {
+       if (aci->hostAddr[i].sin_addr.s_addr == 0) {
+           /* no address spec'd */
+           if (*(aci->hostName[i]) != 0) {
+               int code;
+               struct addrinfo hints;
+               struct addrinfo *result;
+               struct addrinfo *rp;
+
+               memset(&hints, 0, sizeof(struct addrinfo));
+               hints.ai_family = AF_INET;
+               hints.ai_socktype = SOCK_DGRAM;
+
+               code = getaddrinfo(aci->hostName[i], NULL, &hints, &result);
+               if (code) {
+                   printf("Host %s not found in host database...\n",
+                          aci->hostName[i]);
+                   return AFSCONF_FAILURE;
+               }
+               for (rp = result; rp != NULL; rp = rp->ai_next) {
+                   struct sockaddr_in *sa = (struct sockaddr_in *)rp->ai_addr;
+                   if (!rx_IsLoopbackAddr(ntohl(sa->sin_addr.s_addr))) {
+                       aci->hostAddr[i].sin_addr.s_addr = sa->sin_addr.s_addr;
+                       break;
+                   }
+               }
+               freeaddrinfo(result);
+               if (aci->hostAddr[i].sin_addr.s_addr == 0) {
+                   printf("No non-loopback addresses found for host %s\n",
+                          aci->hostName[i]);
+                   return AFSCONF_FAILURE;
+               }
+           }
+           /* otherwise we're deleting this entry */
+       } else {
+           /* address spec'd, perhaps no name known */
+           if (aci->hostName[i][0] != 0)
+               continue;       /* name known too */
+           /* figure out name, if possible */
+           th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
+                              AF_INET);
+           if (!th) {
+               strcpy(aci->hostName[i], "UNKNOWNHOST");
+           } else {
+               if (strlcpy(aci->hostName[i],
+                           th->h_name,
+                           sizeof(aci->hostName[i]))
+                       >= sizeof(aci->hostName[i])) {
+                  strcpy(aci->hostName[i], "UNKNOWNHOST");
+               }
+           }
+       }
+    }
+    return 0;
+}
+
+/* Changed the interface to accept the afsconf_dir datastructure.
+   This is a handle to the internal cache that is maintained by the bosserver.
+   */
+
+int
+afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
+                   struct afsconf_cell *acellInfo)
+{
+    afs_int32 code;
+
+    code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
+    return code;
+}
+
+int
+afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
+                           const char *apath,
+                           struct afsconf_cell *acellInfo, char clones[])
+{
+    afs_int32 code;
+    int fd;
+    char tbuffer[1024];
+    FILE *tf;
+    afs_int32 i;
+
+    LOCK_GLOBAL_MUTEX;
+    /* write ThisCell file */
+    strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, (char *)NULL);
+
+    fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
+    if (fd < 0) {
+       UNLOCK_GLOBAL_MUTEX;
+       return errno;
+    }
+    i = (int)strlen(acellInfo->name);
+    code = write(fd, acellInfo->name, i);
+    if (code != i) {
+       UNLOCK_GLOBAL_MUTEX;
+       return AFSCONF_FAILURE;
+    }
+    if (close(fd) < 0) {
+       UNLOCK_GLOBAL_MUTEX;
+       return errno;
+    }
+
+    /* make sure we have both name and address for each host, looking up other
+     * if need be */
+    code = VerifyEntries(acellInfo);
+    if (code) {
+       UNLOCK_GLOBAL_MUTEX;
+       return code;
+    }
+
+    /* write CellServDB */
+    tf = fopen(adir->cellservDB, "w");
+    if (!tf) {
+       UNLOCK_GLOBAL_MUTEX;
+       return AFSCONF_NOTFOUND;
+    }
+    fprintf(tf, ">%s   #Cell name\n", acellInfo->name);
+    for (i = 0; i < acellInfo->numServers; i++) {
+       code = acellInfo->hostAddr[i].sin_addr.s_addr;  /* net order */
+       if (code == 0)
+           continue;           /* delete request */
+       code = ntohl(code);     /* convert to host order */
+       if (clones && clones[i])
+           fprintf(tf, "[%d.%d.%d.%d]  #%s\n", (code >> 24) & 0xff,
+                   (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
+                   acellInfo->hostName[i]);
+       else
+           fprintf(tf, "%d.%d.%d.%d    #%s\n", (code >> 24) & 0xff,
+                   (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
+                   acellInfo->hostName[i]);
+    }
+    if (ferror(tf)) {
+       fclose(tf);
+       UNLOCK_GLOBAL_MUTEX;
+       return AFSCONF_FAILURE;
+    }
+    code = fclose(tf);
+
+    /* Reset the timestamp in the cache, so that
+     * the CellServDB is read into the cache next time.
+     * Resolves the lost update problem due to an inconsistent cache
+     */
+    if (adir)
+       adir->timeRead = 0;
+
+    UNLOCK_GLOBAL_MUTEX;
+    if (code == EOF)
+       return AFSCONF_FAILURE;
+    return 0;
+}
index c3811fd..2212f39 100644 (file)
@@ -134,6 +134,10 @@ extern int afsconf_GetLocalCell(struct afsconf_dir *adir,
                                char *aname, afs_int32 alen);
 extern int afsconf_Close(struct afsconf_dir *adir);
 extern int afsconf_UpToDate(void *rock);
+int afsconf_SetExtendedCellInfo(struct afsconf_dir *adir, const char *apath,
+                               struct afsconf_cell *acellInfo, char clones[]);
+int afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
+                       struct afsconf_cell *acellInfo);
 
 struct afsconf_keys;
 extern int afsconf_GetKeys(struct afsconf_dir *adir,
@@ -249,11 +253,6 @@ extern void afsconf_BuildServerSecurityObjects(void *,
                                               struct rx_securityClass ***,
                                               afs_int32 *);
 
-/* writeconfig.c */
-int afsconf_SetExtendedCellInfo(struct afsconf_dir *adir, const char *apath,
-                               struct afsconf_cell *acellInfo, char clones[]);
-int afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
-                       struct afsconf_cell *acellInfo);
 
 
 /* userok.c */
diff --git a/src/auth/writeconfig.c b/src/auth/writeconfig.c
deleted file mode 100644 (file)
index c538433..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright 2000, International Business Machines Corporation and others.
- * All Rights Reserved.
- *
- * This software has been released under the terms of the IBM Public
- * License.  For details, see the LICENSE file in the top-level source
- * directory or online at http://www.openafs.org/dl/license10.html
- */
-
-#include <afsconfig.h>
-#include <afs/param.h>
-
-#include <roken.h>
-#include <afs/opr.h>
-
-#include <afs/pthread_glock.h>
-#include <afs/afsutil.h>
-#include <rx/rxkad.h>
-
-#include "cellconfig.h"
-#include "keys.h"
-
-/* write ThisCell and CellServDB containing exactly one cell's info specified
-    by acellInfo parm.   Useful only on the server (which describes only one cell).
-*/
-
-static int
-VerifyEntries(struct afsconf_cell *aci)
-{
-    int i;
-    struct hostent *th;
-
-    for (i = 0; i < aci->numServers; i++) {
-       if (aci->hostAddr[i].sin_addr.s_addr == 0) {
-           /* no address spec'd */
-           if (*(aci->hostName[i]) != 0) {
-               int code;
-               struct addrinfo hints;
-               struct addrinfo *result;
-               struct addrinfo *rp;
-
-               memset(&hints, 0, sizeof(struct addrinfo));
-               hints.ai_family = AF_INET;
-               hints.ai_socktype = SOCK_DGRAM;
-
-               code = getaddrinfo(aci->hostName[i], NULL, &hints, &result);
-               if (code) {
-                   printf("Host %s not found in host database...\n",
-                          aci->hostName[i]);
-                   return AFSCONF_FAILURE;
-               }
-               for (rp = result; rp != NULL; rp = rp->ai_next) {
-                   struct sockaddr_in *sa = (struct sockaddr_in *)rp->ai_addr;
-                   if (!rx_IsLoopbackAddr(ntohl(sa->sin_addr.s_addr))) {
-                       aci->hostAddr[i].sin_addr.s_addr = sa->sin_addr.s_addr;
-                       break;
-                   }
-               }
-               freeaddrinfo(result);
-               if (aci->hostAddr[i].sin_addr.s_addr == 0) {
-                   printf("No non-loopback addresses found for host %s\n",
-                          aci->hostName[i]);
-                   return AFSCONF_FAILURE;
-               }
-           }
-           /* otherwise we're deleting this entry */
-       } else {
-           /* address spec'd, perhaps no name known */
-           if (aci->hostName[i][0] != 0)
-               continue;       /* name known too */
-           /* figure out name, if possible */
-           th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
-                              AF_INET);
-           if (!th) {
-               strcpy(aci->hostName[i], "UNKNOWNHOST");
-           } else {
-               if (strlcpy(aci->hostName[i],
-                           th->h_name,
-                           sizeof(aci->hostName[i]))
-                       >= sizeof(aci->hostName[i])) {
-                  strcpy(aci->hostName[i], "UNKNOWNHOST");
-               }
-           }
-       }
-    }
-    return 0;
-}
-
-/* Changed the interface to accept the afsconf_dir datastructure.
-   This is a handle to the internal cache that is maintained by the bosserver.
-   */
-
-int
-afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
-                   struct afsconf_cell *acellInfo)
-{
-    afs_int32 code;
-
-    code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
-    return code;
-}
-
-int
-afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
-                           const char *apath,
-                           struct afsconf_cell *acellInfo, char clones[])
-{
-    afs_int32 code;
-    int fd;
-    char tbuffer[1024];
-    FILE *tf;
-    afs_int32 i;
-
-    LOCK_GLOBAL_MUTEX;
-    /* write ThisCell file */
-    strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, (char *)NULL);
-
-    fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
-    if (fd < 0) {
-       UNLOCK_GLOBAL_MUTEX;
-       return errno;
-    }
-    i = (int)strlen(acellInfo->name);
-    code = write(fd, acellInfo->name, i);
-    if (code != i) {
-       UNLOCK_GLOBAL_MUTEX;
-       return AFSCONF_FAILURE;
-    }
-    if (close(fd) < 0) {
-       UNLOCK_GLOBAL_MUTEX;
-       return errno;
-    }
-
-    /* make sure we have both name and address for each host, looking up other
-     * if need be */
-    code = VerifyEntries(acellInfo);
-    if (code) {
-       UNLOCK_GLOBAL_MUTEX;
-       return code;
-    }
-
-    /* write CellServDB */
-    tf = fopen(adir->cellservDB, "w");
-    if (!tf) {
-       UNLOCK_GLOBAL_MUTEX;
-       return AFSCONF_NOTFOUND;
-    }
-    fprintf(tf, ">%s   #Cell name\n", acellInfo->name);
-    for (i = 0; i < acellInfo->numServers; i++) {
-       code = acellInfo->hostAddr[i].sin_addr.s_addr;  /* net order */
-       if (code == 0)
-           continue;           /* delete request */
-       code = ntohl(code);     /* convert to host order */
-       if (clones && clones[i])
-           fprintf(tf, "[%d.%d.%d.%d]  #%s\n", (code >> 24) & 0xff,
-                   (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
-                   acellInfo->hostName[i]);
-       else
-           fprintf(tf, "%d.%d.%d.%d    #%s\n", (code >> 24) & 0xff,
-                   (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
-                   acellInfo->hostName[i]);
-    }
-    if (ferror(tf)) {
-       fclose(tf);
-       UNLOCK_GLOBAL_MUTEX;
-       return AFSCONF_FAILURE;
-    }
-    code = fclose(tf);
-
-    /* Reset the timestamp in the cache, so that
-     * the CellServDB is read into the cache next time.
-     * Resolves the lost update problem due to an inconsistent cache
-     */
-    if (adir)
-       adir->timeRead = 0;
-
-    UNLOCK_GLOBAL_MUTEX;
-    if (code == EOF)
-       return AFSCONF_FAILURE;
-    return 0;
-}
index d927d3a..171a04a 100644 (file)
@@ -35,7 +35,6 @@ AUDITOBJS = \
 AUTHOBJS = \
        $(OUT)\cellconfig.obj \
        $(OUT)\userok.obj \
-       $(OUT)\writeconfig.obj \
        $(OUT)\authcon.obj \
        $(OUT)\realms.obj \
        $(OUT)\ktc_errors.obj \