windows-linked-cells-20081103
[openafs.git] / src / WINNT / afsd / fs.c
index 87896d8..0e78fb7 100644 (file)
@@ -42,7 +42,7 @@
 #define        MAXSIZE 2048
 #define MAXINSIZE 1300    /* pioctl complains if data is larger than this */
 #define VMSGSIZE 128      /* size of msg buf in volume hdr */
-#define MAXCELLCHARS           64
+#define CELL_MAXNAMELEN                256
 #define MAXHOSTCHARS           64
 
 static char space[MAXSIZE];
@@ -251,7 +251,7 @@ InAFS(char *apath)
     blob.out_size = MAXSIZE;
     blob.out = space;
 
-    code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
+    code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
     if (code) {
        if ((errno == EINVAL) || (errno == ENOENT)) 
             return 0;
@@ -269,9 +269,9 @@ IsFreelanceRoot(char *apath)
     blob.out_size = MAXSIZE;
     blob.out = space;
 
-    code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
+    code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
     if (code == 0)
-        return !stricmp("Freelance.Local.Root",space);
+        return !cm_stricmp_utf8N("Freelance.Local.Root",space);
     return 1;   /* assume it is because it is more restrictive that way */
 }
 
@@ -535,24 +535,36 @@ EmptyAcl(char *astr)
     tp->nplus = tp->nminus = 0;
     tp->pluslist = tp->minuslist = 0;
     tp->dfs = 0;
