2 Unix SMB/Netbios implementation.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-1999
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
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.
31 extern int DEBUGLEVEL
;
37 /****************************************************************************
38 nt enumerate trusted domains
39 ****************************************************************************/
40 void cmd_lsa_enum_trust_dom(struct client_info
*info
, int argc
, char *argv
[])
44 char **domains
= NULL
;
45 DOM_SID
**sids
= NULL
;
51 fstrcpy(srv_name
, "\\\\");
52 fstrcat(srv_name
, info
->dest_host
);
55 DEBUG(4,("cmd_lsa_enum_trust_dom: server:%s\n", srv_name
));
57 /* lookup domain controller; receive a policy handle */
58 res
= res
? lsa_open_policy( srv_name
,
59 &lsa_pol
, False
, 0x02000000) : False
;
63 /* send enum trusted domains query */
64 res
= res
? lsa_enum_trust_dom( &lsa_pol
,
66 &num_doms
, &domains
, &sids
) : False
;
68 } while (res
&& enum_ctx
!= 0);
70 res
= res
? lsa_close(&lsa_pol
) : False
;
75 DEBUG(5,("cmd_lsa_enum_trust_dom: query succeeded\n"));
77 report(out_hnd
, "LSA Enumerate Trusted Domains\n");
78 for (i
= 0; i
< num_doms
; i
++)
81 sid_to_string(sid
, sids
[i
]);
82 report(out_hnd
, "Domain:\t%s\tSID:\t%s\n",
88 DEBUG(5,("cmd_lsa_enum_trust_dom: query failed\n"));
91 free_char_array(num_doms
, domains
);
92 free_sid_array(num_doms
, sids
);
95 /****************************************************************************
97 ****************************************************************************/
98 void cmd_lsa_query_info(struct client_info
*info
, int argc
, char *argv
[])
105 fstrcpy(info
->dom
.level3_dom
, "");
106 fstrcpy(info
->dom
.level5_dom
, "");
107 ZERO_STRUCT(info
->dom
.level3_sid
);
108 ZERO_STRUCT(info
->dom
.level5_sid
);
110 fstrcpy(srv_name
, "\\\\");
111 fstrcat(srv_name
, info
->dest_host
);
114 DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name
));
116 /* lookup domain controller; receive a policy handle */
117 res
= res
? lsa_open_policy( srv_name
,
118 &lsa_pol
, False
, 0x02000000) : False
;
120 /* send client info query, level 3. receive domain name and sid */
121 res
= res
? lsa_query_info_pol( &lsa_pol
, 0x03,
122 info
->dom
.level3_dom
,
123 &info
->dom
.level3_sid
) : False
;
125 /* send client info query, level 5. receive domain name and sid */
126 res
= res
? lsa_query_info_pol( &lsa_pol
, 0x05,
127 info
->dom
.level5_dom
,
128 &info
->dom
.level5_sid
) : False
;
130 res
= res
? lsa_close(&lsa_pol
) : False
;
134 BOOL domain_something
= False
;
136 DEBUG(5,("cmd_lsa_query_info: query succeeded\n"));
138 report(out_hnd
, "LSA Query Info Policy\n");
140 if (info
->dom
.level3_dom
[0] != 0)
142 sid_to_string(sid
, &info
->dom
.level3_sid
);
143 report(out_hnd
, "Domain Member - Domain: %s SID: %s\n",
144 info
->dom
.level3_dom
, sid
);
145 domain_something
= True
;
147 if (info
->dom
.level5_dom
[0] != 0)
149 sid_to_string(sid
, &info
->dom
.level5_sid
);
150 report(out_hnd
, "Domain Controller - Domain: %s SID: %s\n",
151 info
->dom
.level5_dom
, sid
);
152 domain_something
= True
;
154 if (!domain_something
)
156 report(out_hnd
, "%s is not a Domain Member or Controller\n",
162 DEBUG(5,("cmd_lsa_query_info: query failed\n"));
166 /****************************************************************************
168 ****************************************************************************/
169 void cmd_lsa_lookup_names(struct client_info
*info
, int argc
, char *argv
[])
174 uint32
*types
= NULL
;
175 DOM_SID
*sids
= NULL
;
179 fstrcpy(srv_name
, "\\\\");
180 fstrcat(srv_name
, info
->dest_host
);
183 DEBUG(4,("cmd_lsa_lookup_names: server: %s\n", srv_name
));
193 report(out_hnd
, "lookupnames <name> [<name> ...]\n");
197 ret
= lookup_lsa_names(srv_name
,
199 &num_sids
, &sids
, &types
);
203 report(out_hnd
, "cmd_lsa_lookup_names: FAILED: %s\n",
204 get_nt_error_msg(ret
));
212 report(out_hnd
, "Lookup Names:\n");
213 for (i
= 0; i
< num_sids
; i
++)
215 sid_to_string(temp
, &sids
[i
]);
216 report(out_hnd
, "SID: %s -> %s (%d: %s)\n",
217 names
[i
], temp
, types
[i
],
218 get_sid_name_use_str(types
[i
]));
231 /****************************************************************************
233 ****************************************************************************/
234 void cmd_lsa_lookup_sids(struct client_info
*info
, int argc
, char *argv
[])
240 DOM_SID
**sids
= NULL
;
243 uint32
*types
= NULL
;
248 fstrcpy(srv_name
, "\\\\");
249 fstrcat(srv_name
, info
->dest_host
);
252 DEBUG(4,("cmd_lsa_lookup_sids: server: %s\n", srv_name
));
260 if (strnequal("S-", argv
[0], 2))
262 fstrcpy(sid_name
, argv
[0]);
266 sid_to_string(sid_name
, &info
->dom
.level5_sid
);
268 if (sid_name
[0] == 0)
270 report(out_hnd
, "please use lsaquery first or specify a complete SID\n");
274 fstrcat(sid_name
, "-");
275 fstrcat(sid_name
, argv
[0]);
277 string_to_sid(&sid
, sid_name
);
279 add_sid_to_array(&num_sids
, &sids
, &sid
);
287 report(out_hnd
, "lookupsid RID or SID\n");
291 /* lookup domain controller; receive a policy handle */
292 res
= res
? lsa_open_policy( srv_name
,
293 &lsa_pol
, True
, 0x02000000) : False
;
295 /* send lsa lookup sids call */
296 res
= res
? lsa_lookup_sids( &lsa_pol
,
298 &names
, &types
, &num_names
) : False
;
300 res
= res
? lsa_close(&lsa_pol
) : False
;
304 DEBUG(5,("cmd_lsa_lookup_sids: query succeeded\n"));
308 DEBUG(5,("cmd_lsa_lookup_sids: query failed\n"));
312 report(out_hnd
, "Lookup SIDS:\n");
313 for (i
= 0; i
< num_names
; i
++)
316 sid_to_string(temp
, sids
[i
]);
317 report(out_hnd
, "SID: %s -> %s (%d: %s)\n",
318 temp
, names
[i
], types
[i
],
319 get_sid_name_use_str(types
[i
]));
320 if (names
[i
] != NULL
)
333 free_sid_array(num_sids
, sids
);
336 /****************************************************************************
338 ****************************************************************************/
339 void cmd_lsa_set_secret(struct client_info
*info
, int argc
, char *argv
[])
347 fstrcpy(srv_name
, "\\\\");
348 fstrcat(srv_name
, info
->dest_host
);
353 report(out_hnd
, "setsecret <secret name> <secret value>\n");
357 secret_name
= argv
[1];
359 len
= strlen(argv
[2]);
361 make_unistr2(&uni_data
, data
, len
);
363 if (msrpc_lsa_set_secret(srv_name
, secret_name
,
364 (const char*)uni_data
.buffer
, uni_data
.uni_str_len
* 2))
366 report(out_hnd
, "LSA Set Secret: OK\n");
370 report(out_hnd
, "LSA Set Secret: failed\n");
374 /****************************************************************************
376 ****************************************************************************/
377 void cmd_lsa_create_secret(struct client_info
*info
, int argc
, char *argv
[])
382 fstrcpy(srv_name
, "\\\\");
383 fstrcat(srv_name
, info
->dest_host
);
388 report(out_hnd
, "createsecret <secret name>\n");
392 secret_name
= argv
[1];
394 if (msrpc_lsa_create_secret(srv_name
, secret_name
, 0x020003))
396 report(out_hnd
, "LSA Create Secret: OK\n");
400 report(out_hnd
, "LSA Query Secret: failed\n");
404 /****************************************************************************
406 ****************************************************************************/
407 void cmd_lsa_query_secret_secobj(struct client_info
*info
, int argc
, char *argv
[])
420 fstrcpy(srv_name
, "\\\\");
421 fstrcat(srv_name
, info
->dest_host
);
428 report(out_hnd
, "querysecretsecdes <secret name>\n");
432 secret_name
= argv
[1];
434 /* lookup domain controller; receive a policy handle */
435 res
= res
? lsa_open_policy(srv_name
,
436 &lsa_pol
, False
, 0x02000000) : False
;
438 /* lookup domain controller; receive a policy handle */
439 res1
= res
? lsa_open_secret(&lsa_pol
,
440 secret_name
, 0x02000000,
443 res2
= res1
? lsa_query_sec_obj(&pol_sec
, 0x07, &buf
) : False
;
447 display_sec_desc(out_hnd
, ACTION_HEADER
, buf
.sec
);
448 display_sec_desc(out_hnd
, ACTION_ENUMERATE
, buf
.sec
);
449 display_sec_desc(out_hnd
, ACTION_FOOTER
, buf
.sec
);
453 report(out_hnd
, "LSA Query Secret: failed\n");
456 free_sec_desc_buf(&buf
);
458 res1
= res1
? lsa_close(&pol_sec
) : False
;
459 res
= res
? lsa_close(&lsa_pol
) : False
;
464 /****************************************************************************
466 ****************************************************************************/
467 void cmd_lsa_query_secret(struct client_info
*info
, int argc
, char *argv
[])
474 fstrcpy(srv_name
, "\\\\");
475 fstrcat(srv_name
, info
->dest_host
);
482 report(out_hnd
, "querysecret <secret name>\n");
486 secret_name
= argv
[1];
488 if (msrpc_lsa_query_secret(srv_name
, secret_name
, &secret
,
492 report(out_hnd
, "\tValue : ");
493 for (i
= 0; i
< secret
.str_str_len
; i
++)
495 report(out_hnd
, "%02X", secret
.buffer
[i
]);
498 report(out_hnd
, "\n\tLast Updated: %s\n\n",
499 http_timestring(nt_time_to_unix(&last_update
)));
503 report(out_hnd
, "LSA Query Secret: failed\n");