2 Unix SMB/CIFS implementation.
3 Inter-process communication and named pipe handling
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 2007.
8 Copyright (C) John H Terpstra 1995-1998
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 This file handles the named pipe and mailslot calls
25 in the SMBtrans protocol
29 #include "smbd/smbd.h"
30 #include "smbd/globals.h"
31 #include "rpc_client/rpc_client.h"
32 #include "../librpc/gen_ndr/ndr_samr_c.h"
33 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
34 #include "rpc_client/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
37 #include "../librpc/gen_ndr/rap.h"
38 #include "../lib/util/binsearch.h"
39 #include "../libcli/auth/libcli_auth.h"
40 #include "rpc_client/init_lsa.h"
41 #include "../libcli/security/security.h"
43 #include "passdb/machine_sid.h"
45 #include "rpc_server/rpc_ncacn_np.h"
52 #define NERR_Success 0
53 #define NERR_badpass 86
54 #define NERR_notsupported 50
56 #define NERR_BASE (2100)
57 #define NERR_BufTooSmall (NERR_BASE+23)
58 #define NERR_JobNotFound (NERR_BASE+51)
59 #define NERR_DestNotFound (NERR_BASE+52)
61 #define ACCESS_READ 0x01
62 #define ACCESS_WRITE 0x02
63 #define ACCESS_CREATE 0x04
65 #define SHPWLEN 8 /* share password length */
67 /* Limit size of ipc replies */
69 static char *smb_realloc_limit(void *ptr
, size_t size
)
73 size
= MAX((size
),4*1024);
74 val
= (char *)SMB_REALLOC(ptr
,size
);
76 memset(val
,'\0',size
);
81 static bool api_Unsupported(struct smbd_server_connection
*sconn
,
82 connection_struct
*conn
, uint64_t vuid
,
83 char *param
, int tpscnt
,
84 char *data
, int tdscnt
,
85 int mdrcnt
, int mprcnt
,
86 char **rdata
, char **rparam
,
87 int *rdata_len
, int *rparam_len
);
89 static bool api_TooSmall(struct smbd_server_connection
*sconn
,
90 connection_struct
*conn
, uint64_t vuid
, char *param
, char *data
,
91 int mdrcnt
, int mprcnt
,
92 char **rdata
, char **rparam
,
93 int *rdata_len
, int *rparam_len
);
96 static int CopyExpanded(connection_struct
*conn
,
97 int snum
, char **dst
, char *src
, int *p_space_remaining
)
99 TALLOC_CTX
*ctx
= talloc_tos();
103 if (!src
|| !dst
|| !p_space_remaining
|| !(*dst
) ||
104 *p_space_remaining
<= 0) {
108 buf
= talloc_strdup(ctx
, src
);
110 *p_space_remaining
= 0;
113 buf
= talloc_string_sub(ctx
, buf
,"%S", lp_servicename(ctx
, snum
));
115 *p_space_remaining
= 0;
118 buf
= talloc_sub_advanced(ctx
,
119 lp_servicename(ctx
, SNUM(conn
)),
120 conn
->session_info
->unix_info
->unix_name
,
122 conn
->session_info
->unix_token
->gid
,
123 conn
->session_info
->unix_info
->sanitized_username
,
124 conn
->session_info
->info
->domain_name
,
127 *p_space_remaining
= 0;
130 l
= push_ascii(*dst
,buf
,*p_space_remaining
, STR_TERMINATE
);
135 (*p_space_remaining
) -= l
;
139 static int CopyAndAdvance(char **dst
, char *src
, int *n
)
142 if (!src
|| !dst
|| !n
|| !(*dst
)) {
145 l
= push_ascii(*dst
,src
,*n
, STR_TERMINATE
);
154 static int StrlenExpanded(connection_struct
*conn
, int snum
, char *s
)
156 TALLOC_CTX
*ctx
= talloc_tos();
161 buf
= talloc_strdup(ctx
,s
);
165 buf
= talloc_string_sub(ctx
,buf
,"%S",lp_servicename(ctx
, snum
));
169 buf
= talloc_sub_advanced(ctx
,
170 lp_servicename(ctx
, SNUM(conn
)),
171 conn
->session_info
->unix_info
->unix_name
,
173 conn
->session_info
->unix_token
->gid
,
174 conn
->session_info
->unix_info
->sanitized_username
,
175 conn
->session_info
->info
->domain_name
,
180 return strlen(buf
) + 1;
183 /*******************************************************************
184 Check a API string for validity when we only need to check the prefix.
185 ******************************************************************/
187 static bool prefix_ok(const char *str
, const char *prefix
)
189 return(strncmp(str
,prefix
,strlen(prefix
)) == 0);
193 const char *format
; /* formatstring for structure */
194 const char *subformat
; /* subformat for structure */
195 char *base
; /* baseaddress of buffer */
196 int buflen
; /* remaining size for fixed part; on init: length of base */
197 int subcount
; /* count of substructures */
198 char *structbuf
; /* pointer into buffer for remaining fixed part */
199 int stringlen
; /* remaining size for variable part */
200 char *stringbuf
; /* pointer into buffer for remaining variable part */
201 int neededlen
; /* total needed size */
202 int usedlen
; /* total used size (usedlen <= neededlen and usedlen <= buflen) */
203 const char *curpos
; /* current position; pointer into format or subformat */
207 static int get_counter(const char **p
)
213 if (!isdigit((int)**p
)) {
219 n
= 10 * n
+ (i
- '0');
227 static int getlen(const char *p
)
236 case 'W': /* word (2 byte) */
239 case 'K': /* status word? (2 byte) */
242 case 'N': /* count of substructures (word) at end */
245 case 'D': /* double word (4 byte) */
246 case 'z': /* offset to zero terminated string (4 byte) */
247 case 'l': /* offset to user data (4 byte) */
250 case 'b': /* offset to data (with counter) (4 byte) */
254 case 'B': /* byte (with optional counter) */
255 n
+= get_counter(&p
);
262 static bool init_package(struct pack_desc
*p
, int count
, int subcount
)
267 if (!p
->format
|| !p
->base
) {
271 i
= count
* getlen(p
->format
);
273 i
+= subcount
* getlen(p
->subformat
);
275 p
->structbuf
= p
->base
;
279 p
->curpos
= p
->format
;
285 * This is the old error code we used. Aparently
286 * WinNT/2k systems return ERRbuftoosmall (2123) and
287 * OS/2 needs this. I'm leaving this here so we can revert
290 p
->errcode
= ERRmoredata
;
292 p
->errcode
= ERRbuftoosmall
;
295 p
->errcode
= NERR_Success
;
299 p
->stringbuf
= p
->base
+ i
;
301 return (p
->errcode
== NERR_Success
);
304 static int package(struct pack_desc
*p
, ...)
307 int needed
=0, stringneeded
;
308 const char *str
=NULL
;
309 int is_string
=0, stringused
;
316 p
->curpos
= p
->format
;
318 p
->curpos
= p
->subformat
;
323 str
= va_arg(args
,char*);
324 SMB_ASSERT(strncmp(str
,p
->curpos
,strlen(str
)) == 0);
333 switch( *p
->curpos
++ ) {
334 case 'W': /* word (2 byte) */
336 temp
= va_arg(args
,int);
337 if (p
->buflen
>= needed
) {
338 SSVAL(p
->structbuf
,0,temp
);
341 case 'K': /* status word? (2 byte) */
343 temp
= va_arg(args
,int);
344 if (p
->buflen
>= needed
) {
345 SSVAL(p
->structbuf
,0,temp
);
348 case 'N': /* count of substructures (word) at end */
350 p
->subcount
= va_arg(args
,int);
351 if (p
->buflen
>= needed
) {
352 SSVAL(p
->structbuf
,0,p
->subcount
);
355 case 'D': /* double word (4 byte) */
357 temp
= va_arg(args
,int);
358 if (p
->buflen
>= needed
) {
359 SIVAL(p
->structbuf
,0,temp
);
362 case 'B': /* byte (with optional counter) */
363 needed
= get_counter(&p
->curpos
);
365 char *s
= va_arg(args
,char*);
366 if (p
->buflen
>= needed
) {
367 StrnCpy(p
->structbuf
,s
?s
:"",needed
-1);
371 case 'z': /* offset to zero terminated string (4 byte) */
372 str
= va_arg(args
,char*);
373 stringneeded
= (str
? strlen(str
)+1 : 0);
376 case 'l': /* offset to user data (4 byte) */
377 str
= va_arg(args
,char*);
378 stringneeded
= va_arg(args
,int);
381 case 'b': /* offset to data (with counter) (4 byte) */
382 str
= va_arg(args
,char*);
383 stringneeded
= get_counter(&p
->curpos
);
389 if (stringneeded
>= 0) {
391 if (p
->buflen
>= needed
) {
392 stringused
= stringneeded
;
393 if (stringused
> p
->stringlen
) {
394 stringused
= (is_string
? p
->stringlen
: 0);
395 if (p
->errcode
== NERR_Success
) {
396 p
->errcode
= ERRmoredata
;
400 SIVAL(p
->structbuf
,0,0);
402 SIVAL(p
->structbuf
,0,PTR_DIFF(p
->stringbuf
,p
->base
));
403 memcpy(p
->stringbuf
,str
?str
:"",stringused
);
405 p
->stringbuf
[stringused
-1] = '\0';
407 p
->stringbuf
+= stringused
;
408 p
->stringlen
-= stringused
;
409 p
->usedlen
+= stringused
;
412 p
->neededlen
+= stringneeded
;
415 p
->neededlen
+= needed
;
416 if (p
->buflen
>= needed
) {
417 p
->structbuf
+= needed
;
419 p
->usedlen
+= needed
;
421 if (p
->errcode
== NERR_Success
) {
422 p
->errcode
= ERRmoredata
;
429 #define PACK(desc,t,v) package(desc,t,v,0,0,0,0)
430 #define PACKl(desc,t,v,l) package(desc,t,v,l,0,0,0,0)
432 #define PACK(desc,t,v) package(desc,v)
433 #define PACKl(desc,t,v,l) package(desc,v,l)
436 static void PACKI(struct pack_desc
* desc
, const char *t
,int v
)
441 static void PACKS(struct pack_desc
* desc
,const char *t
,const char *v
)
446 /****************************************************************************
448 ****************************************************************************/
450 static void PackDriverData(struct pack_desc
* desc
)
452 char drivdata
[4+4+32];
453 SIVAL(drivdata
,0,sizeof drivdata
); /* cb */
454 SIVAL(drivdata
,4,1000); /* lVersion */
455 memset(drivdata
+8,0,32); /* szDeviceName */
456 push_ascii(drivdata
+8,"NULL",32, STR_TERMINATE
);
457 PACKl(desc
,"l",drivdata
,sizeof drivdata
); /* pDriverData */
460 static int check_printq_info(struct pack_desc
* desc
,
461 unsigned int uLevel
, char *id1
, char *id2
)
463 desc
->subformat
= NULL
;
466 desc
->format
= "B13";
469 desc
->format
= "B13BWWWzzzzzWW";
472 desc
->format
= "B13BWWWzzzzzWN";
473 desc
->subformat
= "WB21BB16B10zWWzDDz";
476 desc
->format
= "zWWWWzzzzWWzzl";
479 desc
->format
= "zWWWWzzzzWNzzl";
480 desc
->subformat
= "WWzWWDDzz";
489 desc
->format
= "WzzzzzzzzN";
490 desc
->subformat
= "z";
493 DEBUG(0,("check_printq_info: invalid level %d\n",
497 if (id1
== NULL
|| strcmp(desc
->format
,id1
) != 0) {
498 DEBUG(0,("check_printq_info: invalid format %s\n",
499 id1
? id1
: "<NULL>" ));
502 if (desc
->subformat
&& (id2
== NULL
|| strcmp(desc
->subformat
,id2
) != 0)) {
503 DEBUG(0,("check_printq_info: invalid subformat %s\n",
504 id2
? id2
: "<NULL>" ));
511 #define RAP_JOB_STATUS_QUEUED 0
512 #define RAP_JOB_STATUS_PAUSED 1
513 #define RAP_JOB_STATUS_SPOOLING 2
514 #define RAP_JOB_STATUS_PRINTING 3
515 #define RAP_JOB_STATUS_PRINTED 4
517 #define RAP_QUEUE_STATUS_PAUSED 1
518 #define RAP_QUEUE_STATUS_ERROR 2
520 /* turn a print job status into a on the wire status
522 static int printj_spoolss_status(int v
)
524 if (v
== JOB_STATUS_QUEUED
)
525 return RAP_JOB_STATUS_QUEUED
;
526 if (v
& JOB_STATUS_PAUSED
)
527 return RAP_JOB_STATUS_PAUSED
;
528 if (v
& JOB_STATUS_SPOOLING
)
529 return RAP_JOB_STATUS_SPOOLING
;
530 if (v
& JOB_STATUS_PRINTING
)
531 return RAP_JOB_STATUS_PRINTING
;
535 /* turn a print queue status into a on the wire status
537 static int printq_spoolss_status(int v
)
539 if (v
== PRINTER_STATUS_OK
)
541 if (v
& PRINTER_STATUS_PAUSED
)
542 return RAP_QUEUE_STATUS_PAUSED
;
543 return RAP_QUEUE_STATUS_ERROR
;
546 static void fill_spoolss_printjob_info(int uLevel
,
547 struct pack_desc
*desc
,
548 struct spoolss_JobInfo2
*info2
,
551 time_t t
= spoolss_Time_to_time_t(&info2
->submitted
);
553 /* the client expects localtime */
554 t
-= get_time_zone(t
);
556 PACKI(desc
,"W",pjobid_to_rap(info2
->printer_name
, info2
->job_id
)); /* uJobId */
558 PACKS(desc
,"B21", info2
->user_name
); /* szUserName */
559 PACKS(desc
,"B",""); /* pad */
560 PACKS(desc
,"B16",""); /* szNotifyName */
561 PACKS(desc
,"B10","PM_Q_RAW"); /* szDataType */
562 PACKS(desc
,"z",""); /* pszParms */
563 PACKI(desc
,"W",n
+1); /* uPosition */
564 PACKI(desc
,"W", printj_spoolss_status(info2
->status
)); /* fsStatus */
565 PACKS(desc
,"z",""); /* pszStatus */
566 PACKI(desc
,"D", t
); /* ulSubmitted */
567 PACKI(desc
,"D", info2
->size
); /* ulSize */
568 PACKS(desc
,"z", info2
->document_name
); /* pszComment */
570 if (uLevel
== 2 || uLevel
== 3 || uLevel
== 4) {
571 PACKI(desc
,"W", info2
->priority
); /* uPriority */
572 PACKS(desc
,"z", info2
->user_name
); /* pszUserName */
573 PACKI(desc
,"W",n
+1); /* uPosition */
574 PACKI(desc
,"W", printj_spoolss_status(info2
->status
)); /* fsStatus */
575 PACKI(desc
,"D",t
); /* ulSubmitted */
576 PACKI(desc
,"D", info2
->size
); /* ulSize */
577 PACKS(desc
,"z","Samba"); /* pszComment */
578 PACKS(desc
,"z", info2
->document_name
); /* pszDocument */
580 PACKS(desc
,"z",""); /* pszNotifyName */
581 PACKS(desc
,"z","PM_Q_RAW"); /* pszDataType */
582 PACKS(desc
,"z",""); /* pszParms */
583 PACKS(desc
,"z",""); /* pszStatus */
584 PACKS(desc
,"z", info2
->printer_name
); /* pszQueue */
585 PACKS(desc
,"z","lpd"); /* pszQProcName */
586 PACKS(desc
,"z",""); /* pszQProcParms */
587 PACKS(desc
,"z","NULL"); /* pszDriverName */
588 PackDriverData(desc
); /* pDriverData */
589 PACKS(desc
,"z",""); /* pszPrinterName */
590 } else if (uLevel
== 4) { /* OS2 */
591 PACKS(desc
,"z",""); /* pszSpoolFileName */
592 PACKS(desc
,"z",""); /* pszPortName */
593 PACKS(desc
,"z",""); /* pszStatus */
594 PACKI(desc
,"D",0); /* ulPagesSpooled */
595 PACKI(desc
,"D",0); /* ulPagesSent */
596 PACKI(desc
,"D",0); /* ulPagesPrinted */
597 PACKI(desc
,"D",0); /* ulTimePrinted */
598 PACKI(desc
,"D",0); /* ulExtendJobStatus */
599 PACKI(desc
,"D",0); /* ulStartPage */
600 PACKI(desc
,"D",0); /* ulEndPage */
605 /********************************************************************
606 Respond to the DosPrintQInfo command with a level of 52
607 This is used to get printer driver information for Win9x clients
608 ********************************************************************/
609 static void fill_printq_info_52(struct spoolss_DriverInfo3
*driver
,
610 struct pack_desc
* desc
, int count
,
611 const char *printer_name
)
615 trim_string(discard_const_p(char, driver
->driver_path
), "\\print$\\WIN40\\0\\", 0);
616 trim_string(discard_const_p(char, driver
->data_file
), "\\print$\\WIN40\\0\\", 0);
617 trim_string(discard_const_p(char, driver
->help_file
), "\\print$\\WIN40\\0\\", 0);
619 PACKI(desc
, "W", 0x0400); /* don't know */
620 PACKS(desc
, "z", driver
->driver_name
); /* long printer name */
621 PACKS(desc
, "z", driver
->driver_path
); /* Driverfile Name */
622 PACKS(desc
, "z", driver
->data_file
); /* Datafile name */
623 PACKS(desc
, "z", driver
->monitor_name
); /* language monitor */
625 fstrcpy(location
, "\\\\%L\\print$\\WIN40\\0");
626 standard_sub_basic( "", "", location
, sizeof(location
)-1 );
627 PACKS(desc
,"z", location
); /* share to retrieve files */
629 PACKS(desc
,"z", driver
->default_datatype
); /* default data type */
630 PACKS(desc
,"z", driver
->help_file
); /* helpfile name */
631 PACKS(desc
,"z", driver
->driver_path
); /* driver name */
633 DEBUG(3,("Printer Driver Name: %s:\n",driver
->driver_name
));
634 DEBUG(3,("Driver: %s:\n",driver
->driver_path
));
635 DEBUG(3,("Data File: %s:\n",driver
->data_file
));
636 DEBUG(3,("Language Monitor: %s:\n",driver
->monitor_name
));
637 DEBUG(3,("Driver Location: %s:\n",location
));
638 DEBUG(3,("Data Type: %s:\n",driver
->default_datatype
));
639 DEBUG(3,("Help File: %s:\n",driver
->help_file
));
640 PACKI(desc
,"N",count
); /* number of files to copy */
642 for ( i
=0; i
<count
&& driver
->dependent_files
&& *driver
->dependent_files
[i
]; i
++)
644 trim_string(discard_const_p(char, driver
->dependent_files
[i
]), "\\print$\\WIN40\\0\\", 0);
645 PACKS(desc
,"z",driver
->dependent_files
[i
]); /* driver files to copy */
646 DEBUG(3,("Dependent File: %s:\n", driver
->dependent_files
[i
]));
651 DEBUG(3,("fill_printq_info_52: file count specified by client [%d] != number of dependent files [%i]\n",
654 DEBUG(3,("fill_printq_info on <%s> gave %d entries\n", printer_name
, i
));
656 desc
->errcode
=NERR_Success
;
660 static const char *strip_unc(const char *unc
)
668 if ((p
= strrchr(unc
, '\\')) != NULL
) {
675 static void fill_printq_info(int uLevel
,
676 struct pack_desc
* desc
,
678 union spoolss_JobInfo
*job_info
,
679 struct spoolss_DriverInfo3
*driver_info
,
680 struct spoolss_PrinterInfo2
*printer_info
)
686 PACKS(desc
,"B13", strip_unc(printer_info
->printername
));
691 PACKS(desc
,"z", strip_unc(printer_info
->printername
));
694 PACKI(desc
,"K", printq_spoolss_status(printer_info
->status
));
698 if (uLevel
== 1 || uLevel
== 2) {
699 PACKS(desc
,"B",""); /* alignment */
700 PACKI(desc
,"W",5); /* priority */
701 PACKI(desc
,"W",0); /* start time */
702 PACKI(desc
,"W",0); /* until time */
703 PACKS(desc
,"z",""); /* pSepFile */
704 PACKS(desc
,"z","lpd"); /* pPrProc */
705 PACKS(desc
,"z", strip_unc(printer_info
->printername
)); /* pDestinations */
706 PACKS(desc
,"z",""); /* pParms */
707 if (printer_info
->printername
== NULL
) {
708 PACKS(desc
,"z","UNKNOWN PRINTER");
709 PACKI(desc
,"W",LPSTAT_ERROR
);
711 PACKS(desc
,"z", printer_info
->comment
);
712 PACKI(desc
,"W", printq_spoolss_status(printer_info
->status
)); /* status */
714 PACKI(desc
,(uLevel
== 1 ? "W" : "N"),count
);
717 if (uLevel
== 3 || uLevel
== 4) {
718 PACKI(desc
,"W",5); /* uPriority */
719 PACKI(desc
,"W",0); /* uStarttime */
720 PACKI(desc
,"W",0); /* uUntiltime */
721 PACKI(desc
,"W",5); /* pad1 */
722 PACKS(desc
,"z",""); /* pszSepFile */
723 PACKS(desc
,"z","WinPrint"); /* pszPrProc */
724 PACKS(desc
,"z",NULL
); /* pszParms */
725 PACKS(desc
,"z",NULL
); /* pszComment - don't ask.... JRA */
726 /* "don't ask" that it's done this way to fix corrupted
727 Win9X/ME printer comments. */
728 PACKI(desc
,"W", printq_spoolss_status(printer_info
->status
)); /* fsStatus */
729 PACKI(desc
,(uLevel
== 3 ? "W" : "N"),count
); /* cJobs */
730 PACKS(desc
,"z", strip_unc(printer_info
->printername
)); /* pszPrinters */
731 PACKS(desc
,"z", printer_info
->drivername
); /* pszDriverName */
732 PackDriverData(desc
); /* pDriverData */
735 if (uLevel
== 2 || uLevel
== 4) {
737 for (i
= 0; i
< count
; i
++) {
738 fill_spoolss_printjob_info(uLevel
== 2 ? 1 : 2, desc
, &job_info
[i
].info2
, i
);
743 fill_printq_info_52(driver_info
, desc
, count
, printer_info
->printername
);
746 /* This function returns the number of files for a given driver */
747 static int get_printerdrivernumber(const struct spoolss_DriverInfo3
*driver
)
751 /* count the number of files */
752 while (driver
->dependent_files
&& *driver
->dependent_files
[result
])
758 static bool api_DosPrintQGetInfo(struct smbd_server_connection
*sconn
,
759 connection_struct
*conn
, uint64_t vuid
,
760 char *param
, int tpscnt
,
761 char *data
, int tdscnt
,
762 int mdrcnt
,int mprcnt
,
763 char **rdata
,char **rparam
,
764 int *rdata_len
,int *rparam_len
)
766 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
767 char *str2
= skip_string(param
,tpscnt
,str1
);
768 char *p
= skip_string(param
,tpscnt
,str2
);
773 struct pack_desc desc
;
776 WERROR werr
= WERR_OK
;
777 TALLOC_CTX
*mem_ctx
= talloc_tos();
779 struct rpc_pipe_client
*cli
= NULL
;
780 struct dcerpc_binding_handle
*b
= NULL
;
781 struct policy_handle handle
;
782 struct spoolss_DevmodeContainer devmode_ctr
;
783 union spoolss_DriverInfo driver_info
;
784 union spoolss_JobInfo
*job_info
= NULL
;
785 union spoolss_PrinterInfo printer_info
;
787 if (!str1
|| !str2
|| !p
) {
790 memset((char *)&desc
,'\0',sizeof(desc
));
792 p
= skip_string(param
,tpscnt
,p
);
796 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
797 str3
= get_safe_str_ptr(param
,tpscnt
,p
,4);
798 /* str3 may be null here and is checked in check_printq_info(). */
800 /* remove any trailing username */
801 if ((p
= strchr_m(QueueName
,'%')))
804 DEBUG(3,("api_DosPrintQGetInfo uLevel=%d name=%s\n",uLevel
,QueueName
));
806 /* check it's a supported varient */
807 if (!prefix_ok(str1
,"zWrLh"))
809 if (!check_printq_info(&desc
,uLevel
,str2
,str3
)) {
811 * Patch from Scott Moomaw <scott@bridgewater.edu>
812 * to return the 'invalid info level' error if an
813 * unknown level was requested.
817 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
821 SSVALS(*rparam
,0,ERRunknownlevel
);
829 if (QueueName
== NULL
|| (strlen(QueueName
) < 1)) {
830 desc
.errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
834 status
= rpc_pipe_open_interface(conn
,
837 conn
->sconn
->remote_address
,
838 conn
->sconn
->msg_ctx
,
840 if (!NT_STATUS_IS_OK(status
)) {
841 DEBUG(0,("api_DosPrintQGetInfo: could not connect to spoolss: %s\n",
843 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
846 b
= cli
->binding_handle
;
848 ZERO_STRUCT(devmode_ctr
);
850 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
857 if (!NT_STATUS_IS_OK(status
)) {
858 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
861 if (!W_ERROR_IS_OK(werr
)) {
862 desc
.errcode
= W_ERROR_V(werr
);
866 werr
= rpccli_spoolss_getprinter(cli
, mem_ctx
,
871 if (!W_ERROR_IS_OK(werr
)) {
872 desc
.errcode
= W_ERROR_V(werr
);
877 uint32_t server_major_version
;
878 uint32_t server_minor_version
;
880 werr
= rpccli_spoolss_getprinterdriver2(cli
, mem_ctx
,
888 &server_major_version
,
889 &server_minor_version
);
890 if (!W_ERROR_IS_OK(werr
)) {
891 desc
.errcode
= W_ERROR_V(werr
);
895 count
= get_printerdrivernumber(&driver_info
.info3
);
896 DEBUG(3,("api_DosPrintQGetInfo: Driver files count: %d\n",count
));
899 werr
= rpccli_spoolss_enumjobs(cli
, mem_ctx
,
907 if (!W_ERROR_IS_OK(werr
)) {
908 desc
.errcode
= W_ERROR_V(werr
);
916 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
921 desc
.buflen
= mdrcnt
;
924 * Don't return data but need to get correct length
925 * init_package will return wrong size if buflen=0
927 desc
.buflen
= getlen(desc
.format
);
928 desc
.base
= tmpdata
= (char *) SMB_MALLOC (desc
.buflen
);
931 if (init_package(&desc
,1,count
)) {
932 desc
.subcount
= count
;
933 fill_printq_info(uLevel
,&desc
,count
, job_info
, &driver_info
.info3
, &printer_info
.info2
);
936 *rdata_len
= desc
.usedlen
;
939 * We must set the return code to ERRbuftoosmall
940 * in order to support lanman style printing with Win NT/2k
943 if (!mdrcnt
&& lp_disable_spoolss())
944 desc
.errcode
= ERRbuftoosmall
;
947 if (b
&& is_valid_policy_hnd(&handle
)) {
948 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
951 *rdata_len
= desc
.usedlen
;
953 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
958 SSVALS(*rparam
,0,desc
.errcode
);
960 SSVAL(*rparam
,4,desc
.neededlen
);
962 DEBUG(4,("printqgetinfo: errorcode %d\n",desc
.errcode
));
969 /****************************************************************************
970 View list of all print jobs on all queues.
971 ****************************************************************************/
973 static bool api_DosPrintQEnum(struct smbd_server_connection
*sconn
,
974 connection_struct
*conn
, uint64_t vuid
,
975 char *param
, int tpscnt
,
976 char *data
, int tdscnt
,
977 int mdrcnt
, int mprcnt
,
978 char **rdata
, char** rparam
,
979 int *rdata_len
, int *rparam_len
)
981 char *param_format
= get_safe_str_ptr(param
,tpscnt
,param
,2);
982 char *output_format1
= skip_string(param
,tpscnt
,param_format
);
983 char *p
= skip_string(param
,tpscnt
,output_format1
);
984 unsigned int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
985 char *output_format2
= get_safe_str_ptr(param
,tpscnt
,p
,4);
987 struct pack_desc desc
;
988 int *subcntarr
= NULL
;
989 int queuecnt
= 0, subcnt
= 0, succnt
= 0;
991 WERROR werr
= WERR_OK
;
992 TALLOC_CTX
*mem_ctx
= talloc_tos();
994 struct rpc_pipe_client
*cli
= NULL
;
995 struct dcerpc_binding_handle
*b
= NULL
;
996 struct spoolss_DevmodeContainer devmode_ctr
;
997 uint32_t num_printers
;
998 union spoolss_PrinterInfo
*printer_info
;
999 union spoolss_DriverInfo
*driver_info
;
1000 union spoolss_JobInfo
**job_info
;
1002 if (!param_format
|| !output_format1
|| !p
) {
1006 memset((char *)&desc
,'\0',sizeof(desc
));
1008 DEBUG(3,("DosPrintQEnum uLevel=%d\n",uLevel
));
1010 if (!prefix_ok(param_format
,"WrLeh")) {
1013 if (!check_printq_info(&desc
,uLevel
,output_format1
,output_format2
)) {
1015 * Patch from Scott Moomaw <scott@bridgewater.edu>
1016 * to return the 'invalid info level' error if an
1017 * unknown level was requested.
1021 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1025 SSVALS(*rparam
,0,ERRunknownlevel
);
1031 status
= rpc_pipe_open_interface(conn
,
1034 conn
->sconn
->remote_address
,
1035 conn
->sconn
->msg_ctx
,
1037 if (!NT_STATUS_IS_OK(status
)) {
1038 DEBUG(0,("api_DosPrintQEnum: could not connect to spoolss: %s\n",
1039 nt_errstr(status
)));
1040 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
1043 b
= cli
->binding_handle
;
1045 werr
= rpccli_spoolss_enumprinters(cli
, mem_ctx
,
1047 cli
->srv_name_slash
,
1052 if (!W_ERROR_IS_OK(werr
)) {
1053 desc
.errcode
= W_ERROR_V(werr
);
1057 queuecnt
= num_printers
;
1059 job_info
= talloc_array(mem_ctx
, union spoolss_JobInfo
*, num_printers
);
1060 if (job_info
== NULL
) {
1064 driver_info
= talloc_array(mem_ctx
, union spoolss_DriverInfo
, num_printers
);
1065 if (driver_info
== NULL
) {
1069 if((subcntarr
= SMB_MALLOC_ARRAY(int,queuecnt
)) == NULL
) {
1070 DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1075 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
1081 desc
.buflen
= mdrcnt
;
1084 for (i
= 0; i
< num_printers
; i
++) {
1087 struct policy_handle handle
;
1088 const char *printername
;
1090 printername
= talloc_strdup(mem_ctx
, printer_info
[i
].info2
.printername
);
1091 if (printername
== NULL
) {
1095 ZERO_STRUCT(handle
);
1096 ZERO_STRUCT(devmode_ctr
);
1098 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
1105 if (!NT_STATUS_IS_OK(status
)) {
1106 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
1109 if (!W_ERROR_IS_OK(werr
)) {
1110 desc
.errcode
= W_ERROR_V(werr
);
1114 werr
= rpccli_spoolss_enumjobs(cli
, mem_ctx
,
1122 if (!W_ERROR_IS_OK(werr
)) {
1123 desc
.errcode
= W_ERROR_V(werr
);
1128 uint32_t server_major_version
;
1129 uint32_t server_minor_version
;
1131 werr
= rpccli_spoolss_getprinterdriver2(cli
, mem_ctx
,
1139 &server_major_version
,
1140 &server_minor_version
);
1141 if (!W_ERROR_IS_OK(werr
)) {
1142 desc
.errcode
= W_ERROR_V(werr
);
1147 subcntarr
[i
] = num_jobs
;
1148 subcnt
+= subcntarr
[i
];
1150 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
1153 if (init_package(&desc
,queuecnt
,subcnt
)) {
1154 for (i
= 0; i
< num_printers
; i
++) {
1155 fill_printq_info(uLevel
,&desc
,subcntarr
[i
], job_info
[i
], &driver_info
[i
].info3
, &printer_info
[i
].info2
);
1156 if (desc
.errcode
== NERR_Success
) {
1163 SAFE_FREE(subcntarr
);
1164 *rdata_len
= desc
.usedlen
;
1166 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1170 SSVALS(*rparam
,0,desc
.errcode
);
1172 SSVAL(*rparam
,4,succnt
);
1173 SSVAL(*rparam
,6,queuecnt
);
1179 SAFE_FREE(subcntarr
);
1184 /****************************************************************************
1185 Get info level for a server list query.
1186 ****************************************************************************/
1188 static bool check_session_info(int uLevel
, char* id
)
1192 if (strcmp(id
,"B16") != 0) {
1197 if (strcmp(id
,"B16BBDz") != 0) {
1207 struct srv_info_struct
{
1215 /*******************************************************************
1216 Get server info lists from the files saved by nmbd. Return the
1218 ******************************************************************/
1220 static int get_session_info(uint32 servertype
,
1221 struct srv_info_struct
**servers
,
1227 bool local_list_only
;
1230 lines
= file_lines_load(cache_path(SERVER_LIST
), NULL
, 0, NULL
);
1232 DEBUG(4,("Can't open %s - %s\n",cache_path(SERVER_LIST
),strerror(errno
)));
1236 /* request for everything is code for request all servers */
1237 if (servertype
== SV_TYPE_ALL
) {
1238 servertype
&= ~(SV_TYPE_DOMAIN_ENUM
|SV_TYPE_LOCAL_LIST_ONLY
);
1241 local_list_only
= (servertype
& SV_TYPE_LOCAL_LIST_ONLY
);
1243 DEBUG(4,("Servertype search: %8x\n",servertype
));
1245 for (i
=0;lines
[i
];i
++) {
1247 struct srv_info_struct
*s
;
1248 const char *ptr
= lines
[i
];
1250 TALLOC_CTX
*frame
= NULL
;
1257 if (count
== alloced
) {
1259 *servers
= SMB_REALLOC_ARRAY(*servers
,struct srv_info_struct
, alloced
);
1261 DEBUG(0,("get_session_info: failed to enlarge servers info struct!\n"));
1265 memset((char *)((*servers
)+count
),'\0',sizeof(**servers
)*(alloced
-count
));
1267 s
= &(*servers
)[count
];
1269 frame
= talloc_stackframe();
1271 if (!next_token_talloc(frame
,&ptr
,&p
, NULL
)) {
1275 fstrcpy(s
->name
, p
);
1278 if (!next_token_talloc(frame
,&ptr
, &p
, NULL
)) {
1284 s
->comment
[0] = '\0';
1285 if (!next_token_talloc(frame
,&ptr
, &p
, NULL
)) {
1289 fstrcpy(s
->comment
, p
);
1290 string_truncate(s
->comment
, MAX_SERVER_STRING_LENGTH
);
1292 s
->domain
[0] = '\0';
1293 if (!next_token_talloc(frame
,&ptr
,&p
, NULL
)) {
1294 /* this allows us to cope with an old nmbd */
1295 fstrcpy(s
->domain
,lp_workgroup());
1297 fstrcpy(s
->domain
, p
);
1301 if (sscanf(stype
,"%X",&s
->type
) != 1) {
1302 DEBUG(4,("r:host file "));
1306 /* Filter the servers/domains we return based on what was asked for. */
1308 /* Check to see if we are being asked for a local list only. */
1309 if(local_list_only
&& ((s
->type
& SV_TYPE_LOCAL_LIST_ONLY
) == 0)) {
1310 DEBUG(4,("r: local list only"));
1314 /* doesn't match up: don't want it */
1315 if (!(servertype
& s
->type
)) {
1316 DEBUG(4,("r:serv type "));
1320 if ((servertype
& SV_TYPE_DOMAIN_ENUM
) !=
1321 (s
->type
& SV_TYPE_DOMAIN_ENUM
)) {
1322 DEBUG(4,("s: dom mismatch "));
1326 if (!strequal(domain
, s
->domain
) && !(servertype
& SV_TYPE_DOMAIN_ENUM
)) {
1330 /* We should never return a server type with a SV_TYPE_LOCAL_LIST_ONLY set. */
1331 s
->type
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1334 DEBUG(4,("**SV** %20s %8x %25s %15s\n",
1335 s
->name
, s
->type
, s
->comment
, s
->domain
));
1336 s
->server_added
= True
;
1339 DEBUG(4,("%20s %8x %25s %15s\n",
1340 s
->name
, s
->type
, s
->comment
, s
->domain
));
1348 /*******************************************************************
1349 Fill in a server info structure.
1350 ******************************************************************/
1352 static int fill_srv_info(struct srv_info_struct
*service
,
1353 int uLevel
, char **buf
, int *buflen
,
1354 char **stringbuf
, int *stringspace
, char *baseaddr
)
1377 len
= strlen(service
->comment
)+1;
1381 *buflen
= struct_len
;
1383 return struct_len
+ len
;
1388 if (*buflen
< struct_len
) {
1395 p2
= p
+ struct_len
;
1396 l2
= *buflen
- struct_len
;
1404 push_ascii(p
,service
->name
, MAX_NETBIOSNAME_LEN
, STR_TERMINATE
);
1408 push_ascii(p
,service
->name
,MAX_NETBIOSNAME_LEN
, STR_TERMINATE
);
1409 SIVAL(p
,18,service
->type
);
1410 SIVAL(p
,22,PTR_DIFF(p2
,baseaddr
));
1411 len
+= CopyAndAdvance(&p2
,service
->comment
,&l2
);
1416 *buf
= p
+ struct_len
;
1417 *buflen
-= struct_len
;
1428 static int srv_comp(struct srv_info_struct
*s1
,struct srv_info_struct
*s2
)
1430 return strcasecmp_m(s1
->name
,s2
->name
);
1433 /****************************************************************************
1434 View list of servers available (or possibly domains). The info is
1435 extracted from lists saved by nmbd on the local host.
1436 ****************************************************************************/
1438 static bool api_RNetServerEnum2(struct smbd_server_connection
*sconn
,
1439 connection_struct
*conn
, uint64_t vuid
,
1440 char *param
, int tpscnt
,
1441 char *data
, int tdscnt
,
1442 int mdrcnt
, int mprcnt
, char **rdata
,
1443 char **rparam
, int *rdata_len
, int *rparam_len
)
1445 char *str1
= get_safe_str_ptr(param
, tpscnt
, param
, 2);
1446 char *str2
= skip_string(param
,tpscnt
,str1
);
1447 char *p
= skip_string(param
,tpscnt
,str2
);
1448 int uLevel
= get_safe_SVAL(param
, tpscnt
, p
, 0, -1);
1449 int buf_len
= get_safe_SVAL(param
,tpscnt
, p
, 2, 0);
1450 uint32 servertype
= get_safe_IVAL(param
,tpscnt
,p
,4, 0);
1452 int data_len
, fixed_len
, string_len
;
1453 int f_len
= 0, s_len
= 0;
1454 struct srv_info_struct
*servers
=NULL
;
1455 int counted
=0,total
=0;
1458 bool domain_request
;
1461 if (!str1
|| !str2
|| !p
) {
1465 /* If someone sets all the bits they don't really mean to set
1466 DOMAIN_ENUM and LOCAL_LIST_ONLY, they just want all the
1469 if (servertype
== SV_TYPE_ALL
) {
1470 servertype
&= ~(SV_TYPE_DOMAIN_ENUM
|SV_TYPE_LOCAL_LIST_ONLY
);
1473 /* If someone sets SV_TYPE_LOCAL_LIST_ONLY but hasn't set
1474 any other bit (they may just set this bit on its own) they
1475 want all the locally seen servers. However this bit can be
1476 set on its own so set the requested servers to be
1477 ALL - DOMAIN_ENUM. */
1479 if ((servertype
& SV_TYPE_LOCAL_LIST_ONLY
) && !(servertype
& SV_TYPE_DOMAIN_ENUM
)) {
1480 servertype
= SV_TYPE_ALL
& ~(SV_TYPE_DOMAIN_ENUM
);
1483 domain_request
= ((servertype
& SV_TYPE_DOMAIN_ENUM
) != 0);
1484 local_request
= ((servertype
& SV_TYPE_LOCAL_LIST_ONLY
) != 0);
1488 if (!prefix_ok(str1
,"WrLehD")) {
1491 if (!check_session_info(uLevel
,str2
)) {
1495 DEBUG(4, ("server request level: %s %8x ", str2
, servertype
));
1496 DEBUG(4, ("domains_req:%s ", BOOLSTR(domain_request
)));
1497 DEBUG(4, ("local_only:%s\n", BOOLSTR(local_request
)));
1499 if (strcmp(str1
, "WrLehDz") == 0) {
1500 if (skip_string(param
,tpscnt
,p
) == NULL
) {
1503 pull_ascii_fstring(domain
, p
);
1505 fstrcpy(domain
, lp_workgroup());
1508 DEBUG(4, ("domain [%s]\n", domain
));
1510 if (lp_browse_list()) {
1511 total
= get_session_info(servertype
,&servers
,domain
);
1514 data_len
= fixed_len
= string_len
= 0;
1517 TYPESAFE_QSORT(servers
, total
, srv_comp
);
1520 char *lastname
=NULL
;
1522 for (i
=0;i
<total
;i
++) {
1523 struct srv_info_struct
*s
= &servers
[i
];
1525 if (lastname
&& strequal(lastname
,s
->name
)) {
1529 data_len
+= fill_srv_info(s
,uLevel
,0,&f_len
,0,&s_len
,0);
1530 DEBUG(4,("fill_srv_info[%d] %20s %8x %25s %15s\n",
1531 i
, s
->name
, s
->type
, s
->comment
, s
->domain
));
1533 if (data_len
< buf_len
) {
1536 string_len
+= s_len
;
1543 *rdata_len
= fixed_len
+ string_len
;
1544 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
1549 p2
= (*rdata
) + fixed_len
; /* auxilliary data (strings) will go here */
1555 char *lastname
=NULL
;
1556 int count2
= counted
;
1558 for (i
= 0; i
< total
&& count2
;i
++) {
1559 struct srv_info_struct
*s
= &servers
[i
];
1561 if (lastname
&& strequal(lastname
,s
->name
)) {
1565 fill_srv_info(s
,uLevel
,&p
,&f_len
,&p2
,&s_len
,*rdata
);
1566 DEBUG(4,("fill_srv_info[%d] %20s %8x %25s %15s\n",
1567 i
, s
->name
, s
->type
, s
->comment
, s
->domain
));
1573 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1577 SSVAL(*rparam
,0,(missed
== 0 ? NERR_Success
: ERRmoredata
));
1579 SSVAL(*rparam
,4,counted
);
1580 SSVAL(*rparam
,6,counted
+missed
);
1584 DEBUG(3,("NetServerEnum2 domain = %s uLevel=%d counted=%d total=%d\n",
1585 domain
,uLevel
,counted
,counted
+missed
));
1590 static int srv_name_match(const char *n1
, const char *n2
)
1593 * [MS-RAP] footnote <88> for Section 3.2.5.15 says:
1595 * In Windows, FirstNameToReturn need not be an exact match:
1596 * the server will return a list of servers that exist on
1597 * the network greater than or equal to the FirstNameToReturn.
1599 int ret
= strcasecmp_m(n1
, n2
);
1608 static bool api_RNetServerEnum3(struct smbd_server_connection
*sconn
,
1609 connection_struct
*conn
, uint64_t vuid
,
1610 char *param
, int tpscnt
,
1611 char *data
, int tdscnt
,
1612 int mdrcnt
, int mprcnt
, char **rdata
,
1613 char **rparam
, int *rdata_len
, int *rparam_len
)
1615 char *str1
= get_safe_str_ptr(param
, tpscnt
, param
, 2);
1616 char *str2
= skip_string(param
,tpscnt
,str1
);
1617 char *p
= skip_string(param
,tpscnt
,str2
);
1618 int uLevel
= get_safe_SVAL(param
, tpscnt
, p
, 0, -1);
1619 int buf_len
= get_safe_SVAL(param
,tpscnt
, p
, 2, 0);
1620 uint32 servertype
= get_safe_IVAL(param
,tpscnt
,p
,4, 0);
1622 int data_len
, fixed_len
, string_len
;
1623 int f_len
= 0, s_len
= 0;
1624 struct srv_info_struct
*servers
=NULL
;
1625 int counted
=0,first
=0,total
=0;
1629 bool domain_request
;
1632 if (!str1
|| !str2
|| !p
) {
1636 /* If someone sets all the bits they don't really mean to set
1637 DOMAIN_ENUM and LOCAL_LIST_ONLY, they just want all the
1640 if (servertype
== SV_TYPE_ALL
) {
1641 servertype
&= ~(SV_TYPE_DOMAIN_ENUM
|SV_TYPE_LOCAL_LIST_ONLY
);
1644 /* If someone sets SV_TYPE_LOCAL_LIST_ONLY but hasn't set
1645 any other bit (they may just set this bit on its own) they
1646 want all the locally seen servers. However this bit can be
1647 set on its own so set the requested servers to be
1648 ALL - DOMAIN_ENUM. */
1650 if ((servertype
& SV_TYPE_LOCAL_LIST_ONLY
) && !(servertype
& SV_TYPE_DOMAIN_ENUM
)) {
1651 servertype
= SV_TYPE_ALL
& ~(SV_TYPE_DOMAIN_ENUM
);
1654 domain_request
= ((servertype
& SV_TYPE_DOMAIN_ENUM
) != 0);
1655 local_request
= ((servertype
& SV_TYPE_LOCAL_LIST_ONLY
) != 0);
1659 if (strcmp(str1
, "WrLehDzz") != 0) {
1662 if (!check_session_info(uLevel
,str2
)) {
1666 DEBUG(4, ("server request level: %s %8x ", str2
, servertype
));
1667 DEBUG(4, ("domains_req:%s ", BOOLSTR(domain_request
)));
1668 DEBUG(4, ("local_only:%s\n", BOOLSTR(local_request
)));
1670 if (skip_string(param
,tpscnt
,p
) == NULL
) {
1673 pull_ascii_fstring(domain
, p
);
1674 if (domain
[0] == '\0') {
1675 fstrcpy(domain
, lp_workgroup());
1677 p
= skip_string(param
,tpscnt
,p
);
1678 if (skip_string(param
,tpscnt
,p
) == NULL
) {
1681 pull_ascii_fstring(first_name
, p
);
1683 DEBUG(4, ("domain: '%s' first_name: '%s'\n",
1684 domain
, first_name
));
1686 if (lp_browse_list()) {
1687 total
= get_session_info(servertype
,&servers
,domain
);
1690 data_len
= fixed_len
= string_len
= 0;
1693 TYPESAFE_QSORT(servers
, total
, srv_comp
);
1695 if (first_name
[0] != '\0') {
1696 struct srv_info_struct
*first_server
= NULL
;
1698 BINARY_ARRAY_SEARCH(servers
, total
, name
, first_name
,
1699 srv_name_match
, first_server
);
1701 first
= PTR_DIFF(first_server
, servers
) / sizeof(*servers
);
1703 * The binary search may not find the exact match
1704 * so we need to search backward to find the first match
1706 * This implements the strange matching windows
1707 * implements. (see the comment in srv_name_match().
1711 ret
= strcasecmp_m(first_name
,
1712 servers
[first
-1].name
);
1719 /* we should return no entries */
1725 char *lastname
=NULL
;
1727 for (i
=first
;i
<total
;i
++) {
1728 struct srv_info_struct
*s
= &servers
[i
];
1730 if (lastname
&& strequal(lastname
,s
->name
)) {
1734 data_len
+= fill_srv_info(s
,uLevel
,0,&f_len
,0,&s_len
,0);
1735 DEBUG(4,("fill_srv_info[%d] %20s %8x %25s %15s\n",
1736 i
, s
->name
, s
->type
, s
->comment
, s
->domain
));
1738 if (data_len
< buf_len
) {
1741 string_len
+= s_len
;
1748 *rdata_len
= fixed_len
+ string_len
;
1749 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
1754 p2
= (*rdata
) + fixed_len
; /* auxilliary data (strings) will go here */
1760 char *lastname
=NULL
;
1761 int count2
= counted
;
1763 for (i
= first
; i
< total
&& count2
;i
++) {
1764 struct srv_info_struct
*s
= &servers
[i
];
1766 if (lastname
&& strequal(lastname
,s
->name
)) {
1770 fill_srv_info(s
,uLevel
,&p
,&f_len
,&p2
,&s_len
,*rdata
);
1771 DEBUG(4,("fill_srv_info[%d] %20s %8x %25s %15s\n",
1772 i
, s
->name
, s
->type
, s
->comment
, s
->domain
));
1778 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1782 SSVAL(*rparam
,0,(missed
== 0 ? NERR_Success
: ERRmoredata
));
1784 SSVAL(*rparam
,4,counted
);
1785 SSVAL(*rparam
,6,counted
+missed
);
1787 DEBUG(3,("NetServerEnum3 domain = %s uLevel=%d first=%d[%s => %s] counted=%d total=%d\n",
1788 domain
,uLevel
,first
,first_name
,
1789 first
< total
? servers
[first
].name
: "",
1790 counted
,counted
+missed
));
1797 /****************************************************************************
1798 command 0x34 - suspected of being a "Lookup Names" stub api
1799 ****************************************************************************/
1801 static bool api_RNetGroupGetUsers(struct smbd_server_connection
*sconn
,
1802 connection_struct
*conn
, uint64_t vuid
,
1803 char *param
, int tpscnt
,
1804 char *data
, int tdscnt
,
1805 int mdrcnt
, int mprcnt
, char **rdata
,
1806 char **rparam
, int *rdata_len
, int *rparam_len
)
1808 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
1809 char *str2
= skip_string(param
,tpscnt
,str1
);
1810 char *p
= skip_string(param
,tpscnt
,str2
);
1811 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
1812 int buf_len
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
1816 if (!str1
|| !str2
|| !p
) {
1820 DEBUG(5,("RNetGroupGetUsers: %s %s %s %d %d\n",
1821 str1
, str2
, p
, uLevel
, buf_len
));
1823 if (!prefix_ok(str1
,"zWrLeh")) {
1830 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1835 SSVAL(*rparam
,0,0x08AC); /* informational warning message */
1837 SSVAL(*rparam
,4,counted
);
1838 SSVAL(*rparam
,6,counted
+missed
);
1843 /****************************************************************************
1844 get info about a share
1845 ****************************************************************************/
1847 static bool check_share_info(int uLevel
, char* id
)
1851 if (strcmp(id
,"B13") != 0) {
1856 /* Level-2 descriptor is allowed (and ignored) */
1857 if (strcmp(id
,"B13BWz") != 0 &&
1858 strcmp(id
,"B13BWzWWWzB9B") != 0) {
1863 if (strcmp(id
,"B13BWzWWWzB9B") != 0) {
1868 if (strcmp(id
,"B13BWzWWWzB9BB9BWzWWzWW") != 0) {
1878 static int fill_share_info(connection_struct
*conn
, int snum
, int uLevel
,
1879 char** buf
, int* buflen
,
1880 char** stringbuf
, int* stringspace
, char* baseaddr
)
1909 len
+= StrlenExpanded(conn
,snum
,lp_comment(talloc_tos(), snum
));
1912 len
+= strlen(lp_pathname(talloc_tos(), snum
)) + 1;
1915 *buflen
= struct_len
;
1920 return struct_len
+ len
;
1925 if ((*buflen
) < struct_len
) {
1933 p2
= p
+ struct_len
;
1934 l2
= (*buflen
) - struct_len
;
1941 push_ascii(p
,lp_servicename(talloc_tos(), snum
),13, STR_TERMINATE
);
1947 type
= STYPE_DISKTREE
;
1948 if (lp_print_ok(snum
)) {
1949 type
= STYPE_PRINTQ
;
1951 if (strequal("IPC",lp_fstype(talloc_tos(),snum
))) {
1954 SSVAL(p
,14,type
); /* device type */
1955 SIVAL(p
,16,PTR_DIFF(p2
,baseaddr
));
1956 len
+= CopyExpanded(conn
,snum
,&p2
,lp_comment(talloc_tos(),snum
),&l2
);
1960 SSVAL(p
,20,ACCESS_READ
|ACCESS_WRITE
|ACCESS_CREATE
); /* permissions */
1961 SSVALS(p
,22,-1); /* max uses */
1962 SSVAL(p
,24,1); /* current uses */
1963 SIVAL(p
,26,PTR_DIFF(p2
,baseaddr
)); /* local pathname */
1964 len
+= CopyAndAdvance(&p2
,lp_pathname(talloc_tos(),snum
),&l2
);
1965 memset(p
+30,0,SHPWLEN
+2); /* passwd (reserved), pad field */
1969 memset(p
+40,0,SHPWLEN
+2);
1980 (*buf
) = p
+ struct_len
;
1981 (*buflen
) -= struct_len
;
1983 (*stringspace
) = l2
;
1992 static bool api_RNetShareGetInfo(struct smbd_server_connection
*sconn
,
1993 connection_struct
*conn
,uint64_t vuid
,
1994 char *param
, int tpscnt
,
1995 char *data
, int tdscnt
,
1996 int mdrcnt
,int mprcnt
,
1997 char **rdata
,char **rparam
,
1998 int *rdata_len
,int *rparam_len
)
2000 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2001 char *str2
= skip_string(param
,tpscnt
,str1
);
2002 char *netname_in
= skip_string(param
,tpscnt
,str2
);
2003 char *netname
= NULL
;
2004 char *p
= skip_string(param
,tpscnt
,netname
);
2005 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2008 if (!str1
|| !str2
|| !netname_in
|| !p
) {
2012 snum
= find_service(talloc_tos(), netname_in
, &netname
);
2013 if (snum
< 0 || !netname
) {
2017 /* check it's a supported varient */
2018 if (!prefix_ok(str1
,"zWrLh")) {
2021 if (!check_share_info(uLevel
,str2
)) {
2025 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
2030 *rdata_len
= fill_share_info(conn
,snum
,uLevel
,&p
,&mdrcnt
,0,0,0);
2031 if (*rdata_len
< 0) {
2036 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2040 SSVAL(*rparam
,0,NERR_Success
);
2041 SSVAL(*rparam
,2,0); /* converter word */
2042 SSVAL(*rparam
,4,*rdata_len
);
2047 /****************************************************************************
2048 View the list of available shares.
2050 This function is the server side of the NetShareEnum() RAP call.
2051 It fills the return buffer with share names and share comments.
2052 Note that the return buffer normally (in all known cases) allows only
2053 twelve byte strings for share names (plus one for a nul terminator).
2054 Share names longer than 12 bytes must be skipped.
2055 ****************************************************************************/
2057 static bool api_RNetShareEnum(struct smbd_server_connection
*sconn
,
2058 connection_struct
*conn
, uint64_t vuid
,
2059 char *param
, int tpscnt
,
2060 char *data
, int tdscnt
,
2068 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2069 char *str2
= skip_string(param
,tpscnt
,str1
);
2070 char *p
= skip_string(param
,tpscnt
,str2
);
2071 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2072 int buf_len
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
2075 int total
=0,counted
=0;
2076 bool missed
= False
;
2078 int data_len
, fixed_len
, string_len
;
2079 int f_len
= 0, s_len
= 0;
2081 if (!str1
|| !str2
|| !p
) {
2085 if (!prefix_ok(str1
,"WrLeh")) {
2088 if (!check_share_info(uLevel
,str2
)) {
2092 /* Ensure all the usershares are loaded. */
2094 load_registry_shares();
2095 count
= load_usershare_shares(NULL
, connections_snum_used
);
2098 data_len
= fixed_len
= string_len
= 0;
2099 for (i
=0;i
<count
;i
++) {
2100 fstring servicename_dos
;
2101 if (!(lp_browseable(i
) && lp_snum_ok(i
))) {
2104 push_ascii_fstring(servicename_dos
, lp_servicename(talloc_tos(), i
));
2105 /* Maximum name length = 13. */
2106 if( lp_browseable( i
) && lp_snum_ok( i
) && (strlen(servicename_dos
) < 13)) {
2108 data_len
+= fill_share_info(conn
,i
,uLevel
,0,&f_len
,0,&s_len
,0);
2109 if (data_len
< buf_len
) {
2112 string_len
+= s_len
;
2119 *rdata_len
= fixed_len
+ string_len
;
2120 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2125 p2
= (*rdata
) + fixed_len
; /* auxiliary data (strings) will go here */
2130 for( i
= 0; i
< count
; i
++ ) {
2131 fstring servicename_dos
;
2132 if (!(lp_browseable(i
) && lp_snum_ok(i
))) {
2136 push_ascii_fstring(servicename_dos
,
2137 lp_servicename(talloc_tos(), i
));
2138 if (lp_browseable(i
) && lp_snum_ok(i
) && (strlen(servicename_dos
) < 13)) {
2139 if (fill_share_info( conn
,i
,uLevel
,&p
,&f_len
,&p2
,&s_len
,*rdata
) < 0) {
2146 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2150 SSVAL(*rparam
,0,missed
? ERRmoredata
: NERR_Success
);
2152 SSVAL(*rparam
,4,counted
);
2153 SSVAL(*rparam
,6,total
);
2155 DEBUG(3,("RNetShareEnum gave %d entries of %d (%d %d %d %d)\n",
2156 counted
,total
,uLevel
,
2157 buf_len
,*rdata_len
,mdrcnt
));
2162 /****************************************************************************
2164 ****************************************************************************/
2166 static bool api_RNetShareAdd(struct smbd_server_connection
*sconn
,
2167 connection_struct
*conn
,uint64_t vuid
,
2168 char *param
, int tpscnt
,
2169 char *data
, int tdscnt
,
2170 int mdrcnt
,int mprcnt
,
2171 char **rdata
,char **rparam
,
2172 int *rdata_len
,int *rparam_len
)
2174 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2175 char *str2
= skip_string(param
,tpscnt
,str1
);
2176 char *p
= skip_string(param
,tpscnt
,str2
);
2177 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2180 char *pathname
= NULL
;
2181 unsigned int offset
;
2183 size_t converted_size
;
2185 WERROR werr
= WERR_OK
;
2186 TALLOC_CTX
*mem_ctx
= talloc_tos();
2188 struct rpc_pipe_client
*cli
= NULL
;
2189 union srvsvc_NetShareInfo info
;
2190 struct srvsvc_NetShareInfo2 info2
;
2191 struct dcerpc_binding_handle
*b
;
2193 if (!str1
|| !str2
|| !p
) {
2197 /* check it's a supported varient */
2198 if (!prefix_ok(str1
,RAP_WShareAdd_REQ
)) {
2201 if (!check_share_info(uLevel
,str2
)) {
2208 /* Do we have a string ? */
2209 if (skip_string(data
,mdrcnt
,data
) == NULL
) {
2212 pull_ascii_fstring(sharename
,data
);
2218 /* only support disk share adds */
2219 if (SVAL(data
,14)!=STYPE_DISKTREE
) {
2223 offset
= IVAL(data
, 16);
2224 if (offset
>= mdrcnt
) {
2225 res
= ERRinvalidparam
;
2229 /* Do we have a string ? */
2230 if (skip_string(data
,mdrcnt
,data
+offset
) == NULL
) {
2233 pull_ascii_fstring(comment
, offset
? (data
+offset
) : "");
2235 offset
= IVAL(data
, 26);
2237 if (offset
>= mdrcnt
) {
2238 res
= ERRinvalidparam
;
2242 /* Do we have a string ? */
2243 if (skip_string(data
,mdrcnt
,data
+offset
) == NULL
) {
2247 if (!pull_ascii_talloc(talloc_tos(), &pathname
,
2248 offset
? (data
+offset
) : "", &converted_size
))
2250 DEBUG(0,("api_RNetShareAdd: pull_ascii_talloc failed: %s",
2258 status
= rpc_pipe_open_interface(mem_ctx
, &ndr_table_srvsvc
,
2260 conn
->sconn
->remote_address
,
2261 conn
->sconn
->msg_ctx
,
2263 if (!NT_STATUS_IS_OK(status
)) {
2264 DEBUG(0,("api_RNetShareAdd: could not connect to srvsvc: %s\n",
2265 nt_errstr(status
)));
2266 res
= W_ERROR_V(ntstatus_to_werror(status
));
2270 b
= cli
->binding_handle
;
2272 info2
.name
= sharename
;
2273 info2
.type
= STYPE_DISKTREE
;
2274 info2
.comment
= comment
;
2275 info2
.permissions
= 0;
2276 info2
.max_users
= 0;
2277 info2
.current_users
= 0;
2278 info2
.path
= pathname
;
2279 info2
.password
= NULL
;
2281 info
.info2
= &info2
;
2283 status
= dcerpc_srvsvc_NetShareAdd(b
, mem_ctx
,
2284 cli
->srv_name_slash
,
2289 if (!NT_STATUS_IS_OK(status
)) {
2290 res
= W_ERROR_V(ntstatus_to_werror(status
));
2293 if (!W_ERROR_IS_OK(werr
)) {
2294 res
= W_ERROR_V(werr
);
2299 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2303 SSVAL(*rparam
,0,NERR_Success
);
2304 SSVAL(*rparam
,2,0); /* converter word */
2305 SSVAL(*rparam
,4,*rdata_len
);
2313 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2318 SSVAL(*rparam
,0,res
);
2323 /****************************************************************************
2324 view list of groups available
2325 ****************************************************************************/
2327 static bool api_RNetGroupEnum(struct smbd_server_connection
*sconn
,
2328 connection_struct
*conn
,uint64_t vuid
,
2329 char *param
, int tpscnt
,
2330 char *data
, int tdscnt
,
2331 int mdrcnt
,int mprcnt
,
2332 char **rdata
,char **rparam
,
2333 int *rdata_len
,int *rparam_len
)
2337 int resume_context
, cli_buf_size
;
2338 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2339 char *str2
= skip_string(param
,tpscnt
,str1
);
2340 char *p
= skip_string(param
,tpscnt
,str2
);
2342 uint32_t num_groups
;
2343 uint32_t resume_handle
;
2344 struct rpc_pipe_client
*samr_pipe
= NULL
;
2345 struct policy_handle samr_handle
, domain_handle
;
2346 NTSTATUS status
, result
;
2347 struct dcerpc_binding_handle
*b
;
2349 if (!str1
|| !str2
|| !p
) {
2353 if (strcmp(str1
,"WrLeh") != 0) {
2358 * W-> resume context (number of users to skip)
2359 * r -> return parameter pointer to receive buffer
2360 * L -> length of receive buffer
2361 * e -> return parameter number of entries
2362 * h -> return parameter total number of users
2365 if (strcmp("B21",str2
) != 0) {
2369 status
= rpc_pipe_open_interface(
2370 talloc_tos(), &ndr_table_samr
,
2371 conn
->session_info
, conn
->sconn
->remote_address
,
2372 conn
->sconn
->msg_ctx
, &samr_pipe
);
2373 if (!NT_STATUS_IS_OK(status
)) {
2374 DEBUG(0, ("api_RNetUserEnum: Could not connect to samr: %s\n",
2375 nt_errstr(status
)));
2379 b
= samr_pipe
->binding_handle
;
2381 status
= dcerpc_samr_Connect2(b
, talloc_tos(), lp_netbios_name(),
2382 SAMR_ACCESS_LOOKUP_DOMAIN
, &samr_handle
,
2384 if (!NT_STATUS_IS_OK(status
)) {
2385 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2386 nt_errstr(status
)));
2389 if (!NT_STATUS_IS_OK(result
)) {
2390 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2391 nt_errstr(result
)));
2395 status
= dcerpc_samr_OpenDomain(b
, talloc_tos(), &samr_handle
,
2396 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
2397 get_global_sam_sid(), &domain_handle
,
2399 if (!NT_STATUS_IS_OK(status
)) {
2400 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2401 nt_errstr(status
)));
2402 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2405 if (!NT_STATUS_IS_OK(result
)) {
2406 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2407 nt_errstr(result
)));
2408 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2412 resume_context
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2413 cli_buf_size
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
2414 DEBUG(10,("api_RNetGroupEnum:resume context: %d, client buffer size: "
2415 "%d\n", resume_context
, cli_buf_size
));
2417 *rdata_len
= cli_buf_size
;
2418 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2425 errflags
= NERR_Success
;
2430 struct samr_SamArray
*sam_entries
;
2431 uint32_t num_entries
;
2433 status
= dcerpc_samr_EnumDomainGroups(b
, talloc_tos(),
2439 if (!NT_STATUS_IS_OK(status
)) {
2440 DEBUG(10, ("dcerpc_samr_EnumDomainGroups returned "
2441 "%s\n", nt_errstr(status
)));
2444 if (!NT_STATUS_IS_OK(result
)) {
2446 DEBUG(10, ("dcerpc_samr_EnumDomainGroups returned "
2447 "%s\n", nt_errstr(result
)));
2451 if (num_entries
== 0) {
2452 DEBUG(10, ("dcerpc_samr_EnumDomainGroups returned "
2453 "no entries -- done\n"));
2457 for(i
=0; i
<num_entries
; i
++) {
2460 name
= sam_entries
->entries
[i
].name
.string
;
2462 if( ((PTR_DIFF(p
,*rdata
)+21) > *rdata_len
) ) {
2463 /* set overflow error */
2464 DEBUG(3,("overflow on entry %d group %s\n", i
,
2470 /* truncate the name at 21 chars. */
2472 strlcpy(p
, name
, 21);
2473 DEBUG(10,("adding entry %d group %s\n", i
, p
));
2475 p
+= 5; /* Both NT4 and W2k3SP1 do padding here. No
2480 if (errflags
!= NERR_Success
) {
2484 TALLOC_FREE(sam_entries
);
2487 dcerpc_samr_Close(b
, talloc_tos(), &domain_handle
, &result
);
2488 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2490 *rdata_len
= PTR_DIFF(p
,*rdata
);
2493 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2497 SSVAL(*rparam
, 0, errflags
);
2498 SSVAL(*rparam
, 2, 0); /* converter word */
2499 SSVAL(*rparam
, 4, num_groups
); /* is this right?? */
2500 SSVAL(*rparam
, 6, resume_context
+num_groups
); /* is this right?? */
2505 /*******************************************************************
2506 Get groups that a user is a member of.
2507 ******************************************************************/
2509 static bool api_NetUserGetGroups(struct smbd_server_connection
*sconn
,
2510 connection_struct
*conn
,uint64_t vuid
,
2511 char *param
, int tpscnt
,
2512 char *data
, int tdscnt
,
2513 int mdrcnt
,int mprcnt
,
2514 char **rdata
,char **rparam
,
2515 int *rdata_len
,int *rparam_len
)
2517 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2518 char *str2
= skip_string(param
,tpscnt
,str1
);
2519 char *UserName
= skip_string(param
,tpscnt
,str2
);
2520 char *p
= skip_string(param
,tpscnt
,UserName
);
2521 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2522 const char *level_string
;
2528 struct rpc_pipe_client
*samr_pipe
= NULL
;
2529 struct policy_handle samr_handle
, domain_handle
, user_handle
;
2530 struct lsa_String name
;
2531 struct lsa_Strings names
;
2532 struct samr_Ids type
, rid
;
2533 struct samr_RidWithAttributeArray
*rids
;
2534 NTSTATUS status
, result
;
2535 struct dcerpc_binding_handle
*b
;
2537 if (!str1
|| !str2
|| !UserName
|| !p
) {
2542 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2547 /* check it's a supported varient */
2549 if ( strcmp(str1
,"zWrLeh") != 0 )
2554 level_string
= "B21";
2560 if (strcmp(level_string
,str2
) != 0)
2563 *rdata_len
= mdrcnt
+ 1024;
2564 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2569 SSVAL(*rparam
,0,NERR_Success
);
2570 SSVAL(*rparam
,2,0); /* converter word */
2573 endp
= *rdata
+ *rdata_len
;
2575 status
= rpc_pipe_open_interface(
2576 talloc_tos(), &ndr_table_samr
,
2577 conn
->session_info
, conn
->sconn
->remote_address
,
2578 conn
->sconn
->msg_ctx
, &samr_pipe
);
2579 if (!NT_STATUS_IS_OK(status
)) {
2580 DEBUG(0, ("api_RNetUserEnum: Could not connect to samr: %s\n",
2581 nt_errstr(status
)));
2585 b
= samr_pipe
->binding_handle
;
2587 status
= dcerpc_samr_Connect2(b
, talloc_tos(), lp_netbios_name(),
2588 SAMR_ACCESS_LOOKUP_DOMAIN
, &samr_handle
,
2590 if (!NT_STATUS_IS_OK(status
)) {
2591 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2592 nt_errstr(status
)));
2595 if (!NT_STATUS_IS_OK(result
)) {
2596 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2597 nt_errstr(result
)));
2601 status
= dcerpc_samr_OpenDomain(b
, talloc_tos(), &samr_handle
,
2602 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
2603 get_global_sam_sid(), &domain_handle
,
2605 if (!NT_STATUS_IS_OK(status
)) {
2606 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2607 nt_errstr(status
)));
2610 if (!NT_STATUS_IS_OK(result
)) {
2611 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2612 nt_errstr(result
)));
2616 name
.string
= UserName
;
2618 status
= dcerpc_samr_LookupNames(b
, talloc_tos(),
2619 &domain_handle
, 1, &name
,
2622 if (!NT_STATUS_IS_OK(status
)) {
2623 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2624 nt_errstr(status
)));
2627 if (!NT_STATUS_IS_OK(result
)) {
2628 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2629 nt_errstr(result
)));
2632 if (rid
.count
!= 1) {
2633 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2636 if (type
.count
!= 1) {
2637 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2641 if (type
.ids
[0] != SID_NAME_USER
) {
2642 DEBUG(10, ("%s is a %s, not a user\n", UserName
,
2643 sid_type_lookup(type
.ids
[0])));
2647 status
= dcerpc_samr_OpenUser(b
, talloc_tos(),
2649 SAMR_USER_ACCESS_GET_GROUPS
,
2650 rid
.ids
[0], &user_handle
,
2652 if (!NT_STATUS_IS_OK(status
)) {
2653 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2654 nt_errstr(status
)));
2657 if (!NT_STATUS_IS_OK(result
)) {
2658 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2659 nt_errstr(result
)));
2663 status
= dcerpc_samr_GetGroupsForUser(b
, talloc_tos(),
2664 &user_handle
, &rids
,
2666 if (!NT_STATUS_IS_OK(status
)) {
2667 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2668 nt_errstr(status
)));
2671 if (!NT_STATUS_IS_OK(result
)) {
2672 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2673 nt_errstr(result
)));
2677 for (i
=0; i
<rids
->count
; i
++) {
2679 status
= dcerpc_samr_LookupRids(b
, talloc_tos(),
2681 1, &rids
->rids
[i
].rid
,
2684 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(result
) && (names
.count
== 1)) {
2685 strlcpy(p
, names
.names
[0].string
, PTR_DIFF(endp
,p
));
2691 *rdata_len
= PTR_DIFF(p
,*rdata
);
2693 SSVAL(*rparam
,4,count
); /* is this right?? */
2694 SSVAL(*rparam
,6,count
); /* is this right?? */
2699 dcerpc_samr_Close(b
, talloc_tos(), &user_handle
, &result
);
2701 dcerpc_samr_Close(b
, talloc_tos(), &domain_handle
, &result
);
2703 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2708 /*******************************************************************
2710 ******************************************************************/
2712 static bool api_RNetUserEnum(struct smbd_server_connection
*sconn
,
2713 connection_struct
*conn
, uint64_t vuid
,
2714 char *param
, int tpscnt
,
2715 char *data
, int tdscnt
,
2716 int mdrcnt
,int mprcnt
,
2717 char **rdata
,char **rparam
,
2718 int *rdata_len
,int *rparam_len
)
2723 int i
, resume_context
, cli_buf_size
;
2724 uint32_t resume_handle
;
2726 struct rpc_pipe_client
*samr_pipe
= NULL
;
2727 struct policy_handle samr_handle
, domain_handle
;
2728 NTSTATUS status
, result
;
2730 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2731 char *str2
= skip_string(param
,tpscnt
,str1
);
2732 char *p
= skip_string(param
,tpscnt
,str2
);
2735 struct dcerpc_binding_handle
*b
;
2737 if (!str1
|| !str2
|| !p
) {
2741 if (strcmp(str1
,"WrLeh") != 0)
2744 * W-> resume context (number of users to skip)
2745 * r -> return parameter pointer to receive buffer
2746 * L -> length of receive buffer
2747 * e -> return parameter number of entries
2748 * h -> return parameter total number of users
2751 resume_context
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2752 cli_buf_size
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
2753 DEBUG(10,("api_RNetUserEnum:resume context: %d, client buffer size: %d\n",
2754 resume_context
, cli_buf_size
));
2757 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2762 /* check it's a supported varient */
2763 if (strcmp("B21",str2
) != 0)
2766 *rdata_len
= cli_buf_size
;
2767 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2773 endp
= *rdata
+ *rdata_len
;
2775 status
= rpc_pipe_open_interface(
2776 talloc_tos(), &ndr_table_samr
,
2777 conn
->session_info
, conn
->sconn
->remote_address
,
2778 conn
->sconn
->msg_ctx
, &samr_pipe
);
2779 if (!NT_STATUS_IS_OK(status
)) {
2780 DEBUG(0, ("api_RNetUserEnum: Could not connect to samr: %s\n",
2781 nt_errstr(status
)));
2785 b
= samr_pipe
->binding_handle
;
2787 status
= dcerpc_samr_Connect2(b
, talloc_tos(), lp_netbios_name(),
2788 SAMR_ACCESS_LOOKUP_DOMAIN
, &samr_handle
,
2790 if (!NT_STATUS_IS_OK(status
)) {
2791 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2792 nt_errstr(status
)));
2795 if (!NT_STATUS_IS_OK(result
)) {
2796 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2797 nt_errstr(result
)));
2801 status
= dcerpc_samr_OpenDomain(b
, talloc_tos(), &samr_handle
,
2802 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
2803 get_global_sam_sid(), &domain_handle
,
2805 if (!NT_STATUS_IS_OK(status
)) {
2806 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2807 nt_errstr(status
)));
2808 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2811 if (!NT_STATUS_IS_OK(result
)) {
2812 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2813 nt_errstr(result
)));
2814 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2818 errflags
=NERR_Success
;
2823 struct samr_SamArray
*sam_entries
;
2824 uint32_t num_entries
;
2826 status
= dcerpc_samr_EnumDomainUsers(b
, talloc_tos(),
2833 if (!NT_STATUS_IS_OK(status
)) {
2834 DEBUG(10, ("dcerpc_samr_EnumDomainUsers returned "
2835 "%s\n", nt_errstr(status
)));
2838 if (!NT_STATUS_IS_OK(result
)) {
2839 DEBUG(10, ("dcerpc_samr_EnumDomainUsers returned "
2840 "%s\n", nt_errstr(result
)));
2844 if (num_entries
== 0) {
2845 DEBUG(10, ("dcerpc_samr_EnumDomainUsers returned "
2846 "no entries -- done\n"));
2850 for (i
=0; i
<num_entries
; i
++) {
2853 name
= sam_entries
->entries
[i
].name
.string
;
2855 if(((PTR_DIFF(p
,*rdata
)+21)<=*rdata_len
)
2856 &&(strlen(name
)<=21)) {
2857 strlcpy(p
,name
,PTR_DIFF(endp
,p
));
2858 DEBUG(10,("api_RNetUserEnum:adding entry %d "
2859 "username %s\n",count_sent
,p
));
2863 /* set overflow error */
2864 DEBUG(10,("api_RNetUserEnum:overflow on entry %d "
2865 "username %s\n",count_sent
,name
));
2871 if (errflags
!= NERR_Success
) {
2875 TALLOC_FREE(sam_entries
);
2878 dcerpc_samr_Close(b
, talloc_tos(), &domain_handle
, &result
);
2879 dcerpc_samr_Close(b
, talloc_tos(), &samr_handle
, &result
);
2881 *rdata_len
= PTR_DIFF(p
,*rdata
);
2883 SSVAL(*rparam
,0,errflags
);
2884 SSVAL(*rparam
,2,0); /* converter word */
2885 SSVAL(*rparam
,4,count_sent
); /* is this right?? */
2886 SSVAL(*rparam
,6,num_users
); /* is this right?? */
2891 /****************************************************************************
2892 Get the time of day info.
2893 ****************************************************************************/
2895 static bool api_NetRemoteTOD(struct smbd_server_connection
*sconn
,
2896 connection_struct
*conn
,uint64_t vuid
,
2897 char *param
, int tpscnt
,
2898 char *data
, int tdscnt
,
2899 int mdrcnt
,int mprcnt
,
2900 char **rdata
,char **rparam
,
2901 int *rdata_len
,int *rparam_len
)
2904 time_t unixdate
= time(NULL
);
2908 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2914 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2919 SSVAL(*rparam
,0,NERR_Success
);
2920 SSVAL(*rparam
,2,0); /* converter word */
2924 srv_put_dos_date3(p
,0,unixdate
); /* this is the time that is looked at
2925 by NT in a "net time" operation,
2926 it seems to ignore the one below */
2928 /* the client expects to get localtime, not GMT, in this bit
2929 (I think, this needs testing) */
2930 t
= localtime(&unixdate
);
2935 SIVAL(p
,4,0); /* msecs ? */
2936 SCVAL(p
,8,t
->tm_hour
);
2937 SCVAL(p
,9,t
->tm_min
);
2938 SCVAL(p
,10,t
->tm_sec
);
2939 SCVAL(p
,11,0); /* hundredths of seconds */
2940 SSVALS(p
,12,get_time_zone(unixdate
)/60); /* timezone in minutes from GMT */
2941 SSVAL(p
,14,10000); /* timer interval in 0.0001 of sec */
2942 SCVAL(p
,16,t
->tm_mday
);
2943 SCVAL(p
,17,t
->tm_mon
+ 1);
2944 SSVAL(p
,18,1900+t
->tm_year
);
2945 SCVAL(p
,20,t
->tm_wday
);
2950 /****************************************************************************
2951 Set the user password.
2952 *****************************************************************************/
2954 static bool api_SetUserPassword(struct smbd_server_connection
*sconn
,
2955 connection_struct
*conn
,uint64_t vuid
,
2956 char *param
, int tpscnt
,
2957 char *data
, int tdscnt
,
2958 int mdrcnt
,int mprcnt
,
2959 char **rdata
,char **rparam
,
2960 int *rdata_len
,int *rparam_len
)
2962 char *np
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2965 fstring pass1
,pass2
;
2966 TALLOC_CTX
*mem_ctx
= talloc_tos();
2967 NTSTATUS status
, result
;
2968 struct rpc_pipe_client
*cli
= NULL
;
2969 struct policy_handle connect_handle
, domain_handle
, user_handle
;
2970 struct lsa_String domain_name
;
2971 struct dom_sid2
*domain_sid
;
2972 struct lsa_String names
;
2973 struct samr_Ids rids
;
2974 struct samr_Ids types
;
2975 struct samr_Password old_lm_hash
;
2976 struct samr_Password new_lm_hash
;
2977 int errcode
= NERR_badpass
;
2981 struct dcerpc_binding_handle
*b
= NULL
;
2983 /* Skip 2 strings. */
2984 p
= skip_string(param
,tpscnt
,np
);
2985 p
= skip_string(param
,tpscnt
,p
);
2991 /* Do we have a string ? */
2992 if (skip_string(param
,tpscnt
,p
) == NULL
) {
2995 pull_ascii_fstring(user
,p
);
2997 p
= skip_string(param
,tpscnt
,p
);
3002 memset(pass1
,'\0',sizeof(pass1
));
3003 memset(pass2
,'\0',sizeof(pass2
));
3005 * We use 31 here not 32 as we're checking
3006 * the last byte we want to access is safe.
3008 if (!is_offset_safe(param
,tpscnt
,p
,31)) {
3012 memcpy(pass2
,p
+16,16);
3014 encrypted
= get_safe_SVAL(param
,tpscnt
,p
+32,0,-1);
3015 if (encrypted
== -1) {
3016 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3020 min_pwd_length
= get_safe_SVAL(param
,tpscnt
,p
+34,0,-1);
3021 if (min_pwd_length
== -1) {
3022 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3027 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3034 DEBUG(3,("Set password for <%s> (encrypted: %d, min_pwd_length: %d)\n",
3035 user
, encrypted
, min_pwd_length
));
3037 ZERO_STRUCT(connect_handle
);
3038 ZERO_STRUCT(domain_handle
);
3039 ZERO_STRUCT(user_handle
);
3041 status
= rpc_pipe_open_interface(mem_ctx
, &ndr_table_samr
,
3043 conn
->sconn
->remote_address
,
3044 conn
->sconn
->msg_ctx
,
3046 if (!NT_STATUS_IS_OK(status
)) {
3047 DEBUG(0,("api_SetUserPassword: could not connect to samr: %s\n",
3048 nt_errstr(status
)));
3049 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3053 b
= cli
->binding_handle
;
3055 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
3057 SAMR_ACCESS_CONNECT_TO_SERVER
|
3058 SAMR_ACCESS_ENUM_DOMAINS
|
3059 SAMR_ACCESS_LOOKUP_DOMAIN
,
3062 if (!NT_STATUS_IS_OK(status
)) {
3063 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3066 if (!NT_STATUS_IS_OK(result
)) {
3067 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3071 init_lsa_String(&domain_name
, get_global_sam_name());
3073 status
= dcerpc_samr_LookupDomain(b
, mem_ctx
,
3078 if (!NT_STATUS_IS_OK(status
)) {
3079 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3082 if (!NT_STATUS_IS_OK(result
)) {
3083 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3087 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3089 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
3093 if (!NT_STATUS_IS_OK(status
)) {
3094 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3097 if (!NT_STATUS_IS_OK(result
)) {
3098 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3102 init_lsa_String(&names
, user
);
3104 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3111 if (!NT_STATUS_IS_OK(status
)) {
3112 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3115 if (!NT_STATUS_IS_OK(result
)) {
3116 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3120 if (rids
.count
!= 1) {
3121 errcode
= W_ERROR_V(WERR_NO_SUCH_USER
);
3124 if (rids
.count
!= types
.count
) {
3125 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3128 if (types
.ids
[0] != SID_NAME_USER
) {
3129 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3135 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
3137 SAMR_USER_ACCESS_CHANGE_PASSWORD
,
3141 if (!NT_STATUS_IS_OK(status
)) {
3142 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3145 if (!NT_STATUS_IS_OK(result
)) {
3146 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3150 if (encrypted
== 0) {
3151 E_deshash(pass1
, old_lm_hash
.hash
);
3152 E_deshash(pass2
, new_lm_hash
.hash
);
3154 ZERO_STRUCT(old_lm_hash
);
3155 ZERO_STRUCT(new_lm_hash
);
3156 memcpy(old_lm_hash
.hash
, pass1
, MIN(strlen(pass1
), 16));
3157 memcpy(new_lm_hash
.hash
, pass2
, MIN(strlen(pass2
), 16));
3160 status
= dcerpc_samr_ChangePasswordUser(b
, mem_ctx
,
3162 true, /* lm_present */
3165 false, /* nt_present */
3166 NULL
, /* old_nt_crypted */
3167 NULL
, /* new_nt_crypted */
3168 false, /* cross1_present */
3169 NULL
, /* nt_cross */
3170 false, /* cross2_present */
3171 NULL
, /* lm_cross */
3173 if (!NT_STATUS_IS_OK(status
)) {
3174 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3177 if (!NT_STATUS_IS_OK(result
)) {
3178 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3182 errcode
= NERR_Success
;
3185 if (b
&& is_valid_policy_hnd(&user_handle
)) {
3186 dcerpc_samr_Close(b
, mem_ctx
, &user_handle
, &result
);
3188 if (b
&& is_valid_policy_hnd(&domain_handle
)) {
3189 dcerpc_samr_Close(b
, mem_ctx
, &domain_handle
, &result
);
3191 if (b
&& is_valid_policy_hnd(&connect_handle
)) {
3192 dcerpc_samr_Close(b
, mem_ctx
, &connect_handle
, &result
);
3195 memset((char *)pass1
,'\0',sizeof(fstring
));
3196 memset((char *)pass2
,'\0',sizeof(fstring
));
3198 SSVAL(*rparam
,0,errcode
);
3199 SSVAL(*rparam
,2,0); /* converter word */
3203 /****************************************************************************
3204 Set the user password (SamOEM version - gets plaintext).
3205 ****************************************************************************/
3207 static bool api_SamOEMChangePassword(struct smbd_server_connection
*sconn
,
3208 connection_struct
*conn
,uint64_t vuid
,
3209 char *param
, int tpscnt
,
3210 char *data
, int tdscnt
,
3211 int mdrcnt
,int mprcnt
,
3212 char **rdata
,char **rparam
,
3213 int *rdata_len
,int *rparam_len
)
3216 char *p
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3218 TALLOC_CTX
*mem_ctx
= talloc_tos();
3219 NTSTATUS status
, result
;
3220 struct rpc_pipe_client
*cli
= NULL
;
3221 struct lsa_AsciiString server
, account
;
3222 struct samr_CryptPassword password
;
3223 struct samr_Password hash
;
3224 int errcode
= NERR_badpass
;
3226 struct dcerpc_binding_handle
*b
;
3229 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3239 SSVAL(*rparam
,0,NERR_badpass
);
3242 * Check the parameter definition is correct.
3245 /* Do we have a string ? */
3246 if (skip_string(param
,tpscnt
,p
) == 0) {
3249 if(!strequal(p
, "zsT")) {
3250 DEBUG(0,("api_SamOEMChangePassword: Invalid parameter string %s\n", p
));
3253 p
= skip_string(param
, tpscnt
, p
);
3258 /* Do we have a string ? */
3259 if (skip_string(param
,tpscnt
,p
) == 0) {
3262 if(!strequal(p
, "B516B16")) {
3263 DEBUG(0,("api_SamOEMChangePassword: Invalid data parameter string %s\n", p
));
3266 p
= skip_string(param
,tpscnt
,p
);
3270 /* Do we have a string ? */
3271 if (skip_string(param
,tpscnt
,p
) == 0) {
3274 p
+= pull_ascii_fstring(user
,p
);
3276 DEBUG(3,("api_SamOEMChangePassword: Change password for <%s>\n",user
));
3278 if (tdscnt
!= 532) {
3279 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3283 bufsize
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3284 if (bufsize
!= 532) {
3285 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3289 memcpy(password
.data
, data
, 516);
3290 memcpy(hash
.hash
, data
+516, 16);
3292 status
= rpc_pipe_open_interface(mem_ctx
, &ndr_table_samr
,
3294 conn
->sconn
->remote_address
,
3295 conn
->sconn
->msg_ctx
,
3297 if (!NT_STATUS_IS_OK(status
)) {
3298 DEBUG(0,("api_SamOEMChangePassword: could not connect to samr: %s\n",
3299 nt_errstr(status
)));
3300 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3304 b
= cli
->binding_handle
;
3306 init_lsa_AsciiString(&server
, lp_netbios_name());
3307 init_lsa_AsciiString(&account
, user
);
3309 status
= dcerpc_samr_OemChangePasswordUser2(b
, mem_ctx
,
3315 if (!NT_STATUS_IS_OK(status
)) {
3316 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3319 if (!NT_STATUS_IS_OK(result
)) {
3320 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
3324 errcode
= NERR_Success
;
3326 SSVAL(*rparam
,0,errcode
);
3327 SSVAL(*rparam
,2,0); /* converter word */
3332 /****************************************************************************
3335 ****************************************************************************/
3337 static bool api_RDosPrintJobDel(struct smbd_server_connection
*sconn
,
3338 connection_struct
*conn
,uint64_t vuid
,
3339 char *param
, int tpscnt
,
3340 char *data
, int tdscnt
,
3341 int mdrcnt
,int mprcnt
,
3342 char **rdata
,char **rparam
,
3343 int *rdata_len
,int *rparam_len
)
3345 int function
= get_safe_SVAL(param
,tpscnt
,param
,0,0);
3346 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3347 char *str2
= skip_string(param
,tpscnt
,str1
);
3348 char *p
= skip_string(param
,tpscnt
,str2
);
3352 WERROR werr
= WERR_OK
;
3354 TALLOC_CTX
*mem_ctx
= talloc_tos();
3356 struct rpc_pipe_client
*cli
= NULL
;
3357 struct dcerpc_binding_handle
*b
= NULL
;
3358 struct policy_handle handle
;
3359 struct spoolss_DevmodeContainer devmode_ctr
;
3360 enum spoolss_JobControl command
;
3362 if (!str1
|| !str2
|| !p
) {
3366 * We use 1 here not 2 as we're checking
3367 * the last byte we want to access is safe.
3369 if (!is_offset_safe(param
,tpscnt
,p
,1)) {
3372 if(!rap_to_pjobid(SVAL(p
,0), sharename
, &jobid
))
3375 /* check it's a supported varient */
3376 if (!(strcsequal(str1
,"W") && strcsequal(str2
,"")))
3380 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3386 ZERO_STRUCT(handle
);
3388 status
= rpc_pipe_open_interface(conn
,
3391 conn
->sconn
->remote_address
,
3392 conn
->sconn
->msg_ctx
,
3394 if (!NT_STATUS_IS_OK(status
)) {
3395 DEBUG(0,("api_RDosPrintJobDel: could not connect to spoolss: %s\n",
3396 nt_errstr(status
)));
3397 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3400 b
= cli
->binding_handle
;
3402 ZERO_STRUCT(devmode_ctr
);
3404 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
3408 JOB_ACCESS_ADMINISTER
,
3411 if (!NT_STATUS_IS_OK(status
)) {
3412 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3415 if (!W_ERROR_IS_OK(werr
)) {
3416 errcode
= W_ERROR_V(werr
);
3420 /* FIXME: formerly NERR_JobNotFound was returned if job did not exist
3421 * and NERR_DestNotFound if share did not exist */
3423 errcode
= NERR_Success
;
3426 case 81: /* delete */
3427 command
= SPOOLSS_JOB_CONTROL_DELETE
;
3429 case 82: /* pause */
3430 command
= SPOOLSS_JOB_CONTROL_PAUSE
;
3432 case 83: /* resume */
3433 command
= SPOOLSS_JOB_CONTROL_RESUME
;
3436 errcode
= NERR_notsupported
;
3440 status
= dcerpc_spoolss_SetJob(b
, mem_ctx
,
3443 NULL
, /* unique ptr ctr */
3446 if (!NT_STATUS_IS_OK(status
)) {
3447 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3450 if (!W_ERROR_IS_OK(werr
)) {
3451 errcode
= W_ERROR_V(werr
);
3456 if (b
&& is_valid_policy_hnd(&handle
)) {
3457 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
3460 SSVAL(*rparam
,0,errcode
);
3461 SSVAL(*rparam
,2,0); /* converter word */
3466 /****************************************************************************
3467 Purge a print queue - or pause or resume it.
3468 ****************************************************************************/
3470 static bool api_WPrintQueueCtrl(struct smbd_server_connection
*sconn
,
3471 connection_struct
*conn
,uint64_t vuid
,
3472 char *param
, int tpscnt
,
3473 char *data
, int tdscnt
,
3474 int mdrcnt
,int mprcnt
,
3475 char **rdata
,char **rparam
,
3476 int *rdata_len
,int *rparam_len
)
3478 int function
= get_safe_SVAL(param
,tpscnt
,param
,0,0);
3479 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3480 char *str2
= skip_string(param
,tpscnt
,str1
);
3481 char *QueueName
= skip_string(param
,tpscnt
,str2
);
3482 int errcode
= NERR_notsupported
;
3483 WERROR werr
= WERR_OK
;
3486 TALLOC_CTX
*mem_ctx
= talloc_tos();
3487 struct rpc_pipe_client
*cli
= NULL
;
3488 struct dcerpc_binding_handle
*b
= NULL
;
3489 struct policy_handle handle
;
3490 struct spoolss_SetPrinterInfoCtr info_ctr
;
3491 struct spoolss_DevmodeContainer devmode_ctr
;
3492 struct sec_desc_buf secdesc_ctr
;
3493 enum spoolss_PrinterControl command
;
3495 if (!str1
|| !str2
|| !QueueName
) {
3499 /* check it's a supported varient */
3500 if (!(strcsequal(str1
,"z") && strcsequal(str2
,"")))
3504 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3510 if (skip_string(param
,tpscnt
,QueueName
) == NULL
) {
3514 ZERO_STRUCT(handle
);
3516 status
= rpc_pipe_open_interface(conn
,
3519 conn
->sconn
->remote_address
,
3520 conn
->sconn
->msg_ctx
,
3522 if (!NT_STATUS_IS_OK(status
)) {
3523 DEBUG(0,("api_WPrintQueueCtrl: could not connect to spoolss: %s\n",
3524 nt_errstr(status
)));
3525 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3528 b
= cli
->binding_handle
;
3530 ZERO_STRUCT(devmode_ctr
);
3532 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
3536 PRINTER_ACCESS_ADMINISTER
,
3539 if (!NT_STATUS_IS_OK(status
)) {
3540 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3543 if (!W_ERROR_IS_OK(werr
)) {
3544 errcode
= W_ERROR_V(werr
);
3549 case 74: /* Pause queue */
3550 command
= SPOOLSS_PRINTER_CONTROL_PAUSE
;
3552 case 75: /* Resume queue */
3553 command
= SPOOLSS_PRINTER_CONTROL_RESUME
;
3555 case 103: /* Purge */
3556 command
= SPOOLSS_PRINTER_CONTROL_PURGE
;
3559 werr
= WERR_NOT_SUPPORTED
;
3563 if (!W_ERROR_IS_OK(werr
)) {
3564 errcode
= W_ERROR_V(werr
);
3568 ZERO_STRUCT(info_ctr
);
3569 ZERO_STRUCT(secdesc_ctr
);
3571 status
= dcerpc_spoolss_SetPrinter(b
, mem_ctx
,
3578 if (!NT_STATUS_IS_OK(status
)) {
3579 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3582 if (!W_ERROR_IS_OK(werr
)) {
3583 errcode
= W_ERROR_V(werr
);
3587 errcode
= W_ERROR_V(werr
);
3591 if (b
&& is_valid_policy_hnd(&handle
)) {
3592 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
3595 SSVAL(*rparam
,0,errcode
);
3596 SSVAL(*rparam
,2,0); /* converter word */
3601 /****************************************************************************
3602 set the property of a print job (undocumented?)
3603 ? function = 0xb -> set name of print job
3604 ? function = 0x6 -> move print job up/down
3605 Form: <WWsTP> <WWzWWDDzzzzzzzzzzlz>
3606 or <WWsTP> <WB21BB16B10zWWzDDz>
3607 ****************************************************************************/
3609 static int check_printjob_info(struct pack_desc
* desc
,
3610 int uLevel
, char* id
)
3612 desc
->subformat
= NULL
;
3614 case 0: desc
->format
= "W"; break;
3615 case 1: desc
->format
= "WB21BB16B10zWWzDDz"; break;
3616 case 2: desc
->format
= "WWzWWDDzz"; break;
3617 case 3: desc
->format
= "WWzWWDDzzzzzzzzzzlz"; break;
3618 case 4: desc
->format
= "WWzWWDDzzzzzDDDDDDD"; break;
3620 DEBUG(0,("check_printjob_info: invalid level %d\n",
3624 if (id
== NULL
|| strcmp(desc
->format
,id
) != 0) {
3625 DEBUG(0,("check_printjob_info: invalid format %s\n",
3626 id
? id
: "<NULL>" ));
3632 static bool api_PrintJobInfo(struct smbd_server_connection
*sconn
,
3633 connection_struct
*conn
, uint64_t vuid
,
3634 char *param
, int tpscnt
,
3635 char *data
, int tdscnt
,
3636 int mdrcnt
,int mprcnt
,
3637 char **rdata
,char **rparam
,
3638 int *rdata_len
,int *rparam_len
)
3640 struct pack_desc desc
;
3641 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3642 char *str2
= skip_string(param
,tpscnt
,str1
);
3643 char *p
= skip_string(param
,tpscnt
,str2
);
3646 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,2,-1);
3647 int function
= get_safe_SVAL(param
,tpscnt
,p
,4,-1);
3650 TALLOC_CTX
*mem_ctx
= talloc_tos();
3653 struct rpc_pipe_client
*cli
= NULL
;
3654 struct dcerpc_binding_handle
*b
= NULL
;
3655 struct policy_handle handle
;
3656 struct spoolss_DevmodeContainer devmode_ctr
;
3657 struct spoolss_JobInfoContainer ctr
;
3658 union spoolss_JobInfo info
;
3659 struct spoolss_SetJobInfo1 info1
;
3661 if (!str1
|| !str2
|| !p
) {
3665 * We use 1 here not 2 as we're checking
3666 * the last byte we want to access is safe.
3668 if (!is_offset_safe(param
,tpscnt
,p
,1)) {
3671 if(!rap_to_pjobid(SVAL(p
,0), sharename
, &jobid
))
3674 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3681 /* check it's a supported varient */
3682 if ((strcmp(str1
,"WWsTP")) ||
3683 (!check_printjob_info(&desc
,uLevel
,str2
)))
3686 errcode
= NERR_notsupported
;
3690 /* change print job name, data gives the name */
3696 ZERO_STRUCT(handle
);
3698 status
= rpc_pipe_open_interface(conn
,
3701 conn
->sconn
->remote_address
,
3702 conn
->sconn
->msg_ctx
,
3704 if (!NT_STATUS_IS_OK(status
)) {
3705 DEBUG(0,("api_PrintJobInfo: could not connect to spoolss: %s\n",
3706 nt_errstr(status
)));
3707 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3710 b
= cli
->binding_handle
;
3712 ZERO_STRUCT(devmode_ctr
);
3714 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
3721 if (!NT_STATUS_IS_OK(status
)) {
3722 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3725 if (!W_ERROR_IS_OK(werr
)) {
3726 errcode
= W_ERROR_V(werr
);
3730 werr
= rpccli_spoolss_getjob(cli
, mem_ctx
,
3736 if (!W_ERROR_IS_OK(werr
)) {
3737 errcode
= W_ERROR_V(werr
);
3743 info1
.job_id
= info
.info1
.job_id
;
3744 info1
.printer_name
= info
.info1
.printer_name
;
3745 info1
.user_name
= info
.info1
.user_name
;
3746 info1
.document_name
= data
;
3747 info1
.data_type
= info
.info1
.data_type
;
3748 info1
.text_status
= info
.info1
.text_status
;
3749 info1
.status
= info
.info1
.status
;
3750 info1
.priority
= info
.info1
.priority
;
3751 info1
.position
= info
.info1
.position
;
3752 info1
.total_pages
= info
.info1
.total_pages
;
3753 info1
.pages_printed
= info
.info1
.pages_printed
;
3754 info1
.submitted
= info
.info1
.submitted
;
3757 ctr
.info
.info1
= &info1
;
3759 status
= dcerpc_spoolss_SetJob(b
, mem_ctx
,
3765 if (!NT_STATUS_IS_OK(status
)) {
3766 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3769 if (!W_ERROR_IS_OK(werr
)) {
3770 errcode
= W_ERROR_V(werr
);
3774 errcode
= NERR_Success
;
3777 if (b
&& is_valid_policy_hnd(&handle
)) {
3778 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
3781 SSVALS(*rparam
,0,errcode
);
3782 SSVAL(*rparam
,2,0); /* converter word */
3788 /****************************************************************************
3789 Get info about the server.
3790 ****************************************************************************/
3792 static bool api_RNetServerGetInfo(struct smbd_server_connection
*sconn
,
3793 connection_struct
*conn
,uint64_t vuid
,
3794 char *param
, int tpscnt
,
3795 char *data
, int tdscnt
,
3796 int mdrcnt
,int mprcnt
,
3797 char **rdata
,char **rparam
,
3798 int *rdata_len
,int *rparam_len
)
3800 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3801 char *str2
= skip_string(param
,tpscnt
,str1
);
3802 char *p
= skip_string(param
,tpscnt
,str2
);
3803 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3809 TALLOC_CTX
*mem_ctx
= talloc_tos();
3810 struct rpc_pipe_client
*cli
= NULL
;
3811 union srvsvc_NetSrvInfo info
;
3813 struct dcerpc_binding_handle
*b
;
3815 if (!str1
|| !str2
|| !p
) {
3819 DEBUG(4,("NetServerGetInfo level %d\n",uLevel
));
3821 /* check it's a supported varient */
3822 if (!prefix_ok(str1
,"WrLh")) {
3828 if (strcmp(str2
,"B16") != 0) {
3834 if (strcmp(str2
,"B16BBDz") != 0) {
3840 if (strcmp(str2
,"B16BBDzDDDWWzWWWWWWWBB21zWWWWWWWWWWWWWWWWWWWWWWz")!= 0) {
3846 if (strcmp(str2
,"B16BBDzDDDWWzWWWWWWWBB21zWWWWWWWWWWWWWWWWWWWWWWzDWz") != 0) {
3852 if (strcmp(str2
,"DN") != 0) {
3858 if (strcmp(str2
,"B16BBDzWWzzz") != 0) {
3867 *rdata_len
= mdrcnt
;
3868 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
3874 p2
= p
+ struct_len
;
3876 status
= rpc_pipe_open_interface(mem_ctx
, &ndr_table_srvsvc
,
3878 conn
->sconn
->remote_address
,
3879 conn
->sconn
->msg_ctx
,
3881 if (!NT_STATUS_IS_OK(status
)) {
3882 DEBUG(0,("api_RNetServerGetInfo: could not connect to srvsvc: %s\n",
3883 nt_errstr(status
)));
3884 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3888 b
= cli
->binding_handle
;
3890 status
= dcerpc_srvsvc_NetSrvGetInfo(b
, mem_ctx
,
3895 if (!NT_STATUS_IS_OK(status
)) {
3896 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
3899 if (!W_ERROR_IS_OK(werr
)) {
3900 errcode
= W_ERROR_V(werr
);
3904 if (info
.info101
== NULL
) {
3905 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
3910 srvstr_push(NULL
, 0, p
, info
.info101
->server_name
, 16,
3911 STR_ASCII
|STR_UPPER
|STR_TERMINATE
);
3915 SCVAL(p
,0,info
.info101
->version_major
);
3916 SCVAL(p
,1,info
.info101
->version_minor
);
3917 SIVAL(p
,2,info
.info101
->server_type
);
3919 if (mdrcnt
== struct_len
) {
3922 SIVAL(p
,6,PTR_DIFF(p2
,*rdata
));
3923 if (mdrcnt
- struct_len
<= 0) {
3927 info
.info101
->comment
,
3928 MIN(mdrcnt
- struct_len
,
3929 MAX_SERVER_STRING_LENGTH
),
3931 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3939 return False
; /* not yet implemented */
3942 errcode
= NERR_Success
;
3946 *rdata_len
= PTR_DIFF(p2
,*rdata
);
3949 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3953 SSVAL(*rparam
,0,errcode
);
3954 SSVAL(*rparam
,2,0); /* converter word */
3955 SSVAL(*rparam
,4,*rdata_len
);
3960 /****************************************************************************
3961 Get info about the server.
3962 ****************************************************************************/
3964 static bool api_NetWkstaGetInfo(struct smbd_server_connection
*sconn
,
3965 connection_struct
*conn
,uint64_t vuid
,
3966 char *param
, int tpscnt
,
3967 char *data
, int tdscnt
,
3968 int mdrcnt
,int mprcnt
,
3969 char **rdata
,char **rparam
,
3970 int *rdata_len
,int *rparam_len
)
3972 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3973 char *str2
= skip_string(param
,tpscnt
,str1
);
3974 char *p
= skip_string(param
,tpscnt
,str2
);
3977 int level
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3979 if (!str1
|| !str2
|| !p
) {
3983 DEBUG(4,("NetWkstaGetInfo level %d\n",level
));
3986 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3991 /* check it's a supported varient */
3992 if (!(level
==10 && strcsequal(str1
,"WrLh") && strcsequal(str2
,"zzzBBzz"))) {
3996 *rdata_len
= mdrcnt
+ 1024;
3997 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
4002 SSVAL(*rparam
,0,NERR_Success
);
4003 SSVAL(*rparam
,2,0); /* converter word */
4006 endp
= *rdata
+ *rdata_len
;
4008 p2
= get_safe_ptr(*rdata
,*rdata_len
,p
,22);
4013 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
)); /* host name */
4014 strlcpy(p2
,get_local_machine_name(),PTR_DIFF(endp
,p2
));
4015 if (!strupper_m(p2
)) {
4018 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4024 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
));
4025 strlcpy(p2
,conn
->session_info
->unix_info
->sanitized_username
,PTR_DIFF(endp
,p2
));
4026 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4032 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
)); /* login domain */
4033 strlcpy(p2
,lp_workgroup(),PTR_DIFF(endp
,p2
));
4034 if (!strupper_m(p2
)) {
4037 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4043 SCVAL(p
,0,SAMBA_MAJOR_NBT_ANNOUNCE_VERSION
); /* system version - e.g 4 in 4.1 */
4044 SCVAL(p
,1,SAMBA_MINOR_NBT_ANNOUNCE_VERSION
); /* system version - e.g .1 in 4.1 */
4047 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
));
4048 strlcpy(p2
,lp_workgroup(),PTR_DIFF(endp
,p2
)); /* don't know. login domain?? */
4049 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4055 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
)); /* don't know */
4056 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
4057 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4063 *rdata_len
= PTR_DIFF(p2
,*rdata
);
4065 SSVAL(*rparam
,4,*rdata_len
);
4070 /****************************************************************************
4071 get info about a user
4073 struct user_info_11 {
4074 char usri11_name[21]; 0-20
4076 char *usri11_comment; 22-25
4077 char *usri11_usr_comment; 26-29
4078 unsigned short usri11_priv; 30-31
4079 unsigned long usri11_auth_flags; 32-35
4080 long usri11_password_age; 36-39
4081 char *usri11_homedir; 40-43
4082 char *usri11_parms; 44-47
4083 long usri11_last_logon; 48-51
4084 long usri11_last_logoff; 52-55
4085 unsigned short usri11_bad_pw_count; 56-57
4086 unsigned short usri11_num_logons; 58-59
4087 char *usri11_logon_server; 60-63
4088 unsigned short usri11_country_code; 64-65
4089 char *usri11_workstations; 66-69
4090 unsigned long usri11_max_storage; 70-73
4091 unsigned short usri11_units_per_week; 74-75
4092 unsigned char *usri11_logon_hours; 76-79
4093 unsigned short usri11_code_page; 80-81
4098 usri11_name specifies the user name for which information is retrieved
4100 usri11_pad aligns the next data structure element to a word boundary
4102 usri11_comment is a null terminated ASCII comment
4104 usri11_user_comment is a null terminated ASCII comment about the user
4106 usri11_priv specifies the level of the privilege assigned to the user.
4107 The possible values are:
4109 Name Value Description
4110 USER_PRIV_GUEST 0 Guest privilege
4111 USER_PRIV_USER 1 User privilege
4112 USER_PRV_ADMIN 2 Administrator privilege
4114 usri11_auth_flags specifies the account operator privileges. The
4115 possible values are:
4117 Name Value Description
4118 AF_OP_PRINT 0 Print operator
4121 Leach, Naik [Page 28]
4125 INTERNET-DRAFT CIFS Remote Admin Protocol January 10, 1997
4128 AF_OP_COMM 1 Communications operator
4129 AF_OP_SERVER 2 Server operator
4130 AF_OP_ACCOUNTS 3 Accounts operator
4133 usri11_password_age specifies how many seconds have elapsed since the
4134 password was last changed.
4136 usri11_home_dir points to a null terminated ASCII string that contains
4137 the path name of the user's home directory.
4139 usri11_parms points to a null terminated ASCII string that is set
4140 aside for use by applications.
4142 usri11_last_logon specifies the time when the user last logged on.
4143 This value is stored as the number of seconds elapsed since
4144 00:00:00, January 1, 1970.
4146 usri11_last_logoff specifies the time when the user last logged off.
4147 This value is stored as the number of seconds elapsed since
4148 00:00:00, January 1, 1970. A value of 0 means the last logoff
4151 usri11_bad_pw_count specifies the number of incorrect passwords
4152 entered since the last successful logon.
4154 usri11_log1_num_logons specifies the number of times this user has
4155 logged on. A value of -1 means the number of logons is unknown.
4157 usri11_logon_server points to a null terminated ASCII string that
4158 contains the name of the server to which logon requests are sent.
4159 A null string indicates logon requests should be sent to the
4162 usri11_country_code specifies the country code for the user's language
4165 usri11_workstations points to a null terminated ASCII string that
4166 contains the names of workstations the user may log on from.
4167 There may be up to 8 workstations, with the names separated by
4168 commas. A null strings indicates there are no restrictions.
4170 usri11_max_storage specifies the maximum amount of disk space the user
4171 can occupy. A value of 0xffffffff indicates there are no
4174 usri11_units_per_week specifies the equal number of time units into
4175 which a week is divided. This value must be equal to 168.
4177 usri11_logon_hours points to a 21 byte (168 bits) string that
4178 specifies the time during which the user can log on. Each bit
4179 represents one unique hour in a week. The first bit (bit 0, word
4180 0) is Sunday, 0:00 to 0:59, the second bit (bit 1, word 0) is
4184 Leach, Naik [Page 29]
4188 INTERNET-DRAFT CIFS Remote Admin Protocol January 10, 1997
4191 Sunday, 1:00 to 1:59 and so on. A null pointer indicates there
4192 are no restrictions.
4194 usri11_code_page specifies the code page for the user's language of
4197 All of the pointers in this data structure need to be treated
4198 specially. The pointer is a 32 bit pointer. The higher 16 bits need
4199 to be ignored. The converter word returned in the parameters section
4200 needs to be subtracted from the lower 16 bits to calculate an offset
4201 into the return buffer where this ASCII string resides.
4203 There is no auxiliary data in the response.
4205 ****************************************************************************/
4207 #define usri11_name 0
4208 #define usri11_pad 21
4209 #define usri11_comment 22
4210 #define usri11_usr_comment 26
4211 #define usri11_full_name 30
4212 #define usri11_priv 34
4213 #define usri11_auth_flags 36
4214 #define usri11_password_age 40
4215 #define usri11_homedir 44
4216 #define usri11_parms 48
4217 #define usri11_last_logon 52
4218 #define usri11_last_logoff 56
4219 #define usri11_bad_pw_count 60
4220 #define usri11_num_logons 62
4221 #define usri11_logon_server 64
4222 #define usri11_country_code 68
4223 #define usri11_workstations 70
4224 #define usri11_max_storage 74
4225 #define usri11_units_per_week 78
4226 #define usri11_logon_hours 80
4227 #define usri11_code_page 84
4228 #define usri11_end 86
4230 static bool api_RNetUserGetInfo(struct smbd_server_connection
*sconn
,
4231 connection_struct
*conn
, uint64_t vuid
,
4232 char *param
, int tpscnt
,
4233 char *data
, int tdscnt
,
4234 int mdrcnt
,int mprcnt
,
4235 char **rdata
,char **rparam
,
4236 int *rdata_len
,int *rparam_len
)
4238 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4239 char *str2
= skip_string(param
,tpscnt
,str1
);
4240 char *UserName
= skip_string(param
,tpscnt
,str2
);
4241 char *p
= skip_string(param
,tpscnt
,UserName
);
4242 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4245 const char *level_string
;
4247 TALLOC_CTX
*mem_ctx
= talloc_tos();
4248 NTSTATUS status
, result
;
4249 struct rpc_pipe_client
*cli
= NULL
;
4250 struct policy_handle connect_handle
, domain_handle
, user_handle
;
4251 struct lsa_String domain_name
;
4252 struct dom_sid2
*domain_sid
;
4253 struct lsa_String names
;
4254 struct samr_Ids rids
;
4255 struct samr_Ids types
;
4256 int errcode
= W_ERROR_V(WERR_USER_NOT_FOUND
);
4258 union samr_UserInfo
*info
;
4259 struct dcerpc_binding_handle
*b
= NULL
;
4261 if (!str1
|| !str2
|| !UserName
|| !p
) {
4266 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4271 DEBUG(4,("RNetUserGetInfo level=%d\n", uLevel
));
4273 /* check it's a supported variant */
4274 if (strcmp(str1
,"zWrLh") != 0) {
4278 case 0: level_string
= "B21"; break;
4279 case 1: level_string
= "B21BB16DWzzWz"; break;
4280 case 2: level_string
= "B21BB16DWzzWzDzzzzDDDDWb21WWzWW"; break;
4281 case 10: level_string
= "B21Bzzz"; break;
4282 case 11: level_string
= "B21BzzzWDDzzDDWWzWzDWb21W"; break;
4283 default: return False
;
4286 if (strcmp(level_string
,str2
) != 0) {
4290 *rdata_len
= mdrcnt
+ 1024;
4291 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
4297 endp
= *rdata
+ *rdata_len
;
4298 p2
= get_safe_ptr(*rdata
,*rdata_len
,p
,usri11_end
);
4303 ZERO_STRUCT(connect_handle
);
4304 ZERO_STRUCT(domain_handle
);
4305 ZERO_STRUCT(user_handle
);
4307 status
= rpc_pipe_open_interface(mem_ctx
, &ndr_table_samr
,
4309 conn
->sconn
->remote_address
,
4310 conn
->sconn
->msg_ctx
,
4312 if (!NT_STATUS_IS_OK(status
)) {
4313 DEBUG(0,("api_RNetUserGetInfo: could not connect to samr: %s\n",
4314 nt_errstr(status
)));
4315 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4319 b
= cli
->binding_handle
;
4321 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
4323 SAMR_ACCESS_CONNECT_TO_SERVER
|
4324 SAMR_ACCESS_ENUM_DOMAINS
|
4325 SAMR_ACCESS_LOOKUP_DOMAIN
,
4328 if (!NT_STATUS_IS_OK(status
)) {
4329 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4332 if (!NT_STATUS_IS_OK(result
)) {
4333 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
4337 init_lsa_String(&domain_name
, get_global_sam_name());
4339 status
= dcerpc_samr_LookupDomain(b
, mem_ctx
,
4344 if (!NT_STATUS_IS_OK(status
)) {
4345 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4348 if (!NT_STATUS_IS_OK(result
)) {
4349 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
4353 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
4355 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
4359 if (!NT_STATUS_IS_OK(status
)) {
4360 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4363 if (!NT_STATUS_IS_OK(result
)) {
4364 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
4368 init_lsa_String(&names
, UserName
);
4370 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
4377 if (!NT_STATUS_IS_OK(status
)) {
4378 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4381 if (!NT_STATUS_IS_OK(result
)) {
4382 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
4386 if (rids
.count
!= 1) {
4387 errcode
= W_ERROR_V(WERR_NO_SUCH_USER
);
4390 if (rids
.count
!= types
.count
) {
4391 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
4394 if (types
.ids
[0] != SID_NAME_USER
) {
4395 errcode
= W_ERROR_V(WERR_INVALID_PARAM
);
4401 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
4403 SAMR_USER_ACCESS_GET_LOCALE
|
4404 SAMR_USER_ACCESS_GET_LOGONINFO
|
4405 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
4406 SAMR_USER_ACCESS_GET_GROUPS
|
4407 SAMR_USER_ACCESS_GET_GROUP_MEMBERSHIP
|
4408 SEC_STD_READ_CONTROL
,
4412 if (!NT_STATUS_IS_OK(status
)) {
4413 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4416 if (!NT_STATUS_IS_OK(result
)) {
4417 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
4421 status
= dcerpc_samr_QueryUserInfo2(b
, mem_ctx
,
4426 if (!NT_STATUS_IS_OK(status
)) {
4427 errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4430 if (!NT_STATUS_IS_OK(result
)) {
4431 errcode
= W_ERROR_V(ntstatus_to_werror(result
));
4436 fstrcpy(p
+usri11_name
,UserName
); /* 21 bytes - user name */
4439 SCVAL(p
,usri11_pad
,0); /* padding - 1 byte */
4444 SIVAL(p
,usri11_comment
,PTR_DIFF(p2
,p
)); /* comment */
4445 strlcpy(p2
,"Comment",PTR_DIFF(endp
,p2
));
4446 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4451 SIVAL(p
,usri11_usr_comment
,PTR_DIFF(p2
,p
)); /* user_comment */
4452 strlcpy(p2
,"UserComment",PTR_DIFF(endp
,p2
));
4453 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4458 /* EEK! the cifsrap.txt doesn't have this in!!!! */
4459 SIVAL(p
,usri11_full_name
,PTR_DIFF(p2
,p
)); /* full name */
4460 strlcpy(p2
,info
->info21
.full_name
.string
,PTR_DIFF(endp
,p2
));
4461 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4468 const char *homedir
= info
->info21
.home_directory
.string
;
4469 /* modelled after NTAS 3.51 reply */
4470 SSVAL(p
,usri11_priv
,
4471 (get_current_uid(conn
) == sec_initial_uid())?
4472 USER_PRIV_ADMIN
:USER_PRIV_USER
);
4473 SIVAL(p
,usri11_auth_flags
,AF_OP_PRINT
); /* auth flags */
4474 SIVALS(p
,usri11_password_age
,-1); /* password age */
4475 SIVAL(p
,usri11_homedir
,PTR_DIFF(p2
,p
)); /* home dir */
4476 strlcpy(p2
, homedir
, PTR_DIFF(endp
,p2
));
4477 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4481 SIVAL(p
,usri11_parms
,PTR_DIFF(p2
,p
)); /* parms */
4482 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
4483 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4487 SIVAL(p
,usri11_last_logon
,0); /* last logon */
4488 SIVAL(p
,usri11_last_logoff
,0); /* last logoff */
4489 SSVALS(p
,usri11_bad_pw_count
,-1); /* bad pw counts */
4490 SSVALS(p
,usri11_num_logons
,-1); /* num logons */
4491 SIVAL(p
,usri11_logon_server
,PTR_DIFF(p2
,p
)); /* logon server */
4492 strlcpy(p2
,"\\\\*",PTR_DIFF(endp
,p2
));
4493 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4497 SSVAL(p
,usri11_country_code
,0); /* country code */
4499 SIVAL(p
,usri11_workstations
,PTR_DIFF(p2
,p
)); /* workstations */
4500 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
4501 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4506 SIVALS(p
,usri11_max_storage
,-1); /* max storage */
4507 SSVAL(p
,usri11_units_per_week
,168); /* units per week */
4508 SIVAL(p
,usri11_logon_hours
,PTR_DIFF(p2
,p
)); /* logon hours */
4510 /* a simple way to get logon hours at all times. */
4512 SCVAL(p2
,21,0); /* fix zero termination */
4513 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4518 SSVAL(p
,usri11_code_page
,0); /* code page */
4521 if (uLevel
== 1 || uLevel
== 2) {
4522 memset(p
+22,' ',16); /* password */
4523 SIVALS(p
,38,-1); /* password age */
4525 (get_current_uid(conn
) == sec_initial_uid())?
4526 USER_PRIV_ADMIN
:USER_PRIV_USER
);
4527 SIVAL(p
,44,PTR_DIFF(p2
,*rdata
)); /* home dir */
4528 strlcpy(p2
, info
->info21
.home_directory
.string
,
4530 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4534 SIVAL(p
,48,PTR_DIFF(p2
,*rdata
)); /* comment */
4536 SSVAL(p
,52,0); /* flags */
4537 SIVAL(p
,54,PTR_DIFF(p2
,*rdata
)); /* script_path */
4538 strlcpy(p2
, info
->info21
.logon_script
.string
,
4540 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4545 SIVAL(p
,58,0); /* auth_flags */
4546 SIVAL(p
,62,PTR_DIFF(p2
,*rdata
)); /* full_name */
4547 strlcpy(p2
,info
->info21
.full_name
.string
,PTR_DIFF(endp
,p2
));
4548 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4552 SIVAL(p
,66,0); /* urs_comment */
4553 SIVAL(p
,70,PTR_DIFF(p2
,*rdata
)); /* parms */
4554 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
4555 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4559 SIVAL(p
,74,0); /* workstations */
4560 SIVAL(p
,78,0); /* last_logon */
4561 SIVAL(p
,82,0); /* last_logoff */
4562 SIVALS(p
,86,-1); /* acct_expires */
4563 SIVALS(p
,90,-1); /* max_storage */
4564 SSVAL(p
,94,168); /* units_per_week */
4565 SIVAL(p
,96,PTR_DIFF(p2
,*rdata
)); /* logon_hours */
4568 SSVALS(p
,100,-1); /* bad_pw_count */
4569 SSVALS(p
,102,-1); /* num_logons */
4570 SIVAL(p
,104,PTR_DIFF(p2
,*rdata
)); /* logon_server */
4572 TALLOC_CTX
*ctx
= talloc_tos();
4573 int space_rem
= *rdata_len
- (p2
- *rdata
);
4576 if (space_rem
<= 0) {
4579 tmp
= talloc_strdup(ctx
, "\\\\%L");
4583 tmp
= talloc_sub_basic(ctx
,
4596 p2
= skip_string(*rdata
,*rdata_len
,p2
);
4600 SSVAL(p
,108,49); /* country_code */
4601 SSVAL(p
,110,860); /* code page */
4605 errcode
= NERR_Success
;
4608 *rdata_len
= PTR_DIFF(p2
,*rdata
);
4610 if (b
&& is_valid_policy_hnd(&user_handle
)) {
4611 dcerpc_samr_Close(b
, mem_ctx
, &user_handle
, &result
);
4613 if (b
&& is_valid_policy_hnd(&domain_handle
)) {
4614 dcerpc_samr_Close(b
, mem_ctx
, &domain_handle
, &result
);
4616 if (b
&& is_valid_policy_hnd(&connect_handle
)) {
4617 dcerpc_samr_Close(b
, mem_ctx
, &connect_handle
, &result
);
4620 SSVAL(*rparam
,0,errcode
);
4621 SSVAL(*rparam
,2,0); /* converter word */
4622 SSVAL(*rparam
,4,*rdata_len
); /* is this right?? */
4627 static bool api_WWkstaUserLogon(struct smbd_server_connection
*sconn
,
4628 connection_struct
*conn
,uint64_t vuid
,
4629 char *param
, int tpscnt
,
4630 char *data
, int tdscnt
,
4631 int mdrcnt
,int mprcnt
,
4632 char **rdata
,char **rparam
,
4633 int *rdata_len
,int *rparam_len
)
4635 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4636 char *str2
= skip_string(param
,tpscnt
,str1
);
4637 char *p
= skip_string(param
,tpscnt
,str2
);
4639 struct pack_desc desc
;
4641 /* With share level security vuid will always be zero.
4642 Don't depend on vuser being non-null !!. JRA */
4643 struct user_struct
*vuser
= get_valid_user_struct(sconn
, vuid
);
4645 if (!str1
|| !str2
|| !p
) {
4650 DEBUG(3,(" Username of UID %d is %s\n",
4651 (int)vuser
->session_info
->unix_token
->uid
,
4652 vuser
->session_info
->unix_info
->unix_name
));
4655 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4656 name
= get_safe_str_ptr(param
,tpscnt
,p
,2);
4661 memset((char *)&desc
,'\0',sizeof(desc
));
4663 DEBUG(3,("WWkstaUserLogon uLevel=%d name=%s\n",uLevel
,name
));
4665 /* check it's a supported varient */
4666 if (strcmp(str1
,"OOWb54WrLh") != 0) {
4669 if (uLevel
!= 1 || strcmp(str2
,"WB21BWDWWDDDDDDDzzzD") != 0) {
4673 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4680 desc
.buflen
= mdrcnt
;
4681 desc
.subformat
= NULL
;
4684 if (init_package(&desc
,1,0)) {
4685 PACKI(&desc
,"W",0); /* code */
4686 PACKS(&desc
,"B21",name
); /* eff. name */
4687 PACKS(&desc
,"B",""); /* pad */
4689 (get_current_uid(conn
) == sec_initial_uid())?
4690 USER_PRIV_ADMIN
:USER_PRIV_USER
);
4691 PACKI(&desc
,"D",0); /* auth flags XXX */
4692 PACKI(&desc
,"W",0); /* num logons */
4693 PACKI(&desc
,"W",0); /* bad pw count */
4694 PACKI(&desc
,"D",0); /* last logon */
4695 PACKI(&desc
,"D",-1); /* last logoff */
4696 PACKI(&desc
,"D",-1); /* logoff time */
4697 PACKI(&desc
,"D",-1); /* kickoff time */
4698 PACKI(&desc
,"D",0); /* password age */
4699 PACKI(&desc
,"D",0); /* password can change */
4700 PACKI(&desc
,"D",-1); /* password must change */
4704 fstrcpy(mypath
,"\\\\");
4705 fstrcat(mypath
,get_local_machine_name());
4706 if (!strupper_m(mypath
)) {
4709 PACKS(&desc
,"z",mypath
); /* computer */
4712 PACKS(&desc
,"z",lp_workgroup());/* domain */
4713 PACKS(&desc
,"z", vuser
?
4714 vuser
->session_info
->info
->logon_script
4715 : ""); /* script path */
4716 PACKI(&desc
,"D",0x00000000); /* reserved */
4719 *rdata_len
= desc
.usedlen
;
4721 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4725 SSVALS(*rparam
,0,desc
.errcode
);
4727 SSVAL(*rparam
,4,desc
.neededlen
);
4729 DEBUG(4,("WWkstaUserLogon: errorcode %d\n",desc
.errcode
));
4734 /****************************************************************************
4735 api_WAccessGetUserPerms
4736 ****************************************************************************/
4738 static bool api_WAccessGetUserPerms(struct smbd_server_connection
*sconn
,
4739 connection_struct
*conn
,uint64_t vuid
,
4740 char *param
, int tpscnt
,
4741 char *data
, int tdscnt
,
4742 int mdrcnt
,int mprcnt
,
4743 char **rdata
,char **rparam
,
4744 int *rdata_len
,int *rparam_len
)
4746 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4747 char *str2
= skip_string(param
,tpscnt
,str1
);
4748 char *user
= skip_string(param
,tpscnt
,str2
);
4749 char *resource
= skip_string(param
,tpscnt
,user
);
4751 if (!str1
|| !str2
|| !user
|| !resource
) {
4755 if (skip_string(param
,tpscnt
,resource
) == NULL
) {
4758 DEBUG(3,("WAccessGetUserPerms user=%s resource=%s\n",user
,resource
));
4760 /* check it's a supported varient */
4761 if (strcmp(str1
,"zzh") != 0) {
4764 if (strcmp(str2
,"") != 0) {
4769 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4773 SSVALS(*rparam
,0,0); /* errorcode */
4774 SSVAL(*rparam
,2,0); /* converter word */
4775 SSVAL(*rparam
,4,0x7f); /* permission flags */
4780 /****************************************************************************
4781 api_WPrintJobEnumerate
4782 ****************************************************************************/
4784 static bool api_WPrintJobGetInfo(struct smbd_server_connection
*sconn
,
4785 connection_struct
*conn
, uint64_t vuid
,
4786 char *param
, int tpscnt
,
4787 char *data
, int tdscnt
,
4788 int mdrcnt
,int mprcnt
,
4789 char **rdata
,char **rparam
,
4790 int *rdata_len
,int *rparam_len
)
4792 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4793 char *str2
= skip_string(param
,tpscnt
,str1
);
4794 char *p
= skip_string(param
,tpscnt
,str2
);
4798 struct pack_desc desc
;
4801 TALLOC_CTX
*mem_ctx
= talloc_tos();
4804 struct rpc_pipe_client
*cli
= NULL
;
4805 struct dcerpc_binding_handle
*b
= NULL
;
4806 struct policy_handle handle
;
4807 struct spoolss_DevmodeContainer devmode_ctr
;
4808 union spoolss_JobInfo info
;
4810 if (!str1
|| !str2
|| !p
) {
4814 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,2,-1);
4816 memset((char *)&desc
,'\0',sizeof(desc
));
4817 memset((char *)&status
,'\0',sizeof(status
));
4819 DEBUG(3,("WPrintJobGetInfo uLevel=%d uJobId=0x%X\n",uLevel
,SVAL(p
,0)));
4821 /* check it's a supported varient */
4822 if (strcmp(str1
,"WWrLh") != 0) {
4825 if (!check_printjob_info(&desc
,uLevel
,str2
)) {
4829 if(!rap_to_pjobid(SVAL(p
,0), sharename
, &jobid
)) {
4833 ZERO_STRUCT(handle
);
4835 status
= rpc_pipe_open_interface(conn
,
4838 conn
->sconn
->remote_address
,
4839 conn
->sconn
->msg_ctx
,
4841 if (!NT_STATUS_IS_OK(status
)) {
4842 DEBUG(0,("api_WPrintJobGetInfo: could not connect to spoolss: %s\n",
4843 nt_errstr(status
)));
4844 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4847 b
= cli
->binding_handle
;
4849 ZERO_STRUCT(devmode_ctr
);
4851 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
4858 if (!NT_STATUS_IS_OK(status
)) {
4859 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4862 if (!W_ERROR_IS_OK(werr
)) {
4863 desc
.errcode
= W_ERROR_V(werr
);
4867 werr
= rpccli_spoolss_getjob(cli
, mem_ctx
,
4873 if (!W_ERROR_IS_OK(werr
)) {
4874 desc
.errcode
= W_ERROR_V(werr
);
4879 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4884 desc
.buflen
= mdrcnt
;
4887 * Don't return data but need to get correct length
4888 * init_package will return wrong size if buflen=0
4890 desc
.buflen
= getlen(desc
.format
);
4891 desc
.base
= tmpdata
= (char *)SMB_MALLOC( desc
.buflen
);
4894 if (init_package(&desc
,1,0)) {
4895 fill_spoolss_printjob_info(uLevel
, &desc
, &info
.info2
, info
.info2
.position
);
4896 *rdata_len
= desc
.usedlen
;
4898 desc
.errcode
= NERR_JobNotFound
;
4902 if (b
&& is_valid_policy_hnd(&handle
)) {
4903 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
4907 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4911 SSVALS(*rparam
,0,desc
.errcode
);
4913 SSVAL(*rparam
,4,desc
.neededlen
);
4917 DEBUG(4,("WPrintJobGetInfo: errorcode %d\n",desc
.errcode
));
4922 static bool api_WPrintJobEnumerate(struct smbd_server_connection
*sconn
,
4923 connection_struct
*conn
, uint64_t vuid
,
4924 char *param
, int tpscnt
,
4925 char *data
, int tdscnt
,
4926 int mdrcnt
,int mprcnt
,
4927 char **rdata
,char **rparam
,
4928 int *rdata_len
,int *rparam_len
)
4930 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4931 char *str2
= skip_string(param
,tpscnt
,str1
);
4932 char *p
= skip_string(param
,tpscnt
,str2
);
4936 struct pack_desc desc
;
4938 TALLOC_CTX
*mem_ctx
= talloc_tos();
4941 struct rpc_pipe_client
*cli
= NULL
;
4942 struct dcerpc_binding_handle
*b
= NULL
;
4943 struct policy_handle handle
;
4944 struct spoolss_DevmodeContainer devmode_ctr
;
4946 union spoolss_JobInfo
*info
;
4948 if (!str1
|| !str2
|| !p
) {
4952 memset((char *)&desc
,'\0',sizeof(desc
));
4954 p
= skip_string(param
,tpscnt
,p
);
4958 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4960 DEBUG(3,("WPrintJobEnumerate uLevel=%d name=%s\n",uLevel
,name
));
4962 /* check it's a supported variant */
4963 if (strcmp(str1
,"zWrLeh") != 0) {
4968 return False
; /* defined only for uLevel 0,1,2 */
4971 if (!check_printjob_info(&desc
,uLevel
,str2
)) {
4975 ZERO_STRUCT(handle
);
4977 status
= rpc_pipe_open_interface(conn
,
4980 conn
->sconn
->remote_address
,
4981 conn
->sconn
->msg_ctx
,
4983 if (!NT_STATUS_IS_OK(status
)) {
4984 DEBUG(0,("api_WPrintJobEnumerate: could not connect to spoolss: %s\n",
4985 nt_errstr(status
)));
4986 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
4989 b
= cli
->binding_handle
;
4991 ZERO_STRUCT(devmode_ctr
);
4993 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
5000 if (!NT_STATUS_IS_OK(status
)) {
5001 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
5004 if (!W_ERROR_IS_OK(werr
)) {
5005 desc
.errcode
= W_ERROR_V(werr
);
5009 werr
= rpccli_spoolss_enumjobs(cli
, mem_ctx
,
5017 if (!W_ERROR_IS_OK(werr
)) {
5018 desc
.errcode
= W_ERROR_V(werr
);
5023 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5029 desc
.buflen
= mdrcnt
;
5031 if (init_package(&desc
,count
,0)) {
5033 for (i
= 0; i
< count
; i
++) {
5034 fill_spoolss_printjob_info(uLevel
, &desc
, &info
[i
].info2
, i
);
5035 if (desc
.errcode
== NERR_Success
) {
5041 if (b
&& is_valid_policy_hnd(&handle
)) {
5042 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
5045 *rdata_len
= desc
.usedlen
;
5048 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5052 SSVALS(*rparam
,0,desc
.errcode
);
5054 SSVAL(*rparam
,4,succnt
);
5055 SSVAL(*rparam
,6,count
);
5057 DEBUG(4,("WPrintJobEnumerate: errorcode %d\n",desc
.errcode
));
5062 static int check_printdest_info(struct pack_desc
* desc
,
5063 int uLevel
, char* id
)
5065 desc
->subformat
= NULL
;
5068 desc
->format
= "B9";
5071 desc
->format
= "B9B21WWzW";
5077 desc
->format
= "zzzWWzzzWW";
5080 DEBUG(0,("check_printdest_info: invalid level %d\n",
5084 if (id
== NULL
|| strcmp(desc
->format
,id
) != 0) {
5085 DEBUG(0,("check_printdest_info: invalid string %s\n",
5086 id
? id
: "<NULL>" ));
5092 static void fill_printdest_info(struct spoolss_PrinterInfo2
*info2
, int uLevel
,
5093 struct pack_desc
* desc
)
5097 strncpy(buf
, info2
->printername
, sizeof(buf
)-1);
5098 buf
[sizeof(buf
)-1] = 0;
5099 (void)strupper_m(buf
);
5102 PACKS(desc
,"B9",buf
); /* szName */
5104 PACKS(desc
,"B21",""); /* szUserName */
5105 PACKI(desc
,"W",0); /* uJobId */
5106 PACKI(desc
,"W",0); /* fsStatus */
5107 PACKS(desc
,"z",""); /* pszStatus */
5108 PACKI(desc
,"W",0); /* time */
5112 if (uLevel
== 2 || uLevel
== 3) {
5113 PACKS(desc
,"z",buf
); /* pszPrinterName */
5115 PACKS(desc
,"z",""); /* pszUserName */
5116 PACKS(desc
,"z",""); /* pszLogAddr */
5117 PACKI(desc
,"W",0); /* uJobId */
5118 PACKI(desc
,"W",0); /* fsStatus */
5119 PACKS(desc
,"z",""); /* pszStatus */
5120 PACKS(desc
,"z",""); /* pszComment */
5121 PACKS(desc
,"z","NULL"); /* pszDrivers */
5122 PACKI(desc
,"W",0); /* time */
5123 PACKI(desc
,"W",0); /* pad1 */
5128 static bool api_WPrintDestGetInfo(struct smbd_server_connection
*sconn
,
5129 connection_struct
*conn
, uint64_t vuid
,
5130 char *param
, int tpscnt
,
5131 char *data
, int tdscnt
,
5132 int mdrcnt
,int mprcnt
,
5133 char **rdata
,char **rparam
,
5134 int *rdata_len
,int *rparam_len
)
5136 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
5137 char *str2
= skip_string(param
,tpscnt
,str1
);
5138 char *p
= skip_string(param
,tpscnt
,str2
);
5139 char* PrinterName
= p
;
5141 struct pack_desc desc
;
5144 TALLOC_CTX
*mem_ctx
= talloc_tos();
5147 struct rpc_pipe_client
*cli
= NULL
;
5148 struct dcerpc_binding_handle
*b
= NULL
;
5149 struct policy_handle handle
;
5150 struct spoolss_DevmodeContainer devmode_ctr
;
5151 union spoolss_PrinterInfo info
;
5153 if (!str1
|| !str2
|| !p
) {
5157 memset((char *)&desc
,'\0',sizeof(desc
));
5159 p
= skip_string(param
,tpscnt
,p
);
5163 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
5165 DEBUG(3,("WPrintDestGetInfo uLevel=%d PrinterName=%s\n",uLevel
,PrinterName
));
5167 /* check it's a supported varient */
5168 if (strcmp(str1
,"zWrLh") != 0) {
5171 if (!check_printdest_info(&desc
,uLevel
,str2
)) {
5175 ZERO_STRUCT(handle
);
5177 status
= rpc_pipe_open_interface(conn
,
5180 conn
->sconn
->remote_address
,
5181 conn
->sconn
->msg_ctx
,
5183 if (!NT_STATUS_IS_OK(status
)) {
5184 DEBUG(0,("api_WPrintDestGetInfo: could not connect to spoolss: %s\n",
5185 nt_errstr(status
)));
5186 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
5189 b
= cli
->binding_handle
;
5191 ZERO_STRUCT(devmode_ctr
);
5193 status
= dcerpc_spoolss_OpenPrinter(b
, mem_ctx
,
5200 if (!NT_STATUS_IS_OK(status
)) {
5202 desc
.errcode
= NERR_DestNotFound
;
5206 if (!W_ERROR_IS_OK(werr
)) {
5208 desc
.errcode
= NERR_DestNotFound
;
5213 werr
= rpccli_spoolss_getprinter(cli
, mem_ctx
,
5218 if (!W_ERROR_IS_OK(werr
)) {
5220 desc
.errcode
= NERR_DestNotFound
;
5226 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5231 desc
.buflen
= mdrcnt
;
5234 * Don't return data but need to get correct length
5235 * init_package will return wrong size if buflen=0
5237 desc
.buflen
= getlen(desc
.format
);
5238 desc
.base
= tmpdata
= (char *)SMB_MALLOC( desc
.buflen
);
5240 if (init_package(&desc
,1,0)) {
5241 fill_printdest_info(&info
.info2
, uLevel
,&desc
);
5245 if (b
&& is_valid_policy_hnd(&handle
)) {
5246 dcerpc_spoolss_ClosePrinter(b
, mem_ctx
, &handle
, &werr
);
5249 *rdata_len
= desc
.usedlen
;
5252 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5256 SSVALS(*rparam
,0,desc
.errcode
);
5258 SSVAL(*rparam
,4,desc
.neededlen
);
5260 DEBUG(4,("WPrintDestGetInfo: errorcode %d\n",desc
.errcode
));
5266 static bool api_WPrintDestEnum(struct smbd_server_connection
*sconn
,
5267 connection_struct
*conn
, uint64_t vuid
,
5268 char *param
, int tpscnt
,
5269 char *data
, int tdscnt
,
5270 int mdrcnt
,int mprcnt
,
5271 char **rdata
,char **rparam
,
5272 int *rdata_len
,int *rparam_len
)
5274 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
5275 char *str2
= skip_string(param
,tpscnt
,str1
);
5276 char *p
= skip_string(param
,tpscnt
,str2
);
5280 struct pack_desc desc
;
5282 TALLOC_CTX
*mem_ctx
= talloc_tos();
5285 struct rpc_pipe_client
*cli
= NULL
;
5286 union spoolss_PrinterInfo
*info
;
5289 if (!str1
|| !str2
|| !p
) {
5293 memset((char *)&desc
,'\0',sizeof(desc
));
5295 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
5297 DEBUG(3,("WPrintDestEnum uLevel=%d\n",uLevel
));
5299 /* check it's a supported varient */
5300 if (strcmp(str1
,"WrLeh") != 0) {
5303 if (!check_printdest_info(&desc
,uLevel
,str2
)) {
5309 status
= rpc_pipe_open_interface(conn
,
5312 conn
->sconn
->remote_address
,
5313 conn
->sconn
->msg_ctx
,
5315 if (!NT_STATUS_IS_OK(status
)) {
5316 DEBUG(0,("api_WPrintDestEnum: could not connect to spoolss: %s\n",
5317 nt_errstr(status
)));
5318 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
5322 werr
= rpccli_spoolss_enumprinters(cli
, mem_ctx
,
5324 cli
->srv_name_slash
,
5329 if (!W_ERROR_IS_OK(werr
)) {
5330 desc
.errcode
= W_ERROR_V(werr
);
5332 desc
.errcode
= NERR_DestNotFound
;
5340 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5347 desc
.buflen
= mdrcnt
;
5348 if (init_package(&desc
,queuecnt
,0)) {
5351 for (i
= 0; i
< count
; i
++) {
5352 fill_printdest_info(&info
[i
].info2
, uLevel
,&desc
);
5354 if (desc
.errcode
== NERR_Success
) {
5360 *rdata_len
= desc
.usedlen
;
5363 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5367 SSVALS(*rparam
,0,desc
.errcode
);
5369 SSVAL(*rparam
,4,succnt
);
5370 SSVAL(*rparam
,6,queuecnt
);
5372 DEBUG(4,("WPrintDestEnumerate: errorcode %d\n",desc
.errcode
));
5377 static bool api_WPrintDriverEnum(struct smbd_server_connection
*sconn
,
5378 connection_struct
*conn
, uint64_t vuid
,
5379 char *param
, int tpscnt
,
5380 char *data
, int tdscnt
,
5381 int mdrcnt
,int mprcnt
,
5382 char **rdata
,char **rparam
,
5383 int *rdata_len
,int *rparam_len
)
5385 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
5386 char *str2
= skip_string(param
,tpscnt
,str1
);
5387 char *p
= skip_string(param
,tpscnt
,str2
);
5390 struct pack_desc desc
;
5392 if (!str1
|| !str2
|| !p
) {
5396 memset((char *)&desc
,'\0',sizeof(desc
));
5398 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
5400 DEBUG(3,("WPrintDriverEnum uLevel=%d\n",uLevel
));
5402 /* check it's a supported varient */
5403 if (strcmp(str1
,"WrLeh") != 0) {
5406 if (uLevel
!= 0 || strcmp(str2
,"B41") != 0) {
5411 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5417 desc
.buflen
= mdrcnt
;
5418 if (init_package(&desc
,1,0)) {
5419 PACKS(&desc
,"B41","NULL");
5422 succnt
= (desc
.errcode
== NERR_Success
? 1 : 0);
5424 *rdata_len
= desc
.usedlen
;
5427 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5431 SSVALS(*rparam
,0,desc
.errcode
);
5433 SSVAL(*rparam
,4,succnt
);
5436 DEBUG(4,("WPrintDriverEnum: errorcode %d\n",desc
.errcode
));
5441 static bool api_WPrintQProcEnum(struct smbd_server_connection
*sconn
,
5442 connection_struct
*conn
, uint64_t vuid
,
5443 char *param
, int tpscnt
,
5444 char *data
, int tdscnt
,
5445 int mdrcnt
,int mprcnt
,
5446 char **rdata
,char **rparam
,
5447 int *rdata_len
,int *rparam_len
)
5449 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
5450 char *str2
= skip_string(param
,tpscnt
,str1
);
5451 char *p
= skip_string(param
,tpscnt
,str2
);
5454 struct pack_desc desc
;
5456 if (!str1
|| !str2
|| !p
) {
5459 memset((char *)&desc
,'\0',sizeof(desc
));
5461 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
5463 DEBUG(3,("WPrintQProcEnum uLevel=%d\n",uLevel
));
5465 /* check it's a supported varient */
5466 if (strcmp(str1
,"WrLeh") != 0) {
5469 if (uLevel
!= 0 || strcmp(str2
,"B13") != 0) {
5474 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5480 desc
.buflen
= mdrcnt
;
5482 if (init_package(&desc
,1,0)) {
5483 PACKS(&desc
,"B13","lpd");
5486 succnt
= (desc
.errcode
== NERR_Success
? 1 : 0);
5488 *rdata_len
= desc
.usedlen
;
5491 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5495 SSVALS(*rparam
,0,desc
.errcode
);
5497 SSVAL(*rparam
,4,succnt
);
5500 DEBUG(4,("WPrintQProcEnum: errorcode %d\n",desc
.errcode
));
5505 static bool api_WPrintPortEnum(struct smbd_server_connection
*sconn
,
5506 connection_struct
*conn
, uint64_t vuid
,
5507 char *param
, int tpscnt
,
5508 char *data
, int tdscnt
,
5509 int mdrcnt
,int mprcnt
,
5510 char **rdata
,char **rparam
,
5511 int *rdata_len
,int *rparam_len
)
5513 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
5514 char *str2
= skip_string(param
,tpscnt
,str1
);
5515 char *p
= skip_string(param
,tpscnt
,str2
);
5518 struct pack_desc desc
;
5520 if (!str1
|| !str2
|| !p
) {
5524 memset((char *)&desc
,'\0',sizeof(desc
));
5526 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
5528 DEBUG(3,("WPrintPortEnum uLevel=%d\n",uLevel
));
5530 /* check it's a supported varient */
5531 if (strcmp(str1
,"WrLeh") != 0) {
5534 if (uLevel
!= 0 || strcmp(str2
,"B9") != 0) {
5539 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5544 memset((char *)&desc
,'\0',sizeof(desc
));
5546 desc
.buflen
= mdrcnt
;
5548 if (init_package(&desc
,1,0)) {
5549 PACKS(&desc
,"B13","lp0");
5552 succnt
= (desc
.errcode
== NERR_Success
? 1 : 0);
5554 *rdata_len
= desc
.usedlen
;
5557 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5561 SSVALS(*rparam
,0,desc
.errcode
);
5563 SSVAL(*rparam
,4,succnt
);
5566 DEBUG(4,("WPrintPortEnum: errorcode %d\n",desc
.errcode
));
5571 /****************************************************************************
5573 ****************************************************************************/
5575 static bool api_RNetSessionEnum(struct smbd_server_connection
*sconn
,
5576 connection_struct
*conn
, uint64_t vuid
,
5577 char *param
, int tpscnt
,
5578 char *data
, int tdscnt
,
5579 int mdrcnt
,int mprcnt
,
5580 char **rdata
,char **rparam
,
5581 int *rdata_len
,int *rparam_len
)
5584 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
5585 char *str2
= skip_string(param
,tpscnt
,str1
);
5586 char *p
= skip_string(param
,tpscnt
,str2
);
5588 struct pack_desc desc
;
5591 TALLOC_CTX
*mem_ctx
= talloc_tos();
5594 struct rpc_pipe_client
*cli
= NULL
;
5595 struct dcerpc_binding_handle
*b
= NULL
;
5596 struct srvsvc_NetSessInfoCtr info_ctr
;
5597 uint32_t totalentries
, resume_handle
= 0;
5600 if (!str1
|| !str2
|| !p
) {
5606 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
5608 DEBUG(3,("RNetSessionEnum uLevel=%d\n",uLevel
));
5609 DEBUG(7,("RNetSessionEnum req string=%s\n",str1
));
5610 DEBUG(7,("RNetSessionEnum ret string=%s\n",str2
));
5612 /* check it's a supported varient */
5613 if (strcmp(str1
,RAP_NetSessionEnum_REQ
) != 0) {
5616 if (uLevel
!= 2 || strcmp(str2
,RAP_SESSION_INFO_L2
) != 0) {
5620 status
= rpc_pipe_open_interface(conn
,
5623 conn
->sconn
->remote_address
,
5624 conn
->sconn
->msg_ctx
,
5626 if (!NT_STATUS_IS_OK(status
)) {
5627 DEBUG(0,("RNetSessionEnum: could not connect to srvsvc: %s\n",
5628 nt_errstr(status
)));
5629 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
5632 b
= cli
->binding_handle
;
5635 info_ctr
.ctr
.ctr1
= talloc_zero(talloc_tos(), struct srvsvc_NetSessCtr1
);
5636 if (info_ctr
.ctr
.ctr1
== NULL
) {
5637 desc
.errcode
= W_ERROR_V(WERR_NOMEM
);
5641 status
= dcerpc_srvsvc_NetSessEnum(b
, mem_ctx
,
5642 cli
->srv_name_slash
,
5646 (uint32_t)-1, /* max_buffer */
5650 if (!NT_STATUS_IS_OK(status
)) {
5651 DEBUG(0,("RNetSessionEnum: dcerpc_srvsvc_NetSessEnum failed: %s\n",
5652 nt_errstr(status
)));
5653 desc
.errcode
= W_ERROR_V(ntstatus_to_werror(status
));
5657 if (!W_ERROR_IS_OK(werr
)) {
5658 DEBUG(0,("RNetSessionEnum: dcerpc_srvsvc_NetSessEnum failed: %s\n",
5660 desc
.errcode
= W_ERROR_V(werr
);
5664 count
= info_ctr
.ctr
.ctr1
->count
;
5668 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
5675 desc
.buflen
= mdrcnt
;
5677 if (!init_package(&desc
, count
,0)) {
5681 for(i
=0; i
< count
; i
++) {
5682 PACKS(&desc
, "z", info_ctr
.ctr
.ctr1
->array
[i
].client
);
5683 PACKS(&desc
, "z", info_ctr
.ctr
.ctr1
->array
[i
].user
);
5684 PACKI(&desc
, "W", 1); /* num conns */
5685 PACKI(&desc
, "W", info_ctr
.ctr
.ctr1
->array
[i
].num_open
);
5686 PACKI(&desc
, "W", 1); /* num users */
5687 PACKI(&desc
, "D", 0); /* session time */
5688 PACKI(&desc
, "D", 0); /* idle time */
5689 PACKI(&desc
, "D", 0); /* flags */
5690 PACKS(&desc
, "z", "Unknown Client"); /* client type string */
5693 *rdata_len
= desc
.usedlen
;
5696 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5700 SSVALS(*rparam
,0,desc
.errcode
);
5701 SSVAL(*rparam
,2,0); /* converter */
5702 SSVAL(*rparam
,4, count
); /* count */
5704 DEBUG(4,("RNetSessionEnum: errorcode %d\n",desc
.errcode
));
5710 /****************************************************************************
5711 The buffer was too small.
5712 ****************************************************************************/
5714 static bool api_TooSmall(struct smbd_server_connection
*sconn
,
5715 connection_struct
*conn
,uint64_t vuid
, char *param
, char *data
,
5716 int mdrcnt
, int mprcnt
,
5717 char **rdata
, char **rparam
,
5718 int *rdata_len
, int *rparam_len
)
5720 *rparam_len
= MIN(*rparam_len
,mprcnt
);
5721 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5728 SSVAL(*rparam
,0,NERR_BufTooSmall
);
5730 DEBUG(3,("Supplied buffer too small in API command\n"));
5735 /****************************************************************************
5736 The request is not supported.
5737 ****************************************************************************/
5739 static bool api_Unsupported(struct smbd_server_connection
*sconn
,
5740 connection_struct
*conn
, uint64_t vuid
,
5741 char *param
, int tpscnt
,
5742 char *data
, int tdscnt
,
5743 int mdrcnt
, int mprcnt
,
5744 char **rdata
, char **rparam
,
5745 int *rdata_len
, int *rparam_len
)
5748 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
5755 SSVAL(*rparam
,0,NERR_notsupported
);
5756 SSVAL(*rparam
,2,0); /* converter word */
5758 DEBUG(3,("Unsupported API command\n"));
5763 static const struct {
5766 bool (*fn
)(struct smbd_server_connection
*sconn
,
5767 connection_struct
*, uint64_t,
5770 int,int,char **,char **,int *,int *);
5771 bool auth_user
; /* Deny anonymous access? */
5772 } api_commands
[] = {
5773 {"RNetShareEnum", RAP_WshareEnum
, api_RNetShareEnum
, True
},
5774 {"RNetShareGetInfo", RAP_WshareGetInfo
, api_RNetShareGetInfo
},
5775 {"RNetShareAdd", RAP_WshareAdd
, api_RNetShareAdd
},
5776 {"RNetSessionEnum", RAP_WsessionEnum
, api_RNetSessionEnum
, True
},
5777 {"RNetServerGetInfo", RAP_WserverGetInfo
, api_RNetServerGetInfo
},
5778 {"RNetGroupEnum", RAP_WGroupEnum
, api_RNetGroupEnum
, True
},
5779 {"RNetGroupGetUsers", RAP_WGroupGetUsers
, api_RNetGroupGetUsers
, True
},
5780 {"RNetUserEnum", RAP_WUserEnum
, api_RNetUserEnum
, True
},
5781 {"RNetUserGetInfo", RAP_WUserGetInfo
, api_RNetUserGetInfo
},
5782 {"NetUserGetGroups", RAP_WUserGetGroups
, api_NetUserGetGroups
},
5783 {"NetWkstaGetInfo", RAP_WWkstaGetInfo
, api_NetWkstaGetInfo
},
5784 {"DosPrintQEnum", RAP_WPrintQEnum
, api_DosPrintQEnum
, True
},
5785 {"DosPrintQGetInfo", RAP_WPrintQGetInfo
, api_DosPrintQGetInfo
},
5786 {"WPrintQueuePause", RAP_WPrintQPause
, api_WPrintQueueCtrl
},
5787 {"WPrintQueueResume", RAP_WPrintQContinue
, api_WPrintQueueCtrl
},
5788 {"WPrintJobEnumerate",RAP_WPrintJobEnum
, api_WPrintJobEnumerate
},
5789 {"WPrintJobGetInfo", RAP_WPrintJobGetInfo
, api_WPrintJobGetInfo
},
5790 {"RDosPrintJobDel", RAP_WPrintJobDel
, api_RDosPrintJobDel
},
5791 {"RDosPrintJobPause", RAP_WPrintJobPause
, api_RDosPrintJobDel
},
5792 {"RDosPrintJobResume",RAP_WPrintJobContinue
, api_RDosPrintJobDel
},
5793 {"WPrintDestEnum", RAP_WPrintDestEnum
, api_WPrintDestEnum
},
5794 {"WPrintDestGetInfo", RAP_WPrintDestGetInfo
, api_WPrintDestGetInfo
},
5795 {"NetRemoteTOD", RAP_NetRemoteTOD
, api_NetRemoteTOD
},
5796 {"WPrintQueuePurge", RAP_WPrintQPurge
, api_WPrintQueueCtrl
},
5797 {"NetServerEnum2", RAP_NetServerEnum2
, api_RNetServerEnum2
}, /* anon OK */
5798 {"NetServerEnum3", RAP_NetServerEnum3
, api_RNetServerEnum3
}, /* anon OK */
5799 {"WAccessGetUserPerms",RAP_WAccessGetUserPerms
,api_WAccessGetUserPerms
},
5800 {"SetUserPassword", RAP_WUserPasswordSet2
, api_SetUserPassword
},
5801 {"WWkstaUserLogon", RAP_WWkstaUserLogon
, api_WWkstaUserLogon
},
5802 {"PrintJobInfo", RAP_WPrintJobSetInfo
, api_PrintJobInfo
},
5803 {"WPrintDriverEnum", RAP_WPrintDriverEnum
, api_WPrintDriverEnum
},
5804 {"WPrintQProcEnum", RAP_WPrintQProcessorEnum
,api_WPrintQProcEnum
},
5805 {"WPrintPortEnum", RAP_WPrintPortEnum
, api_WPrintPortEnum
},
5806 {"SamOEMChangePassword",RAP_SamOEMChgPasswordUser2_P
,api_SamOEMChangePassword
}, /* anon OK */
5807 {NULL
, -1, api_Unsupported
}
5808 /* The following RAP calls are not implemented by Samba:
5810 RAP_WFileEnum2 - anon not OK
5815 /****************************************************************************
5816 Handle remote api calls.
5817 ****************************************************************************/
5819 void api_reply(connection_struct
*conn
, uint64_t vuid
,
5820 struct smb_request
*req
,
5821 char *data
, char *params
,
5822 int tdscnt
, int tpscnt
,
5823 int mdrcnt
, int mprcnt
)
5827 char *rparam
= NULL
;
5828 const char *name1
= NULL
;
5829 const char *name2
= NULL
;
5836 DEBUG(0,("ERROR: NULL params in api_reply()\n"));
5837 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
5842 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
5845 api_command
= SVAL(params
,0);
5846 /* Is there a string at position params+2 ? */
5847 if (skip_string(params
,tpscnt
,params
+2)) {
5852 name2
= skip_string(params
,tpscnt
,params
+2);
5857 DEBUG(3,("Got API command %d of form <%s> <%s> (tdscnt=%d,tpscnt=%d,mdrcnt=%d,mprcnt=%d)\n",
5861 tdscnt
,tpscnt
,mdrcnt
,mprcnt
));
5863 for (i
=0;api_commands
[i
].name
;i
++) {
5864 if (api_commands
[i
].id
== api_command
&& api_commands
[i
].fn
) {
5865 DEBUG(3,("Doing %s\n",api_commands
[i
].name
));
5870 /* Check whether this api call can be done anonymously */
5872 if (api_commands
[i
].auth_user
&& lp_restrict_anonymous()) {
5873 struct user_struct
*user
= get_valid_user_struct(req
->sconn
, vuid
);
5875 if (!user
|| security_session_user_level(user
->session_info
, NULL
) < SECURITY_USER
) {
5876 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
5881 rdata
= (char *)SMB_MALLOC(1024);
5883 memset(rdata
,'\0',1024);
5886 rparam
= (char *)SMB_MALLOC(1024);
5888 memset(rparam
,'\0',1024);
5891 if(!rdata
|| !rparam
) {
5892 DEBUG(0,("api_reply: malloc fail !\n"));
5895 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
5899 reply
= api_commands
[i
].fn(req
->sconn
, conn
,
5901 params
,tpscnt
, /* params + length */
5902 data
,tdscnt
, /* data + length */
5904 &rdata
,&rparam
,&rdata_len
,&rparam_len
);
5907 if (rdata_len
> mdrcnt
|| rparam_len
> mprcnt
) {
5908 reply
= api_TooSmall(req
->sconn
,conn
,vuid
,params
,data
,
5910 &rdata
,&rparam
,&rdata_len
,&rparam_len
);
5913 /* if we get False back then it's actually unsupported */
5915 reply
= api_Unsupported(req
->sconn
,conn
,vuid
,params
,tpscnt
,
5917 tdscnt
,mdrcnt
,mprcnt
,
5918 &rdata
,&rparam
,&rdata_len
,&rparam_len
);
5921 /* If api_Unsupported returns false we can't return anything. */
5923 send_trans_reply(conn
, req
, rparam
, rparam_len
,
5924 rdata
, rdata_len
, False
);