Windows: Fix port assignment to use network byte order
authorJeffrey Altman <jaltman@secure-endpoints.com>
Sun, 15 Nov 2009 06:01:23 +0000 (01:01 -0500)
committerJeffrey Altman <jaltman|account-1000011@unknown>
Sun, 15 Nov 2009 06:04:14 +0000 (22:04 -0800)
Service port numbers are stored within sockaddr* structures
and returned by afsconf_FindService() in network byte order.
getAFSServer() and afsconf_GetAfsdbInfo() accept and return
service port numbers in network byte order.

When processing the special case for 7002 and 7003 in
afsconf_GetAfsdbInfo(), the comparisons must consistently
use network byte order.

When assigning port numbers for AFSDB lookups, getAFSServer()
must use network byte order.

Document the use of network byte order for each variable.

LICENSE MIT

Change-Id: I2163826e8a234a1d19474b2eba3d36335ba12afb
Reviewed-on: http://gerrit.openafs.org/830
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/cm_config.c
src/WINNT/afsd/cm_dns.c
src/auth/cellconfig.c

index b4f8ce5..3cc5b13 100644 (file)
@@ -698,7 +698,7 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
     int  cellHostAddrs[AFSMAXCELLHOSTS];
     char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
     unsigned short ipRanks[AFSMAXCELLHOSTS];
-    unsigned short ports[AFSMAXCELLHOSTS];
+    unsigned short ports[AFSMAXCELLHOSTS];      /* network byte order */
     int numServers;
     int i;
     struct sockaddr_in vlSockAddr;
@@ -717,13 +717,13 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
          strncasecmp(cellNamep, CM_IOCTL_FILENAME_NOSLASH, strlen(CM_IOCTL_FILENAME_NOSLASH)) == 0)
        return -1;
 
-    rc = getAFSServer("afs3-vlserver", "udp", cellNamep, 7003,
+    rc = getAFSServer("afs3-vlserver", "udp", cellNamep, htons(7003),
                       cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, ttl);
     if (rc == 0 && numServers > 0) {     /* found the cell */
         for (i = 0; i < numServers; i++) {
             memcpy(&vlSockAddr.sin_addr.s_addr, &cellHostAddrs[i],
                    sizeof(long));
-            vlSockAddr.sin_port = htons(ports[i]);
+            vlSockAddr.sin_port = ports[i];
             vlSockAddr.sin_family = AF_INET;
             if (procp)
                 (*procp)(rockp, &vlSockAddr, cellHostNames[i], ipRanks[i]);
index a42cad5..d8bce28 100644 (file)
@@ -624,9 +624,10 @@ int DNSgetAddr(SOCKET commSock, char *hostName, struct in_addr *iNet)
 #endif /* DNSAPI_ENV */
 
 int getAFSServer(const char *service, const char *protocol, const char *cellName,
-                 unsigned short afsdbPort,
+                 unsigned short afsdbPort,  /* network byte order */
                  int *cellHostAddrs, char cellHostNames[][MAXHOSTCHARS],
-                 unsigned short ports[], unsigned short ipRanks[],
+                 unsigned short ports[],    /* network byte order */
+                 unsigned short ipRanks[],
                  int *numServers, int *ttl)
 {
 #ifndef DNSAPI_ENV
@@ -722,7 +723,7 @@ int getAFSServer(const char *service, const char *protocol, const char *cellName
                 StringCbCopyA(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
                               pDnsIter->Data.SRV.pNameTarget);
                 ipRanks[*numServers] = pDnsIter->Data.SRV.wPriority;
-                ports[*numServers] = pDnsIter->Data.SRV.wPort;
+                ports[*numServers] = htons(pDnsIter->Data.SRV.wPort);
                 (*numServers)++;
 
                 if (!*ttl) 
@@ -790,7 +791,7 @@ int getAFSServer(const char *service, const char *protocol, const char *cellName
                     StringCbCopyA(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
                                    pDnsIter->Data.Afsdb.pNameExchange);
                     ipRanks[*numServers] = 0;
-                    ports[*numServers] = htons(afsdbPort);
+                    ports[*numServers] = afsdbPort;
                     (*numServers)++;
 
                     if (!*ttl) 
@@ -853,10 +854,10 @@ int getAFSServer(const char *service, const char *protocol, const char *cellName
 }
 
 int getAFSServerW(const cm_unichar_t *service, const cm_unichar_t *protocol, const cm_unichar_t *cellName,
-                  unsigned short afsdbPort,
+                  unsigned short afsdbPort, /* network byte order */
                   int *cellHostAddrs,
                   cm_unichar_t cellHostNames[][MAXHOSTCHARS], 
-                  unsigned short ports[],
+                  unsigned short ports[],   /* network byte order */
                   unsigned short ipRanks[],
                   int *numServers, int *ttl)
 {
@@ -891,7 +892,7 @@ int getAFSServerW(const cm_unichar_t *service, const cm_unichar_t *protocol, con
                 StringCbCopyW(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
                               pDnsIter->Data.SRV.pNameTarget);
                 ipRanks[*numServers] = pDnsIter->Data.SRV.wPriority;
-                ports[*numServers] = pDnsIter->Data.SRV.wPort;
+                ports[*numServers] = htons(pDnsIter->Data.SRV.wPort);
                 (*numServers)++;
                 
                 if (!*ttl) 
@@ -961,7 +962,7 @@ int getAFSServerW(const cm_unichar_t *service, const cm_unichar_t *protocol, con
                     StringCbCopyW(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
                                   pDnsIter->Data.Afsdb.pNameExchange);
                     ipRanks[*numServers] = 0;
-                    ports[*numServers] = htons(afsdbPort);
+                    ports[*numServers] = afsdbPort;
                     (*numServers)++;
                 
                     if (!*ttl) 
index bfd78e9..cdb6107 100644 (file)
@@ -1239,13 +1239,13 @@ afsconf_GetAfsdbInfo(char *acellName, char *aservice,
                     struct afsconf_cell *acellInfo)
 {
     afs_int32 i;
-    int tservice = afsconf_FindService(aservice);
+    int tservice = afsconf_FindService(aservice);   /* network byte order */
     const char *ianaName = afsconf_FindIANAName(aservice);
     struct afsconf_entry DNSce;
     afs_int32 cellHostAddrs[AFSMAXCELLHOSTS];
     char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
     unsigned short ipRanks[AFSMAXCELLHOSTS];
-    unsigned short ports[AFSMAXCELLHOSTS];
+    unsigned short ports[AFSMAXCELLHOSTS];          /* network byte order */
     int numServers;
     int rc;
     int ttl;
@@ -1273,7 +1273,7 @@ afsconf_GetAfsdbInfo(char *acellName, char *aservice,
      * and that service happens to be the prservice or kaservice
      * then fallback to searching for afs3-vlserver and assigning
      * the port number here. */
-    if (rc < 0 && tservice == 7002 || tservice == 7004) {
+    if (rc < 0 && tservice == htons(7002) || tservice == htons(7004)) {
         rc = getAFSServer("afs3-vlserver", "udp", acellName, tservice,
                            cellHostAddrs, cellHostNames, ports, ipRanks, &numServers,
                            &ttl);