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
35 #define NERR_Success 0
36 #define NERR_badpass 86
37 #define NERR_notsupported 50
39 #define NERR_BASE (2100)
40 #define NERR_BufTooSmall (NERR_BASE+23)
41 #define NERR_JobNotFound (NERR_BASE+51)
42 #define NERR_DestNotFound (NERR_BASE+52)
44 #define ACCESS_READ 0x01
45 #define ACCESS_WRITE 0x02
46 #define ACCESS_CREATE 0x04
48 #define SHPWLEN 8 /* share password length */
50 /* Limit size of ipc replies */
52 static char *smb_realloc_limit(void *ptr
, size_t size
)
56 size
= MAX((size
),4*1024);
57 val
= (char *)SMB_REALLOC(ptr
,size
);
59 memset(val
,'\0',size
);
64 static bool api_Unsupported(connection_struct
*conn
, uint16 vuid
,
65 char *param
, int tpscnt
,
66 char *data
, int tdscnt
,
67 int mdrcnt
, int mprcnt
,
68 char **rdata
, char **rparam
,
69 int *rdata_len
, int *rparam_len
);
71 static bool api_TooSmall(connection_struct
*conn
, uint16 vuid
, char *param
, char *data
,
72 int mdrcnt
, int mprcnt
,
73 char **rdata
, char **rparam
,
74 int *rdata_len
, int *rparam_len
);
77 static int CopyExpanded(connection_struct
*conn
,
78 int snum
, char **dst
, char *src
, int *p_space_remaining
)
80 TALLOC_CTX
*ctx
= talloc_tos();
84 if (!src
|| !dst
|| !p_space_remaining
|| !(*dst
) ||
85 *p_space_remaining
<= 0) {
89 buf
= talloc_strdup(ctx
, src
);
91 *p_space_remaining
= 0;
94 buf
= talloc_string_sub(ctx
, buf
,"%S",lp_servicename(snum
));
96 *p_space_remaining
= 0;
99 buf
= talloc_sub_advanced(ctx
,
100 lp_servicename(SNUM(conn
)),
101 conn
->server_info
->unix_name
,
103 conn
->server_info
->utok
.gid
,
104 conn
->server_info
->sanitized_username
,
105 pdb_get_domain(conn
->server_info
->sam_account
),
108 *p_space_remaining
= 0;
111 l
= push_ascii(*dst
,buf
,*p_space_remaining
, STR_TERMINATE
);
116 (*p_space_remaining
) -= l
;
120 static int CopyAndAdvance(char **dst
, char *src
, int *n
)
123 if (!src
|| !dst
|| !n
|| !(*dst
)) {
126 l
= push_ascii(*dst
,src
,*n
, STR_TERMINATE
);
135 static int StrlenExpanded(connection_struct
*conn
, int snum
, char *s
)
137 TALLOC_CTX
*ctx
= talloc_tos();
142 buf
= talloc_strdup(ctx
,s
);
146 buf
= talloc_string_sub(ctx
,buf
,"%S",lp_servicename(snum
));
150 buf
= talloc_sub_advanced(ctx
,
151 lp_servicename(SNUM(conn
)),
152 conn
->server_info
->unix_name
,
154 conn
->server_info
->utok
.gid
,
155 conn
->server_info
->sanitized_username
,
156 pdb_get_domain(conn
->server_info
->sam_account
),
161 return strlen(buf
) + 1;
164 static char *Expand(connection_struct
*conn
, int snum
, char *s
)
166 TALLOC_CTX
*ctx
= talloc_tos();
172 buf
= talloc_strdup(ctx
,s
);
176 buf
= talloc_string_sub(ctx
,buf
,"%S",lp_servicename(snum
));
180 return talloc_sub_advanced(ctx
,
181 lp_servicename(SNUM(conn
)),
182 conn
->server_info
->unix_name
,
184 conn
->server_info
->utok
.gid
,
185 conn
->server_info
->sanitized_username
,
186 pdb_get_domain(conn
->server_info
->sam_account
),
190 /*******************************************************************
191 Check a API string for validity when we only need to check the prefix.
192 ******************************************************************/
194 static bool prefix_ok(const char *str
, const char *prefix
)
196 return(strncmp(str
,prefix
,strlen(prefix
)) == 0);
200 const char *format
; /* formatstring for structure */
201 const char *subformat
; /* subformat for structure */
202 char *base
; /* baseaddress of buffer */
203 int buflen
; /* remaining size for fixed part; on init: length of base */
204 int subcount
; /* count of substructures */
205 char *structbuf
; /* pointer into buffer for remaining fixed part */
206 int stringlen
; /* remaining size for variable part */
207 char *stringbuf
; /* pointer into buffer for remaining variable part */
208 int neededlen
; /* total needed size */
209 int usedlen
; /* total used size (usedlen <= neededlen and usedlen <= buflen) */
210 const char *curpos
; /* current position; pointer into format or subformat */
214 static int get_counter(const char **p
)
220 if (!isdigit((int)**p
)) {
226 n
= 10 * n
+ (i
- '0');
234 static int getlen(const char *p
)
243 case 'W': /* word (2 byte) */
246 case 'K': /* status word? (2 byte) */
249 case 'N': /* count of substructures (word) at end */
252 case 'D': /* double word (4 byte) */
253 case 'z': /* offset to zero terminated string (4 byte) */
254 case 'l': /* offset to user data (4 byte) */
257 case 'b': /* offset to data (with counter) (4 byte) */
261 case 'B': /* byte (with optional counter) */
262 n
+= get_counter(&p
);
269 static bool init_package(struct pack_desc
*p
, int count
, int subcount
)
274 if (!p
->format
|| !p
->base
) {
278 i
= count
* getlen(p
->format
);
280 i
+= subcount
* getlen(p
->subformat
);
282 p
->structbuf
= p
->base
;
286 p
->curpos
= p
->format
;
292 * This is the old error code we used. Aparently
293 * WinNT/2k systems return ERRbuftoosmall (2123) and
294 * OS/2 needs this. I'm leaving this here so we can revert
297 p
->errcode
= ERRmoredata
;
299 p
->errcode
= ERRbuftoosmall
;
302 p
->errcode
= NERR_Success
;
306 p
->stringbuf
= p
->base
+ i
;
308 return (p
->errcode
== NERR_Success
);
311 static int package(struct pack_desc
*p
, ...)
314 int needed
=0, stringneeded
;
315 const char *str
=NULL
;
316 int is_string
=0, stringused
;
323 p
->curpos
= p
->format
;
325 p
->curpos
= p
->subformat
;
330 str
= va_arg(args
,char*);
331 SMB_ASSERT(strncmp(str
,p
->curpos
,strlen(str
)) == 0);
340 switch( *p
->curpos
++ ) {
341 case 'W': /* word (2 byte) */
343 temp
= va_arg(args
,int);
344 if (p
->buflen
>= needed
) {
345 SSVAL(p
->structbuf
,0,temp
);
348 case 'K': /* status word? (2 byte) */
350 temp
= va_arg(args
,int);
351 if (p
->buflen
>= needed
) {
352 SSVAL(p
->structbuf
,0,temp
);
355 case 'N': /* count of substructures (word) at end */
357 p
->subcount
= va_arg(args
,int);
358 if (p
->buflen
>= needed
) {
359 SSVAL(p
->structbuf
,0,p
->subcount
);
362 case 'D': /* double word (4 byte) */
364 temp
= va_arg(args
,int);
365 if (p
->buflen
>= needed
) {
366 SIVAL(p
->structbuf
,0,temp
);
369 case 'B': /* byte (with optional counter) */
370 needed
= get_counter(&p
->curpos
);
372 char *s
= va_arg(args
,char*);
373 if (p
->buflen
>= needed
) {
374 StrnCpy(p
->structbuf
,s
?s
:"",needed
-1);
378 case 'z': /* offset to zero terminated string (4 byte) */
379 str
= va_arg(args
,char*);
380 stringneeded
= (str
? strlen(str
)+1 : 0);
383 case 'l': /* offset to user data (4 byte) */
384 str
= va_arg(args
,char*);
385 stringneeded
= va_arg(args
,int);
388 case 'b': /* offset to data (with counter) (4 byte) */
389 str
= va_arg(args
,char*);
390 stringneeded
= get_counter(&p
->curpos
);
396 if (stringneeded
>= 0) {
398 if (p
->buflen
>= needed
) {
399 stringused
= stringneeded
;
400 if (stringused
> p
->stringlen
) {
401 stringused
= (is_string
? p
->stringlen
: 0);
402 if (p
->errcode
== NERR_Success
) {
403 p
->errcode
= ERRmoredata
;
407 SIVAL(p
->structbuf
,0,0);
409 SIVAL(p
->structbuf
,0,PTR_DIFF(p
->stringbuf
,p
->base
));
410 memcpy(p
->stringbuf
,str
?str
:"",stringused
);
412 p
->stringbuf
[stringused
-1] = '\0';
414 p
->stringbuf
+= stringused
;
415 p
->stringlen
-= stringused
;
416 p
->usedlen
+= stringused
;
419 p
->neededlen
+= stringneeded
;
422 p
->neededlen
+= needed
;
423 if (p
->buflen
>= needed
) {
424 p
->structbuf
+= needed
;
426 p
->usedlen
+= needed
;
428 if (p
->errcode
== NERR_Success
) {
429 p
->errcode
= ERRmoredata
;
436 #define PACK(desc,t,v) package(desc,t,v,0,0,0,0)
437 #define PACKl(desc,t,v,l) package(desc,t,v,l,0,0,0,0)
439 #define PACK(desc,t,v) package(desc,v)
440 #define PACKl(desc,t,v,l) package(desc,v,l)
443 static void PACKI(struct pack_desc
* desc
, const char *t
,int v
)
448 static void PACKS(struct pack_desc
* desc
,const char *t
,const char *v
)
453 /****************************************************************************
455 ****************************************************************************/
457 static void PackDriverData(struct pack_desc
* desc
)
459 char drivdata
[4+4+32];
460 SIVAL(drivdata
,0,sizeof drivdata
); /* cb */
461 SIVAL(drivdata
,4,1000); /* lVersion */
462 memset(drivdata
+8,0,32); /* szDeviceName */
463 push_ascii(drivdata
+8,"NULL",32, STR_TERMINATE
);
464 PACKl(desc
,"l",drivdata
,sizeof drivdata
); /* pDriverData */
467 static int check_printq_info(struct pack_desc
* desc
,
468 unsigned int uLevel
, char *id1
, char *id2
)
470 desc
->subformat
= NULL
;
473 desc
->format
= "B13";
476 desc
->format
= "B13BWWWzzzzzWW";
479 desc
->format
= "B13BWWWzzzzzWN";
480 desc
->subformat
= "WB21BB16B10zWWzDDz";
483 desc
->format
= "zWWWWzzzzWWzzl";
486 desc
->format
= "zWWWWzzzzWNzzl";
487 desc
->subformat
= "WWzWWDDzz";
496 desc
->format
= "WzzzzzzzzN";
497 desc
->subformat
= "z";
500 DEBUG(0,("check_printq_info: invalid level %d\n",
504 if (id1
== NULL
|| strcmp(desc
->format
,id1
) != 0) {
505 DEBUG(0,("check_printq_info: invalid format %s\n",
506 id1
? id1
: "<NULL>" ));
509 if (desc
->subformat
&& (id2
== NULL
|| strcmp(desc
->subformat
,id2
) != 0)) {
510 DEBUG(0,("check_printq_info: invalid subformat %s\n",
511 id2
? id2
: "<NULL>" ));
518 #define RAP_JOB_STATUS_QUEUED 0
519 #define RAP_JOB_STATUS_PAUSED 1
520 #define RAP_JOB_STATUS_SPOOLING 2
521 #define RAP_JOB_STATUS_PRINTING 3
522 #define RAP_JOB_STATUS_PRINTED 4
524 #define RAP_QUEUE_STATUS_PAUSED 1
525 #define RAP_QUEUE_STATUS_ERROR 2
527 /* turn a print job status into a on the wire status
529 static int printj_status(int v
)
533 return RAP_JOB_STATUS_QUEUED
;
535 return RAP_JOB_STATUS_PAUSED
;
537 return RAP_JOB_STATUS_SPOOLING
;
539 return RAP_JOB_STATUS_PRINTING
;
544 /* turn a print queue status into a on the wire status
546 static int printq_status(int v
)
552 return RAP_QUEUE_STATUS_PAUSED
;
554 return RAP_QUEUE_STATUS_ERROR
;
557 static void fill_printjob_info(connection_struct
*conn
, int snum
, int uLevel
,
558 struct pack_desc
*desc
,
559 print_queue_struct
*queue
, int n
)
561 time_t t
= queue
->time
;
563 /* the client expects localtime */
564 t
-= get_time_zone(t
);
566 PACKI(desc
,"W",pjobid_to_rap(lp_const_servicename(snum
),queue
->job
)); /* uJobId */
568 PACKS(desc
,"B21",queue
->fs_user
); /* szUserName */
569 PACKS(desc
,"B",""); /* pad */
570 PACKS(desc
,"B16",""); /* szNotifyName */
571 PACKS(desc
,"B10","PM_Q_RAW"); /* szDataType */
572 PACKS(desc
,"z",""); /* pszParms */
573 PACKI(desc
,"W",n
+1); /* uPosition */
574 PACKI(desc
,"W",printj_status(queue
->status
)); /* fsStatus */
575 PACKS(desc
,"z",""); /* pszStatus */
576 PACKI(desc
,"D",t
); /* ulSubmitted */
577 PACKI(desc
,"D",queue
->size
); /* ulSize */
578 PACKS(desc
,"z",queue
->fs_file
); /* pszComment */
580 if (uLevel
== 2 || uLevel
== 3 || uLevel
== 4) {
581 PACKI(desc
,"W",queue
->priority
); /* uPriority */
582 PACKS(desc
,"z",queue
->fs_user
); /* pszUserName */
583 PACKI(desc
,"W",n
+1); /* uPosition */
584 PACKI(desc
,"W",printj_status(queue
->status
)); /* fsStatus */
585 PACKI(desc
,"D",t
); /* ulSubmitted */
586 PACKI(desc
,"D",queue
->size
); /* ulSize */
587 PACKS(desc
,"z","Samba"); /* pszComment */
588 PACKS(desc
,"z",queue
->fs_file
); /* pszDocument */
590 PACKS(desc
,"z",""); /* pszNotifyName */
591 PACKS(desc
,"z","PM_Q_RAW"); /* pszDataType */
592 PACKS(desc
,"z",""); /* pszParms */
593 PACKS(desc
,"z",""); /* pszStatus */
594 PACKS(desc
,"z",SERVICE(snum
)); /* pszQueue */
595 PACKS(desc
,"z","lpd"); /* pszQProcName */
596 PACKS(desc
,"z",""); /* pszQProcParms */
597 PACKS(desc
,"z","NULL"); /* pszDriverName */
598 PackDriverData(desc
); /* pDriverData */
599 PACKS(desc
,"z",""); /* pszPrinterName */
600 } else if (uLevel
== 4) { /* OS2 */
601 PACKS(desc
,"z",""); /* pszSpoolFileName */
602 PACKS(desc
,"z",""); /* pszPortName */
603 PACKS(desc
,"z",""); /* pszStatus */
604 PACKI(desc
,"D",0); /* ulPagesSpooled */
605 PACKI(desc
,"D",0); /* ulPagesSent */
606 PACKI(desc
,"D",0); /* ulPagesPrinted */
607 PACKI(desc
,"D",0); /* ulTimePrinted */
608 PACKI(desc
,"D",0); /* ulExtendJobStatus */
609 PACKI(desc
,"D",0); /* ulStartPage */
610 PACKI(desc
,"D",0); /* ulEndPage */
615 /********************************************************************
616 Return a driver name given an snum.
617 Returns True if from tdb, False otherwise.
618 ********************************************************************/
620 static bool get_driver_name(int snum
, char **pp_drivername
)
622 NT_PRINTER_INFO_LEVEL
*info
= NULL
;
625 get_a_printer (NULL
, &info
, 2, lp_servicename(snum
));
627 *pp_drivername
= talloc_strdup(talloc_tos(),
628 info
->info_2
->drivername
);
630 free_a_printer(&info
, 2);
631 if (!*pp_drivername
) {
639 /********************************************************************
640 Respond to the DosPrintQInfo command with a level of 52
641 This is used to get printer driver information for Win9x clients
642 ********************************************************************/
643 static void fill_printq_info_52(connection_struct
*conn
, int snum
,
644 struct pack_desc
* desc
, int count
)
648 NT_PRINTER_DRIVER_INFO_LEVEL driver
;
649 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
653 if ( !W_ERROR_IS_OK(get_a_printer( NULL
, &printer
, 2, lp_servicename(snum
))) ) {
654 DEBUG(3,("fill_printq_info_52: Failed to lookup printer [%s]\n",
655 lp_servicename(snum
)));
659 if ( !W_ERROR_IS_OK(get_a_printer_driver(&driver
, 3, printer
->info_2
->drivername
,
662 DEBUG(3,("fill_printq_info_52: Failed to lookup driver [%s]\n",
663 printer
->info_2
->drivername
));
667 trim_string(driver
.info_3
->driverpath
, "\\print$\\WIN40\\0\\", 0);
668 trim_string(driver
.info_3
->datafile
, "\\print$\\WIN40\\0\\", 0);
669 trim_string(driver
.info_3
->helpfile
, "\\print$\\WIN40\\0\\", 0);
671 PACKI(desc
, "W", 0x0400); /* don't know */
672 PACKS(desc
, "z", driver
.info_3
->name
); /* long printer name */
673 PACKS(desc
, "z", driver
.info_3
->driverpath
); /* Driverfile Name */
674 PACKS(desc
, "z", driver
.info_3
->datafile
); /* Datafile name */
675 PACKS(desc
, "z", driver
.info_3
->monitorname
); /* language monitor */
677 fstrcpy(location
, "\\\\%L\\print$\\WIN40\\0");
678 standard_sub_basic( "", "", location
, sizeof(location
)-1 );
679 PACKS(desc
,"z", location
); /* share to retrieve files */
681 PACKS(desc
,"z", driver
.info_3
->defaultdatatype
); /* default data type */
682 PACKS(desc
,"z", driver
.info_3
->helpfile
); /* helpfile name */
683 PACKS(desc
,"z", driver
.info_3
->driverpath
); /* driver name */
685 DEBUG(3,("Printer Driver Name: %s:\n",driver
.info_3
->name
));
686 DEBUG(3,("Driver: %s:\n",driver
.info_3
->driverpath
));
687 DEBUG(3,("Data File: %s:\n",driver
.info_3
->datafile
));
688 DEBUG(3,("Language Monitor: %s:\n",driver
.info_3
->monitorname
));
689 DEBUG(3,("Driver Location: %s:\n",location
));
690 DEBUG(3,("Data Type: %s:\n",driver
.info_3
->defaultdatatype
));
691 DEBUG(3,("Help File: %s:\n",driver
.info_3
->helpfile
));
692 PACKI(desc
,"N",count
); /* number of files to copy */
694 for ( i
=0; i
<count
&& driver
.info_3
->dependentfiles
&& *driver
.info_3
->dependentfiles
[i
]; i
++)
696 trim_string(driver
.info_3
->dependentfiles
[i
], "\\print$\\WIN40\\0\\", 0);
697 PACKS(desc
,"z",driver
.info_3
->dependentfiles
[i
]); /* driver files to copy */
698 DEBUG(3,("Dependent File: %s:\n",driver
.info_3
->dependentfiles
[i
]));
703 DEBUG(3,("fill_printq_info_52: file count specified by client [%d] != number of dependent files [%i]\n",
706 DEBUG(3,("fill_printq_info on <%s> gave %d entries\n", SERVICE(snum
),i
));
708 desc
->errcode
=NERR_Success
;
712 DEBUG(3,("fill_printq_info: Can't supply driver files\n"));
713 desc
->errcode
=NERR_notsupported
;
717 free_a_printer( &printer
, 2 );
720 free_a_printer_driver( driver
, 3 );
724 static void fill_printq_info(connection_struct
*conn
, int snum
, int uLevel
,
725 struct pack_desc
* desc
,
726 int count
, print_queue_struct
* queue
,
727 print_status_struct
* status
)
732 PACKS(desc
,"B13",SERVICE(snum
));
737 PACKS(desc
,"z",Expand(conn
,snum
,SERVICE(snum
)));
740 PACKI(desc
,"K",printq_status(status
->status
));
744 if (uLevel
== 1 || uLevel
== 2) {
745 PACKS(desc
,"B",""); /* alignment */
746 PACKI(desc
,"W",5); /* priority */
747 PACKI(desc
,"W",0); /* start time */
748 PACKI(desc
,"W",0); /* until time */
749 PACKS(desc
,"z",""); /* pSepFile */
750 PACKS(desc
,"z","lpd"); /* pPrProc */
751 PACKS(desc
,"z",SERVICE(snum
)); /* pDestinations */
752 PACKS(desc
,"z",""); /* pParms */
754 PACKS(desc
,"z","UNKNOWN PRINTER");
755 PACKI(desc
,"W",LPSTAT_ERROR
);
757 else if (!status
|| !status
->message
[0]) {
758 PACKS(desc
,"z",Expand(conn
,snum
,lp_comment(snum
)));
759 PACKI(desc
,"W",LPSTAT_OK
); /* status */
761 PACKS(desc
,"z",status
->message
);
762 PACKI(desc
,"W",printq_status(status
->status
)); /* status */
764 PACKI(desc
,(uLevel
== 1 ? "W" : "N"),count
);
767 if (uLevel
== 3 || uLevel
== 4) {
768 char *drivername
= NULL
;
770 PACKI(desc
,"W",5); /* uPriority */
771 PACKI(desc
,"W",0); /* uStarttime */
772 PACKI(desc
,"W",0); /* uUntiltime */
773 PACKI(desc
,"W",5); /* pad1 */
774 PACKS(desc
,"z",""); /* pszSepFile */
775 PACKS(desc
,"z","WinPrint"); /* pszPrProc */
776 PACKS(desc
,"z",NULL
); /* pszParms */
777 PACKS(desc
,"z",NULL
); /* pszComment - don't ask.... JRA */
778 /* "don't ask" that it's done this way to fix corrupted
779 Win9X/ME printer comments. */
781 PACKI(desc
,"W",LPSTAT_OK
); /* fsStatus */
783 PACKI(desc
,"W",printq_status(status
->status
)); /* fsStatus */
785 PACKI(desc
,(uLevel
== 3 ? "W" : "N"),count
); /* cJobs */
786 PACKS(desc
,"z",SERVICE(snum
)); /* pszPrinters */
787 get_driver_name(snum
,&drivername
);
791 PACKS(desc
,"z",drivername
); /* pszDriverName */
792 PackDriverData(desc
); /* pDriverData */
795 if (uLevel
== 2 || uLevel
== 4) {
797 for (i
=0;i
<count
;i
++)
798 fill_printjob_info(conn
,snum
,uLevel
== 2 ? 1 : 2,desc
,&queue
[i
],i
);
802 fill_printq_info_52( conn
, snum
, desc
, count
);
805 /* This function returns the number of files for a given driver */
806 static int get_printerdrivernumber(int snum
)
809 NT_PRINTER_DRIVER_INFO_LEVEL driver
;
810 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
814 if ( !W_ERROR_IS_OK(get_a_printer( NULL
, &printer
, 2, lp_servicename(snum
))) ) {
815 DEBUG(3,("get_printerdrivernumber: Failed to lookup printer [%s]\n",
816 lp_servicename(snum
)));
820 if ( !W_ERROR_IS_OK(get_a_printer_driver(&driver
, 3, printer
->info_2
->drivername
,
823 DEBUG(3,("get_printerdrivernumber: Failed to lookup driver [%s]\n",
824 printer
->info_2
->drivername
));
828 /* count the number of files */
829 while ( driver
.info_3
->dependentfiles
&& *driver
.info_3
->dependentfiles
[result
] )
834 free_a_printer( &printer
, 2 );
837 free_a_printer_driver( driver
, 3 );
842 static bool api_DosPrintQGetInfo(connection_struct
*conn
, uint16 vuid
,
843 char *param
, int tpscnt
,
844 char *data
, int tdscnt
,
845 int mdrcnt
,int mprcnt
,
846 char **rdata
,char **rparam
,
847 int *rdata_len
,int *rparam_len
)
849 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
850 char *str2
= skip_string(param
,tpscnt
,str1
);
851 char *p
= skip_string(param
,tpscnt
,str2
);
857 struct pack_desc desc
;
858 print_queue_struct
*queue
=NULL
;
859 print_status_struct status
;
862 if (!str1
|| !str2
|| !p
) {
865 memset((char *)&status
,'\0',sizeof(status
));
866 memset((char *)&desc
,'\0',sizeof(desc
));
868 p
= skip_string(param
,tpscnt
,p
);
872 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
873 str3
= get_safe_str_ptr(param
,tpscnt
,p
,4);
874 /* str3 may be null here and is checked in check_printq_info(). */
876 /* remove any trailing username */
877 if ((p
= strchr_m(QueueName
,'%')))
880 DEBUG(3,("api_DosPrintQGetInfo uLevel=%d name=%s\n",uLevel
,QueueName
));
882 /* check it's a supported varient */
883 if (!prefix_ok(str1
,"zWrLh"))
885 if (!check_printq_info(&desc
,uLevel
,str2
,str3
)) {
887 * Patch from Scott Moomaw <scott@bridgewater.edu>
888 * to return the 'invalid info level' error if an
889 * unknown level was requested.
893 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
897 SSVALS(*rparam
,0,ERRunknownlevel
);
903 snum
= find_service(QueueName
);
904 if ( !(lp_snum_ok(snum
) && lp_print_ok(snum
)) )
908 count
= get_printerdrivernumber(snum
);
909 DEBUG(3,("api_DosPrintQGetInfo: Driver files count: %d\n",count
));
911 count
= print_queue_status(snum
, &queue
,&status
);
915 *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(conn
,snum
,uLevel
,&desc
,count
,queue
,&status
);
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
;
946 *rdata_len
= desc
.usedlen
;
948 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
954 SSVALS(*rparam
,0,desc
.errcode
);
956 SSVAL(*rparam
,4,desc
.neededlen
);
958 DEBUG(4,("printqgetinfo: errorcode %d\n",desc
.errcode
));
966 /****************************************************************************
967 View list of all print jobs on all queues.
968 ****************************************************************************/
970 static bool api_DosPrintQEnum(connection_struct
*conn
, uint16 vuid
,
971 char *param
, int tpscnt
,
972 char *data
, int tdscnt
,
973 int mdrcnt
, int mprcnt
,
974 char **rdata
, char** rparam
,
975 int *rdata_len
, int *rparam_len
)
977 char *param_format
= get_safe_str_ptr(param
,tpscnt
,param
,2);
978 char *output_format1
= skip_string(param
,tpscnt
,param_format
);
979 char *p
= skip_string(param
,tpscnt
,output_format1
);
980 unsigned int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
981 char *output_format2
= get_safe_str_ptr(param
,tpscnt
,p
,4);
982 int services
= lp_numservices();
984 struct pack_desc desc
;
985 print_queue_struct
**queue
= NULL
;
986 print_status_struct
*status
= NULL
;
987 int *subcntarr
= NULL
;
988 int queuecnt
= 0, subcnt
= 0, succnt
= 0;
990 if (!param_format
|| !output_format1
|| !p
) {
994 memset((char *)&desc
,'\0',sizeof(desc
));
996 DEBUG(3,("DosPrintQEnum uLevel=%d\n",uLevel
));
998 if (!prefix_ok(param_format
,"WrLeh")) {
1001 if (!check_printq_info(&desc
,uLevel
,output_format1
,output_format2
)) {
1003 * Patch from Scott Moomaw <scott@bridgewater.edu>
1004 * to return the 'invalid info level' error if an
1005 * unknown level was requested.
1009 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1013 SSVALS(*rparam
,0,ERRunknownlevel
);
1019 for (i
= 0; i
< services
; i
++) {
1020 if (lp_snum_ok(i
) && lp_print_ok(i
) && lp_browseable(i
)) {
1025 if((queue
= SMB_MALLOC_ARRAY(print_queue_struct
*, queuecnt
)) == NULL
) {
1026 DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1029 memset(queue
,0,queuecnt
*sizeof(print_queue_struct
*));
1030 if((status
= SMB_MALLOC_ARRAY(print_status_struct
,queuecnt
)) == NULL
) {
1031 DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1034 memset(status
,0,queuecnt
*sizeof(print_status_struct
));
1035 if((subcntarr
= SMB_MALLOC_ARRAY(int,queuecnt
)) == NULL
) {
1036 DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
1042 for (i
= 0; i
< services
; i
++) {
1043 if (lp_snum_ok(i
) && lp_print_ok(i
) && lp_browseable(i
)) {
1044 subcntarr
[n
] = print_queue_status(i
, &queue
[n
],&status
[n
]);
1045 subcnt
+= subcntarr
[n
];
1051 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
1057 desc
.buflen
= mdrcnt
;
1059 if (init_package(&desc
,queuecnt
,subcnt
)) {
1062 for (i
= 0; i
< services
; i
++) {
1063 if (lp_snum_ok(i
) && lp_print_ok(i
) && lp_browseable(i
)) {
1064 fill_printq_info(conn
,i
,uLevel
,&desc
,subcntarr
[n
],queue
[n
],&status
[n
]);
1066 if (desc
.errcode
== NERR_Success
) {
1073 SAFE_FREE(subcntarr
);
1075 *rdata_len
= desc
.usedlen
;
1077 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1081 SSVALS(*rparam
,0,desc
.errcode
);
1083 SSVAL(*rparam
,4,succnt
);
1084 SSVAL(*rparam
,6,queuecnt
);
1086 for (i
= 0; i
< queuecnt
; i
++) {
1088 SAFE_FREE(queue
[i
]);
1099 SAFE_FREE(subcntarr
);
1100 for (i
= 0; i
< queuecnt
; i
++) {
1102 SAFE_FREE(queue
[i
]);
1111 /****************************************************************************
1112 Get info level for a server list query.
1113 ****************************************************************************/
1115 static bool check_server_info(int uLevel
, char* id
)
1119 if (strcmp(id
,"B16") != 0) {
1124 if (strcmp(id
,"B16BBDz") != 0) {
1134 struct srv_info_struct
{
1142 /*******************************************************************
1143 Get server info lists from the files saved by nmbd. Return the
1145 ******************************************************************/
1147 static int get_server_info(uint32 servertype
,
1148 struct srv_info_struct
**servers
,
1154 bool local_list_only
;
1157 lines
= file_lines_load(cache_path(SERVER_LIST
), NULL
, 0, NULL
);
1159 DEBUG(4,("Can't open %s - %s\n",cache_path(SERVER_LIST
),strerror(errno
)));
1163 /* request for everything is code for request all servers */
1164 if (servertype
== SV_TYPE_ALL
) {
1165 servertype
&= ~(SV_TYPE_DOMAIN_ENUM
|SV_TYPE_LOCAL_LIST_ONLY
);
1168 local_list_only
= (servertype
& SV_TYPE_LOCAL_LIST_ONLY
);
1170 DEBUG(4,("Servertype search: %8x\n",servertype
));
1172 for (i
=0;lines
[i
];i
++) {
1174 struct srv_info_struct
*s
;
1175 const char *ptr
= lines
[i
];
1177 TALLOC_CTX
*frame
= NULL
;
1184 if (count
== alloced
) {
1186 *servers
= SMB_REALLOC_ARRAY(*servers
,struct srv_info_struct
, alloced
);
1188 DEBUG(0,("get_server_info: failed to enlarge servers info struct!\n"));
1192 memset((char *)((*servers
)+count
),'\0',sizeof(**servers
)*(alloced
-count
));
1194 s
= &(*servers
)[count
];
1196 frame
= talloc_stackframe();
1198 if (!next_token_talloc(frame
,&ptr
,&p
, NULL
)) {
1202 fstrcpy(s
->name
, p
);
1205 if (!next_token_talloc(frame
,&ptr
, &p
, NULL
)) {
1211 s
->comment
[0] = '\0';
1212 if (!next_token_talloc(frame
,&ptr
, &p
, NULL
)) {
1216 fstrcpy(s
->comment
, p
);
1217 string_truncate(s
->comment
, MAX_SERVER_STRING_LENGTH
);
1219 s
->domain
[0] = '\0';
1220 if (!next_token_talloc(frame
,&ptr
,&p
, NULL
)) {
1221 /* this allows us to cope with an old nmbd */
1222 fstrcpy(s
->domain
,lp_workgroup());
1224 fstrcpy(s
->domain
, p
);
1228 if (sscanf(stype
,"%X",&s
->type
) != 1) {
1229 DEBUG(4,("r:host file "));
1233 /* Filter the servers/domains we return based on what was asked for. */
1235 /* Check to see if we are being asked for a local list only. */
1236 if(local_list_only
&& ((s
->type
& SV_TYPE_LOCAL_LIST_ONLY
) == 0)) {
1237 DEBUG(4,("r: local list only"));
1241 /* doesn't match up: don't want it */
1242 if (!(servertype
& s
->type
)) {
1243 DEBUG(4,("r:serv type "));
1247 if ((servertype
& SV_TYPE_DOMAIN_ENUM
) !=
1248 (s
->type
& SV_TYPE_DOMAIN_ENUM
)) {
1249 DEBUG(4,("s: dom mismatch "));
1253 if (!strequal(domain
, s
->domain
) && !(servertype
& SV_TYPE_DOMAIN_ENUM
)) {
1257 /* We should never return a server type with a SV_TYPE_LOCAL_LIST_ONLY set. */
1258 s
->type
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
1261 DEBUG(4,("**SV** %20s %8x %25s %15s\n",
1262 s
->name
, s
->type
, s
->comment
, s
->domain
));
1263 s
->server_added
= True
;
1266 DEBUG(4,("%20s %8x %25s %15s\n",
1267 s
->name
, s
->type
, s
->comment
, s
->domain
));
1275 /*******************************************************************
1276 Fill in a server info structure.
1277 ******************************************************************/
1279 static int fill_srv_info(struct srv_info_struct
*service
,
1280 int uLevel
, char **buf
, int *buflen
,
1281 char **stringbuf
, int *stringspace
, char *baseaddr
)
1304 len
= strlen(service
->comment
)+1;
1308 *buflen
= struct_len
;
1310 return struct_len
+ len
;
1315 if (*buflen
< struct_len
) {
1322 p2
= p
+ struct_len
;
1323 l2
= *buflen
- struct_len
;
1331 push_ascii(p
,service
->name
, MAX_NETBIOSNAME_LEN
, STR_TERMINATE
);
1335 push_ascii(p
,service
->name
,MAX_NETBIOSNAME_LEN
, STR_TERMINATE
);
1336 SIVAL(p
,18,service
->type
);
1337 SIVAL(p
,22,PTR_DIFF(p2
,baseaddr
));
1338 len
+= CopyAndAdvance(&p2
,service
->comment
,&l2
);
1343 *buf
= p
+ struct_len
;
1344 *buflen
-= struct_len
;
1355 static bool srv_comp(struct srv_info_struct
*s1
,struct srv_info_struct
*s2
)
1357 return(strcmp(s1
->name
,s2
->name
));
1360 /****************************************************************************
1361 View list of servers available (or possibly domains). The info is
1362 extracted from lists saved by nmbd on the local host.
1363 ****************************************************************************/
1365 static bool api_RNetServerEnum(connection_struct
*conn
, uint16 vuid
,
1366 char *param
, int tpscnt
,
1367 char *data
, int tdscnt
,
1368 int mdrcnt
, int mprcnt
, char **rdata
,
1369 char **rparam
, int *rdata_len
, int *rparam_len
)
1371 char *str1
= get_safe_str_ptr(param
, tpscnt
, param
, 2);
1372 char *str2
= skip_string(param
,tpscnt
,str1
);
1373 char *p
= skip_string(param
,tpscnt
,str2
);
1374 int uLevel
= get_safe_SVAL(param
, tpscnt
, p
, 0, -1);
1375 int buf_len
= get_safe_SVAL(param
,tpscnt
, p
, 2, 0);
1376 uint32 servertype
= get_safe_IVAL(param
,tpscnt
,p
,4, 0);
1378 int data_len
, fixed_len
, string_len
;
1379 int f_len
= 0, s_len
= 0;
1380 struct srv_info_struct
*servers
=NULL
;
1381 int counted
=0,total
=0;
1384 bool domain_request
;
1387 if (!str1
|| !str2
|| !p
) {
1391 /* If someone sets all the bits they don't really mean to set
1392 DOMAIN_ENUM and LOCAL_LIST_ONLY, they just want all the
1395 if (servertype
== SV_TYPE_ALL
) {
1396 servertype
&= ~(SV_TYPE_DOMAIN_ENUM
|SV_TYPE_LOCAL_LIST_ONLY
);
1399 /* If someone sets SV_TYPE_LOCAL_LIST_ONLY but hasn't set
1400 any other bit (they may just set this bit on its own) they
1401 want all the locally seen servers. However this bit can be
1402 set on its own so set the requested servers to be
1403 ALL - DOMAIN_ENUM. */
1405 if ((servertype
& SV_TYPE_LOCAL_LIST_ONLY
) && !(servertype
& SV_TYPE_DOMAIN_ENUM
)) {
1406 servertype
= SV_TYPE_ALL
& ~(SV_TYPE_DOMAIN_ENUM
);
1409 domain_request
= ((servertype
& SV_TYPE_DOMAIN_ENUM
) != 0);
1410 local_request
= ((servertype
& SV_TYPE_LOCAL_LIST_ONLY
) != 0);
1414 if (!prefix_ok(str1
,"WrLehD")) {
1417 if (!check_server_info(uLevel
,str2
)) {
1421 DEBUG(4, ("server request level: %s %8x ", str2
, servertype
));
1422 DEBUG(4, ("domains_req:%s ", BOOLSTR(domain_request
)));
1423 DEBUG(4, ("local_only:%s\n", BOOLSTR(local_request
)));
1425 if (strcmp(str1
, "WrLehDz") == 0) {
1426 if (skip_string(param
,tpscnt
,p
) == NULL
) {
1429 pull_ascii_fstring(domain
, p
);
1431 fstrcpy(domain
, lp_workgroup());
1434 if (lp_browse_list()) {
1435 total
= get_server_info(servertype
,&servers
,domain
);
1438 data_len
= fixed_len
= string_len
= 0;
1442 qsort(servers
,total
,sizeof(servers
[0]),QSORT_CAST srv_comp
);
1446 char *lastname
=NULL
;
1448 for (i
=0;i
<total
;i
++) {
1449 struct srv_info_struct
*s
= &servers
[i
];
1451 if (lastname
&& strequal(lastname
,s
->name
)) {
1455 data_len
+= fill_srv_info(s
,uLevel
,0,&f_len
,0,&s_len
,0);
1456 DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
1457 s
->name
, s
->type
, s
->comment
, s
->domain
));
1459 if (data_len
<= buf_len
) {
1462 string_len
+= s_len
;
1469 *rdata_len
= fixed_len
+ string_len
;
1470 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
1475 p2
= (*rdata
) + fixed_len
; /* auxilliary data (strings) will go here */
1481 char *lastname
=NULL
;
1482 int count2
= counted
;
1484 for (i
= 0; i
< total
&& count2
;i
++) {
1485 struct srv_info_struct
*s
= &servers
[i
];
1487 if (lastname
&& strequal(lastname
,s
->name
)) {
1491 fill_srv_info(s
,uLevel
,&p
,&f_len
,&p2
,&s_len
,*rdata
);
1492 DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
1493 s
->name
, s
->type
, s
->comment
, s
->domain
));
1499 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1503 SSVAL(*rparam
,0,(missed
== 0 ? NERR_Success
: ERRmoredata
));
1505 SSVAL(*rparam
,4,counted
);
1506 SSVAL(*rparam
,6,counted
+missed
);
1510 DEBUG(3,("NetServerEnum domain = %s uLevel=%d counted=%d total=%d\n",
1511 domain
,uLevel
,counted
,counted
+missed
));
1516 /****************************************************************************
1517 command 0x34 - suspected of being a "Lookup Names" stub api
1518 ****************************************************************************/
1520 static bool api_RNetGroupGetUsers(connection_struct
*conn
, uint16 vuid
,
1521 char *param
, int tpscnt
,
1522 char *data
, int tdscnt
,
1523 int mdrcnt
, int mprcnt
, char **rdata
,
1524 char **rparam
, int *rdata_len
, int *rparam_len
)
1526 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
1527 char *str2
= skip_string(param
,tpscnt
,str1
);
1528 char *p
= skip_string(param
,tpscnt
,str2
);
1529 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
1530 int buf_len
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
1534 if (!str1
|| !str2
|| !p
) {
1538 DEBUG(5,("RNetGroupGetUsers: %s %s %s %d %d\n",
1539 str1
, str2
, p
, uLevel
, buf_len
));
1541 if (!prefix_ok(str1
,"zWrLeh")) {
1548 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1553 SSVAL(*rparam
,0,0x08AC); /* informational warning message */
1555 SSVAL(*rparam
,4,counted
);
1556 SSVAL(*rparam
,6,counted
+missed
);
1561 /****************************************************************************
1562 get info about a share
1563 ****************************************************************************/
1565 static bool check_share_info(int uLevel
, char* id
)
1569 if (strcmp(id
,"B13") != 0) {
1574 if (strcmp(id
,"B13BWz") != 0) {
1579 if (strcmp(id
,"B13BWzWWWzB9B") != 0) {
1584 if (strcmp(id
,"B13BWzWWWzB9BB9BWzWWzWW") != 0) {
1594 static int fill_share_info(connection_struct
*conn
, int snum
, int uLevel
,
1595 char** buf
, int* buflen
,
1596 char** stringbuf
, int* stringspace
, char* baseaddr
)
1625 len
+= StrlenExpanded(conn
,snum
,lp_comment(snum
));
1628 len
+= strlen(lp_pathname(snum
)) + 1;
1631 *buflen
= struct_len
;
1636 return struct_len
+ len
;
1641 if ((*buflen
) < struct_len
) {
1649 p2
= p
+ struct_len
;
1650 l2
= (*buflen
) - struct_len
;
1657 push_ascii(p
,lp_servicename(snum
),13, STR_TERMINATE
);
1663 type
= STYPE_DISKTREE
;
1664 if (lp_print_ok(snum
)) {
1665 type
= STYPE_PRINTQ
;
1667 if (strequal("IPC",lp_fstype(snum
))) {
1670 SSVAL(p
,14,type
); /* device type */
1671 SIVAL(p
,16,PTR_DIFF(p2
,baseaddr
));
1672 len
+= CopyExpanded(conn
,snum
,&p2
,lp_comment(snum
),&l2
);
1676 SSVAL(p
,20,ACCESS_READ
|ACCESS_WRITE
|ACCESS_CREATE
); /* permissions */
1677 SSVALS(p
,22,-1); /* max uses */
1678 SSVAL(p
,24,1); /* current uses */
1679 SIVAL(p
,26,PTR_DIFF(p2
,baseaddr
)); /* local pathname */
1680 len
+= CopyAndAdvance(&p2
,lp_pathname(snum
),&l2
);
1681 memset(p
+30,0,SHPWLEN
+2); /* passwd (reserved), pad field */
1685 memset(p
+40,0,SHPWLEN
+2);
1696 (*buf
) = p
+ struct_len
;
1697 (*buflen
) -= struct_len
;
1699 (*stringspace
) = l2
;
1708 static bool api_RNetShareGetInfo(connection_struct
*conn
,uint16 vuid
,
1709 char *param
, int tpscnt
,
1710 char *data
, int tdscnt
,
1711 int mdrcnt
,int mprcnt
,
1712 char **rdata
,char **rparam
,
1713 int *rdata_len
,int *rparam_len
)
1715 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
1716 char *str2
= skip_string(param
,tpscnt
,str1
);
1717 char *netname
= skip_string(param
,tpscnt
,str2
);
1718 char *p
= skip_string(param
,tpscnt
,netname
);
1719 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
1722 if (!str1
|| !str2
|| !netname
|| !p
) {
1726 snum
= find_service(netname
);
1731 /* check it's a supported varient */
1732 if (!prefix_ok(str1
,"zWrLh")) {
1735 if (!check_share_info(uLevel
,str2
)) {
1739 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
1744 *rdata_len
= fill_share_info(conn
,snum
,uLevel
,&p
,&mdrcnt
,0,0,0);
1745 if (*rdata_len
< 0) {
1750 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1754 SSVAL(*rparam
,0,NERR_Success
);
1755 SSVAL(*rparam
,2,0); /* converter word */
1756 SSVAL(*rparam
,4,*rdata_len
);
1761 /****************************************************************************
1762 View the list of available shares.
1764 This function is the server side of the NetShareEnum() RAP call.
1765 It fills the return buffer with share names and share comments.
1766 Note that the return buffer normally (in all known cases) allows only
1767 twelve byte strings for share names (plus one for a nul terminator).
1768 Share names longer than 12 bytes must be skipped.
1769 ****************************************************************************/
1771 static bool api_RNetShareEnum( connection_struct
*conn
, uint16 vuid
,
1772 char *param
, int tpscnt
,
1773 char *data
, int tdscnt
,
1781 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
1782 char *str2
= skip_string(param
,tpscnt
,str1
);
1783 char *p
= skip_string(param
,tpscnt
,str2
);
1784 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
1785 int buf_len
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
1788 int total
=0,counted
=0;
1789 bool missed
= False
;
1791 int data_len
, fixed_len
, string_len
;
1792 int f_len
= 0, s_len
= 0;
1794 if (!str1
|| !str2
|| !p
) {
1798 if (!prefix_ok(str1
,"WrLeh")) {
1801 if (!check_share_info(uLevel
,str2
)) {
1805 /* Ensure all the usershares are loaded. */
1807 load_registry_shares();
1808 count
= load_usershare_shares();
1811 data_len
= fixed_len
= string_len
= 0;
1812 for (i
=0;i
<count
;i
++) {
1813 fstring servicename_dos
;
1814 if (!(lp_browseable(i
) && lp_snum_ok(i
))) {
1817 push_ascii_fstring(servicename_dos
, lp_servicename(i
));
1818 /* Maximum name length = 13. */
1819 if( lp_browseable( i
) && lp_snum_ok( i
) && (strlen(servicename_dos
) < 13)) {
1821 data_len
+= fill_share_info(conn
,i
,uLevel
,0,&f_len
,0,&s_len
,0);
1822 if (data_len
<= buf_len
) {
1825 string_len
+= s_len
;
1832 *rdata_len
= fixed_len
+ string_len
;
1833 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
1838 p2
= (*rdata
) + fixed_len
; /* auxiliary data (strings) will go here */
1843 for( i
= 0; i
< count
; i
++ ) {
1844 fstring servicename_dos
;
1845 if (!(lp_browseable(i
) && lp_snum_ok(i
))) {
1849 push_ascii_fstring(servicename_dos
, lp_servicename(i
));
1850 if (lp_browseable(i
) && lp_snum_ok(i
) && (strlen(servicename_dos
) < 13)) {
1851 if (fill_share_info( conn
,i
,uLevel
,&p
,&f_len
,&p2
,&s_len
,*rdata
) < 0) {
1858 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
1862 SSVAL(*rparam
,0,missed
? ERRmoredata
: NERR_Success
);
1864 SSVAL(*rparam
,4,counted
);
1865 SSVAL(*rparam
,6,total
);
1867 DEBUG(3,("RNetShareEnum gave %d entries of %d (%d %d %d %d)\n",
1868 counted
,total
,uLevel
,
1869 buf_len
,*rdata_len
,mdrcnt
));
1874 /****************************************************************************
1876 ****************************************************************************/
1878 static bool api_RNetShareAdd(connection_struct
*conn
,uint16 vuid
,
1879 char *param
, int tpscnt
,
1880 char *data
, int tdscnt
,
1881 int mdrcnt
,int mprcnt
,
1882 char **rdata
,char **rparam
,
1883 int *rdata_len
,int *rparam_len
)
1885 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
1886 char *str2
= skip_string(param
,tpscnt
,str1
);
1887 char *p
= skip_string(param
,tpscnt
,str2
);
1888 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
1891 char *pathname
= NULL
;
1892 char *command
, *cmdname
;
1893 unsigned int offset
;
1896 size_t converted_size
;
1898 if (!str1
|| !str2
|| !p
) {
1902 /* check it's a supported varient */
1903 if (!prefix_ok(str1
,RAP_WShareAdd_REQ
)) {
1906 if (!check_share_info(uLevel
,str2
)) {
1913 /* Do we have a string ? */
1914 if (skip_string(data
,mdrcnt
,data
) == NULL
) {
1917 pull_ascii_fstring(sharename
,data
);
1918 snum
= find_service(sharename
);
1919 if (snum
>= 0) { /* already exists */
1928 /* only support disk share adds */
1929 if (SVAL(data
,14)!=STYPE_DISKTREE
) {
1933 offset
= IVAL(data
, 16);
1934 if (offset
>= mdrcnt
) {
1935 res
= ERRinvalidparam
;
1939 /* Do we have a string ? */
1940 if (skip_string(data
,mdrcnt
,data
+offset
) == NULL
) {
1943 pull_ascii_fstring(comment
, offset
? (data
+offset
) : "");
1945 offset
= IVAL(data
, 26);
1947 if (offset
>= mdrcnt
) {
1948 res
= ERRinvalidparam
;
1952 /* Do we have a string ? */
1953 if (skip_string(data
,mdrcnt
,data
+offset
) == NULL
) {
1957 if (!pull_ascii_talloc(talloc_tos(), &pathname
,
1958 offset
? (data
+offset
) : "", &converted_size
))
1960 DEBUG(0,("api_RNetShareAdd: pull_ascii_talloc failed: %s",
1968 string_replace(sharename
, '"', ' ');
1969 string_replace(pathname
, '"', ' ');
1970 string_replace(comment
, '"', ' ');
1972 cmdname
= lp_add_share_cmd();
1974 if (!cmdname
|| *cmdname
== '\0') {
1978 if (asprintf(&command
, "%s \"%s\" \"%s\" \"%s\" \"%s\"",
1979 lp_add_share_cmd(), get_dyn_CONFIGFILE(), sharename
,
1980 pathname
, comment
) == -1) {
1984 DEBUG(10,("api_RNetShareAdd: Running [%s]\n", command
));
1986 if ((res
= smbrun(command
, NULL
)) != 0) {
1987 DEBUG(1,("api_RNetShareAdd: Running [%s] returned (%d)\n",
1994 message_send_all(smbd_messaging_context(),
1995 MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
1999 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2003 SSVAL(*rparam
,0,NERR_Success
);
2004 SSVAL(*rparam
,2,0); /* converter word */
2005 SSVAL(*rparam
,4,*rdata_len
);
2013 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2018 SSVAL(*rparam
,0,res
);
2023 /****************************************************************************
2024 view list of groups available
2025 ****************************************************************************/
2027 static bool api_RNetGroupEnum(connection_struct
*conn
,uint16 vuid
,
2028 char *param
, int tpscnt
,
2029 char *data
, int tdscnt
,
2030 int mdrcnt
,int mprcnt
,
2031 char **rdata
,char **rparam
,
2032 int *rdata_len
,int *rparam_len
)
2036 int resume_context
, cli_buf_size
;
2037 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2038 char *str2
= skip_string(param
,tpscnt
,str1
);
2039 char *p
= skip_string(param
,tpscnt
,str2
);
2041 uint32_t num_groups
;
2042 uint32_t resume_handle
;
2043 struct rpc_pipe_client
*samr_pipe
;
2044 struct policy_handle samr_handle
, domain_handle
;
2047 if (!str1
|| !str2
|| !p
) {
2051 if (strcmp(str1
,"WrLeh") != 0) {
2056 * W-> resume context (number of users to skip)
2057 * r -> return parameter pointer to receive buffer
2058 * L -> length of receive buffer
2059 * e -> return parameter number of entries
2060 * h -> return parameter total number of users
2063 if (strcmp("B21",str2
) != 0) {
2067 status
= rpc_pipe_open_internal(
2068 talloc_tos(), &ndr_table_samr
.syntax_id
, rpc_samr_dispatch
,
2069 conn
->server_info
, &samr_pipe
);
2070 if (!NT_STATUS_IS_OK(status
)) {
2071 DEBUG(0, ("api_RNetUserEnum: Could not connect to samr: %s\n",
2072 nt_errstr(status
)));
2076 status
= rpccli_samr_Connect2(samr_pipe
, talloc_tos(), global_myname(),
2077 SAMR_ACCESS_LOOKUP_DOMAIN
, &samr_handle
);
2078 if (!NT_STATUS_IS_OK(status
)) {
2079 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2080 nt_errstr(status
)));
2084 status
= rpccli_samr_OpenDomain(samr_pipe
, talloc_tos(), &samr_handle
,
2085 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
2086 get_global_sam_sid(), &domain_handle
);
2087 if (!NT_STATUS_IS_OK(status
)) {
2088 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2089 nt_errstr(status
)));
2090 rpccli_samr_Close(samr_pipe
, talloc_tos(), &samr_handle
);
2094 resume_context
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2095 cli_buf_size
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
2096 DEBUG(10,("api_RNetGroupEnum:resume context: %d, client buffer size: "
2097 "%d\n", resume_context
, cli_buf_size
));
2099 *rdata_len
= cli_buf_size
;
2100 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2107 errflags
= NERR_Success
;
2112 struct samr_SamArray
*sam_entries
;
2113 uint32_t num_entries
;
2115 status
= rpccli_samr_EnumDomainGroups(samr_pipe
, talloc_tos(),
2120 if (!NT_STATUS_IS_OK(status
)) {
2121 DEBUG(10, ("rpccli_samr_EnumDomainGroups returned "
2122 "%s\n", nt_errstr(status
)));
2126 if (num_entries
== 0) {
2127 DEBUG(10, ("rpccli_samr_EnumDomainGroups returned "
2128 "no entries -- done\n"));
2132 for(i
=0; i
<num_entries
; i
++) {
2135 name
= sam_entries
->entries
[i
].name
.string
;
2137 if( ((PTR_DIFF(p
,*rdata
)+21) > *rdata_len
) ) {
2138 /* set overflow error */
2139 DEBUG(3,("overflow on entry %d group %s\n", i
,
2145 /* truncate the name at 21 chars. */
2147 strlcpy(p
, name
, 21);
2148 DEBUG(10,("adding entry %d group %s\n", i
, p
));
2150 p
+= 5; /* Both NT4 and W2k3SP1 do padding here. No
2155 if (errflags
!= NERR_Success
) {
2159 TALLOC_FREE(sam_entries
);
2162 rpccli_samr_Close(samr_pipe
, talloc_tos(), &domain_handle
);
2163 rpccli_samr_Close(samr_pipe
, talloc_tos(), &samr_handle
);
2165 *rdata_len
= PTR_DIFF(p
,*rdata
);
2168 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2172 SSVAL(*rparam
, 0, errflags
);
2173 SSVAL(*rparam
, 2, 0); /* converter word */
2174 SSVAL(*rparam
, 4, num_groups
); /* is this right?? */
2175 SSVAL(*rparam
, 6, resume_context
+num_groups
); /* is this right?? */
2180 /*******************************************************************
2181 Get groups that a user is a member of.
2182 ******************************************************************/
2184 static bool api_NetUserGetGroups(connection_struct
*conn
,uint16 vuid
,
2185 char *param
, int tpscnt
,
2186 char *data
, int tdscnt
,
2187 int mdrcnt
,int mprcnt
,
2188 char **rdata
,char **rparam
,
2189 int *rdata_len
,int *rparam_len
)
2191 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2192 char *str2
= skip_string(param
,tpscnt
,str1
);
2193 char *UserName
= skip_string(param
,tpscnt
,str2
);
2194 char *p
= skip_string(param
,tpscnt
,UserName
);
2195 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2196 const char *level_string
;
2202 struct rpc_pipe_client
*samr_pipe
;
2203 struct policy_handle samr_handle
, domain_handle
, user_handle
;
2204 struct lsa_String name
;
2205 struct lsa_Strings names
;
2206 struct samr_Ids type
, rid
;
2207 struct samr_RidWithAttributeArray
*rids
;
2210 if (!str1
|| !str2
|| !UserName
|| !p
) {
2215 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2220 /* check it's a supported varient */
2222 if ( strcmp(str1
,"zWrLeh") != 0 )
2227 level_string
= "B21";
2233 if (strcmp(level_string
,str2
) != 0)
2236 *rdata_len
= mdrcnt
+ 1024;
2237 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2242 SSVAL(*rparam
,0,NERR_Success
);
2243 SSVAL(*rparam
,2,0); /* converter word */
2246 endp
= *rdata
+ *rdata_len
;
2248 status
= rpc_pipe_open_internal(
2249 talloc_tos(), &ndr_table_samr
.syntax_id
, rpc_samr_dispatch
,
2250 conn
->server_info
, &samr_pipe
);
2251 if (!NT_STATUS_IS_OK(status
)) {
2252 DEBUG(0, ("api_RNetUserEnum: Could not connect to samr: %s\n",
2253 nt_errstr(status
)));
2257 status
= rpccli_samr_Connect2(samr_pipe
, talloc_tos(), global_myname(),
2258 SAMR_ACCESS_LOOKUP_DOMAIN
, &samr_handle
);
2259 if (!NT_STATUS_IS_OK(status
)) {
2260 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2261 nt_errstr(status
)));
2265 status
= rpccli_samr_OpenDomain(samr_pipe
, talloc_tos(), &samr_handle
,
2266 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
2267 get_global_sam_sid(), &domain_handle
);
2268 if (!NT_STATUS_IS_OK(status
)) {
2269 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2270 nt_errstr(status
)));
2274 name
.string
= UserName
;
2276 status
= rpccli_samr_LookupNames(samr_pipe
, talloc_tos(),
2277 &domain_handle
, 1, &name
,
2279 if (!NT_STATUS_IS_OK(status
)) {
2280 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2281 nt_errstr(status
)));
2285 if (type
.ids
[0] != SID_NAME_USER
) {
2286 DEBUG(10, ("%s is a %s, not a user\n", UserName
,
2287 sid_type_lookup(type
.ids
[0])));
2291 status
= rpccli_samr_OpenUser(samr_pipe
, talloc_tos(),
2293 SAMR_USER_ACCESS_GET_GROUPS
,
2294 rid
.ids
[0], &user_handle
);
2295 if (!NT_STATUS_IS_OK(status
)) {
2296 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2297 nt_errstr(status
)));
2301 status
= rpccli_samr_GetGroupsForUser(samr_pipe
, talloc_tos(),
2302 &user_handle
, &rids
);
2303 if (!NT_STATUS_IS_OK(status
)) {
2304 DEBUG(0, ("api_RNetUserEnum: samr_LookupNames failed: %s\n",
2305 nt_errstr(status
)));
2309 for (i
=0; i
<rids
->count
; i
++) {
2311 status
= rpccli_samr_LookupRids(samr_pipe
, talloc_tos(),
2313 1, &rids
->rids
[i
].rid
,
2315 if (NT_STATUS_IS_OK(status
) && (names
.count
== 1)) {
2316 strlcpy(p
, names
.names
[0].string
, PTR_DIFF(endp
,p
));
2322 *rdata_len
= PTR_DIFF(p
,*rdata
);
2324 SSVAL(*rparam
,4,count
); /* is this right?? */
2325 SSVAL(*rparam
,6,count
); /* is this right?? */
2330 rpccli_samr_Close(samr_pipe
, talloc_tos(), &user_handle
);
2332 rpccli_samr_Close(samr_pipe
, talloc_tos(), &domain_handle
);
2334 rpccli_samr_Close(samr_pipe
, talloc_tos(), &samr_handle
);
2339 /*******************************************************************
2341 ******************************************************************/
2343 static bool api_RNetUserEnum(connection_struct
*conn
, uint16 vuid
,
2344 char *param
, int tpscnt
,
2345 char *data
, int tdscnt
,
2346 int mdrcnt
,int mprcnt
,
2347 char **rdata
,char **rparam
,
2348 int *rdata_len
,int *rparam_len
)
2353 int i
, resume_context
, cli_buf_size
;
2354 uint32_t resume_handle
;
2356 struct rpc_pipe_client
*samr_pipe
;
2357 struct policy_handle samr_handle
, domain_handle
;
2360 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2361 char *str2
= skip_string(param
,tpscnt
,str1
);
2362 char *p
= skip_string(param
,tpscnt
,str2
);
2365 if (!str1
|| !str2
|| !p
) {
2369 if (strcmp(str1
,"WrLeh") != 0)
2372 * W-> resume context (number of users to skip)
2373 * r -> return parameter pointer to receive buffer
2374 * L -> length of receive buffer
2375 * e -> return parameter number of entries
2376 * h -> return parameter total number of users
2379 resume_context
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
2380 cli_buf_size
= get_safe_SVAL(param
,tpscnt
,p
,2,0);
2381 DEBUG(10,("api_RNetUserEnum:resume context: %d, client buffer size: %d\n",
2382 resume_context
, cli_buf_size
));
2385 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2390 /* check it's a supported varient */
2391 if (strcmp("B21",str2
) != 0)
2394 *rdata_len
= cli_buf_size
;
2395 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2401 endp
= *rdata
+ *rdata_len
;
2403 status
= rpc_pipe_open_internal(
2404 talloc_tos(), &ndr_table_samr
.syntax_id
, rpc_samr_dispatch
,
2405 conn
->server_info
, &samr_pipe
);
2406 if (!NT_STATUS_IS_OK(status
)) {
2407 DEBUG(0, ("api_RNetUserEnum: Could not connect to samr: %s\n",
2408 nt_errstr(status
)));
2412 status
= rpccli_samr_Connect2(samr_pipe
, talloc_tos(), global_myname(),
2413 SAMR_ACCESS_LOOKUP_DOMAIN
, &samr_handle
);
2414 if (!NT_STATUS_IS_OK(status
)) {
2415 DEBUG(0, ("api_RNetUserEnum: samr_Connect2 failed: %s\n",
2416 nt_errstr(status
)));
2420 status
= rpccli_samr_OpenDomain(samr_pipe
, talloc_tos(), &samr_handle
,
2421 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
2422 get_global_sam_sid(), &domain_handle
);
2423 if (!NT_STATUS_IS_OK(status
)) {
2424 DEBUG(0, ("api_RNetUserEnum: samr_OpenDomain failed: %s\n",
2425 nt_errstr(status
)));
2426 rpccli_samr_Close(samr_pipe
, talloc_tos(), &samr_handle
);
2430 errflags
=NERR_Success
;
2435 struct samr_SamArray
*sam_entries
;
2436 uint32_t num_entries
;
2438 status
= rpccli_samr_EnumDomainUsers(samr_pipe
, talloc_tos(),
2444 if (!NT_STATUS_IS_OK(status
)) {
2445 DEBUG(10, ("rpccli_samr_EnumDomainUsers returned "
2446 "%s\n", nt_errstr(status
)));
2450 if (num_entries
== 0) {
2451 DEBUG(10, ("rpccli_samr_EnumDomainUsers returned "
2452 "no entries -- done\n"));
2456 for (i
=0; i
<num_entries
; i
++) {
2459 name
= sam_entries
->entries
[i
].name
.string
;
2461 if(((PTR_DIFF(p
,*rdata
)+21)<=*rdata_len
)
2462 &&(strlen(name
)<=21)) {
2463 strlcpy(p
,name
,PTR_DIFF(endp
,p
));
2464 DEBUG(10,("api_RNetUserEnum:adding entry %d "
2465 "username %s\n",count_sent
,p
));
2469 /* set overflow error */
2470 DEBUG(10,("api_RNetUserEnum:overflow on entry %d "
2471 "username %s\n",count_sent
,name
));
2477 if (errflags
!= NERR_Success
) {
2481 TALLOC_FREE(sam_entries
);
2484 rpccli_samr_Close(samr_pipe
, talloc_tos(), &domain_handle
);
2485 rpccli_samr_Close(samr_pipe
, talloc_tos(), &samr_handle
);
2487 *rdata_len
= PTR_DIFF(p
,*rdata
);
2489 SSVAL(*rparam
,0,errflags
);
2490 SSVAL(*rparam
,2,0); /* converter word */
2491 SSVAL(*rparam
,4,count_sent
); /* is this right?? */
2492 SSVAL(*rparam
,6,num_users
); /* is this right?? */
2497 /****************************************************************************
2498 Get the time of day info.
2499 ****************************************************************************/
2501 static bool api_NetRemoteTOD(connection_struct
*conn
,uint16 vuid
,
2502 char *param
, int tpscnt
,
2503 char *data
, int tdscnt
,
2504 int mdrcnt
,int mprcnt
,
2505 char **rdata
,char **rparam
,
2506 int *rdata_len
,int *rparam_len
)
2509 time_t unixdate
= time(NULL
);
2513 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2519 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
2524 SSVAL(*rparam
,0,NERR_Success
);
2525 SSVAL(*rparam
,2,0); /* converter word */
2529 srv_put_dos_date3(p
,0,unixdate
); /* this is the time that is looked at
2530 by NT in a "net time" operation,
2531 it seems to ignore the one below */
2533 /* the client expects to get localtime, not GMT, in this bit
2534 (I think, this needs testing) */
2535 t
= localtime(&unixdate
);
2540 SIVAL(p
,4,0); /* msecs ? */
2541 SCVAL(p
,8,t
->tm_hour
);
2542 SCVAL(p
,9,t
->tm_min
);
2543 SCVAL(p
,10,t
->tm_sec
);
2544 SCVAL(p
,11,0); /* hundredths of seconds */
2545 SSVALS(p
,12,get_time_zone(unixdate
)/60); /* timezone in minutes from GMT */
2546 SSVAL(p
,14,10000); /* timer interval in 0.0001 of sec */
2547 SCVAL(p
,16,t
->tm_mday
);
2548 SCVAL(p
,17,t
->tm_mon
+ 1);
2549 SSVAL(p
,18,1900+t
->tm_year
);
2550 SCVAL(p
,20,t
->tm_wday
);
2555 /****************************************************************************
2556 Set the user password.
2557 *****************************************************************************/
2559 static bool api_SetUserPassword(connection_struct
*conn
,uint16 vuid
,
2560 char *param
, int tpscnt
,
2561 char *data
, int tdscnt
,
2562 int mdrcnt
,int mprcnt
,
2563 char **rdata
,char **rparam
,
2564 int *rdata_len
,int *rparam_len
)
2566 char *np
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2569 fstring pass1
,pass2
;
2571 /* Skip 2 strings. */
2572 p
= skip_string(param
,tpscnt
,np
);
2573 p
= skip_string(param
,tpscnt
,p
);
2579 /* Do we have a string ? */
2580 if (skip_string(param
,tpscnt
,p
) == NULL
) {
2583 pull_ascii_fstring(user
,p
);
2585 p
= skip_string(param
,tpscnt
,p
);
2590 memset(pass1
,'\0',sizeof(pass1
));
2591 memset(pass2
,'\0',sizeof(pass2
));
2593 * We use 31 here not 32 as we're checking
2594 * the last byte we want to access is safe.
2596 if (!is_offset_safe(param
,tpscnt
,p
,31)) {
2600 memcpy(pass2
,p
+16,16);
2603 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2610 SSVAL(*rparam
,0,NERR_badpass
);
2611 SSVAL(*rparam
,2,0); /* converter word */
2613 DEBUG(3,("Set password for <%s>\n",user
));
2616 * Attempt to verify the old password against smbpasswd entries
2617 * Win98 clients send old and new password in plaintext for this call.
2621 auth_serversupplied_info
*server_info
= NULL
;
2622 DATA_BLOB password
= data_blob(pass1
, strlen(pass1
)+1);
2624 if (NT_STATUS_IS_OK(check_plaintext_password(user
,password
,&server_info
))) {
2627 if (NT_STATUS_IS_OK(change_oem_password(server_info
->sam_account
, pass1
, pass2
, False
, NULL
))) {
2628 SSVAL(*rparam
,0,NERR_Success
);
2632 TALLOC_FREE(server_info
);
2634 data_blob_clear_free(&password
);
2638 * If the plaintext change failed, attempt
2639 * the old encrypted method. NT will generate this
2640 * after trying the samr method. Note that this
2641 * method is done as a last resort as this
2642 * password change method loses the NT password hash
2643 * and cannot change the UNIX password as no plaintext
2647 if(SVAL(*rparam
,0) != NERR_Success
) {
2648 struct samu
*hnd
= NULL
;
2650 if (check_lanman_password(user
,(unsigned char *)pass1
,(unsigned char *)pass2
, &hnd
)) {
2652 if (change_lanman_password(hnd
,(uchar
*)pass2
)) {
2653 SSVAL(*rparam
,0,NERR_Success
);
2660 memset((char *)pass1
,'\0',sizeof(fstring
));
2661 memset((char *)pass2
,'\0',sizeof(fstring
));
2666 /****************************************************************************
2667 Set the user password (SamOEM version - gets plaintext).
2668 ****************************************************************************/
2670 static bool api_SamOEMChangePassword(connection_struct
*conn
,uint16 vuid
,
2671 char *param
, int tpscnt
,
2672 char *data
, int tdscnt
,
2673 int mdrcnt
,int mprcnt
,
2674 char **rdata
,char **rparam
,
2675 int *rdata_len
,int *rparam_len
)
2678 char *p
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2680 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2690 SSVAL(*rparam
,0,NERR_badpass
);
2693 * Check the parameter definition is correct.
2696 /* Do we have a string ? */
2697 if (skip_string(param
,tpscnt
,p
) == 0) {
2700 if(!strequal(p
, "zsT")) {
2701 DEBUG(0,("api_SamOEMChangePassword: Invalid parameter string %s\n", p
));
2704 p
= skip_string(param
, tpscnt
, p
);
2709 /* Do we have a string ? */
2710 if (skip_string(param
,tpscnt
,p
) == 0) {
2713 if(!strequal(p
, "B516B16")) {
2714 DEBUG(0,("api_SamOEMChangePassword: Invalid data parameter string %s\n", p
));
2717 p
= skip_string(param
,tpscnt
,p
);
2721 /* Do we have a string ? */
2722 if (skip_string(param
,tpscnt
,p
) == 0) {
2725 p
+= pull_ascii_fstring(user
,p
);
2727 DEBUG(3,("api_SamOEMChangePassword: Change password for <%s>\n",user
));
2730 * Pass the user through the NT -> unix user mapping
2734 (void)map_username(user
);
2736 if (NT_STATUS_IS_OK(pass_oem_change(user
, (uchar
*) data
, (uchar
*)&data
[516], NULL
, NULL
, NULL
))) {
2737 SSVAL(*rparam
,0,NERR_Success
);
2743 /****************************************************************************
2746 ****************************************************************************/
2748 static bool api_RDosPrintJobDel(connection_struct
*conn
,uint16 vuid
,
2749 char *param
, int tpscnt
,
2750 char *data
, int tdscnt
,
2751 int mdrcnt
,int mprcnt
,
2752 char **rdata
,char **rparam
,
2753 int *rdata_len
,int *rparam_len
)
2755 int function
= get_safe_SVAL(param
,tpscnt
,param
,0,0);
2756 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2757 char *str2
= skip_string(param
,tpscnt
,str1
);
2758 char *p
= skip_string(param
,tpscnt
,str2
);
2763 WERROR werr
= WERR_OK
;
2765 if (!str1
|| !str2
|| !p
) {
2769 * We use 1 here not 2 as we're checking
2770 * the last byte we want to access is safe.
2772 if (!is_offset_safe(param
,tpscnt
,p
,1)) {
2775 if(!rap_to_pjobid(SVAL(p
,0), sharename
, &jobid
))
2778 /* check it's a supported varient */
2779 if (!(strcsequal(str1
,"W") && strcsequal(str2
,"")))
2783 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2789 if (!print_job_exists(sharename
, jobid
)) {
2790 errcode
= NERR_JobNotFound
;
2794 snum
= lp_servicenumber( sharename
);
2796 errcode
= NERR_DestNotFound
;
2800 errcode
= NERR_notsupported
;
2803 case 81: /* delete */
2804 if (print_job_delete(conn
->server_info
, snum
, jobid
, &werr
))
2805 errcode
= NERR_Success
;
2807 case 82: /* pause */
2808 if (print_job_pause(conn
->server_info
, snum
, jobid
, &werr
))
2809 errcode
= NERR_Success
;
2811 case 83: /* resume */
2812 if (print_job_resume(conn
->server_info
, snum
, jobid
, &werr
))
2813 errcode
= NERR_Success
;
2817 if (!W_ERROR_IS_OK(werr
))
2818 errcode
= W_ERROR_V(werr
);
2821 SSVAL(*rparam
,0,errcode
);
2822 SSVAL(*rparam
,2,0); /* converter word */
2827 /****************************************************************************
2828 Purge a print queue - or pause or resume it.
2829 ****************************************************************************/
2831 static bool api_WPrintQueueCtrl(connection_struct
*conn
,uint16 vuid
,
2832 char *param
, int tpscnt
,
2833 char *data
, int tdscnt
,
2834 int mdrcnt
,int mprcnt
,
2835 char **rdata
,char **rparam
,
2836 int *rdata_len
,int *rparam_len
)
2838 int function
= get_safe_SVAL(param
,tpscnt
,param
,0,0);
2839 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2840 char *str2
= skip_string(param
,tpscnt
,str1
);
2841 char *QueueName
= skip_string(param
,tpscnt
,str2
);
2842 int errcode
= NERR_notsupported
;
2844 WERROR werr
= WERR_OK
;
2846 if (!str1
|| !str2
|| !QueueName
) {
2850 /* check it's a supported varient */
2851 if (!(strcsequal(str1
,"z") && strcsequal(str2
,"")))
2855 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2861 if (skip_string(param
,tpscnt
,QueueName
) == NULL
) {
2864 snum
= print_queue_snum(QueueName
);
2867 errcode
= NERR_JobNotFound
;
2872 case 74: /* Pause queue */
2873 werr
= print_queue_pause(conn
->server_info
, snum
);
2875 case 75: /* Resume queue */
2876 werr
= print_queue_resume(conn
->server_info
, snum
);
2878 case 103: /* Purge */
2879 werr
= print_queue_purge(conn
->server_info
, snum
);
2882 werr
= WERR_NOT_SUPPORTED
;
2886 errcode
= W_ERROR_V(werr
);
2889 SSVAL(*rparam
,0,errcode
);
2890 SSVAL(*rparam
,2,0); /* converter word */
2895 /****************************************************************************
2896 set the property of a print job (undocumented?)
2897 ? function = 0xb -> set name of print job
2898 ? function = 0x6 -> move print job up/down
2899 Form: <WWsTP> <WWzWWDDzzzzzzzzzzlz>
2900 or <WWsTP> <WB21BB16B10zWWzDDz>
2901 ****************************************************************************/
2903 static int check_printjob_info(struct pack_desc
* desc
,
2904 int uLevel
, char* id
)
2906 desc
->subformat
= NULL
;
2908 case 0: desc
->format
= "W"; break;
2909 case 1: desc
->format
= "WB21BB16B10zWWzDDz"; break;
2910 case 2: desc
->format
= "WWzWWDDzz"; break;
2911 case 3: desc
->format
= "WWzWWDDzzzzzzzzzzlz"; break;
2912 case 4: desc
->format
= "WWzWWDDzzzzzDDDDDDD"; break;
2914 DEBUG(0,("check_printjob_info: invalid level %d\n",
2918 if (id
== NULL
|| strcmp(desc
->format
,id
) != 0) {
2919 DEBUG(0,("check_printjob_info: invalid format %s\n",
2920 id
? id
: "<NULL>" ));
2926 static bool api_PrintJobInfo(connection_struct
*conn
, uint16 vuid
,
2927 char *param
, int tpscnt
,
2928 char *data
, int tdscnt
,
2929 int mdrcnt
,int mprcnt
,
2930 char **rdata
,char **rparam
,
2931 int *rdata_len
,int *rparam_len
)
2933 struct pack_desc desc
;
2934 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
2935 char *str2
= skip_string(param
,tpscnt
,str1
);
2936 char *p
= skip_string(param
,tpscnt
,str2
);
2939 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,2,-1);
2940 int function
= get_safe_SVAL(param
,tpscnt
,p
,4,-1);
2943 if (!str1
|| !str2
|| !p
) {
2947 * We use 1 here not 2 as we're checking
2948 * the last byte we want to access is safe.
2950 if (!is_offset_safe(param
,tpscnt
,p
,1)) {
2953 if(!rap_to_pjobid(SVAL(p
,0), sharename
, &jobid
))
2956 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
2961 if (!share_defined(sharename
)) {
2962 DEBUG(0,("api_PrintJobInfo: sharen [%s] not defined\n",
2969 /* check it's a supported varient */
2970 if ((strcmp(str1
,"WWsTP")) ||
2971 (!check_printjob_info(&desc
,uLevel
,str2
)))
2974 if (!print_job_exists(sharename
, jobid
)) {
2975 errcode
=NERR_JobNotFound
;
2979 errcode
= NERR_notsupported
;
2983 /* change job place in the queue,
2984 data gives the new place */
2985 place
= SVAL(data
,0);
2986 if (print_job_set_place(sharename
, jobid
, place
)) {
2987 errcode
=NERR_Success
;
2992 /* change print job name, data gives the name */
2993 if (print_job_set_name(sharename
, jobid
, data
)) {
2994 errcode
=NERR_Success
;
3003 SSVALS(*rparam
,0,errcode
);
3004 SSVAL(*rparam
,2,0); /* converter word */
3010 /****************************************************************************
3011 Get info about the server.
3012 ****************************************************************************/
3014 static bool api_RNetServerGetInfo(connection_struct
*conn
,uint16 vuid
,
3015 char *param
, int tpscnt
,
3016 char *data
, int tdscnt
,
3017 int mdrcnt
,int mprcnt
,
3018 char **rdata
,char **rparam
,
3019 int *rdata_len
,int *rparam_len
)
3021 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3022 char *str2
= skip_string(param
,tpscnt
,str1
);
3023 char *p
= skip_string(param
,tpscnt
,str2
);
3024 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3028 if (!str1
|| !str2
|| !p
) {
3032 DEBUG(4,("NetServerGetInfo level %d\n",uLevel
));
3034 /* check it's a supported varient */
3035 if (!prefix_ok(str1
,"WrLh")) {
3041 if (strcmp(str2
,"B16") != 0) {
3047 if (strcmp(str2
,"B16BBDz") != 0) {
3053 if (strcmp(str2
,"B16BBDzDDDWWzWWWWWWWBB21zWWWWWWWWWWWWWWWWWWWWWWz")!= 0) {
3059 if (strcmp(str2
,"B16BBDzDDDWWzWWWWWWWBB21zWWWWWWWWWWWWWWWWWWWWWWzDWz") != 0) {
3065 if (strcmp(str2
,"DN") != 0) {
3071 if (strcmp(str2
,"B16BBDzWWzzz") != 0) {
3080 *rdata_len
= mdrcnt
;
3081 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
3087 p2
= p
+ struct_len
;
3089 srvstr_push(NULL
, 0, p
,global_myname(),16,
3090 STR_ASCII
|STR_UPPER
|STR_TERMINATE
);
3094 struct srv_info_struct
*servers
=NULL
;
3096 char *comment
= NULL
;
3097 TALLOC_CTX
*ctx
= talloc_tos();
3098 uint32 servertype
= lp_default_server_announce();
3100 comment
= talloc_strdup(ctx
,lp_serverstring());
3105 if ((count
=get_server_info(SV_TYPE_ALL
,&servers
,lp_workgroup()))>0) {
3106 for (i
=0;i
<count
;i
++) {
3107 if (strequal(servers
[i
].name
,global_myname())) {
3108 servertype
= servers
[i
].type
;
3109 TALLOC_FREE(comment
);
3110 comment
= talloc_strdup(ctx
,
3111 servers
[i
].comment
);
3121 SCVAL(p
,0,lp_major_announce_version());
3122 SCVAL(p
,1,lp_minor_announce_version());
3123 SIVAL(p
,2,servertype
);
3125 if (mdrcnt
== struct_len
) {
3128 SIVAL(p
,6,PTR_DIFF(p2
,*rdata
));
3129 comment
= talloc_sub_advanced(
3131 lp_servicename(SNUM(conn
)),
3132 conn
->server_info
->unix_name
,
3134 conn
->server_info
->utok
.gid
,
3135 conn
->server_info
->sanitized_username
,
3136 pdb_get_domain(conn
->server_info
->sam_account
),
3141 if (mdrcnt
- struct_len
<= 0) {
3146 MIN(mdrcnt
- struct_len
,
3147 MAX_SERVER_STRING_LENGTH
),
3149 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3157 return False
; /* not yet implemented */
3160 *rdata_len
= PTR_DIFF(p2
,*rdata
);
3163 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3167 SSVAL(*rparam
,0,NERR_Success
);
3168 SSVAL(*rparam
,2,0); /* converter word */
3169 SSVAL(*rparam
,4,*rdata_len
);
3174 /****************************************************************************
3175 Get info about the server.
3176 ****************************************************************************/
3178 static bool api_NetWkstaGetInfo(connection_struct
*conn
,uint16 vuid
,
3179 char *param
, int tpscnt
,
3180 char *data
, int tdscnt
,
3181 int mdrcnt
,int mprcnt
,
3182 char **rdata
,char **rparam
,
3183 int *rdata_len
,int *rparam_len
)
3185 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3186 char *str2
= skip_string(param
,tpscnt
,str1
);
3187 char *p
= skip_string(param
,tpscnt
,str2
);
3190 int level
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3192 if (!str1
|| !str2
|| !p
) {
3196 DEBUG(4,("NetWkstaGetInfo level %d\n",level
));
3199 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3204 /* check it's a supported varient */
3205 if (!(level
==10 && strcsequal(str1
,"WrLh") && strcsequal(str2
,"zzzBBzz"))) {
3209 *rdata_len
= mdrcnt
+ 1024;
3210 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
3215 SSVAL(*rparam
,0,NERR_Success
);
3216 SSVAL(*rparam
,2,0); /* converter word */
3219 endp
= *rdata
+ *rdata_len
;
3221 p2
= get_safe_ptr(*rdata
,*rdata_len
,p
,22);
3226 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
)); /* host name */
3227 strlcpy(p2
,get_local_machine_name(),PTR_DIFF(endp
,p2
));
3229 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3235 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
));
3236 strlcpy(p2
,conn
->server_info
->sanitized_username
,PTR_DIFF(endp
,p2
));
3237 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3243 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
)); /* login domain */
3244 strlcpy(p2
,lp_workgroup(),PTR_DIFF(endp
,p2
));
3246 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3252 SCVAL(p
,0,lp_major_announce_version()); /* system version - e.g 4 in 4.1 */
3253 SCVAL(p
,1,lp_minor_announce_version()); /* system version - e.g .1 in 4.1 */
3256 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
));
3257 strlcpy(p2
,lp_workgroup(),PTR_DIFF(endp
,p2
)); /* don't know. login domain?? */
3258 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3264 SIVAL(p
,0,PTR_DIFF(p2
,*rdata
)); /* don't know */
3265 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
3266 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3272 *rdata_len
= PTR_DIFF(p2
,*rdata
);
3274 SSVAL(*rparam
,4,*rdata_len
);
3279 /****************************************************************************
3280 get info about a user
3282 struct user_info_11 {
3283 char usri11_name[21]; 0-20
3285 char *usri11_comment; 22-25
3286 char *usri11_usr_comment; 26-29
3287 unsigned short usri11_priv; 30-31
3288 unsigned long usri11_auth_flags; 32-35
3289 long usri11_password_age; 36-39
3290 char *usri11_homedir; 40-43
3291 char *usri11_parms; 44-47
3292 long usri11_last_logon; 48-51
3293 long usri11_last_logoff; 52-55
3294 unsigned short usri11_bad_pw_count; 56-57
3295 unsigned short usri11_num_logons; 58-59
3296 char *usri11_logon_server; 60-63
3297 unsigned short usri11_country_code; 64-65
3298 char *usri11_workstations; 66-69
3299 unsigned long usri11_max_storage; 70-73
3300 unsigned short usri11_units_per_week; 74-75
3301 unsigned char *usri11_logon_hours; 76-79
3302 unsigned short usri11_code_page; 80-81
3307 usri11_name specifies the user name for which information is retrieved
3309 usri11_pad aligns the next data structure element to a word boundary
3311 usri11_comment is a null terminated ASCII comment
3313 usri11_user_comment is a null terminated ASCII comment about the user
3315 usri11_priv specifies the level of the privilege assigned to the user.
3316 The possible values are:
3318 Name Value Description
3319 USER_PRIV_GUEST 0 Guest privilege
3320 USER_PRIV_USER 1 User privilege
3321 USER_PRV_ADMIN 2 Administrator privilege
3323 usri11_auth_flags specifies the account operator privileges. The
3324 possible values are:
3326 Name Value Description
3327 AF_OP_PRINT 0 Print operator
3330 Leach, Naik [Page 28]
3334 INTERNET-DRAFT CIFS Remote Admin Protocol January 10, 1997
3337 AF_OP_COMM 1 Communications operator
3338 AF_OP_SERVER 2 Server operator
3339 AF_OP_ACCOUNTS 3 Accounts operator
3342 usri11_password_age specifies how many seconds have elapsed since the
3343 password was last changed.
3345 usri11_home_dir points to a null terminated ASCII string that contains
3346 the path name of the user's home directory.
3348 usri11_parms points to a null terminated ASCII string that is set
3349 aside for use by applications.
3351 usri11_last_logon specifies the time when the user last logged on.
3352 This value is stored as the number of seconds elapsed since
3353 00:00:00, January 1, 1970.
3355 usri11_last_logoff specifies the time when the user last logged off.
3356 This value is stored as the number of seconds elapsed since
3357 00:00:00, January 1, 1970. A value of 0 means the last logoff
3360 usri11_bad_pw_count specifies the number of incorrect passwords
3361 entered since the last successful logon.
3363 usri11_log1_num_logons specifies the number of times this user has
3364 logged on. A value of -1 means the number of logons is unknown.
3366 usri11_logon_server points to a null terminated ASCII string that
3367 contains the name of the server to which logon requests are sent.
3368 A null string indicates logon requests should be sent to the
3371 usri11_country_code specifies the country code for the user's language
3374 usri11_workstations points to a null terminated ASCII string that
3375 contains the names of workstations the user may log on from.
3376 There may be up to 8 workstations, with the names separated by
3377 commas. A null strings indicates there are no restrictions.
3379 usri11_max_storage specifies the maximum amount of disk space the user
3380 can occupy. A value of 0xffffffff indicates there are no
3383 usri11_units_per_week specifies the equal number of time units into
3384 which a week is divided. This value must be equal to 168.
3386 usri11_logon_hours points to a 21 byte (168 bits) string that
3387 specifies the time during which the user can log on. Each bit
3388 represents one unique hour in a week. The first bit (bit 0, word
3389 0) is Sunday, 0:00 to 0:59, the second bit (bit 1, word 0) is
3393 Leach, Naik [Page 29]
3397 INTERNET-DRAFT CIFS Remote Admin Protocol January 10, 1997
3400 Sunday, 1:00 to 1:59 and so on. A null pointer indicates there
3401 are no restrictions.
3403 usri11_code_page specifies the code page for the user's language of
3406 All of the pointers in this data structure need to be treated
3407 specially. The pointer is a 32 bit pointer. The higher 16 bits need
3408 to be ignored. The converter word returned in the parameters section
3409 needs to be subtracted from the lower 16 bits to calculate an offset
3410 into the return buffer where this ASCII string resides.
3412 There is no auxiliary data in the response.
3414 ****************************************************************************/
3416 #define usri11_name 0
3417 #define usri11_pad 21
3418 #define usri11_comment 22
3419 #define usri11_usr_comment 26
3420 #define usri11_full_name 30
3421 #define usri11_priv 34
3422 #define usri11_auth_flags 36
3423 #define usri11_password_age 40
3424 #define usri11_homedir 44
3425 #define usri11_parms 48
3426 #define usri11_last_logon 52
3427 #define usri11_last_logoff 56
3428 #define usri11_bad_pw_count 60
3429 #define usri11_num_logons 62
3430 #define usri11_logon_server 64
3431 #define usri11_country_code 68
3432 #define usri11_workstations 70
3433 #define usri11_max_storage 74
3434 #define usri11_units_per_week 78
3435 #define usri11_logon_hours 80
3436 #define usri11_code_page 84
3437 #define usri11_end 86
3439 #define USER_PRIV_GUEST 0
3440 #define USER_PRIV_USER 1
3441 #define USER_PRIV_ADMIN 2
3443 #define AF_OP_PRINT 0
3444 #define AF_OP_COMM 1
3445 #define AF_OP_SERVER 2
3446 #define AF_OP_ACCOUNTS 3
3449 static bool api_RNetUserGetInfo(connection_struct
*conn
, uint16 vuid
,
3450 char *param
, int tpscnt
,
3451 char *data
, int tdscnt
,
3452 int mdrcnt
,int mprcnt
,
3453 char **rdata
,char **rparam
,
3454 int *rdata_len
,int *rparam_len
)
3456 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3457 char *str2
= skip_string(param
,tpscnt
,str1
);
3458 char *UserName
= skip_string(param
,tpscnt
,str2
);
3459 char *p
= skip_string(param
,tpscnt
,UserName
);
3460 int uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3463 const char *level_string
;
3465 /* get NIS home of a previously validated user - simeon */
3466 /* With share level security vuid will always be zero.
3467 Don't depend on vuser being non-null !!. JRA */
3468 user_struct
*vuser
= get_valid_user_struct(vuid
);
3470 DEBUG(3,(" Username of UID %d is %s\n",
3471 (int)vuser
->server_info
->utok
.uid
,
3472 vuser
->server_info
->unix_name
));
3475 if (!str1
|| !str2
|| !UserName
|| !p
) {
3480 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3485 DEBUG(4,("RNetUserGetInfo level=%d\n", uLevel
));
3487 /* check it's a supported variant */
3488 if (strcmp(str1
,"zWrLh") != 0) {
3492 case 0: level_string
= "B21"; break;
3493 case 1: level_string
= "B21BB16DWzzWz"; break;
3494 case 2: level_string
= "B21BB16DWzzWzDzzzzDDDDWb21WWzWW"; break;
3495 case 10: level_string
= "B21Bzzz"; break;
3496 case 11: level_string
= "B21BzzzWDDzzDDWWzWzDWb21W"; break;
3497 default: return False
;
3500 if (strcmp(level_string
,str2
) != 0) {
3504 *rdata_len
= mdrcnt
+ 1024;
3505 *rdata
= smb_realloc_limit(*rdata
,*rdata_len
);
3510 SSVAL(*rparam
,0,NERR_Success
);
3511 SSVAL(*rparam
,2,0); /* converter word */
3514 endp
= *rdata
+ *rdata_len
;
3515 p2
= get_safe_ptr(*rdata
,*rdata_len
,p
,usri11_end
);
3521 fstrcpy(p
+usri11_name
,UserName
); /* 21 bytes - user name */
3524 SCVAL(p
,usri11_pad
,0); /* padding - 1 byte */
3529 SIVAL(p
,usri11_comment
,PTR_DIFF(p2
,p
)); /* comment */
3530 strlcpy(p2
,"Comment",PTR_DIFF(endp
,p2
));
3531 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3536 SIVAL(p
,usri11_usr_comment
,PTR_DIFF(p2
,p
)); /* user_comment */
3537 strlcpy(p2
,"UserComment",PTR_DIFF(endp
,p2
));
3538 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3543 /* EEK! the cifsrap.txt doesn't have this in!!!! */
3544 SIVAL(p
,usri11_full_name
,PTR_DIFF(p2
,p
)); /* full name */
3545 strlcpy(p2
,((vuser
!= NULL
)
3546 ? pdb_get_fullname(vuser
->server_info
->sam_account
)
3547 : UserName
),PTR_DIFF(endp
,p2
));
3548 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3555 const char *homedir
= "";
3556 if (vuser
!= NULL
) {
3557 homedir
= pdb_get_homedir(
3558 vuser
->server_info
->sam_account
);
3560 /* modelled after NTAS 3.51 reply */
3561 SSVAL(p
,usri11_priv
,conn
->admin_user
?USER_PRIV_ADMIN
:USER_PRIV_USER
);
3562 SIVAL(p
,usri11_auth_flags
,AF_OP_PRINT
); /* auth flags */
3563 SIVALS(p
,usri11_password_age
,-1); /* password age */
3564 SIVAL(p
,usri11_homedir
,PTR_DIFF(p2
,p
)); /* home dir */
3565 strlcpy(p2
, homedir
, PTR_DIFF(endp
,p2
));
3566 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3570 SIVAL(p
,usri11_parms
,PTR_DIFF(p2
,p
)); /* parms */
3571 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
3572 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3576 SIVAL(p
,usri11_last_logon
,0); /* last logon */
3577 SIVAL(p
,usri11_last_logoff
,0); /* last logoff */
3578 SSVALS(p
,usri11_bad_pw_count
,-1); /* bad pw counts */
3579 SSVALS(p
,usri11_num_logons
,-1); /* num logons */
3580 SIVAL(p
,usri11_logon_server
,PTR_DIFF(p2
,p
)); /* logon server */
3581 strlcpy(p2
,"\\\\*",PTR_DIFF(endp
,p2
));
3582 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3586 SSVAL(p
,usri11_country_code
,0); /* country code */
3588 SIVAL(p
,usri11_workstations
,PTR_DIFF(p2
,p
)); /* workstations */
3589 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
3590 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3595 SIVALS(p
,usri11_max_storage
,-1); /* max storage */
3596 SSVAL(p
,usri11_units_per_week
,168); /* units per week */
3597 SIVAL(p
,usri11_logon_hours
,PTR_DIFF(p2
,p
)); /* logon hours */
3599 /* a simple way to get logon hours at all times. */
3601 SCVAL(p2
,21,0); /* fix zero termination */
3602 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3607 SSVAL(p
,usri11_code_page
,0); /* code page */
3610 if (uLevel
== 1 || uLevel
== 2) {
3611 memset(p
+22,' ',16); /* password */
3612 SIVALS(p
,38,-1); /* password age */
3614 conn
->admin_user
?USER_PRIV_ADMIN
:USER_PRIV_USER
);
3615 SIVAL(p
,44,PTR_DIFF(p2
,*rdata
)); /* home dir */
3616 strlcpy(p2
, vuser
? pdb_get_homedir(
3617 vuser
->server_info
->sam_account
) : "",
3619 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3623 SIVAL(p
,48,PTR_DIFF(p2
,*rdata
)); /* comment */
3625 SSVAL(p
,52,0); /* flags */
3626 SIVAL(p
,54,PTR_DIFF(p2
,*rdata
)); /* script_path */
3627 strlcpy(p2
, vuser
? pdb_get_logon_script(
3628 vuser
->server_info
->sam_account
) : "",
3630 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3635 SIVAL(p
,60,0); /* auth_flags */
3636 SIVAL(p
,64,PTR_DIFF(p2
,*rdata
)); /* full_name */
3637 strlcpy(p2
,((vuser
!= NULL
)
3638 ? pdb_get_fullname(vuser
->server_info
->sam_account
)
3639 : UserName
),PTR_DIFF(endp
,p2
));
3640 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3644 SIVAL(p
,68,0); /* urs_comment */
3645 SIVAL(p
,72,PTR_DIFF(p2
,*rdata
)); /* parms */
3646 strlcpy(p2
,"",PTR_DIFF(endp
,p2
));
3647 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3651 SIVAL(p
,76,0); /* workstations */
3652 SIVAL(p
,80,0); /* last_logon */
3653 SIVAL(p
,84,0); /* last_logoff */
3654 SIVALS(p
,88,-1); /* acct_expires */
3655 SIVALS(p
,92,-1); /* max_storage */
3656 SSVAL(p
,96,168); /* units_per_week */
3657 SIVAL(p
,98,PTR_DIFF(p2
,*rdata
)); /* logon_hours */
3660 SSVALS(p
,102,-1); /* bad_pw_count */
3661 SSVALS(p
,104,-1); /* num_logons */
3662 SIVAL(p
,106,PTR_DIFF(p2
,*rdata
)); /* logon_server */
3664 TALLOC_CTX
*ctx
= talloc_tos();
3665 int space_rem
= *rdata_len
- (p2
- *rdata
);
3668 if (space_rem
<= 0) {
3671 tmp
= talloc_strdup(ctx
, "\\\\%L");
3675 tmp
= talloc_sub_basic(ctx
,
3688 p2
= skip_string(*rdata
,*rdata_len
,p2
);
3692 SSVAL(p
,110,49); /* country_code */
3693 SSVAL(p
,112,860); /* code page */
3697 *rdata_len
= PTR_DIFF(p2
,*rdata
);
3699 SSVAL(*rparam
,4,*rdata_len
); /* is this right?? */
3704 static bool api_WWkstaUserLogon(connection_struct
*conn
,uint16 vuid
,
3705 char *param
, int tpscnt
,
3706 char *data
, int tdscnt
,
3707 int mdrcnt
,int mprcnt
,
3708 char **rdata
,char **rparam
,
3709 int *rdata_len
,int *rparam_len
)
3711 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3712 char *str2
= skip_string(param
,tpscnt
,str1
);
3713 char *p
= skip_string(param
,tpscnt
,str2
);
3715 struct pack_desc desc
;
3717 /* With share level security vuid will always be zero.
3718 Don't depend on vuser being non-null !!. JRA */
3719 user_struct
*vuser
= get_valid_user_struct(vuid
);
3721 if (!str1
|| !str2
|| !p
) {
3726 DEBUG(3,(" Username of UID %d is %s\n",
3727 (int)vuser
->server_info
->utok
.uid
,
3728 vuser
->server_info
->unix_name
));
3731 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3732 name
= get_safe_str_ptr(param
,tpscnt
,p
,2);
3737 memset((char *)&desc
,'\0',sizeof(desc
));
3739 DEBUG(3,("WWkstaUserLogon uLevel=%d name=%s\n",uLevel
,name
));
3741 /* check it's a supported varient */
3742 if (strcmp(str1
,"OOWb54WrLh") != 0) {
3745 if (uLevel
!= 1 || strcmp(str2
,"WB21BWDWWDDDDDDDzzzD") != 0) {
3749 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
3756 desc
.buflen
= mdrcnt
;
3757 desc
.subformat
= NULL
;
3760 if (init_package(&desc
,1,0)) {
3761 PACKI(&desc
,"W",0); /* code */
3762 PACKS(&desc
,"B21",name
); /* eff. name */
3763 PACKS(&desc
,"B",""); /* pad */
3764 PACKI(&desc
,"W", conn
->admin_user
?USER_PRIV_ADMIN
:USER_PRIV_USER
);
3765 PACKI(&desc
,"D",0); /* auth flags XXX */
3766 PACKI(&desc
,"W",0); /* num logons */
3767 PACKI(&desc
,"W",0); /* bad pw count */
3768 PACKI(&desc
,"D",0); /* last logon */
3769 PACKI(&desc
,"D",-1); /* last logoff */
3770 PACKI(&desc
,"D",-1); /* logoff time */
3771 PACKI(&desc
,"D",-1); /* kickoff time */
3772 PACKI(&desc
,"D",0); /* password age */
3773 PACKI(&desc
,"D",0); /* password can change */
3774 PACKI(&desc
,"D",-1); /* password must change */
3778 fstrcpy(mypath
,"\\\\");
3779 fstrcat(mypath
,get_local_machine_name());
3781 PACKS(&desc
,"z",mypath
); /* computer */
3784 PACKS(&desc
,"z",lp_workgroup());/* domain */
3785 PACKS(&desc
,"z", vuser
? pdb_get_logon_script(
3786 vuser
->server_info
->sam_account
) : ""); /* script path */
3787 PACKI(&desc
,"D",0x00000000); /* reserved */
3790 *rdata_len
= desc
.usedlen
;
3792 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3796 SSVALS(*rparam
,0,desc
.errcode
);
3798 SSVAL(*rparam
,4,desc
.neededlen
);
3800 DEBUG(4,("WWkstaUserLogon: errorcode %d\n",desc
.errcode
));
3805 /****************************************************************************
3806 api_WAccessGetUserPerms
3807 ****************************************************************************/
3809 static bool api_WAccessGetUserPerms(connection_struct
*conn
,uint16 vuid
,
3810 char *param
, int tpscnt
,
3811 char *data
, int tdscnt
,
3812 int mdrcnt
,int mprcnt
,
3813 char **rdata
,char **rparam
,
3814 int *rdata_len
,int *rparam_len
)
3816 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3817 char *str2
= skip_string(param
,tpscnt
,str1
);
3818 char *user
= skip_string(param
,tpscnt
,str2
);
3819 char *resource
= skip_string(param
,tpscnt
,user
);
3821 if (!str1
|| !str2
|| !user
|| !resource
) {
3825 if (skip_string(param
,tpscnt
,resource
) == NULL
) {
3828 DEBUG(3,("WAccessGetUserPerms user=%s resource=%s\n",user
,resource
));
3830 /* check it's a supported varient */
3831 if (strcmp(str1
,"zzh") != 0) {
3834 if (strcmp(str2
,"") != 0) {
3839 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3843 SSVALS(*rparam
,0,0); /* errorcode */
3844 SSVAL(*rparam
,2,0); /* converter word */
3845 SSVAL(*rparam
,4,0x7f); /* permission flags */
3850 /****************************************************************************
3851 api_WPrintJobEnumerate
3852 ****************************************************************************/
3854 static bool api_WPrintJobGetInfo(connection_struct
*conn
, uint16 vuid
,
3855 char *param
, int tpscnt
,
3856 char *data
, int tdscnt
,
3857 int mdrcnt
,int mprcnt
,
3858 char **rdata
,char **rparam
,
3859 int *rdata_len
,int *rparam_len
)
3861 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3862 char *str2
= skip_string(param
,tpscnt
,str1
);
3863 char *p
= skip_string(param
,tpscnt
,str2
);
3870 struct pack_desc desc
;
3871 print_queue_struct
*queue
=NULL
;
3872 print_status_struct status
;
3875 if (!str1
|| !str2
|| !p
) {
3879 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,2,-1);
3881 memset((char *)&desc
,'\0',sizeof(desc
));
3882 memset((char *)&status
,'\0',sizeof(status
));
3884 DEBUG(3,("WPrintJobGetInfo uLevel=%d uJobId=0x%X\n",uLevel
,SVAL(p
,0)));
3886 /* check it's a supported varient */
3887 if (strcmp(str1
,"WWrLh") != 0) {
3890 if (!check_printjob_info(&desc
,uLevel
,str2
)) {
3894 if(!rap_to_pjobid(SVAL(p
,0), sharename
, &jobid
)) {
3898 snum
= lp_servicenumber( sharename
);
3899 if (snum
< 0 || !VALID_SNUM(snum
)) {
3903 count
= print_queue_status(snum
,&queue
,&status
);
3904 for (i
= 0; i
< count
; i
++) {
3905 if (queue
[i
].job
== jobid
) {
3911 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
3916 desc
.buflen
= mdrcnt
;
3919 * Don't return data but need to get correct length
3920 * init_package will return wrong size if buflen=0
3922 desc
.buflen
= getlen(desc
.format
);
3923 desc
.base
= tmpdata
= (char *)SMB_MALLOC( desc
.buflen
);
3926 if (init_package(&desc
,1,0)) {
3928 fill_printjob_info(conn
,snum
,uLevel
,&desc
,&queue
[i
],i
);
3929 *rdata_len
= desc
.usedlen
;
3931 desc
.errcode
= NERR_JobNotFound
;
3937 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
3941 SSVALS(*rparam
,0,desc
.errcode
);
3943 SSVAL(*rparam
,4,desc
.neededlen
);
3948 DEBUG(4,("WPrintJobGetInfo: errorcode %d\n",desc
.errcode
));
3953 static bool api_WPrintJobEnumerate(connection_struct
*conn
, uint16 vuid
,
3954 char *param
, int tpscnt
,
3955 char *data
, int tdscnt
,
3956 int mdrcnt
,int mprcnt
,
3957 char **rdata
,char **rparam
,
3958 int *rdata_len
,int *rparam_len
)
3960 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
3961 char *str2
= skip_string(param
,tpscnt
,str1
);
3962 char *p
= skip_string(param
,tpscnt
,str2
);
3968 struct pack_desc desc
;
3969 print_queue_struct
*queue
=NULL
;
3970 print_status_struct status
;
3972 if (!str1
|| !str2
|| !p
) {
3976 memset((char *)&desc
,'\0',sizeof(desc
));
3977 memset((char *)&status
,'\0',sizeof(status
));
3979 p
= skip_string(param
,tpscnt
,p
);
3983 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
3985 DEBUG(3,("WPrintJobEnumerate uLevel=%d name=%s\n",uLevel
,name
));
3987 /* check it's a supported variant */
3988 if (strcmp(str1
,"zWrLeh") != 0) {
3993 return False
; /* defined only for uLevel 0,1,2 */
3996 if (!check_printjob_info(&desc
,uLevel
,str2
)) {
4000 snum
= find_service(name
);
4001 if ( !(lp_snum_ok(snum
) && lp_print_ok(snum
)) ) {
4005 count
= print_queue_status(snum
,&queue
,&status
);
4007 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4013 desc
.buflen
= mdrcnt
;
4015 if (init_package(&desc
,count
,0)) {
4017 for (i
= 0; i
< count
; i
++) {
4018 fill_printjob_info(conn
,snum
,uLevel
,&desc
,&queue
[i
],i
);
4019 if (desc
.errcode
== NERR_Success
) {
4025 *rdata_len
= desc
.usedlen
;
4028 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4032 SSVALS(*rparam
,0,desc
.errcode
);
4034 SSVAL(*rparam
,4,succnt
);
4035 SSVAL(*rparam
,6,count
);
4039 DEBUG(4,("WPrintJobEnumerate: errorcode %d\n",desc
.errcode
));
4044 static int check_printdest_info(struct pack_desc
* desc
,
4045 int uLevel
, char* id
)
4047 desc
->subformat
= NULL
;
4050 desc
->format
= "B9";
4053 desc
->format
= "B9B21WWzW";
4059 desc
->format
= "zzzWWzzzWW";
4062 DEBUG(0,("check_printdest_info: invalid level %d\n",
4066 if (id
== NULL
|| strcmp(desc
->format
,id
) != 0) {
4067 DEBUG(0,("check_printdest_info: invalid string %s\n",
4068 id
? id
: "<NULL>" ));
4074 static void fill_printdest_info(connection_struct
*conn
, int snum
, int uLevel
,
4075 struct pack_desc
* desc
)
4079 strncpy(buf
,SERVICE(snum
),sizeof(buf
)-1);
4080 buf
[sizeof(buf
)-1] = 0;
4084 PACKS(desc
,"B9",buf
); /* szName */
4086 PACKS(desc
,"B21",""); /* szUserName */
4087 PACKI(desc
,"W",0); /* uJobId */
4088 PACKI(desc
,"W",0); /* fsStatus */
4089 PACKS(desc
,"z",""); /* pszStatus */
4090 PACKI(desc
,"W",0); /* time */
4094 if (uLevel
== 2 || uLevel
== 3) {
4095 PACKS(desc
,"z",buf
); /* pszPrinterName */
4097 PACKS(desc
,"z",""); /* pszUserName */
4098 PACKS(desc
,"z",""); /* pszLogAddr */
4099 PACKI(desc
,"W",0); /* uJobId */
4100 PACKI(desc
,"W",0); /* fsStatus */
4101 PACKS(desc
,"z",""); /* pszStatus */
4102 PACKS(desc
,"z",""); /* pszComment */
4103 PACKS(desc
,"z","NULL"); /* pszDrivers */
4104 PACKI(desc
,"W",0); /* time */
4105 PACKI(desc
,"W",0); /* pad1 */
4110 static bool api_WPrintDestGetInfo(connection_struct
*conn
, uint16 vuid
,
4111 char *param
, int tpscnt
,
4112 char *data
, int tdscnt
,
4113 int mdrcnt
,int mprcnt
,
4114 char **rdata
,char **rparam
,
4115 int *rdata_len
,int *rparam_len
)
4117 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4118 char *str2
= skip_string(param
,tpscnt
,str1
);
4119 char *p
= skip_string(param
,tpscnt
,str2
);
4120 char* PrinterName
= p
;
4122 struct pack_desc desc
;
4126 if (!str1
|| !str2
|| !p
) {
4130 memset((char *)&desc
,'\0',sizeof(desc
));
4132 p
= skip_string(param
,tpscnt
,p
);
4136 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4138 DEBUG(3,("WPrintDestGetInfo uLevel=%d PrinterName=%s\n",uLevel
,PrinterName
));
4140 /* check it's a supported varient */
4141 if (strcmp(str1
,"zWrLh") != 0) {
4144 if (!check_printdest_info(&desc
,uLevel
,str2
)) {
4148 snum
= find_service(PrinterName
);
4149 if ( !(lp_snum_ok(snum
) && lp_print_ok(snum
)) ) {
4151 desc
.errcode
= NERR_DestNotFound
;
4155 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4160 desc
.buflen
= mdrcnt
;
4163 * Don't return data but need to get correct length
4164 * init_package will return wrong size if buflen=0
4166 desc
.buflen
= getlen(desc
.format
);
4167 desc
.base
= tmpdata
= (char *)SMB_MALLOC( desc
.buflen
);
4169 if (init_package(&desc
,1,0)) {
4170 fill_printdest_info(conn
,snum
,uLevel
,&desc
);
4172 *rdata_len
= desc
.usedlen
;
4176 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4180 SSVALS(*rparam
,0,desc
.errcode
);
4182 SSVAL(*rparam
,4,desc
.neededlen
);
4184 DEBUG(4,("WPrintDestGetInfo: errorcode %d\n",desc
.errcode
));
4190 static bool api_WPrintDestEnum(connection_struct
*conn
, uint16 vuid
,
4191 char *param
, int tpscnt
,
4192 char *data
, int tdscnt
,
4193 int mdrcnt
,int mprcnt
,
4194 char **rdata
,char **rparam
,
4195 int *rdata_len
,int *rparam_len
)
4197 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4198 char *str2
= skip_string(param
,tpscnt
,str1
);
4199 char *p
= skip_string(param
,tpscnt
,str2
);
4203 struct pack_desc desc
;
4204 int services
= lp_numservices();
4206 if (!str1
|| !str2
|| !p
) {
4210 memset((char *)&desc
,'\0',sizeof(desc
));
4212 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4214 DEBUG(3,("WPrintDestEnum uLevel=%d\n",uLevel
));
4216 /* check it's a supported varient */
4217 if (strcmp(str1
,"WrLeh") != 0) {
4220 if (!check_printdest_info(&desc
,uLevel
,str2
)) {
4225 for (i
= 0; i
< services
; i
++) {
4226 if (lp_snum_ok(i
) && lp_print_ok(i
) && lp_browseable(i
)) {
4232 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4239 desc
.buflen
= mdrcnt
;
4240 if (init_package(&desc
,queuecnt
,0)) {
4243 for (i
= 0; i
< services
; i
++) {
4244 if (lp_snum_ok(i
) && lp_print_ok(i
) && lp_browseable(i
)) {
4245 fill_printdest_info(conn
,i
,uLevel
,&desc
);
4247 if (desc
.errcode
== NERR_Success
) {
4254 *rdata_len
= desc
.usedlen
;
4257 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4261 SSVALS(*rparam
,0,desc
.errcode
);
4263 SSVAL(*rparam
,4,succnt
);
4264 SSVAL(*rparam
,6,queuecnt
);
4266 DEBUG(4,("WPrintDestEnumerate: errorcode %d\n",desc
.errcode
));
4271 static bool api_WPrintDriverEnum(connection_struct
*conn
, uint16 vuid
,
4272 char *param
, int tpscnt
,
4273 char *data
, int tdscnt
,
4274 int mdrcnt
,int mprcnt
,
4275 char **rdata
,char **rparam
,
4276 int *rdata_len
,int *rparam_len
)
4278 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4279 char *str2
= skip_string(param
,tpscnt
,str1
);
4280 char *p
= skip_string(param
,tpscnt
,str2
);
4283 struct pack_desc desc
;
4285 if (!str1
|| !str2
|| !p
) {
4289 memset((char *)&desc
,'\0',sizeof(desc
));
4291 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4293 DEBUG(3,("WPrintDriverEnum uLevel=%d\n",uLevel
));
4295 /* check it's a supported varient */
4296 if (strcmp(str1
,"WrLeh") != 0) {
4299 if (uLevel
!= 0 || strcmp(str2
,"B41") != 0) {
4304 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4310 desc
.buflen
= mdrcnt
;
4311 if (init_package(&desc
,1,0)) {
4312 PACKS(&desc
,"B41","NULL");
4315 succnt
= (desc
.errcode
== NERR_Success
? 1 : 0);
4317 *rdata_len
= desc
.usedlen
;
4320 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4324 SSVALS(*rparam
,0,desc
.errcode
);
4326 SSVAL(*rparam
,4,succnt
);
4329 DEBUG(4,("WPrintDriverEnum: errorcode %d\n",desc
.errcode
));
4334 static bool api_WPrintQProcEnum(connection_struct
*conn
, uint16 vuid
,
4335 char *param
, int tpscnt
,
4336 char *data
, int tdscnt
,
4337 int mdrcnt
,int mprcnt
,
4338 char **rdata
,char **rparam
,
4339 int *rdata_len
,int *rparam_len
)
4341 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4342 char *str2
= skip_string(param
,tpscnt
,str1
);
4343 char *p
= skip_string(param
,tpscnt
,str2
);
4346 struct pack_desc desc
;
4348 if (!str1
|| !str2
|| !p
) {
4351 memset((char *)&desc
,'\0',sizeof(desc
));
4353 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4355 DEBUG(3,("WPrintQProcEnum uLevel=%d\n",uLevel
));
4357 /* check it's a supported varient */
4358 if (strcmp(str1
,"WrLeh") != 0) {
4361 if (uLevel
!= 0 || strcmp(str2
,"B13") != 0) {
4366 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4372 desc
.buflen
= mdrcnt
;
4374 if (init_package(&desc
,1,0)) {
4375 PACKS(&desc
,"B13","lpd");
4378 succnt
= (desc
.errcode
== NERR_Success
? 1 : 0);
4380 *rdata_len
= desc
.usedlen
;
4383 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4387 SSVALS(*rparam
,0,desc
.errcode
);
4389 SSVAL(*rparam
,4,succnt
);
4392 DEBUG(4,("WPrintQProcEnum: errorcode %d\n",desc
.errcode
));
4397 static bool api_WPrintPortEnum(connection_struct
*conn
, uint16 vuid
,
4398 char *param
, int tpscnt
,
4399 char *data
, int tdscnt
,
4400 int mdrcnt
,int mprcnt
,
4401 char **rdata
,char **rparam
,
4402 int *rdata_len
,int *rparam_len
)
4404 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4405 char *str2
= skip_string(param
,tpscnt
,str1
);
4406 char *p
= skip_string(param
,tpscnt
,str2
);
4409 struct pack_desc desc
;
4411 if (!str1
|| !str2
|| !p
) {
4415 memset((char *)&desc
,'\0',sizeof(desc
));
4417 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4419 DEBUG(3,("WPrintPortEnum uLevel=%d\n",uLevel
));
4421 /* check it's a supported varient */
4422 if (strcmp(str1
,"WrLeh") != 0) {
4425 if (uLevel
!= 0 || strcmp(str2
,"B9") != 0) {
4430 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4435 memset((char *)&desc
,'\0',sizeof(desc
));
4437 desc
.buflen
= mdrcnt
;
4439 if (init_package(&desc
,1,0)) {
4440 PACKS(&desc
,"B13","lp0");
4443 succnt
= (desc
.errcode
== NERR_Success
? 1 : 0);
4445 *rdata_len
= desc
.usedlen
;
4448 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4452 SSVALS(*rparam
,0,desc
.errcode
);
4454 SSVAL(*rparam
,4,succnt
);
4457 DEBUG(4,("WPrintPortEnum: errorcode %d\n",desc
.errcode
));
4462 /****************************************************************************
4464 ****************************************************************************/
4466 static bool api_RNetSessionEnum(connection_struct
*conn
, uint16 vuid
,
4467 char *param
, int tpscnt
,
4468 char *data
, int tdscnt
,
4469 int mdrcnt
,int mprcnt
,
4470 char **rdata
,char **rparam
,
4471 int *rdata_len
,int *rparam_len
)
4474 char *str1
= get_safe_str_ptr(param
,tpscnt
,param
,2);
4475 char *str2
= skip_string(param
,tpscnt
,str1
);
4476 char *p
= skip_string(param
,tpscnt
,str2
);
4478 struct pack_desc desc
;
4479 struct sessionid
*session_list
;
4480 int i
, num_sessions
;
4482 if (!str1
|| !str2
|| !p
) {
4486 memset((char *)&desc
,'\0',sizeof(desc
));
4488 uLevel
= get_safe_SVAL(param
,tpscnt
,p
,0,-1);
4490 DEBUG(3,("RNetSessionEnum uLevel=%d\n",uLevel
));
4491 DEBUG(7,("RNetSessionEnum req string=%s\n",str1
));
4492 DEBUG(7,("RNetSessionEnum ret string=%s\n",str2
));
4494 /* check it's a supported varient */
4495 if (strcmp(str1
,RAP_NetSessionEnum_REQ
) != 0) {
4498 if (uLevel
!= 2 || strcmp(str2
,RAP_SESSION_INFO_L2
) != 0) {
4502 num_sessions
= list_sessions(talloc_tos(), &session_list
);
4505 *rdata
= smb_realloc_limit(*rdata
,mdrcnt
);
4510 memset((char *)&desc
,'\0',sizeof(desc
));
4512 desc
.buflen
= mdrcnt
;
4514 if (!init_package(&desc
,num_sessions
,0)) {
4518 for(i
=0; i
<num_sessions
; i
++) {
4519 PACKS(&desc
, "z", session_list
[i
].remote_machine
);
4520 PACKS(&desc
, "z", session_list
[i
].username
);
4521 PACKI(&desc
, "W", 1); /* num conns */
4522 PACKI(&desc
, "W", 0); /* num opens */
4523 PACKI(&desc
, "W", 1); /* num users */
4524 PACKI(&desc
, "D", 0); /* session time */
4525 PACKI(&desc
, "D", 0); /* idle time */
4526 PACKI(&desc
, "D", 0); /* flags */
4527 PACKS(&desc
, "z", "Unknown Client"); /* client type string */
4530 *rdata_len
= desc
.usedlen
;
4533 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4537 SSVALS(*rparam
,0,desc
.errcode
);
4538 SSVAL(*rparam
,2,0); /* converter */
4539 SSVAL(*rparam
,4,num_sessions
); /* count */
4541 DEBUG(4,("RNetSessionEnum: errorcode %d\n",desc
.errcode
));
4547 /****************************************************************************
4548 The buffer was too small.
4549 ****************************************************************************/
4551 static bool api_TooSmall(connection_struct
*conn
,uint16 vuid
, char *param
, char *data
,
4552 int mdrcnt
, int mprcnt
,
4553 char **rdata
, char **rparam
,
4554 int *rdata_len
, int *rparam_len
)
4556 *rparam_len
= MIN(*rparam_len
,mprcnt
);
4557 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4564 SSVAL(*rparam
,0,NERR_BufTooSmall
);
4566 DEBUG(3,("Supplied buffer too small in API command\n"));
4571 /****************************************************************************
4572 The request is not supported.
4573 ****************************************************************************/
4575 static bool api_Unsupported(connection_struct
*conn
, uint16 vuid
,
4576 char *param
, int tpscnt
,
4577 char *data
, int tdscnt
,
4578 int mdrcnt
, int mprcnt
,
4579 char **rdata
, char **rparam
,
4580 int *rdata_len
, int *rparam_len
)
4583 *rparam
= smb_realloc_limit(*rparam
,*rparam_len
);
4590 SSVAL(*rparam
,0,NERR_notsupported
);
4591 SSVAL(*rparam
,2,0); /* converter word */
4593 DEBUG(3,("Unsupported API command\n"));
4598 static const struct {
4601 bool (*fn
)(connection_struct
*, uint16
,
4604 int,int,char **,char **,int *,int *);
4605 bool auth_user
; /* Deny anonymous access? */
4606 } api_commands
[] = {
4607 {"RNetShareEnum", RAP_WshareEnum
, api_RNetShareEnum
, True
},
4608 {"RNetShareGetInfo", RAP_WshareGetInfo
, api_RNetShareGetInfo
},
4609 {"RNetShareAdd", RAP_WshareAdd
, api_RNetShareAdd
},
4610 {"RNetSessionEnum", RAP_WsessionEnum
, api_RNetSessionEnum
, True
},
4611 {"RNetServerGetInfo", RAP_WserverGetInfo
, api_RNetServerGetInfo
},
4612 {"RNetGroupEnum", RAP_WGroupEnum
, api_RNetGroupEnum
, True
},
4613 {"RNetGroupGetUsers", RAP_WGroupGetUsers
, api_RNetGroupGetUsers
, True
},
4614 {"RNetUserEnum", RAP_WUserEnum
, api_RNetUserEnum
, True
},
4615 {"RNetUserGetInfo", RAP_WUserGetInfo
, api_RNetUserGetInfo
},
4616 {"NetUserGetGroups", RAP_WUserGetGroups
, api_NetUserGetGroups
},
4617 {"NetWkstaGetInfo", RAP_WWkstaGetInfo
, api_NetWkstaGetInfo
},
4618 {"DosPrintQEnum", RAP_WPrintQEnum
, api_DosPrintQEnum
, True
},
4619 {"DosPrintQGetInfo", RAP_WPrintQGetInfo
, api_DosPrintQGetInfo
},
4620 {"WPrintQueuePause", RAP_WPrintQPause
, api_WPrintQueueCtrl
},
4621 {"WPrintQueueResume", RAP_WPrintQContinue
, api_WPrintQueueCtrl
},
4622 {"WPrintJobEnumerate",RAP_WPrintJobEnum
, api_WPrintJobEnumerate
},
4623 {"WPrintJobGetInfo", RAP_WPrintJobGetInfo
, api_WPrintJobGetInfo
},
4624 {"RDosPrintJobDel", RAP_WPrintJobDel
, api_RDosPrintJobDel
},
4625 {"RDosPrintJobPause", RAP_WPrintJobPause
, api_RDosPrintJobDel
},
4626 {"RDosPrintJobResume",RAP_WPrintJobContinue
, api_RDosPrintJobDel
},
4627 {"WPrintDestEnum", RAP_WPrintDestEnum
, api_WPrintDestEnum
},
4628 {"WPrintDestGetInfo", RAP_WPrintDestGetInfo
, api_WPrintDestGetInfo
},
4629 {"NetRemoteTOD", RAP_NetRemoteTOD
, api_NetRemoteTOD
},
4630 {"WPrintQueuePurge", RAP_WPrintQPurge
, api_WPrintQueueCtrl
},
4631 {"NetServerEnum", RAP_NetServerEnum2
, api_RNetServerEnum
}, /* anon OK */
4632 {"WAccessGetUserPerms",RAP_WAccessGetUserPerms
,api_WAccessGetUserPerms
},
4633 {"SetUserPassword", RAP_WUserPasswordSet2
, api_SetUserPassword
},
4634 {"WWkstaUserLogon", RAP_WWkstaUserLogon
, api_WWkstaUserLogon
},
4635 {"PrintJobInfo", RAP_WPrintJobSetInfo
, api_PrintJobInfo
},
4636 {"WPrintDriverEnum", RAP_WPrintDriverEnum
, api_WPrintDriverEnum
},
4637 {"WPrintQProcEnum", RAP_WPrintQProcessorEnum
,api_WPrintQProcEnum
},
4638 {"WPrintPortEnum", RAP_WPrintPortEnum
, api_WPrintPortEnum
},
4639 {"SamOEMChangePassword",RAP_SamOEMChgPasswordUser2_P
,api_SamOEMChangePassword
}, /* anon OK */
4640 {NULL
, -1, api_Unsupported
}
4641 /* The following RAP calls are not implemented by Samba:
4643 RAP_WFileEnum2 - anon not OK
4648 /****************************************************************************
4649 Handle remote api calls.
4650 ****************************************************************************/
4652 void api_reply(connection_struct
*conn
, uint16 vuid
,
4653 struct smb_request
*req
,
4654 char *data
, char *params
,
4655 int tdscnt
, int tpscnt
,
4656 int mdrcnt
, int mprcnt
)
4660 char *rparam
= NULL
;
4661 const char *name1
= NULL
;
4662 const char *name2
= NULL
;
4669 DEBUG(0,("ERROR: NULL params in api_reply()\n"));
4670 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
4675 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
4678 api_command
= SVAL(params
,0);
4679 /* Is there a string at position params+2 ? */
4680 if (skip_string(params
,tpscnt
,params
+2)) {
4685 name2
= skip_string(params
,tpscnt
,params
+2);
4690 DEBUG(3,("Got API command %d of form <%s> <%s> (tdscnt=%d,tpscnt=%d,mdrcnt=%d,mprcnt=%d)\n",
4694 tdscnt
,tpscnt
,mdrcnt
,mprcnt
));
4696 for (i
=0;api_commands
[i
].name
;i
++) {
4697 if (api_commands
[i
].id
== api_command
&& api_commands
[i
].fn
) {
4698 DEBUG(3,("Doing %s\n",api_commands
[i
].name
));
4703 /* Check whether this api call can be done anonymously */
4705 if (api_commands
[i
].auth_user
&& lp_restrict_anonymous()) {
4706 user_struct
*user
= get_valid_user_struct(vuid
);
4708 if (!user
|| user
->server_info
->guest
) {
4709 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
4714 rdata
= (char *)SMB_MALLOC(1024);
4716 memset(rdata
,'\0',1024);
4719 rparam
= (char *)SMB_MALLOC(1024);
4721 memset(rparam
,'\0',1024);
4724 if(!rdata
|| !rparam
) {
4725 DEBUG(0,("api_reply: malloc fail !\n"));
4728 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
4732 reply
= api_commands
[i
].fn(conn
,
4734 params
,tpscnt
, /* params + length */
4735 data
,tdscnt
, /* data + length */
4737 &rdata
,&rparam
,&rdata_len
,&rparam_len
);
4740 if (rdata_len
> mdrcnt
|| rparam_len
> mprcnt
) {
4741 reply
= api_TooSmall(conn
,vuid
,params
,data
,mdrcnt
,mprcnt
,
4742 &rdata
,&rparam
,&rdata_len
,&rparam_len
);
4745 /* if we get False back then it's actually unsupported */
4747 reply
= api_Unsupported(conn
,vuid
,params
,tpscnt
,data
,tdscnt
,mdrcnt
,mprcnt
,
4748 &rdata
,&rparam
,&rdata_len
,&rparam_len
);
4751 /* If api_Unsupported returns false we can't return anything. */
4753 send_trans_reply(conn
, req
, rparam
, rparam_len
,
4754 rdata
, rdata_len
, False
);