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.level3_sid, "");
53 fstrcpy(info->dom.level5_dom, "");
54 fstrcpy(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) : 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;
92 DEBUG(5,("cmd_lsa_query_info: query succeeded\n"));
94 fprintf(out_hnd, "LSA Query Info Policy\n");
96 if (info->dom.level3_sid[0] != 0)
98 fprintf(out_hnd, "Domain Member - Domain: %s SID: %s\n",
99 info->dom.level3_dom, info->dom.level3_sid);
100 domain_something = True;
102 if (info->dom.level5_sid[0] != 0)
104 fprintf(out_hnd, "Domain Controller - Domain: %s SID: %s\n",
105 info->dom.level5_dom, info->dom.level5_sid);
106 domain_something = True;
108 if (!domain_something)
110 fprintf(out_hnd, "%s is not a Domain Member or Controller\n",
116 DEBUG(5,("cmd_lsa_query_info: query failed\n"));
120 /****************************************************************************
122 ****************************************************************************/
123 void cmd_lsa_lookup_sids(struct client_info *info)
134 DEBUG(5, ("cmd_lsa_lookup_sids: smb_cli->fd:%d\n", smb_cli->fd));
136 fstrcpy(srv_name, "\\\\");
137 fstrcat(srv_name, info->myhostname);
140 fstrcpy(sid_name, info->dom.level5_sid);
142 if (next_token(NULL, temp, NULL, sizeof(temp)))
144 if (info->dom.level5_sid[0] == 0)
146 fprintf(out_hnd, "please use lsaquery first or specify a complete SID\n");
150 if (strnequal("S-", temp, 2))
152 fstrcpy(sid_name, temp);
156 fstrcat(sid_name, "-");
157 fstrcat(sid_name, temp);
162 fprintf(out_hnd, "lsalookup RID or SID\n");
166 DEBUG(4,("cmd_lsa_lookup_sids: server: %s sid:%s\n",
167 srv_name, sid_name));
169 make_dom_sid(&sid, sid_name);
173 /* open LSARPC session. */
174 res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, False) : False;
176 /* lookup domain controller; receive a policy handle */
177 res = res ? do_lsa_open_policy(smb_cli,
179 &info->dom.lsa_info_pol, True) : False;
181 /* send client info query, level 3. receive domain name and sid */
182 res = res ? do_lsa_lookup_sids(smb_cli,
183 &info->dom.lsa_info_pol, 1, sids, names) : False;
185 res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False;
187 /* close the session */
188 cli_nt_session_close(smb_cli);
192 DEBUG(5,("cmd_lsa_lookup_sids: query succeeded\n"));
197 DEBUG(5,("cmd_lsa_lookup_sids: query failed\n"));