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.
29 extern int DEBUGLEVEL
;
30 extern pstring username
;
31 extern pstring workgroup
;
33 #define CLIENT_TIMEOUT (30*1000)
37 /****************************************************************************
39 ****************************************************************************/
40 BOOL
do_lsa_open_policy(uint16 fnum
, uint32 call_id
,
41 char *server_name
, LSA_POL_HND
*hnd
)
47 pstring data
; /* only 1024 bytes */
48 uint16 setup
[2]; /* only need 2 uint16 setup parameters */
50 BOOL valid_pol
= False
;
52 if (hnd
== NULL
) return False
;
54 /* create and send a MSRPC command with api LSA_OPENPOLICY */
56 DEBUG(4,("LSA Open Policy\n"));
58 /* store the parameters */
59 make_q_open_pol(&q_o
, server_name
, 0, 0, 0x1);
61 /* turn parameters into data stream */
62 p
= lsa_io_q_open_pol(False
, &q_o
, data
+ 0x18, data
, 4, 0);
64 /* create the request RPC_HDR_RR with no data */
65 create_rpc_request(call_id
, LSA_OPENPOLICY
, data
, PTR_DIFF(p
, data
));
67 /* create setup parameters. */
68 setup
[0] = 0x0026; /* 0x26 indicates "transact named pipe" */
69 setup
[1] = fnum
; /* file handle, from the SMBcreateX pipe, earlier */
71 /* send the data on \PIPE\ */
72 if (cli_call_api("\\PIPE\\", 0, PTR_DIFF(p
, data
), 2, 1024,
83 DEBUG(5, ("cli_call_api: return OK\n"));
87 if (p
) p
= smb_io_rpc_hdr_rr (True
, &hdr
, p
, rdata
, 4, 0);
88 if (p
) p
= align_offset(p
, rdata
, 4); /* oh, what a surprise */
90 hdr_len
= PTR_DIFF(p
, rdata
);
92 if (p
&& hdr_len
!= hdr
.hdr
.frag_len
- hdr
.alloc_hint
)
94 /* header length not same as calculated header length */
95 DEBUG(2,("do_lsa_open_policy: hdr_len %x != frag_len-alloc_hint %x\n",
96 hdr_len
, hdr
.hdr
.frag_len
- hdr
.alloc_hint
));
100 if (p
) p
= lsa_io_r_open_pol(True
, &r_o
, p
, rdata
, 4, 0);
102 pkt_len
= PTR_DIFF(p
, rdata
);
104 if (p
&& pkt_len
!= hdr
.hdr
.frag_len
)
106 /* packet data size not same as reported fragment length */
107 DEBUG(2,("do_lsa_open_policy: pkt_len %x != frag_len \n",
108 pkt_len
, hdr
.hdr
.frag_len
));
112 if (p
&& r_o
.status
!= 0)
114 /* report error code */
115 DEBUG(0,("LSA_OPENPOLICY: nt_status error %lx\n", r_o
.status
));
121 /* ok, at last: we're happy. return the policy handle */
122 memcpy(hnd
, r_o
.pol
.data
, sizeof(hnd
->data
));
127 if (rparam
) free(rparam
);
128 if (rdata
) free(rdata
);
133 /****************************************************************************
134 do a LSA Query Info Policy
135 ****************************************************************************/
136 BOOL
do_lsa_query_info_pol(uint16 fnum
, uint32 call_id
,
137 LSA_POL_HND
*hnd
, uint16 info_class
,
138 fstring domain_name
, pstring domain_sid
)
144 pstring data
; /* only 1024 bytes */
145 uint16 setup
[2]; /* only need 2 uint16 setup parameters */
146 LSA_Q_QUERY_INFO q_q
;
147 BOOL valid_response
= False
;
149 if (hnd
== NULL
|| domain_name
== NULL
|| domain_sid
== NULL
) return False
;
151 /* create and send a MSRPC command with api LSA_QUERYINFOPOLICY */
153 DEBUG(4,("LSA Query Info Policy\n"));
155 /* store the parameters */
156 make_q_query(&q_q
, hnd
, info_class
);
158 /* turn parameters into data stream */
159 p
= lsa_io_q_query(False
, &q_q
, data
+ 0x18, data
, 4, 0);
161 /* create the request RPC_HDR_RR with no data */
162 create_rpc_request(call_id
, LSA_QUERYINFOPOLICY
, data
, PTR_DIFF(p
, data
));
164 /* create setup parameters. */
165 setup
[0] = 0x0026; /* 0x26 indicates "transact named pipe" */
166 setup
[1] = fnum
; /* file handle, from the SMBcreateX pipe, earlier */
168 /* send the data on \PIPE\ */
169 if (cli_call_api("\\PIPE\\", 0, PTR_DIFF(p
, data
), 2, 1024,
175 LSA_R_QUERY_INFO r_q
;
180 DEBUG(5, ("cli_call_api: return OK\n"));
184 if (p
) p
= smb_io_rpc_hdr_rr (True
, &hdr
, p
, rdata
, 4, 0);
185 if (p
) p
= align_offset(p
, rdata
, 4); /* oh, what a surprise */
187 hdr_len
= PTR_DIFF(p
, rdata
);
189 if (p
&& hdr_len
!= hdr
.hdr
.frag_len
- hdr
.alloc_hint
)
191 /* header length not same as calculated header length */
192 DEBUG(2,("do_lsa_query_info: hdr_len %x != frag_len-alloc_hint %x\n",
193 hdr_len
, hdr
.hdr
.frag_len
- hdr
.alloc_hint
));
197 if (p
) p
= lsa_io_r_query(True
, &r_q
, p
, rdata
, 4, 0);
199 pkt_len
= PTR_DIFF(p
, rdata
);
201 if (p
&& pkt_len
!= hdr
.hdr
.frag_len
)
203 /* packet data size not same as reported fragment length */
204 DEBUG(2,("do_lsa_query_info: pkt_len %x != frag_len \n",
205 pkt_len
, hdr
.hdr
.frag_len
));
209 if (p
&& r_q
.status
!= 0)
211 /* report error code */
212 DEBUG(0,("LSA_QUERYINFOPOLICY: nt_status error %lx\n", r_q
.status
));
216 if (p
&& r_q
.info_class
!= q_q
.info_class
)
218 /* report different info classes */
219 DEBUG(0,("LSA_QUERYINFOPOLICY: error info_class (q,r) differ - (%x,%x)\n",
220 q_q
.info_class
, r_q
.info_class
));
226 /* ok, at last: we're happy. */
227 switch (r_q
.info_class
)
231 char *dom_name
= unistrn2(r_q
.dom
.id3
.uni_domain_name
.buffer
,
232 r_q
.dom
.id3
.uni_domain_name
.uni_str_len
);
233 char *dom_sid
= dom_sid_to_string(&(r_q
.dom
.id3
.dom_sid
));
234 fstrcpy(domain_name
, dom_name
);
235 pstrcpy(domain_sid
, dom_sid
);
237 valid_response
= True
;
242 char *dom_name
= unistrn2(r_q
.dom
.id5
.uni_domain_name
.buffer
,
243 r_q
.dom
.id5
.uni_domain_name
.uni_str_len
);
244 char *dom_sid
= dom_sid_to_string(&(r_q
.dom
.id5
.dom_sid
));
245 fstrcpy(domain_name
, dom_name
);
246 pstrcpy(domain_sid
, dom_sid
);
248 valid_response
= True
;
253 DEBUG(3,("LSA_QUERYINFOPOLICY: unknown info class\n"));
260 DEBUG(3,("LSA_QUERYINFOPOLICY (level %x): domain:%s domain sid:%s\n",
261 r_q
.info_class
, domain_name
, domain_sid
));
265 if (rparam
) free(rparam
);
266 if (rdata
) free(rdata
);
268 return valid_response
;
271 /****************************************************************************
273 ****************************************************************************/
274 BOOL
do_lsa_close(uint16 fnum
, uint32 call_id
,
281 pstring data
; /* only 1024 bytes */
282 uint16 setup
[2]; /* only need 2 uint16 setup parameters */
284 BOOL valid_close
= False
;
286 if (hnd
== NULL
) return False
;
288 /* create and send a MSRPC command with api LSA_OPENPOLICY */
290 DEBUG(4,("LSA Close\n"));
292 /* store the parameters */
293 make_q_close(&q_c
, hnd
);
295 /* turn parameters into data stream */
296 p
= lsa_io_q_close(False
, &q_c
, data
+ 0x18, data
, 4, 0);
298 /* create the request RPC_HDR_RR with no data */
299 create_rpc_request(call_id
, LSA_CLOSE
, data
, PTR_DIFF(p
, data
));
301 /* create setup parameters. */
302 setup
[0] = 0x0026; /* 0x26 indicates "transact named pipe" */
303 setup
[1] = fnum
; /* file handle, from the SMBcreateX pipe, earlier */
305 /* send the data on \PIPE\ */
306 if (cli_call_api("\\PIPE\\", 0, PTR_DIFF(p
, data
), 2, 1024,
317 DEBUG(5, ("cli_call_api: return OK\n"));
321 if (p
) p
= smb_io_rpc_hdr_rr (True
, &hdr
, p
, rdata
, 4, 0);
322 if (p
) p
= align_offset(p
, rdata
, 4); /* oh, what a surprise */
324 hdr_len
= PTR_DIFF(p
, rdata
);
326 if (p
&& hdr_len
!= hdr
.hdr
.frag_len
- hdr
.alloc_hint
)
328 /* header length not same as calculated header length */
329 DEBUG(2,("do_lsa_close: hdr_len %x != frag_len-alloc_hint %x\n",
330 hdr_len
, hdr
.hdr
.frag_len
- hdr
.alloc_hint
));
334 if (p
) p
= lsa_io_r_close(True
, &r_c
, p
, rdata
, 4, 0);
336 pkt_len
= PTR_DIFF(p
, rdata
);
338 if (p
&& pkt_len
!= hdr
.hdr
.frag_len
)
340 /* packet data size not same as reported fragment length */
341 DEBUG(2,("do_lsa_close: pkt_len %x != frag_len \n",
342 pkt_len
, hdr
.hdr
.frag_len
));
346 if (p
&& r_c
.status
!= 0)
348 /* report error code */
349 DEBUG(0,("LSA_OPENPOLICY: nt_status error %lx\n", r_c
.status
));
355 /* check that the returned policy handle is all zeros */
359 for (i
= 0; i
< sizeof(r_c
.pol
.data
); i
++)
361 if (r_c
.pol
.data
[i
] != 0)
369 DEBUG(0,("LSA_CLOSE: non-zero handle returned\n"));
374 if (rparam
) free(rparam
);
375 if (rdata
) free(rdata
);
380 #endif /* NTDOMAIN */