DEVEL15-windows-fs-uuid-20060627
authorJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 27 Jun 2006 23:19:35 +0000 (23:19 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 27 Jun 2006 23:19:35 +0000 (23:19 +0000)
 fs uuid [-generate]

(cherry picked from commit 5c563c121e853a06bb47d0b8932276982e676150)

src/WINNT/afsd/cm_ioctl.c
src/WINNT/afsd/cm_ioctl.h
src/WINNT/afsd/fs.c
src/WINNT/afsd/smb_iocons.h
src/WINNT/afsd/smb_ioctl.c

index f8ee369..2906bc0 100644 (file)
@@ -2647,6 +2647,24 @@ long cm_IoctlGetSMBName(smb_ioctl_t *ioctlp, cm_user_t *userp)
   return 0;
 }
 
+long cm_IoctlUUIDControl(struct smb_ioctl * ioctlp, struct cm_user *userp)
+{
+    long cmd;
+    afsUUID uuid;
+
+    memcpy(&cmd, ioctlp->inDatap, sizeof(long));
+
+    if (cmd) {             /* generate a new UUID */
+        UuidCreate((UUID *) &uuid);
+        cm_data.Uuid = uuid;
+    }
+
+    memcpy(ioctlp->outDatap, &cm_data.Uuid, sizeof(cm_data.Uuid));
+    ioctlp->outDatap += sizeof(cm_data.Uuid);
+
+    return 0;
+}
+
 /* 
  * functions to dump contents of various structures. 
  * In debug build (linked with crt debug library) will dump allocated but not freed memory
index 246a788..6753cb3 100644 (file)
@@ -161,6 +161,9 @@ extern long cm_IoctlMemoryDump(smb_ioctl_t *ioctlp, cm_user_t *userp);
 extern long cm_IoctlRxStatProcess(smb_ioctl_t *ioctlp, cm_user_t *userp);
 
 extern long cm_IoctlRxStatPeer(smb_ioctl_t *ioctlp, cm_user_t *userp);
+
+extern long cm_IoctlUUIDControl(struct smb_ioctl * ioctlp, struct cm_user *userp);
+
 #endif /* __CM_IOCTL_INTERFACES_ONLY__ */
 
 #endif /*  __CM_IOCTL_H_ENV__ */
index 7b000bf..ed5db81 100644 (file)
@@ -3533,6 +3533,56 @@ GetPrefCmd(struct cmd_syndesc *as, char *arock)
 #endif /* WIN32 */
 
 static int
+UuidCmd(struct cmd_syndesc *asp, char *arock)
+{
+    long code;
+    long inValue;
+    afsUUID outValue;
+    struct ViceIoctl blob;
+    char * uuidstring = NULL;
+
+#ifdef WIN32
+    if ( !IsAdmin() ) {
+        fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
+        return EACCES;
+    }
+#else
+    if (geteuid()) {
+        fprintf (stderr, "Permission denied: requires root access.\n");
+        return EACCES;
+    }
+#endif
+
+    if (asp->parms[0].items) {
+        inValue = 1;            /* generate new UUID */
+    } else {
+        inValue = 0;            /* just show the current UUID */
+    }
+
+    blob.in_size = sizeof(inValue);
+    blob.in = (char *) &inValue;
+    blob.out_size = sizeof(outValue);
+    blob.out = (char *) &outValue;
+
+    code = pioctl(NULL, VIOC_UUIDCTL, &blob, 1);
+    if (code) {
+        Die(errno, NULL);
+        return code;
+    }
+
+    UuidToString((UUID *) &outValue, &uuidstring);
+
+    printf("%sUUID: %s",
+           ((inValue == 1)?"New ":""),
+           uuidstring);
+
+    if (uuidstring)
+        RpcStringFree(&uuidstring);
+
+    return 0;
+}
+
+static int
 TraceCmd(struct cmd_syndesc *asp, char *arock)
 {
     long code;
@@ -4543,6 +4593,9 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
     cmd_CreateAlias(ts, "tr");
 
+    ts = cmd_CreateSyntax("uuid", UuidCmd, 0, "manage the UUID for the cache manager");
+    cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
+
     ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
     cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
     cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
index 585bdc8..be34f81 100644 (file)
@@ -96,4 +96,5 @@ typedef struct cm_cacheParms {
 #define VIOCGETOWNER                    0x2d
 #define VIOC_RXSTAT_PROC                0x2e
 #define VIOC_RXSTAT_PEER                0x2f
+#define VIOC_UUIDCTL                    0x30
 #endif /*  __SMB_IOCONS_H_ENV_ */
index 70f4b28..3961dc0 100644 (file)
@@ -83,6 +83,7 @@ void smb_InitIoctl(void)
         smb_ioctlProcsp[VIOCGETOWNER] = cm_IoctlGetOwner;
         smb_ioctlProcsp[VIOC_RXSTAT_PROC] = cm_IoctlRxStatProcess;
         smb_ioctlProcsp[VIOC_RXSTAT_PEER] = cm_IoctlRxStatPeer;
+        smb_ioctlProcsp[VIOC_UUIDCTL] = cm_IoctlUUIDControl;
 }
 
 /* called to make a fid structure into an IOCTL fid structure */