summaryrefslogtreecommitdiffstats
path: root/source3/rpcclient/cmd_unixinfo.c
blob: 16f13a268269f473a93bd729417f38f3212a7894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Unix SMB/CIFS implementation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "includes.h"
#include "rpcclient.h"
#include "../librpc/gen_ndr/ndr_unixinfo_c.h"
#include "libcli/security/dom_sid.h"

static NTSTATUS cmd_unixinfo_uidtosid(
	struct rpc_pipe_client *cli,
	TALLOC_CTX *mem_ctx,
	int argc,
	const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	uint64_t uid = 0;
	struct dom_sid sid = { .sid_rev_num = 0, };
	struct dom_sid_buf buf;
	NTSTATUS status, result;

	if (argc != 2) {
		printf("Usage: %s [uid]\n", argv[0]);
		return NT_STATUS_OK;
	}
	uid = atoi(argv[1]);

	status = dcerpc_unixinfo_UidToSid(b, mem_ctx, uid, &sid, &result);
	if (!NT_STATUS_IS_OK(status)) {
		fprintf(stderr,
			"dcerpc_unixinfo_UidToSid failed: %s\n",
			nt_errstr(status));
		goto done;
	}
	if (!NT_STATUS_IS_OK(result)) {
		fprintf(stderr,
			"dcerpc_unixinfo_UidToSid returned: %s\n",
			nt_errstr(result));
		status = result;
		goto done;
	}

	printf("UidToSid(%"PRIu64")=%s\n",
	       uid,
	       dom_sid_str_buf(&sid, &buf));

done:
	return status;
}

static NTSTATUS cmd_unixinfo_getpwuid(
	struct rpc_pipe_client *cli,
	TALLOC_CTX *mem_ctx,
	int argc,
	const char **argv)
{
	struct dcerpc_binding_handle *b = cli->binding_handle;
	uint32_t count = 1;
	uint64_t uids = 0;
	struct unixinfo_GetPWUidInfo infos = { .homedir = NULL, };
	NTSTATUS status, result;

	if (argc != 2) {
		printf("Usage: %s [uid]\n", argv[0]);
		return NT_STATUS_OK;
	}
	uids = atoi(argv[1]);

	status = dcerpc_unixinfo_GetPWUid(
		b, mem_ctx, &count, &uids, &infos, &result);
	if (!NT_STATUS_IS_OK(status)) {
		goto done;
	}

	if (!NT_STATUS_IS_OK(status)) {
		fprintf(stderr,
			"dcerpc_unixinfo_GetPWUid failed: %s\n",
			nt_errstr(status));
		return status;
	}
	if (!NT_STATUS_IS_OK(result)) {
		fprintf(stderr,
			"dcerpc_unixinfo_GetPWUid returned: %s\n",
			nt_errstr(result));
		return result;
	}

	printf("status=%s, homedir=%s, shell=%s\n",
	       nt_errstr(infos.status),
	       infos.homedir,
	       infos.shell);

done:
	return status;
}

/* List of commands exported by this module */

struct cmd_set unixinfo_commands[] = {

	{
		.name = "UNIXINFO",
	},

	{
		.name               = "getpwuid",
		.returntype         = RPC_RTYPE_NTSTATUS,
		.ntfn               = cmd_unixinfo_getpwuid,
		.wfn                = NULL,
		.table              = &ndr_table_unixinfo,
		.rpc_pipe           = NULL,
		.description        = "Get shell and homedir",
		.usage              = "",
	},
	{
		.name               = "uidtosid",
		.returntype         = RPC_RTYPE_NTSTATUS,
		.ntfn               = cmd_unixinfo_uidtosid,
		.wfn                = NULL,
		.table              = &ndr_table_unixinfo,
		.rpc_pipe           = NULL,
		.description        = "Convert uid to sid",
		.usage              = "",
	},
	{
		.name = NULL
	},
};