-    sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
+    if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
+        tp->dfs = 0;
+        tp->cell[0] = '\0';
+    }
     return tp;
 }
 
 static struct Acl *
 ParseAcl (char *astr)
 {
-    int nplus, nminus, i, trights;
+    int nplus, nminus, i, trights, ret;
     char tname[MAXNAME];
-    struct AclEntry *first, *last, *tl;
+    struct AclEntry *first, *next, *last, *tl;
     struct Acl *ta;
 
-    ta = (struct Acl *) malloc (sizeof (struct Acl));
-    assert(ta);
-    ta->dfs = 0;
-    sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
+    ta = EmptyAcl(NULL);
+    if (astr == NULL || strlen(astr) == 0)
+        return ta;
+
+    ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
+    if (ret <= 0) {
+        free(ta);
+        return NULL;
+    }
     astr = SkipLine(astr);
-    sscanf(astr, "%d", &ta->nminus);
+    ret = sscanf(astr, "%d", &ta->nminus);
+    if (ret <= 0) {
+        free(ta);
+        return NULL;
+    }
     astr = SkipLine(astr);
 
     nplus = ta->nplus;
@@ -561,10 +573,13 @@ ParseAcl (char *astr)
     last = 0;
     first = 0;
     for(i=0;i<nplus;i++) {
-        sscanf(astr, "%100s %d", tname, &trights);
+        ret = sscanf(astr, "%100s %d", tname, &trights); 
+        if (ret <= 0)
+            goto nplus_err;
         astr = SkipLine(astr);
         tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
-        assert(tl);
+        if (tl == NULL)
+            goto nplus_err;
         if (!first) 
             first = tl;
         strcpy(tl->name, tname);
@@ -579,10 +594,13 @@ ParseAcl (char *astr)
     last = 0;
     first = 0;
     for(i=0;i<nminus;i++) {
-        sscanf(astr, "%100s %d", tname, &trights);
+        ret = sscanf(astr, "%100s %d", tname, &trights);
+        if (ret <= 0)
+            goto nminus_err;
         astr = SkipLine(astr);
         tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
-        assert(tl);
+        if (tl == NULL)
+            goto nminus_err;
         if (!first) 
             first = tl;
         strcpy(tl->name, tname);
@@ -595,6 +613,21 @@ ParseAcl (char *astr)
     ta->minuslist = first;
 
     return ta;
+
+  nminus_err:
+    for (;first; first = next) {
+        next = first->next;
+        free(first);
+    }   
+    first = ta->pluslist;
+
+  nplus_err:
+    for (;first; first = next) {
+        next = first->next;
+        free(first);
+    }   
+    free(ta);
+    return NULL;
 }
 
 static int
@@ -702,7 +735,7 @@ static DWORD IsFreelance(void)
     DWORD enabled = 0;
 
     code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
-                         0, KEY_QUERY_VALUE, &parmKey);
+                         0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
     if (code == ERROR_SUCCESS) {
         dummyLen = sizeof(cm_freelanceEnabled);
         code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
@@ -721,7 +754,7 @@ static const char * NetbiosName(void)
     DWORD enabled = 0;
 
     code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
-                         0, KEY_QUERY_VALUE, &parmKey);
+                         0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
     if (code == ERROR_SUCCESS) {
         dummyLen = sizeof(buffer);
         code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
@@ -895,7 +928,7 @@ SetACLCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = MAXSIZE;
        blob.in_size = idf;
        blob.in = blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
            Die(errno, ti->data);
            error = 1;
@@ -904,6 +937,13 @@ SetACLCmd(struct cmd_syndesc *as, void *arock)
         if (ta)
             ZapAcl(ta);
        ta = ParseAcl(space);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        if (!plusp && ta->dfs) {
            fprintf(stderr,
                    "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
@@ -918,6 +958,13 @@ SetACLCmd(struct cmd_syndesc *as, void *arock)
             ta = EmptyAcl(space);
        else 
             ta = ParseAcl(space);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        CleanAcl(ta, ti->data);
        for(ui=as->parms[1].items; ui; ui=ui->next->next) {
            enum rtype rtype;
@@ -944,7 +991,7 @@ SetACLCmd(struct cmd_syndesc *as, void *arock)
        blob.in = AclToString(ta);
        blob.out_size=0;
        blob.in_size = 1+(long)strlen(blob.in);
-       code = pioctl(ti->data, VIOCSETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
        if (code) {
            if (errno == EINVAL) {
                if (ta->dfs) {
@@ -1021,18 +1068,24 @@ CopyACLCmd(struct cmd_syndesc *as, void *arock)
     blob.out_size = MAXSIZE;
     blob.in_size = idf;
     blob.in = blob.out = space;
-    code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
+    code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
     if (code) {
        Die(errno, as->parms[0].items->data);
        return 1;
     }
     fa = ParseAcl(space);
+    if (!fa) {
+        fprintf(stderr,
+                 "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                 as->parms[0].items->data);
+        return 1;
+    }
     CleanAcl(fa, as->parms[0].items->data);
     for (ti=as->parms[1].items; ti;ti=ti->next) {
        blob.out_size = MAXSIZE;
        blob.in_size = idf;
        blob.in = blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
            Die(errno, ti->data);
            error = 1;
@@ -1044,6 +1097,13 @@ CopyACLCmd(struct cmd_syndesc *as, void *arock)
             ta = EmptyAcl(space);
        else 
             ta = ParseAcl(space);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        CleanAcl(ta, ti->data);
        if (ta->dfs != fa->dfs) {
            fprintf(stderr, 
@@ -1069,7 +1129,7 @@ CopyACLCmd(struct cmd_syndesc *as, void *arock)
        blob.in = AclToString(ta);
        blob.out_size=0;
        blob.in_size = 1+(long)strlen(blob.in);
-       code = pioctl(ti->data, VIOCSETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
        if (code) {
            if (errno == EINVAL) {
                fprintf(stderr,
@@ -1087,7 +1147,7 @@ CopyACLCmd(struct cmd_syndesc *as, void *arock)
     return error;
 }
 
-/* pioctl() call to get the cellname of a pathname */
+/* pioctl_utf8() call to get the cellname of a pathname */
 static afs_int32
 GetCell(char *fname, char *cellname)
 {
@@ -1095,10 +1155,10 @@ GetCell(char *fname, char *cellname)
     struct ViceIoctl blob;
 
     blob.in_size = 0;
-    blob.out_size = MAXCELLCHARS;
+    blob.out_size = CELL_MAXNAMELEN;
     blob.out = cellname;
 
-    code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
+    code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
     return code;
 }
 
@@ -1111,7 +1171,7 @@ BadName(char *aname, char *fname)
 {
     afs_int32 tc, code, id;
     char *nm;
-    char cell[MAXCELLCHARS];
+    char cell[CELL_MAXNAMELEN];
     char confDir[257];
 
     for ( nm = aname; tc = *nm; nm++) {
@@ -1197,7 +1257,7 @@ CleanACLCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
            Die(errno, ti->data);
             error = 1;
@@ -1206,7 +1266,13 @@ CleanACLCmd(struct cmd_syndesc *as, void *arock)
         if (ta)
             ZapAcl(ta);
        ta = ParseAcl(space);
-
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        if (ta->dfs) {
            fprintf(stderr,
                    "%s: cleanacl is not supported for DFS access lists.\n",
@@ -1222,7 +1288,7 @@ CleanACLCmd(struct cmd_syndesc *as, void *arock)
            blob.in=AclToString(ta);
            blob.in_size = (long)strlen(blob.in)+1;
            blob.out_size = 0;
-           code = pioctl(ti->data, VIOCSETAL, &blob, 1);
+           code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
            if (code) {
                if (errno == EINVAL) {
                    fprintf(stderr,
@@ -1285,13 +1351,20 @@ ListACLCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = MAXSIZE;
        blob.in_size = idf;
        blob.in = blob.out = space;
-       code = pioctl(ti->data, VIOCGETAL, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
        if (code) {
            Die(errno, ti->data);
             error = 1;
            continue;
        }
        ta = ParseAcl(space);
+        if (!ta) {
+            fprintf(stderr,
+                    "fs: %s: invalid acl data returned from VIOCGETAL\n",
+                     ti->data);
+            error = 1;
+            continue;
+        }
        switch (ta->dfs) {
          case 0:
            printf("Access list for %s is\n", ti->data);
@@ -1341,7 +1414,7 @@ FlushAllCmd(struct cmd_syndesc *as, void *arock)
     struct ViceIoctl blob;
 
     blob.in_size = blob.out_size = 0;
-    code = pioctl(NULL, VIOC_FLUSHALL, &blob, 0);
+    code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
     if (code) {
        fprintf(stderr, "Error flushing all ");
        return 1;
@@ -1360,7 +1433,7 @@ FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
     SetDotDefault(&as->parms[0].items);
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        blob.in_size = blob.out_size = 0;
-       code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
+       code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
        if (code) {
            fprintf(stderr, "Error flushing volume ");
             perror(ti->data);
@@ -1394,7 +1467,7 @@ FlushCmd(struct cmd_syndesc *as, void *arock)
         blob.in = &options;
 
        blob.out_size = 0;
-       code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
+       code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
        if (code) {
            if (errno == EMFILE) {
                fprintf(stderr, "%s: Can't flush active file %s\n", pn, 
@@ -1476,7 +1549,7 @@ SetVolCmd(struct cmd_syndesc *as, void *arock) {
            input += strlen(motd) + 1;
        } else 
             *(input++) = '\0';
-       code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
        if (code) {
            Die(errno, ti->data);
            error = 1;
@@ -1531,7 +1604,7 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
         cm_fid_t fid;
         afs_uint32 filetype;
        afs_uint32 owner[2];
-       char cell[MAXCELLCHARS];
+       char cell[CELL_MAXNAMELEN];
 
         /* once per file */
         memset(&fid, 0, sizeof(fid));
@@ -1545,7 +1618,7 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
 
         blob.out_size = sizeof(cm_fid_t);
         blob.out = (char *) &fid;
-        if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
             options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
             options.fid = fid;
         } else {
@@ -1557,12 +1630,12 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
         blob.out_size = sizeof(filetype);
         blob.out = &filetype;
 
-        code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
 
-        blob.out_size = MAXCELLCHARS;
+        blob.out_size = CELL_MAXNAMELEN;
         blob.out = cell;
 
-        code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
+        code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
         printf("%s %s (%u.%u.%u) contained in cell %s\n",
                 filetypestr(filetype),
                 ti->data, fid.volume, fid.vnode, fid.unique,
@@ -1570,7 +1643,7 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
 
        blob.out_size = 2 * sizeof(afs_uint32);
         blob.out = (char *) &owner;
-       if (0 == pioctl(ti->data, VIOCGETOWNER, &blob, 1)) {
+       if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1)) {
            char oname[PR_MAXNAMELEN] = "(unknown)";
             char confDir[257];
 
@@ -1584,7 +1657,7 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
 
        blob.out = space;
        blob.out_size = MAXSIZE;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
        if (code == 0) {
             status = (VolumeStatus *)space;
             name = (char *)status + sizeof(*status);
@@ -1597,7 +1670,7 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
         }
 
         errno = 0;
-        code = pioctl(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
+        code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
         switch (errno) {
         case 0:
             printf("Volume is online\n");
@@ -1639,7 +1712,7 @@ ListQuotaCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
        if (code) {
            Die(errno, ti->data);
             error = 1;
@@ -1685,7 +1758,7 @@ WhereIsCmd(struct cmd_syndesc *as, void *arock)
         
         blob.out_size = sizeof(cm_fid_t);
         blob.out = (char *) &fid;
-        if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
             options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
             options.fid = fid;
         } else {
@@ -1697,12 +1770,12 @@ WhereIsCmd(struct cmd_syndesc *as, void *arock)
         blob.out_size = sizeof(filetype);
         blob.out = &filetype;
 
-        code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
 
         blob.out_size = MAXSIZE;
        blob.out = space;
        memset(space, 0, sizeof(space));
-       code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
        if (code) {
            Die(errno, ti->data);
             error = 1;
@@ -1743,7 +1816,7 @@ DiskFreeCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
        if (code) {
            Die(errno, ti->data);
             error = 1;
@@ -1772,7 +1845,7 @@ QuotaCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = MAXSIZE;
        blob.in_size = 0;
        blob.out = space;
-       code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
        if (code) {
            Die(errno, ti->data);
             error = 1;
@@ -1920,7 +1993,7 @@ ListMountCmd(struct cmd_syndesc *as, void *arock)
        blob.out = space;
        memset(space, 0, MAXSIZE);
 
-       code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
+       code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
 
        if (code == 0) {
            printf("'%s' is a %smount point for volume '%s'\n",
@@ -1954,6 +2027,8 @@ MakeMountCmd(struct cmd_syndesc *as, void *arock)
     struct ViceIoctl blob;
     char * parent;
 
+    memset(&info, 0, sizeof(info));
+
     if (as->parms[2].items)    /* cell name specified */
        cellName = as->parms[2].items->data;
     else
@@ -2017,7 +2092,7 @@ MakeMountCmd(struct cmd_syndesc *as, void *arock)
            blob.in_size = 0;
            blob.out_size = sizeof(localCellName);
            blob.out = localCellName;
-           code = pioctl(parent, VIOC_GET_WS_CELL, &blob, 1);
+           code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
            if (!code)
                cellName = localCellName;
        }
@@ -2068,10 +2143,14 @@ MakeMountCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = 1 + (long)strlen(space);
     blob.in = space;
     blob.out = NULL;
-    code = pioctl(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
+    code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
 #else /* not WIN32 */
     code = symlink(space, path);
 #endif /* not WIN32 */
+
+    if (info.linkedCell)
+        free(info.linkedCell);
+
     if (code) {
        Die(errno, path);
        return 1;
@@ -2129,7 +2208,7 @@ RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
        blob.in_size = (long)strlen(tp)+1;
        blob.out = lsbuffer;
        blob.out_size = sizeof(lsbuffer);
-       code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
+       code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
        if (code) {
            if (errno == EINVAL) {
                fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
@@ -2149,7 +2228,7 @@ RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
         blob.out_size = 0;
        blob.in = tp;
        blob.in_size = (long)strlen(tp)+1;
-       code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
+       code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
        if (code) {
            Die(errno, ti->data);
             error = 1;
@@ -2172,6 +2251,7 @@ CheckServersCmd(struct cmd_syndesc *as, void *arock)
     struct afsconf_cell info;
     struct chservinfo checkserv;
 
+    memset(&info, 0, sizeof(info));
     memset(&checkserv, 0, sizeof(struct chservinfo));
     blob.in_size=sizeof(struct chservinfo);
     blob.in=(caddr_t)&checkserv;
@@ -2198,6 +2278,8 @@ CheckServersCmd(struct cmd_syndesc *as, void *arock)
        }
        strcpy(checkserv.tbuffer,info.name);
        checkserv.tsize=(int)strlen(info.name)+1;
+        if (info.linkedCell)
+            free(info.linkedCell);
     } else {
         strcpy(checkserv.tbuffer,"\0");
         checkserv.tsize=0;
@@ -2232,7 +2314,7 @@ CheckServersCmd(struct cmd_syndesc *as, void *arock)
 #endif /* WIN32 */
     }
 
-    code = pioctl(0, VIOCCKSERV, &blob, 1);
+    code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
     if (code) {
        if ((errno == EACCES) && (checkserv.tinterval > 0)) {
            printf("Must be root to change -interval\n");
@@ -2302,7 +2384,7 @@ MessagesCmd(struct cmd_syndesc *as, void *arock)
     if (code)
         return 1;
 
-    code = pioctl(0, VIOC_GAG, &blob, 1);
+    code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
     if (code) {
        Die(errno, 0);
         return 1;
@@ -2318,7 +2400,7 @@ CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
     
     blob.in_size = 0;
     blob.out_size = 0;
-    code = pioctl(0, VIOCCKBACK, &blob, 1);
+    code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
     if (code) {
        Die(errno, 0);
        return 1;
@@ -2362,7 +2444,7 @@ SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
     blob.in = (char *) &temp;
     blob.in_size = sizeof(afs_int32);
     blob.out_size = 0;
-    code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
+    code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
     if (code) {
        Die(errno, (char *) 0);
         return 1;
@@ -2384,7 +2466,7 @@ GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = 0;
     blob.out_size = sizeof(parms);
     blob.out = (char *) &parms;
-    code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
+    code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
     if (code) {
        Die(errno, NULL);
         return 1;
@@ -2420,7 +2502,7 @@ ListCellsCmd(struct cmd_syndesc *as, void *arock)
        blob.in_size = sizeof(afs_int32);
        blob.in = space;
        blob.out = space;
-       code = pioctl(0, VIOCGETCELL, &blob, 1);
+       code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
        if (code < 0) {
            if (errno == EDOM) 
                 break; /* done with the list */
@@ -2471,7 +2553,7 @@ ListAliasesCmd(struct cmd_syndesc *as, void *arock)
        blob.in_size = sizeof(afs_int32);
        blob.in = space;
        blob.out = space;
-       code = pioctl(0, VIOC_GETALIAS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
        if (code < 0) {
            if (errno == EDOM)
                break;          /* done with the list */
@@ -2518,7 +2600,7 @@ CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
     blob.in = (char *) &hostAddr;
     blob.out = (char *) &hostAddr;
     
-    code = pioctl(0, VIOC_CBADDR, &blob, 1);
+    code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
     if (code < 0) {
        Die(errno, 0);
        return 1;
@@ -2593,7 +2675,7 @@ NewCellCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = size;
     blob.in = space;
     blob.out_size = 0;
-    code = pioctl(0, VIOCNEWCELL, &blob, 1);
+    code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
     if (code < 0)
        Die(errno, 0);
     return 0;
@@ -2611,7 +2693,7 @@ NewCellCmd(struct cmd_syndesc *as, void *arock)
     blob.out_size = MAXSIZE;
     blob.out = space;
 
-    code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
+    code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
 
     if (code) {
         Die(errno, (char *) 0);
@@ -2645,7 +2727,7 @@ NewAliasCmd(struct cmd_syndesc *as, void *arock)
     blob.in = space;
     blob.out_size = 0;
     blob.out = space;
-    code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
+    code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
     if (code < 0) {
        if (errno == EEXIST) {
            fprintf(stderr,
@@ -2677,7 +2759,7 @@ WhichCellCmd(struct cmd_syndesc *as, void *arock)
     for(ti=as->parms[0].items; ti; ti=ti->next) {
         cm_fid_t fid;
         afs_uint32 filetype;
-       char cell[MAXCELLCHARS];
+       char cell[CELL_MAXNAMELEN];
 
         /* once per file */
         memset(&fid, 0, sizeof(fid));
@@ -2691,7 +2773,7 @@ WhichCellCmd(struct cmd_syndesc *as, void *arock)
 
         blob.out_size = sizeof(cm_fid_t);
         blob.out = (char *) &fid;
-        if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
+        if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
             options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
             options.fid = fid;
         } else {
@@ -2703,12 +2785,12 @@ WhichCellCmd(struct cmd_syndesc *as, void *arock)
         blob.out_size = sizeof(filetype);
         blob.out = &filetype;
 
-        code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
+        code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
 
-        blob.out_size = MAXCELLCHARS;
+        blob.out_size = CELL_MAXNAMELEN;
         blob.out = cell;
 
-        code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
+        code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
        if (code) {
            if (errno == ENOENT)
                fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
@@ -2735,7 +2817,7 @@ WSCellCmd(struct cmd_syndesc *as, void *arock)
     blob.out_size = MAXSIZE;
     blob.out = space;
 
-    code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
 
     if (code) {
        Die(errno, NULL);
@@ -2797,7 +2879,7 @@ MonitorCmd(struct cmd_syndesc *as, void *arock)
     blob.out_size = sizeof(afs_int32);
     blob.in = (char *) &hostAddr;
     blob.out = (char *) &hostAddr;
-    code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
+    code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
     if (code) {
        Die(errno, 0);
        return 1;
@@ -2860,7 +2942,7 @@ SysNameCmd(struct cmd_syndesc *as, void *arock)
         *(input++) = '\0';
     }
     memcpy(space, &setp, sizeof(afs_int32));
-    code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
+    code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
     if (code) {
         Die(errno, 0);
         return 1;
@@ -2966,7 +3048,7 @@ static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = sizeof(afs_int32);
     blob.out = (char *) &exportcall;
     blob.out_size = sizeof(afs_int32);
-    code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
+    code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
     if (code) {
        if (errno == ENODEV) {
            fprintf(stderr,
@@ -3004,6 +3086,7 @@ GetCellCmd(struct cmd_syndesc *as, void *arock)
     } args;
     int error = 0;
 
+    memset(&info, 0, sizeof(info));
     memset(&args, 0, sizeof(args));      /* avoid Purify UMR error */
     for(ti=as->parms[0].items; ti; ti=ti->next) {
        /* once per cell */
@@ -3014,9 +3097,11 @@ GetCellCmd(struct cmd_syndesc *as, void *arock)
             error = 1;
            continue;
        }
+        if (info.linkedCell)
+            free(info.linkedCell);
        blob.in_size = 1+(long)strlen(info.name);
        blob.in = info.name;
-       code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
        if (code) {
            if (errno == ENOENT)
                fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
@@ -3054,6 +3139,8 @@ static int SetCellCmd(struct cmd_syndesc *as, void *arock)
     } args;
     int error = 0;
 
+    memset(&info, 0, sizeof(info));
+
     /* Check arguments. */
     if (as->parms[1].items && as->parms[2].items) {
         fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
@@ -3087,12 +3174,14 @@ static int SetCellCmd(struct cmd_syndesc *as, void *arock)
             error = 1;
            continue;
        }
+        if (info.linkedCell)
+            free(info.linkedCell);
        strcpy(args.cname, info.name);
        blob.in_size = sizeof(args);
        blob.in = (caddr_t) &args;
        blob.out_size = 0;
        blob.out = (caddr_t) 0;
-       code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
        if (code) {
            Die(errno, info.name);      /* XXX added cell name to Die() call */
             error = 1;
@@ -3144,7 +3233,7 @@ pokeServers(void)
 {
     int code;
     cm_SSetPref_t *ssp;
-    code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
+    code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
 
     ssp = (cm_SSetPref_t *)space;
     gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
@@ -3162,14 +3251,14 @@ pokeServers(void)
 {
     int code;
 
-    code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
+    code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
     if (code && (errno == EINVAL)) {
        struct setspref *ssp;
        ssp = (struct setspref *)gblob.in;
        if (!(ssp->flags & DBservers)) {
            gblob.in = (void *)&(ssp->servers[0]);
            gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
-           code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
+           code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
            return code ? errno : 0;
        }
        fprintf(stderr,
@@ -3543,7 +3632,7 @@ GetPrefCmd(struct cmd_syndesc *as, void *arock)
         in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
         in->flags = vlservers; 
 
-        code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
+        code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
         if (code){
             perror("getserverprefs pioctl");
             Die (errno,0);
@@ -3615,7 +3704,7 @@ GetPrefCmd(struct cmd_syndesc *as, void *arock)
            (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
        in->flags = vlservers;
 
-       code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
        if (code) {
            perror("getserverprefs pioctl");
            return 1;
@@ -3642,6 +3731,52 @@ GetPrefCmd(struct cmd_syndesc *as, void *arock)
 }
 #endif /* WIN32 */
 
+static afs_int32
+SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
+{
+    long inValue = 0;
+    long outValue = 0;
+    long code;
+
+    struct ViceIoctl blob;
+
+    if (asp->parms[0].items) {
+        /* On */
+
+        inValue = 3;
+    } else if (asp->parms[1].items) {
+        /* Off */
+
+        inValue = 2;
+    }
+
+    if (inValue != 0 && !IsAdmin()) {
+        fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
+
+    blob.in_size = sizeof(inValue);
+    blob.in = (char *) &inValue;
+    blob.out_size = sizeof(outValue);
+    blob.out = (char *) &outValue;
+
+    code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
+    if (code) {
+        Die(errno, NULL);
+        return code;
+    }
+
+    if (outValue != 2) {
+        printf("Unicode support is %s%s.\n",
+               ((outValue != 0)? "enabled":"disabled"),
+               ((inValue != 0)? " for new SMB connections":""));
+    } else {
+        printf("Unicode support is absent in this installation of OpenAFS.\n");
+    }
+
+    return 0;
+}
+
 static int
 UuidCmd(struct cmd_syndesc *asp, void *arock)
 {
@@ -3673,7 +3808,7 @@ UuidCmd(struct cmd_syndesc *asp, void *arock)
     blob.out_size = sizeof(outValue);
     blob.out = (char *) &outValue;
 
-    code = pioctl(NULL, VIOC_UUIDCTL, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
     if (code) {
         Die(errno, NULL);
         return code;
@@ -3732,7 +3867,7 @@ TraceCmd(struct cmd_syndesc *asp, void *arock)
     blob.out_size = sizeof(long);
     blob.out = (char *) &outValue;
         
-    code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
     if (code) {
         Die(errno, NULL);
         return code;
@@ -3813,14 +3948,14 @@ StoreBehindCmd(struct cmd_syndesc *as, void *arock)
     /* once per -file */
     for (ti = as->parms[1].items; ti; ti = ti->next) {
        /* Do this solely to see if the file is there */
-       code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
        if (code) {
            Die(errno, ti->data);
            error = 1;
            continue;
        }
 
-       code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
+       code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
        if (code) {
            Die(errno, ti->data);
            error = 1;
@@ -3844,7 +3979,7 @@ StoreBehindCmd(struct cmd_syndesc *as, void *arock)
      */
     if (!as->parms[1].items || (allfiles != -1)) {
        tsb.sb_default = allfiles;
-       code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
+       code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
        if (code) {
            Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
            error = 1;
@@ -3879,15 +4014,17 @@ SetCryptCmd(struct cmd_syndesc *as, void *arock)
       flag = 1;
     else if (strcmp(tp, "off") == 0)
       flag = 0;
+    else if (strcmp(tp, "auth") == 0)
+      flag = 2;
     else {
-      fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
+      fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
       return EINVAL;
     }
 
     blob.in = (char *) &flag;
     blob.in_size = sizeof(flag);
     blob.out_size = 0;
-    code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
+    code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
     if (code)
         Die(code, NULL);
     return 0;
@@ -3905,7 +4042,7 @@ GetCryptCmd(struct cmd_syndesc *as, void *arock)
     blob.out_size = sizeof(flag);
     blob.out = space;
 
-    code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
+    code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
 
     if (code) 
         Die(code, NULL);
@@ -3913,7 +4050,9 @@ GetCryptCmd(struct cmd_syndesc *as, void *arock)
       tp = space;
       memcpy(&flag, tp, sizeof(afs_int32));
       printf("Security level is currently ");
-      if (flag == 1)
+      if (flag == 2)
+          printf("auth (data integrity).\n");
+      else if (flag == 1)
         printf("crypt (data security).\n");
       else
         printf("clear.\n");
@@ -3951,7 +4090,7 @@ MemDumpCmd(struct cmd_syndesc *asp, void *arock)
     blob.out_size = sizeof(long);
     blob.out = (char *) &outValue;
 
-    code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
     if (code) {
         Die(errno, NULL);
         return code;
@@ -4036,7 +4175,7 @@ CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
                         0, 
                         "AFS", 
                         REG_OPTION_NON_VOLATILE,
-                        KEY_WRITE,
+                        (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
                         NULL, 
                         &hkCSCPolicy,
                         NULL );
@@ -4084,7 +4223,7 @@ CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
                         0, 
                         "AFS", 
                         REG_OPTION_NON_VOLATILE,
-                        KEY_READ|KEY_QUERY_VALUE,
+                        (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
                         NULL, 
                         &hkCSCPolicy,
                         NULL );
@@ -4143,7 +4282,7 @@ GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
        in->num_servers =
            (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
        /* returns addr in network byte order */
-       code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
+       code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
        if (code) {
            perror("getClientInterfaceAddr pioctl");
            return 1;
@@ -4232,7 +4371,7 @@ SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
     }
     blob.in_size = sizeUsed - sizeof(struct spref);
 
-    code = pioctl(0, VIOC_SETCPREFS, &blob, 1);        /* network order */
+    code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1);   /* network order */
     if (code) {
        Die(errno, 0);
        error = 1;
@@ -4343,7 +4482,7 @@ FlushMountCmd(struct cmd_syndesc *as, void *arock)
        blob.out_size = 0;
        memset(space, 0, MAXSIZE);
 
-       code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
+       code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
 
        if (code != 0) {
            if (errno == EINVAL) {
@@ -4383,7 +4522,7 @@ RxStatProcCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = sizeof(afs_int32);
     blob.out_size = 0;
 
-    code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
     if (code != 0) {
        Die(errno, NULL);
        return 1;
@@ -4417,7 +4556,7 @@ RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = sizeof(afs_int32);
     blob.out_size = 0;
 
-    code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
     if (code != 0) {
        Die(errno, NULL);
        return 1;
@@ -4497,7 +4636,7 @@ TestVolStatCmd(struct cmd_syndesc *as, void *arock)
     blob.in_size = sizeof(test);
     blob.out_size = 0;
 
-    code = pioctl(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
+    code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
     if (code != 0) {
        Die(errno, NULL);
        return 1;
@@ -4510,10 +4649,55 @@ TestVolStatCmd(struct cmd_syndesc *as, void *arock)
 #include "AFS_component_version_number.c"
 #endif
 
-main(int argc, char **argv)
+static void
+FreeUtf8CmdLine(int argc, char ** argv)
+{
+    int i;
+    for (i=0; i < argc; i++) {
+        if (argv[i])
+            free(argv[i]);
+    }
+    free(argv);
+}
+
+static char **
+MakeUtf8Cmdline(int argc, const wchar_t **wargv)
+{
+    char ** argv;
+    int i;
+
+    argv = calloc(argc, sizeof(argv[0]));
+    if (argv == NULL)
+        return NULL;
+
+    for (i=0; i < argc; i++) {
+        int s;
+
+        s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
+        if (s == 0 ||
+            (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
+            break;
+        }
+
+        s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
+        if (s == 0) {
+            break;
+        }
+    }
+
+    if (i < argc) {
+        FreeUtf8CmdLine(argc, argv);
+        return NULL;
+    }
+
+    return argv;
+}
+
+int wmain(int argc, wchar_t **wargv)
 {
     afs_int32 code;
     struct cmd_syndesc *ts;
+    char ** argv;
 
 #ifdef AFS_AIX32_ENV
     /*
@@ -4535,6 +4719,8 @@ main(int argc, char **argv)
     WSAStartup(0x0101, &WSAjunk);
 #endif /* WIN32 */
 
+    argv = MakeUtf8Cmdline(argc, wargv);
+
     /* try to find volume location information */
     osi_Init();
 
@@ -4811,11 +4997,17 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-volume",  CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
     cmd_AddParm(ts, "-state",   CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
 
+    ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
+    cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
+    cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
+
     code = cmd_Dispatch(argc, argv);
 
     if (rxInitDone) 
         rx_Finalize();
     
+    FreeUtf8CmdLine(argc, argv);
+    
     return code;
 }