r5316: Get 'net afskey' into a subcommand of its own, 'net afs key'.
authorVolker Lendecke <vlendec@samba.org>
Thu, 10 Feb 2005 17:38:49 +0000 (17:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:55:37 +0000 (10:55 -0500)
Implement 'net afs impersonate', generate a token for a specified user. You
obviously need to be root for this operation.

Volker
(This used to be commit 5818b092e6e50d38238b0520329eb8912125c90a)

source3/utils/net.c
source3/utils/net_help.c

index cfbc8aca512146066e99a42ed19ff097242732e6..9c05828357c15f90d6f35ca844f502a7767afda7 100644 (file)
@@ -552,14 +552,16 @@ static int net_getdomainsid(int argc, const char **argv)
 
 #ifdef WITH_FAKE_KASERVER
 
-int net_afskey_usage(int argc, const char **argv)
+int net_help_afs(int argc, const char **argv)
 {
-       d_printf("  net afskey filename\n"
+       d_printf("  net afs key filename\n"
                 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n");
+       d_printf("  net afs impersonate <user> <cell>\n"
+                "\tCreates a token for user@cell\n\n");
        return -1;
 }
 
-static int net_afskey(int argc, const char **argv)
+static int net_afs_key(int argc, const char **argv)
 {
        int fd;
        struct afs_keyfile keyfile;
@@ -592,6 +594,42 @@ static int net_afskey(int argc, const char **argv)
        return 0;
 }
 
+static int net_afs_impersonate(int argc, const char **argv)
+{
+       char *token;
+
+       if (argc != 2) {
+               fprintf(stderr, "Usage: net afs impersonate <user> <cell>\n");
+               exit(1);
+       }
+
+       token = afs_createtoken_str(argv[0], argv[1]);
+
+       if (token == NULL) {
+               fprintf(stderr, "Could not create token\n");
+               exit(1);
+       }
+
+       if (!afs_settoken_str(token)) {
+               fprintf(stderr, "Could not set token into kernel\n");
+               exit(1);
+       }
+
+       printf("Success: %s@%s\n", argv[0], argv[1]);
+       return 0;
+}
+
+static int net_afs(int argc, const char **argv)
+{
+       struct functable func[] = {
+               {"key", net_afs_key},
+               {"impersonate", net_afs_impersonate},
+               {"help", net_help_afs},
+               {NULL, NULL}
+       };
+       return net_run_function(argc, argv, func, net_help_afs);
+}
+
 #endif /* WITH_FAKE_KASERVER */
 
 static uint32 get_maxrid(void)
@@ -707,7 +745,7 @@ static struct functable net_func[] = {
        {"STATUS", net_status},
        {"USERSIDLIST", net_usersidlist},
 #ifdef WITH_FAKE_KASERVER
-       {"AFSKEY", net_afskey},
+       {"AFS", net_afs},
 #endif
 
        {"HELP", net_help},
index 60206429b7ed6b9701315e2a4cae0eef8dca02cb..26d59beda2bf2aea1982d9e2d7e457f83726b77a 100644 (file)
@@ -269,7 +269,7 @@ int net_help(int argc, const char **argv)
                {"LOOKUP", net_lookup_usage},
                {"USERSIDLIST", net_usersidlist_usage},
 #ifdef WITH_FAKE_KASERVER
-               {"AFSKEY", net_afskey_usage},
+               {"AFS", net_help_afs},
 #endif
 
                {"HELP", help_usage},