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_sids(struct client_info *info)
140 fstrcpy(srv_name, "\\\\");
141 fstrcat(srv_name, info->myhostname);
144 DEBUG(4,("cmd_lsa_lookup_sids: server: %s\n", srv_name));
146 while (num_sids < 10 && next_token(NULL, temp, NULL, sizeof(temp)))
148 if (strnequal("S-", temp, 2))
150 fstrcpy(sid_name, temp);
154 sid_to_string(sid_name, &info->dom.level5_sid);
156 if (sid_name[0] == 0)
158 fprintf(out_hnd, "please use lsaquery first or specify a complete SID\n");
162 fstrcat(sid_name, "-");
163 fstrcat(sid_name, temp);
165 init_dom_sid(&sid[num_sids], sid_name);
166 sids[num_sids] = &sid[num_sids];
172 fprintf(out_hnd, "lookupsid RID or SID\n");
176 /* open LSARPC session. */
177 res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC) : False;
179 /* lookup domain controller; receive a policy handle */
180 res = res ? do_lsa_open_policy(smb_cli,
182 &info->dom.lsa_info_pol, True) : False;
184 /* send lsa lookup sids call */
185 res = res ? do_lsa_lookup_sids(smb_cli,
186 &info->dom.lsa_info_pol,
188 &names, &num_names) : False;
190 res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False;
192 /* close the session */
193 cli_nt_session_close(smb_cli);
197 DEBUG(5,("cmd_lsa_lookup_sids: query succeeded\n"));
201 DEBUG(5,("cmd_lsa_lookup_sids: query failed\n"));
205 fprintf(out_hnd,"Lookup SIDS:\n");
206 for (i = 0; i < num_names; i++)
208 sid_to_string(temp, sids[i]);
209 fprintf(out_hnd, "SID: %s -> %s\n", temp, names[i]);
210 if (names[i] != NULL)