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 /*****************************************************/
79 #include "../librpc/gen_ndr/rap.h"
84 #define PUTBYTE(p,b) do {SCVAL(p,0,b); p++;} while(0)
86 #define GETBYTE(p,b,endp) \
94 #define PUTWORD(p,w) do {SSVAL(p,0,w); p += WORDSIZE;} while(0)
96 #define GETWORD(p,w,endp) \
98 if (p+WORDSIZE < endp) {\
104 #define PUTDWORD(p,d) do {SIVAL(p,0,d); p += DWORDSIZE;} while(0)
106 #define GETDWORD(p,d,endp) \
108 if (p+DWORDSIZE < endp) {\
114 #define GETRES(p,endp) ((p && p+2 < endp) ? SVAL(p,0) : -1)
116 /* put string s at p with max len n and increment p past string */
117 #define PUTSTRING(p,s,n) \
119 push_ascii(p,s?s:"",n?n:256,STR_TERMINATE);\
120 p = push_skip_string(p);\
123 /* put string s and p, using fixed len l, and increment p by l */
124 #define PUTSTRINGF(p,s,l) \
126 push_ascii(p,s?s:"",l,STR_TERMINATE);\
130 /* put string pointer at p, supplying offset o from rdata r, store */
131 /* dword offset at p, increment p by 4 and o by length of s. This */
132 /* means on the first call, you must calc the offset yourself! */
134 #define PUTSTRINGP(p,s,r,o) \
137 push_ascii(r+o,s,strlen(s)+1,STR_TERMINATE);\
145 /* get asciiz string dest from src, return increment past string */
147 static size_t rap_getstring(TALLOC_CTX
*ctx
, char *src
, char **dest
, const char *endp
)
153 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++)
158 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
162 /* get fixed length l string dest from src, return increment for src */
164 static size_t rap_getstringf(char *src
, char *dest
, size_t l
, size_t dlen
, char *endp
)
172 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
182 pull_ascii(dest
,src
,len
,len
,STR_ASCII
);
187 /* get string dest from offset (obtained at p) from rdata r - converter c */
188 static size_t rap_getstringp(TALLOC_CTX
*ctx
, char *p
, char **dest
, char *r
, uint16_t c
, char *endp
)
196 GETDWORD(p
,off
,endp
);
197 off
&= 0x0000FFFF; /* mask the obsolete segment number from the offset */
200 if (r
+off
> endp
|| r
+off
< r
) {
206 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
213 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
217 static char *make_header(char *param
, uint16 apinum
, const char *reqfmt
, const char *datafmt
)
219 PUTWORD(param
,apinum
);
221 PUTSTRING(param
,reqfmt
,0);
226 PUTSTRING(param
,datafmt
,0);
233 /****************************************************************************
234 call a NetGroupDelete - delete user group from remote server
235 ****************************************************************************/
237 int cli_NetGroupDelete(struct cli_state
*cli
, const char *group_name
)
242 unsigned int rdrcnt
,rprcnt
;
244 char param
[WORDSIZE
/* api number */
245 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
246 +1 /* no ret string */
247 +RAP_GROUPNAME_LEN
/* group to del */
248 +WORDSIZE
]; /* reserved word */
250 /* now send a SMBtrans command with api GroupDel */
251 p
= make_header(param
, RAP_WGroupDel
, RAP_NetGroupDel_REQ
, NULL
);
252 PUTSTRING(p
, group_name
, RAP_GROUPNAME_LEN
);
253 PUTWORD(p
,0); /* reserved word MBZ on input */
256 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
257 NULL
, 0, 200, /* data, length, maxlen */
258 &rparam
, &rprcnt
, /* return params, length */
259 &rdata
, &rdrcnt
)) /* return data, length */
261 char *endp
= rparam
+ rprcnt
;
262 res
= GETRES(rparam
,endp
);
266 } else if ((res
== 5) || (res
== 65)) {
267 DEBUG(1, ("Access Denied\n"));
268 } else if (res
== 2220) {
269 DEBUG (1, ("Group does not exist\n"));
271 DEBUG(4,("NetGroupDelete res=%d\n", res
));
275 DEBUG(4,("NetGroupDelete failed\n"));
284 /****************************************************************************
285 call a NetGroupAdd - add user group to remote server
286 ****************************************************************************/
288 int cli_NetGroupAdd(struct cli_state
*cli
, struct rap_group_info_1
*grinfo
)
293 unsigned int rdrcnt
,rprcnt
;
295 char param
[WORDSIZE
/* api number */
296 +sizeof(RAP_NetGroupAdd_REQ
) /* req string */
297 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
298 +WORDSIZE
/* info level */
299 +WORDSIZE
]; /* reserved word */
301 /* offset into data of free format strings. Will be updated */
302 /* by PUTSTRINGP macro and end up with total data length. */
303 int soffset
= RAP_GROUPNAME_LEN
+ 1 + DWORDSIZE
;
308 data_size
= MAX(soffset
+ strlen(grinfo
->comment
) + 1, 1024);
310 data
= SMB_MALLOC_ARRAY(char, data_size
);
312 DEBUG (1, ("Malloc fail\n"));
316 /* now send a SMBtrans command with api WGroupAdd */
318 p
= make_header(param
, RAP_WGroupAdd
,
319 RAP_NetGroupAdd_REQ
, RAP_GROUP_INFO_L1
);
320 PUTWORD(p
, 1); /* info level */
321 PUTWORD(p
, 0); /* reserved word 0 */
324 PUTSTRINGF(p
, (const char *)grinfo
->group_name
, RAP_GROUPNAME_LEN
);
325 PUTBYTE(p
, 0); /* pad byte 0 */
326 PUTSTRINGP(p
, grinfo
->comment
, data
, soffset
);
329 param
, sizeof(param
), 1024, /* Param, length, maxlen */
330 data
, soffset
, sizeof(data
), /* data, length, maxlen */
331 &rparam
, &rprcnt
, /* return params, length */
332 &rdata
, &rdrcnt
)) /* return data, length */
334 char *endp
= rparam
+ rprcnt
;
335 res
= GETRES(rparam
, endp
);
339 } else if ((res
== 5) || (res
== 65)) {
340 DEBUG(1, ("Access Denied\n"));
341 } else if (res
== 2223) {
342 DEBUG (1, ("Group already exists\n"));
344 DEBUG(4,("NetGroupAdd res=%d\n", res
));
348 DEBUG(4,("NetGroupAdd failed\n"));
358 /****************************************************************************
359 Call a NetGroupEnum - try and list user groups on a different host.
360 ****************************************************************************/
362 int cli_RNetGroupEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
364 char param
[WORDSIZE
/* api number */
365 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
366 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
367 +WORDSIZE
/* info level */
368 +WORDSIZE
]; /* buffer size */
372 unsigned int rprcnt
, rdrcnt
;
375 memset(param
, '\0', sizeof(param
));
376 p
= make_header(param
, RAP_WGroupEnum
,
377 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L1
);
378 PUTWORD(p
,1); /* Info level 1 */ /* add level 0 */
379 PUTWORD(p
,0xFFE0); /* Return buffer size */
382 param
, PTR_DIFF(p
,param
),8,
383 NULL
, 0, 0xFFE0 /* data area size */,
386 char *endp
= rparam
+ rdrcnt
;
388 res
= GETRES(rparam
, endp
);
389 cli
->rap_error
= res
;
390 if(cli
->rap_error
== 234) {
391 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
392 } else if (cli
->rap_error
!= 0) {
393 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
398 DEBUG(4,("NetGroupEnum no data returned\n"));
402 if (res
== 0 || res
== ERRmoredata
) {
403 char *endp
= rparam
+ rprcnt
;
404 int i
, converter
= 0, count
= 0;
405 TALLOC_CTX
*frame
= talloc_stackframe();
407 p
= rparam
+ WORDSIZE
; /* skip result */
408 GETWORD(p
, converter
, endp
);
409 GETWORD(p
, count
, endp
);
411 endp
= rdata
+ rdrcnt
;
412 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
413 char *comment
= NULL
;
414 char groupname
[RAP_GROUPNAME_LEN
];
416 p
+= rap_getstringf(p
,
422 p
+= rap_getstringp(frame
,
429 if (!comment
|| !groupname
[0]) {
433 fn(groupname
, comment
, cli
);
437 DEBUG(4,("NetGroupEnum res=%d\n", res
));
448 int cli_RNetGroupEnum0(struct cli_state
*cli
,
449 void (*fn
)(const char *, void *),
452 char param
[WORDSIZE
/* api number */
453 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
454 +sizeof(RAP_GROUP_INFO_L0
) /* return string */
455 +WORDSIZE
/* info level */
456 +WORDSIZE
]; /* buffer size */
460 unsigned int rprcnt
, rdrcnt
;
463 memset(param
, '\0', sizeof(param
));
464 p
= make_header(param
, RAP_WGroupEnum
,
465 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L0
);
466 PUTWORD(p
,0); /* Info level 0 */ /* Hmmm. I *very* much suspect this
467 is the resume count, at least
468 that's what smbd believes... */
469 PUTWORD(p
,0xFFE0); /* Return buffer size */
472 param
, PTR_DIFF(p
,param
),8,
473 NULL
, 0, 0xFFE0 /* data area size */,
476 char *endp
= rparam
+rprcnt
;
477 res
= GETRES(rparam
,endp
);
478 cli
->rap_error
= res
;
479 if(cli
->rap_error
== 234) {
480 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
481 } else if (cli
->rap_error
!= 0) {
482 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
487 DEBUG(4,("NetGroupEnum no data returned\n"));
491 if (res
== 0 || res
== ERRmoredata
) {
492 char *endp
= rparam
+ rprcnt
;
495 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
496 GETWORD(p
, count
, endp
);
498 endp
= rdata
+ rdrcnt
;
499 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
500 char groupname
[RAP_GROUPNAME_LEN
];
502 p
+= rap_getstringf(p
,
512 DEBUG(4,("NetGroupEnum res=%d\n", res
));
523 int cli_NetGroupDelUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
528 unsigned int rdrcnt
,rprcnt
;
530 char param
[WORDSIZE
/* api number */
531 +sizeof(RAP_NetGroupDelUser_REQ
) /* parm string */
532 +1 /* no ret string */
533 +RAP_GROUPNAME_LEN
/* group name */
534 +RAP_USERNAME_LEN
]; /* user to del */
536 /* now send a SMBtrans command with api GroupMemberAdd */
537 p
= make_header(param
, RAP_WGroupDelUser
, RAP_NetGroupDelUser_REQ
, NULL
);
538 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
539 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
542 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
543 NULL
, 0, 200, /* data, length, maxlen */
544 &rparam
, &rprcnt
, /* return params, length */
545 &rdata
, &rdrcnt
)) /* return data, length */
547 char *endp
= rparam
+ rprcnt
;
548 res
= GETRES(rparam
,endp
);
555 DEBUG(1, ("Access Denied\n"));
558 DEBUG(1, ("Not supported by server\n"));
561 DEBUG(1, ("Group does not exist\n"));
564 DEBUG(1, ("User does not exist\n"));
567 DEBUG(1, ("User is not in group\n"));
570 DEBUG(4,("NetGroupDelUser res=%d\n", res
));
574 DEBUG(4,("NetGroupDelUser failed\n"));
583 int cli_NetGroupAddUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
588 unsigned int rdrcnt
,rprcnt
;
590 char param
[WORDSIZE
/* api number */
591 +sizeof(RAP_NetGroupAddUser_REQ
) /* parm string */
592 +1 /* no ret string */
593 +RAP_GROUPNAME_LEN
/* group name */
594 +RAP_USERNAME_LEN
]; /* user to add */
596 /* now send a SMBtrans command with api GroupMemberAdd */
597 p
= make_header(param
, RAP_WGroupAddUser
, RAP_NetGroupAddUser_REQ
, NULL
);
598 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
599 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
602 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
603 NULL
, 0, 200, /* data, length, maxlen */
604 &rparam
, &rprcnt
, /* return params, length */
605 &rdata
, &rdrcnt
)) /* return data, length */
607 char *endp
= rparam
+ rprcnt
;
608 res
= GETRES(rparam
,endp
);
615 DEBUG(1, ("Access Denied\n"));
618 DEBUG(1, ("Not supported by server\n"));
621 DEBUG(1, ("Group does not exist\n"));
624 DEBUG(1, ("User does not exist\n"));
627 DEBUG(4,("NetGroupAddUser res=%d\n", res
));
631 DEBUG(4,("NetGroupAddUser failed\n"));
641 int cli_NetGroupGetUsers(struct cli_state
* cli
, const char *group_name
, void (*fn
)(const char *, void *), void *state
)
646 unsigned int rdrcnt
,rprcnt
;
648 char param
[WORDSIZE
/* api number */
649 +sizeof(RAP_NetGroupGetUsers_REQ
)/* parm string */
650 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
651 +RAP_GROUPNAME_LEN
/* group name */
652 +WORDSIZE
/* info level */
653 +WORDSIZE
]; /* buffer size */
655 /* now send a SMBtrans command with api GroupGetUsers */
656 p
= make_header(param
, RAP_WGroupGetUsers
,
657 RAP_NetGroupGetUsers_REQ
, RAP_GROUP_USERS_INFO_0
);
658 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
-1);
659 PUTWORD(p
,0); /* info level 0 */
660 PUTWORD(p
,0xFFE0); /* return buffer size */
663 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
664 NULL
, 0, CLI_BUFFER_SIZE
,
667 char *endp
= rparam
+ rprcnt
;
668 res
= GETRES(rparam
,endp
);
669 cli
->rap_error
= res
;
671 DEBUG(1,("NetGroupGetUsers gave error %d\n", res
));
676 DEBUG(4,("NetGroupGetUsers no data returned\n"));
680 if (res
== 0 || res
== ERRmoredata
) {
681 char *endp
= rparam
+ rprcnt
;
683 char username
[RAP_USERNAME_LEN
];
685 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
686 GETWORD(p
, count
, endp
);
688 endp
= rdata
+ rdrcnt
;
689 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
690 p
+= rap_getstringf(p
,
700 DEBUG(4,("NetGroupGetUsers res=%d\n", res
));
710 int cli_NetUserGetGroups(struct cli_state
* cli
, const char *user_name
, void (*fn
)(const char *, void *), void *state
)
715 unsigned int rdrcnt
,rprcnt
;
717 char param
[WORDSIZE
/* api number */
718 +sizeof(RAP_NetUserGetGroups_REQ
)/* parm string */
719 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
720 +RAP_USERNAME_LEN
/* user name */
721 +WORDSIZE
/* info level */
722 +WORDSIZE
]; /* buffer size */
724 /* now send a SMBtrans command with api GroupGetUsers */
725 p
= make_header(param
, RAP_WUserGetGroups
,
726 RAP_NetUserGetGroups_REQ
, RAP_GROUP_USERS_INFO_0
);
727 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
-1);
728 PUTWORD(p
,0); /* info level 0 */
729 PUTWORD(p
,0xFFE0); /* return buffer size */
732 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
733 NULL
, 0, CLI_BUFFER_SIZE
,
736 char *endp
= rparam
+ rprcnt
;
737 res
= GETRES(rparam
,endp
);
738 cli
->rap_error
= res
;
740 DEBUG(1,("NetUserGetGroups gave error %d\n", res
));
745 DEBUG(4,("NetUserGetGroups no data returned\n"));
749 if (res
== 0 || res
== ERRmoredata
) {
750 char *endp
= rparam
+ rprcnt
;
752 char groupname
[RAP_GROUPNAME_LEN
];
754 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
755 GETWORD(p
, count
, endp
);
757 endp
= rdata
+ rdrcnt
;
758 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
759 p
+= rap_getstringf(p
,
765 fn(groupname
, state
);
769 DEBUG(4,("NetUserGetGroups res=%d\n", res
));
779 /****************************************************************************
780 Call a NetUserDelete - delete user from remote server.
781 ****************************************************************************/
783 int cli_NetUserDelete(struct cli_state
*cli
, const char * user_name
)
788 unsigned int rdrcnt
,rprcnt
;
790 char param
[WORDSIZE
/* api number */
791 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
792 +1 /* no ret string */
793 +RAP_USERNAME_LEN
/* user to del */
794 +WORDSIZE
]; /* reserved word */
796 /* now send a SMBtrans command with api UserDel */
797 p
= make_header(param
, RAP_WUserDel
, RAP_NetGroupDel_REQ
, NULL
);
798 PUTSTRING(p
, user_name
, RAP_USERNAME_LEN
);
799 PUTWORD(p
,0); /* reserved word MBZ on input */
802 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
803 NULL
, 0, 200, /* data, length, maxlen */
804 &rparam
, &rprcnt
, /* return params, length */
805 &rdata
, &rdrcnt
)) /* return data, length */
807 char *endp
= rparam
+ rprcnt
;
808 res
= GETRES(rparam
,endp
);
812 } else if ((res
== 5) || (res
== 65)) {
813 DEBUG(1, ("Access Denied\n"));
814 } else if (res
== 2221) {
815 DEBUG (1, ("User does not exist\n"));
817 DEBUG(4,("NetUserDelete res=%d\n", res
));
821 DEBUG(4,("NetUserDelete failed\n"));
830 /****************************************************************************
831 Call a NetUserAdd - add user to remote server.
832 ****************************************************************************/
834 int cli_NetUserAdd(struct cli_state
*cli
, struct rap_user_info_1
* userinfo
)
839 unsigned int rdrcnt
,rprcnt
;
841 char param
[WORDSIZE
/* api number */
842 +sizeof(RAP_NetUserAdd2_REQ
) /* req string */
843 +sizeof(RAP_USER_INFO_L1
) /* data string */
844 +WORDSIZE
/* info level */
845 +WORDSIZE
/* buffer length */
846 +WORDSIZE
]; /* reserved */
849 /* offset into data of free format strings. Will be updated */
850 /* by PUTSTRINGP macro and end up with total data length. */
851 int soffset
=RAP_USERNAME_LEN
+1 /* user name + pad */
852 + RAP_UPASSWD_LEN
/* password */
853 + DWORDSIZE
/* password age */
854 + WORDSIZE
/* privilege */
855 + DWORDSIZE
/* home dir ptr */
856 + DWORDSIZE
/* comment ptr */
857 + WORDSIZE
/* flags */
858 + DWORDSIZE
; /* login script ptr*/
860 /* now send a SMBtrans command with api NetUserAdd */
861 p
= make_header(param
, RAP_WUserAdd2
,
862 RAP_NetUserAdd2_REQ
, RAP_USER_INFO_L1
);
864 PUTWORD(p
, 1); /* info level */
865 PUTWORD(p
, 0); /* pwencrypt */
866 if(userinfo
->passwrd
)
867 PUTWORD(p
,MIN(strlen((const char *)userinfo
->passwrd
), RAP_UPASSWD_LEN
));
869 PUTWORD(p
, 0); /* password length */
872 memset(data
, '\0', soffset
);
874 PUTSTRINGF(p
, (const char *)userinfo
->user_name
, RAP_USERNAME_LEN
);
875 PUTBYTE(p
, 0); /* pad byte 0 */
876 PUTSTRINGF(p
, (const char *)userinfo
->passwrd
, RAP_UPASSWD_LEN
);
877 PUTDWORD(p
, 0); /* pw age - n.a. on user add */
878 PUTWORD(p
, userinfo
->priv
);
879 PUTSTRINGP(p
, userinfo
->home_dir
, data
, soffset
);
880 PUTSTRINGP(p
, userinfo
->comment
, data
, soffset
);
881 PUTWORD(p
, userinfo
->userflags
);
882 PUTSTRINGP(p
, userinfo
->logon_script
, data
, soffset
);
885 param
, sizeof(param
), 1024, /* Param, length, maxlen */
886 data
, soffset
, sizeof(data
), /* data, length, maxlen */
887 &rparam
, &rprcnt
, /* return params, length */
888 &rdata
, &rdrcnt
)) /* return data, length */
890 char *endp
= rparam
+ rprcnt
;
891 res
= GETRES(rparam
, endp
);
895 } else if ((res
== 5) || (res
== 65)) {
896 DEBUG(1, ("Access Denied\n"));
897 } else if (res
== 2224) {
898 DEBUG (1, ("User already exists\n"));
900 DEBUG(4,("NetUserAdd res=%d\n", res
));
904 DEBUG(4,("NetUserAdd failed\n"));
913 /****************************************************************************
914 call a NetUserEnum - try and list users on a different host
915 ****************************************************************************/
917 int cli_RNetUserEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, const char *, const char *, void *), void *state
)
919 char param
[WORDSIZE
/* api number */
920 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
921 +sizeof(RAP_USER_INFO_L1
) /* return string */
922 +WORDSIZE
/* info level */
923 +WORDSIZE
]; /* buffer size */
927 unsigned int rprcnt
, rdrcnt
;
930 memset(param
, '\0', sizeof(param
));
931 p
= make_header(param
, RAP_WUserEnum
,
932 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L1
);
933 PUTWORD(p
,1); /* Info level 1 */
934 PUTWORD(p
,0xFF00); /* Return buffer size */
936 /* BB Fix handling of large numbers of users to be returned */
938 param
, PTR_DIFF(p
,param
),8,
939 NULL
, 0, CLI_BUFFER_SIZE
,
942 char *endp
= rparam
+ rprcnt
;
943 res
= GETRES(rparam
,endp
);
944 cli
->rap_error
= res
;
945 if (cli
->rap_error
!= 0) {
946 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
951 DEBUG(4,("NetUserEnum no data returned\n"));
955 if (res
== 0 || res
== ERRmoredata
) {
956 int i
, converter
= 0, count
= 0;
957 char username
[RAP_USERNAME_LEN
];
958 char userpw
[RAP_UPASSWD_LEN
];
959 char *endp
= rparam
+ rprcnt
;
960 char *comment
, *homedir
, *logonscript
;
961 TALLOC_CTX
*frame
= talloc_stackframe();
963 p
= rparam
+ WORDSIZE
; /* skip result */
964 GETWORD(p
, converter
, endp
);
965 GETWORD(p
, count
, endp
);
967 endp
= rdata
+ rdrcnt
;
968 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
969 p
+= rap_getstringf(p
,
975 p
+= rap_getstringf(p
,
980 p
+= DWORDSIZE
; /* skip password age */
981 p
+= WORDSIZE
; /* skip priv: 0=guest, 1=user, 2=admin */
982 p
+= rap_getstringp(frame
,
988 p
+= rap_getstringp(frame
,
994 p
+= WORDSIZE
; /* skip flags */
995 p
+= rap_getstringp(frame
,
1001 if (username
[0] && comment
&&
1002 homedir
&& logonscript
) {
1012 DEBUG(4,("NetUserEnum res=%d\n", res
));
1023 int cli_RNetUserEnum0(struct cli_state
*cli
,
1024 void (*fn
)(const char *, void *),
1027 char param
[WORDSIZE
/* api number */
1028 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
1029 +sizeof(RAP_USER_INFO_L0
) /* return string */
1030 +WORDSIZE
/* info level */
1031 +WORDSIZE
]; /* buffer size */
1033 char *rparam
= NULL
;
1035 unsigned int rprcnt
, rdrcnt
;
1038 memset(param
, '\0', sizeof(param
));
1039 p
= make_header(param
, RAP_WUserEnum
,
1040 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L0
);
1041 PUTWORD(p
,0); /* Info level 1 */
1042 PUTWORD(p
,0xFF00); /* Return buffer size */
1044 /* BB Fix handling of large numbers of users to be returned */
1046 param
, PTR_DIFF(p
,param
),8,
1047 NULL
, 0, CLI_BUFFER_SIZE
,
1050 char *endp
= rparam
+ rprcnt
;
1051 res
= GETRES(rparam
,endp
);
1052 cli
->rap_error
= res
;
1053 if (cli
->rap_error
!= 0) {
1054 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
1059 DEBUG(4,("NetUserEnum no data returned\n"));
1063 if (res
== 0 || res
== ERRmoredata
) {
1065 char *endp
= rparam
+ rprcnt
;
1066 char username
[RAP_USERNAME_LEN
];
1068 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1069 GETWORD(p
, count
, endp
);
1071 endp
= rdata
+ rdrcnt
;
1072 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
1073 p
+= rap_getstringf(p
,
1083 DEBUG(4,("NetUserEnum res=%d\n", res
));
1094 /****************************************************************************
1095 Call a NetFileClose2 - close open file on another session to server.
1096 ****************************************************************************/
1098 int cli_NetFileClose(struct cli_state
*cli
, uint32 file_id
)
1100 char *rparam
= NULL
;
1103 unsigned int rdrcnt
,rprcnt
;
1104 char param
[WORDSIZE
/* api number */
1105 +sizeof(RAP_WFileClose2_REQ
) /* req string */
1106 +1 /* no ret string */
1107 +DWORDSIZE
]; /* file ID */
1110 /* now send a SMBtrans command with api RNetShareEnum */
1111 p
= make_header(param
, RAP_WFileClose2
, RAP_WFileClose2_REQ
, NULL
);
1112 PUTDWORD(p
, file_id
);
1115 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1116 NULL
, 0, 200, /* data, length, maxlen */
1117 &rparam
, &rprcnt
, /* return params, length */
1118 &rdata
, &rdrcnt
)) /* return data, length */
1120 char *endp
= rparam
+ rprcnt
;
1121 res
= GETRES(rparam
, endp
);
1125 } else if (res
== 2314){
1126 DEBUG(1, ("NetFileClose2 - attempt to close non-existant file open instance\n"));
1128 DEBUG(4,("NetFileClose2 res=%d\n", res
));
1132 DEBUG(4,("NetFileClose2 failed\n"));
1141 /****************************************************************************
1142 Call a NetFileGetInfo - get information about server file opened from other
1144 ****************************************************************************/
1146 int cli_NetFileGetInfo(struct cli_state
*cli
, uint32 file_id
, void (*fn
)(const char *, const char *, uint16
, uint16
, uint32
))
1148 char *rparam
= NULL
;
1151 unsigned int rdrcnt
,rprcnt
;
1153 char param
[WORDSIZE
/* api number */
1154 +sizeof(RAP_WFileGetInfo2_REQ
) /* req string */
1155 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1156 +DWORDSIZE
/* file ID */
1157 +WORDSIZE
/* info level */
1158 +WORDSIZE
]; /* buffer size */
1160 /* now send a SMBtrans command with api RNetShareEnum */
1161 p
= make_header(param
, RAP_WFileGetInfo2
,
1162 RAP_WFileGetInfo2_REQ
, RAP_FILE_INFO_L3
);
1163 PUTDWORD(p
, file_id
);
1164 PUTWORD(p
, 3); /* info level */
1165 PUTWORD(p
, 0x1000); /* buffer size */
1167 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1168 NULL
, 0, 0x1000, /* data, length, maxlen */
1169 &rparam
, &rprcnt
, /* return params, length */
1170 &rdata
, &rdrcnt
)) /* return data, length */
1172 char *endp
= rparam
+ rprcnt
;
1173 res
= GETRES(rparam
,endp
);
1174 if (res
== 0 || res
== ERRmoredata
) {
1175 TALLOC_CTX
*frame
= talloc_stackframe();
1176 int converter
= 0,id
= 0, perms
= 0, locks
= 0;
1177 char *fpath
, *fuser
;
1179 p
= rparam
+ WORDSIZE
; /* skip result */
1180 GETWORD(p
, converter
, endp
);
1183 endp
= rdata
+ rdrcnt
;
1185 GETDWORD(p
, id
, endp
);
1186 GETWORD(p
, perms
, endp
);
1187 GETWORD(p
, locks
, endp
);
1189 p
+= rap_getstringp(frame
,
1195 p
+= rap_getstringp(frame
,
1202 if (fpath
&& fuser
) {
1203 fn(fpath
, fuser
, perms
, locks
, id
);
1208 DEBUG(4,("NetFileGetInfo2 res=%d\n", res
));
1212 DEBUG(4,("NetFileGetInfo2 failed\n"));
1221 /****************************************************************************
1222 * Call a NetFileEnum2 - list open files on an SMB server
1224 * PURPOSE: Remotes a NetFileEnum API call to the current server or target
1225 * server listing the files open via the network (and their
1226 * corresponding open instance ids)
1228 * Dependencies: none
1231 * cli - pointer to cli_state structure
1232 * user - if present, return only files opened by this remote user
1233 * base_path - if present, return only files opened below this
1235 * fn - display function to invoke for each entry in the result
1242 ****************************************************************************/
1244 int cli_NetFileEnum(struct cli_state
*cli
, const char * user
,
1245 const char * base_path
,
1246 void (*fn
)(const char *, const char *, uint16
, uint16
,
1249 char *rparam
= NULL
;
1252 unsigned int rdrcnt
,rprcnt
;
1253 char param
[WORDSIZE
/* api number */
1254 +sizeof(RAP_WFileEnum2_REQ
) /* req string */
1255 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1256 +1024 /* base path (opt) */
1257 +RAP_USERNAME_LEN
/* user name (opt) */
1258 +WORDSIZE
/* info level */
1259 +WORDSIZE
/* buffer size */
1260 +DWORDSIZE
/* resume key ? */
1261 +DWORDSIZE
]; /* resume key ? */
1265 /* now send a SMBtrans command with api RNetShareEnum */
1266 p
= make_header(param
, RAP_WFileEnum2
,
1267 RAP_WFileEnum2_REQ
, RAP_FILE_INFO_L3
);
1269 PUTSTRING(p
, base_path
, 1024);
1270 PUTSTRING(p
, user
, RAP_USERNAME_LEN
);
1271 PUTWORD(p
, 3); /* info level */
1272 PUTWORD(p
, 0xFF00); /* buffer size */
1273 PUTDWORD(p
, 0); /* zero out the resume key */
1274 PUTDWORD(p
, 0); /* or is this one the resume key? */
1277 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1278 NULL
, 0, 0xFF00, /* data, length, maxlen */
1279 &rparam
, &rprcnt
, /* return params, length */
1280 &rdata
, &rdrcnt
)) /* return data, length */
1282 char *endp
= rparam
+ rprcnt
;
1283 res
= GETRES(rparam
, endp
);
1285 if (res
== 0 || res
== ERRmoredata
) {
1286 TALLOC_CTX
*frame
= talloc_stackframe();
1287 int converter
= 0, i
;
1289 p
= rparam
+ WORDSIZE
; /* skip result */
1290 GETWORD(p
, converter
, endp
);
1291 GETWORD(p
, count
, endp
);
1294 endp
= rdata
+ rdrcnt
;
1295 for (i
=0; i
<count
&& p
< endp
; i
++) {
1296 int id
= 0, perms
= 0, locks
= 0;
1297 char *fpath
, *fuser
;
1299 GETDWORD(p
, id
, endp
);
1300 GETWORD(p
, perms
, endp
);
1301 GETWORD(p
, locks
, endp
);
1302 p
+= rap_getstringp(frame
,
1308 p
+= rap_getstringp(frame
,
1315 if (fpath
&& fuser
) {
1316 fn(fpath
, fuser
, perms
, locks
, id
);
1318 } /* BB fix ERRmoredata case to send resume request */
1321 DEBUG(4,("NetFileEnum2 res=%d\n", res
));
1324 DEBUG(4,("NetFileEnum2 failed\n"));
1333 /****************************************************************************
1334 Call a NetShareAdd - share/export directory on remote server.
1335 ****************************************************************************/
1337 int cli_NetShareAdd(struct cli_state
*cli
, struct rap_share_info_2
* sinfo
)
1339 char *rparam
= NULL
;
1342 unsigned int rdrcnt
,rprcnt
;
1344 char param
[WORDSIZE
/* api number */
1345 +sizeof(RAP_WShareAdd_REQ
) /* req string */
1346 +sizeof(RAP_SHARE_INFO_L2
) /* return string */
1347 +WORDSIZE
/* info level */
1348 +WORDSIZE
]; /* reserved word */
1350 /* offset to free format string section following fixed length data. */
1351 /* will be updated by PUTSTRINGP macro and will end up with total len */
1352 int soffset
= RAP_SHARENAME_LEN
+ 1 /* share name + pad */
1353 + WORDSIZE
/* share type */
1354 + DWORDSIZE
/* comment pointer */
1355 + WORDSIZE
/* permissions */
1356 + WORDSIZE
/* max users */
1357 + WORDSIZE
/* active users */
1358 + DWORDSIZE
/* share path */
1359 + RAP_SPASSWD_LEN
+ 1; /* share password + pad */
1361 memset(param
,'\0',sizeof(param
));
1362 /* now send a SMBtrans command with api RNetShareAdd */
1363 p
= make_header(param
, RAP_WshareAdd
,
1364 RAP_WShareAdd_REQ
, RAP_SHARE_INFO_L2
);
1365 PUTWORD(p
, 2); /* info level */
1366 PUTWORD(p
, 0); /* reserved word 0 */
1369 PUTSTRINGF(p
, (const char *)sinfo
->share_name
, RAP_SHARENAME_LEN
);
1370 PUTBYTE(p
, 0); /* pad byte 0 */
1372 PUTWORD(p
, sinfo
->share_type
);
1373 PUTSTRINGP(p
, sinfo
->comment
, data
, soffset
);
1374 PUTWORD(p
, sinfo
->perms
);
1375 PUTWORD(p
, sinfo
->maximum_users
);
1376 PUTWORD(p
, sinfo
->active_users
);
1377 PUTSTRINGP(p
, sinfo
->path
, data
, soffset
);
1378 PUTSTRINGF(p
, (const char *)sinfo
->password
, RAP_SPASSWD_LEN
);
1379 SCVAL(p
,-1,0x0A); /* required 0x0A at end of password */
1382 param
, sizeof(param
), 1024, /* Param, length, maxlen */
1383 data
, soffset
, sizeof(data
), /* data, length, maxlen */
1384 &rparam
, &rprcnt
, /* return params, length */
1385 &rdata
, &rdrcnt
)) /* return data, length */
1387 char *endp
= rparam
+ rprcnt
;
1388 res
= GETRES(rparam
, endp
);
1393 DEBUG(4,("NetShareAdd res=%d\n", res
));
1396 DEBUG(4,("NetShareAdd failed\n"));
1405 /****************************************************************************
1406 Call a NetShareDelete - unshare exported directory on remote server.
1407 ****************************************************************************/
1409 int cli_NetShareDelete(struct cli_state
*cli
, const char * share_name
)
1411 char *rparam
= NULL
;
1414 unsigned int rdrcnt
,rprcnt
;
1416 char param
[WORDSIZE
/* api number */
1417 +sizeof(RAP_WShareDel_REQ
) /* req string */
1418 +1 /* no ret string */
1419 +RAP_SHARENAME_LEN
/* share to del */
1420 +WORDSIZE
]; /* reserved word */
1422 /* now send a SMBtrans command with api RNetShareDelete */
1423 p
= make_header(param
, RAP_WshareDel
, RAP_WShareDel_REQ
, NULL
);
1424 PUTSTRING(p
,share_name
,RAP_SHARENAME_LEN
);
1425 PUTWORD(p
,0); /* reserved word MBZ on input */
1428 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1429 NULL
, 0, 200, /* data, length, maxlen */
1430 &rparam
, &rprcnt
, /* return params, length */
1431 &rdata
, &rdrcnt
)) /* return data, length */
1433 char *endp
= rparam
+ rprcnt
;
1434 res
= GETRES(rparam
, endp
);
1439 DEBUG(4,("NetShareDelete res=%d\n", res
));
1442 DEBUG(4,("NetShareDelete failed\n"));
1451 /*************************************************************************
1453 * Function Name: cli_get_pdc_name
1455 * PURPOSE: Remotes a NetServerEnum API call to the current server
1456 * requesting the name of a server matching the server
1457 * type of SV_TYPE_DOMAIN_CTRL (PDC).
1459 * Dependencies: none
1462 * cli - pointer to cli_state structure
1463 * workgroup - pointer to string containing name of domain
1464 * pdc_name - pointer to string that will contain PDC name
1465 * on successful return
1471 ************************************************************************/
1473 bool cli_get_pdc_name(struct cli_state
*cli
, const char *workgroup
, char **pdc_name
)
1475 char *rparam
= NULL
;
1477 unsigned int rdrcnt
,rprcnt
;
1479 char param
[WORDSIZE
/* api number */
1480 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1481 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1482 +WORDSIZE
/* info level */
1483 +WORDSIZE
/* buffer size */
1484 +DWORDSIZE
/* server type */
1485 +RAP_MACHNAME_LEN
]; /* workgroup */
1491 /* send a SMBtrans command with api NetServerEnum */
1492 p
= make_header(param
, RAP_NetServerEnum2
,
1493 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L1
);
1494 PUTWORD(p
, 1); /* info level */
1495 PUTWORD(p
, CLI_BUFFER_SIZE
);
1496 PUTDWORD(p
, SV_TYPE_DOMAIN_CTRL
);
1497 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1500 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1501 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1502 &rparam
, &rprcnt
, /* return params, return size */
1503 &rdata
, &rdrcnt
/* return data, return size */
1506 char *endp
= rparam
+ rprcnt
;
1507 res
= GETRES(rparam
, endp
);
1508 cli
->rap_error
= res
;
1511 * We only really care to copy a name if the
1512 * API succeeded and we got back a name.
1514 if (cli
->rap_error
== 0) {
1515 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1516 GETWORD(p
, count
, endp
);
1518 endp
= rdata
+ rdrcnt
;
1521 TALLOC_CTX
*frame
= talloc_stackframe();
1523 p
+= rap_getstring(frame
,
1528 *pdc_name
= SMB_STRDUP(dcname
);
1533 DEBUG(4,("cli_get_pdc_name: machine %s failed the NetServerEnum call. "
1534 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1544 /*************************************************************************
1546 * Function Name: cli_get_server_domain
1548 * PURPOSE: Remotes a NetWkstaGetInfo API call to the current server
1549 * requesting wksta_info_10 level information to determine
1550 * the domain the server belongs to. On success, this
1551 * routine sets the server_domain field in the cli_state structure
1552 * to the server's domain name.
1554 * Dependencies: none
1557 * cli - pointer to cli_state structure
1563 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1565 ************************************************************************/
1567 bool cli_get_server_domain(struct cli_state
*cli
)
1569 char *rparam
= NULL
;
1571 unsigned int rdrcnt
,rprcnt
;
1573 char param
[WORDSIZE
/* api number */
1574 +sizeof(RAP_WWkstaGetInfo_REQ
) /* req string */
1575 +sizeof(RAP_WKSTA_INFO_L10
) /* return string */
1576 +WORDSIZE
/* info level */
1577 +WORDSIZE
]; /* buffer size */
1580 /* send a SMBtrans command with api NetWkstaGetInfo */
1581 p
= make_header(param
, RAP_WWkstaGetInfo
,
1582 RAP_WWkstaGetInfo_REQ
, RAP_WKSTA_INFO_L10
);
1583 PUTWORD(p
, 10); /* info level */
1584 PUTWORD(p
, CLI_BUFFER_SIZE
);
1586 if (cli_api(cli
, param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1587 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1588 &rparam
, &rprcnt
, /* return params, return size */
1589 &rdata
, &rdrcnt
)) { /* return data, return size */
1590 char *endp
= rparam
+ rprcnt
;
1591 res
= GETRES(rparam
, endp
);
1594 TALLOC_CTX
*frame
= talloc_stackframe();
1595 char *server_domain
;
1598 p
= rparam
+ WORDSIZE
;
1599 GETWORD(p
, converter
, endp
);
1601 p
= rdata
+ DWORDSIZE
+ DWORDSIZE
; /* skip computer & user names */
1602 endp
= rdata
+ rdrcnt
;
1603 p
+= rap_getstringp(frame
,
1610 if (server_domain
) {
1611 fstrcpy(cli
->server_domain
, server_domain
);
1623 /*************************************************************************
1625 * Function Name: cli_get_server_type
1627 * PURPOSE: Remotes a NetServerGetInfo API call to the current server
1628 * requesting server_info_1 level information to retrieve
1631 * Dependencies: none
1634 * cli - pointer to cli_state structure
1635 * pstype - pointer to uint32 to contain returned server type
1641 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1643 ************************************************************************/
1645 bool cli_get_server_type(struct cli_state
*cli
, uint32
*pstype
)
1647 char *rparam
= NULL
;
1649 unsigned int rdrcnt
,rprcnt
;
1651 char param
[WORDSIZE
/* api number */
1652 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1653 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1654 +WORDSIZE
/* info level */
1655 +WORDSIZE
]; /* buffer size */
1658 /* send a SMBtrans command with api NetServerGetInfo */
1659 p
= make_header(param
, RAP_WserverGetInfo
,
1660 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1661 PUTWORD(p
, 1); /* info level */
1662 PUTWORD(p
, CLI_BUFFER_SIZE
);
1665 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1666 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1667 &rparam
, &rprcnt
, /* return params, return size */
1668 &rdata
, &rdrcnt
/* return data, return size */
1670 char *endp
= rparam
+ rprcnt
;
1671 res
= GETRES(rparam
,endp
);
1673 if (res
== 0 || res
== ERRmoredata
) {
1675 endp
= rparam
+ rprcnt
;
1677 GETDWORD(p
,*pstype
,endp
);
1678 *pstype
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1685 return(res
== 0 || res
== ERRmoredata
);
1688 bool cli_get_server_name(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
1691 char *rparam
= NULL
;
1693 unsigned int rdrcnt
,rprcnt
;
1695 char param
[WORDSIZE
/* api number */
1696 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1697 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1698 +WORDSIZE
/* info level */
1699 +WORDSIZE
]; /* buffer size */
1704 /* send a SMBtrans command with api NetServerGetInfo */
1705 p
= make_header(param
, RAP_WserverGetInfo
,
1706 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1707 PUTWORD(p
, 1); /* info level */
1708 PUTWORD(p
, CLI_BUFFER_SIZE
);
1711 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1712 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1713 &rparam
, &rprcnt
, /* return params, return size */
1714 &rdata
, &rdrcnt
/* return data, return size */
1719 endp
= rparam
+ rprcnt
;
1720 if (GETRES(rparam
, endp
) != 0) {
1725 DEBUG(10, ("invalid data count %d, expected >= 16\n", rdrcnt
));
1729 if (pull_ascii(tmp
, rdata
, sizeof(tmp
)-1, 16, STR_TERMINATE
) == -1) {
1730 DEBUG(10, ("pull_ascii failed\n"));
1734 if (!(*servername
= talloc_strdup(mem_ctx
, tmp
))) {
1735 DEBUG(1, ("talloc_strdup failed\n"));
1747 /*************************************************************************
1749 * Function Name: cli_ns_check_server_type
1751 * PURPOSE: Remotes a NetServerEnum2 API call to the current server
1752 * requesting server_info_0 level information of machines
1753 * matching the given server type. If the returned server
1754 * list contains the machine name contained in cli->desthost
1755 * then we conclude the server type checks out. This routine
1756 * is useful to retrieve list of server's of a certain
1757 * type when all you have is a null session connection and
1758 * can't remote API calls such as NetWkstaGetInfo or
1761 * Dependencies: none
1764 * cli - pointer to cli_state structure
1765 * workgroup - pointer to string containing domain
1766 * stype - server type
1772 ************************************************************************/
1774 bool cli_ns_check_server_type(struct cli_state
*cli
, char *workgroup
, uint32 stype
)
1776 char *rparam
= NULL
;
1778 unsigned int rdrcnt
,rprcnt
;
1780 char param
[WORDSIZE
/* api number */
1781 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1782 +sizeof(RAP_SERVER_INFO_L0
) /* return string */
1783 +WORDSIZE
/* info level */
1784 +WORDSIZE
/* buffer size */
1785 +DWORDSIZE
/* server type */
1786 +RAP_MACHNAME_LEN
]; /* workgroup */
1787 bool found_server
= false;
1790 /* send a SMBtrans command with api NetServerEnum */
1791 p
= make_header(param
, RAP_NetServerEnum2
,
1792 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L0
);
1793 PUTWORD(p
, 0); /* info level 0 */
1794 PUTWORD(p
, CLI_BUFFER_SIZE
);
1796 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1799 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1800 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1801 &rparam
, &rprcnt
, /* return params, return size */
1802 &rdata
, &rdrcnt
/* return data, return size */
1804 char *endp
= rparam
+ rprcnt
;
1805 res
= GETRES(rparam
,endp
);
1806 cli
->rap_error
= res
;
1808 if (res
== 0 || res
== ERRmoredata
) {
1811 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
1812 GETWORD(p
, count
,endp
);
1815 endp
= rdata
+ rdrcnt
;
1816 for (i
= 0;i
< count
&& p
< endp
;i
++, p
+= 16) {
1817 char ret_server
[RAP_MACHNAME_LEN
];
1819 p
+= rap_getstringf(p
,
1824 if (strequal(ret_server
, cli
->desthost
)) {
1825 found_server
= true;
1830 DEBUG(4,("cli_ns_check_server_type: machine %s failed the NetServerEnum call. "
1831 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1838 return found_server
;
1841 /****************************************************************************
1842 Perform a NetWkstaUserLogoff.
1843 ****************************************************************************/
1845 bool cli_NetWkstaUserLogoff(struct cli_state
*cli
, const char *user
, const char *workstation
)
1847 char *rparam
= NULL
;
1850 unsigned int rdrcnt
,rprcnt
;
1851 char param
[WORDSIZE
/* api number */
1852 +sizeof(RAP_NetWkstaUserLogoff_REQ
) /* req string */
1853 +sizeof(RAP_USER_LOGOFF_INFO_L1
) /* return string */
1854 +RAP_USERNAME_LEN
+1 /* user name+pad */
1855 +RAP_MACHNAME_LEN
/* wksta name */
1856 +WORDSIZE
/* buffer size */
1857 +WORDSIZE
]; /* buffer size? */
1858 char upperbuf
[MAX(RAP_USERNAME_LEN
,RAP_MACHNAME_LEN
)];
1862 memset(param
, 0, sizeof(param
));
1864 /* send a SMBtrans command with api NetWkstaUserLogoff */
1865 p
= make_header(param
, RAP_WWkstaUserLogoff
,
1866 RAP_NetWkstaUserLogoff_REQ
, RAP_USER_LOGOFF_INFO_L1
);
1867 PUTDWORD(p
, 0); /* Null pointer */
1868 PUTDWORD(p
, 0); /* Null pointer */
1869 strlcpy(upperbuf
, user
, sizeof(upperbuf
));
1870 strupper_m(upperbuf
);
1872 PUTSTRINGF(p
, tmp
, RAP_USERNAME_LEN
);
1873 p
++; /* strange format, but ok */
1874 strlcpy(upperbuf
, workstation
, sizeof(upperbuf
));
1875 strupper_m(upperbuf
);
1877 PUTSTRINGF(p
, tmp
, RAP_MACHNAME_LEN
);
1878 PUTWORD(p
, CLI_BUFFER_SIZE
);
1879 PUTWORD(p
, CLI_BUFFER_SIZE
);
1882 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
1883 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1884 &rparam
, &rprcnt
, /* return params, return size */
1885 &rdata
, &rdrcnt
/* return data, return size */
1887 char *endp
= rparam
+ rprcnt
;
1888 res
= GETRES(rparam
,endp
);
1889 cli
->rap_error
= res
;
1891 if (cli
->rap_error
!= 0) {
1892 DEBUG(4,("NetwkstaUserLogoff gave error %d\n", cli
->rap_error
));
1898 return (cli
->rap_error
== 0);
1901 int cli_NetPrintQEnum(struct cli_state
*cli
,
1902 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
1903 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
1905 char param
[WORDSIZE
/* api number */
1906 +sizeof(RAP_NetPrintQEnum_REQ
) /* req string */
1907 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
1908 +WORDSIZE
/* info level */
1909 +WORDSIZE
/* buffer size */
1910 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
1912 char *rparam
= NULL
;
1914 unsigned int rprcnt
, rdrcnt
;
1917 memset(param
, '\0',sizeof(param
));
1918 p
= make_header(param
, RAP_WPrintQEnum
,
1919 RAP_NetPrintQEnum_REQ
, RAP_PRINTQ_INFO_L2
);
1920 PUTWORD(p
,2); /* Info level 2 */
1921 PUTWORD(p
,0xFFE0); /* Return buffer size */
1922 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
1925 param
, PTR_DIFF(p
,param
),1024,
1926 NULL
, 0, CLI_BUFFER_SIZE
,
1929 char *endp
= rparam
+ rprcnt
;
1930 res
= GETRES(rparam
, endp
);
1931 cli
->rap_error
= res
;
1933 DEBUG(1,("NetPrintQEnum gave error %d\n", res
));
1938 DEBUG(4,("NetPrintQEnum no data returned\n"));
1942 if (res
== 0 || res
== ERRmoredata
) {
1943 TALLOC_CTX
*frame
= talloc_stackframe();
1944 char *endp
= rparam
+ rprcnt
;
1945 int i
, converter
= 0, count
= 0;
1947 p
= rparam
+ WORDSIZE
;
1948 GETWORD(p
, converter
, endp
);
1949 GETWORD(p
, count
, endp
);
1952 endp
= rdata
+ rdrcnt
;
1953 for (i
=0;i
<count
&& p
< endp
;i
++) {
1954 char qname
[RAP_SHARENAME_LEN
];
1955 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
1956 uint16_t jobcount
= 0, priority
= 0;
1957 uint16_t start_time
= 0, until_time
= 0, status
= 0;
1959 p
+= rap_getstringf(p
,
1965 GETWORD(p
, priority
, endp
);
1966 GETWORD(p
, start_time
, endp
);
1967 GETWORD(p
, until_time
, endp
);
1968 p
+= rap_getstringp(frame
,
1974 p
+= rap_getstringp(frame
,
1980 p
+= rap_getstringp(frame
,
1986 p
+= rap_getstringp(frame
,
1992 p
+= rap_getstringp(frame
,
1998 GETWORD(p
, status
, endp
);
1999 GETWORD(p
, jobcount
, endp
);
2001 if (sep_file
&& print_proc
&& dest
&& parms
&&
2003 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2004 dest
, parms
, comment
, status
, jobcount
);
2009 for (j
=0;j
<jobcount
;j
++) {
2010 uint16 jid
= 0, pos
= 0, fsstatus
= 0;
2011 char ownername
[RAP_USERNAME_LEN
];
2012 char notifyname
[RAP_MACHNAME_LEN
];
2013 char datatype
[RAP_DATATYPE_LEN
];
2014 char *jparms
, *jstatus
, *jcomment
;
2015 unsigned int submitted
= 0, jsize
= 0;
2017 GETWORD(p
, jid
, endp
);
2018 p
+= rap_getstringf(p
,
2024 p
+= rap_getstringf(p
,
2029 p
+= rap_getstringf(p
,
2034 p
+= rap_getstringp(frame
,
2040 GETWORD(p
, pos
, endp
);
2041 GETWORD(p
, fsstatus
, endp
);
2042 p
+= rap_getstringp(frame
,
2048 GETDWORD(p
, submitted
, endp
);
2049 GETDWORD(p
, jsize
, endp
);
2050 p
+= rap_getstringp(frame
,
2057 if (jparms
&& jstatus
&& jcomment
) {
2058 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2059 jstatus
, submitted
, jsize
, jcomment
);
2066 DEBUG(4,("NetPrintQEnum res=%d\n", res
));
2077 int cli_NetPrintQGetInfo(struct cli_state
*cli
, const char *printer
,
2078 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
2079 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
2081 char param
[WORDSIZE
/* api number */
2082 +sizeof(RAP_NetPrintQGetInfo_REQ
) /* req string */
2083 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
2084 +RAP_SHARENAME_LEN
/* printer name */
2085 +WORDSIZE
/* info level */
2086 +WORDSIZE
/* buffer size */
2087 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
2089 char *rparam
= NULL
;
2091 unsigned int rprcnt
, rdrcnt
;
2094 memset(param
, '\0',sizeof(param
));
2095 p
= make_header(param
, RAP_WPrintQGetInfo
,
2096 RAP_NetPrintQGetInfo_REQ
, RAP_PRINTQ_INFO_L2
);
2097 PUTSTRING(p
, printer
, RAP_SHARENAME_LEN
-1);
2098 PUTWORD(p
, 2); /* Info level 2 */
2099 PUTWORD(p
,0xFFE0); /* Return buffer size */
2100 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
2103 param
, PTR_DIFF(p
,param
),1024,
2104 NULL
, 0, CLI_BUFFER_SIZE
,
2107 char *endp
= rparam
+ rprcnt
;
2108 res
= GETRES(rparam
, endp
);
2109 cli
->rap_error
= res
;
2111 DEBUG(1,("NetPrintQGetInfo gave error %d\n", res
));
2116 DEBUG(4,("NetPrintQGetInfo no data returned\n"));
2120 if (res
== 0 || res
== ERRmoredata
) {
2121 TALLOC_CTX
*frame
= talloc_stackframe();
2122 char *endp
= rparam
+ rprcnt
;
2123 int rsize
= 0, converter
= 0;
2124 char qname
[RAP_SHARENAME_LEN
];
2125 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
2126 uint16_t jobcount
= 0, priority
= 0;
2127 uint16_t start_time
= 0, until_time
= 0, status
= 0;
2129 p
= rparam
+ WORDSIZE
;
2130 GETWORD(p
, converter
, endp
);
2131 GETWORD(p
, rsize
, endp
);
2134 endp
= rdata
+ rdrcnt
;
2135 p
+= rap_getstringf(p
,
2141 GETWORD(p
, priority
, endp
);
2142 GETWORD(p
, start_time
, endp
);
2143 GETWORD(p
, until_time
, endp
);
2144 p
+= rap_getstringp(frame
,
2150 p
+= rap_getstringp(frame
,
2156 p
+= rap_getstringp(frame
,
2162 p
+= rap_getstringp(frame
,
2168 p
+= rap_getstringp(frame
,
2174 GETWORD(p
, status
, endp
);
2175 GETWORD(p
, jobcount
, endp
);
2177 if (sep_file
&& print_proc
&& dest
&&
2179 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2180 dest
, parms
, comment
, status
, jobcount
);
2184 for (j
=0;(j
<jobcount
)&&(PTR_DIFF(p
,rdata
)< rsize
)&&
2186 uint16_t jid
= 0, pos
= 0, fsstatus
= 0;
2187 char ownername
[RAP_USERNAME_LEN
];
2188 char notifyname
[RAP_MACHNAME_LEN
];
2189 char datatype
[RAP_DATATYPE_LEN
];
2190 char *jparms
, *jstatus
, *jcomment
;
2191 unsigned int submitted
= 0, jsize
= 0;
2193 GETWORD(p
, jid
, endp
);
2194 p
+= rap_getstringf(p
,
2200 p
+= rap_getstringf(p
,
2205 p
+= rap_getstringf(p
,
2210 p
+= rap_getstringp(frame
,
2216 GETWORD(p
, pos
,endp
);
2217 GETWORD(p
, fsstatus
,endp
);
2218 p
+= rap_getstringp(frame
,
2224 GETDWORD(p
, submitted
,endp
);
2225 GETDWORD(p
, jsize
,endp
);
2226 p
+= rap_getstringp(frame
,
2233 if (jparms
&& jstatus
&& jcomment
) {
2234 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2235 jstatus
, submitted
, jsize
, jcomment
);
2241 DEBUG(4,("NetPrintQGetInfo res=%d\n", res
));
2252 /****************************************************************************
2253 Call a NetServiceEnum - list running services on a different host.
2254 ****************************************************************************/
2256 int cli_RNetServiceEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
2258 char param
[WORDSIZE
/* api number */
2259 +sizeof(RAP_NetServiceEnum_REQ
) /* parm string */
2260 +sizeof(RAP_SERVICE_INFO_L2
) /* return string */
2261 +WORDSIZE
/* info level */
2262 +WORDSIZE
]; /* buffer size */
2264 char *rparam
= NULL
;
2266 unsigned int rprcnt
, rdrcnt
;
2269 memset(param
, '\0', sizeof(param
));
2270 p
= make_header(param
, RAP_WServiceEnum
,
2271 RAP_NetServiceEnum_REQ
, RAP_SERVICE_INFO_L2
);
2272 PUTWORD(p
,2); /* Info level 2 */
2273 PUTWORD(p
,0xFFE0); /* Return buffer size */
2276 param
, PTR_DIFF(p
,param
),8,
2277 NULL
, 0, 0xFFE0 /* data area size */,
2280 char *endp
= rparam
+ rprcnt
;
2281 res
= GETRES(rparam
, endp
);
2282 cli
->rap_error
= res
;
2283 if(cli
->rap_error
== 234) {
2284 DEBUG(1,("Not all service names were returned (such as those longer than 15 characters)\n"));
2285 } else if (cli
->rap_error
!= 0) {
2286 DEBUG(1,("NetServiceEnum gave error %d\n", cli
->rap_error
));
2291 DEBUG(4,("NetServiceEnum no data returned\n"));
2295 if (res
== 0 || res
== ERRmoredata
) {
2296 char *endp
= rparam
+ rprcnt
;
2299 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
2300 GETWORD(p
, count
,endp
);
2302 endp
= rdata
+ rdrcnt
;
2303 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2304 char comment
[RAP_SRVCCMNT_LEN
];
2305 char servicename
[RAP_SRVCNAME_LEN
];
2307 p
+= rap_getstringf(p
,
2312 p
+=8; /* pass status words */
2313 p
+= rap_getstringf(p
,
2319 if (servicename
[0]) {
2320 fn(servicename
, comment
, cli
); /* BB add status too */
2324 DEBUG(4,("NetServiceEnum res=%d\n", res
));
2335 /****************************************************************************
2336 Call a NetSessionEnum - list workstations with sessions to an SMB server.
2337 ****************************************************************************/
2339 int cli_NetSessionEnum(struct cli_state
*cli
, void (*fn
)(char *, char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, char *))
2341 char param
[WORDSIZE
/* api number */
2342 +sizeof(RAP_NetSessionEnum_REQ
) /* parm string */
2343 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2344 +WORDSIZE
/* info level */
2345 +WORDSIZE
]; /* buffer size */
2347 char *rparam
= NULL
;
2349 unsigned int rprcnt
, rdrcnt
;
2352 memset(param
, '\0', sizeof(param
));
2353 p
= make_header(param
, RAP_WsessionEnum
,
2354 RAP_NetSessionEnum_REQ
, RAP_SESSION_INFO_L2
);
2355 PUTWORD(p
,2); /* Info level 2 */
2356 PUTWORD(p
,0xFF); /* Return buffer size */
2359 param
, PTR_DIFF(p
,param
),8,
2360 NULL
, 0, CLI_BUFFER_SIZE
,
2363 char *endp
= rparam
+ rprcnt
;
2364 res
= GETRES(rparam
, endp
);
2365 cli
->rap_error
= res
;
2367 DEBUG(1,("NetSessionEnum gave error %d\n", res
));
2372 DEBUG(4,("NetSesssionEnum no data returned\n"));
2376 if (res
== 0 || res
== ERRmoredata
) {
2377 TALLOC_CTX
*frame
= talloc_stackframe();
2378 char *endp
= rparam
+ rprcnt
;
2379 int i
, converter
= 0, count
= 0;
2381 p
= rparam
+ WORDSIZE
;
2382 GETWORD(p
, converter
, endp
);
2383 GETWORD(p
, count
, endp
);
2385 endp
= rdata
+ rdrcnt
;
2386 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2387 char *wsname
, *username
, *clitype_name
;
2388 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2389 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2391 p
+= rap_getstringp(frame
,
2397 p
+= rap_getstringp(frame
,
2403 GETWORD(p
, num_conns
, endp
);
2404 GETWORD(p
, num_opens
, endp
);
2405 GETWORD(p
, num_users
, endp
);
2406 GETDWORD(p
, sess_time
, endp
);
2407 GETDWORD(p
, idle_time
, endp
);
2408 GETDWORD(p
, user_flags
, endp
);
2409 p
+= rap_getstringp(frame
,
2416 if (wsname
&& username
&& clitype_name
) {
2417 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2418 idle_time
, user_flags
, clitype_name
);
2423 DEBUG(4,("NetSessionEnum res=%d\n", res
));
2434 /****************************************************************************
2435 Call a NetSessionGetInfo - get information about other session to an SMB server.
2436 ****************************************************************************/
2438 int cli_NetSessionGetInfo(struct cli_state
*cli
, const char *workstation
,
2439 void (*fn
)(const char *, const char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, const char *))
2441 char param
[WORDSIZE
/* api number */
2442 +sizeof(RAP_NetSessionGetInfo_REQ
) /* req string */
2443 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2444 +RAP_MACHNAME_LEN
/* wksta name */
2445 +WORDSIZE
/* info level */
2446 +WORDSIZE
]; /* buffer size */
2448 char *rparam
= NULL
;
2450 unsigned int rprcnt
, rdrcnt
;
2454 memset(param
, '\0', sizeof(param
));
2455 p
= make_header(param
, RAP_WsessionGetInfo
,
2456 RAP_NetSessionGetInfo_REQ
, RAP_SESSION_INFO_L2
);
2457 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2458 PUTWORD(p
,2); /* Info level 2 */
2459 PUTWORD(p
,0xFF); /* Return buffer size */
2462 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2463 NULL
, 0, CLI_BUFFER_SIZE
,
2466 endp
= rparam
+ rprcnt
;
2467 res
= GETRES(rparam
, endp
);
2468 cli
->rap_error
= res
;
2469 if (cli
->rap_error
!= 0) {
2470 DEBUG(1,("NetSessionGetInfo gave error %d\n", cli
->rap_error
));
2475 DEBUG(4,("NetSessionGetInfo no data returned\n"));
2479 endp
= rparam
+ rprcnt
;
2480 res
= GETRES(rparam
, endp
);
2482 if (res
== 0 || res
== ERRmoredata
) {
2483 TALLOC_CTX
*frame
= talloc_stackframe();
2485 char *wsname
, *username
, *clitype_name
;
2486 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2487 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2489 p
= rparam
+ WORDSIZE
;
2490 GETWORD(p
, converter
,endp
);
2491 p
+= WORDSIZE
; /* skip rsize */
2494 endp
= rdata
+ rdrcnt
;
2495 p
+= rap_getstringp(frame
,
2501 p
+= rap_getstringp(frame
,
2507 GETWORD(p
, num_conns
, endp
);
2508 GETWORD(p
, num_opens
, endp
);
2509 GETWORD(p
, num_users
, endp
);
2510 GETDWORD(p
, sess_time
, endp
);
2511 GETDWORD(p
, idle_time
, endp
);
2512 GETDWORD(p
, user_flags
, endp
);
2513 p
+= rap_getstringp(frame
,
2520 if (wsname
&& username
&& clitype_name
) {
2521 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2522 idle_time
, user_flags
, clitype_name
);
2526 DEBUG(4,("NetSessionGetInfo res=%d\n", res
));
2537 /****************************************************************************
2538 Call a NetSessionDel - close a session to an SMB server.
2539 ****************************************************************************/
2541 int cli_NetSessionDel(struct cli_state
*cli
, const char *workstation
)
2543 char param
[WORDSIZE
/* api number */
2544 +sizeof(RAP_NetSessionDel_REQ
) /* req string */
2545 +1 /* no return string */
2546 +RAP_MACHNAME_LEN
/* workstation name */
2547 +WORDSIZE
]; /* reserved (0) */
2549 char *rparam
= NULL
;
2551 unsigned int rprcnt
, rdrcnt
;
2554 memset(param
, '\0', sizeof(param
));
2555 p
= make_header(param
, RAP_WsessionDel
, RAP_NetSessionDel_REQ
, NULL
);
2556 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2557 PUTWORD(p
,0); /* reserved word of 0 */
2560 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
2561 NULL
, 0, 200, /* data, length, maxlen */
2562 &rparam
, &rprcnt
, /* return params, length */
2563 &rdata
, &rdrcnt
)) /* return data, length */
2565 char *endp
= rparam
+ rprcnt
;
2566 res
= GETRES(rparam
, endp
);
2567 cli
->rap_error
= res
;
2572 DEBUG(4,("NetFileClose2 res=%d\n", res
));
2576 DEBUG(4,("NetFileClose2 failed\n"));
2585 int cli_NetConnectionEnum(struct cli_state
*cli
, const char *qualifier
,
2586 void (*fn
)(uint16_t conid
, uint16_t contype
,
2587 uint16_t numopens
, uint16_t numusers
,
2588 uint32_t contime
, const char *username
,
2589 const char *netname
))
2591 char param
[WORDSIZE
/* api number */
2592 +sizeof(RAP_NetConnectionEnum_REQ
) /* req string */
2593 +sizeof(RAP_CONNECTION_INFO_L1
) /* return string */
2594 +RAP_MACHNAME_LEN
/* wksta name */
2595 +WORDSIZE
/* info level */
2596 +WORDSIZE
]; /* buffer size */
2598 char *rparam
= NULL
;
2600 unsigned int rprcnt
, rdrcnt
;
2603 memset(param
, '\0', sizeof(param
));
2604 p
= make_header(param
, RAP_WconnectionEnum
,
2605 RAP_NetConnectionEnum_REQ
, RAP_CONNECTION_INFO_L1
);
2606 PUTSTRING(p
, qualifier
, RAP_MACHNAME_LEN
-1);/* Workstation name */
2607 PUTWORD(p
,1); /* Info level 1 */
2608 PUTWORD(p
,0xFFE0); /* Return buffer size */
2611 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2612 NULL
, 0, CLI_BUFFER_SIZE
,
2615 char *endp
= rparam
+ rprcnt
;
2616 res
= GETRES(rparam
, endp
);
2617 cli
->rap_error
= res
;
2619 DEBUG(1,("NetConnectionEnum gave error %d\n", res
));
2624 DEBUG(4,("NetConnectionEnum no data returned\n"));
2628 if (res
== 0 || res
== ERRmoredata
) {
2629 TALLOC_CTX
*frame
= talloc_stackframe();
2630 char *endp
= rparam
+ rprcnt
;
2631 int i
, converter
= 0, count
= 0;
2633 p
= rparam
+ WORDSIZE
;
2634 GETWORD(p
, converter
, endp
);
2635 GETWORD(p
, count
, endp
);
2637 endp
= rdata
+ rdrcnt
;
2638 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2639 char *netname
, *username
;
2640 uint16_t conn_id
= 0, conn_type
= 0, num_opens
= 0, num_users
= 0;
2641 unsigned int conn_time
= 0;
2643 GETWORD(p
,conn_id
, endp
);
2644 GETWORD(p
,conn_type
, endp
);
2645 GETWORD(p
,num_opens
, endp
);
2646 GETWORD(p
,num_users
, endp
);
2647 GETDWORD(p
,conn_time
, endp
);
2648 p
+= rap_getstringp(frame
,
2654 p
+= rap_getstringp(frame
,
2661 if (username
&& netname
) {
2662 fn(conn_id
, conn_type
, num_opens
, num_users
, conn_time
,
2668 DEBUG(4,("NetConnectionEnum res=%d\n", res
));