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 "libsmb/libsmb.h"
80 #include "../librpc/gen_ndr/rap.h"
81 #include "../librpc/gen_ndr/svcctl.h"
82 #include "libsmb/clirap.h"
87 #define PUTBYTE(p,b) do {SCVAL(p,0,b); p++;} while(0)
89 #define GETBYTE(p,b,endp) \
97 #define PUTWORD(p,w) do {SSVAL(p,0,w); p += WORDSIZE;} while(0)
99 #define GETWORD(p,w,endp) \
101 if (p+WORDSIZE < endp) {\
107 #define PUTDWORD(p,d) do {SIVAL(p,0,d); p += DWORDSIZE;} while(0)
109 #define GETDWORD(p,d,endp) \
111 if (p+DWORDSIZE < endp) {\
117 #define GETRES(p,endp) ((p && p+2 < endp) ? SVAL(p,0) : -1)
119 /* put string s at p with max len n and increment p past string */
120 #define PUTSTRING(p,s,n) \
122 push_ascii(p,s?s:"",n?n:256,STR_TERMINATE);\
123 p = push_skip_string(p);\
126 /* put string s and p, using fixed len l, and increment p by l */
127 #define PUTSTRINGF(p,s,l) \
129 push_ascii(p,s?s:"",l,STR_TERMINATE);\
133 /* put string pointer at p, supplying offset o from rdata r, store */
134 /* dword offset at p, increment p by 4 and o by length of s. This */
135 /* means on the first call, you must calc the offset yourself! */
137 #define PUTSTRINGP(p,s,r,o) \
140 push_ascii(r+o,s,strlen(s)+1,STR_TERMINATE);\
148 /* get asciiz string dest from src, return increment past string */
150 static size_t rap_getstring(TALLOC_CTX
*ctx
, char *src
, char **dest
, const char *endp
)
156 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++)
161 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
165 /* get fixed length l string dest from src, return increment for src */
167 static size_t rap_getstringf(char *src
, char *dest
, size_t l
, size_t dlen
, char *endp
)
175 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
185 pull_ascii(dest
,src
,len
,len
,STR_ASCII
);
190 /* get string dest from offset (obtained at p) from rdata r - converter c */
191 static size_t rap_getstringp(TALLOC_CTX
*ctx
, char *p
, char **dest
, char *r
, uint16_t c
, char *endp
)
199 GETDWORD(p
,off
,endp
);
200 off
&= 0x0000FFFF; /* mask the obsolete segment number from the offset */
203 if (r
+off
> endp
|| r
+off
< r
) {
209 for (p1
= src
, len
= 0; *p1
&& p1
< endp
; len
++) {
216 pull_string_talloc(ctx
,src
,0,dest
,src
,len
,STR_ASCII
);
220 static char *make_header(char *param
, uint16 apinum
, const char *reqfmt
, const char *datafmt
)
222 PUTWORD(param
,apinum
);
224 PUTSTRING(param
,reqfmt
,0);
229 PUTSTRING(param
,datafmt
,0);
236 /****************************************************************************
237 call a NetGroupDelete - delete user group from remote server
238 ****************************************************************************/
240 int cli_NetGroupDelete(struct cli_state
*cli
, const char *group_name
)
245 unsigned int rdrcnt
,rprcnt
;
247 char param
[WORDSIZE
/* api number */
248 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
249 +1 /* no ret string */
250 +RAP_GROUPNAME_LEN
/* group to del */
251 +WORDSIZE
]; /* reserved word */
253 /* now send a SMBtrans command with api GroupDel */
254 p
= make_header(param
, RAP_WGroupDel
, RAP_NetGroupDel_REQ
, NULL
);
255 PUTSTRING(p
, group_name
, RAP_GROUPNAME_LEN
);
256 PUTWORD(p
,0); /* reserved word MBZ on input */
259 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
260 NULL
, 0, 200, /* data, length, maxlen */
261 &rparam
, &rprcnt
, /* return params, length */
262 &rdata
, &rdrcnt
)) /* return data, length */
264 char *endp
= rparam
+ rprcnt
;
265 res
= GETRES(rparam
,endp
);
269 } else if ((res
== 5) || (res
== 65)) {
270 DEBUG(1, ("Access Denied\n"));
271 } else if (res
== 2220) {
272 DEBUG (1, ("Group does not exist\n"));
274 DEBUG(4,("NetGroupDelete res=%d\n", res
));
278 DEBUG(4,("NetGroupDelete failed\n"));
287 /****************************************************************************
288 call a NetGroupAdd - add user group to remote server
289 ****************************************************************************/
291 int cli_NetGroupAdd(struct cli_state
*cli
, struct rap_group_info_1
*grinfo
)
296 unsigned int rdrcnt
,rprcnt
;
298 char param
[WORDSIZE
/* api number */
299 +sizeof(RAP_NetGroupAdd_REQ
) /* req string */
300 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
301 +WORDSIZE
/* info level */
302 +WORDSIZE
]; /* reserved word */
304 /* offset into data of free format strings. Will be updated */
305 /* by PUTSTRINGP macro and end up with total data length. */
306 int soffset
= RAP_GROUPNAME_LEN
+ 1 + DWORDSIZE
;
311 data_size
= MAX(soffset
+ strlen(grinfo
->comment
) + 1, 1024);
313 data
= SMB_MALLOC_ARRAY(char, data_size
);
315 DEBUG (1, ("Malloc fail\n"));
319 /* now send a SMBtrans command with api WGroupAdd */
321 p
= make_header(param
, RAP_WGroupAdd
,
322 RAP_NetGroupAdd_REQ
, RAP_GROUP_INFO_L1
);
323 PUTWORD(p
, 1); /* info level */
324 PUTWORD(p
, 0); /* reserved word 0 */
327 PUTSTRINGF(p
, (const char *)grinfo
->group_name
, RAP_GROUPNAME_LEN
);
328 PUTBYTE(p
, 0); /* pad byte 0 */
329 PUTSTRINGP(p
, grinfo
->comment
, data
, soffset
);
332 param
, sizeof(param
), 1024, /* Param, length, maxlen */
333 data
, soffset
, sizeof(data
), /* data, length, maxlen */
334 &rparam
, &rprcnt
, /* return params, length */
335 &rdata
, &rdrcnt
)) /* return data, length */
337 char *endp
= rparam
+ rprcnt
;
338 res
= GETRES(rparam
, endp
);
342 } else if ((res
== 5) || (res
== 65)) {
343 DEBUG(1, ("Access Denied\n"));
344 } else if (res
== 2223) {
345 DEBUG (1, ("Group already exists\n"));
347 DEBUG(4,("NetGroupAdd res=%d\n", res
));
351 DEBUG(4,("NetGroupAdd failed\n"));
361 /****************************************************************************
362 Call a NetGroupEnum - try and list user groups on a different host.
363 ****************************************************************************/
365 int cli_RNetGroupEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
367 char param
[WORDSIZE
/* api number */
368 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
369 +sizeof(RAP_GROUP_INFO_L1
) /* return string */
370 +WORDSIZE
/* info level */
371 +WORDSIZE
]; /* buffer size */
375 unsigned int rprcnt
, rdrcnt
;
378 memset(param
, '\0', sizeof(param
));
379 p
= make_header(param
, RAP_WGroupEnum
,
380 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L1
);
381 PUTWORD(p
,1); /* Info level 1 */ /* add level 0 */
382 PUTWORD(p
,0xFFE0); /* Return buffer size */
385 param
, PTR_DIFF(p
,param
),8,
386 NULL
, 0, 0xFFE0 /* data area size */,
389 char *endp
= rparam
+ rdrcnt
;
391 res
= GETRES(rparam
, endp
);
392 cli
->rap_error
= res
;
393 if(cli
->rap_error
== 234) {
394 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
395 } else if (cli
->rap_error
!= 0) {
396 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
401 DEBUG(4,("NetGroupEnum no data returned\n"));
405 if (res
== 0 || res
== ERRmoredata
) {
406 char *endp
= rparam
+ rprcnt
;
407 int i
, converter
= 0, count
= 0;
408 TALLOC_CTX
*frame
= talloc_stackframe();
410 p
= rparam
+ WORDSIZE
; /* skip result */
411 GETWORD(p
, converter
, endp
);
412 GETWORD(p
, count
, endp
);
414 endp
= rdata
+ rdrcnt
;
415 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
416 char *comment
= NULL
;
417 char groupname
[RAP_GROUPNAME_LEN
];
419 p
+= rap_getstringf(p
,
425 p
+= rap_getstringp(frame
,
432 if (!comment
|| !groupname
[0]) {
436 fn(groupname
, comment
, cli
);
440 DEBUG(4,("NetGroupEnum res=%d\n", res
));
451 int cli_RNetGroupEnum0(struct cli_state
*cli
,
452 void (*fn
)(const char *, void *),
455 char param
[WORDSIZE
/* api number */
456 +sizeof(RAP_NetGroupEnum_REQ
) /* parm string */
457 +sizeof(RAP_GROUP_INFO_L0
) /* return string */
458 +WORDSIZE
/* info level */
459 +WORDSIZE
]; /* buffer size */
463 unsigned int rprcnt
, rdrcnt
;
466 memset(param
, '\0', sizeof(param
));
467 p
= make_header(param
, RAP_WGroupEnum
,
468 RAP_NetGroupEnum_REQ
, RAP_GROUP_INFO_L0
);
469 PUTWORD(p
,0); /* Info level 0 */ /* Hmmm. I *very* much suspect this
470 is the resume count, at least
471 that's what smbd believes... */
472 PUTWORD(p
,0xFFE0); /* Return buffer size */
475 param
, PTR_DIFF(p
,param
),8,
476 NULL
, 0, 0xFFE0 /* data area size */,
479 char *endp
= rparam
+rprcnt
;
480 res
= GETRES(rparam
,endp
);
481 cli
->rap_error
= res
;
482 if(cli
->rap_error
== 234) {
483 DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
484 } else if (cli
->rap_error
!= 0) {
485 DEBUG(1,("NetGroupEnum gave error %d\n", cli
->rap_error
));
490 DEBUG(4,("NetGroupEnum no data returned\n"));
494 if (res
== 0 || res
== ERRmoredata
) {
495 char *endp
= rparam
+ rprcnt
;
498 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
499 GETWORD(p
, count
, endp
);
501 endp
= rdata
+ rdrcnt
;
502 for (i
=0,p
=rdata
; i
<count
&& p
< endp
;i
++) {
503 char groupname
[RAP_GROUPNAME_LEN
];
505 p
+= rap_getstringf(p
,
515 DEBUG(4,("NetGroupEnum res=%d\n", res
));
526 int cli_NetGroupDelUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
531 unsigned int rdrcnt
,rprcnt
;
533 char param
[WORDSIZE
/* api number */
534 +sizeof(RAP_NetGroupDelUser_REQ
) /* parm string */
535 +1 /* no ret string */
536 +RAP_GROUPNAME_LEN
/* group name */
537 +RAP_USERNAME_LEN
]; /* user to del */
539 /* now send a SMBtrans command with api GroupMemberAdd */
540 p
= make_header(param
, RAP_WGroupDelUser
, RAP_NetGroupDelUser_REQ
, NULL
);
541 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
542 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
545 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
546 NULL
, 0, 200, /* data, length, maxlen */
547 &rparam
, &rprcnt
, /* return params, length */
548 &rdata
, &rdrcnt
)) /* return data, length */
550 char *endp
= rparam
+ rprcnt
;
551 res
= GETRES(rparam
,endp
);
558 DEBUG(1, ("Access Denied\n"));
561 DEBUG(1, ("Not supported by server\n"));
564 DEBUG(1, ("Group does not exist\n"));
567 DEBUG(1, ("User does not exist\n"));
570 DEBUG(1, ("User is not in group\n"));
573 DEBUG(4,("NetGroupDelUser res=%d\n", res
));
577 DEBUG(4,("NetGroupDelUser failed\n"));
586 int cli_NetGroupAddUser(struct cli_state
* cli
, const char *group_name
, const char *user_name
)
591 unsigned int rdrcnt
,rprcnt
;
593 char param
[WORDSIZE
/* api number */
594 +sizeof(RAP_NetGroupAddUser_REQ
) /* parm string */
595 +1 /* no ret string */
596 +RAP_GROUPNAME_LEN
/* group name */
597 +RAP_USERNAME_LEN
]; /* user to add */
599 /* now send a SMBtrans command with api GroupMemberAdd */
600 p
= make_header(param
, RAP_WGroupAddUser
, RAP_NetGroupAddUser_REQ
, NULL
);
601 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
);
602 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
);
605 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
606 NULL
, 0, 200, /* data, length, maxlen */
607 &rparam
, &rprcnt
, /* return params, length */
608 &rdata
, &rdrcnt
)) /* return data, length */
610 char *endp
= rparam
+ rprcnt
;
611 res
= GETRES(rparam
,endp
);
618 DEBUG(1, ("Access Denied\n"));
621 DEBUG(1, ("Not supported by server\n"));
624 DEBUG(1, ("Group does not exist\n"));
627 DEBUG(1, ("User does not exist\n"));
630 DEBUG(4,("NetGroupAddUser res=%d\n", res
));
634 DEBUG(4,("NetGroupAddUser failed\n"));
644 int cli_NetGroupGetUsers(struct cli_state
* cli
, const char *group_name
, void (*fn
)(const char *, void *), void *state
)
649 unsigned int rdrcnt
,rprcnt
;
651 char param
[WORDSIZE
/* api number */
652 +sizeof(RAP_NetGroupGetUsers_REQ
)/* parm string */
653 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
654 +RAP_GROUPNAME_LEN
/* group name */
655 +WORDSIZE
/* info level */
656 +WORDSIZE
]; /* buffer size */
658 /* now send a SMBtrans command with api GroupGetUsers */
659 p
= make_header(param
, RAP_WGroupGetUsers
,
660 RAP_NetGroupGetUsers_REQ
, RAP_GROUP_USERS_INFO_0
);
661 PUTSTRING(p
,group_name
,RAP_GROUPNAME_LEN
-1);
662 PUTWORD(p
,0); /* info level 0 */
663 PUTWORD(p
,0xFFE0); /* return buffer size */
666 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
667 NULL
, 0, CLI_BUFFER_SIZE
,
670 char *endp
= rparam
+ rprcnt
;
671 res
= GETRES(rparam
,endp
);
672 cli
->rap_error
= res
;
674 DEBUG(1,("NetGroupGetUsers gave error %d\n", res
));
679 DEBUG(4,("NetGroupGetUsers no data returned\n"));
683 if (res
== 0 || res
== ERRmoredata
) {
684 char *endp
= rparam
+ rprcnt
;
686 char username
[RAP_USERNAME_LEN
];
688 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
689 GETWORD(p
, count
, endp
);
691 endp
= rdata
+ rdrcnt
;
692 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
693 p
+= rap_getstringf(p
,
703 DEBUG(4,("NetGroupGetUsers res=%d\n", res
));
713 int cli_NetUserGetGroups(struct cli_state
* cli
, const char *user_name
, void (*fn
)(const char *, void *), void *state
)
718 unsigned int rdrcnt
,rprcnt
;
720 char param
[WORDSIZE
/* api number */
721 +sizeof(RAP_NetUserGetGroups_REQ
)/* parm string */
722 +sizeof(RAP_GROUP_USERS_INFO_0
) /* return string */
723 +RAP_USERNAME_LEN
/* user name */
724 +WORDSIZE
/* info level */
725 +WORDSIZE
]; /* buffer size */
727 /* now send a SMBtrans command with api GroupGetUsers */
728 p
= make_header(param
, RAP_WUserGetGroups
,
729 RAP_NetUserGetGroups_REQ
, RAP_GROUP_USERS_INFO_0
);
730 PUTSTRING(p
,user_name
,RAP_USERNAME_LEN
-1);
731 PUTWORD(p
,0); /* info level 0 */
732 PUTWORD(p
,0xFFE0); /* return buffer size */
735 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
736 NULL
, 0, CLI_BUFFER_SIZE
,
739 char *endp
= rparam
+ rprcnt
;
740 res
= GETRES(rparam
,endp
);
741 cli
->rap_error
= res
;
743 DEBUG(1,("NetUserGetGroups gave error %d\n", res
));
748 DEBUG(4,("NetUserGetGroups no data returned\n"));
752 if (res
== 0 || res
== ERRmoredata
) {
753 char *endp
= rparam
+ rprcnt
;
755 char groupname
[RAP_GROUPNAME_LEN
];
757 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
758 GETWORD(p
, count
, endp
);
760 endp
= rdata
+ rdrcnt
;
761 for (i
=0,p
=rdata
; i
<count
&& p
< endp
; i
++) {
762 p
+= rap_getstringf(p
,
768 fn(groupname
, state
);
772 DEBUG(4,("NetUserGetGroups res=%d\n", res
));
782 /****************************************************************************
783 Call a NetUserDelete - delete user from remote server.
784 ****************************************************************************/
786 int cli_NetUserDelete(struct cli_state
*cli
, const char * user_name
)
791 unsigned int rdrcnt
,rprcnt
;
793 char param
[WORDSIZE
/* api number */
794 +sizeof(RAP_NetGroupDel_REQ
) /* parm string */
795 +1 /* no ret string */
796 +RAP_USERNAME_LEN
/* user to del */
797 +WORDSIZE
]; /* reserved word */
799 /* now send a SMBtrans command with api UserDel */
800 p
= make_header(param
, RAP_WUserDel
, RAP_NetGroupDel_REQ
, NULL
);
801 PUTSTRING(p
, user_name
, RAP_USERNAME_LEN
);
802 PUTWORD(p
,0); /* reserved word MBZ on input */
805 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
806 NULL
, 0, 200, /* data, length, maxlen */
807 &rparam
, &rprcnt
, /* return params, length */
808 &rdata
, &rdrcnt
)) /* return data, length */
810 char *endp
= rparam
+ rprcnt
;
811 res
= GETRES(rparam
,endp
);
815 } else if ((res
== 5) || (res
== 65)) {
816 DEBUG(1, ("Access Denied\n"));
817 } else if (res
== 2221) {
818 DEBUG (1, ("User does not exist\n"));
820 DEBUG(4,("NetUserDelete res=%d\n", res
));
824 DEBUG(4,("NetUserDelete failed\n"));
833 /****************************************************************************
834 Call a NetUserAdd - add user to remote server.
835 ****************************************************************************/
837 int cli_NetUserAdd(struct cli_state
*cli
, struct rap_user_info_1
* userinfo
)
842 unsigned int rdrcnt
,rprcnt
;
844 char param
[WORDSIZE
/* api number */
845 +sizeof(RAP_NetUserAdd2_REQ
) /* req string */
846 +sizeof(RAP_USER_INFO_L1
) /* data string */
847 +WORDSIZE
/* info level */
848 +WORDSIZE
/* buffer length */
849 +WORDSIZE
]; /* reserved */
852 /* offset into data of free format strings. Will be updated */
853 /* by PUTSTRINGP macro and end up with total data length. */
854 int soffset
=RAP_USERNAME_LEN
+1 /* user name + pad */
855 + RAP_UPASSWD_LEN
/* password */
856 + DWORDSIZE
/* password age */
857 + WORDSIZE
/* privilege */
858 + DWORDSIZE
/* home dir ptr */
859 + DWORDSIZE
/* comment ptr */
860 + WORDSIZE
/* flags */
861 + DWORDSIZE
; /* login script ptr*/
863 /* now send a SMBtrans command with api NetUserAdd */
864 p
= make_header(param
, RAP_WUserAdd2
,
865 RAP_NetUserAdd2_REQ
, RAP_USER_INFO_L1
);
867 PUTWORD(p
, 1); /* info level */
868 PUTWORD(p
, 0); /* pwencrypt */
869 if(userinfo
->passwrd
)
870 PUTWORD(p
,MIN(strlen((const char *)userinfo
->passwrd
), RAP_UPASSWD_LEN
));
872 PUTWORD(p
, 0); /* password length */
875 memset(data
, '\0', soffset
);
877 PUTSTRINGF(p
, (const char *)userinfo
->user_name
, RAP_USERNAME_LEN
);
878 PUTBYTE(p
, 0); /* pad byte 0 */
879 PUTSTRINGF(p
, (const char *)userinfo
->passwrd
, RAP_UPASSWD_LEN
);
880 PUTDWORD(p
, 0); /* pw age - n.a. on user add */
881 PUTWORD(p
, userinfo
->priv
);
882 PUTSTRINGP(p
, userinfo
->home_dir
, data
, soffset
);
883 PUTSTRINGP(p
, userinfo
->comment
, data
, soffset
);
884 PUTWORD(p
, userinfo
->userflags
);
885 PUTSTRINGP(p
, userinfo
->logon_script
, data
, soffset
);
888 param
, sizeof(param
), 1024, /* Param, length, maxlen */
889 data
, soffset
, sizeof(data
), /* data, length, maxlen */
890 &rparam
, &rprcnt
, /* return params, length */
891 &rdata
, &rdrcnt
)) /* return data, length */
893 char *endp
= rparam
+ rprcnt
;
894 res
= GETRES(rparam
, endp
);
898 } else if ((res
== 5) || (res
== 65)) {
899 DEBUG(1, ("Access Denied\n"));
900 } else if (res
== 2224) {
901 DEBUG (1, ("User already exists\n"));
903 DEBUG(4,("NetUserAdd res=%d\n", res
));
907 DEBUG(4,("NetUserAdd failed\n"));
916 /****************************************************************************
917 call a NetUserEnum - try and list users on a different host
918 ****************************************************************************/
920 int cli_RNetUserEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, const char *, const char *, void *), void *state
)
922 char param
[WORDSIZE
/* api number */
923 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
924 +sizeof(RAP_USER_INFO_L1
) /* return string */
925 +WORDSIZE
/* info level */
926 +WORDSIZE
]; /* buffer size */
930 unsigned int rprcnt
, rdrcnt
;
933 memset(param
, '\0', sizeof(param
));
934 p
= make_header(param
, RAP_WUserEnum
,
935 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L1
);
936 PUTWORD(p
,1); /* Info level 1 */
937 PUTWORD(p
,0xFF00); /* Return buffer size */
939 /* BB Fix handling of large numbers of users to be returned */
941 param
, PTR_DIFF(p
,param
),8,
942 NULL
, 0, CLI_BUFFER_SIZE
,
945 char *endp
= rparam
+ rprcnt
;
946 res
= GETRES(rparam
,endp
);
947 cli
->rap_error
= res
;
948 if (cli
->rap_error
!= 0) {
949 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
954 DEBUG(4,("NetUserEnum no data returned\n"));
958 if (res
== 0 || res
== ERRmoredata
) {
959 int i
, converter
= 0, count
= 0;
960 char username
[RAP_USERNAME_LEN
];
961 char userpw
[RAP_UPASSWD_LEN
];
962 char *endp
= rparam
+ rprcnt
;
963 char *comment
, *homedir
, *logonscript
;
964 TALLOC_CTX
*frame
= talloc_stackframe();
966 p
= rparam
+ WORDSIZE
; /* skip result */
967 GETWORD(p
, converter
, endp
);
968 GETWORD(p
, count
, endp
);
970 endp
= rdata
+ rdrcnt
;
971 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
972 p
+= rap_getstringf(p
,
978 p
+= rap_getstringf(p
,
983 p
+= DWORDSIZE
; /* skip password age */
984 p
+= WORDSIZE
; /* skip priv: 0=guest, 1=user, 2=admin */
985 p
+= rap_getstringp(frame
,
991 p
+= rap_getstringp(frame
,
997 p
+= WORDSIZE
; /* skip flags */
998 p
+= rap_getstringp(frame
,
1004 if (username
[0] && comment
&&
1005 homedir
&& logonscript
) {
1015 DEBUG(4,("NetUserEnum res=%d\n", res
));
1026 int cli_RNetUserEnum0(struct cli_state
*cli
,
1027 void (*fn
)(const char *, void *),
1030 char param
[WORDSIZE
/* api number */
1031 +sizeof(RAP_NetUserEnum_REQ
) /* parm string */
1032 +sizeof(RAP_USER_INFO_L0
) /* return string */
1033 +WORDSIZE
/* info level */
1034 +WORDSIZE
]; /* buffer size */
1036 char *rparam
= NULL
;
1038 unsigned int rprcnt
, rdrcnt
;
1041 memset(param
, '\0', sizeof(param
));
1042 p
= make_header(param
, RAP_WUserEnum
,
1043 RAP_NetUserEnum_REQ
, RAP_USER_INFO_L0
);
1044 PUTWORD(p
,0); /* Info level 1 */
1045 PUTWORD(p
,0xFF00); /* Return buffer size */
1047 /* BB Fix handling of large numbers of users to be returned */
1049 param
, PTR_DIFF(p
,param
),8,
1050 NULL
, 0, CLI_BUFFER_SIZE
,
1053 char *endp
= rparam
+ rprcnt
;
1054 res
= GETRES(rparam
,endp
);
1055 cli
->rap_error
= res
;
1056 if (cli
->rap_error
!= 0) {
1057 DEBUG(1,("NetUserEnum gave error %d\n", cli
->rap_error
));
1062 DEBUG(4,("NetUserEnum no data returned\n"));
1066 if (res
== 0 || res
== ERRmoredata
) {
1068 char *endp
= rparam
+ rprcnt
;
1069 char username
[RAP_USERNAME_LEN
];
1071 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1072 GETWORD(p
, count
, endp
);
1074 endp
= rdata
+ rdrcnt
;
1075 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
1076 p
+= rap_getstringf(p
,
1086 DEBUG(4,("NetUserEnum res=%d\n", res
));
1097 /****************************************************************************
1098 Call a NetFileClose2 - close open file on another session to server.
1099 ****************************************************************************/
1101 int cli_NetFileClose(struct cli_state
*cli
, uint32 file_id
)
1103 char *rparam
= NULL
;
1106 unsigned int rdrcnt
,rprcnt
;
1107 char param
[WORDSIZE
/* api number */
1108 +sizeof(RAP_WFileClose2_REQ
) /* req string */
1109 +1 /* no ret string */
1110 +DWORDSIZE
]; /* file ID */
1113 /* now send a SMBtrans command with api RNetShareEnum */
1114 p
= make_header(param
, RAP_WFileClose2
, RAP_WFileClose2_REQ
, NULL
);
1115 PUTDWORD(p
, file_id
);
1118 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1119 NULL
, 0, 200, /* data, length, maxlen */
1120 &rparam
, &rprcnt
, /* return params, length */
1121 &rdata
, &rdrcnt
)) /* return data, length */
1123 char *endp
= rparam
+ rprcnt
;
1124 res
= GETRES(rparam
, endp
);
1128 } else if (res
== 2314){
1129 DEBUG(1, ("NetFileClose2 - attempt to close non-existant file open instance\n"));
1131 DEBUG(4,("NetFileClose2 res=%d\n", res
));
1135 DEBUG(4,("NetFileClose2 failed\n"));
1144 /****************************************************************************
1145 Call a NetFileGetInfo - get information about server file opened from other
1147 ****************************************************************************/
1149 int cli_NetFileGetInfo(struct cli_state
*cli
, uint32 file_id
, void (*fn
)(const char *, const char *, uint16
, uint16
, uint32
))
1151 char *rparam
= NULL
;
1154 unsigned int rdrcnt
,rprcnt
;
1156 char param
[WORDSIZE
/* api number */
1157 +sizeof(RAP_WFileGetInfo2_REQ
) /* req string */
1158 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1159 +DWORDSIZE
/* file ID */
1160 +WORDSIZE
/* info level */
1161 +WORDSIZE
]; /* buffer size */
1163 /* now send a SMBtrans command with api RNetShareEnum */
1164 p
= make_header(param
, RAP_WFileGetInfo2
,
1165 RAP_WFileGetInfo2_REQ
, RAP_FILE_INFO_L3
);
1166 PUTDWORD(p
, file_id
);
1167 PUTWORD(p
, 3); /* info level */
1168 PUTWORD(p
, 0x1000); /* buffer size */
1170 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1171 NULL
, 0, 0x1000, /* data, length, maxlen */
1172 &rparam
, &rprcnt
, /* return params, length */
1173 &rdata
, &rdrcnt
)) /* return data, length */
1175 char *endp
= rparam
+ rprcnt
;
1176 res
= GETRES(rparam
,endp
);
1177 if (res
== 0 || res
== ERRmoredata
) {
1178 TALLOC_CTX
*frame
= talloc_stackframe();
1179 int converter
= 0,id
= 0, perms
= 0, locks
= 0;
1180 char *fpath
, *fuser
;
1182 p
= rparam
+ WORDSIZE
; /* skip result */
1183 GETWORD(p
, converter
, endp
);
1186 endp
= rdata
+ rdrcnt
;
1188 GETDWORD(p
, id
, endp
);
1189 GETWORD(p
, perms
, endp
);
1190 GETWORD(p
, locks
, endp
);
1192 p
+= rap_getstringp(frame
,
1198 p
+= rap_getstringp(frame
,
1205 if (fpath
&& fuser
) {
1206 fn(fpath
, fuser
, perms
, locks
, id
);
1211 DEBUG(4,("NetFileGetInfo2 res=%d\n", res
));
1215 DEBUG(4,("NetFileGetInfo2 failed\n"));
1224 /****************************************************************************
1225 * Call a NetFileEnum2 - list open files on an SMB server
1227 * PURPOSE: Remotes a NetFileEnum API call to the current server or target
1228 * server listing the files open via the network (and their
1229 * corresponding open instance ids)
1231 * Dependencies: none
1234 * cli - pointer to cli_state structure
1235 * user - if present, return only files opened by this remote user
1236 * base_path - if present, return only files opened below this
1238 * fn - display function to invoke for each entry in the result
1245 ****************************************************************************/
1247 int cli_NetFileEnum(struct cli_state
*cli
, const char * user
,
1248 const char * base_path
,
1249 void (*fn
)(const char *, const char *, uint16
, uint16
,
1252 char *rparam
= NULL
;
1255 unsigned int rdrcnt
,rprcnt
;
1256 char param
[WORDSIZE
/* api number */
1257 +sizeof(RAP_WFileEnum2_REQ
) /* req string */
1258 +sizeof(RAP_FILE_INFO_L3
) /* return string */
1259 +1024 /* base path (opt) */
1260 +RAP_USERNAME_LEN
/* user name (opt) */
1261 +WORDSIZE
/* info level */
1262 +WORDSIZE
/* buffer size */
1263 +DWORDSIZE
/* resume key ? */
1264 +DWORDSIZE
]; /* resume key ? */
1268 /* now send a SMBtrans command with api RNetShareEnum */
1269 p
= make_header(param
, RAP_WFileEnum2
,
1270 RAP_WFileEnum2_REQ
, RAP_FILE_INFO_L3
);
1272 PUTSTRING(p
, base_path
, 1024);
1273 PUTSTRING(p
, user
, RAP_USERNAME_LEN
);
1274 PUTWORD(p
, 3); /* info level */
1275 PUTWORD(p
, 0xFF00); /* buffer size */
1276 PUTDWORD(p
, 0); /* zero out the resume key */
1277 PUTDWORD(p
, 0); /* or is this one the resume key? */
1280 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1281 NULL
, 0, 0xFF00, /* data, length, maxlen */
1282 &rparam
, &rprcnt
, /* return params, length */
1283 &rdata
, &rdrcnt
)) /* return data, length */
1285 char *endp
= rparam
+ rprcnt
;
1286 res
= GETRES(rparam
, endp
);
1288 if (res
== 0 || res
== ERRmoredata
) {
1289 TALLOC_CTX
*frame
= talloc_stackframe();
1290 int converter
= 0, i
;
1292 p
= rparam
+ WORDSIZE
; /* skip result */
1293 GETWORD(p
, converter
, endp
);
1294 GETWORD(p
, count
, endp
);
1297 endp
= rdata
+ rdrcnt
;
1298 for (i
=0; i
<count
&& p
< endp
; i
++) {
1299 int id
= 0, perms
= 0, locks
= 0;
1300 char *fpath
, *fuser
;
1302 GETDWORD(p
, id
, endp
);
1303 GETWORD(p
, perms
, endp
);
1304 GETWORD(p
, locks
, endp
);
1305 p
+= rap_getstringp(frame
,
1311 p
+= rap_getstringp(frame
,
1318 if (fpath
&& fuser
) {
1319 fn(fpath
, fuser
, perms
, locks
, id
);
1321 } /* BB fix ERRmoredata case to send resume request */
1324 DEBUG(4,("NetFileEnum2 res=%d\n", res
));
1327 DEBUG(4,("NetFileEnum2 failed\n"));
1336 /****************************************************************************
1337 Call a NetShareAdd - share/export directory on remote server.
1338 ****************************************************************************/
1340 int cli_NetShareAdd(struct cli_state
*cli
, struct rap_share_info_2
* sinfo
)
1342 char *rparam
= NULL
;
1345 unsigned int rdrcnt
,rprcnt
;
1347 char param
[WORDSIZE
/* api number */
1348 +sizeof(RAP_WShareAdd_REQ
) /* req string */
1349 +sizeof(RAP_SHARE_INFO_L2
) /* return string */
1350 +WORDSIZE
/* info level */
1351 +WORDSIZE
]; /* reserved word */
1353 /* offset to free format string section following fixed length data. */
1354 /* will be updated by PUTSTRINGP macro and will end up with total len */
1355 int soffset
= RAP_SHARENAME_LEN
+ 1 /* share name + pad */
1356 + WORDSIZE
/* share type */
1357 + DWORDSIZE
/* comment pointer */
1358 + WORDSIZE
/* permissions */
1359 + WORDSIZE
/* max users */
1360 + WORDSIZE
/* active users */
1361 + DWORDSIZE
/* share path */
1362 + RAP_SPASSWD_LEN
+ 1; /* share password + pad */
1364 memset(param
,'\0',sizeof(param
));
1365 /* now send a SMBtrans command with api RNetShareAdd */
1366 p
= make_header(param
, RAP_WshareAdd
,
1367 RAP_WShareAdd_REQ
, RAP_SHARE_INFO_L2
);
1368 PUTWORD(p
, 2); /* info level */
1369 PUTWORD(p
, 0); /* reserved word 0 */
1372 PUTSTRINGF(p
, (const char *)sinfo
->share_name
, RAP_SHARENAME_LEN
);
1373 PUTBYTE(p
, 0); /* pad byte 0 */
1375 PUTWORD(p
, sinfo
->share_type
);
1376 PUTSTRINGP(p
, sinfo
->comment
, data
, soffset
);
1377 PUTWORD(p
, sinfo
->perms
);
1378 PUTWORD(p
, sinfo
->maximum_users
);
1379 PUTWORD(p
, sinfo
->active_users
);
1380 PUTSTRINGP(p
, sinfo
->path
, data
, soffset
);
1381 PUTSTRINGF(p
, (const char *)sinfo
->password
, RAP_SPASSWD_LEN
);
1382 SCVAL(p
,-1,0x0A); /* required 0x0A at end of password */
1385 param
, sizeof(param
), 1024, /* Param, length, maxlen */
1386 data
, soffset
, sizeof(data
), /* data, length, maxlen */
1387 &rparam
, &rprcnt
, /* return params, length */
1388 &rdata
, &rdrcnt
)) /* return data, length */
1390 char *endp
= rparam
+ rprcnt
;
1391 res
= GETRES(rparam
, endp
);
1396 DEBUG(4,("NetShareAdd res=%d\n", res
));
1399 DEBUG(4,("NetShareAdd failed\n"));
1408 /****************************************************************************
1409 Call a NetShareDelete - unshare exported directory on remote server.
1410 ****************************************************************************/
1412 int cli_NetShareDelete(struct cli_state
*cli
, const char * share_name
)
1414 char *rparam
= NULL
;
1417 unsigned int rdrcnt
,rprcnt
;
1419 char param
[WORDSIZE
/* api number */
1420 +sizeof(RAP_WShareDel_REQ
) /* req string */
1421 +1 /* no ret string */
1422 +RAP_SHARENAME_LEN
/* share to del */
1423 +WORDSIZE
]; /* reserved word */
1425 /* now send a SMBtrans command with api RNetShareDelete */
1426 p
= make_header(param
, RAP_WshareDel
, RAP_WShareDel_REQ
, NULL
);
1427 PUTSTRING(p
,share_name
,RAP_SHARENAME_LEN
);
1428 PUTWORD(p
,0); /* reserved word MBZ on input */
1431 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
1432 NULL
, 0, 200, /* data, length, maxlen */
1433 &rparam
, &rprcnt
, /* return params, length */
1434 &rdata
, &rdrcnt
)) /* return data, length */
1436 char *endp
= rparam
+ rprcnt
;
1437 res
= GETRES(rparam
, endp
);
1442 DEBUG(4,("NetShareDelete res=%d\n", res
));
1445 DEBUG(4,("NetShareDelete failed\n"));
1454 /*************************************************************************
1456 * Function Name: cli_get_pdc_name
1458 * PURPOSE: Remotes a NetServerEnum API call to the current server
1459 * requesting the name of a server matching the server
1460 * type of SV_TYPE_DOMAIN_CTRL (PDC).
1462 * Dependencies: none
1465 * cli - pointer to cli_state structure
1466 * workgroup - pointer to string containing name of domain
1467 * pdc_name - pointer to string that will contain PDC name
1468 * on successful return
1474 ************************************************************************/
1476 bool cli_get_pdc_name(struct cli_state
*cli
, const char *workgroup
, char **pdc_name
)
1478 char *rparam
= NULL
;
1480 unsigned int rdrcnt
,rprcnt
;
1482 char param
[WORDSIZE
/* api number */
1483 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1484 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1485 +WORDSIZE
/* info level */
1486 +WORDSIZE
/* buffer size */
1487 +DWORDSIZE
/* server type */
1488 +RAP_MACHNAME_LEN
]; /* workgroup */
1494 /* send a SMBtrans command with api NetServerEnum */
1495 p
= make_header(param
, RAP_NetServerEnum2
,
1496 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L1
);
1497 PUTWORD(p
, 1); /* info level */
1498 PUTWORD(p
, CLI_BUFFER_SIZE
);
1499 PUTDWORD(p
, SV_TYPE_DOMAIN_CTRL
);
1500 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1503 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1504 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1505 &rparam
, &rprcnt
, /* return params, return size */
1506 &rdata
, &rdrcnt
/* return data, return size */
1509 char *endp
= rparam
+ rprcnt
;
1510 res
= GETRES(rparam
, endp
);
1511 cli
->rap_error
= res
;
1514 * We only really care to copy a name if the
1515 * API succeeded and we got back a name.
1517 if (cli
->rap_error
== 0) {
1518 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
1519 GETWORD(p
, count
, endp
);
1521 endp
= rdata
+ rdrcnt
;
1524 TALLOC_CTX
*frame
= talloc_stackframe();
1526 p
+= rap_getstring(frame
,
1531 *pdc_name
= SMB_STRDUP(dcname
);
1536 DEBUG(4,("cli_get_pdc_name: machine %s failed the NetServerEnum call. "
1537 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1547 /*************************************************************************
1549 * Function Name: cli_get_server_domain
1551 * PURPOSE: Remotes a NetWkstaGetInfo API call to the current server
1552 * requesting wksta_info_10 level information to determine
1553 * the domain the server belongs to. On success, this
1554 * routine sets the server_domain field in the cli_state structure
1555 * to the server's domain name.
1557 * Dependencies: none
1560 * cli - pointer to cli_state structure
1566 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1568 ************************************************************************/
1570 bool cli_get_server_domain(struct cli_state
*cli
)
1572 char *rparam
= NULL
;
1574 unsigned int rdrcnt
,rprcnt
;
1576 char param
[WORDSIZE
/* api number */
1577 +sizeof(RAP_WWkstaGetInfo_REQ
) /* req string */
1578 +sizeof(RAP_WKSTA_INFO_L10
) /* return string */
1579 +WORDSIZE
/* info level */
1580 +WORDSIZE
]; /* buffer size */
1583 /* send a SMBtrans command with api NetWkstaGetInfo */
1584 p
= make_header(param
, RAP_WWkstaGetInfo
,
1585 RAP_WWkstaGetInfo_REQ
, RAP_WKSTA_INFO_L10
);
1586 PUTWORD(p
, 10); /* info level */
1587 PUTWORD(p
, CLI_BUFFER_SIZE
);
1589 if (cli_api(cli
, param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1590 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1591 &rparam
, &rprcnt
, /* return params, return size */
1592 &rdata
, &rdrcnt
)) { /* return data, return size */
1593 char *endp
= rparam
+ rprcnt
;
1594 res
= GETRES(rparam
, endp
);
1597 TALLOC_CTX
*frame
= talloc_stackframe();
1598 char *server_domain
;
1601 p
= rparam
+ WORDSIZE
;
1602 GETWORD(p
, converter
, endp
);
1604 p
= rdata
+ DWORDSIZE
+ DWORDSIZE
; /* skip computer & user names */
1605 endp
= rdata
+ rdrcnt
;
1606 p
+= rap_getstringp(frame
,
1613 if (server_domain
) {
1614 fstrcpy(cli
->server_domain
, server_domain
);
1626 /*************************************************************************
1628 * Function Name: cli_get_server_type
1630 * PURPOSE: Remotes a NetServerGetInfo API call to the current server
1631 * requesting server_info_1 level information to retrieve
1634 * Dependencies: none
1637 * cli - pointer to cli_state structure
1638 * pstype - pointer to uint32 to contain returned server type
1644 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1646 ************************************************************************/
1648 bool cli_get_server_type(struct cli_state
*cli
, uint32
*pstype
)
1650 char *rparam
= NULL
;
1652 unsigned int rdrcnt
,rprcnt
;
1654 char param
[WORDSIZE
/* api number */
1655 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1656 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1657 +WORDSIZE
/* info level */
1658 +WORDSIZE
]; /* buffer size */
1661 /* send a SMBtrans command with api NetServerGetInfo */
1662 p
= make_header(param
, RAP_WserverGetInfo
,
1663 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1664 PUTWORD(p
, 1); /* info level */
1665 PUTWORD(p
, CLI_BUFFER_SIZE
);
1668 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1669 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1670 &rparam
, &rprcnt
, /* return params, return size */
1671 &rdata
, &rdrcnt
/* return data, return size */
1673 char *endp
= rparam
+ rprcnt
;
1674 res
= GETRES(rparam
,endp
);
1676 if (res
== 0 || res
== ERRmoredata
) {
1678 endp
= rparam
+ rprcnt
;
1680 GETDWORD(p
,*pstype
,endp
);
1681 *pstype
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1688 return(res
== 0 || res
== ERRmoredata
);
1691 bool cli_get_server_name(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
1694 char *rparam
= NULL
;
1696 unsigned int rdrcnt
,rprcnt
;
1698 char param
[WORDSIZE
/* api number */
1699 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1700 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1701 +WORDSIZE
/* info level */
1702 +WORDSIZE
]; /* buffer size */
1707 /* send a SMBtrans command with api NetServerGetInfo */
1708 p
= make_header(param
, RAP_WserverGetInfo
,
1709 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1710 PUTWORD(p
, 1); /* info level */
1711 PUTWORD(p
, CLI_BUFFER_SIZE
);
1714 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1715 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1716 &rparam
, &rprcnt
, /* return params, return size */
1717 &rdata
, &rdrcnt
/* return data, return size */
1722 endp
= rparam
+ rprcnt
;
1723 if (GETRES(rparam
, endp
) != 0) {
1728 DEBUG(10, ("invalid data count %d, expected >= 16\n", rdrcnt
));
1732 if (pull_ascii(tmp
, rdata
, sizeof(tmp
)-1, 16, STR_TERMINATE
) == -1) {
1733 DEBUG(10, ("pull_ascii failed\n"));
1737 if (!(*servername
= talloc_strdup(mem_ctx
, tmp
))) {
1738 DEBUG(1, ("talloc_strdup failed\n"));
1750 /*************************************************************************
1752 * Function Name: cli_ns_check_server_type
1754 * PURPOSE: Remotes a NetServerEnum2 API call to the current server
1755 * requesting server_info_0 level information of machines
1756 * matching the given server type. If the returned server
1757 * list contains the machine name contained in cli->desthost
1758 * then we conclude the server type checks out. This routine
1759 * is useful to retrieve list of server's of a certain
1760 * type when all you have is a null session connection and
1761 * can't remote API calls such as NetWkstaGetInfo or
1764 * Dependencies: none
1767 * cli - pointer to cli_state structure
1768 * workgroup - pointer to string containing domain
1769 * stype - server type
1775 ************************************************************************/
1777 bool cli_ns_check_server_type(struct cli_state
*cli
, char *workgroup
, uint32 stype
)
1779 char *rparam
= NULL
;
1781 unsigned int rdrcnt
,rprcnt
;
1783 char param
[WORDSIZE
/* api number */
1784 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1785 +sizeof(RAP_SERVER_INFO_L0
) /* return string */
1786 +WORDSIZE
/* info level */
1787 +WORDSIZE
/* buffer size */
1788 +DWORDSIZE
/* server type */
1789 +RAP_MACHNAME_LEN
]; /* workgroup */
1790 bool found_server
= false;
1793 /* send a SMBtrans command with api NetServerEnum */
1794 p
= make_header(param
, RAP_NetServerEnum2
,
1795 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L0
);
1796 PUTWORD(p
, 0); /* info level 0 */
1797 PUTWORD(p
, CLI_BUFFER_SIZE
);
1799 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1802 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1803 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1804 &rparam
, &rprcnt
, /* return params, return size */
1805 &rdata
, &rdrcnt
/* return data, return size */
1807 char *endp
= rparam
+ rprcnt
;
1808 res
= GETRES(rparam
,endp
);
1809 cli
->rap_error
= res
;
1811 if (res
== 0 || res
== ERRmoredata
) {
1814 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
1815 GETWORD(p
, count
,endp
);
1818 endp
= rdata
+ rdrcnt
;
1819 for (i
= 0;i
< count
&& p
< endp
;i
++, p
+= 16) {
1820 char ret_server
[RAP_MACHNAME_LEN
];
1822 p
+= rap_getstringf(p
,
1827 if (strequal(ret_server
, cli
->desthost
)) {
1828 found_server
= true;
1833 DEBUG(4,("cli_ns_check_server_type: machine %s failed the NetServerEnum call. "
1834 "Error was : %s.\n", cli
->desthost
, cli_errstr(cli
) ));
1841 return found_server
;
1844 /****************************************************************************
1845 Perform a NetWkstaUserLogoff.
1846 ****************************************************************************/
1848 bool cli_NetWkstaUserLogoff(struct cli_state
*cli
, const char *user
, const char *workstation
)
1850 char *rparam
= NULL
;
1853 unsigned int rdrcnt
,rprcnt
;
1854 char param
[WORDSIZE
/* api number */
1855 +sizeof(RAP_NetWkstaUserLogoff_REQ
) /* req string */
1856 +sizeof(RAP_USER_LOGOFF_INFO_L1
) /* return string */
1857 +RAP_USERNAME_LEN
+1 /* user name+pad */
1858 +RAP_MACHNAME_LEN
/* wksta name */
1859 +WORDSIZE
/* buffer size */
1860 +WORDSIZE
]; /* buffer size? */
1861 char upperbuf
[MAX(RAP_USERNAME_LEN
,RAP_MACHNAME_LEN
)];
1865 memset(param
, 0, sizeof(param
));
1867 /* send a SMBtrans command with api NetWkstaUserLogoff */
1868 p
= make_header(param
, RAP_WWkstaUserLogoff
,
1869 RAP_NetWkstaUserLogoff_REQ
, RAP_USER_LOGOFF_INFO_L1
);
1870 PUTDWORD(p
, 0); /* Null pointer */
1871 PUTDWORD(p
, 0); /* Null pointer */
1872 strlcpy(upperbuf
, user
, sizeof(upperbuf
));
1873 strupper_m(upperbuf
);
1875 PUTSTRINGF(p
, tmp
, RAP_USERNAME_LEN
);
1876 p
++; /* strange format, but ok */
1877 strlcpy(upperbuf
, workstation
, sizeof(upperbuf
));
1878 strupper_m(upperbuf
);
1880 PUTSTRINGF(p
, tmp
, RAP_MACHNAME_LEN
);
1881 PUTWORD(p
, CLI_BUFFER_SIZE
);
1882 PUTWORD(p
, CLI_BUFFER_SIZE
);
1885 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
1886 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1887 &rparam
, &rprcnt
, /* return params, return size */
1888 &rdata
, &rdrcnt
/* return data, return size */
1890 char *endp
= rparam
+ rprcnt
;
1891 res
= GETRES(rparam
,endp
);
1892 cli
->rap_error
= res
;
1894 if (cli
->rap_error
!= 0) {
1895 DEBUG(4,("NetwkstaUserLogoff gave error %d\n", cli
->rap_error
));
1901 return (cli
->rap_error
== 0);
1904 int cli_NetPrintQEnum(struct cli_state
*cli
,
1905 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
1906 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
1908 char param
[WORDSIZE
/* api number */
1909 +sizeof(RAP_NetPrintQEnum_REQ
) /* req string */
1910 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
1911 +WORDSIZE
/* info level */
1912 +WORDSIZE
/* buffer size */
1913 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
1915 char *rparam
= NULL
;
1917 unsigned int rprcnt
, rdrcnt
;
1920 memset(param
, '\0',sizeof(param
));
1921 p
= make_header(param
, RAP_WPrintQEnum
,
1922 RAP_NetPrintQEnum_REQ
, RAP_PRINTQ_INFO_L2
);
1923 PUTWORD(p
,2); /* Info level 2 */
1924 PUTWORD(p
,0xFFE0); /* Return buffer size */
1925 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
1928 param
, PTR_DIFF(p
,param
),1024,
1929 NULL
, 0, CLI_BUFFER_SIZE
,
1932 char *endp
= rparam
+ rprcnt
;
1933 res
= GETRES(rparam
, endp
);
1934 cli
->rap_error
= res
;
1936 DEBUG(1,("NetPrintQEnum gave error %d\n", res
));
1941 DEBUG(4,("NetPrintQEnum no data returned\n"));
1945 if (res
== 0 || res
== ERRmoredata
) {
1946 TALLOC_CTX
*frame
= talloc_stackframe();
1947 char *endp
= rparam
+ rprcnt
;
1948 int i
, converter
= 0, count
= 0;
1950 p
= rparam
+ WORDSIZE
;
1951 GETWORD(p
, converter
, endp
);
1952 GETWORD(p
, count
, endp
);
1955 endp
= rdata
+ rdrcnt
;
1956 for (i
=0;i
<count
&& p
< endp
;i
++) {
1957 char qname
[RAP_SHARENAME_LEN
];
1958 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
1959 uint16_t jobcount
= 0, priority
= 0;
1960 uint16_t start_time
= 0, until_time
= 0, status
= 0;
1962 p
+= rap_getstringf(p
,
1968 GETWORD(p
, priority
, endp
);
1969 GETWORD(p
, start_time
, endp
);
1970 GETWORD(p
, until_time
, endp
);
1971 p
+= rap_getstringp(frame
,
1977 p
+= rap_getstringp(frame
,
1983 p
+= rap_getstringp(frame
,
1989 p
+= rap_getstringp(frame
,
1995 p
+= rap_getstringp(frame
,
2001 GETWORD(p
, status
, endp
);
2002 GETWORD(p
, jobcount
, endp
);
2004 if (sep_file
&& print_proc
&& dest
&& parms
&&
2006 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2007 dest
, parms
, comment
, status
, jobcount
);
2012 for (j
=0;j
<jobcount
;j
++) {
2013 uint16 jid
= 0, pos
= 0, fsstatus
= 0;
2014 char ownername
[RAP_USERNAME_LEN
];
2015 char notifyname
[RAP_MACHNAME_LEN
];
2016 char datatype
[RAP_DATATYPE_LEN
];
2017 char *jparms
, *jstatus
, *jcomment
;
2018 unsigned int submitted
= 0, jsize
= 0;
2020 GETWORD(p
, jid
, endp
);
2021 p
+= rap_getstringf(p
,
2027 p
+= rap_getstringf(p
,
2032 p
+= rap_getstringf(p
,
2037 p
+= rap_getstringp(frame
,
2043 GETWORD(p
, pos
, endp
);
2044 GETWORD(p
, fsstatus
, endp
);
2045 p
+= rap_getstringp(frame
,
2051 GETDWORD(p
, submitted
, endp
);
2052 GETDWORD(p
, jsize
, endp
);
2053 p
+= rap_getstringp(frame
,
2060 if (jparms
&& jstatus
&& jcomment
) {
2061 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2062 jstatus
, submitted
, jsize
, jcomment
);
2069 DEBUG(4,("NetPrintQEnum res=%d\n", res
));
2080 int cli_NetPrintQGetInfo(struct cli_state
*cli
, const char *printer
,
2081 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
2082 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
2084 char param
[WORDSIZE
/* api number */
2085 +sizeof(RAP_NetPrintQGetInfo_REQ
) /* req string */
2086 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
2087 +RAP_SHARENAME_LEN
/* printer name */
2088 +WORDSIZE
/* info level */
2089 +WORDSIZE
/* buffer size */
2090 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
2092 char *rparam
= NULL
;
2094 unsigned int rprcnt
, rdrcnt
;
2097 memset(param
, '\0',sizeof(param
));
2098 p
= make_header(param
, RAP_WPrintQGetInfo
,
2099 RAP_NetPrintQGetInfo_REQ
, RAP_PRINTQ_INFO_L2
);
2100 PUTSTRING(p
, printer
, RAP_SHARENAME_LEN
-1);
2101 PUTWORD(p
, 2); /* Info level 2 */
2102 PUTWORD(p
,0xFFE0); /* Return buffer size */
2103 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
2106 param
, PTR_DIFF(p
,param
),1024,
2107 NULL
, 0, CLI_BUFFER_SIZE
,
2110 char *endp
= rparam
+ rprcnt
;
2111 res
= GETRES(rparam
, endp
);
2112 cli
->rap_error
= res
;
2114 DEBUG(1,("NetPrintQGetInfo gave error %d\n", res
));
2119 DEBUG(4,("NetPrintQGetInfo no data returned\n"));
2123 if (res
== 0 || res
== ERRmoredata
) {
2124 TALLOC_CTX
*frame
= talloc_stackframe();
2125 char *endp
= rparam
+ rprcnt
;
2126 int rsize
= 0, converter
= 0;
2127 char qname
[RAP_SHARENAME_LEN
];
2128 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
2129 uint16_t jobcount
= 0, priority
= 0;
2130 uint16_t start_time
= 0, until_time
= 0, status
= 0;
2132 p
= rparam
+ WORDSIZE
;
2133 GETWORD(p
, converter
, endp
);
2134 GETWORD(p
, rsize
, endp
);
2137 endp
= rdata
+ rdrcnt
;
2138 p
+= rap_getstringf(p
,
2144 GETWORD(p
, priority
, endp
);
2145 GETWORD(p
, start_time
, endp
);
2146 GETWORD(p
, until_time
, endp
);
2147 p
+= rap_getstringp(frame
,
2153 p
+= rap_getstringp(frame
,
2159 p
+= rap_getstringp(frame
,
2165 p
+= rap_getstringp(frame
,
2171 p
+= rap_getstringp(frame
,
2177 GETWORD(p
, status
, endp
);
2178 GETWORD(p
, jobcount
, endp
);
2180 if (sep_file
&& print_proc
&& dest
&&
2182 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2183 dest
, parms
, comment
, status
, jobcount
);
2187 for (j
=0;(j
<jobcount
)&&(PTR_DIFF(p
,rdata
)< rsize
)&&
2189 uint16_t jid
= 0, pos
= 0, fsstatus
= 0;
2190 char ownername
[RAP_USERNAME_LEN
];
2191 char notifyname
[RAP_MACHNAME_LEN
];
2192 char datatype
[RAP_DATATYPE_LEN
];
2193 char *jparms
, *jstatus
, *jcomment
;
2194 unsigned int submitted
= 0, jsize
= 0;
2196 GETWORD(p
, jid
, endp
);
2197 p
+= rap_getstringf(p
,
2203 p
+= rap_getstringf(p
,
2208 p
+= rap_getstringf(p
,
2213 p
+= rap_getstringp(frame
,
2219 GETWORD(p
, pos
,endp
);
2220 GETWORD(p
, fsstatus
,endp
);
2221 p
+= rap_getstringp(frame
,
2227 GETDWORD(p
, submitted
,endp
);
2228 GETDWORD(p
, jsize
,endp
);
2229 p
+= rap_getstringp(frame
,
2236 if (jparms
&& jstatus
&& jcomment
) {
2237 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2238 jstatus
, submitted
, jsize
, jcomment
);
2244 DEBUG(4,("NetPrintQGetInfo res=%d\n", res
));
2255 /****************************************************************************
2256 Call a NetServiceEnum - list running services on a different host.
2257 ****************************************************************************/
2259 int cli_RNetServiceEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
2261 char param
[WORDSIZE
/* api number */
2262 +sizeof(RAP_NetServiceEnum_REQ
) /* parm string */
2263 +sizeof(RAP_SERVICE_INFO_L2
) /* return string */
2264 +WORDSIZE
/* info level */
2265 +WORDSIZE
]; /* buffer size */
2267 char *rparam
= NULL
;
2269 unsigned int rprcnt
, rdrcnt
;
2272 memset(param
, '\0', sizeof(param
));
2273 p
= make_header(param
, RAP_WServiceEnum
,
2274 RAP_NetServiceEnum_REQ
, RAP_SERVICE_INFO_L2
);
2275 PUTWORD(p
,2); /* Info level 2 */
2276 PUTWORD(p
,0xFFE0); /* Return buffer size */
2279 param
, PTR_DIFF(p
,param
),8,
2280 NULL
, 0, 0xFFE0 /* data area size */,
2283 char *endp
= rparam
+ rprcnt
;
2284 res
= GETRES(rparam
, endp
);
2285 cli
->rap_error
= res
;
2286 if(cli
->rap_error
== 234) {
2287 DEBUG(1,("Not all service names were returned (such as those longer than 15 characters)\n"));
2288 } else if (cli
->rap_error
!= 0) {
2289 DEBUG(1,("NetServiceEnum gave error %d\n", cli
->rap_error
));
2294 DEBUG(4,("NetServiceEnum no data returned\n"));
2298 if (res
== 0 || res
== ERRmoredata
) {
2299 char *endp
= rparam
+ rprcnt
;
2302 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
2303 GETWORD(p
, count
,endp
);
2305 endp
= rdata
+ rdrcnt
;
2306 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2307 char comment
[RAP_SRVCCMNT_LEN
];
2308 char servicename
[RAP_SRVCNAME_LEN
];
2310 p
+= rap_getstringf(p
,
2315 p
+=8; /* pass status words */
2316 p
+= rap_getstringf(p
,
2322 if (servicename
[0]) {
2323 fn(servicename
, comment
, cli
); /* BB add status too */
2327 DEBUG(4,("NetServiceEnum res=%d\n", res
));
2338 /****************************************************************************
2339 Call a NetSessionEnum - list workstations with sessions to an SMB server.
2340 ****************************************************************************/
2342 int cli_NetSessionEnum(struct cli_state
*cli
, void (*fn
)(char *, char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, char *))
2344 char param
[WORDSIZE
/* api number */
2345 +sizeof(RAP_NetSessionEnum_REQ
) /* parm string */
2346 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2347 +WORDSIZE
/* info level */
2348 +WORDSIZE
]; /* buffer size */
2350 char *rparam
= NULL
;
2352 unsigned int rprcnt
, rdrcnt
;
2355 memset(param
, '\0', sizeof(param
));
2356 p
= make_header(param
, RAP_WsessionEnum
,
2357 RAP_NetSessionEnum_REQ
, RAP_SESSION_INFO_L2
);
2358 PUTWORD(p
,2); /* Info level 2 */
2359 PUTWORD(p
,0xFF); /* Return buffer size */
2362 param
, PTR_DIFF(p
,param
),8,
2363 NULL
, 0, CLI_BUFFER_SIZE
,
2366 char *endp
= rparam
+ rprcnt
;
2367 res
= GETRES(rparam
, endp
);
2368 cli
->rap_error
= res
;
2370 DEBUG(1,("NetSessionEnum gave error %d\n", res
));
2375 DEBUG(4,("NetSesssionEnum no data returned\n"));
2379 if (res
== 0 || res
== ERRmoredata
) {
2380 TALLOC_CTX
*frame
= talloc_stackframe();
2381 char *endp
= rparam
+ rprcnt
;
2382 int i
, converter
= 0, count
= 0;
2384 p
= rparam
+ WORDSIZE
;
2385 GETWORD(p
, converter
, endp
);
2386 GETWORD(p
, count
, endp
);
2388 endp
= rdata
+ rdrcnt
;
2389 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2390 char *wsname
, *username
, *clitype_name
;
2391 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2392 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2394 p
+= rap_getstringp(frame
,
2400 p
+= rap_getstringp(frame
,
2406 GETWORD(p
, num_conns
, endp
);
2407 GETWORD(p
, num_opens
, endp
);
2408 GETWORD(p
, num_users
, endp
);
2409 GETDWORD(p
, sess_time
, endp
);
2410 GETDWORD(p
, idle_time
, endp
);
2411 GETDWORD(p
, user_flags
, endp
);
2412 p
+= rap_getstringp(frame
,
2419 if (wsname
&& username
&& clitype_name
) {
2420 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2421 idle_time
, user_flags
, clitype_name
);
2426 DEBUG(4,("NetSessionEnum res=%d\n", res
));
2437 /****************************************************************************
2438 Call a NetSessionGetInfo - get information about other session to an SMB server.
2439 ****************************************************************************/
2441 int cli_NetSessionGetInfo(struct cli_state
*cli
, const char *workstation
,
2442 void (*fn
)(const char *, const char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, const char *))
2444 char param
[WORDSIZE
/* api number */
2445 +sizeof(RAP_NetSessionGetInfo_REQ
) /* req string */
2446 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2447 +RAP_MACHNAME_LEN
/* wksta name */
2448 +WORDSIZE
/* info level */
2449 +WORDSIZE
]; /* buffer size */
2451 char *rparam
= NULL
;
2453 unsigned int rprcnt
, rdrcnt
;
2457 memset(param
, '\0', sizeof(param
));
2458 p
= make_header(param
, RAP_WsessionGetInfo
,
2459 RAP_NetSessionGetInfo_REQ
, RAP_SESSION_INFO_L2
);
2460 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2461 PUTWORD(p
,2); /* Info level 2 */
2462 PUTWORD(p
,0xFF); /* Return buffer size */
2465 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2466 NULL
, 0, CLI_BUFFER_SIZE
,
2469 endp
= rparam
+ rprcnt
;
2470 res
= GETRES(rparam
, endp
);
2471 cli
->rap_error
= res
;
2472 if (cli
->rap_error
!= 0) {
2473 DEBUG(1,("NetSessionGetInfo gave error %d\n", cli
->rap_error
));
2478 DEBUG(4,("NetSessionGetInfo no data returned\n"));
2482 endp
= rparam
+ rprcnt
;
2483 res
= GETRES(rparam
, endp
);
2485 if (res
== 0 || res
== ERRmoredata
) {
2486 TALLOC_CTX
*frame
= talloc_stackframe();
2488 char *wsname
, *username
, *clitype_name
;
2489 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2490 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2492 p
= rparam
+ WORDSIZE
;
2493 GETWORD(p
, converter
,endp
);
2494 p
+= WORDSIZE
; /* skip rsize */
2497 endp
= rdata
+ rdrcnt
;
2498 p
+= rap_getstringp(frame
,
2504 p
+= rap_getstringp(frame
,
2510 GETWORD(p
, num_conns
, endp
);
2511 GETWORD(p
, num_opens
, endp
);
2512 GETWORD(p
, num_users
, endp
);
2513 GETDWORD(p
, sess_time
, endp
);
2514 GETDWORD(p
, idle_time
, endp
);
2515 GETDWORD(p
, user_flags
, endp
);
2516 p
+= rap_getstringp(frame
,
2523 if (wsname
&& username
&& clitype_name
) {
2524 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2525 idle_time
, user_flags
, clitype_name
);
2529 DEBUG(4,("NetSessionGetInfo res=%d\n", res
));
2540 /****************************************************************************
2541 Call a NetSessionDel - close a session to an SMB server.
2542 ****************************************************************************/
2544 int cli_NetSessionDel(struct cli_state
*cli
, const char *workstation
)
2546 char param
[WORDSIZE
/* api number */
2547 +sizeof(RAP_NetSessionDel_REQ
) /* req string */
2548 +1 /* no return string */
2549 +RAP_MACHNAME_LEN
/* workstation name */
2550 +WORDSIZE
]; /* reserved (0) */
2552 char *rparam
= NULL
;
2554 unsigned int rprcnt
, rdrcnt
;
2557 memset(param
, '\0', sizeof(param
));
2558 p
= make_header(param
, RAP_WsessionDel
, RAP_NetSessionDel_REQ
, NULL
);
2559 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2560 PUTWORD(p
,0); /* reserved word of 0 */
2563 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
2564 NULL
, 0, 200, /* data, length, maxlen */
2565 &rparam
, &rprcnt
, /* return params, length */
2566 &rdata
, &rdrcnt
)) /* return data, length */
2568 char *endp
= rparam
+ rprcnt
;
2569 res
= GETRES(rparam
, endp
);
2570 cli
->rap_error
= res
;
2575 DEBUG(4,("NetFileClose2 res=%d\n", res
));
2579 DEBUG(4,("NetFileClose2 failed\n"));
2588 int cli_NetConnectionEnum(struct cli_state
*cli
, const char *qualifier
,
2589 void (*fn
)(uint16_t conid
, uint16_t contype
,
2590 uint16_t numopens
, uint16_t numusers
,
2591 uint32_t contime
, const char *username
,
2592 const char *netname
))
2594 char param
[WORDSIZE
/* api number */
2595 +sizeof(RAP_NetConnectionEnum_REQ
) /* req string */
2596 +sizeof(RAP_CONNECTION_INFO_L1
) /* return string */
2597 +RAP_MACHNAME_LEN
/* wksta name */
2598 +WORDSIZE
/* info level */
2599 +WORDSIZE
]; /* buffer size */
2601 char *rparam
= NULL
;
2603 unsigned int rprcnt
, rdrcnt
;
2606 memset(param
, '\0', sizeof(param
));
2607 p
= make_header(param
, RAP_WconnectionEnum
,
2608 RAP_NetConnectionEnum_REQ
, RAP_CONNECTION_INFO_L1
);
2609 PUTSTRING(p
, qualifier
, RAP_MACHNAME_LEN
-1);/* Workstation name */
2610 PUTWORD(p
,1); /* Info level 1 */
2611 PUTWORD(p
,0xFFE0); /* Return buffer size */
2614 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2615 NULL
, 0, CLI_BUFFER_SIZE
,
2618 char *endp
= rparam
+ rprcnt
;
2619 res
= GETRES(rparam
, endp
);
2620 cli
->rap_error
= res
;
2622 DEBUG(1,("NetConnectionEnum gave error %d\n", res
));
2627 DEBUG(4,("NetConnectionEnum no data returned\n"));
2631 if (res
== 0 || res
== ERRmoredata
) {
2632 TALLOC_CTX
*frame
= talloc_stackframe();
2633 char *endp
= rparam
+ rprcnt
;
2634 int i
, converter
= 0, count
= 0;
2636 p
= rparam
+ WORDSIZE
;
2637 GETWORD(p
, converter
, endp
);
2638 GETWORD(p
, count
, endp
);
2640 endp
= rdata
+ rdrcnt
;
2641 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2642 char *netname
, *username
;
2643 uint16_t conn_id
= 0, conn_type
= 0, num_opens
= 0, num_users
= 0;
2644 unsigned int conn_time
= 0;
2646 GETWORD(p
,conn_id
, endp
);
2647 GETWORD(p
,conn_type
, endp
);
2648 GETWORD(p
,num_opens
, endp
);
2649 GETWORD(p
,num_users
, endp
);
2650 GETDWORD(p
,conn_time
, endp
);
2651 p
+= rap_getstringp(frame
,
2657 p
+= rap_getstringp(frame
,
2664 if (username
&& netname
) {
2665 fn(conn_id
, conn_type
, num_opens
, num_users
, conn_time
,
2671 DEBUG(4,("NetConnectionEnum res=%d\n", res
));