s3: smbclient: Add posix_whoami command.
authorJeremy Allison <jra@samba.org>
Wed, 25 May 2016 16:15:13 +0000 (09:15 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 25 May 2016 21:09:08 +0000 (23:09 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
source3/client/client.c

index 831b9bc82609a9076e6bfa35628aa0709f493829..45dc11c2ba8ab277821733375285209d26bb1019 100644 (file)
@@ -2956,6 +2956,50 @@ static int cmd_unlock(void)
        return 0;
 }
 
+static int cmd_posix_whoami(void)
+{
+       TALLOC_CTX *ctx = talloc_tos();
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       uint64_t uid = 0;
+       uint64_t gid = 0;
+       uint32_t num_gids = 0;
+       uint32_t num_sids = 0;
+       uint64_t *gids = NULL;
+       struct dom_sid *sids = NULL;
+       bool guest = false;
+       uint32_t i;
+
+       status = cli_posix_whoami(cli,
+                       ctx,
+                       &uid,
+                       &gid,
+                       &num_gids,
+                       &gids,
+                       &num_sids,
+                       &sids,
+                       &guest);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("posix_whoami failed with error %s\n", nt_errstr(status));
+               return 1;
+       }
+
+       d_printf("GUEST:%s\n", guest ? "True" : "False");
+       d_printf("UID:%" PRIu64 "\n", uid);
+       d_printf("GID:%" PRIu64 "\n", gid);
+       d_printf("NUM_GIDS:%" PRIu32 "\n", num_gids);
+       for (i = 0; i < num_gids; i++) {
+               d_printf("GIDS[%" PRIu32 "]:%" PRIu64 "\n", i, gids[i]);
+       }
+       d_printf("NUM_SIDS:%" PRIu32 "\n", num_sids);
+       for (i = 0; i < num_sids; i++) {
+               char *sid_str = dom_sid_string(ctx, &sids[i]);
+               d_printf("SIDS[%" PRIu32 "]:%s\n", i, sid_str);
+               TALLOC_FREE(sid_str);
+       }
+       return 0;
+}
+
 
 /****************************************************************************
  Remove a directory.
@@ -4931,6 +4975,8 @@ static struct {
   {"posix_mkdir",cmd_posix_mkdir,"<name> 0<mode> creates a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
   {"posix_rmdir",cmd_posix_rmdir,"<name> removes a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
   {"posix_unlink",cmd_posix_unlink,"<name> removes a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
+  {"posix_whoami",cmd_posix_whoami,"retun logged on user information "
+                       "using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
   {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
   {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
   {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},