auth: accept a NULL afsconf_dir in afsconf_SetCellInfo again 61/14061/9
authorMichael Meffie <mmeffie@sinenomine.net>
Fri, 21 Feb 2020 15:08:42 +0000 (10:08 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 6 Mar 2020 02:34:55 +0000 (21:34 -0500)
Commit 93b26c6f55245e2187e574eb928f5e0ce66a245e added the cellservDB
field to the afsconf_dir structure to track the CellServDB pathname.
This commit also changed the afsconf_SetCellInfo() and
afsconf_SetExtendedCellInfo() functions to use the new cellservDB member
to open the CellServDB file.

Unfortunately, the bosserver intentionally calls afsconf_SetCellInfo()
with a NULL afsconf_dir pointer when attempting to create the default
CellServDB and ThisCell files (e.g., "localcell"), which causes the
bosserver to crash on startup when the cell configuration is not present.

Fix this by calling the static function to lookup the CellServDB
pathname when a afsconf_dir data object is not given.

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

src/auth/cellconfig.c

index ef69dec..d570afd 100644 (file)
@@ -1685,10 +1685,6 @@ afsconf_Reopen(struct afsconf_dir *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)
 {
@@ -1751,10 +1747,23 @@ VerifyEntries(struct afsconf_cell *aci)
     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.
-   */
-
+/**
+ * Set cell information (deprecated)
+ *
+ * Write ThisCell and CellServDB containing exactly one cell's info specified
+ * by acellInfo param.  Useful only on the server (which describes only one
+ * cell).
+ *
+ * @param adir       cell configuation data; may be NULL
+ * @param apath      cell configuration path
+ * @param acellInfo  cell information
+ *
+ * @note This interface was changed at some point to optionally accept the
+ *       afsconf_dir data structure.  This is a handle to the internal cache
+ *       that is maintained by the bosserver.
+ *
+ * @return 0 on success
+ */
 int
 afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
                    struct afsconf_cell *acellInfo)
@@ -1765,6 +1774,20 @@ afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
     return code;
 }
 
+/**
+ * Set cell information
+ *
+ * Write ThisCell and CellServDB containing exactly one cell's info specified
+ * by acellInfo param.  Useful only on the server (which describes only one
+ * cell).
+ *
+ * @param adir       cell configuation data; may be NULL
+ * @param apath      cell configuration path
+ * @param acellInfo  cell information
+ * @param clones     array of booleans to indicate which hosts are clones
+ *
+ * @return 0 on success
+ */
 int
 afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
                            const char *apath,
@@ -1776,6 +1799,9 @@ afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
     FILE *tf;
     afs_int32 i;
 
+    opr_Assert(apath);
+    opr_Assert(acellInfo);
+
     LOCK_GLOBAL_MUTEX;
     /* write ThisCell file */
     strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, (char *)NULL);
@@ -1805,7 +1831,17 @@ afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
     }
 
     /* write CellServDB */
-    tf = fopen(adir->cellservDB, "w");
+    if (adir) {
+       tf = fopen(adir->cellservDB, "w");
+    } else {
+       char *cellservDB = NULL;
+       _afsconf_CellServDBPath(apath, &cellservDB);
+       if (cellservDB)
+           tf = fopen(cellservDB, "w");
+       else
+           tf = NULL;
+       free(cellservDB);
+    }
     if (!tf) {
        UNLOCK_GLOBAL_MUTEX;
        return AFSCONF_NOTFOUND;