s3:rpcclient: Encrypt the password buffers only if really needed
[samba.git] / source3 / rpcclient / cmd_unixinfo.c
1 /*
2  * Unix SMB/CIFS implementation.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "includes.h"
19 #include "rpcclient.h"
20 #include "../librpc/gen_ndr/ndr_unixinfo_c.h"
21 #include "libcli/security/dom_sid.h"
22
23 static NTSTATUS cmd_unixinfo_uidtosid(
24         struct rpc_pipe_client *cli,
25         TALLOC_CTX *mem_ctx,
26         int argc,
27         const char **argv)
28 {
29         struct dcerpc_binding_handle *b = cli->binding_handle;
30         uint64_t uid = 0;
31         struct dom_sid sid = { .sid_rev_num = 0, };
32         struct dom_sid_buf buf;
33         NTSTATUS status, result;
34
35         if (argc != 2) {
36                 printf("Usage: %s [uid]\n", argv[0]);
37                 return NT_STATUS_OK;
38         }
39         uid = atoi(argv[1]);
40
41         status = dcerpc_unixinfo_UidToSid(b, mem_ctx, uid, &sid, &result);
42         if (!NT_STATUS_IS_OK(status)) {
43                 fprintf(stderr,
44                         "dcerpc_unixinfo_UidToSid failed: %s\n",
45                         nt_errstr(status));
46                 goto done;
47         }
48         if (!NT_STATUS_IS_OK(result)) {
49                 fprintf(stderr,
50                         "dcerpc_unixinfo_UidToSid returned: %s\n",
51                         nt_errstr(result));
52                 status = result;
53                 goto done;
54         }
55
56         printf("UidToSid(%"PRIu64")=%s\n",
57                uid,
58                dom_sid_str_buf(&sid, &buf));
59
60 done:
61         return status;
62 }
63
64 static NTSTATUS cmd_unixinfo_getpwuid(
65         struct rpc_pipe_client *cli,
66         TALLOC_CTX *mem_ctx,
67         int argc,
68         const char **argv)
69 {
70         struct dcerpc_binding_handle *b = cli->binding_handle;
71         uint32_t count = 1;
72         uint64_t uids = 0;
73         struct unixinfo_GetPWUidInfo infos = { .homedir = NULL, };
74         NTSTATUS status, result;
75
76         if (argc != 2) {
77                 printf("Usage: %s [uid]\n", argv[0]);
78                 return NT_STATUS_OK;
79         }
80         uids = atoi(argv[1]);
81
82         status = dcerpc_unixinfo_GetPWUid(
83                 b, mem_ctx, &count, &uids, &infos, &result);
84         if (!NT_STATUS_IS_OK(status)) {
85                 goto done;
86         }
87
88         if (!NT_STATUS_IS_OK(status)) {
89                 fprintf(stderr,
90                         "dcerpc_unixinfo_GetPWUid failed: %s\n",
91                         nt_errstr(status));
92                 return status;
93         }
94         if (!NT_STATUS_IS_OK(result)) {
95                 fprintf(stderr,
96                         "dcerpc_unixinfo_GetPWUid returned: %s\n",
97                         nt_errstr(result));
98                 return result;
99         }
100
101         printf("status=%s, homedir=%s, shell=%s\n",
102                nt_errstr(infos.status),
103                infos.homedir,
104                infos.shell);
105
106 done:
107         return status;
108 }
109
110 /* List of commands exported by this module */
111
112 struct cmd_set unixinfo_commands[] = {
113
114         {
115                 .name = "UNIXINFO",
116         },
117
118         {
119                 .name               = "getpwuid",
120                 .returntype         = RPC_RTYPE_NTSTATUS,
121                 .ntfn               = cmd_unixinfo_getpwuid,
122                 .wfn                = NULL,
123                 .table              = &ndr_table_unixinfo,
124                 .rpc_pipe           = NULL,
125                 .description        = "Get shell and homedir",
126                 .usage              = "",
127         },
128         {
129                 .name               = "uidtosid",
130                 .returntype         = RPC_RTYPE_NTSTATUS,
131                 .ntfn               = cmd_unixinfo_uidtosid,
132                 .wfn                = NULL,
133                 .table              = &ndr_table_unixinfo,
134                 .rpc_pipe           = NULL,
135                 .description        = "Convert uid to sid",
136                 .usage              = "",
137         },
138         {
139                 .name = NULL
140         },
141 };