]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE12-afsdb-avoid-dns-case-issues-for-cell-aliases-20020120
authorNickolai Zeldovich <kolya@mit.edu>
Sun, 20 Jan 2002 08:33:04 +0000 (08:33 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 20 Jan 2002 08:33:04 +0000 (08:33 +0000)
This patch makes sure that in-kernel aliases to non-existant names aren't
  accidentally created due to case mismatch (e.g. "athena" being created as
  a symlink to "athena.MIT.EDU", while "athena.mit.edu" is the real cell
  that already exists).  It also lowercases cell names in AFSDB lookups,
  otherwise the same problem appears in userspace (eg "aklog athena" tries
  to obtain tokens for cell "athena.MIT.EDU").

src/afs/afs_cell.c
src/auth/cellconfig.c

index 12df1b96377f6fb33d31e48086735db1a6182918..ca69560d9a4e65dc9d0630a7cd925cd5fbf698ed 100644 (file)
@@ -220,17 +220,18 @@ int afs_GetCellHostsFromDns(acellName, acellHosts, timeout, realName)
 }
 
 
-void afs_RefreshCell(tc)
-    register struct cell *tc;
+void afs_RefreshCell(ac)
+    register struct cell *ac;
 {
     afs_int32 cellHosts[MAXCELLHOSTS];
     char *realName = NULL;
+    struct cell *tc;
     int timeout;
 
     /* Don't need to do anything if no timeout or it's not expired */
-    if (!tc->timeout || tc->timeout > osi_Time()) return;
+    if (!ac->timeout || ac->timeout > osi_Time()) return;
 
-    if (afs_GetCellHostsFromDns(tc->cellName, cellHosts, &timeout, &realName))
+    if (afs_GetCellHostsFromDns(ac->cellName, cellHosts, &timeout, &realName))
        /* In case of lookup failure, keep old data */
        goto done;
 
@@ -238,9 +239,19 @@ void afs_RefreshCell(tc)
     afs_NewCell(realName, cellHosts, 0, (char *) 0, 0, 0, timeout, (char *) 0);
 
     /* If this is an alias, update the alias entry too */
-    if (afs_strcasecmp(tc->cellName, realName))
-       afs_NewCell(tc->cellName, 0, CAlias, (char *) 0, 0, 0,
-                   timeout, realName);
+    if (afs_strcasecmp(ac->cellName, realName)) {
+       /*
+        * Look up the entry we just updated, to compensate for
+        * uppercase-vs-lowercase lossage with DNS.
+        */
+       tc = afs_GetCellByName2(realName, READ_LOCK, 0 /* no AFSDB */);
+
+       if (tc) {
+           afs_NewCell(ac->cellName, 0, CAlias, (char *) 0, 0, 0,
+                       timeout, tc->cellName);
+           afs_PutCell(tc, READ_LOCK);
+       }
+    }
 
 done:
     if (realName)
@@ -254,6 +265,7 @@ struct cell *afs_GetCellByName_Dns(acellName, locktype)
 {
     afs_int32 cellHosts[MAXCELLHOSTS];
     char *realName = NULL;
+    struct cell *tc;
     int timeout;
 
     if (afs_GetCellHostsFromDns(acellName, cellHosts, &timeout, &realName))
@@ -264,9 +276,21 @@ struct cell *afs_GetCellByName_Dns(acellName, locktype)
 
     /* If this is an alias, create an entry for it too */
     if (afs_strcasecmp(acellName, realName)) {
+       /*
+        * Look up the entry we just updated, to compensate for
+        * uppercase-vs-lowercase lossage with DNS.
+        */
+       tc = afs_GetCellByName2(realName, READ_LOCK, 0 /* no AFSDB */);
+       if (!tc)
+           goto bad;
+
        if (afs_NewCell(acellName, 0, CAlias, (char *) 0, 0, 0,
-                       timeout, realName))
+                       timeout, tc->cellName)) {
+           afs_PutCell(tc, READ_LOCK);
            goto bad;
+       }
+
+       afs_PutCell(tc, READ_LOCK);
     }
 
     if (realName)
index 8e299f4d0ab990e901f2d1584a9322e2dd028d67..f0d2d0a038a7c77524aafa7877023871410bf6de 100644 (file)
@@ -718,6 +718,11 @@ afsconf_GetAfsdbInfo(acellName, aservice, acellInfo)
 
     if (server_num == 0)               /* No AFSDB records */
        return AFSCONF_NOTFOUND;
+
+    /* Convert the real cell name to lowercase */
+    for (p = (unsigned char *) realCellName; *p; p++)
+       *p = tolower(*p);
+
     strncpy(acellInfo->name, realCellName, sizeof(acellInfo->name));
     acellInfo->numServers = server_num;