source: trunk/guitools/shared/rxrpclib.vrs@ 736

Last change on this file since 736 was 703, checked in by Herwig Bauernfeind, 13 years ago

GUI-Tools: Updates in EVFSGUI/SMBMON/Shared code

File size: 18.3 KB
Line 
1/* REXX Function Library for RPC calls */
2
3/* Currently implemented functions: */
4/* _rpcenumdomgroups(server,username,password) */
5/* _rpcenumdomusers(server,username,password) */
6/* _rpcenumprinters(server,username,password) */
7/* _rpcnetshareenum(server,username,password) */
8/* _rpcnetsharegetinfo(server,username,password,share) */
9/* _rpcquerygroupmem(server,username,password,grouprid) */
10/* _rpcqueryuser(server,username,password,userrid) */
11/* _rpcsrvinfo(server,username,password) */
12
13/*:VRX _rpcenumdomgroups
14*/
15_rpcenumdomgroups: procedure expose rpc. samba. options. debuglevel
16 IF options.!debug == 1 THEN SAY time()" _rpcenumdomgroups() started"
17 server = arg(1)
18 username = arg(2)
19 password = arg(3)
20
21 call VRSet VRWindow(), 'Pointer', 'Wait'
22 say ' 'samba.!rpcclientexe' 'server' --user='username'%'password' --command="enumdomgroups" 'debuglevel' '
23 address cmd samba.!rpcclientexe' 'server' --user='username'%'password' --command="enumdomgroups" 'debuglevel' >'samba.!msg
24 call VRSet VRWindow(), 'Pointer', '<default>'
25
26 rpc.enumdomgroups. = ""
27
28 Failure = 0
29
30 count = 0
31 SIGNAL ON SYNTAX NAME RPCERROR
32 do until lines(samba.!msg) = 0
33 rpcline = linein(samba.!msg)
34 if pos("creating default valid table",rpcline) <> 0 then iterate
35
36 if pos("LOGON_FAILURE", rpcline) > 0 then do
37 Failure = 1
38 leave
39 end
40 parse var rpcline 'group:['tuser'] rid:['trid']'
41
42 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
43 tvalue= strip(strip(tvalue,'L','09'x))
44 count = count + 1
45
46 dyn = 'rpc.enumdomgroups.'count'.GROUP = "'Tuser'"'
47 say " "dyn
48 interpret dyn
49
50 dyn = 'rpc.enumdomgroups.'count'.RID = "'Trid'"'
51 say " "dyn
52 interpret dyn
53
54 end
55 SIGNAL OFF SYNTAX
56 ok = stream(samba.!msg,'c','close')
57 ok = SysFileDelete(samba.!msg)
58 rpc.enumdomgroups.0 = count
59
60 if Failure = 0 then do
61 retval = 1
62 rpc.enumdomgroups.LOGONSTATUS="OK"
63 end
64 else do
65 retval = 0
66 rpc.enumdomgroups.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
67 end
68 IF options.!debug == 1 THEN SAY time()" _rpcenumdomgroups() done, "retval" "rpc.enumdomgroups.LOGONSTATUS
69return retval
70
71/*:VRX _rpcenumdomusers
72*/
73_rpcenumdomusers: procedure expose rpc. samba. options. debuglevel
74 IF options.!debug == 1 THEN SAY time()" _rpcenumdomusers() started"
75 server = arg(1)
76 username = arg(2)
77 password = arg(3)
78
79 call VRSet VRWindow(), 'Pointer', 'Wait'
80 say ' 'samba.!rpcclientexe' 'server' --user='username'%'password' --command="enumdomusers" 'debuglevel' '
81 address cmd samba.!rpcclientexe' 'server' --user='username'%'password' --command="enumdomusers" 'debuglevel' >'samba.!msg
82 call VRSet VRWindow(), 'Pointer', '<default>'
83
84 rpc.enumdomusers. = ""
85
86 Failure = 0
87
88 count = 0
89 SIGNAL ON SYNTAX NAME RPCERROR
90 do until lines(samba.!msg) = 0
91 rpcline = linein(samba.!msg)
92 if pos("creating default valid table",rpcline) <> 0 then iterate
93
94 if pos("LOGON_FAILURE", rpcline) > 0 then do
95 Failure = 1
96 leave
97 end
98 parse var rpcline 'user:['tuser'] rid:['trid']'
99
100 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
101 tvalue= strip(strip(tvalue,'L','09'x))
102 count = count + 1
103
104 dyn = 'rpc.enumdomusers.'count'.USER = "'Tuser'"'
105 say " "dyn
106 interpret dyn
107
108 dyn = 'rpc.enumdomusers.'count'.RID = "'Trid'"'
109 say " "dyn
110 interpret dyn
111
112 end
113 SIGNAL OFF SYNTAX
114 ok = stream(samba.!msg,'c','close')
115 ok = SysFileDelete(samba.!msg)
116 rpc.enumdomusers.0 = count
117
118 if Failure = 0 then do
119 retval = 1
120 rpc.enumdomusers.LOGONSTATUS="OK"
121 end
122 else do
123 retval = 0
124 rpc.enumdomusers.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
125 end
126 IF options.!debug == 1 THEN SAY time()" _rpcenumdomusers() done, "retval" "rpc.enumdomusers.LOGONSTATUS
127return retval
128
129/*:VRX _rpcenumprinters
130*/
131_rpcenumprinters: procedure expose rpc. samba. options. debuglevel
132 IF options.!debug == 1 THEN SAY time()" _rpcenumprinters() started"
133 server = arg(1)
134 username = arg(2)
135 password = arg(3)
136
137 usercred = '--user='username'%'password
138
139 call VRSet VRWindow(), 'Pointer', 'Wait'
140 say ' 'samba.!rpcclientexe' 'server' 'usercred' --command="enumprinters" 'debuglevel' '
141 address cmd samba.!rpcclientexe' 'server' 'usercred' --command="enumprinters" 'debuglevel' >'samba.!msg
142 call VRSet VRWindow(), 'Pointer', '<default>'
143
144 rpc.enumprinters. = ""
145
146 Failure = 0
147
148 count = 0
149 SIGNAL ON SYNTAX NAME RPCERROR
150 do until lines(samba.!msg) = 0
151 rpcline = linein(samba.!msg)
152 if pos("creating default valid table",rpcline) <> 0 then iterate
153
154 if pos("LOGON_FAILURE", rpcline) > 0 then do
155 Failure = 1
156 leave
157 end
158 parse var rpcline token ':[' tvalue']' .
159 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
160 if Token = "FLAGS" then count = count + 1
161 tvalue= strip(strip(tvalue,'L','09'x))
162 if pos('[',Token) = 0 & pos('TABLE',Token) = 0 & Token <> "" then do
163 dyn = 'rpc.enumprinters.'count'.'Token' = "'Tvalue'"'
164 say " "dyn
165 interpret dyn
166 end
167 end
168 SIGNAL OFF SYNTAX
169 ok = stream(samba.!msg,'c','close')
170 ok = SysFileDelete(samba.!msg)
171 rpc.enumprinters.0 = count
172
173 if Failure = 0 then do
174 retval = 1
175 rpc.enumprinters.LOGONSTATUS="OK"
176 end
177 else do
178 retval = 0
179 rpc.enumprinters.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
180 end
181 IF options.!debug == 1 THEN SAY time()" _rpcenumprinters() done, "retval" "rpc.enumprinters.LOGONSTATUS
182return retval
183/*:VRX _rpcnetshareenum
184*/
185_rpcnetshareenum: procedure expose rpc. samba. options. debuglevel
186 IF options.!debug == 1 THEN SAY time()" _rpcnetshareenum() started"
187 server = arg(1)
188 username = arg(2)
189 password = arg(3)
190
191 call VRSet VRWindow(), 'Pointer', 'Wait'
192 say ' 'samba.!rpcclientexe' 'server' --user='username'%'password' --command="netshareenum" 'debuglevel' '
193 address cmd samba.!rpcclientexe' 'server' --user='username'%'password' --command="netshareenum" 'debuglevel' >'samba.!msg
194 call VRSet VRWindow(), 'Pointer', '<default>'
195
196 rpc.netshareenum. = ""
197
198 Failure = 0
199
200 count = 0
201 SIGNAL ON SYNTAX NAME RPCERROR
202 do until lines(samba.!msg) = 0
203 rpcline = linein(samba.!msg)
204 if pos("creating default valid table",rpcline) <> 0 then iterate
205
206 if pos("LOGON_FAILURE", rpcline) > 0 then do
207 Failure = 1
208 leave
209 end
210 parse var rpcline token ':' tvalue
211 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
212 if Token = "NETNAME" then count = count + 1
213 tvalue= strip(strip(tvalue,'L','09'x))
214 if pos('[',Token) = 0 & pos('TABLE',Token) = 0 & Token <> "" then do
215 dyn = 'rpc.netshareenum.'count'.'Token' = "'Tvalue'"'
216 say " "dyn
217 interpret dyn
218 end
219 end
220 SIGNAL OFF SYNTAX
221 ok = stream(samba.!msg,'c','close')
222 ok = SysFileDelete(samba.!msg)
223 rpc.netshareenum.0 = count
224
225 if Failure = 0 then do
226 retval = 1
227 rpc.netshareenum.LOGONSTATUS="OK"
228 end
229 else do
230 retval = 0
231 rpc.netshareenum.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
232 end
233 IF options.!debug == 1 THEN SAY time()" _rpcnetshareenum() done, "retval" "rpc.netshareenum.LOGONSTATUS
234return retval
235
236/*:VRX _rpcnetsharegetinfo
237*/
238_rpcnetsharegetinfo: procedure expose rpc. samba. options. debuglevel
239 IF options.!debug == 1 THEN SAY time()" _rpcnetsharegetinfo() started"
240 server = arg(1)
241 username = arg(2)
242 password = arg(3)
243 share = arg(4)
244
245 call VRSet VRWindow(), 'Pointer', 'Wait'
246 say ' 'samba.!rpcclientexe' 'server' --user='username'%'password' --command="netsharegetinfo 'share'" 'debuglevel' '
247 address cmd samba.!rpcclientexe' 'server' --user='username'%'password' --command="netsharegetinfo 'share'" 'debuglevel' >'samba.!msg
248 call VRSet VRWindow(), 'Pointer', '<default>'
249
250 rpc.netsharegetinfo. = ""
251
252 Failure = 0
253 SIGNAL ON SYNTAX NAME RPCERROR
254 do until lines(samba.!msg) = 0
255 rpcline = linein(samba.!msg)
256 if pos("creating default valid table",rpcline) <> 0 then iterate
257
258 if pos("LOGON_FAILURE", rpcline) > 0 then do
259 Failure = 1
260 leave
261 end
262 parse var rpcline token ':' tvalue
263 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
264 tvalue= strip(strip(tvalue,'L','09'x))
265 if pos('ACL',Token) = 0 & pos('ACE',Token) = 0 & pos('---',Token) = 0 & Token <> "" then do
266
267 if Token = "TYPE" & left(Tvalue,2) = "0x" & length(Tvalue) = 3 then Token = "SHARETYPE"
268 if Token = "TYPE" & pos("SEC",Tvalue) > 1 then Token = "SECTYPE"
269
270 dyn = 'rpc.netsharegetinfo.'Token' = "'Tvalue'"'
271 say " "dyn
272 interpret dyn
273 end
274 end
275 SIGNAL OFF SYNTAX
276 ok = stream(samba.!msg,'c','close')
277 ok = SysFileDelete(samba.!msg)
278
279 if Failure = 0 then do
280 retval = '1'
281 rpc.netsharegetinfo.LOGONSTATUS="OK"
282 end
283 else do
284 retval = '0 '
285 rpc.netsharegetinfo.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
286 end
287 IF options.!debug == 1 THEN SAY time()" _rpcnetsharegetinfo() done, "retval" "rpc.netsharegetinfo.LOGONSTATUS
288return retval
289
290/*:VRX _rpcquerygroupmem
291*/
292_rpcquerygroupmem: procedure expose rpc. samba. options. debuglevel
293 IF options.!debug == 1 THEN SAY time()" _rpcquerygroupmem() started"
294 server = arg(1)
295 username = arg(2)
296 password = arg(3)
297 grouprid = arg(4)
298
299 say ' 'samba.!rpcclientexe' 'server' --user='username'%'password' --command="querygroupmem 'grouprid'" 'debuglevel' '
300 address cmd samba.!rpcclientexe' 'server' --user='username'%'password' --command="querygroupmem 'grouprid'" 'debuglevel' >'samba.!msg
301
302 rpc.querygroupmem. = ""
303
304 Failure = 0
305
306 count = 0
307 SIGNAL ON SYNTAX NAME RPCERROR
308 do until lines(samba.!msg) = 0
309 rpcline = linein(samba.!msg)
310 if pos("creating default valid table",rpcline) <> 0 then iterate
311
312 if pos("LOGON_FAILURE", rpcline) > 0 then do
313 Failure = 1
314 leave
315 end
316 parse var rpcline 'rid:['trid'] attr:['tattr']'
317
318 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
319 tvalue= strip(strip(tvalue,'L','09'x))
320 count = count + 1
321
322 dyn = 'rpc.querygroupmem.'count'.RID = "'Trid'"'
323 say " "dyn
324 interpret dyn
325
326 dyn = 'rpc.querygroupmem.'count'.ATTR = "'Tattr'"'
327 say " "dyn
328 interpret dyn
329
330 end
331 SIGNAL OFF SYNTAX
332 ok = stream(samba.!msg,'c','close')
333 ok = SysFileDelete(samba.!msg)
334 rpc.querygroupmem.0 = count
335
336 if Failure = 0 then do
337 retval = 1
338 rpc.querygroupmem.LOGONSTATUS="OK"
339 end
340 else do
341 retval = 0
342 rpc.querygroupmem.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
343 end
344 IF options.!debug == 1 THEN SAY time()" _rpcquerygroupmem() done, "retval" "rpc.querygroupmem.LOGONSTATUS
345return retval
346/*:VRX _rpcqueryuser
347*/
348_rpcqueryuser: procedure expose rpc. samba. options. debuglevel
349 IF options.!debug == 1 THEN SAY time()" _rpcqueryuser() started"
350 server = arg(1)
351 username = arg(2)
352 password = arg(3)
353 userrid = arg(4)
354
355 call VRSet VRWindow(), 'Pointer', 'Wait'
356 say ' 'samba.!rpcclientexe' 'server' --user='username'%'password' --command="queryuser 'userrid'" 'debuglevel' '
357 address cmd samba.!rpcclientexe' 'server' --user='username'%'password' --command="queryuser 'userrid'" 'debuglevel' >'samba.!msg
358 call VRSet VRWindow(), 'Pointer', '<default>'
359
360 rpc.queryuser. = ""
361
362 Failure = 0
363 SIGNAL ON SYNTAX NAME RPCERROR
364 do until lines(samba.!msg) = 0
365 rpcline = linein(samba.!msg)
366 if pos("creating default valid table",rpcline) <> 0 then iterate
367
368 if pos("NT_STATUS", rpcline) > 0 then do
369 Failure = 1
370 leave
371 end
372 if pos("TDB(", translate(rpcline)) > 0 then do
373 Failure = 1
374 /* provide a fake NT_STATUS */
375 rpcline = 'NT_STATUS_TDBERROR 'rpcline
376 leave
377 end
378
379 parse var rpcline token ':' tvalue
380 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
381 tvalue= strip(strip(tvalue,'L','09'x))
382 if pos('[',Token) = 0 & pos('TABLE',Token) = 0 & Token <> "" then do
383 dyn = 'rpc.queryuser.'Token' = "'Tvalue'"'
384 say " "dyn
385 interpret dyn
386 end
387 end
388 SIGNAL OFF SYNTAX
389 ok = stream(samba.!msg,'c','close')
390 ok = SysFileDelete(samba.!msg)
391
392 if Failure = 0 then do
393 retval = 1
394 rpc.queryuser.LOGONSTATUS="OK"
395 end
396 else do
397 retval = '0 '
398 rpc.queryuser.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
399 end
400 IF options.!debug == 1 THEN SAY time()" _rpcqueryuser() done, "retval" "rpc.queryuser.LOGONSTATUS
401return retval
402/*:VRX _rpcsrvinfo
403*/
404_rpcsrvinfo: procedure expose rpc. samba. options. debuglevel tempdir
405 IF options.!debug == 1 THEN SAY time()" _rpcsrvinfo() started"
406 server = arg(1)
407 username = arg(2)
408 password = arg(3)
409
410 /* Initialize temporary files */
411 rpcinfo.!msg = SysTempFileName(TempDir||"rpcinfo_msg.???")
412 rpcinfo.!err = SysTempFileName(TempDir||"rpcinfo_err.???")
413 ok = stream(rpcinfo.!msg,'c','close')
414 ok = stream(rpcinfo.!err,'c','close')
415 ok = SysFileDelete(rpcinfo.!msg)
416 ok = SysFileDelete(rpcinfo.!err)
417
418 usercred = '--user='username'%'password
419 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
420
421 call VRSet VRWindow(), 'Pointer', 'Wait'
422 say ' 'samba.!rpcclientexe' 'server' 'usercred' --command="srvinfo" 'debuglevel' 2>'rpcinfo.!err' 1>'rpcinfo.!msg
423 address cmd samba.!rpcclientexe' 'server' 'usercred' --command="srvinfo" 'debuglevel' 2>'rpcinfo.!err' 1>'rpcinfo.!msg
424 call VRSet VRWindow(), 'Pointer', '<default>'
425
426 rpc.srvinfo. = ""
427
428 Failure = 0
429 do while lines(rpcinfo.!err) > 0
430 rpcline = linein(rpcinfo.!err)
431 IF options.!debug == 1 THEN say " "rpcinfo.!err': "'rpcline'"'
432 if pos("UNSUCCESSFUL", translate(rpcline)) > 0 | pos("CANNOT CONNECT", translate(rpcline)) > 0 then do
433 ok = stream(rpcinfo.!msg,'c','close')
434 ok = stream(rpcinfo.!err,'c','close')
435 ok = SysFileDelete(rpcinfo.!msg)
436 ok = SysFileDelete(rpcinfo.!err)
437 Failure = 1
438 retval = 0
439 rpc.srvinfo. = ""
440 rpc.srvinfo.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
441 IF options.!debug == 1 THEN SAY time()" _rpcsrvinfo() aborted, "retval
442 return retval
443 end
444 end
445
446 SIGNAL ON SYNTAX NAME RPCERROR
447 do until lines(rpcinfo.!msg) = 0
448 rpcline = linein(rpcinfo.!msg)
449 if pos("creating default valid table",rpcline) <> 0 then iterate
450
451 if pos("LOGON_FAILURE", rpcline) > 0 then do
452 Failure = 1
453 leave
454 end
455 if pos(':',rpcline) <> 0 then do
456 parse var rpcline token ':' tvalue
457 token = translate(strip(strip(translate(token),'L','09'x)),'_',' ')
458 tvalue= strip(strip(tvalue,'L','09'x))
459 dyn = 'rpc.srvinfo.'Token' = "'Tvalue'"'
460 say " "dyn
461 interpret dyn
462 end
463 else do
464 parse var rpcline '09'x rpc.srvinfo.NETBIOSNAME' 'rpc.srvinfo.SERVERSTRING
465 rpc.srvinfo.SERVERSTRING = strip(rpc.srvinfo.SERVERSTRING)
466 say ' rpc.srvinfo.NETBIOSNAME = "'rpc.srvinfo.NETBIOSNAME'"'
467 say ' rpc.srvinfo.SERVERSTRING = "'rpc.srvinfo.SERVERSTRING'"'
468 rpc.srvinfo.CAPABILITIES = ""
469 do I = 1 to words(rpc.srvinfo.SERVERSTRING)
470 /* say "Word "I":"word(rpc.srvinfo.SERVERSTRING,I) */
471 if length(word(rpc.srvinfo.SERVERSTRING,I)) >=4 then leave
472 if length(word(rpc.srvinfo.SERVERSTRING,I)) = 2 | length(word(rpc.srvinfo.SERVERSTRING,I)) = 3 then do
473 rpc.srvinfo.CAPABILITIES = rpc.srvinfo.CAPABILITIES||word(rpc.srvinfo.SERVERSTRING,I)||' '
474 end
475 end
476 if rpc.srvinfo.CAPABILITIES <> "" then do
477 rpc.srvinfo.SERVERSTRING = strip(substr(rpc.srvinfo.SERVERSTRING,length(rpc.srvinfo.CAPABILITIES),))
478 rpc.srvinfo.CAPABILITIES = strip(rpc.srvinfo.CAPABILITIES)
479 end
480 say ' rpc.srvinfo.CAPABILITIES = "'rpc.srvinfo.CAPABILITIES'"'
481 say ' rpc.srvinfo.SERVERSTRING = "'rpc.srvinfo.SERVERSTRING'"'
482 end
483 end
484 SIGNAL OFF SYNTAX
485
486 ok = stream(rpcinfo.!msg,'c','close')
487 ok = stream(rpcinfo.!err,'c','close')
488 ok = SysFileDelete(rpcinfo.!msg)
489 ok = SysFileDelete(rpcinfo.!err)
490
491 if Failure = 0 then do
492 retval = 1
493 rpc.srvinfo.LOGONSTATUS="OK"
494 end
495 else do
496 retval = 0
497 rpc.srvinfo. = ""
498 rpc.srvinfo.LOGONSTATUS=substr(rpcline,pos("NT_STATUS",rpcline),)
499 end
500 say ' rpc.srvinfo.LOGONSTATUS = "'rpc.srvinfo.LOGONSTATUS'"'
501 IF options.!debug == 1 THEN SAY time()" _rpcsrvinfo() done, "retval
502return retval
503
504RPCERROR:
505 ok = stream(rpcinfo.!msg,'c','close')
506 ok = stream(rpcinfo.!err,'c','close')
507 ok = SysFileDelete(rpcinfo.!msg)
508 ok = SysFileDelete(rpcinfo.!err)
509
510 say " rpc parsing error in line "sigl": "strip(sourceline(sigl))
511 retval = -1
512 IF options.!debug == 1 THEN SAY time()" _rpclibrary aborted, "retval
513return retval
Note: See TracBrowser for help on using the repository browser.