2 Samba Unix/Linux SMB client library
3 More client RAP (SMB Remote Procedure Calls) functions
4 Copyright (C) 2001 Steve French (sfrench@us.ibm.com)
5 Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2007 Jeremy Allison. jra@samba.org
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 3 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, see <http://www.gnu.org/licenses/>.
22 /*****************************************************/
24 /* Additional RAP functionality */
26 /* RAP is the original SMB RPC, documented */
27 /* by Microsoft and X/Open in the 1990s and */
28 /* supported by most SMB/CIFS servers although */
29 /* it is unlikely that any one implementation */
30 /* supports all RAP command codes since some */
31 /* are quite obsolete and a few are specific */
32 /* to a particular network operating system */
34 /* Although it has largely been replaced */
35 /* for complex remote admistration and management */
36 /* (of servers) by the relatively newer */
37 /* DCE/RPC based remote API (which better handles */
38 /* large >64K data structures), there are many */
39 /* important administrative and resource location */
40 /* tasks and user tasks (e.g. password change) */
41 /* that are performed via RAP. */
43 /* Although a few of the RAP calls are implemented */
44 /* in the Samba client library already (clirap.c) */
45 /* the new ones are in clirap2.c for easy patching */
46 /* and integration and a corresponding header */
47 /* file, rap.h, has been created. */
49 /* This is based on data from the CIFS spec */
50 /* and the LAN Server and LAN Manager */
51 /* Programming Reference books and published */
52 /* RAP document and CIFS forum postings and */
53 /* lots of trial and error */
55 /* Function names changed from API_ (as they are */
56 /* in the CIFS specification) to RAP_ in order */
57 /* to avoid confusion with other API calls */
58 /* sent via DCE RPC */
60 /*****************************************************/
62 /*****************************************************/
64 /* cifsrap.c already includes support for: */
66 /* WshareEnum ( API number 0, level 1) */
67 /* NetServerEnum2 (API num 104, level 1) */
68 /* WWkstaUserLogon (132) */
69 /* SamOEMchgPasswordUser2_P (214) */
71 /* cifsprint.c already includes support for: */
73 /* WPrintJobEnum (API num 76, level 2) */
74 /* WPrintJobDel (API num 81) */
76 /*****************************************************/
83 #define PUTBYTE(p,b) do {SCVAL(p,0,b); p++;} while(0)
85 #define GETBYTE(p,b,endp) \
93 #define PUTWORD(p,w) do {SSVAL(p,0,w); p += WORDSIZE;} while(0)
95 #define GETWORD(p,w,endp) \
97 if (p+WORDSIZE < endp) {\
103 #define PUTDWORD(p,d) do {SIVAL(p,0,d); p += DWORDSIZE;} while(0)
105 #define GETDWORD(p,d,endp) \
107 if (p+DWORDSIZE < endp) {\
113 #define GETRES(p,endp) ((p && p+2 < endp) ? SVAL(p,0) : -1)
115 /* put string s at p with max len n and increment p past string */
116 #define PUTSTRING(p,s,n) \
118 push_ascii(p,s?s:"",n?n:256,STR_TERMINATE);\
119 p = push_skip_string(p);\
122 /* put string s and p, using fixed len l, and increment p by l */
123 #define PUTSTRINGF(p,s,l) \
125 push_ascii(p,s?s:"",l,STR_TERMINATE);\
129 /* put string pointer at p, supplying offset o from rdata r, store */
130 /* dword offset at p, increment p by 4 and o by length of s. This */
131 /* means on the first call, you must calc the offset yourself! */
133 #define PUTSTRINGP(p,s,r,o) \
136 push_ascii(r+o,s,strlen(s)+1,STR_TERMINATE);\
144 /* get asciiz string dest from src, return increment past string */
146 static size_t rap_getstring(TALLOC_CTX
*ctx
, char *src
, char **dest
, const char *endp
)
152 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++)
157 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
161 /* get fixed length l string dest from src, return increment for src */
163 static size_t rap_getstringf(char *src
, char *dest
, size_t l
, size_t dlen
, char *endp
)
171 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
181 pull_ascii(dest
,src
,len
,len
,STR_ASCII
);
186 /* get string dest from offset (obtained at p) from rdata r - converter c */
187 static size_t rap_getstringp(TALLOC_CTX
*ctx
, char *p
, char **dest
, char *r
, uint16_t c
, char *endp
)
195 GETDWORD(p
,off
,endp
);
196 off
&= 0x0000FFFF; /* mask the obsolete segment number from the offset */
199 if (r
+off
> endp
|| r
+off
< r
) {
205 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
212 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
216 static char *make_header(char *param
, uint16 apinum
, const char *reqfmt
, const char *datafmt
)
218 PUTWORD(param
,apinum
);
220 PUTSTRING(param
,reqfmt
,0);
225 PUTSTRING(param
,datafmt
,0);
232 /****************************************************************************
233 call a NetGroupDelete - delete user group from remote server
234 ****************************************************************************/
236 int cli_NetGroupDelete(struct cli_state
*cli
, const char *group_name
)
241 unsigned int rdrcnt
,rprcnt
;
243 char param
[WORDSIZE
/* api number */
244 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
245 +1 /* no ret string */
246 +RAP_GROUPNAME_LEN
/* group to del */
247 +WORDSIZE
]; /* reserved word */
249 /* now send a SMBtrans command with api GroupDel */
250 p
= make_header(param
, RAP_WGroupDel
, RAP_NetGroupDel_REQ
, NULL
);
251 PUTSTRING(p
, group_name
, RAP_GROUPNAME_LEN
);
252 PUTWORD(p
,0); /* reserved word MBZ on input */
255 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
256 NULL
, 0, 200, /* data, length, maxlen */
257 &rparam
, &rprcnt
, /* return params, length */
258 &rdata
, &rdrcnt
)) /* return data, length */
260 char *endp
= rparam
+ rprcnt
;
261 res
= GETRES(rparam
,endp
);
265 } else if ((res
== 5) || (res
== 65)) {
266 DEBUG(1, ("Access Denied\n"));
267 } else if (res
== 2220) {
268 DEBUG (1, ("Group does not exist\n"));
270 DEBUG(4,("NetGroupDelete res=%d\n", res
));
274 DEBUG(4,("NetGroupDelete failed\n"));
283 /****************************************************************************
284 call a NetGroupAdd - add user group to remote server
285 ****************************************************************************/
287 int cli_NetGroupAdd(struct cli_state
*cli
, RAP_GROUP_INFO_1
*grinfo
)
292 unsigned int rdrcnt
,rprcnt
;
294 char param
[WORDSIZE
/* api number */
295 +sizeof(RAP_NetGroupAdd_REQ
) /* req string */
296 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
297 +WORDSIZE
/* info level */
298 +WORDSIZE
]; /* reserved word */
300 /* offset into data of free format strings. Will be updated */
301 /* by PUTSTRINGP macro and end up with total data length. */
302 int soffset
= RAP_GROUPNAME_LEN
+ 1 + DWORDSIZE
;
307 data_size
= MAX(soffset
+ strlen(grinfo
->comment
) + 1, 1024);
309 data
= SMB_MALLOC_ARRAY(char, data_size
);
311 DEBUG (1, ("Malloc fail\n"));
315 /* now send a SMBtrans command with api WGroupAdd */
317 p
= make_header(param
, RAP_WGroupAdd
,
318 RAP_NetGroupAdd_REQ
, RAP_GROUP_INFO_L1
);
319 PUTWORD(p
, 1); /* info level */
320 PUTWORD(p
, 0); /* reserved word 0 */
323 PUTSTRINGF(p
, grinfo
->group_name
, RAP_GROUPNAME_LEN
);
324 PUTBYTE(p
, 0); /* pad byte 0 */
325 PUTSTRINGP(p
, grinfo
->comment
, data
, soffset
);
328 param
, sizeof(param
), 1024, /* Param, length, maxlen */
329 data
, soffset
, sizeof(data
), /* data, length, maxlen */
330 &rparam
, &rprcnt
, /* return params, length */
331 &rdata
, &rdrcnt
)) /* return data, length */
333 char *endp
= rparam
+ rprcnt
;
334 res
= GETRES(rparam
, endp
);
338 } else if ((res
== 5) || (res
== 65)) {
339 DEBUG(1, ("Access Denied\n"));
340 } else if (res
== 2223) {
341 DEBUG (1, ("Group already exists\n"));
343 DEBUG(4,("NetGroupAdd res=%d\n", res
));
347 DEBUG(4,("NetGroupAdd failed\n"));
357 /****************************************************************************
358 Call a NetGroupEnum - try and list user groups on a different host.
359 ****************************************************************************/
361 int cli_RNetGroupEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
363 char param
[WORDSIZE
/* api number */
364 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
365 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
366 +WORDSIZE
/* info level */
367 +WORDSIZE
]; /* buffer size */
371 unsigned int rprcnt
, rdrcnt
;
374 memset(param
, '\0', sizeof(param
));
375 p
= make_header(param
, RAP_WGroupEnum
,
376 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L1
);
377 PUTWORD(p
,1); /* Info level 1 */ /* add level 0 */
378 PUTWORD(p
,0xFFE0); /* Return buffer size */
381 param
, PTR_DIFF(p
,param
),8,
382 NULL
, 0, 0xFFE0 /* data area size */,
385 char *endp
= rparam
+ rdrcnt
;
387 res
= GETRES(rparam
, endp
);
388 cli
->rap_error
= res
;
389 if(cli
->rap_error
== 234) {
390 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
391 } else if (cli
->rap_error
!= 0) {
392 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
397 DEBUG(4,("NetGroupEnum no data returned\n"));
401 if (res
== 0 || res
== ERRmoredata
) {
402 char *endp
= rparam
+ rprcnt
;
403 int i
, converter
= 0, count
= 0;
404 TALLOC_CTX
*frame
= talloc_stackframe();
406 p
= rparam
+ WORDSIZE
; /* skip result */
407 GETWORD(p
, converter
, endp
);
408 GETWORD(p
, count
, endp
);
410 endp
= rdata
+ rdrcnt
;
411 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
412 char *comment
= NULL
;
413 char groupname
[RAP_GROUPNAME_LEN
];
415 p
+= rap_getstringf(p
,
421 p
+= rap_getstringp(frame
,
428 if (!comment
|| !groupname
[0]) {
432 fn(groupname
, comment
, cli
);
436 DEBUG(4,("NetGroupEnum res=%d\n", res
));
447 int cli_RNetGroupEnum0(struct cli_state
*cli
,
448 void (*fn
)(const char *, void *),
451 char param
[WORDSIZE
/* api number */
452 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
453 +sizeof(RAP_GROUP_INFO_L0
) /* return string */
454 +WORDSIZE
/* info level */
455 +WORDSIZE
]; /* buffer size */
459 unsigned int rprcnt
, rdrcnt
;
462 memset(param
, '\0', sizeof(param
));
463 p
= make_header(param
, RAP_WGroupEnum
,
464 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L0
);
465 PUTWORD(p
,0); /* Info level 0 */ /* Hmmm. I *very* much suspect this
466 is the resume count, at least
467 that's what smbd believes... */
468 PUTWORD(p
,0xFFE0); /* Return buffer size */
471 param
, PTR_DIFF(p
,param
),8,
472 NULL
, 0, 0xFFE0 /* data area size */,
475 char *endp
= rparam
+rprcnt
;
476 res
= GETRES(rparam
,endp
);
477 cli
->rap_error
= res
;
478 if(cli
->rap_error
== 234) {
479 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
480 } else if (cli
->rap_error
!= 0) {
481 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
486 DEBUG(4,("NetGroupEnum no data returned\n"));
490 if (res
== 0 || res
== ERRmoredata
) {
491 char *endp
= rparam
+ rprcnt
;
494 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
495 GETWORD(p
, count
, endp
);
497 endp
= rdata
+ rdrcnt
;
498 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
499 char groupname
[RAP_GROUPNAME_LEN
];
501 p
+= rap_getstringf(p
,
511 DEBUG(4,("NetGroupEnum res=%d\n", res
));
522 int cli_NetGroupDelUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
527 unsigned int rdrcnt
,rprcnt
;
529 char param
[WORDSIZE
/* api number */
530 +sizeof(RAP_NetGroupDelUser_REQ
) /* parm string */
531 +1 /* no ret string */
532 +RAP_GROUPNAME_LEN
/* group name */
533 +RAP_USERNAME_LEN
]; /* user to del */
535 /* now send a SMBtrans command with api GroupMemberAdd */
536 p
= make_header(param
, RAP_WGroupDelUser
, RAP_NetGroupDelUser_REQ
, NULL
);
537 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
538 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
541 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
542 NULL
, 0, 200, /* data, length, maxlen */
543 &rparam
, &rprcnt
, /* return params, length */
544 &rdata
, &rdrcnt
)) /* return data, length */
546 char *endp
= rparam
+ rprcnt
;
547 res
= GETRES(rparam
,endp
);
554 DEBUG(1, ("Access Denied\n"));
557 DEBUG(1, ("Not supported by server\n"));
560 DEBUG(1, ("Group does not exist\n"));
563 DEBUG(1, ("User does not exist\n"));
566 DEBUG(1, ("User is not in group\n"));
569 DEBUG(4,("NetGroupDelUser res=%d\n", res
));
573 DEBUG(4,("NetGroupDelUser failed\n"));
582 int cli_NetGroupAddUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
587 unsigned int rdrcnt
,rprcnt
;
589 char param
[WORDSIZE
/* api number */
590 +sizeof(RAP_NetGroupAddUser_REQ
) /* parm string */
591 +1 /* no ret string */
592 +RAP_GROUPNAME_LEN
/* group name */
593 +RAP_USERNAME_LEN
]; /* user to add */
595 /* now send a SMBtrans command with api GroupMemberAdd */
596 p
= make_header(param
, RAP_WGroupAddUser
, RAP_NetGroupAddUser_REQ
, NULL
);
597 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
598 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
601 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
602 NULL
, 0, 200, /* data, length, maxlen */
603 &rparam
, &rprcnt
, /* return params, length */
604 &rdata
, &rdrcnt
)) /* return data, length */
606 char *endp
= rparam
+ rprcnt
;
607 res
= GETRES(rparam
,endp
);
614 DEBUG(1, ("Access Denied\n"));
617 DEBUG(1, ("Not supported by server\n"));
620 DEBUG(1, ("Group does not exist\n"));
623 DEBUG(1, ("User does not exist\n"));
626 DEBUG(4,("NetGroupAddUser res=%d\n", res
));
630 DEBUG(4,("NetGroupAddUser failed\n"));
640 int cli_NetGroupGetUsers(struct cli_state
* cli
, const char *group_name
, void (*fn
)(const char *, void *), void *state
)
645 unsigned int rdrcnt
,rprcnt
;
647 char param
[WORDSIZE
/* api number */
648 +sizeof(RAP_NetGroupGetUsers_REQ
)/* parm string */
649 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
650 +RAP_GROUPNAME_LEN
/* group name */
651 +WORDSIZE
/* info level */
652 +WORDSIZE
]; /* buffer size */
654 /* now send a SMBtrans command with api GroupGetUsers */
655 p
= make_header(param
, RAP_WGroupGetUsers
,
656 RAP_NetGroupGetUsers_REQ
, RAP_GROUP_USERS_INFO_0
);
657 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
-1);
658 PUTWORD(p
,0); /* info level 0 */
659 PUTWORD(p
,0xFFE0); /* return buffer size */
662 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
663 NULL
, 0, CLI_BUFFER_SIZE
,
666 char *endp
= rparam
+ rprcnt
;
667 res
= GETRES(rparam
,endp
);
668 cli
->rap_error
= res
;
670 DEBUG(1,("NetGroupGetUsers gave error %d\n", res
));
675 DEBUG(4,("NetGroupGetUsers no data returned\n"));
679 if (res
== 0 || res
== ERRmoredata
) {
680 char *endp
= rparam
+ rprcnt
;
682 char username
[RAP_USERNAME_LEN
];
684 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
685 GETWORD(p
, count
, endp
);
687 endp
= rdata
+ rdrcnt
;
688 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
689 p
+= rap_getstringf(p
,
699 DEBUG(4,("NetGroupGetUsers res=%d\n", res
));
709 int cli_NetUserGetGroups(struct cli_state
* cli
, const char *user_name
, void (*fn
)(const char *, void *), void *state
)
714 unsigned int rdrcnt
,rprcnt
;
716 char param
[WORDSIZE
/* api number */
717 +sizeof(RAP_NetUserGetGroups_REQ
)/* parm string */
718 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
719 +RAP_USERNAME_LEN
/* user name */
720 +WORDSIZE
/* info level */
721 +WORDSIZE
]; /* buffer size */
723 /* now send a SMBtrans command with api GroupGetUsers */
724 p
= make_header(param
, RAP_WUserGetGroups
,
725 RAP_NetUserGetGroups_REQ
, RAP_GROUP_USERS_INFO_0
);
726 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
-1);
727 PUTWORD(p
,0); /* info level 0 */
728 PUTWORD(p
,0xFFE0); /* return buffer size */
731 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
732 NULL
, 0, CLI_BUFFER_SIZE
,
735 char *endp
= rparam
+ rprcnt
;
736 res
= GETRES(rparam
,endp
);
737 cli
->rap_error
= res
;
739 DEBUG(1,("NetUserGetGroups gave error %d\n", res
));
744 DEBUG(4,("NetUserGetGroups no data returned\n"));
748 if (res
== 0 || res
== ERRmoredata
) {
749 char *endp
= rparam
+ rprcnt
;
751 char groupname
[RAP_GROUPNAME_LEN
];
753 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
754 GETWORD(p
, count
, endp
);
756 endp
= rdata
+ rdrcnt
;
757 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
758 p
+= rap_getstringf(p
,
764 fn(groupname
, state
);
768 DEBUG(4,("NetUserGetGroups res=%d\n", res
));
778 /****************************************************************************
779 Call a NetUserDelete - delete user from remote server.
780 ****************************************************************************/
782 int cli_NetUserDelete(struct cli_state
*cli
, const char * user_name
)
787 unsigned int rdrcnt
,rprcnt
;
789 char param
[WORDSIZE
/* api number */
790 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
791 +1 /* no ret string */
792 +RAP_USERNAME_LEN
/* user to del */
793 +WORDSIZE
]; /* reserved word */
795 /* now send a SMBtrans command with api UserDel */
796 p
= make_header(param
, RAP_WUserDel
, RAP_NetGroupDel_REQ
, NULL
);
797 PUTSTRING(p
, user_name
, RAP_USERNAME_LEN
);
798 PUTWORD(p
,0); /* reserved word MBZ on input */
801 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
802 NULL
, 0, 200, /* data, length, maxlen */
803 &rparam
, &rprcnt
, /* return params, length */
804 &rdata
, &rdrcnt
)) /* return data, length */
806 char *endp
= rparam
+ rprcnt
;
807 res
= GETRES(rparam
,endp
);
811 } else if ((res
== 5) || (res
== 65)) {
812 DEBUG(1, ("Access Denied\n"));
813 } else if (res
== 2221) {
814 DEBUG (1, ("User does not exist\n"));
816 DEBUG(4,("NetUserDelete res=%d\n", res
));
820 DEBUG(4,("NetUserDelete failed\n"));
829 /****************************************************************************
830 Call a NetUserAdd - add user to remote server.
831 ****************************************************************************/
833 int cli_NetUserAdd(struct cli_state
*cli
, RAP_USER_INFO_1
* userinfo
)
838 unsigned int rdrcnt
,rprcnt
;
840 char param
[WORDSIZE
/* api number */
841 +sizeof(RAP_NetUserAdd2_REQ
) /* req string */
842 +sizeof(RAP_USER_INFO_L1
) /* data string */
843 +WORDSIZE
/* info level */
844 +WORDSIZE
/* buffer length */
845 +WORDSIZE
]; /* reserved */
848 /* offset into data of free format strings. Will be updated */
849 /* by PUTSTRINGP macro and end up with total data length. */
850 int soffset
=RAP_USERNAME_LEN
+1 /* user name + pad */
851 + RAP_UPASSWD_LEN
/* password */
852 + DWORDSIZE
/* password age */
853 + WORDSIZE
/* privilege */
854 + DWORDSIZE
/* home dir ptr */
855 + DWORDSIZE
/* comment ptr */
856 + WORDSIZE
/* flags */
857 + DWORDSIZE
; /* login script ptr*/
859 /* now send a SMBtrans command with api NetUserAdd */
860 p
= make_header(param
, RAP_WUserAdd2
,
861 RAP_NetUserAdd2_REQ
, RAP_USER_INFO_L1
);
863 PUTWORD(p
, 1); /* info level */
864 PUTWORD(p
, 0); /* pwencrypt */
865 if(userinfo
->passwrd
)
866 PUTWORD(p
,MIN(strlen(userinfo
->passwrd
), RAP_UPASSWD_LEN
));
868 PUTWORD(p
, 0); /* password length */
871 memset(data
, '\0', soffset
);
873 PUTSTRINGF(p
, userinfo
->user_name
, RAP_USERNAME_LEN
);
874 PUTBYTE(p
, 0); /* pad byte 0 */
875 PUTSTRINGF(p
, userinfo
->passwrd
, RAP_UPASSWD_LEN
);
876 PUTDWORD(p
, 0); /* pw age - n.a. on user add */
877 PUTWORD(p
, userinfo
->priv
);
878 PUTSTRINGP(p
, userinfo
->home_dir
, data
, soffset
);
879 PUTSTRINGP(p
, userinfo
->comment
, data
, soffset
);
880 PUTWORD(p
, userinfo
->userflags
);
881 PUTSTRINGP(p
, userinfo
->logon_script
, data
, soffset
);
884 param
, sizeof(param
), 1024, /* Param, length, maxlen */
885 data
, soffset
, sizeof(data
), /* data, length, maxlen */
886 &rparam
, &rprcnt
, /* return params, length */
887 &rdata
, &rdrcnt
)) /* return data, length */
889 char *endp
= rparam
+ rprcnt
;
890 res
= GETRES(rparam
, endp
);
894 } else if ((res
== 5) || (res
== 65)) {
895 DEBUG(1, ("Access Denied\n"));
896 } else if (res
== 2224) {
897 DEBUG (1, ("User already exists\n"));
899 DEBUG(4,("NetUserAdd res=%d\n", res
));
903 DEBUG(4,("NetUserAdd failed\n"));
912 /****************************************************************************
913 call a NetUserEnum - try and list users on a different host
914 ****************************************************************************/
916 int cli_RNetUserEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, const char *, const char *, void *), void *state
)
918 char param
[WORDSIZE
/* api number */
919 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
920 +sizeof(RAP_USER_INFO_L1
) /* return string */
921 +WORDSIZE
/* info level */
922 +WORDSIZE
]; /* buffer size */
926 unsigned int rprcnt
, rdrcnt
;
929 memset(param
, '\0', sizeof(param
));
930 p
= make_header(param
, RAP_WUserEnum
,
931 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L1
);
932 PUTWORD(p
,1); /* Info level 1 */
933 PUTWORD(p
,0xFF00); /* Return buffer size */
935 /* BB Fix handling of large numbers of users to be returned */
937 param
, PTR_DIFF(p
,param
),8,
938 NULL
, 0, CLI_BUFFER_SIZE
,
941 char *endp
= rparam
+ rprcnt
;
942 res
= GETRES(rparam
,endp
);
943 cli
->rap_error
= res
;
944 if (cli
->rap_error
!= 0) {
945 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
950 DEBUG(4,("NetUserEnum no data returned\n"));
954 if (res
== 0 || res
== ERRmoredata
) {
955 int i
, converter
= 0, count
= 0;
956 char username
[RAP_USERNAME_LEN
];
957 char userpw
[RAP_UPASSWD_LEN
];
958 char *endp
= rparam
+ rprcnt
;
959 char *comment
, *homedir
, *logonscript
;
960 TALLOC_CTX
*frame
= talloc_stackframe();
962 p
= rparam
+ WORDSIZE
; /* skip result */
963 GETWORD(p
, converter
, endp
);
964 GETWORD(p
, count
, endp
);
966 endp
= rdata
+ rdrcnt
;
967 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
968 p
+= rap_getstringf(p
,
974 p
+= rap_getstringf(p
,
979 p
+= DWORDSIZE
; /* skip password age */
980 p
+= WORDSIZE
; /* skip priv: 0=guest, 1=user, 2=admin */
981 p
+= rap_getstringp(frame
,
987 p
+= rap_getstringp(frame
,
993 p
+= WORDSIZE
; /* skip flags */
994 p
+= rap_getstringp(frame
,
1000 if (username
[0] && comment
&&
1001 homedir
&& logonscript
) {
1011 DEBUG(4,("NetUserEnum res=%d\n", res
));
1022 int cli_RNetUserEnum0(struct cli_state
*cli
,
1023 void (*fn
)(const char *, void *),
1026 char param
[WORDSIZE
/* api number */
1027 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
1028 +sizeof(RAP_USER_INFO_L0
) /* return string */
1029 +WORDSIZE
/* info level */
1030 +WORDSIZE
]; /* buffer size */
1032 char *rparam
= NULL
;
1034 unsigned int rprcnt
, rdrcnt
;
1037 memset(param
, '\0', sizeof(param
));
1038 p
= make_header(param
, RAP_WUserEnum
,
1039 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L0
);
1040 PUTWORD(p
,0); /* Info level 1 */
1041 PUTWORD(p
,0xFF00); /* Return buffer size */
1043 /* BB Fix handling of large numbers of users to be returned */
1045 param
, PTR_DIFF(p
,param
),8,
1046 NULL
, 0, CLI_BUFFER_SIZE
,
1049 char *endp
= rparam
+ rprcnt
;
1050 res
= GETRES(rparam
,endp
);
1051 cli
->rap_error
= res
;
1052 if (cli
->rap_error
!= 0) {
1053 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
1058 DEBUG(4,("NetUserEnum no data returned\n"));
1062 if (res
== 0 || res
== ERRmoredata
) {
1064 char *endp
= rparam
+ rprcnt
;
1065 char username
[RAP_USERNAME_LEN
];
1067 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1068 GETWORD(p
, count
, endp
);
1070 endp
= rdata
+ rdrcnt
;
1071 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
1072 p
+= rap_getstringf(p
,
1082 DEBUG(4,("NetUserEnum res=%d\n", res
));
1093 /****************************************************************************
1094 Call a NetFileClose2 - close open file on another session to server.
1095 ****************************************************************************/
1097 int cli_NetFileClose(struct cli_state
*cli
, uint32 file_id
)
1099 char *rparam
= NULL
;
1102 unsigned int rdrcnt
,rprcnt
;
1103 char param
[WORDSIZE
/* api number */
1104 +sizeof(RAP_WFileClose2_REQ
) /* req string */
1105 +1 /* no ret string */
1106 +DWORDSIZE
]; /* file ID */
1109 /* now send a SMBtrans command with api RNetShareEnum */
1110 p
= make_header(param
, RAP_WFileClose2
, RAP_WFileClose2_REQ
, NULL
);
1111 PUTDWORD(p
, file_id
);
1114 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1115 NULL
, 0, 200, /* data, length, maxlen */
1116 &rparam
, &rprcnt
, /* return params, length */
1117 &rdata
, &rdrcnt
)) /* return data, length */
1119 char *endp
= rparam
+ rprcnt
;
1120 res
= GETRES(rparam
, endp
);
1124 } else if (res
== 2314){
1125 DEBUG(1, ("NetFileClose2 - attempt to close non-existant file open instance\n"));
1127 DEBUG(4,("NetFileClose2 res=%d\n", res
));
1131 DEBUG(4,("NetFileClose2 failed\n"));
1140 /****************************************************************************
1141 Call a NetFileGetInfo - get information about server file opened from other
1143 ****************************************************************************/
1145 int cli_NetFileGetInfo(struct cli_state
*cli
, uint32 file_id
, void (*fn
)(const char *, const char *, uint16
, uint16
, uint32
))
1147 char *rparam
= NULL
;
1150 unsigned int rdrcnt
,rprcnt
;
1152 char param
[WORDSIZE
/* api number */
1153 +sizeof(RAP_WFileGetInfo2_REQ
) /* req string */
1154 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1155 +DWORDSIZE
/* file ID */
1156 +WORDSIZE
/* info level */
1157 +WORDSIZE
]; /* buffer size */
1159 /* now send a SMBtrans command with api RNetShareEnum */
1160 p
= make_header(param
, RAP_WFileGetInfo2
,
1161 RAP_WFileGetInfo2_REQ
, RAP_FILE_INFO_L3
);
1162 PUTDWORD(p
, file_id
);
1163 PUTWORD(p
, 3); /* info level */
1164 PUTWORD(p
, 0x1000); /* buffer size */
1166 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1167 NULL
, 0, 0x1000, /* data, length, maxlen */
1168 &rparam
, &rprcnt
, /* return params, length */
1169 &rdata
, &rdrcnt
)) /* return data, length */
1171 char *endp
= rparam
+ rprcnt
;
1172 res
= GETRES(rparam
,endp
);
1173 if (res
== 0 || res
== ERRmoredata
) {
1174 TALLOC_CTX
*frame
= talloc_stackframe();
1175 int converter
= 0,id
= 0, perms
= 0, locks
= 0;
1176 char *fpath
, *fuser
;
1178 p
= rparam
+ WORDSIZE
; /* skip result */
1179 GETWORD(p
, converter
, endp
);
1182 endp
= rdata
+ rdrcnt
;
1184 GETDWORD(p
, id
, endp
);
1185 GETWORD(p
, perms
, endp
);
1186 GETWORD(p
, locks
, endp
);
1188 p
+= rap_getstringp(frame
,
1194 p
+= rap_getstringp(frame
,
1201 if (fpath
&& fuser
) {
1202 fn(fpath
, fuser
, perms
, locks
, id
);
1207 DEBUG(4,("NetFileGetInfo2 res=%d\n", res
));
1211 DEBUG(4,("NetFileGetInfo2 failed\n"));
1220 /****************************************************************************
1221 * Call a NetFileEnum2 - list open files on an SMB server
1223 * PURPOSE: Remotes a NetFileEnum API call to the current server or target
1224 * server listing the files open via the network (and their
1225 * corresponding open instance ids)
1227 * Dependencies: none
1230 * cli - pointer to cli_state structure
1231 * user - if present, return only files opened by this remote user
1232 * base_path - if present, return only files opened below this
1234 * fn - display function to invoke for each entry in the result
1241 ****************************************************************************/
1243 int cli_NetFileEnum(struct cli_state
*cli
, const char * user
,
1244 const char * base_path
,
1245 void (*fn
)(const char *, const char *, uint16
, uint16
,
1248 char *rparam
= NULL
;
1251 unsigned int rdrcnt
,rprcnt
;
1252 char param
[WORDSIZE
/* api number */
1253 +sizeof(RAP_WFileEnum2_REQ
) /* req string */
1254 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1255 +1024 /* base path (opt) */
1256 +RAP_USERNAME_LEN
/* user name (opt) */
1257 +WORDSIZE
/* info level */
1258 +WORDSIZE
/* buffer size */
1259 +DWORDSIZE
/* resume key ? */
1260 +DWORDSIZE
]; /* resume key ? */
1264 /* now send a SMBtrans command with api RNetShareEnum */
1265 p
= make_header(param
, RAP_WFileEnum2
,
1266 RAP_WFileEnum2_REQ
, RAP_FILE_INFO_L3
);
1268 PUTSTRING(p
, base_path
, 1024);
1269 PUTSTRING(p
, user
, RAP_USERNAME_LEN
);
1270 PUTWORD(p
, 3); /* info level */
1271 PUTWORD(p
, 0xFF00); /* buffer size */
1272 PUTDWORD(p
, 0); /* zero out the resume key */
1273 PUTDWORD(p
, 0); /* or is this one the resume key? */
1276 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1277 NULL
, 0, 0xFF00, /* data, length, maxlen */
1278 &rparam
, &rprcnt
, /* return params, length */
1279 &rdata
, &rdrcnt
)) /* return data, length */
1281 char *endp
= rparam
+ rprcnt
;
1282 res
= GETRES(rparam
, endp
);
1284 if (res
== 0 || res
== ERRmoredata
) {
1285 TALLOC_CTX
*frame
= talloc_stackframe();
1286 int converter
= 0, i
;
1288 p
= rparam
+ WORDSIZE
; /* skip result */
1289 GETWORD(p
, converter
, endp
);
1290 GETWORD(p
, count
, endp
);
1293 endp
= rdata
+ rdrcnt
;
1294 for (i
=0; i
<count
&& p
< endp
; i
++) {
1295 int id
= 0, perms
= 0, locks
= 0;
1296 char *fpath
, *fuser
;
1298 GETDWORD(p
, id
, endp
);
1299 GETWORD(p
, perms
, endp
);
1300 GETWORD(p
, locks
, endp
);
1301 p
+= rap_getstringp(frame
,
1307 p
+= rap_getstringp(frame
,
1314 if (fpath
&& fuser
) {
1315 fn(fpath
, fuser
, perms
, locks
, id
);
1317 } /* BB fix ERRmoredata case to send resume request */
1320 DEBUG(4,("NetFileEnum2 res=%d\n", res
));
1323 DEBUG(4,("NetFileEnum2 failed\n"));
1332 /****************************************************************************
1333 Call a NetShareAdd - share/export directory on remote server.
1334 ****************************************************************************/
1336 int cli_NetShareAdd(struct cli_state
*cli
, RAP_SHARE_INFO_2
* sinfo
)
1338 char *rparam
= NULL
;
1341 unsigned int rdrcnt
,rprcnt
;
1343 char param
[WORDSIZE
/* api number */
1344 +sizeof(RAP_WShareAdd_REQ
) /* req string */
1345 +sizeof(RAP_SHARE_INFO_L2
) /* return string */
1346 +WORDSIZE
/* info level */
1347 +WORDSIZE
]; /* reserved word */
1349 /* offset to free format string section following fixed length data. */
1350 /* will be updated by PUTSTRINGP macro and will end up with total len */
1351 int soffset
= RAP_SHARENAME_LEN
+ 1 /* share name + pad */
1352 + WORDSIZE
/* share type */
1353 + DWORDSIZE
/* comment pointer */
1354 + WORDSIZE
/* permissions */
1355 + WORDSIZE
/* max users */
1356 + WORDSIZE
/* active users */
1357 + DWORDSIZE
/* share path */
1358 + RAP_SPASSWD_LEN
+ 1; /* share password + pad */
1360 memset(param
,'\0',sizeof(param
));
1361 /* now send a SMBtrans command with api RNetShareAdd */
1362 p
= make_header(param
, RAP_WshareAdd
,
1363 RAP_WShareAdd_REQ
, RAP_SHARE_INFO_L2
);
1364 PUTWORD(p
, 2); /* info level */
1365 PUTWORD(p
, 0); /* reserved word 0 */
1368 PUTSTRINGF(p
, sinfo
->share_name
, RAP_SHARENAME_LEN
);
1369 PUTBYTE(p
, 0); /* pad byte 0 */
1371 PUTWORD(p
, sinfo
->share_type
);
1372 PUTSTRINGP(p
, sinfo
->comment
, data
, soffset
);
1373 PUTWORD(p
, sinfo
->perms
);
1374 PUTWORD(p
, sinfo
->maximum_users
);
1375 PUTWORD(p
, sinfo
->active_users
);
1376 PUTSTRINGP(p
, sinfo
->path
, data
, soffset
);
1377 PUTSTRINGF(p
, sinfo
->password
, RAP_SPASSWD_LEN
);
1378 SCVAL(p
,-1,0x0A); /* required 0x0A at end of password */
1381 param
, sizeof(param
), 1024, /* Param, length, maxlen */
1382 data
, soffset
, sizeof(data
), /* data, length, maxlen */
1383 &rparam
, &rprcnt
, /* return params, length */
1384 &rdata
, &rdrcnt
)) /* return data, length */
1386 char *endp
= rparam
+ rprcnt
;
1387 res
= GETRES(rparam
, endp
);
1392 DEBUG(4,("NetShareAdd res=%d\n", res
));
1395 DEBUG(4,("NetShareAdd failed\n"));
1404 /****************************************************************************
1405 Call a NetShareDelete - unshare exported directory on remote server.
1406 ****************************************************************************/
1408 int cli_NetShareDelete(struct cli_state
*cli
, const char * share_name
)
1410 char *rparam
= NULL
;
1413 unsigned int rdrcnt
,rprcnt
;
1415 char param
[WORDSIZE
/* api number */
1416 +sizeof(RAP_WShareDel_REQ
) /* req string */
1417 +1 /* no ret string */
1418 +RAP_SHARENAME_LEN
/* share to del */
1419 +WORDSIZE
]; /* reserved word */
1421 /* now send a SMBtrans command with api RNetShareDelete */
1422 p
= make_header(param
, RAP_WshareDel
, RAP_WShareDel_REQ
, NULL
);
1423 PUTSTRING(p
,share_name
,RAP_SHARENAME_LEN
);
1424 PUTWORD(p
,0); /* reserved word MBZ on input */
1427 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1428 NULL
, 0, 200, /* data, length, maxlen */
1429 &rparam
, &rprcnt
, /* return params, length */
1430 &rdata
, &rdrcnt
)) /* return data, length */
1432 char *endp
= rparam
+ rprcnt
;
1433 res
= GETRES(rparam
, endp
);
1438 DEBUG(4,("NetShareDelete res=%d\n", res
));
1441 DEBUG(4,("NetShareDelete failed\n"));
1450 /*************************************************************************
1452 * Function Name: cli_get_pdc_name
1454 * PURPOSE: Remotes a NetServerEnum API call to the current server
1455 * requesting the name of a server matching the server
1456 * type of SV_TYPE_DOMAIN_CTRL (PDC).
1458 * Dependencies: none
1461 * cli - pointer to cli_state structure
1462 * workgroup - pointer to string containing name of domain
1463 * pdc_name - pointer to string that will contain PDC name
1464 * on successful return
1470 ************************************************************************/
1472 bool cli_get_pdc_name(struct cli_state
*cli
, const char *workgroup
, char **pdc_name
)
1474 char *rparam
= NULL
;
1476 unsigned int rdrcnt
,rprcnt
;
1478 char param
[WORDSIZE
/* api number */
1479 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1480 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1481 +WORDSIZE
/* info level */
1482 +WORDSIZE
/* buffer size */
1483 +DWORDSIZE
/* server type */
1484 +RAP_MACHNAME_LEN
]; /* workgroup */
1490 /* send a SMBtrans command with api NetServerEnum */
1491 p
= make_header(param
, RAP_NetServerEnum2
,
1492 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L1
);
1493 PUTWORD(p
, 1); /* info level */
1494 PUTWORD(p
, CLI_BUFFER_SIZE
);
1495 PUTDWORD(p
, SV_TYPE_DOMAIN_CTRL
);
1496 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1499 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1500 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1501 &rparam
, &rprcnt
, /* return params, return size */
1502 &rdata
, &rdrcnt
/* return data, return size */
1505 char *endp
= rparam
+ rprcnt
;
1506 res
= GETRES(rparam
, endp
);
1507 cli
->rap_error
= res
;
1510 * We only really care to copy a name if the
1511 * API succeeded and we got back a name.
1513 if (cli
->rap_error
== 0) {
1514 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1515 GETWORD(p
, count
, endp
);
1517 endp
= rdata
+ rdrcnt
;
1520 TALLOC_CTX
*frame
= talloc_stackframe();
1522 p
+= rap_getstring(frame
,
1527 *pdc_name
= SMB_STRDUP(dcname
);
1532 DEBUG(4,("cli_get_pdc_name: machine %s failed the NetServerEnum call. "
1533 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1543 /*************************************************************************
1545 * Function Name: cli_get_server_domain
1547 * PURPOSE: Remotes a NetWkstaGetInfo API call to the current server
1548 * requesting wksta_info_10 level information to determine
1549 * the domain the server belongs to. On success, this
1550 * routine sets the server_domain field in the cli_state structure
1551 * to the server's domain name.
1553 * Dependencies: none
1556 * cli - pointer to cli_state structure
1562 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1564 ************************************************************************/
1566 bool cli_get_server_domain(struct cli_state
*cli
)
1568 char *rparam
= NULL
;
1570 unsigned int rdrcnt
,rprcnt
;
1572 char param
[WORDSIZE
/* api number */
1573 +sizeof(RAP_WWkstaGetInfo_REQ
) /* req string */
1574 +sizeof(RAP_WKSTA_INFO_L10
) /* return string */
1575 +WORDSIZE
/* info level */
1576 +WORDSIZE
]; /* buffer size */
1579 /* send a SMBtrans command with api NetWkstaGetInfo */
1580 p
= make_header(param
, RAP_WWkstaGetInfo
,
1581 RAP_WWkstaGetInfo_REQ
, RAP_WKSTA_INFO_L10
);
1582 PUTWORD(p
, 10); /* info level */
1583 PUTWORD(p
, CLI_BUFFER_SIZE
);
1585 if (cli_api(cli
, param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1586 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1587 &rparam
, &rprcnt
, /* return params, return size */
1588 &rdata
, &rdrcnt
)) { /* return data, return size */
1589 char *endp
= rparam
+ rprcnt
;
1590 res
= GETRES(rparam
, endp
);
1593 TALLOC_CTX
*frame
= talloc_stackframe();
1594 char *server_domain
;
1597 p
= rparam
+ WORDSIZE
;
1598 GETWORD(p
, converter
, endp
);
1600 p
= rdata
+ DWORDSIZE
+ DWORDSIZE
; /* skip computer & user names */
1601 endp
= rdata
+ rdrcnt
;
1602 p
+= rap_getstringp(frame
,
1609 if (server_domain
) {
1610 fstrcpy(cli
->server_domain
, server_domain
);
1622 /*************************************************************************
1624 * Function Name: cli_get_server_type
1626 * PURPOSE: Remotes a NetServerGetInfo API call to the current server
1627 * requesting server_info_1 level information to retrieve
1630 * Dependencies: none
1633 * cli - pointer to cli_state structure
1634 * pstype - pointer to uint32 to contain returned server type
1640 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1642 ************************************************************************/
1644 bool cli_get_server_type(struct cli_state
*cli
, uint32
*pstype
)
1646 char *rparam
= NULL
;
1648 unsigned int rdrcnt
,rprcnt
;
1650 char param
[WORDSIZE
/* api number */
1651 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1652 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1653 +WORDSIZE
/* info level */
1654 +WORDSIZE
]; /* buffer size */
1657 /* send a SMBtrans command with api NetServerGetInfo */
1658 p
= make_header(param
, RAP_WserverGetInfo
,
1659 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1660 PUTWORD(p
, 1); /* info level */
1661 PUTWORD(p
, CLI_BUFFER_SIZE
);
1664 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1665 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1666 &rparam
, &rprcnt
, /* return params, return size */
1667 &rdata
, &rdrcnt
/* return data, return size */
1669 char *endp
= rparam
+ rprcnt
;
1670 res
= GETRES(rparam
,endp
);
1672 if (res
== 0 || res
== ERRmoredata
) {
1674 endp
= rparam
+ rprcnt
;
1676 GETDWORD(p
,*pstype
,endp
);
1677 *pstype
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1684 return(res
== 0 || res
== ERRmoredata
);
1687 bool cli_get_server_name(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
1690 char *rparam
= NULL
;
1692 unsigned int rdrcnt
,rprcnt
;
1694 char param
[WORDSIZE
/* api number */
1695 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1696 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1697 +WORDSIZE
/* info level */
1698 +WORDSIZE
]; /* buffer size */
1703 /* send a SMBtrans command with api NetServerGetInfo */
1704 p
= make_header(param
, RAP_WserverGetInfo
,
1705 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1706 PUTWORD(p
, 1); /* info level */
1707 PUTWORD(p
, CLI_BUFFER_SIZE
);
1710 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1711 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1712 &rparam
, &rprcnt
, /* return params, return size */
1713 &rdata
, &rdrcnt
/* return data, return size */
1718 endp
= rparam
+ rprcnt
;
1719 if (GETRES(rparam
, endp
) != 0) {
1724 DEBUG(10, ("invalid data count %d, expected >= 16\n", rdrcnt
));
1728 if (pull_ascii(tmp
, rdata
, sizeof(tmp
)-1, 16, STR_TERMINATE
) == -1) {
1729 DEBUG(10, ("pull_ascii failed\n"));
1733 if (!(*servername
= talloc_strdup(mem_ctx
, tmp
))) {
1734 DEBUG(1, ("talloc_strdup failed\n"));
1746 /*************************************************************************
1748 * Function Name: cli_ns_check_server_type
1750 * PURPOSE: Remotes a NetServerEnum2 API call to the current server
1751 * requesting server_info_0 level information of machines
1752 * matching the given server type. If the returned server
1753 * list contains the machine name contained in cli->desthost
1754 * then we conclude the server type checks out. This routine
1755 * is useful to retrieve list of server's of a certain
1756 * type when all you have is a null session connection and
1757 * can't remote API calls such as NetWkstaGetInfo or
1760 * Dependencies: none
1763 * cli - pointer to cli_state structure
1764 * workgroup - pointer to string containing domain
1765 * stype - server type
1771 ************************************************************************/
1773 bool cli_ns_check_server_type(struct cli_state
*cli
, char *workgroup
, uint32 stype
)
1775 char *rparam
= NULL
;
1777 unsigned int rdrcnt
,rprcnt
;
1779 char param
[WORDSIZE
/* api number */
1780 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1781 +sizeof(RAP_SERVER_INFO_L0
) /* return string */
1782 +WORDSIZE
/* info level */
1783 +WORDSIZE
/* buffer size */
1784 +DWORDSIZE
/* server type */
1785 +RAP_MACHNAME_LEN
]; /* workgroup */
1786 bool found_server
= false;
1789 /* send a SMBtrans command with api NetServerEnum */
1790 p
= make_header(param
, RAP_NetServerEnum2
,
1791 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L0
);
1792 PUTWORD(p
, 0); /* info level 0 */
1793 PUTWORD(p
, CLI_BUFFER_SIZE
);
1795 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1798 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1799 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1800 &rparam
, &rprcnt
, /* return params, return size */
1801 &rdata
, &rdrcnt
/* return data, return size */
1803 char *endp
= rparam
+ rprcnt
;
1804 res
= GETRES(rparam
,endp
);
1805 cli
->rap_error
= res
;
1807 if (res
== 0 || res
== ERRmoredata
) {
1810 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
1811 GETWORD(p
, count
,endp
);
1814 endp
= rdata
+ rdrcnt
;
1815 for (i
= 0;i
< count
&& p
< endp
;i
++, p
+= 16) {
1816 char ret_server
[RAP_MACHNAME_LEN
];
1818 p
+= rap_getstringf(p
,
1823 if (strequal(ret_server
, cli
->desthost
)) {
1824 found_server
= true;
1829 DEBUG(4,("cli_ns_check_server_type: machine %s failed the NetServerEnum call. "
1830 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1837 return found_server
;
1840 /****************************************************************************
1841 Perform a NetWkstaUserLogoff.
1842 ****************************************************************************/
1844 bool cli_NetWkstaUserLogoff(struct cli_state
*cli
, const char *user
, const char *workstation
)
1846 char *rparam
= NULL
;
1849 unsigned int rdrcnt
,rprcnt
;
1850 char param
[WORDSIZE
/* api number */
1851 +sizeof(RAP_NetWkstaUserLogoff_REQ
) /* req string */
1852 +sizeof(RAP_USER_LOGOFF_INFO_L1
) /* return string */
1853 +RAP_USERNAME_LEN
+1 /* user name+pad */
1854 +RAP_MACHNAME_LEN
/* wksta name */
1855 +WORDSIZE
/* buffer size */
1856 +WORDSIZE
]; /* buffer size? */
1857 char upperbuf
[MAX(RAP_USERNAME_LEN
,RAP_MACHNAME_LEN
)];
1860 memset(param
, 0, sizeof(param
));
1862 /* send a SMBtrans command with api NetWkstaUserLogoff */
1863 p
= make_header(param
, RAP_WWkstaUserLogoff
,
1864 RAP_NetWkstaUserLogoff_REQ
, RAP_USER_LOGOFF_INFO_L1
);
1865 PUTDWORD(p
, 0); /* Null pointer */
1866 PUTDWORD(p
, 0); /* Null pointer */
1867 strlcpy(upperbuf
, user
, sizeof(upperbuf
));
1868 strupper_m(upperbuf
);
1869 PUTSTRINGF(p
, upperbuf
, RAP_USERNAME_LEN
);
1870 p
++; /* strange format, but ok */
1871 strlcpy(upperbuf
, workstation
, sizeof(upperbuf
));
1872 strupper_m(upperbuf
);
1873 PUTSTRINGF(p
, upperbuf
, RAP_MACHNAME_LEN
);
1874 PUTWORD(p
, CLI_BUFFER_SIZE
);
1875 PUTWORD(p
, CLI_BUFFER_SIZE
);
1878 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
1879 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1880 &rparam
, &rprcnt
, /* return params, return size */
1881 &rdata
, &rdrcnt
/* return data, return size */
1883 char *endp
= rparam
+ rprcnt
;
1884 res
= GETRES(rparam
,endp
);
1885 cli
->rap_error
= res
;
1887 if (cli
->rap_error
!= 0) {
1888 DEBUG(4,("NetwkstaUserLogoff gave error %d\n", cli
->rap_error
));
1894 return (cli
->rap_error
== 0);
1897 int cli_NetPrintQEnum(struct cli_state
*cli
,
1898 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
1899 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,uint
,uint
,const char*))
1901 char param
[WORDSIZE
/* api number */
1902 +sizeof(RAP_NetPrintQEnum_REQ
) /* req string */
1903 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
1904 +WORDSIZE
/* info level */
1905 +WORDSIZE
/* buffer size */
1906 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
1908 char *rparam
= NULL
;
1910 unsigned int rprcnt
, rdrcnt
;
1913 memset(param
, '\0',sizeof(param
));
1914 p
= make_header(param
, RAP_WPrintQEnum
,
1915 RAP_NetPrintQEnum_REQ
, RAP_PRINTQ_INFO_L2
);
1916 PUTWORD(p
,2); /* Info level 2 */
1917 PUTWORD(p
,0xFFE0); /* Return buffer size */
1918 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
1921 param
, PTR_DIFF(p
,param
),1024,
1922 NULL
, 0, CLI_BUFFER_SIZE
,
1925 char *endp
= rparam
+ rprcnt
;
1926 res
= GETRES(rparam
, endp
);
1927 cli
->rap_error
= res
;
1929 DEBUG(1,("NetPrintQEnum gave error %d\n", res
));
1934 DEBUG(4,("NetPrintQEnum no data returned\n"));
1938 if (res
== 0 || res
== ERRmoredata
) {
1939 TALLOC_CTX
*frame
= talloc_stackframe();
1940 char *endp
= rparam
+ rprcnt
;
1941 int i
, converter
= 0, count
= 0;
1943 p
= rparam
+ WORDSIZE
;
1944 GETWORD(p
, converter
, endp
);
1945 GETWORD(p
, count
, endp
);
1948 endp
= rdata
+ rdrcnt
;
1949 for (i
=0;i
<count
&& p
< endp
;i
++) {
1950 char qname
[RAP_SHARENAME_LEN
];
1951 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
1952 uint16_t jobcount
= 0, priority
= 0;
1953 uint16_t start_time
= 0, until_time
= 0, status
= 0;
1955 p
+= rap_getstringf(p
,
1961 GETWORD(p
, priority
, endp
);
1962 GETWORD(p
, start_time
, endp
);
1963 GETWORD(p
, until_time
, endp
);
1964 p
+= rap_getstringp(frame
,
1970 p
+= rap_getstringp(frame
,
1976 p
+= rap_getstringp(frame
,
1982 p
+= rap_getstringp(frame
,
1988 p
+= rap_getstringp(frame
,
1994 GETWORD(p
, status
, endp
);
1995 GETWORD(p
, jobcount
, endp
);
1997 if (sep_file
&& print_proc
&& dest
&& parms
&&
1999 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2000 dest
, parms
, comment
, status
, jobcount
);
2005 for (j
=0;j
<jobcount
;j
++) {
2006 uint16 jid
= 0, pos
= 0, fsstatus
= 0;
2007 char ownername
[RAP_USERNAME_LEN
];
2008 char notifyname
[RAP_MACHNAME_LEN
];
2009 char datatype
[RAP_DATATYPE_LEN
];
2010 char *jparms
, *jstatus
, *jcomment
;
2011 unsigned int submitted
= 0, jsize
= 0;
2013 GETWORD(p
, jid
, endp
);
2014 p
+= rap_getstringf(p
,
2020 p
+= rap_getstringf(p
,
2025 p
+= rap_getstringf(p
,
2030 p
+= rap_getstringp(frame
,
2036 GETWORD(p
, pos
, endp
);
2037 GETWORD(p
, fsstatus
, endp
);
2038 p
+= rap_getstringp(frame
,
2044 GETDWORD(p
, submitted
, endp
);
2045 GETDWORD(p
, jsize
, endp
);
2046 p
+= rap_getstringp(frame
,
2053 if (jparms
&& jstatus
&& jcomment
) {
2054 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2055 jstatus
, submitted
, jsize
, jcomment
);
2062 DEBUG(4,("NetPrintQEnum res=%d\n", res
));
2073 int cli_NetPrintQGetInfo(struct cli_state
*cli
, const char *printer
,
2074 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
2075 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,uint
,uint
,const char*))
2077 char param
[WORDSIZE
/* api number */
2078 +sizeof(RAP_NetPrintQGetInfo_REQ
) /* req string */
2079 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
2080 +RAP_SHARENAME_LEN
/* printer name */
2081 +WORDSIZE
/* info level */
2082 +WORDSIZE
/* buffer size */
2083 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
2085 char *rparam
= NULL
;
2087 unsigned int rprcnt
, rdrcnt
;
2090 memset(param
, '\0',sizeof(param
));
2091 p
= make_header(param
, RAP_WPrintQGetInfo
,
2092 RAP_NetPrintQGetInfo_REQ
, RAP_PRINTQ_INFO_L2
);
2093 PUTSTRING(p
, printer
, RAP_SHARENAME_LEN
-1);
2094 PUTWORD(p
, 2); /* Info level 2 */
2095 PUTWORD(p
,0xFFE0); /* Return buffer size */
2096 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
2099 param
, PTR_DIFF(p
,param
),1024,
2100 NULL
, 0, CLI_BUFFER_SIZE
,
2103 char *endp
= rparam
+ rprcnt
;
2104 res
= GETRES(rparam
, endp
);
2105 cli
->rap_error
= res
;
2107 DEBUG(1,("NetPrintQGetInfo gave error %d\n", res
));
2112 DEBUG(4,("NetPrintQGetInfo no data returned\n"));
2116 if (res
== 0 || res
== ERRmoredata
) {
2117 TALLOC_CTX
*frame
= talloc_stackframe();
2118 char *endp
= rparam
+ rprcnt
;
2119 int rsize
= 0, converter
= 0;
2120 char qname
[RAP_SHARENAME_LEN
];
2121 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
2122 uint16_t jobcount
= 0, priority
= 0;
2123 uint16_t start_time
= 0, until_time
= 0, status
= 0;
2125 p
= rparam
+ WORDSIZE
;
2126 GETWORD(p
, converter
, endp
);
2127 GETWORD(p
, rsize
, endp
);
2130 endp
= rdata
+ rdrcnt
;
2131 p
+= rap_getstringf(p
,
2137 GETWORD(p
, priority
, endp
);
2138 GETWORD(p
, start_time
, endp
);
2139 GETWORD(p
, until_time
, endp
);
2140 p
+= rap_getstringp(frame
,
2146 p
+= rap_getstringp(frame
,
2152 p
+= rap_getstringp(frame
,
2158 p
+= rap_getstringp(frame
,
2164 p
+= rap_getstringp(frame
,
2170 GETWORD(p
, status
, endp
);
2171 GETWORD(p
, jobcount
, endp
);
2173 if (sep_file
&& print_proc
&& dest
&&
2175 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2176 dest
, parms
, comment
, status
, jobcount
);
2180 for (j
=0;(j
<jobcount
)&&(PTR_DIFF(p
,rdata
)< rsize
)&&
2182 uint16_t jid
= 0, pos
= 0, fsstatus
= 0;
2183 char ownername
[RAP_USERNAME_LEN
];
2184 char notifyname
[RAP_MACHNAME_LEN
];
2185 char datatype
[RAP_DATATYPE_LEN
];
2186 char *jparms
, *jstatus
, *jcomment
;
2187 unsigned int submitted
= 0, jsize
= 0;
2189 GETWORD(p
, jid
, endp
);
2190 p
+= rap_getstringf(p
,
2196 p
+= rap_getstringf(p
,
2201 p
+= rap_getstringf(p
,
2206 p
+= rap_getstringp(frame
,
2212 GETWORD(p
, pos
,endp
);
2213 GETWORD(p
, fsstatus
,endp
);
2214 p
+= rap_getstringp(frame
,
2220 GETDWORD(p
, submitted
,endp
);
2221 GETDWORD(p
, jsize
,endp
);
2222 p
+= rap_getstringp(frame
,
2229 if (jparms
&& jstatus
&& jcomment
) {
2230 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2231 jstatus
, submitted
, jsize
, jcomment
);
2237 DEBUG(4,("NetPrintQGetInfo res=%d\n", res
));
2248 /****************************************************************************
2249 Call a NetServiceEnum - list running services on a different host.
2250 ****************************************************************************/
2252 int cli_RNetServiceEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
2254 char param
[WORDSIZE
/* api number */
2255 +sizeof(RAP_NetServiceEnum_REQ
) /* parm string */
2256 +sizeof(RAP_SERVICE_INFO_L2
) /* return string */
2257 +WORDSIZE
/* info level */
2258 +WORDSIZE
]; /* buffer size */
2260 char *rparam
= NULL
;
2262 unsigned int rprcnt
, rdrcnt
;
2265 memset(param
, '\0', sizeof(param
));
2266 p
= make_header(param
, RAP_WServiceEnum
,
2267 RAP_NetServiceEnum_REQ
, RAP_SERVICE_INFO_L2
);
2268 PUTWORD(p
,2); /* Info level 2 */
2269 PUTWORD(p
,0xFFE0); /* Return buffer size */
2272 param
, PTR_DIFF(p
,param
),8,
2273 NULL
, 0, 0xFFE0 /* data area size */,
2276 char *endp
= rparam
+ rprcnt
;
2277 res
= GETRES(rparam
, endp
);
2278 cli
->rap_error
= res
;
2279 if(cli
->rap_error
== 234) {
2280 DEBUG(1,("Not all service names were returned (such as those longer than 15 characters)\n"));
2281 } else if (cli
->rap_error
!= 0) {
2282 DEBUG(1,("NetServiceEnum gave error %d\n", cli
->rap_error
));
2287 DEBUG(4,("NetServiceEnum no data returned\n"));
2291 if (res
== 0 || res
== ERRmoredata
) {
2292 char *endp
= rparam
+ rprcnt
;
2295 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
2296 GETWORD(p
, count
,endp
);
2298 endp
= rdata
+ rdrcnt
;
2299 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2300 char comment
[RAP_SRVCCMNT_LEN
];
2301 char servicename
[RAP_SRVCNAME_LEN
];
2303 p
+= rap_getstringf(p
,
2308 p
+=8; /* pass status words */
2309 p
+= rap_getstringf(p
,
2315 if (servicename
[0]) {
2316 fn(servicename
, comment
, cli
); /* BB add status too */
2320 DEBUG(4,("NetServiceEnum res=%d\n", res
));
2331 /****************************************************************************
2332 Call a NetSessionEnum - list workstations with sessions to an SMB server.
2333 ****************************************************************************/
2335 int cli_NetSessionEnum(struct cli_state
*cli
, void (*fn
)(char *, char *, uint16
, uint16
, uint16
, uint
, uint
, uint
, char *))
2337 char param
[WORDSIZE
/* api number */
2338 +sizeof(RAP_NetSessionEnum_REQ
) /* parm string */
2339 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2340 +WORDSIZE
/* info level */
2341 +WORDSIZE
]; /* buffer size */
2343 char *rparam
= NULL
;
2345 unsigned int rprcnt
, rdrcnt
;
2348 memset(param
, '\0', sizeof(param
));
2349 p
= make_header(param
, RAP_WsessionEnum
,
2350 RAP_NetSessionEnum_REQ
, RAP_SESSION_INFO_L2
);
2351 PUTWORD(p
,2); /* Info level 2 */
2352 PUTWORD(p
,0xFF); /* Return buffer size */
2355 param
, PTR_DIFF(p
,param
),8,
2356 NULL
, 0, CLI_BUFFER_SIZE
,
2359 char *endp
= rparam
+ rprcnt
;
2360 res
= GETRES(rparam
, endp
);
2361 cli
->rap_error
= res
;
2363 DEBUG(1,("NetSessionEnum gave error %d\n", res
));
2368 DEBUG(4,("NetSesssionEnum no data returned\n"));
2372 if (res
== 0 || res
== ERRmoredata
) {
2373 TALLOC_CTX
*frame
= talloc_stackframe();
2374 char *endp
= rparam
+ rprcnt
;
2375 int i
, converter
= 0, count
= 0;
2377 p
= rparam
+ WORDSIZE
;
2378 GETWORD(p
, converter
, endp
);
2379 GETWORD(p
, count
, endp
);
2381 endp
= rdata
+ rdrcnt
;
2382 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2383 char *wsname
, *username
, *clitype_name
;
2384 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2385 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2387 p
+= rap_getstringp(frame
,
2393 p
+= rap_getstringp(frame
,
2399 GETWORD(p
, num_conns
, endp
);
2400 GETWORD(p
, num_opens
, endp
);
2401 GETWORD(p
, num_users
, endp
);
2402 GETDWORD(p
, sess_time
, endp
);
2403 GETDWORD(p
, idle_time
, endp
);
2404 GETDWORD(p
, user_flags
, endp
);
2405 p
+= rap_getstringp(frame
,
2412 if (wsname
&& username
&& clitype_name
) {
2413 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2414 idle_time
, user_flags
, clitype_name
);
2419 DEBUG(4,("NetSessionEnum res=%d\n", res
));
2430 /****************************************************************************
2431 Call a NetSessionGetInfo - get information about other session to an SMB server.
2432 ****************************************************************************/
2434 int cli_NetSessionGetInfo(struct cli_state
*cli
, const char *workstation
,
2435 void (*fn
)(const char *, const char *, uint16
, uint16
, uint16
, uint
, uint
, uint
, const char *))
2437 char param
[WORDSIZE
/* api number */
2438 +sizeof(RAP_NetSessionGetInfo_REQ
) /* req string */
2439 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2440 +RAP_MACHNAME_LEN
/* wksta name */
2441 +WORDSIZE
/* info level */
2442 +WORDSIZE
]; /* buffer size */
2444 char *rparam
= NULL
;
2446 unsigned int rprcnt
, rdrcnt
;
2450 memset(param
, '\0', sizeof(param
));
2451 p
= make_header(param
, RAP_WsessionGetInfo
,
2452 RAP_NetSessionGetInfo_REQ
, RAP_SESSION_INFO_L2
);
2453 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2454 PUTWORD(p
,2); /* Info level 2 */
2455 PUTWORD(p
,0xFF); /* Return buffer size */
2458 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2459 NULL
, 0, CLI_BUFFER_SIZE
,
2462 endp
= rparam
+ rprcnt
;
2463 res
= GETRES(rparam
, endp
);
2464 cli
->rap_error
= res
;
2465 if (cli
->rap_error
!= 0) {
2466 DEBUG(1,("NetSessionGetInfo gave error %d\n", cli
->rap_error
));
2471 DEBUG(4,("NetSessionGetInfo no data returned\n"));
2475 endp
= rparam
+ rprcnt
;
2476 res
= GETRES(rparam
, endp
);
2478 if (res
== 0 || res
== ERRmoredata
) {
2479 TALLOC_CTX
*frame
= talloc_stackframe();
2481 char *wsname
, *username
, *clitype_name
;
2482 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2483 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2485 p
= rparam
+ WORDSIZE
;
2486 GETWORD(p
, converter
,endp
);
2487 p
+= WORDSIZE
; /* skip rsize */
2490 endp
= rdata
+ rdrcnt
;
2491 p
+= rap_getstringp(frame
,
2497 p
+= rap_getstringp(frame
,
2503 GETWORD(p
, num_conns
, endp
);
2504 GETWORD(p
, num_opens
, endp
);
2505 GETWORD(p
, num_users
, endp
);
2506 GETDWORD(p
, sess_time
, endp
);
2507 GETDWORD(p
, idle_time
, endp
);
2508 GETDWORD(p
, user_flags
, endp
);
2509 p
+= rap_getstringp(frame
,
2516 if (wsname
&& username
&& clitype_name
) {
2517 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2518 idle_time
, user_flags
, clitype_name
);
2522 DEBUG(4,("NetSessionGetInfo res=%d\n", res
));
2533 /****************************************************************************
2534 Call a NetSessionDel - close a session to an SMB server.
2535 ****************************************************************************/
2537 int cli_NetSessionDel(struct cli_state
*cli
, const char *workstation
)
2539 char param
[WORDSIZE
/* api number */
2540 +sizeof(RAP_NetSessionDel_REQ
) /* req string */
2541 +1 /* no return string */
2542 +RAP_MACHNAME_LEN
/* workstation name */
2543 +WORDSIZE
]; /* reserved (0) */
2545 char *rparam
= NULL
;
2547 unsigned int rprcnt
, rdrcnt
;
2550 memset(param
, '\0', sizeof(param
));
2551 p
= make_header(param
, RAP_WsessionDel
, RAP_NetSessionDel_REQ
, NULL
);
2552 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2553 PUTWORD(p
,0); /* reserved word of 0 */
2556 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
2557 NULL
, 0, 200, /* data, length, maxlen */
2558 &rparam
, &rprcnt
, /* return params, length */
2559 &rdata
, &rdrcnt
)) /* return data, length */
2561 char *endp
= rparam
+ rprcnt
;
2562 res
= GETRES(rparam
, endp
);
2563 cli
->rap_error
= res
;
2568 DEBUG(4,("NetFileClose2 res=%d\n", res
));
2572 DEBUG(4,("NetFileClose2 failed\n"));
2581 int cli_NetConnectionEnum(struct cli_state
*cli
, const char *qualifier
,
2582 void (*fn
)(uint16_t conid
, uint16_t contype
,
2583 uint16_t numopens
, uint16_t numusers
,
2584 uint32_t contime
, const char *username
,
2585 const char *netname
))
2587 char param
[WORDSIZE
/* api number */
2588 +sizeof(RAP_NetConnectionEnum_REQ
) /* req string */
2589 +sizeof(RAP_CONNECTION_INFO_L1
) /* return string */
2590 +RAP_MACHNAME_LEN
/* wksta name */
2591 +WORDSIZE
/* info level */
2592 +WORDSIZE
]; /* buffer size */
2594 char *rparam
= NULL
;
2596 unsigned int rprcnt
, rdrcnt
;
2599 memset(param
, '\0', sizeof(param
));
2600 p
= make_header(param
, RAP_WconnectionEnum
,
2601 RAP_NetConnectionEnum_REQ
, RAP_CONNECTION_INFO_L1
);
2602 PUTSTRING(p
, qualifier
, RAP_MACHNAME_LEN
-1);/* Workstation name */
2603 PUTWORD(p
,1); /* Info level 1 */
2604 PUTWORD(p
,0xFFE0); /* Return buffer size */
2607 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2608 NULL
, 0, CLI_BUFFER_SIZE
,
2611 char *endp
= rparam
+ rprcnt
;
2612 res
= GETRES(rparam
, endp
);
2613 cli
->rap_error
= res
;
2615 DEBUG(1,("NetConnectionEnum gave error %d\n", res
));
2620 DEBUG(4,("NetConnectionEnum no data returned\n"));
2624 if (res
== 0 || res
== ERRmoredata
) {
2625 TALLOC_CTX
*frame
= talloc_stackframe();
2626 char *endp
= rparam
+ rprcnt
;
2627 int i
, converter
= 0, count
= 0;
2629 p
= rparam
+ WORDSIZE
;
2630 GETWORD(p
, converter
, endp
);
2631 GETWORD(p
, count
, endp
);
2633 endp
= rdata
+ rdrcnt
;
2634 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2635 char *netname
, *username
;
2636 uint16_t conn_id
= 0, conn_type
= 0, num_opens
= 0, num_users
= 0;
2637 unsigned int conn_time
= 0;
2639 GETWORD(p
,conn_id
, endp
);
2640 GETWORD(p
,conn_type
, endp
);
2641 GETWORD(p
,num_opens
, endp
);
2642 GETWORD(p
,num_users
, endp
);
2643 GETDWORD(p
,conn_time
, endp
);
2644 p
+= rap_getstringp(frame
,
2650 p
+= rap_getstringp(frame
,
2657 if (username
&& netname
) {
2658 fn(conn_id
, conn_type
, num_opens
, num_users
, conn_time
,
2664 DEBUG(4,("NetConnectionEnum res=%d\n", res
));