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 "
1537 "NetServerEnum call. Error was : %s.\n",
1538 cli_state_remote_name(cli
),
1539 win_errstr(W_ERROR(cli
->rap_error
))));
1549 /*************************************************************************
1551 * Function Name: cli_get_server_domain
1553 * PURPOSE: Remotes a NetWkstaGetInfo API call to the current server
1554 * requesting wksta_info_10 level information to determine
1555 * the domain the server belongs to. On success, this
1556 * routine sets the server_domain field in the cli_state structure
1557 * to the server's domain name.
1559 * Dependencies: none
1562 * cli - pointer to cli_state structure
1568 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1570 ************************************************************************/
1572 bool cli_get_server_domain(struct cli_state
*cli
)
1574 char *rparam
= NULL
;
1576 unsigned int rdrcnt
,rprcnt
;
1578 char param
[WORDSIZE
/* api number */
1579 +sizeof(RAP_WWkstaGetInfo_REQ
) /* req string */
1580 +sizeof(RAP_WKSTA_INFO_L10
) /* return string */
1581 +WORDSIZE
/* info level */
1582 +WORDSIZE
]; /* buffer size */
1585 /* send a SMBtrans command with api NetWkstaGetInfo */
1586 p
= make_header(param
, RAP_WWkstaGetInfo
,
1587 RAP_WWkstaGetInfo_REQ
, RAP_WKSTA_INFO_L10
);
1588 PUTWORD(p
, 10); /* info level */
1589 PUTWORD(p
, CLI_BUFFER_SIZE
);
1591 if (cli_api(cli
, param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1592 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1593 &rparam
, &rprcnt
, /* return params, return size */
1594 &rdata
, &rdrcnt
)) { /* return data, return size */
1595 char *endp
= rparam
+ rprcnt
;
1596 res
= GETRES(rparam
, endp
);
1599 TALLOC_CTX
*frame
= talloc_stackframe();
1600 char *server_domain
;
1603 p
= rparam
+ WORDSIZE
;
1604 GETWORD(p
, converter
, endp
);
1606 p
= rdata
+ DWORDSIZE
+ DWORDSIZE
; /* skip computer & user names */
1607 endp
= rdata
+ rdrcnt
;
1608 p
+= rap_getstringp(frame
,
1615 if (server_domain
) {
1616 fstrcpy(cli
->server_domain
, server_domain
);
1628 /*************************************************************************
1630 * Function Name: cli_get_server_type
1632 * PURPOSE: Remotes a NetServerGetInfo API call to the current server
1633 * requesting server_info_1 level information to retrieve
1636 * Dependencies: none
1639 * cli - pointer to cli_state structure
1640 * pstype - pointer to uint32 to contain returned server type
1646 * Origins: samba 2.0.6 source/libsmb/clientgen.c cli_NetServerEnum()
1648 ************************************************************************/
1650 bool cli_get_server_type(struct cli_state
*cli
, uint32
*pstype
)
1652 char *rparam
= NULL
;
1654 unsigned int rdrcnt
,rprcnt
;
1656 char param
[WORDSIZE
/* api number */
1657 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1658 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1659 +WORDSIZE
/* info level */
1660 +WORDSIZE
]; /* buffer size */
1663 /* send a SMBtrans command with api NetServerGetInfo */
1664 p
= make_header(param
, RAP_WserverGetInfo
,
1665 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1666 PUTWORD(p
, 1); /* info level */
1667 PUTWORD(p
, CLI_BUFFER_SIZE
);
1670 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1671 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1672 &rparam
, &rprcnt
, /* return params, return size */
1673 &rdata
, &rdrcnt
/* return data, return size */
1675 char *endp
= rparam
+ rprcnt
;
1676 res
= GETRES(rparam
,endp
);
1678 if (res
== 0 || res
== ERRmoredata
) {
1680 endp
= rparam
+ rprcnt
;
1682 GETDWORD(p
,*pstype
,endp
);
1683 *pstype
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1690 return(res
== 0 || res
== ERRmoredata
);
1693 bool cli_get_server_name(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
1696 char *rparam
= NULL
;
1698 unsigned int rdrcnt
,rprcnt
;
1700 char param
[WORDSIZE
/* api number */
1701 +sizeof(RAP_WserverGetInfo_REQ
) /* req string */
1702 +sizeof(RAP_SERVER_INFO_L1
) /* return string */
1703 +WORDSIZE
/* info level */
1704 +WORDSIZE
]; /* buffer size */
1709 /* send a SMBtrans command with api NetServerGetInfo */
1710 p
= make_header(param
, RAP_WserverGetInfo
,
1711 RAP_WserverGetInfo_REQ
, RAP_SERVER_INFO_L1
);
1712 PUTWORD(p
, 1); /* info level */
1713 PUTWORD(p
, CLI_BUFFER_SIZE
);
1716 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1717 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1718 &rparam
, &rprcnt
, /* return params, return size */
1719 &rdata
, &rdrcnt
/* return data, return size */
1724 endp
= rparam
+ rprcnt
;
1725 if (GETRES(rparam
, endp
) != 0) {
1730 DEBUG(10, ("invalid data count %d, expected >= 16\n", rdrcnt
));
1734 if (pull_ascii(tmp
, rdata
, sizeof(tmp
)-1, 16, STR_TERMINATE
) == -1) {
1735 DEBUG(10, ("pull_ascii failed\n"));
1739 if (!(*servername
= talloc_strdup(mem_ctx
, tmp
))) {
1740 DEBUG(1, ("talloc_strdup failed\n"));
1752 /*************************************************************************
1754 * Function Name: cli_ns_check_server_type
1756 * PURPOSE: Remotes a NetServerEnum2 API call to the current server
1757 * requesting server_info_0 level information of machines
1758 * matching the given server type. If the returned server
1759 * list contains the machine name contained in cli_state_remote_name()
1760 * then we conclude the server type checks out. This routine
1761 * is useful to retrieve list of server's of a certain
1762 * type when all you have is a null session connection and
1763 * can't remote API calls such as NetWkstaGetInfo or
1766 * Dependencies: none
1769 * cli - pointer to cli_state structure
1770 * workgroup - pointer to string containing domain
1771 * stype - server type
1777 ************************************************************************/
1779 bool cli_ns_check_server_type(struct cli_state
*cli
, char *workgroup
, uint32 stype
)
1781 char *rparam
= NULL
;
1783 unsigned int rdrcnt
,rprcnt
;
1785 char param
[WORDSIZE
/* api number */
1786 +sizeof(RAP_NetServerEnum2_REQ
) /* req string */
1787 +sizeof(RAP_SERVER_INFO_L0
) /* return string */
1788 +WORDSIZE
/* info level */
1789 +WORDSIZE
/* buffer size */
1790 +DWORDSIZE
/* server type */
1791 +RAP_MACHNAME_LEN
]; /* workgroup */
1792 bool found_server
= false;
1794 const char *remote_name
= cli_state_remote_name(cli
);
1796 /* send a SMBtrans command with api NetServerEnum */
1797 p
= make_header(param
, RAP_NetServerEnum2
,
1798 RAP_NetServerEnum2_REQ
, RAP_SERVER_INFO_L0
);
1799 PUTWORD(p
, 0); /* info level 0 */
1800 PUTWORD(p
, CLI_BUFFER_SIZE
);
1802 PUTSTRING(p
, workgroup
, RAP_MACHNAME_LEN
);
1805 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
1806 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1807 &rparam
, &rprcnt
, /* return params, return size */
1808 &rdata
, &rdrcnt
/* return data, return size */
1810 char *endp
= rparam
+ rprcnt
;
1811 res
= GETRES(rparam
,endp
);
1812 cli
->rap_error
= res
;
1814 if (res
== 0 || res
== ERRmoredata
) {
1817 p
= rparam
+ WORDSIZE
+ WORDSIZE
;
1818 GETWORD(p
, count
,endp
);
1821 endp
= rdata
+ rdrcnt
;
1822 for (i
= 0;i
< count
&& p
< endp
;i
++, p
+= 16) {
1823 char ret_server
[RAP_MACHNAME_LEN
];
1825 p
+= rap_getstringf(p
,
1830 if (strequal(ret_server
, remote_name
)) {
1831 found_server
= true;
1836 DEBUG(4, ("cli_ns_check_server_type: machine %s "
1837 "failed the NetServerEnum call. Error was : "
1838 "%s.\n", remote_name
,
1839 win_errstr(W_ERROR(cli
->rap_error
))));
1846 return found_server
;
1849 /****************************************************************************
1850 Perform a NetWkstaUserLogoff.
1851 ****************************************************************************/
1853 bool cli_NetWkstaUserLogoff(struct cli_state
*cli
, const char *user
, const char *workstation
)
1855 char *rparam
= NULL
;
1858 unsigned int rdrcnt
,rprcnt
;
1859 char param
[WORDSIZE
/* api number */
1860 +sizeof(RAP_NetWkstaUserLogoff_REQ
) /* req string */
1861 +sizeof(RAP_USER_LOGOFF_INFO_L1
) /* return string */
1862 +RAP_USERNAME_LEN
+1 /* user name+pad */
1863 +RAP_MACHNAME_LEN
/* wksta name */
1864 +WORDSIZE
/* buffer size */
1865 +WORDSIZE
]; /* buffer size? */
1866 char upperbuf
[MAX(RAP_USERNAME_LEN
,RAP_MACHNAME_LEN
)];
1870 memset(param
, 0, sizeof(param
));
1872 /* send a SMBtrans command with api NetWkstaUserLogoff */
1873 p
= make_header(param
, RAP_WWkstaUserLogoff
,
1874 RAP_NetWkstaUserLogoff_REQ
, RAP_USER_LOGOFF_INFO_L1
);
1875 PUTDWORD(p
, 0); /* Null pointer */
1876 PUTDWORD(p
, 0); /* Null pointer */
1877 strlcpy(upperbuf
, user
, sizeof(upperbuf
));
1878 strupper_m(upperbuf
);
1880 PUTSTRINGF(p
, tmp
, RAP_USERNAME_LEN
);
1881 p
++; /* strange format, but ok */
1882 strlcpy(upperbuf
, workstation
, sizeof(upperbuf
));
1883 strupper_m(upperbuf
);
1885 PUTSTRINGF(p
, tmp
, RAP_MACHNAME_LEN
);
1886 PUTWORD(p
, CLI_BUFFER_SIZE
);
1887 PUTWORD(p
, CLI_BUFFER_SIZE
);
1890 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
1891 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
1892 &rparam
, &rprcnt
, /* return params, return size */
1893 &rdata
, &rdrcnt
/* return data, return size */
1895 char *endp
= rparam
+ rprcnt
;
1896 res
= GETRES(rparam
,endp
);
1897 cli
->rap_error
= res
;
1899 if (cli
->rap_error
!= 0) {
1900 DEBUG(4,("NetwkstaUserLogoff gave error %d\n", cli
->rap_error
));
1906 return (cli
->rap_error
== 0);
1909 int cli_NetPrintQEnum(struct cli_state
*cli
,
1910 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
1911 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
1913 char param
[WORDSIZE
/* api number */
1914 +sizeof(RAP_NetPrintQEnum_REQ
) /* req string */
1915 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
1916 +WORDSIZE
/* info level */
1917 +WORDSIZE
/* buffer size */
1918 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
1920 char *rparam
= NULL
;
1922 unsigned int rprcnt
, rdrcnt
;
1925 memset(param
, '\0',sizeof(param
));
1926 p
= make_header(param
, RAP_WPrintQEnum
,
1927 RAP_NetPrintQEnum_REQ
, RAP_PRINTQ_INFO_L2
);
1928 PUTWORD(p
,2); /* Info level 2 */
1929 PUTWORD(p
,0xFFE0); /* Return buffer size */
1930 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
1933 param
, PTR_DIFF(p
,param
),1024,
1934 NULL
, 0, CLI_BUFFER_SIZE
,
1937 char *endp
= rparam
+ rprcnt
;
1938 res
= GETRES(rparam
, endp
);
1939 cli
->rap_error
= res
;
1941 DEBUG(1,("NetPrintQEnum gave error %d\n", res
));
1946 DEBUG(4,("NetPrintQEnum no data returned\n"));
1950 if (res
== 0 || res
== ERRmoredata
) {
1951 TALLOC_CTX
*frame
= talloc_stackframe();
1952 char *endp
= rparam
+ rprcnt
;
1953 int i
, converter
= 0, count
= 0;
1955 p
= rparam
+ WORDSIZE
;
1956 GETWORD(p
, converter
, endp
);
1957 GETWORD(p
, count
, endp
);
1960 endp
= rdata
+ rdrcnt
;
1961 for (i
=0;i
<count
&& p
< endp
;i
++) {
1962 char qname
[RAP_SHARENAME_LEN
];
1963 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
1964 uint16_t jobcount
= 0, priority
= 0;
1965 uint16_t start_time
= 0, until_time
= 0, status
= 0;
1967 p
+= rap_getstringf(p
,
1973 GETWORD(p
, priority
, endp
);
1974 GETWORD(p
, start_time
, endp
);
1975 GETWORD(p
, until_time
, endp
);
1976 p
+= rap_getstringp(frame
,
1982 p
+= rap_getstringp(frame
,
1988 p
+= rap_getstringp(frame
,
1994 p
+= rap_getstringp(frame
,
2000 p
+= rap_getstringp(frame
,
2006 GETWORD(p
, status
, endp
);
2007 GETWORD(p
, jobcount
, endp
);
2009 if (sep_file
&& print_proc
&& dest
&& parms
&&
2011 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2012 dest
, parms
, comment
, status
, jobcount
);
2017 for (j
=0;j
<jobcount
;j
++) {
2018 uint16 jid
= 0, pos
= 0, fsstatus
= 0;
2019 char ownername
[RAP_USERNAME_LEN
];
2020 char notifyname
[RAP_MACHNAME_LEN
];
2021 char datatype
[RAP_DATATYPE_LEN
];
2022 char *jparms
, *jstatus
, *jcomment
;
2023 unsigned int submitted
= 0, jsize
= 0;
2025 GETWORD(p
, jid
, endp
);
2026 p
+= rap_getstringf(p
,
2032 p
+= rap_getstringf(p
,
2037 p
+= rap_getstringf(p
,
2042 p
+= rap_getstringp(frame
,
2048 GETWORD(p
, pos
, endp
);
2049 GETWORD(p
, fsstatus
, endp
);
2050 p
+= rap_getstringp(frame
,
2056 GETDWORD(p
, submitted
, endp
);
2057 GETDWORD(p
, jsize
, endp
);
2058 p
+= rap_getstringp(frame
,
2065 if (jparms
&& jstatus
&& jcomment
) {
2066 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2067 jstatus
, submitted
, jsize
, jcomment
);
2074 DEBUG(4,("NetPrintQEnum res=%d\n", res
));
2085 int cli_NetPrintQGetInfo(struct cli_state
*cli
, const char *printer
,
2086 void (*qfn
)(const char*,uint16
,uint16
,uint16
,const char*,const char*,const char*,const char*,const char*,uint16
,uint16
),
2087 void (*jfn
)(uint16
,const char*,const char*,const char*,const char*,uint16
,uint16
,const char*,unsigned int,unsigned int,const char*))
2089 char param
[WORDSIZE
/* api number */
2090 +sizeof(RAP_NetPrintQGetInfo_REQ
) /* req string */
2091 +sizeof(RAP_PRINTQ_INFO_L2
) /* return string */
2092 +RAP_SHARENAME_LEN
/* printer name */
2093 +WORDSIZE
/* info level */
2094 +WORDSIZE
/* buffer size */
2095 +sizeof(RAP_SMB_PRINT_JOB_L1
)]; /* more ret data */
2097 char *rparam
= NULL
;
2099 unsigned int rprcnt
, rdrcnt
;
2102 memset(param
, '\0',sizeof(param
));
2103 p
= make_header(param
, RAP_WPrintQGetInfo
,
2104 RAP_NetPrintQGetInfo_REQ
, RAP_PRINTQ_INFO_L2
);
2105 PUTSTRING(p
, printer
, RAP_SHARENAME_LEN
-1);
2106 PUTWORD(p
, 2); /* Info level 2 */
2107 PUTWORD(p
,0xFFE0); /* Return buffer size */
2108 PUTSTRING(p
, RAP_SMB_PRINT_JOB_L1
, 0);
2111 param
, PTR_DIFF(p
,param
),1024,
2112 NULL
, 0, CLI_BUFFER_SIZE
,
2115 char *endp
= rparam
+ rprcnt
;
2116 res
= GETRES(rparam
, endp
);
2117 cli
->rap_error
= res
;
2119 DEBUG(1,("NetPrintQGetInfo gave error %d\n", res
));
2124 DEBUG(4,("NetPrintQGetInfo no data returned\n"));
2128 if (res
== 0 || res
== ERRmoredata
) {
2129 TALLOC_CTX
*frame
= talloc_stackframe();
2130 char *endp
= rparam
+ rprcnt
;
2131 int rsize
= 0, converter
= 0;
2132 char qname
[RAP_SHARENAME_LEN
];
2133 char *sep_file
, *print_proc
, *dest
, *parms
, *comment
;
2134 uint16_t jobcount
= 0, priority
= 0;
2135 uint16_t start_time
= 0, until_time
= 0, status
= 0;
2137 p
= rparam
+ WORDSIZE
;
2138 GETWORD(p
, converter
, endp
);
2139 GETWORD(p
, rsize
, endp
);
2142 endp
= rdata
+ rdrcnt
;
2143 p
+= rap_getstringf(p
,
2149 GETWORD(p
, priority
, endp
);
2150 GETWORD(p
, start_time
, endp
);
2151 GETWORD(p
, until_time
, endp
);
2152 p
+= rap_getstringp(frame
,
2158 p
+= rap_getstringp(frame
,
2164 p
+= rap_getstringp(frame
,
2170 p
+= rap_getstringp(frame
,
2176 p
+= rap_getstringp(frame
,
2182 GETWORD(p
, status
, endp
);
2183 GETWORD(p
, jobcount
, endp
);
2185 if (sep_file
&& print_proc
&& dest
&&
2187 qfn(qname
, priority
, start_time
, until_time
, sep_file
, print_proc
,
2188 dest
, parms
, comment
, status
, jobcount
);
2192 for (j
=0;(j
<jobcount
)&&(PTR_DIFF(p
,rdata
)< rsize
)&&
2194 uint16_t jid
= 0, pos
= 0, fsstatus
= 0;
2195 char ownername
[RAP_USERNAME_LEN
];
2196 char notifyname
[RAP_MACHNAME_LEN
];
2197 char datatype
[RAP_DATATYPE_LEN
];
2198 char *jparms
, *jstatus
, *jcomment
;
2199 unsigned int submitted
= 0, jsize
= 0;
2201 GETWORD(p
, jid
, endp
);
2202 p
+= rap_getstringf(p
,
2208 p
+= rap_getstringf(p
,
2213 p
+= rap_getstringf(p
,
2218 p
+= rap_getstringp(frame
,
2224 GETWORD(p
, pos
,endp
);
2225 GETWORD(p
, fsstatus
,endp
);
2226 p
+= rap_getstringp(frame
,
2232 GETDWORD(p
, submitted
,endp
);
2233 GETDWORD(p
, jsize
,endp
);
2234 p
+= rap_getstringp(frame
,
2241 if (jparms
&& jstatus
&& jcomment
) {
2242 jfn(jid
, ownername
, notifyname
, datatype
, jparms
, pos
, fsstatus
,
2243 jstatus
, submitted
, jsize
, jcomment
);
2249 DEBUG(4,("NetPrintQGetInfo res=%d\n", res
));
2260 /****************************************************************************
2261 Call a NetServiceEnum - list running services on a different host.
2262 ****************************************************************************/
2264 int cli_RNetServiceEnum(struct cli_state
*cli
, void (*fn
)(const char *, const char *, void *), void *state
)
2266 char param
[WORDSIZE
/* api number */
2267 +sizeof(RAP_NetServiceEnum_REQ
) /* parm string */
2268 +sizeof(RAP_SERVICE_INFO_L2
) /* return string */
2269 +WORDSIZE
/* info level */
2270 +WORDSIZE
]; /* buffer size */
2272 char *rparam
= NULL
;
2274 unsigned int rprcnt
, rdrcnt
;
2277 memset(param
, '\0', sizeof(param
));
2278 p
= make_header(param
, RAP_WServiceEnum
,
2279 RAP_NetServiceEnum_REQ
, RAP_SERVICE_INFO_L2
);
2280 PUTWORD(p
,2); /* Info level 2 */
2281 PUTWORD(p
,0xFFE0); /* Return buffer size */
2284 param
, PTR_DIFF(p
,param
),8,
2285 NULL
, 0, 0xFFE0 /* data area size */,
2288 char *endp
= rparam
+ rprcnt
;
2289 res
= GETRES(rparam
, endp
);
2290 cli
->rap_error
= res
;
2291 if(cli
->rap_error
== 234) {
2292 DEBUG(1,("Not all service names were returned (such as those longer than 15 characters)\n"));
2293 } else if (cli
->rap_error
!= 0) {
2294 DEBUG(1,("NetServiceEnum gave error %d\n", cli
->rap_error
));
2299 DEBUG(4,("NetServiceEnum no data returned\n"));
2303 if (res
== 0 || res
== ERRmoredata
) {
2304 char *endp
= rparam
+ rprcnt
;
2307 p
= rparam
+ WORDSIZE
+ WORDSIZE
; /* skip result and converter */
2308 GETWORD(p
, count
,endp
);
2310 endp
= rdata
+ rdrcnt
;
2311 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2312 char comment
[RAP_SRVCCMNT_LEN
];
2313 char servicename
[RAP_SRVCNAME_LEN
];
2315 p
+= rap_getstringf(p
,
2320 p
+=8; /* pass status words */
2321 p
+= rap_getstringf(p
,
2327 if (servicename
[0]) {
2328 fn(servicename
, comment
, cli
); /* BB add status too */
2332 DEBUG(4,("NetServiceEnum res=%d\n", res
));
2343 /****************************************************************************
2344 Call a NetSessionEnum - list workstations with sessions to an SMB server.
2345 ****************************************************************************/
2347 int cli_NetSessionEnum(struct cli_state
*cli
, void (*fn
)(char *, char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, char *))
2349 char param
[WORDSIZE
/* api number */
2350 +sizeof(RAP_NetSessionEnum_REQ
) /* parm string */
2351 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2352 +WORDSIZE
/* info level */
2353 +WORDSIZE
]; /* buffer size */
2355 char *rparam
= NULL
;
2357 unsigned int rprcnt
, rdrcnt
;
2360 memset(param
, '\0', sizeof(param
));
2361 p
= make_header(param
, RAP_WsessionEnum
,
2362 RAP_NetSessionEnum_REQ
, RAP_SESSION_INFO_L2
);
2363 PUTWORD(p
,2); /* Info level 2 */
2364 PUTWORD(p
,0xFF); /* Return buffer size */
2367 param
, PTR_DIFF(p
,param
),8,
2368 NULL
, 0, CLI_BUFFER_SIZE
,
2371 char *endp
= rparam
+ rprcnt
;
2372 res
= GETRES(rparam
, endp
);
2373 cli
->rap_error
= res
;
2375 DEBUG(1,("NetSessionEnum gave error %d\n", res
));
2380 DEBUG(4,("NetSesssionEnum no data returned\n"));
2384 if (res
== 0 || res
== ERRmoredata
) {
2385 TALLOC_CTX
*frame
= talloc_stackframe();
2386 char *endp
= rparam
+ rprcnt
;
2387 int i
, converter
= 0, count
= 0;
2389 p
= rparam
+ WORDSIZE
;
2390 GETWORD(p
, converter
, endp
);
2391 GETWORD(p
, count
, endp
);
2393 endp
= rdata
+ rdrcnt
;
2394 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2395 char *wsname
, *username
, *clitype_name
;
2396 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2397 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2399 p
+= rap_getstringp(frame
,
2405 p
+= rap_getstringp(frame
,
2411 GETWORD(p
, num_conns
, endp
);
2412 GETWORD(p
, num_opens
, endp
);
2413 GETWORD(p
, num_users
, endp
);
2414 GETDWORD(p
, sess_time
, endp
);
2415 GETDWORD(p
, idle_time
, endp
);
2416 GETDWORD(p
, user_flags
, endp
);
2417 p
+= rap_getstringp(frame
,
2424 if (wsname
&& username
&& clitype_name
) {
2425 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2426 idle_time
, user_flags
, clitype_name
);
2431 DEBUG(4,("NetSessionEnum res=%d\n", res
));
2442 /****************************************************************************
2443 Call a NetSessionGetInfo - get information about other session to an SMB server.
2444 ****************************************************************************/
2446 int cli_NetSessionGetInfo(struct cli_state
*cli
, const char *workstation
,
2447 void (*fn
)(const char *, const char *, uint16
, uint16
, uint16
, unsigned int, unsigned int, unsigned int, const char *))
2449 char param
[WORDSIZE
/* api number */
2450 +sizeof(RAP_NetSessionGetInfo_REQ
) /* req string */
2451 +sizeof(RAP_SESSION_INFO_L2
) /* return string */
2452 +RAP_MACHNAME_LEN
/* wksta name */
2453 +WORDSIZE
/* info level */
2454 +WORDSIZE
]; /* buffer size */
2456 char *rparam
= NULL
;
2458 unsigned int rprcnt
, rdrcnt
;
2462 memset(param
, '\0', sizeof(param
));
2463 p
= make_header(param
, RAP_WsessionGetInfo
,
2464 RAP_NetSessionGetInfo_REQ
, RAP_SESSION_INFO_L2
);
2465 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2466 PUTWORD(p
,2); /* Info level 2 */
2467 PUTWORD(p
,0xFF); /* Return buffer size */
2470 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2471 NULL
, 0, CLI_BUFFER_SIZE
,
2474 endp
= rparam
+ rprcnt
;
2475 res
= GETRES(rparam
, endp
);
2476 cli
->rap_error
= res
;
2477 if (cli
->rap_error
!= 0) {
2478 DEBUG(1,("NetSessionGetInfo gave error %d\n", cli
->rap_error
));
2483 DEBUG(4,("NetSessionGetInfo no data returned\n"));
2487 endp
= rparam
+ rprcnt
;
2488 res
= GETRES(rparam
, endp
);
2490 if (res
== 0 || res
== ERRmoredata
) {
2491 TALLOC_CTX
*frame
= talloc_stackframe();
2493 char *wsname
, *username
, *clitype_name
;
2494 uint16_t num_conns
= 0, num_opens
= 0, num_users
= 0;
2495 unsigned int sess_time
= 0, idle_time
= 0, user_flags
= 0;
2497 p
= rparam
+ WORDSIZE
;
2498 GETWORD(p
, converter
,endp
);
2499 p
+= WORDSIZE
; /* skip rsize */
2502 endp
= rdata
+ rdrcnt
;
2503 p
+= rap_getstringp(frame
,
2509 p
+= rap_getstringp(frame
,
2515 GETWORD(p
, num_conns
, endp
);
2516 GETWORD(p
, num_opens
, endp
);
2517 GETWORD(p
, num_users
, endp
);
2518 GETDWORD(p
, sess_time
, endp
);
2519 GETDWORD(p
, idle_time
, endp
);
2520 GETDWORD(p
, user_flags
, endp
);
2521 p
+= rap_getstringp(frame
,
2528 if (wsname
&& username
&& clitype_name
) {
2529 fn(wsname
, username
, num_conns
, num_opens
, num_users
, sess_time
,
2530 idle_time
, user_flags
, clitype_name
);
2534 DEBUG(4,("NetSessionGetInfo res=%d\n", res
));
2545 /****************************************************************************
2546 Call a NetSessionDel - close a session to an SMB server.
2547 ****************************************************************************/
2549 int cli_NetSessionDel(struct cli_state
*cli
, const char *workstation
)
2551 char param
[WORDSIZE
/* api number */
2552 +sizeof(RAP_NetSessionDel_REQ
) /* req string */
2553 +1 /* no return string */
2554 +RAP_MACHNAME_LEN
/* workstation name */
2555 +WORDSIZE
]; /* reserved (0) */
2557 char *rparam
= NULL
;
2559 unsigned int rprcnt
, rdrcnt
;
2562 memset(param
, '\0', sizeof(param
));
2563 p
= make_header(param
, RAP_WsessionDel
, RAP_NetSessionDel_REQ
, NULL
);
2564 PUTSTRING(p
, workstation
, RAP_MACHNAME_LEN
-1);
2565 PUTWORD(p
,0); /* reserved word of 0 */
2568 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
2569 NULL
, 0, 200, /* data, length, maxlen */
2570 &rparam
, &rprcnt
, /* return params, length */
2571 &rdata
, &rdrcnt
)) /* return data, length */
2573 char *endp
= rparam
+ rprcnt
;
2574 res
= GETRES(rparam
, endp
);
2575 cli
->rap_error
= res
;
2580 DEBUG(4,("NetFileClose2 res=%d\n", res
));
2584 DEBUG(4,("NetFileClose2 failed\n"));
2593 int cli_NetConnectionEnum(struct cli_state
*cli
, const char *qualifier
,
2594 void (*fn
)(uint16_t conid
, uint16_t contype
,
2595 uint16_t numopens
, uint16_t numusers
,
2596 uint32_t contime
, const char *username
,
2597 const char *netname
))
2599 char param
[WORDSIZE
/* api number */
2600 +sizeof(RAP_NetConnectionEnum_REQ
) /* req string */
2601 +sizeof(RAP_CONNECTION_INFO_L1
) /* return string */
2602 +RAP_MACHNAME_LEN
/* wksta name */
2603 +WORDSIZE
/* info level */
2604 +WORDSIZE
]; /* buffer size */
2606 char *rparam
= NULL
;
2608 unsigned int rprcnt
, rdrcnt
;
2611 memset(param
, '\0', sizeof(param
));
2612 p
= make_header(param
, RAP_WconnectionEnum
,
2613 RAP_NetConnectionEnum_REQ
, RAP_CONNECTION_INFO_L1
);
2614 PUTSTRING(p
, qualifier
, RAP_MACHNAME_LEN
-1);/* Workstation name */
2615 PUTWORD(p
,1); /* Info level 1 */
2616 PUTWORD(p
,0xFFE0); /* Return buffer size */
2619 param
, PTR_DIFF(p
,param
),PTR_DIFF(p
,param
),
2620 NULL
, 0, CLI_BUFFER_SIZE
,
2623 char *endp
= rparam
+ rprcnt
;
2624 res
= GETRES(rparam
, endp
);
2625 cli
->rap_error
= res
;
2627 DEBUG(1,("NetConnectionEnum gave error %d\n", res
));
2632 DEBUG(4,("NetConnectionEnum no data returned\n"));
2636 if (res
== 0 || res
== ERRmoredata
) {
2637 TALLOC_CTX
*frame
= talloc_stackframe();
2638 char *endp
= rparam
+ rprcnt
;
2639 int i
, converter
= 0, count
= 0;
2641 p
= rparam
+ WORDSIZE
;
2642 GETWORD(p
, converter
, endp
);
2643 GETWORD(p
, count
, endp
);
2645 endp
= rdata
+ rdrcnt
;
2646 for (i
=0,p
=rdata
;i
<count
&& p
< endp
;i
++) {
2647 char *netname
, *username
;
2648 uint16_t conn_id
= 0, conn_type
= 0, num_opens
= 0, num_users
= 0;
2649 unsigned int conn_time
= 0;
2651 GETWORD(p
,conn_id
, endp
);
2652 GETWORD(p
,conn_type
, endp
);
2653 GETWORD(p
,num_opens
, endp
);
2654 GETWORD(p
,num_users
, endp
);
2655 GETDWORD(p
,conn_time
, endp
);
2656 p
+= rap_getstringp(frame
,
2662 p
+= rap_getstringp(frame
,
2669 if (username
&& netname
) {
2670 fn(conn_id
, conn_type
, num_opens
, num_users
, conn_time
,
2676 DEBUG(4,("NetConnectionEnum res=%d\n", res
));