update: convert upserver and client from LWP to pthreads
[openafs.git] / src / update / client.c
index bdcfd52..5bc0ec0 100644 (file)
@@ -177,10 +177,18 @@ main(int argc, char **argv)
                    ("Usage: upclient <hostname> [-crypt] [-clear] [-t <retry time>] [-verbose]* <dir>+ [-help]\n");
                exit(1);
            }
-       } else if (strlen(hostname) == 0)
-           strcpy(hostname, argv[a]);
-       else {
-           strcpy(filename, argv[a]);
+       } else if (strlen(hostname) == 0) {
+           if (strlcpy(hostname, argv[a], sizeof(hostname))
+                   >= sizeof(hostname)) {
+               fprintf(stderr, "Supplied hostname is too long\n");
+               exit(1);
+           }
+       } else {
+           if (strlcpy(filename, argv[a], sizeof(filename))
+                   >= sizeof(filename)) {
+               fprintf(stderr, "Supplied filename is too long\n");
+               exit(1);
+           }
            FilepathNormalize(filename);
            AddToList(&dirname, filename);
        }
@@ -367,14 +375,14 @@ main(int argc, char **argv)
            free(curDir);
        }                       /* end for each dir loop */
        /*delete the file with info on files in directory df->name */
-       IOMGR_Sleep(interval);
+       sleep(interval);
        continue;
 
       fail_dirbuf:
        fclose(stream);
        unlink(dirbuf);
       fail:
-       IOMGR_Sleep(retrytime);
+       sleep(retrytime);
        if (cnt > 10) {
            rx_DestroyConnection(conn);
            goto again;
@@ -499,28 +507,45 @@ update_ReceiveFile(int fd, struct rx_call *call, struct stat *status)
 
 /*
  * PathsAreEquivalent() -- determine if paths are equivalent
+ * Returns 1 if yes, 0 if no, -1 on error.
  */
 static int
 PathsAreEquivalent(char *path1, char *path2)
 {
-    int areEq = 0;
-    char pathNorm1[AFSDIR_PATH_MAX], pathNorm2[AFSDIR_PATH_MAX];
+    int areEq = 0, code;
+    char *pathNorm1, *pathNorm2;
 
 #ifdef AFS_NT40_ENV
     /* case-insensitive comparison of normalized, same-flavor (short) paths */
     DWORD status;
 
+    pathNorm1 = malloc(AFSDIR_PATH_MAX);
+    if (pathNorm1 == NULL)
+       return -1;
     status = GetShortPathName(path1, pathNorm1, AFSDIR_PATH_MAX);
     if (status == 0 || status > AFSDIR_PATH_MAX) {
        /* can't convert path to short version; just use long version */
-       strcpy(pathNorm1, path1);
+       free(pathNorm1);
+       pathNorm1 = strdup(path1);
+       if (pathNorm1 == NULL)
+           return -1;
     }
     FilepathNormalize(pathNorm1);
 
+    pathNorm2 = malloc(AFSDIR_PATH_MAX);
+    if (pathNorm2 == NULL) {
+       code = -1;
+       goto out;
+    }
     status = GetShortPathName(path2, pathNorm2, AFSDIR_PATH_MAX);
     if (status == 0 || status > AFSDIR_PATH_MAX) {
        /* can't convert path to short version; just use long version */
-       strcpy(pathNorm2, path2);
+       free(pathNorm2);
+       pathNorm2 = strdup(path2);
+       if (pathNorm2 == NULL) {
+           code = -1;
+           goto out;
+       }
     }
     FilepathNormalize(pathNorm2);
 
@@ -529,17 +554,27 @@ PathsAreEquivalent(char *path1, char *path2)
     }
 #else
     /* case-sensitive comparison of normalized paths */
-    strcpy(pathNorm1, path1);
+    pathNorm1 = strdup(path1);
+    if (pathNorm1 == NULL)
+       return -1;
     FilepathNormalize(pathNorm1);
 
-    strcpy(pathNorm2, path2);
+    pathNorm2 = strdup(path2);
+    if (pathNorm2 == NULL) {
+       code = -1;
+       goto out;
+    }
     FilepathNormalize(pathNorm2);
 
     if (strcmp(pathNorm1, pathNorm2) == 0) {
        areEq = 1;
     }
 #endif /* AFS_NT40_ENV */
-    return areEq;
+    code = 0;
+out:
+    free(pathNorm1);
+    free(pathNorm2);
+    return (code != 0) ? code : areEq;
 }
 
 
@@ -569,11 +604,12 @@ NotOnHost(char *filename, struct filestr *okhostfiles)
            afs_com_err(whoami, rc, "Unable to construct local path");
            return -1;
        }
-       if (PathsAreEquivalent(hostfile, filename)) {
-           free(hostfile);
-           return 0;
-       }
+       rc = PathsAreEquivalent(hostfile, filename);
        free(hostfile);
+       if (rc < 0)
+           return -1;
+       if (rc)
+           return 0;
     }
     return 1;
 }