2 Unix SMB/Netbios implementation.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-1997
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 extern int DEBUGLEVEL;
36 extern struct cli_state *smb_cli;
42 /****************************************************************************
44 ****************************************************************************/
45 void cmd_lsa_query_info(struct client_info *info)
51 fstrcpy(info->dom.level3_dom, "");
52 fstrcpy(info->dom.level5_dom, "");
53 ZERO_STRUCT(info->dom.level3_sid);
54 ZERO_STRUCT(info->dom.level5_sid);
56 fstrcpy(srv_name, "\\\\");
57 fstrcat(srv_name, info->myhostname);
60 DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name));
62 DEBUG(5, ("cmd_lsa_query_info: smb_cli->fd:%d\n", smb_cli->fd));
64 /* open LSARPC session. */
65 res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC) : False;
67 /* lookup domain controller; receive a policy handle */
68 res = res ? do_lsa_open_policy(smb_cli,
70 &info->dom.lsa_info_pol, False) : False;
72 /* send client info query, level 3. receive domain name and sid */
73 res = res ? do_lsa_query_info_pol(smb_cli,
74 &info->dom.lsa_info_pol, 0x03,
76 &info->dom.level3_sid) : False;
78 /* send client info query, level 5. receive domain name and sid */
79 res = res ? do_lsa_query_info_pol(smb_cli,
80 &info->dom.lsa_info_pol, 0x05,
82 &info->dom.level5_sid) : False;
84 res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False;
86 /* close the session */
87 cli_nt_session_close(smb_cli);
91 BOOL domain_something = False;
93 DEBUG(5,("cmd_lsa_query_info: query succeeded\n"));
95 fprintf(out_hnd, "LSA Query Info Policy\n");
97 if (info->dom.level3_dom[0] != 0)
99 sid_to_string(sid, &info->dom.level3_sid);
100 fprintf(out_hnd, "Domain Member - Domain: %s SID: %s\n",
101 info->dom.level3_dom, sid);
102 domain_something = True;
104 if (info->dom.level5_dom[0] != 0)
106 sid_to_string(sid, &info->dom.level5_sid);
107 fprintf(out_hnd, "Domain Controller - Domain: %s SID: %s\n",
108 info->dom.level5_dom, sid);
109 domain_something = True;
111 if (!domain_something)
113 fprintf(out_hnd, "%s is not a Domain Member or Controller\n",
119 DEBUG(5,("cmd_lsa_query_info: query failed\n"));
123 /****************************************************************************
125 ****************************************************************************/
126 void cmd_lsa_lookup_names(struct client_info *info)
141 fstrcpy(srv_name, "\\\\");
142 fstrcat(srv_name, info->myhostname);
145 DEBUG(4,("cmd_lsa_lookup_names: server: %s\n", srv_name));
147 while (num_names < 10 && next_token(NULL, temp, NULL, sizeof(temp)))
149 names[num_names] = strdup(temp);
155 fprintf(out_hnd, "lookupnames <name> [<name> ...]\n");
159 /* open LSARPC session. */
160 res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC) : False;
162 /* lookup domain controller; receive a policy handle */
163 res = res ? do_lsa_open_policy(smb_cli,
165 &info->dom.lsa_info_pol, True) : False;
167 /* send lsa lookup sids call */
168 res = res ? do_lsa_lookup_names(smb_cli,
169 &info->dom.lsa_info_pol,
171 &sids, &num_sids) : False;
173 res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False;
175 /* close the session */
176 cli_nt_session_close(smb_cli);
180 DEBUG(5,("cmd_lsa_lookup_names: query succeeded\n"));
184 DEBUG(5,("cmd_lsa_lookup_names: query failed\n"));
189 fprintf(out_hnd,"Lookup Names:\n");
190 for (i = 0; i < num_sids; i++)
192 sid_to_string(temp, &sids[i]);
193 fprintf(out_hnd, "SID: %s -> %s\n", names[i], temp);
204 for (i = 0; i < num_names; i++)
206 if (names[i] != NULL)
213 /****************************************************************************
215 ****************************************************************************/
216 void cmd_lsa_lookup_sids(struct client_info *info)
230 fstrcpy(srv_name, "\\\\");
231 fstrcat(srv_name, info->myhostname);
234 DEBUG(4,("cmd_lsa_lookup_sids: server: %s\n", srv_name));
236 while (num_sids < 10 && next_token(NULL, temp, NULL, sizeof(temp)))
238 if (strnequal("S-", temp, 2))
240 fstrcpy(sid_name, temp);
244 sid_to_string(sid_name, &info->dom.level5_sid);
246 if (sid_name[0] == 0)
248 fprintf(out_hnd, "please use lsaquery first or specify a complete SID\n");
252 fstrcat(sid_name, "-");
253 fstrcat(sid_name, temp);
255 make_dom_sid(&sid[num_sids], sid_name);
256 sids[num_sids] = &sid[num_sids];
262 fprintf(out_hnd, "lookupsid RID or SID\n");
266 /* open LSARPC session. */
267 res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC) : False;
269 /* lookup domain controller; receive a policy handle */
270 res = res ? do_lsa_open_policy(smb_cli,
272 &info->dom.lsa_info_pol, True) : False;
274 /* send lsa lookup sids call */
275 res = res ? do_lsa_lookup_sids(smb_cli,
276 &info->dom.lsa_info_pol,
278 &names, &num_names) : False;
280 res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False;
282 /* close the session */
283 cli_nt_session_close(smb_cli);
287 DEBUG(5,("cmd_lsa_lookup_sids: query succeeded\n"));
291 DEBUG(5,("cmd_lsa_lookup_sids: query failed\n"));
295 fprintf(out_hnd,"Lookup SIDS:\n");
296 for (i = 0; i < num_names; i++)
298 sid_to_string(temp, sids[i]);
299 fprintf(out_hnd, "SID: %s -> %s\n", temp, names[i]);
300 if (names[i] != NULL)