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"
80 #include "../librpc/gen_ndr/svcctl.h"
85 #define PUTBYTE(p,b) do {SCVAL(p,0,b); p++;} while(0)
87 #define GETBYTE(p,b,endp) \
95 #define PUTWORD(p,w) do {SSVAL(p,0,w); p += WORDSIZE;} while(0)
97 #define GETWORD(p,w,endp) \
99 if (p+WORDSIZE < endp) {\
105 #define PUTDWORD(p,d) do {SIVAL(p,0,d); p += DWORDSIZE;} while(0)
107 #define GETDWORD(p,d,endp) \
109 if (p+DWORDSIZE < endp) {\
115 #define GETRES(p,endp) ((p && p+2 < endp) ? SVAL(p,0) : -1)
117 /* put string s at p with max len n and increment p past string */
118 #define PUTSTRING(p,s,n) \
120 push_ascii(p,s?s:"",n?n:256,STR_TERMINATE);\
121 p = push_skip_string(p);\
124 /* put string s and p, using fixed len l, and increment p by l */
125 #define PUTSTRINGF(p,s,l) \
127 push_ascii(p,s?s:"",l,STR_TERMINATE);\
131 /* put string pointer at p, supplying offset o from rdata r, store */
132 /* dword offset at p, increment p by 4 and o by length of s. This */
133 /* means on the first call, you must calc the offset yourself! */
135 #define PUTSTRINGP(p,s,r,o) \
138 push_ascii(r+o,s,strlen(s)+1,STR_TERMINATE);\
146 /* get asciiz string dest from src, return increment past string */
148 static size_t rap_getstring(TALLOC_CTX
*ctx
, char *src
, char **dest
, const char *endp
)
154 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++)
159 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
163 /* get fixed length l string dest from src, return increment for src */
165 static size_t rap_getstringf(char *src
, char *dest
, size_t l
, size_t dlen
, char *endp
)
173 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
183 pull_ascii(dest
,src
,len
,len
,STR_ASCII
);
188 /* get string dest from offset (obtained at p) from rdata r - converter c */
189 static size_t rap_getstringp(TALLOC_CTX
*ctx
, char *p
, char **dest
, char *r
, uint16_t c
, char *endp
)
197 GETDWORD(p
,off
,endp
);
198 off
&= 0x0000FFFF; /* mask the obsolete segment number from the offset */
201 if (r
+off
> endp
|| r
+off
< r
) {
207 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
214 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
218 static char *make_header(char *param
, uint16 apinum
, const char *reqfmt
, const char *datafmt
)
220 PUTWORD(param
,apinum
);
222 PUTSTRING(param
,reqfmt
,0);
227 PUTSTRING(param
,datafmt
,0);
234 /****************************************************************************
235 call a NetGroupDelete - delete user group from remote server
236 ****************************************************************************/
238 int cli_NetGroupDelete(struct cli_state
*cli
, const char *group_name
)
243 unsigned int rdrcnt
,rprcnt
;
245 char param
[WORDSIZE
/* api number */
246 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
247 +1 /* no ret string */
248 +RAP_GROUPNAME_LEN
/* group to del */
249 +WORDSIZE
]; /* reserved word */
251 /* now send a SMBtrans command with api GroupDel */
252 p
= make_header(param
, RAP_WGroupDel
, RAP_NetGroupDel_REQ
, NULL
);
253 PUTSTRING(p
, group_name
, RAP_GROUPNAME_LEN
);
254 PUTWORD(p
,0); /* reserved word MBZ on input */
257 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
258 NULL
, 0, 200, /* data, length, maxlen */
259 &rparam
, &rprcnt
, /* return params, length */
260 &rdata
, &rdrcnt
)) /* return data, length */
262 char *endp
= rparam
+ rprcnt
;
263 res
= GETRES(rparam
,endp
);
267 } else if ((res
== 5) || (res
== 65)) {
268 DEBUG(1, ("Access Denied\n"));
269 } else if (res
== 2220) {
270 DEBUG (1, ("Group does not exist\n"));
272 DEBUG(4,("NetGroupDelete res=%d\n", res
));
276 DEBUG(4,("NetGroupDelete failed\n"));
285 /****************************************************************************
286 call a NetGroupAdd - add user group to remote server
287 ****************************************************************************/
289 int cli_NetGroupAdd(struct cli_state
*cli
, struct rap_group_info_1
*grinfo
)
294 unsigned int rdrcnt
,rprcnt
;
296 char param
[WORDSIZE
/* api number */
297 +sizeof(RAP_NetGroupAdd_REQ
) /* req string */
298 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
299 +WORDSIZE
/* info level */
300 +WORDSIZE
]; /* reserved word */
302 /* offset into data of free format strings. Will be updated */
303 /* by PUTSTRINGP macro and end up with total data length. */
304 int soffset
= RAP_GROUPNAME_LEN
+ 1 + DWORDSIZE
;
309 data_size
= MAX(soffset
+ strlen(grinfo
->comment
) + 1, 1024);
311 data
= SMB_MALLOC_ARRAY(char, data_size
);
313 DEBUG (1, ("Malloc fail\n"));
317 /* now send a SMBtrans command with api WGroupAdd */
319 p
= make_header(param
, RAP_WGroupAdd
,
320 RAP_NetGroupAdd_REQ
, RAP_GROUP_INFO_L1
);
321 PUTWORD(p
, 1); /* info level */
322 PUTWORD(p
, 0); /* reserved word 0 */
325 PUTSTRINGF(p
, (const char *)grinfo
->group_name
, RAP_GROUPNAME_LEN
);
326 PUTBYTE(p
, 0); /* pad byte 0 */
327 PUTSTRINGP(p
, grinfo
->comment
, data
, soffset
);
330 param
, sizeof(param
), 1024, /* Param, length, maxlen */
331 data
, soffset
, sizeof(data
), /* data, length, maxlen */
332 &rparam
, &rprcnt
, /* return params, length */
333 &rdata
, &rdrcnt
)) /* return data, length */
335 char *endp
= rparam
+ rprcnt
;
336 res
= GETRES(rparam
, endp
);
340 } else if ((res
== 5) || (res
== 65)) {
341 DEBUG(1, ("Access Denied\n"));
342 } else if (res
== 2223) {
343 DEBUG (1, ("Group already exists\n"));
345 DEBUG(4,("NetGroupAdd res=%d\n", res
));
349 DEBUG(4,("NetGroupAdd failed\n"));
359 /****************************************************************************
360 Call a NetGroupEnum - try and list user groups on a different host.
361 ****************************************************************************/
363 int cli_RNetGroupEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
365 char param
[WORDSIZE
/* api number */
366 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
367 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
368 +WORDSIZE
/* info level */
369 +WORDSIZE
]; /* buffer size */
373 unsigned int rprcnt
, rdrcnt
;
376 memset(param
, '\0', sizeof(param
));
377 p
= make_header(param
, RAP_WGroupEnum
,
378 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L1
);
379 PUTWORD(p
,1); /* Info level 1 */ /* add level 0 */
380 PUTWORD(p
,0xFFE0); /* Return buffer size */
383 param
, PTR_DIFF(p
,param
),8,
384 NULL
, 0, 0xFFE0 /* data area size */,
387 char *endp
= rparam
+ rdrcnt
;
389 res
= GETRES(rparam
, endp
);
390 cli
->rap_error
= res
;
391 if(cli
->rap_error
== 234) {
392 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
393 } else if (cli
->rap_error
!= 0) {
394 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
399 DEBUG(4,("NetGroupEnum no data returned\n"));
403 if (res
== 0 || res
== ERRmoredata
) {
404 char *endp
= rparam
+ rprcnt
;
405 int i
, converter
= 0, count
= 0;
406 TALLOC_CTX
*frame
= talloc_stackframe();
408 p
= rparam
+ WORDSIZE
; /* skip result */
409 GETWORD(p
, converter
, endp
);
410 GETWORD(p
, count
, endp
);
412 endp
= rdata
+ rdrcnt
;
413 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
414 char *comment
= NULL
;
415 char groupname
[RAP_GROUPNAME_LEN
];
417 p
+= rap_getstringf(p
,
423 p
+= rap_getstringp(frame
,
430 if (!comment
|| !groupname
[0]) {
434 fn(groupname
, comment
, cli
);
438 DEBUG(4,("NetGroupEnum res=%d\n", res
));
449 int cli_RNetGroupEnum0(struct cli_state
*cli
,
450 void (*fn
)(const char *, void *),
453 char param
[WORDSIZE
/* api number */
454 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
455 +sizeof(RAP_GROUP_INFO_L0
) /* return string */
456 +WORDSIZE
/* info level */
457 +WORDSIZE
]; /* buffer size */
461 unsigned int rprcnt
, rdrcnt
;
464 memset(param
, '\0', sizeof(param
));
465 p
= make_header(param
, RAP_WGroupEnum
,
466 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L0
);
467 PUTWORD(p
,0); /* Info level 0 */ /* Hmmm. I *very* much suspect this
468 is the resume count, at least
469 that's what smbd believes... */
470 PUTWORD(p
,0xFFE0); /* Return buffer size */
473 param
, PTR_DIFF(p
,param
),8,
474 NULL
, 0, 0xFFE0 /* data area size */,
477 char *endp
= rparam
+rprcnt
;
478 res
= GETRES(rparam
,endp
);
479 cli
->rap_error
= res
;
480 if(cli
->rap_error
== 234) {
481 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
482 } else if (cli
->rap_error
!= 0) {
483 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
488 DEBUG(4,("NetGroupEnum no data returned\n"));
492 if (res
== 0 || res
== ERRmoredata
) {
493 char *endp
= rparam
+ rprcnt
;
496 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
497 GETWORD(p
, count
, endp
);
499 endp
= rdata
+ rdrcnt
;
500 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
501 char groupname
[RAP_GROUPNAME_LEN
];
503 p
+= rap_getstringf(p
,
513 DEBUG(4,("NetGroupEnum res=%d\n", res
));
524 int cli_NetGroupDelUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
529 unsigned int rdrcnt
,rprcnt
;
531 char param
[WORDSIZE
/* api number */
532 +sizeof(RAP_NetGroupDelUser_REQ
) /* parm string */
533 +1 /* no ret string */
534 +RAP_GROUPNAME_LEN
/* group name */
535 +RAP_USERNAME_LEN
]; /* user to del */
537 /* now send a SMBtrans command with api GroupMemberAdd */
538 p
= make_header(param
, RAP_WGroupDelUser
, RAP_NetGroupDelUser_REQ
, NULL
);
539 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
540 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
543 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
544 NULL
, 0, 200, /* data, length, maxlen */
545 &rparam
, &rprcnt
, /* return params, length */
546 &rdata
, &rdrcnt
)) /* return data, length */
548 char *endp
= rparam
+ rprcnt
;
549 res
= GETRES(rparam
,endp
);
556 DEBUG(1, ("Access Denied\n"));
559 DEBUG(1, ("Not supported by server\n"));
562 DEBUG(1, ("Group does not exist\n"));
565 DEBUG(1, ("User does not exist\n"));
568 DEBUG(1, ("User is not in group\n"));
571 DEBUG(4,("NetGroupDelUser res=%d\n", res
));
575 DEBUG(4,("NetGroupDelUser failed\n"));
584 int cli_NetGroupAddUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
589 unsigned int rdrcnt
,rprcnt
;
591 char param
[WORDSIZE
/* api number */
592 +sizeof(RAP_NetGroupAddUser_REQ
) /* parm string */
593 +1 /* no ret string */
594 +RAP_GROUPNAME_LEN
/* group name */
595 +RAP_USERNAME_LEN
]; /* user to add */
597 /* now send a SMBtrans command with api GroupMemberAdd */
598 p
= make_header(param
, RAP_WGroupAddUser
, RAP_NetGroupAddUser_REQ
, NULL
);
599 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
600 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
603 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
604 NULL
, 0, 200, /* data, length, maxlen */
605 &rparam
, &rprcnt
, /* return params, length */
606 &rdata
, &rdrcnt
)) /* return data, length */
608 char *endp
= rparam
+ rprcnt
;
609 res
= GETRES(rparam
,endp
);
616 DEBUG(1, ("Access Denied\n"));
619 DEBUG(1, ("Not supported by server\n"));
622 DEBUG(1, ("Group does not exist\n"));
625 DEBUG(1, ("User does not exist\n"));
628 DEBUG(4,("NetGroupAddUser res=%d\n", res
));
632 DEBUG(4,("NetGroupAddUser failed\n"));
642 int cli_NetGroupGetUsers(struct cli_state
* cli
, const char *group_name
, void (*fn
)(const char *, void *), void *state
)
647 unsigned int rdrcnt
,rprcnt
;
649 char param
[WORDSIZE
/* api number */
650 +sizeof(RAP_NetGroupGetUsers_REQ
)/* parm string */
651 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
652 +RAP_GROUPNAME_LEN
/* group name */
653 +WORDSIZE
/* info level */
654 +WORDSIZE
]; /* buffer size */
656 /* now send a SMBtrans command with api GroupGetUsers */
657 p
= make_header(param
, RAP_WGroupGetUsers
,
658 RAP_NetGroupGetUsers_REQ
, RAP_GROUP_USERS_INFO_0
);
659 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
-1);
660 PUTWORD(p
,0); /* info level 0 */
661 PUTWORD(p
,0xFFE0); /* return buffer size */
664 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
665 NULL
, 0, CLI_BUFFER_SIZE
,
668 char *endp
= rparam
+ rprcnt
;
669 res
= GETRES(rparam
,endp
);
670 cli
->rap_error
= res
;
672 DEBUG(1,("NetGroupGetUsers gave error %d\n", res
));
677 DEBUG(4,("NetGroupGetUsers no data returned\n"));
681 if (res
== 0 || res
== ERRmoredata
) {
682 char *endp
= rparam
+ rprcnt
;
684 char username
[RAP_USERNAME_LEN
];
686 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
687 GETWORD(p
, count
, endp
);
689 endp
= rdata
+ rdrcnt
;
690 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
691 p
+= rap_getstringf(p
,
701 DEBUG(4,("NetGroupGetUsers res=%d\n", res
));
711 int cli_NetUserGetGroups(struct cli_state
* cli
, const char *user_name
, void (*fn
)(const char *, void *), void *state
)
716 unsigned int rdrcnt
,rprcnt
;
718 char param
[WORDSIZE
/* api number */
719 +sizeof(RAP_NetUserGetGroups_REQ
)/* parm string */
720 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
721 +RAP_USERNAME_LEN
/* user name */
722 +WORDSIZE
/* info level */
723 +WORDSIZE
]; /* buffer size */
725 /* now send a SMBtrans command with api GroupGetUsers */
726 p
= make_header(param
, RAP_WUserGetGroups
,
727 RAP_NetUserGetGroups_REQ
, RAP_GROUP_USERS_INFO_0
);
728 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
-1);
729 PUTWORD(p
,0); /* info level 0 */
730 PUTWORD(p
,0xFFE0); /* return buffer size */
733 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
734 NULL
, 0, CLI_BUFFER_SIZE
,
737 char *endp
= rparam
+ rprcnt
;
738 res
= GETRES(rparam
,endp
);
739 cli
->rap_error
= res
;
741 DEBUG(1,("NetUserGetGroups gave error %d\n", res
));
746 DEBUG(4,("NetUserGetGroups no data returned\n"));
750 if (res
== 0 || res
== ERRmoredata
) {
751 char *endp
= rparam
+ rprcnt
;
753 char groupname
[RAP_GROUPNAME_LEN
];
755 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
756 GETWORD(p
, count
, endp
);
758 endp
= rdata
+ rdrcnt
;
759 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
760 p
+= rap_getstringf(p
,
766 fn(groupname
, state
);
770 DEBUG(4,("NetUserGetGroups res=%d\n", res
));
780 /****************************************************************************
781 Call a NetUserDelete - delete user from remote server.
782 ****************************************************************************/
784 int cli_NetUserDelete(struct cli_state
*cli
, const char * user_name
)
789 unsigned int rdrcnt
,rprcnt
;
791 char param
[WORDSIZE
/* api number */
792 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
793 +1 /* no ret string */
794 +RAP_USERNAME_LEN
/* user to del */
795 +WORDSIZE
]; /* reserved word */
797 /* now send a SMBtrans command with api UserDel */
798 p
= make_header(param
, RAP_WUserDel
, RAP_NetGroupDel_REQ
, NULL
);
799 PUTSTRING(p
, user_name
, RAP_USERNAME_LEN
);
800 PUTWORD(p
,0); /* reserved word MBZ on input */
803 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
804 NULL
, 0, 200, /* data, length, maxlen */
805 &rparam
, &rprcnt
, /* return params, length */
806 &rdata
, &rdrcnt
)) /* return data, length */
808 char *endp
= rparam
+ rprcnt
;
809 res
= GETRES(rparam
,endp
);
813 } else if ((res
== 5) || (res
== 65)) {
814 DEBUG(1, ("Access Denied\n"));
815 } else if (res
== 2221) {
816 DEBUG (1, ("User does not exist\n"));
818 DEBUG(4,("NetUserDelete res=%d\n", res
));
822 DEBUG(4,("NetUserDelete failed\n"));
831 /****************************************************************************
832 Call a NetUserAdd - add user to remote server.
833 ****************************************************************************/
835 int cli_NetUserAdd(struct cli_state
*cli
, struct rap_user_info_1
* userinfo
)
840 unsigned int rdrcnt
,rprcnt
;
842 char param
[WORDSIZE
/* api number */
843 +sizeof(RAP_NetUserAdd2_REQ
) /* req string */
844 +sizeof(RAP_USER_INFO_L1
) /* data string */
845 +WORDSIZE
/* info level */
846 +WORDSIZE
/* buffer length */
847 +WORDSIZE
]; /* reserved */
850 /* offset into data of free format strings. Will be updated */
851 /* by PUTSTRINGP macro and end up with total data length. */
852 int soffset
=RAP_USERNAME_LEN
+1 /* user name + pad */
853 + RAP_UPASSWD_LEN
/* password */
854 + DWORDSIZE
/* password age */
855 + WORDSIZE
/* privilege */
856 + DWORDSIZE
/* home dir ptr */
857 + DWORDSIZE
/* comment ptr */
858 + WORDSIZE
/* flags */
859 + DWORDSIZE
; /* login script ptr*/
861 /* now send a SMBtrans command with api NetUserAdd */
862 p
= make_header(param
, RAP_WUserAdd2
,
863 RAP_NetUserAdd2_REQ
, RAP_USER_INFO_L1
);
865 PUTWORD(p
, 1); /* info level */
866 PUTWORD(p
, 0); /* pwencrypt */
867 if(userinfo
->passwrd
)
868 PUTWORD(p
,MIN(strlen((const char *)userinfo
->passwrd
), RAP_UPASSWD_LEN
));
870 PUTWORD(p
, 0); /* password length */
873 memset(data
, '\0', soffset
);
875 PUTSTRINGF(p
, (const char *)userinfo
->user_name
, RAP_USERNAME_LEN
);
876 PUTBYTE(p
, 0); /* pad byte 0 */
877 PUTSTRINGF(p
, (const char *)userinfo
->passwrd
, RAP_UPASSWD_LEN
);
878 PUTDWORD(p
, 0); /* pw age - n.a. on user add */
879 PUTWORD(p
, userinfo
->priv
);
880 PUTSTRINGP(p
, userinfo
->home_dir
, data
, soffset
);
881 PUTSTRINGP(p
, userinfo
->comment
, data
, soffset
);
882 PUTWORD(p
, userinfo
->userflags
);
883 PUTSTRINGP(p
, userinfo
->logon_script
, data
, soffset
);
886 param
, sizeof(param
), 1024, /* Param, length, maxlen */
887 data
, soffset
, sizeof(data
), /* data, length, maxlen */
888 &rparam
, &rprcnt
, /* return params, length */
889 &rdata
, &rdrcnt
)) /* return data, length */
891 char *endp
= rparam
+ rprcnt
;
892 res
= GETRES(rparam
, endp
);
896 } else if ((res
== 5) || (res
== 65)) {
897 DEBUG(1, ("Access Denied\n"));
898 } else if (res
== 2224) {
899 DEBUG (1, ("User already exists\n"));
901 DEBUG(4,("NetUserAdd res=%d\n", res
));
905 DEBUG(4,("NetUserAdd failed\n"));
914 /****************************************************************************
915 call a NetUserEnum - try and list users on a different host
916 ****************************************************************************/
918 int cli_RNetUserEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, const char *, const char *, void *), void *state
)
920 char param
[WORDSIZE
/* api number */
921 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
922 +sizeof(RAP_USER_INFO_L1
) /* return string */
923 +WORDSIZE
/* info level */
924 +WORDSIZE
]; /* buffer size */
928 unsigned int rprcnt
, rdrcnt
;
931 memset(param
, '\0', sizeof(param
));
932 p
= make_header(param
, RAP_WUserEnum
,
933 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L1
);
934 PUTWORD(p
,1); /* Info level 1 */
935 PUTWORD(p
,0xFF00); /* Return buffer size */
937 /* BB Fix handling of large numbers of users to be returned */
939 param
, PTR_DIFF(p
,param
),8,
940 NULL
, 0, CLI_BUFFER_SIZE
,
943 char *endp
= rparam
+ rprcnt
;
944 res
= GETRES(rparam
,endp
);
945 cli
->rap_error
= res
;
946 if (cli
->rap_error
!= 0) {
947 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
952 DEBUG(4,("NetUserEnum no data returned\n"));
956 if (res
== 0 || res
== ERRmoredata
) {
957 int i
, converter
= 0, count
= 0;
958 char username
[RAP_USERNAME_LEN
];
959 char userpw
[RAP_UPASSWD_LEN
];
960 char *endp
= rparam
+ rprcnt
;
961 char *comment
, *homedir
, *logonscript
;
962 TALLOC_CTX
*frame
= talloc_stackframe();
964 p
= rparam
+ WORDSIZE
; /* skip result */
965 GETWORD(p
, converter
, endp
);
966 GETWORD(p
, count
, endp
);
968 endp
= rdata
+ rdrcnt
;
969 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
970 p
+= rap_getstringf(p
,
976 p
+= rap_getstringf(p
,
981 p
+= DWORDSIZE
; /* skip password age */
982 p
+= WORDSIZE
; /* skip priv: 0=guest, 1=user, 2=admin */
983 p
+= rap_getstringp(frame
,
989 p
+= rap_getstringp(frame
,
995 p
+= WORDSIZE
; /* skip flags */
996 p
+= rap_getstringp(frame
,
1002 if (username
[0] && comment
&&
1003 homedir
&& logonscript
) {
1013 DEBUG(4,("NetUserEnum res=%d\n", res
));
1024 int cli_RNetUserEnum0(struct cli_state
*cli
,
1025 void (*fn
)(const char *, void *),
1028 char param
[WORDSIZE
/* api number */
1029 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
1030 +sizeof(RAP_USER_INFO_L0
) /* return string */
1031 +WORDSIZE
/* info level */
1032 +WORDSIZE
]; /* buffer size */
1034 char *rparam
= NULL
;
1036 unsigned int rprcnt
, rdrcnt
;
1039 memset(param
, '\0', sizeof(param
));
1040 p
= make_header(param
, RAP_WUserEnum
,
1041 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L0
);
1042 PUTWORD(p
,0); /* Info level 1 */
1043 PUTWORD(p
,0xFF00); /* Return buffer size */
1045 /* BB Fix handling of large numbers of users to be returned */
1047 param
, PTR_DIFF(p
,param
),8,
1048 NULL
, 0, CLI_BUFFER_SIZE
,
1051 char *endp
= rparam
+ rprcnt
;
1052 res
= GETRES(rparam
,endp
);
1053 cli
->rap_error
= res
;
1054 if (cli
->rap_error
!= 0) {
1055 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
1060 DEBUG(4,("NetUserEnum no data returned\n"));
1064 if (res
== 0 || res
== ERRmoredata
) {
1066 char *endp
= rparam
+ rprcnt
;
1067 char username
[RAP_USERNAME_LEN
];
1069 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1070 GETWORD(p
, count
, endp
);
1072 endp
= rdata
+ rdrcnt
;
1073 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
1074 p
+= rap_getstringf(p
,
1084 DEBUG(4,("NetUserEnum res=%d\n", res
));
1095 /****************************************************************************
1096 Call a NetFileClose2 - close open file on another session to server.
1097 ****************************************************************************/
1099 int cli_NetFileClose(struct cli_state
*cli
, uint32 file_id
)
1101 char *rparam
= NULL
;
1104 unsigned int rdrcnt
,rprcnt
;
1105 char param
[WORDSIZE
/* api number */
1106 +sizeof(RAP_WFileClose2_REQ
) /* req string */
1107 +1 /* no ret string */
1108 +DWORDSIZE
]; /* file ID */
1111 /* now send a SMBtrans command with api RNetShareEnum */
1112 p
= make_header(param
, RAP_WFileClose2
, RAP_WFileClose2_REQ
, NULL
);
1113 PUTDWORD(p
, file_id
);
1116 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1117 NULL
, 0, 200, /* data, length, maxlen */
1118 &rparam
, &rprcnt
, /* return params, length */
1119 &rdata
, &rdrcnt
)) /* return data, length */
1121 char *endp
= rparam
+ rprcnt
;
1122 res
= GETRES(rparam
, endp
);
1126 } else if (res
== 2314){
1127 DEBUG(1, ("NetFileClose2 - attempt to close non-existant file open instance\n"));
1129 DEBUG(4,("NetFileClose2 res=%d\n", res
));
1133 DEBUG(4,("NetFileClose2 failed\n"));
1142 /****************************************************************************
1143 Call a NetFileGetInfo - get information about server file opened from other
1145 ****************************************************************************/
1147 int cli_NetFileGetInfo(struct cli_state
*cli
, uint32 file_id
, void (*fn
)(const char *, const char *, uint16
, uint16
, uint32
))
1149 char *rparam
= NULL
;
1152 unsigned int rdrcnt
,rprcnt
;
1154 char param
[WORDSIZE
/* api number */
1155 +sizeof(RAP_WFileGetInfo2_REQ
) /* req string */
1156 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1157 +DWORDSIZE
/* file ID */
1158 +WORDSIZE
/* info level */
1159 +WORDSIZE
]; /* buffer size */
1161 /* now send a SMBtrans command with api RNetShareEnum */
1162 p
= make_header(param
, RAP_WFileGetInfo2
,
1163 RAP_WFileGetInfo2_REQ
, RAP_FILE_INFO_L3
);
1164 PUTDWORD(p
, file_id
);
1165 PUTWORD(p
, 3); /* info level */
1166 PUTWORD(p
, 0x1000); /* buffer size */
1168 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1169 NULL
, 0, 0x1000, /* data, length, maxlen */
1170 &rparam
, &rprcnt
, /* return params, length */
1171 &rdata
, &rdrcnt
)) /* return data, length */
1173 char *endp
= rparam
+ rprcnt
;
1174 res
= GETRES(rparam
,endp
);
1175 if (res
== 0 || res
== ERRmoredata
) {
1176 TALLOC_CTX
*frame
= talloc_stackframe();
1177 int converter
= 0,id
= 0, perms
= 0, locks
= 0;
1178 char *fpath
, *fuser
;
1180 p
= rparam
+ WORDSIZE
; /* skip result */
1181 GETWORD(p
, converter
, endp
);
1184 endp
= rdata
+ rdrcnt
;
1186 GETDWORD(p
, id
, endp
);
1187 GETWORD(p
, perms
, endp
);
1188 GETWORD(p
, locks
, endp
);
1190 p
+= rap_getstringp(frame
,
1196 p
+= rap_getstringp(frame
,
1203 if (fpath
&& fuser
) {
1204 fn(fpath
, fuser
, perms
, locks
, id
);
1209 DEBUG(4,("NetFileGetInfo2 res=%d\n", res
));
1213 DEBUG(4,("NetFileGetInfo2 failed\n"));
1222 /****************************************************************************
1223 * Call a NetFileEnum2 - list open files on an SMB server
1225 * PURPOSE: Remotes a NetFileEnum API call to the current server or target
1226 * server listing the files open via the network (and their
1227 * corresponding open instance ids)
1229 * Dependencies: none
1232 * cli - pointer to cli_state structure
1233 * user - if present, return only files opened by this remote user
1234 * base_path - if present, return only files opened below this
1236 * fn - display function to invoke for each entry in the result
1243 ****************************************************************************/
1245 int cli_NetFileEnum(struct cli_state
*cli
, const char * user
,
1246 const char * base_path
,
1247 void (*fn
)(const char *, const char *, uint16
, uint16
,
1250 char *rparam
= NULL
;
1253 unsigned int rdrcnt
,rprcnt
;
1254 char param
[WORDSIZE
/* api number */
1255 +sizeof(RAP_WFileEnum2_REQ
) /* req string */
1256 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1257 +1024 /* base path (opt) */
1258 +RAP_USERNAME_LEN
/* user name (opt) */
1259 +WORDSIZE
/* info level */
1260 +WORDSIZE
/* buffer size */
1261 +DWORDSIZE
/* resume key ? */
1262 +DWORDSIZE
]; /* resume key ? */
1266 /* now send a SMBtrans command with api RNetShareEnum */
1267 p
= make_header(param
, RAP_WFileEnum2
,
1268 RAP_WFileEnum2_REQ
, RAP_FILE_INFO_L3
);
1270 PUTSTRING(p
, base_path
, 1024);
1271 PUTSTRING(p
, user
, RAP_USERNAME_LEN
);
1272 PUTWORD(p
, 3); /* info level */
1273 PUTWORD(p
, 0xFF00); /* buffer size */
1274 PUTDWORD(p
, 0); /* zero out the resume key */
1275 PUTDWORD(p
, 0); /* or is this one the resume key? */
1278 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1279 NULL
, 0, 0xFF00, /* data, length, maxlen */
1280 &rparam
, &rprcnt
, /* return params, length */
1281 &rdata
, &rdrcnt
)) /* return data, length */
1283 char *endp
= rparam
+ rprcnt
;
1284 res
= GETRES(rparam
, endp
);
1286 if (res
== 0 || res
== ERRmoredata
) {
1287 TALLOC_CTX
*frame
= talloc_stackframe();
1288 int converter
= 0, i
;
1290 p
= rparam
+ WORDSIZE
; /* skip result */
1291 GETWORD(p
, converter
, endp
);
1292 GETWORD(p
, count
, endp
);
1295 endp
= rdata
+ rdrcnt
;
1296 for (i
=0; i
<count
&& p
< endp
; i
++) {
1297 int id
= 0, perms
= 0, locks
= 0;
1298 char *fpath
, *fuser
;
1300 GETDWORD(p
, id
, endp
);
1301 GETWORD(p
, perms
, endp
);
1302 GETWORD(p
, locks
, endp
);
1303 p
+= rap_getstringp(frame
,
1309 p
+= rap_getstringp(frame
,
1316 if (fpath
&& fuser
) {
1317 fn(fpath
, fuser
, perms
, locks
, id
);
1319 } /* BB fix ERRmoredata case to send resume request */
1322 DEBUG(4,("NetFileEnum2 res=%d\n", res
));
1325 DEBUG(4,("NetFileEnum2 failed\n"));
1334 /****************************************************************************
1335 Call a NetShareAdd - share/export directory on remote server.
1336 ****************************************************************************/
1338 int cli_NetShareAdd(struct cli_state
*cli
, struct rap_share_info_2
* sinfo
)
1340 char *rparam
= NULL
;
1343 unsigned int rdrcnt
,rprcnt
;
1345 char param
[WORDSIZE
/* api number */
1346 +sizeof(RAP_WShareAdd_REQ
) /* req string */
1347 +sizeof(RAP_SHARE_INFO_L2
) /* return string */
1348 +WORDSIZE
/* info level */
1349 +WORDSIZE
]; /* reserved word */
1351 /* offset to free format string section following fixed length data. */
1352 /* will be updated by PUTSTRINGP macro and will end up with total len */
1353 int soffset
= RAP_SHARENAME_LEN
+ 1 /* share name + pad */
1354 + WORDSIZE
/* share type */
1355 + DWORDSIZE
/* comment pointer */
1356 + WORDSIZE
/* permissions */
1357 + WORDSIZE
/* max users */
1358 + WORDSIZE
/* active users */
1359 + DWORDSIZE
/* share path */
1360 + RAP_SPASSWD_LEN
+ 1; /* share password + pad */
1362 memset(param
,'\0',sizeof(param
));
1363 /* now send a SMBtrans command with api RNetShareAdd */
1364 p
= make_header(param
, RAP_WshareAdd
,
1365 RAP_WShareAdd_REQ
, RAP_SHARE_INFO_L2
);
1366 PUTWORD(p
, 2); /* info level */
1367 PUTWORD(p
, 0); /* reserved word 0 */
1370 PUTSTRINGF(p
, (const char *)sinfo
->share_name
, RAP_SHARENAME_LEN
);
1371 PUTBYTE(p
, 0); /* pad byte 0 */
1373 PUTWORD(p
, sinfo
->share_type
);
1374 PUTSTRINGP(p
, sinfo
->comment
, data
, soffset
);
1375 PUTWORD(p
, sinfo
->perms
);
1376 PUTWORD(p
, sinfo
->maximum_users
);
1377 PUTWORD(p
, sinfo
->active_users
);
1378 PUTSTRINGP(p
, sinfo
->path
, data
, soffset
);
1379 PUTSTRINGF(p
, (const char *)sinfo
->password
, RAP_SPASSWD_LEN
);
1380 SCVAL(p
,-1,0x0A); /* required 0x0A at end of password */
1383 param
, sizeof(param
), 1024, /* Param, length, maxlen */
1384 data
, soffset
, sizeof(data
), /* data, length, maxlen */
1385 &rparam
, &rprcnt
, /* return params, length */
1386 &rdata
, &rdrcnt
)) /* return data, length */
1388 char *endp
= rparam
+ rprcnt
;
1389 res
= GETRES(rparam
, endp
);
1394 DEBUG(4,("NetShareAdd res=%d\n", res
));
1397 DEBUG(4,("NetShareAdd failed\n"));
1406 /****************************************************************************
1407 Call a NetShareDelete - unshare exported directory on remote server.
1408 ****************************************************************************/
1410 int cli_NetShareDelete(struct cli_state
*cli
, const char * share_name
)
1412 char *rparam
= NULL
;
1415 unsigned int rdrcnt
,rprcnt
;
1417 char param
[WORDSIZE
/* api number */
1418 +sizeof(RAP_WShareDel_REQ
) /* req string */
1419 +1 /* no ret string */
1420 +RAP_SHARENAME_LEN
/* share to del */
1421 +WORDSIZE
]; /* reserved word */
1423 /* now send a SMBtrans command with api RNetShareDelete */
1424 p
= make_header(param
, RAP_WshareDel
, RAP_WShareDel_REQ
, NULL
);
1425 PUTSTRING(p
,share_name
,RAP_SHARENAME_LEN
);
1426 PUTWORD(p
,0); /* reserved word MBZ on input */
1429 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1430 NULL
, 0, 200, /* data, length, maxlen */
1431 &rparam
, &rprcnt
, /* return params, length */
1432 &rdata
, &rdrcnt
)) /* return data, length */
1434 char *endp
= rparam
+ rprcnt
;
1435 res
= GETRES(rparam
, endp
);
1440 DEBUG(4,("NetShareDelete res=%d\n", res
));
1443 DEBUG(4,("NetShareDelete failed\n"));
1452 /*************************************************************************
1454 * Function Name: cli_get_pdc_name
1456 * PURPOSE: Remotes a NetServerEnum API call to the current server
1457 * requesting the name of a server matching the server
1458 * type of SV_TYPE_DOMAIN_CTRL (PDC).
1460 * Dependencies: none
1463 * cli - pointer to cli_state structure
1464 * workgroup - pointer to string containing name of domain
1465 * pdc_name - pointer to string that will contain PDC name
1466 * on successful return
1472 ************************************************************************/
1474 bool cli_get_pdc_name(struct cli_state
*cli
, const char *workgroup
, char **pdc_name
)
1476 char *rparam
= NULL
;
1478 unsigned int rdrcnt
,rprcnt
;
1480 char param
[WORDSIZE
/* api number */
1481 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1482 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1483 +WORDSIZE
/* info level */
1484 +WORDSIZE
/* buffer size */
1485 +DWORDSIZE
/* server type */
1486 +RAP_MACHNAME_LEN
]; /* workgroup */
1492 /* send a SMBtrans command with api NetServerEnum */
1493 p
= make_header(param
, RAP_NetServerEnum2
,
1494 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L1
);
1495 PUTWORD(p
, 1); /* info level */
1496 PUTWORD(p
, CLI_BUFFER_SIZE
);
1497 PUTDWORD(p
, SV_TYPE_DOMAIN_CTRL
);
1498 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1501 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1502 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1503 &rparam
, &rprcnt
, /* return params, return size */
1504 &rdata
, &rdrcnt
/* return data, return size */
1507 char *endp
= rparam
+ rprcnt
;
1508 res
= GETRES(rparam
, endp
);
1509 cli
->rap_error
= res
;
1512 * We only really care to copy a name if the
1513 * API succeeded and we got back a name.
1515 if (cli
->rap_error
== 0) {
1516 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1517 GETWORD(p
, count
, endp
);
1519 endp
= rdata
+ rdrcnt
;
1522 TALLOC_CTX
*frame
= talloc_stackframe();
1524 p
+= rap_getstring(frame
,
1529 *pdc_name
= SMB_STRDUP(dcname
);
1534 DEBUG(4,("cli_get_pdc_name: machine %s failed the NetServerEnum call. "
1535 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1545 /*************************************************************************
1547 * Function Name: cli_get_server_domain
1549 * PURPOSE: Remotes a NetWkstaGetInfo API call to the current server
1550 * requesting wksta_info_10 level information to determine
1551 * the domain the server belongs to. On success, this
1552 * routine sets the server_domain field in the cli_state structure
1553 * to the server's domain name.
1555 * Dependencies: none
1558 * cli - pointer to cli_state structure
1564 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1566 ************************************************************************/
1568 bool cli_get_server_domain(struct cli_state
*cli
)
1570 char *rparam
= NULL
;
1572 unsigned int rdrcnt
,rprcnt
;
1574 char param
[WORDSIZE
/* api number */
1575 +sizeof(RAP_WWkstaGetInfo_REQ
) /* req string */
1576 +sizeof(RAP_WKSTA_INFO_L10
) /* return string */
1577 +WORDSIZE
/* info level */
1578 +WORDSIZE
]; /* buffer size */
1581 /* send a SMBtrans command with api NetWkstaGetInfo */
1582 p
= make_header(param
, RAP_WWkstaGetInfo
,
1583 RAP_WWkstaGetInfo_REQ
, RAP_WKSTA_INFO_L10
);
1584 PUTWORD(p
, 10); /* info level */
1585 PUTWORD(p
, CLI_BUFFER_SIZE
);
1587 if (cli_api(cli
, param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1588 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1589 &rparam
, &rprcnt
, /* return params, return size */
1590 &rdata
, &rdrcnt
)) { /* return data, return size */
1591 char *endp
= rparam
+ rprcnt
;
1592 res
= GETRES(rparam
, endp
);
1595 TALLOC_CTX
*frame
= talloc_stackframe();
1596 char *server_domain
;
1599 p
= rparam
+ WORDSIZE
;
1600 GETWORD(p
, converter
, endp
);
1602 p
= rdata
+ DWORDSIZE
+ DWORDSIZE
; /* skip computer & user names */
1603 endp
= rdata
+ rdrcnt
;
1604 p
+= rap_getstringp(frame
,
1611 if (server_domain
) {
1612 fstrcpy(cli
->server_domain
, server_domain
);
1624 /*************************************************************************
1626 * Function Name: cli_get_server_type
1628 * PURPOSE: Remotes a NetServerGetInfo API call to the current server
1629 * requesting server_info_1 level information to retrieve
1632 * Dependencies: none
1635 * cli - pointer to cli_state structure
1636 * pstype - pointer to uint32 to contain returned server type
1642 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1644 ************************************************************************/
1646 bool cli_get_server_type(struct cli_state
*cli
, uint32
*pstype
)
1648 char *rparam
= NULL
;
1650 unsigned int rdrcnt
,rprcnt
;
1652 char param
[WORDSIZE
/* api number */
1653 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1654 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1655 +WORDSIZE
/* info level */
1656 +WORDSIZE
]; /* buffer size */
1659 /* send a SMBtrans command with api NetServerGetInfo */
1660 p
= make_header(param
, RAP_WserverGetInfo
,
1661 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1662 PUTWORD(p
, 1); /* info level */
1663 PUTWORD(p
, CLI_BUFFER_SIZE
);
1666 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1667 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1668 &rparam
, &rprcnt
, /* return params, return size */
1669 &rdata
, &rdrcnt
/* return data, return size */
1671 char *endp
= rparam
+ rprcnt
;
1672 res
= GETRES(rparam
,endp
);
1674 if (res
== 0 || res
== ERRmoredata
) {
1676 endp
= rparam
+ rprcnt
;
1678 GETDWORD(p
,*pstype
,endp
);
1679 *pstype
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1686 return(res
== 0 || res
== ERRmoredata
);
1689 bool cli_get_server_name(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
1692 char *rparam
= NULL
;
1694 unsigned int rdrcnt
,rprcnt
;
1696 char param
[WORDSIZE
/* api number */
1697 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1698 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1699 +WORDSIZE
/* info level */
1700 +WORDSIZE
]; /* buffer size */
1705 /* send a SMBtrans command with api NetServerGetInfo */
1706 p
= make_header(param
, RAP_WserverGetInfo
,
1707 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1708 PUTWORD(p
, 1); /* info level */
1709 PUTWORD(p
, CLI_BUFFER_SIZE
);
1712 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1713 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1714 &rparam
, &rprcnt
, /* return params, return size */
1715 &rdata
, &rdrcnt
/* return data, return size */
1720 endp
= rparam
+ rprcnt
;
1721 if (GETRES(rparam
, endp
) != 0) {
1726 DEBUG(10, ("invalid data count %d, expected >= 16\n", rdrcnt
));
1730 if (pull_ascii(tmp
, rdata
, sizeof(tmp
)-1, 16, STR_TERMINATE
) == -1) {
1731 DEBUG(10, ("pull_ascii failed\n"));
1735 if (!(*servername
= talloc_strdup(mem_ctx
, tmp
))) {
1736 DEBUG(1, ("talloc_strdup failed\n"));
1748 /*************************************************************************
1750 * Function Name: cli_ns_check_server_type
1752 * PURPOSE: Remotes a NetServerEnum2 API call to the current server
1753 * requesting server_info_0 level information of machines
1754 * matching the given server type. If the returned server
1755 * list contains the machine name contained in cli->desthost
1756 * then we conclude the server type checks out. This routine
1757 * is useful to retrieve list of server's of a certain
1758 * type when all you have is a null session connection and
1759 * can't remote API calls such as NetWkstaGetInfo or
1762 * Dependencies: none
1765 * cli - pointer to cli_state structure
1766 * workgroup - pointer to string containing domain
1767 * stype - server type
1773 ************************************************************************/
1775 bool cli_ns_check_server_type(struct cli_state
*cli
, char *workgroup
, uint32 stype
)
1777 char *rparam
= NULL
;
1779 unsigned int rdrcnt
,rprcnt
;
1781 char param
[WORDSIZE
/* api number */
1782 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1783 +sizeof(RAP_SERVER_INFO_L0
) /* return string */
1784 +WORDSIZE
/* info level */
1785 +WORDSIZE
/* buffer size */
1786 +DWORDSIZE
/* server type */
1787 +RAP_MACHNAME_LEN
]; /* workgroup */
1788 bool found_server
= false;
1791 /* send a SMBtrans command with api NetServerEnum */
1792 p
= make_header(param
, RAP_NetServerEnum2
,
1793 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L0
);
1794 PUTWORD(p
, 0); /* info level 0 */
1795 PUTWORD(p
, CLI_BUFFER_SIZE
);
1797 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1800 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1801 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1802 &rparam
, &rprcnt
, /* return params, return size */
1803 &rdata
, &rdrcnt
/* return data, return size */
1805 char *endp
= rparam
+ rprcnt
;
1806 res
= GETRES(rparam
,endp
);
1807 cli
->rap_error
= res
;
1809 if (res
== 0 || res
== ERRmoredata
) {
1812 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
1813 GETWORD(p
, count
,endp
);
1816 endp
= rdata
+ rdrcnt
;
1817 for (i
= 0;i
< count
&& p
< endp
;i
++, p
+= 16) {
1818 char ret_server
[RAP_MACHNAME_LEN
];
1820 p
+= rap_getstringf(p
,
1825 if (strequal(ret_server
, cli
->desthost
)) {
1826 found_server
= true;
1831 DEBUG(4,("cli_ns_check_server_type: machine %s failed the NetServerEnum call. "
1832 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1839 return found_server
;
1842 /****************************************************************************
1843 Perform a NetWkstaUserLogoff.
1844 ****************************************************************************/
1846 bool cli_NetWkstaUserLogoff(struct cli_state
*cli
, const char *user
, const char *workstation
)
1848 char *rparam
= NULL
;
1851 unsigned int rdrcnt
,rprcnt
;
1852 char param
[WORDSIZE
/* api number */
1853 +sizeof(RAP_NetWkstaUserLogoff_REQ
) /* req string */
1854 +sizeof(RAP_USER_LOGOFF_INFO_L1
) /* return string */
1855 +RAP_USERNAME_LEN
+1 /* user name+pad */
1856 +RAP_MACHNAME_LEN
/* wksta name */
1857 +WORDSIZE
/* buffer size */
1858 +WORDSIZE
]; /* buffer size? */
1859 char upperbuf
[MAX(RAP_USERNAME_LEN
,RAP_MACHNAME_LEN
)];
1863 memset(param
, 0, sizeof(param
));
1865 /* send a SMBtrans command with api NetWkstaUserLogoff */
1866 p
= make_header(param
, RAP_WWkstaUserLogoff
,
1867 RAP_NetWkstaUserLogoff_REQ
, RAP_USER_LOGOFF_INFO_L1
);
1868 PUTDWORD(p
, 0); /* Null pointer */
1869 PUTDWORD(p
, 0); /* Null pointer */
1870 strlcpy(upperbuf
, user
, sizeof(upperbuf
));
1871 strupper_m(upperbuf
);
1873 PUTSTRINGF(p
, tmp
, RAP_USERNAME_LEN
);
1874 p
++; /* strange format, but ok */
1875 strlcpy(upperbuf
, workstation
, sizeof(upperbuf
));
1876 strupper_m(upperbuf
);
1878 PUTSTRINGF(p
, tmp
, RAP_MACHNAME_LEN
);
1879 PUTWORD(p
, CLI_BUFFER_SIZE
);
1880 PUTWORD(p
, CLI_BUFFER_SIZE
);
1883 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
1884 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1885 &rparam
, &rprcnt
, /* return params, return size */
1886 &rdata
, &rdrcnt
/* return data, return size */
1888 char *endp
= rparam
+ rprcnt
;
1889 res
= GETRES(rparam
,endp
);
1890 cli
->rap_error
= res
;
1892 if (cli
->rap_error
!= 0) {
1893 DEBUG(4,("NetwkstaUserLogoff gave error %d\n", cli
->rap_error
));
1899 return (cli
->rap_error
== 0);
1902 int cli_NetPrintQEnum(struct cli_state
*cli
,
1903 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
1904 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
1906 char param
[WORDSIZE
/* api number */
1907 +sizeof(RAP_NetPrintQEnum_REQ
) /* req string */
1908 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
1909 +WORDSIZE
/* info level */
1910 +WORDSIZE
/* buffer size */
1911 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
1913 char *rparam
= NULL
;
1915 unsigned int rprcnt
, rdrcnt
;
1918 memset(param
, '\0',sizeof(param
));
1919 p
= make_header(param
, RAP_WPrintQEnum
,
1920 RAP_NetPrintQEnum_REQ
, RAP_PRINTQ_INFO_L2
);
1921 PUTWORD(p
,2); /* Info level 2 */
1922 PUTWORD(p
,0xFFE0); /* Return buffer size */
1923 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
1926 param
, PTR_DIFF(p
,param
),1024,
1927 NULL
, 0, CLI_BUFFER_SIZE
,
1930 char *endp
= rparam
+ rprcnt
;
1931 res
= GETRES(rparam
, endp
);
1932 cli
->rap_error
= res
;
1934 DEBUG(1,("NetPrintQEnum gave error %d\n", res
));
1939 DEBUG(4,("NetPrintQEnum no data returned\n"));
1943 if (res
== 0 || res
== ERRmoredata
) {
1944 TALLOC_CTX
*frame
= talloc_stackframe();
1945 char *endp
= rparam
+ rprcnt
;
1946 int i
, converter
= 0, count
= 0;
1948 p
= rparam
+ WORDSIZE
;
1949 GETWORD(p
, converter
, endp
);
1950 GETWORD(p
, count
, endp
);
1953 endp
= rdata
+ rdrcnt
;
1954 for (i
=0;i
<count
&& p
< endp
;i
++) {
1955 char qname
[RAP_SHARENAME_LEN
];
1956 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
1957 uint16_t jobcount
= 0, priority
= 0;
1958 uint16_t start_time
= 0, until_time
= 0, status
= 0;
1960 p
+= rap_getstringf(p
,
1966 GETWORD(p
, priority
, endp
);
1967 GETWORD(p
, start_time
, endp
);
1968 GETWORD(p
, until_time
, endp
);
1969 p
+= rap_getstringp(frame
,
1975 p
+= rap_getstringp(frame
,
1981 p
+= rap_getstringp(frame
,
1987 p
+= rap_getstringp(frame
,
1993 p
+= rap_getstringp(frame
,
1999 GETWORD(p
, status
, endp
);
2000 GETWORD(p
, jobcount
, endp
);
2002 if (sep_file
&& print_proc
&& dest
&& parms
&&
2004 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2005 dest
, parms
, comment
, status
, jobcount
);
2010 for (j
=0;j
<jobcount
;j
++) {
2011 uint16 jid
= 0, pos
= 0, fsstatus
= 0;
2012 char ownername
[RAP_USERNAME_LEN
];
2013 char notifyname
[RAP_MACHNAME_LEN
];
2014 char datatype
[RAP_DATATYPE_LEN
];
2015 char *jparms
, *jstatus
, *jcomment
;
2016 unsigned int submitted
= 0, jsize
= 0;
2018 GETWORD(p
, jid
, endp
);
2019 p
+= rap_getstringf(p
,
2025 p
+= rap_getstringf(p
,
2030 p
+= rap_getstringf(p
,
2035 p
+= rap_getstringp(frame
,
2041 GETWORD(p
, pos
, endp
);
2042 GETWORD(p
, fsstatus
, endp
);
2043 p
+= rap_getstringp(frame
,
2049 GETDWORD(p
, submitted
, endp
);
2050 GETDWORD(p
, jsize
, endp
);
2051 p
+= rap_getstringp(frame
,
2058 if (jparms
&& jstatus
&& jcomment
) {
2059 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2060 jstatus
, submitted
, jsize
, jcomment
);
2067 DEBUG(4,("NetPrintQEnum res=%d\n", res
));
2078 int cli_NetPrintQGetInfo(struct cli_state
*cli
, const char *printer
,
2079 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
2080 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
2082 char param
[WORDSIZE
/* api number */
2083 +sizeof(RAP_NetPrintQGetInfo_REQ
) /* req string */
2084 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
2085 +RAP_SHARENAME_LEN
/* printer name */
2086 +WORDSIZE
/* info level */
2087 +WORDSIZE
/* buffer size */
2088 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
2090 char *rparam
= NULL
;
2092 unsigned int rprcnt
, rdrcnt
;
2095 memset(param
, '\0',sizeof(param
));
2096 p
= make_header(param
, RAP_WPrintQGetInfo
,
2097 RAP_NetPrintQGetInfo_REQ
, RAP_PRINTQ_INFO_L2
);
2098 PUTSTRING(p
, printer
, RAP_SHARENAME_LEN
-1);
2099 PUTWORD(p
, 2); /* Info level 2 */
2100 PUTWORD(p
,0xFFE0); /* Return buffer size */
2101 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
2104 param
, PTR_DIFF(p
,param
),1024,
2105 NULL
, 0, CLI_BUFFER_SIZE
,
2108 char *endp
= rparam
+ rprcnt
;
2109 res
= GETRES(rparam
, endp
);
2110 cli
->rap_error
= res
;
2112 DEBUG(1,("NetPrintQGetInfo gave error %d\n", res
));
2117 DEBUG(4,("NetPrintQGetInfo no data returned\n"));
2121 if (res
== 0 || res
== ERRmoredata
) {
2122 TALLOC_CTX
*frame
= talloc_stackframe();
2123 char *endp
= rparam
+ rprcnt
;
2124 int rsize
= 0, converter
= 0;
2125 char qname
[RAP_SHARENAME_LEN
];
2126 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
2127 uint16_t jobcount
= 0, priority
= 0;
2128 uint16_t start_time
= 0, until_time
= 0, status
= 0;
2130 p
= rparam
+ WORDSIZE
;
2131 GETWORD(p
, converter
, endp
);
2132 GETWORD(p
, rsize
, endp
);
2135 endp
= rdata
+ rdrcnt
;
2136 p
+= rap_getstringf(p
,
2142 GETWORD(p
, priority
, endp
);
2143 GETWORD(p
, start_time
, endp
);
2144 GETWORD(p
, until_time
, endp
);
2145 p
+= rap_getstringp(frame
,
2151 p
+= rap_getstringp(frame
,
2157 p
+= rap_getstringp(frame
,
2163 p
+= rap_getstringp(frame
,
2169 p
+= rap_getstringp(frame
,
2175 GETWORD(p
, status
, endp
);
2176 GETWORD(p
, jobcount
, endp
);
2178 if (sep_file
&& print_proc
&& dest
&&
2180 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2181 dest
, parms
, comment
, status
, jobcount
);
2185 for (j
=0;(j
<jobcount
)&&(PTR_DIFF(p
,rdata
)< rsize
)&&
2187 uint16_t jid
= 0, pos
= 0, fsstatus
= 0;
2188 char ownername
[RAP_USERNAME_LEN
];
2189 char notifyname
[RAP_MACHNAME_LEN
];
2190 char datatype
[RAP_DATATYPE_LEN
];
2191 char *jparms
, *jstatus
, *jcomment
;
2192 unsigned int submitted
= 0, jsize
= 0;
2194 GETWORD(p
, jid
, endp
);
2195 p
+= rap_getstringf(p
,
2201 p
+= rap_getstringf(p
,
2206 p
+= rap_getstringf(p
,
2211 p
+= rap_getstringp(frame
,
2217 GETWORD(p
, pos
,endp
);
2218 GETWORD(p
, fsstatus
,endp
);
2219 p
+= rap_getstringp(frame
,
2225 GETDWORD(p
, submitted
,endp
);
2226 GETDWORD(p
, jsize
,endp
);
2227 p
+= rap_getstringp(frame
,
2234 if (jparms
&& jstatus
&& jcomment
) {
2235 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2236 jstatus
, submitted
, jsize
, jcomment
);
2242 DEBUG(4,("NetPrintQGetInfo res=%d\n", res
));
2253 /****************************************************************************
2254 Call a NetServiceEnum - list running services on a different host.
2255 ****************************************************************************/
2257 int cli_RNetServiceEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
2259 char param
[WORDSIZE
/* api number */
2260 +sizeof(RAP_NetServiceEnum_REQ
) /* parm string */
2261 +sizeof(RAP_SERVICE_INFO_L2
) /* return string */
2262 +WORDSIZE
/* info level */
2263 +WORDSIZE
]; /* buffer size */
2265 char *rparam
= NULL
;
2267 unsigned int rprcnt
, rdrcnt
;
2270 memset(param
, '\0', sizeof(param
));
2271 p
= make_header(param
, RAP_WServiceEnum
,
2272 RAP_NetServiceEnum_REQ
, RAP_SERVICE_INFO_L2
);
2273 PUTWORD(p
,2); /* Info level 2 */
2274 PUTWORD(p
,0xFFE0); /* Return buffer size */
2277 param
, PTR_DIFF(p
,param
),8,
2278 NULL
, 0, 0xFFE0 /* data area size */,
2281 char *endp
= rparam
+ rprcnt
;
2282 res
= GETRES(rparam
, endp
);
2283 cli
->rap_error
= res
;
2284 if(cli
->rap_error
== 234) {
2285 DEBUG(1,("Not all service names were returned (such as those longer than 15 characters)\n"));
2286 } else if (cli
->rap_error
!= 0) {
2287 DEBUG(1,("NetServiceEnum gave error %d\n", cli
->rap_error
));
2292 DEBUG(4,("NetServiceEnum no data returned\n"));
2296 if (res
== 0 || res
== ERRmoredata
) {
2297 char *endp
= rparam
+ rprcnt
;
2300 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
2301 GETWORD(p
, count
,endp
);
2303 endp
= rdata
+ rdrcnt
;
2304 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2305 char comment
[RAP_SRVCCMNT_LEN
];
2306 char servicename
[RAP_SRVCNAME_LEN
];
2308 p
+= rap_getstringf(p
,
2313 p
+=8; /* pass status words */
2314 p
+= rap_getstringf(p
,
2320 if (servicename
[0]) {
2321 fn(servicename
, comment
, cli
); /* BB add status too */
2325 DEBUG(4,("NetServiceEnum res=%d\n", res
));
2336 /****************************************************************************
2337 Call a NetSessionEnum - list workstations with sessions to an SMB server.
2338 ****************************************************************************/
2340 int cli_NetSessionEnum(struct cli_state
*cli
, void (*fn
)(char *, char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, char *))
2342 char param
[WORDSIZE
/* api number */
2343 +sizeof(RAP_NetSessionEnum_REQ
) /* parm string */
2344 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2345 +WORDSIZE
/* info level */
2346 +WORDSIZE
]; /* buffer size */
2348 char *rparam
= NULL
;
2350 unsigned int rprcnt
, rdrcnt
;
2353 memset(param
, '\0', sizeof(param
));
2354 p
= make_header(param
, RAP_WsessionEnum
,
2355 RAP_NetSessionEnum_REQ
, RAP_SESSION_INFO_L2
);
2356 PUTWORD(p
,2); /* Info level 2 */
2357 PUTWORD(p
,0xFF); /* Return buffer size */
2360 param
, PTR_DIFF(p
,param
),8,
2361 NULL
, 0, CLI_BUFFER_SIZE
,
2364 char *endp
= rparam
+ rprcnt
;
2365 res
= GETRES(rparam
, endp
);
2366 cli
->rap_error
= res
;
2368 DEBUG(1,("NetSessionEnum gave error %d\n", res
));
2373 DEBUG(4,("NetSesssionEnum no data returned\n"));
2377 if (res
== 0 || res
== ERRmoredata
) {
2378 TALLOC_CTX
*frame
= talloc_stackframe();
2379 char *endp
= rparam
+ rprcnt
;
2380 int i
, converter
= 0, count
= 0;
2382 p
= rparam
+ WORDSIZE
;
2383 GETWORD(p
, converter
, endp
);
2384 GETWORD(p
, count
, endp
);
2386 endp
= rdata
+ rdrcnt
;
2387 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2388 char *wsname
, *username
, *clitype_name
;
2389 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2390 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2392 p
+= rap_getstringp(frame
,
2398 p
+= rap_getstringp(frame
,
2404 GETWORD(p
, num_conns
, endp
);
2405 GETWORD(p
, num_opens
, endp
);
2406 GETWORD(p
, num_users
, endp
);
2407 GETDWORD(p
, sess_time
, endp
);
2408 GETDWORD(p
, idle_time
, endp
);
2409 GETDWORD(p
, user_flags
, endp
);
2410 p
+= rap_getstringp(frame
,
2417 if (wsname
&& username
&& clitype_name
) {
2418 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2419 idle_time
, user_flags
, clitype_name
);
2424 DEBUG(4,("NetSessionEnum res=%d\n", res
));
2435 /****************************************************************************
2436 Call a NetSessionGetInfo - get information about other session to an SMB server.
2437 ****************************************************************************/
2439 int cli_NetSessionGetInfo(struct cli_state
*cli
, const char *workstation
,
2440 void (*fn
)(const char *, const char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, const char *))
2442 char param
[WORDSIZE
/* api number */
2443 +sizeof(RAP_NetSessionGetInfo_REQ
) /* req string */
2444 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2445 +RAP_MACHNAME_LEN
/* wksta name */
2446 +WORDSIZE
/* info level */
2447 +WORDSIZE
]; /* buffer size */
2449 char *rparam
= NULL
;
2451 unsigned int rprcnt
, rdrcnt
;
2455 memset(param
, '\0', sizeof(param
));
2456 p
= make_header(param
, RAP_WsessionGetInfo
,
2457 RAP_NetSessionGetInfo_REQ
, RAP_SESSION_INFO_L2
);
2458 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2459 PUTWORD(p
,2); /* Info level 2 */
2460 PUTWORD(p
,0xFF); /* Return buffer size */
2463 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2464 NULL
, 0, CLI_BUFFER_SIZE
,
2467 endp
= rparam
+ rprcnt
;
2468 res
= GETRES(rparam
, endp
);
2469 cli
->rap_error
= res
;
2470 if (cli
->rap_error
!= 0) {
2471 DEBUG(1,("NetSessionGetInfo gave error %d\n", cli
->rap_error
));
2476 DEBUG(4,("NetSessionGetInfo no data returned\n"));
2480 endp
= rparam
+ rprcnt
;
2481 res
= GETRES(rparam
, endp
);
2483 if (res
== 0 || res
== ERRmoredata
) {
2484 TALLOC_CTX
*frame
= talloc_stackframe();
2486 char *wsname
, *username
, *clitype_name
;
2487 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2488 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2490 p
= rparam
+ WORDSIZE
;
2491 GETWORD(p
, converter
,endp
);
2492 p
+= WORDSIZE
; /* skip rsize */
2495 endp
= rdata
+ rdrcnt
;
2496 p
+= rap_getstringp(frame
,
2502 p
+= rap_getstringp(frame
,
2508 GETWORD(p
, num_conns
, endp
);
2509 GETWORD(p
, num_opens
, endp
);
2510 GETWORD(p
, num_users
, endp
);
2511 GETDWORD(p
, sess_time
, endp
);
2512 GETDWORD(p
, idle_time
, endp
);
2513 GETDWORD(p
, user_flags
, endp
);
2514 p
+= rap_getstringp(frame
,
2521 if (wsname
&& username
&& clitype_name
) {
2522 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2523 idle_time
, user_flags
, clitype_name
);
2527 DEBUG(4,("NetSessionGetInfo res=%d\n", res
));
2538 /****************************************************************************
2539 Call a NetSessionDel - close a session to an SMB server.
2540 ****************************************************************************/
2542 int cli_NetSessionDel(struct cli_state
*cli
, const char *workstation
)
2544 char param
[WORDSIZE
/* api number */
2545 +sizeof(RAP_NetSessionDel_REQ
) /* req string */
2546 +1 /* no return string */
2547 +RAP_MACHNAME_LEN
/* workstation name */
2548 +WORDSIZE
]; /* reserved (0) */
2550 char *rparam
= NULL
;
2552 unsigned int rprcnt
, rdrcnt
;
2555 memset(param
, '\0', sizeof(param
));
2556 p
= make_header(param
, RAP_WsessionDel
, RAP_NetSessionDel_REQ
, NULL
);
2557 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2558 PUTWORD(p
,0); /* reserved word of 0 */
2561 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
2562 NULL
, 0, 200, /* data, length, maxlen */
2563 &rparam
, &rprcnt
, /* return params, length */
2564 &rdata
, &rdrcnt
)) /* return data, length */
2566 char *endp
= rparam
+ rprcnt
;
2567 res
= GETRES(rparam
, endp
);
2568 cli
->rap_error
= res
;
2573 DEBUG(4,("NetFileClose2 res=%d\n", res
));
2577 DEBUG(4,("NetFileClose2 failed\n"));
2586 int cli_NetConnectionEnum(struct cli_state
*cli
, const char *qualifier
,
2587 void (*fn
)(uint16_t conid
, uint16_t contype
,
2588 uint16_t numopens
, uint16_t numusers
,
2589 uint32_t contime
, const char *username
,
2590 const char *netname
))
2592 char param
[WORDSIZE
/* api number */
2593 +sizeof(RAP_NetConnectionEnum_REQ
) /* req string */
2594 +sizeof(RAP_CONNECTION_INFO_L1
) /* return string */
2595 +RAP_MACHNAME_LEN
/* wksta name */
2596 +WORDSIZE
/* info level */
2597 +WORDSIZE
]; /* buffer size */
2599 char *rparam
= NULL
;
2601 unsigned int rprcnt
, rdrcnt
;
2604 memset(param
, '\0', sizeof(param
));
2605 p
= make_header(param
, RAP_WconnectionEnum
,
2606 RAP_NetConnectionEnum_REQ
, RAP_CONNECTION_INFO_L1
);
2607 PUTSTRING(p
, qualifier
, RAP_MACHNAME_LEN
-1);/* Workstation name */
2608 PUTWORD(p
,1); /* Info level 1 */
2609 PUTWORD(p
,0xFFE0); /* Return buffer size */
2612 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2613 NULL
, 0, CLI_BUFFER_SIZE
,
2616 char *endp
= rparam
+ rprcnt
;
2617 res
= GETRES(rparam
, endp
);
2618 cli
->rap_error
= res
;
2620 DEBUG(1,("NetConnectionEnum gave error %d\n", res
));
2625 DEBUG(4,("NetConnectionEnum no data returned\n"));
2629 if (res
== 0 || res
== ERRmoredata
) {
2630 TALLOC_CTX
*frame
= talloc_stackframe();
2631 char *endp
= rparam
+ rprcnt
;
2632 int i
, converter
= 0, count
= 0;
2634 p
= rparam
+ WORDSIZE
;
2635 GETWORD(p
, converter
, endp
);
2636 GETWORD(p
, count
, endp
);
2638 endp
= rdata
+ rdrcnt
;
2639 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2640 char *netname
, *username
;
2641 uint16_t conn_id
= 0, conn_type
= 0, num_opens
= 0, num_users
= 0;
2642 unsigned int conn_time
= 0;
2644 GETWORD(p
,conn_id
, endp
);
2645 GETWORD(p
,conn_type
, endp
);
2646 GETWORD(p
,num_opens
, endp
);
2647 GETWORD(p
,num_users
, endp
);
2648 GETDWORD(p
,conn_time
, endp
);
2649 p
+= rap_getstringp(frame
,
2655 p
+= rap_getstringp(frame
,
2662 if (username
&& netname
) {
2663 fn(conn_id
, conn_type
, num_opens
, num_users
, conn_time
,
2669 DEBUG(4,("NetConnectionEnum res=%d\n", res
));