xref: /onnv-gate/usr/src/lib/smbsrv/libmlsvc/common/spoolss_svc.c (revision 13082:81ec56bf6147)
18334SJose.Borrego@Sun.COM /*
28334SJose.Borrego@Sun.COM  * CDDL HEADER START
38334SJose.Borrego@Sun.COM  *
48334SJose.Borrego@Sun.COM  * The contents of this file are subject to the terms of the
58334SJose.Borrego@Sun.COM  * Common Development and Distribution License (the "License").
68334SJose.Borrego@Sun.COM  * You may not use this file except in compliance with the License.
78334SJose.Borrego@Sun.COM  *
88334SJose.Borrego@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98334SJose.Borrego@Sun.COM  * or http://www.opensolaris.org/os/licensing.
108334SJose.Borrego@Sun.COM  * See the License for the specific language governing permissions
118334SJose.Borrego@Sun.COM  * and limitations under the License.
128334SJose.Borrego@Sun.COM  *
138334SJose.Borrego@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
148334SJose.Borrego@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158334SJose.Borrego@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
168334SJose.Borrego@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
178334SJose.Borrego@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
188334SJose.Borrego@Sun.COM  *
198334SJose.Borrego@Sun.COM  * CDDL HEADER END
208334SJose.Borrego@Sun.COM  */
218334SJose.Borrego@Sun.COM /*
2212890SJoyce.McIntosh@Sun.COM  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
238334SJose.Borrego@Sun.COM  */
248334SJose.Borrego@Sun.COM 
258334SJose.Borrego@Sun.COM /*
268334SJose.Borrego@Sun.COM  * Printing and Spooling RPC service.
278334SJose.Borrego@Sun.COM  */
28*13082SJoyce.McIntosh@Sun.COM #include <sys/types.h>
29*13082SJoyce.McIntosh@Sun.COM #include <sys/stat.h>
30*13082SJoyce.McIntosh@Sun.COM #include <sys/utsname.h>
3112890SJoyce.McIntosh@Sun.COM #include <unistd.h>
328334SJose.Borrego@Sun.COM #include <stdlib.h>
338334SJose.Borrego@Sun.COM #include <strings.h>
34*13082SJoyce.McIntosh@Sun.COM #include <fcntl.h>
35*13082SJoyce.McIntosh@Sun.COM #include <errno.h>
368334SJose.Borrego@Sun.COM #include <smbsrv/libsmb.h>
378334SJose.Borrego@Sun.COM #include <smbsrv/libmlrpc.h>
388334SJose.Borrego@Sun.COM #include <smbsrv/libmlsvc.h>
39*13082SJoyce.McIntosh@Sun.COM #include <smbsrv/smb.h>
408334SJose.Borrego@Sun.COM #include <smbsrv/ndl/spoolss.ndl>
41*13082SJoyce.McIntosh@Sun.COM #include <smbsrv/ndl/winreg.ndl>
4212890SJoyce.McIntosh@Sun.COM #include <smb/nterror.h>
438334SJose.Borrego@Sun.COM #include <smbsrv/smbinfo.h>
448334SJose.Borrego@Sun.COM #include <smbsrv/nmpipes.h>
4512890SJoyce.McIntosh@Sun.COM #include <mlsvc.h>
468334SJose.Borrego@Sun.COM 
47*13082SJoyce.McIntosh@Sun.COM #define	SPOOLSS_PRINTER		"Postscript"
48*13082SJoyce.McIntosh@Sun.COM 
4912890SJoyce.McIntosh@Sun.COM typedef struct smb_spool {
50*13082SJoyce.McIntosh@Sun.COM 	list_t		sp_list;
51*13082SJoyce.McIntosh@Sun.COM 	int		sp_cnt;
52*13082SJoyce.McIntosh@Sun.COM 	rwlock_t	sp_rwl;
53*13082SJoyce.McIntosh@Sun.COM 	int		sp_initialized;
5412890SJoyce.McIntosh@Sun.COM } smb_spool_t;
5512890SJoyce.McIntosh@Sun.COM 
56*13082SJoyce.McIntosh@Sun.COM typedef struct smb_spooldoc {
57*13082SJoyce.McIntosh@Sun.COM 	uint32_t	sd_magic;
58*13082SJoyce.McIntosh@Sun.COM 	list_node_t	sd_lnd;
59*13082SJoyce.McIntosh@Sun.COM 	smb_inaddr_t	sd_ipaddr;
60*13082SJoyce.McIntosh@Sun.COM 	int		sd_spool_num;
61*13082SJoyce.McIntosh@Sun.COM 	char		sd_username[MAXNAMELEN];
62*13082SJoyce.McIntosh@Sun.COM 	char		sd_path[MAXPATHLEN];
63*13082SJoyce.McIntosh@Sun.COM 	char		sd_doc_name[MAXNAMELEN];
64*13082SJoyce.McIntosh@Sun.COM 	char		sd_printer_name[MAXPATHLEN];
65*13082SJoyce.McIntosh@Sun.COM 	int32_t		sd_fd;
66*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t	sd_handle;
67*13082SJoyce.McIntosh@Sun.COM } smb_spooldoc_t;
68*13082SJoyce.McIntosh@Sun.COM 
69*13082SJoyce.McIntosh@Sun.COM typedef struct {
70*13082SJoyce.McIntosh@Sun.COM 	char		*name;
71*13082SJoyce.McIntosh@Sun.COM 	uint32_t	value;
72*13082SJoyce.McIntosh@Sun.COM } spoolss_winreg_t;
73*13082SJoyce.McIntosh@Sun.COM 
74*13082SJoyce.McIntosh@Sun.COM typedef struct {
75*13082SJoyce.McIntosh@Sun.COM 	uint8_t		*sd_buf;
76*13082SJoyce.McIntosh@Sun.COM 	uint32_t	sd_size;
77*13082SJoyce.McIntosh@Sun.COM } spoolss_sd_t;
78*13082SJoyce.McIntosh@Sun.COM 
7912890SJoyce.McIntosh@Sun.COM static uint32_t spoolss_cnt;
8012890SJoyce.McIntosh@Sun.COM static smb_spool_t spoolss_splist;
8112890SJoyce.McIntosh@Sun.COM 
82*13082SJoyce.McIntosh@Sun.COM void (*spoolss_copyfile_callback)(smb_inaddr_t *, char *, char *, char *);
8312890SJoyce.McIntosh@Sun.COM 
8412890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_GetPrinter_result_u);
8512890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_GetPrinter_result);
8612890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_GetPrinter);
8712890SJoyce.McIntosh@Sun.COM 
8812890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO_DATA_DATA);
8912890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO_DATA);
9012890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO);
9112890SJoyce.McIntosh@Sun.COM DECL_FIXUP_STRUCT(spoolss_RFNPCNEX);
9212890SJoyce.McIntosh@Sun.COM 
9312890SJoyce.McIntosh@Sun.COM uint32_t srvsvc_sd_set_relative(smb_sd_t *, uint8_t *);
94*13082SJoyce.McIntosh@Sun.COM static int spoolss_getservername(char *, size_t);
95*13082SJoyce.McIntosh@Sun.COM static uint32_t spoolss_make_sd(ndr_xa_t *, spoolss_sd_t *);
96*13082SJoyce.McIntosh@Sun.COM static uint32_t spoolss_format_sd(smb_sd_t *);
97*13082SJoyce.McIntosh@Sun.COM static int spoolss_find_document(ndr_hdid_t *);
9812890SJoyce.McIntosh@Sun.COM 
9912890SJoyce.McIntosh@Sun.COM static int spoolss_s_OpenPrinter(void *, ndr_xa_t *);
10012890SJoyce.McIntosh@Sun.COM static int spoolss_s_ClosePrinter(void *, ndr_xa_t *);
10112890SJoyce.McIntosh@Sun.COM static int spoolss_s_AbortPrinter(void *, ndr_xa_t *);
10212890SJoyce.McIntosh@Sun.COM static int spoolss_s_ResetPrinter(void *, ndr_xa_t *);
10312890SJoyce.McIntosh@Sun.COM static int spoolss_s_GetPrinter(void *, ndr_xa_t *);
10412890SJoyce.McIntosh@Sun.COM static int spoolss_s_GetPrinterData(void *, ndr_xa_t *);
10512890SJoyce.McIntosh@Sun.COM static int spoolss_s_AddJob(void *, ndr_xa_t *);
10612890SJoyce.McIntosh@Sun.COM static int spoolss_s_GetJob(void *, ndr_xa_t *);
10712890SJoyce.McIntosh@Sun.COM static int spoolss_s_EnumJobs(void *, ndr_xa_t *);
10812890SJoyce.McIntosh@Sun.COM static int spoolss_s_ScheduleJob(void *, ndr_xa_t *);
10912890SJoyce.McIntosh@Sun.COM static int spoolss_s_StartDocPrinter(void *, ndr_xa_t *);
11012890SJoyce.McIntosh@Sun.COM static int spoolss_s_EndDocPrinter(void *, ndr_xa_t *);
11112890SJoyce.McIntosh@Sun.COM static int spoolss_s_StartPagePrinter(void *, ndr_xa_t *);
11212890SJoyce.McIntosh@Sun.COM static int spoolss_s_EndPagePrinter(void *, ndr_xa_t *);
11312890SJoyce.McIntosh@Sun.COM static int spoolss_s_rfnpcnex(void *, ndr_xa_t *);
11412890SJoyce.McIntosh@Sun.COM static int spoolss_s_WritePrinter(void *, ndr_xa_t *);
115*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_AddForm(void *, ndr_xa_t *);
116*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_DeleteForm(void *, ndr_xa_t *);
11712890SJoyce.McIntosh@Sun.COM static int spoolss_s_EnumForms(void *, ndr_xa_t *);
118*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_AddMonitor(void *, ndr_xa_t *);
119*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_DeleteMonitor(void *, ndr_xa_t *);
120*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_DeletePort(void *, ndr_xa_t *);
121*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_AddPortEx(void *, ndr_xa_t *);
122*13082SJoyce.McIntosh@Sun.COM static int spoolss_s_SetPort(void *, ndr_xa_t *);
12312890SJoyce.McIntosh@Sun.COM static int spoolss_s_stub(void *, ndr_xa_t *);
1248334SJose.Borrego@Sun.COM 
1258334SJose.Borrego@Sun.COM static ndr_stub_table_t spoolss_stub_table[] = {
12612890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_GetJob,		SPOOLSS_OPNUM_GetJob },
12712890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_EnumJobs,		SPOOLSS_OPNUM_EnumJobs },
12812890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub, SPOOLSS_OPNUM_DeletePrinter },
12912890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_GetPrinter,		SPOOLSS_OPNUM_GetPrinter },
13012890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_GetPrinterDriver },
13112890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_DeletePrinterDriver },
1328334SJose.Borrego@Sun.COM 	{ spoolss_s_OpenPrinter,	SPOOLSS_OPNUM_OpenPrinter },
13312890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_StartDocPrinter,	SPOOLSS_OPNUM_StartDocPrinter },
13412890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_WritePrinter,	SPOOLSS_OPNUM_WritePrinter },
13512890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_EndDocPrinter,	SPOOLSS_OPNUM_EndDocPrinter },
13612890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_StartPagePrinter,	SPOOLSS_OPNUM_StartPagePrinter },
13712890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_EndPagePrinter,	SPOOLSS_OPNUM_EndPagePrinter },
13812890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_AbortPrinter,	SPOOLSS_OPNUM_AbortPrinter },
13912890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_ResetPrinter,	SPOOLSS_OPNUM_ResetPrinter },
14012890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_AddJob,		SPOOLSS_OPNUM_AddJob },
14112890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_ScheduleJob,    	SPOOLSS_OPNUM_ScheduleJob },
14212890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_GetPrinterData,	SPOOLSS_OPNUM_GetPrinterData },
14312890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_ClosePrinter,	SPOOLSS_OPNUM_ClosePrinter },
144*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_AddForm,		SPOOLSS_OPNUM_AddForm },
145*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_DeleteForm,		SPOOLSS_OPNUM_DeleteForm },
14612890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_EnumForms,		SPOOLSS_OPNUM_EnumForms },
147*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_AddMonitor,		SPOOLSS_OPNUM_AddMonitor },
148*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_DeleteMonitor,	SPOOLSS_OPNUM_DeleteMonitor },
149*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_DeletePort,		SPOOLSS_OPNUM_DeletePort },
150*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_AddPortEx,		SPOOLSS_OPNUM_AddPortEx },
151*13082SJoyce.McIntosh@Sun.COM 	{ spoolss_s_SetPort,		SPOOLSS_OPNUM_SetPort },
15212890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_GetPrinterDriver2 },
15312890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_FCPN },
15412890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_ReplyOpenPrinter },
15512890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_ReplyClosePrinter },
15612890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_RFFPCNEX },
15712890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_rfnpcnex,		SPOOLSS_OPNUM_RFNPCNEX },
15812890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_RRPCN },
15912890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_OpenPrinter,	SPOOLSS_OPNUM_OpenPrinterEx },
16012890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_EnumPrinterData },
16112890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_EnumPrinterDataEx },
16212890SJoyce.McIntosh@Sun.COM 	{ spoolss_s_stub,		SPOOLSS_OPNUM_EnumPrinterKey },
1638334SJose.Borrego@Sun.COM 	{0}
1648334SJose.Borrego@Sun.COM };
1658334SJose.Borrego@Sun.COM 
1668334SJose.Borrego@Sun.COM static ndr_service_t spoolss_service = {
1678334SJose.Borrego@Sun.COM 	"SPOOLSS",			/* name */
1688334SJose.Borrego@Sun.COM 	"Print Spool Service",		/* desc */
1698334SJose.Borrego@Sun.COM 	"\\spoolss",			/* endpoint */
1708334SJose.Borrego@Sun.COM 	PIPE_SPOOLSS,			/* sec_addr_port */
17112890SJoyce.McIntosh@Sun.COM 	"12345678-1234-abcd-ef00-0123456789ab",	1,	/* abstract */
1728334SJose.Borrego@Sun.COM 	NDR_TRANSFER_SYNTAX_UUID,		2,	/* transfer */
1738334SJose.Borrego@Sun.COM 	0,				/* no bind_instance_size */
1748334SJose.Borrego@Sun.COM 	0,				/* no bind_req() */
1758334SJose.Borrego@Sun.COM 	0,				/* no unbind_and_close() */
1768334SJose.Borrego@Sun.COM 	0,				/* use generic_call_stub() */
1778334SJose.Borrego@Sun.COM 	&TYPEINFO(spoolss_interface),	/* interface ti */
1788334SJose.Borrego@Sun.COM 	spoolss_stub_table		/* stub_table */
1798334SJose.Borrego@Sun.COM };
1808334SJose.Borrego@Sun.COM 
1818334SJose.Borrego@Sun.COM void
spoolss_initialize(void)1828334SJose.Borrego@Sun.COM spoolss_initialize(void)
1838334SJose.Borrego@Sun.COM {
184*13082SJoyce.McIntosh@Sun.COM 	if (!spoolss_splist.sp_initialized) {
185*13082SJoyce.McIntosh@Sun.COM 		list_create(&spoolss_splist.sp_list,
186*13082SJoyce.McIntosh@Sun.COM 		    sizeof (smb_spooldoc_t),
187*13082SJoyce.McIntosh@Sun.COM 		    offsetof(smb_spooldoc_t, sd_lnd));
188*13082SJoyce.McIntosh@Sun.COM 		spoolss_splist.sp_initialized = 1;
189*13082SJoyce.McIntosh@Sun.COM 	}
190*13082SJoyce.McIntosh@Sun.COM 
191*13082SJoyce.McIntosh@Sun.COM 	spoolss_copyfile_callback = NULL;
192*13082SJoyce.McIntosh@Sun.COM 
1938334SJose.Borrego@Sun.COM 	(void) ndr_svc_register(&spoolss_service);
1948334SJose.Borrego@Sun.COM }
1958334SJose.Borrego@Sun.COM 
19612890SJoyce.McIntosh@Sun.COM void
spoolss_finalize(void)19712890SJoyce.McIntosh@Sun.COM spoolss_finalize(void)
19812890SJoyce.McIntosh@Sun.COM {
199*13082SJoyce.McIntosh@Sun.COM 	spoolss_copyfile_callback = NULL;
200*13082SJoyce.McIntosh@Sun.COM }
201*13082SJoyce.McIntosh@Sun.COM 
202*13082SJoyce.McIntosh@Sun.COM /*
203*13082SJoyce.McIntosh@Sun.COM  * Register a copyfile callback that the spoolss service can use to
204*13082SJoyce.McIntosh@Sun.COM  * copy files to the spool directory.
205*13082SJoyce.McIntosh@Sun.COM  *
206*13082SJoyce.McIntosh@Sun.COM  * Set a null pointer to disable the copying of files to the spool
207*13082SJoyce.McIntosh@Sun.COM  * directory.
208*13082SJoyce.McIntosh@Sun.COM  */
209*13082SJoyce.McIntosh@Sun.COM void
spoolss_register_copyfile(spoolss_copyfile_t copyfile)210*13082SJoyce.McIntosh@Sun.COM spoolss_register_copyfile(spoolss_copyfile_t copyfile)
211*13082SJoyce.McIntosh@Sun.COM {
212*13082SJoyce.McIntosh@Sun.COM 	spoolss_copyfile_callback = copyfile;
213*13082SJoyce.McIntosh@Sun.COM }
214*13082SJoyce.McIntosh@Sun.COM 
215*13082SJoyce.McIntosh@Sun.COM static void
spoolss_copyfile(smb_inaddr_t * ipaddr,char * username,char * path,char * docname)216*13082SJoyce.McIntosh@Sun.COM spoolss_copyfile(smb_inaddr_t *ipaddr, char *username, char *path,
217*13082SJoyce.McIntosh@Sun.COM     char *docname)
218*13082SJoyce.McIntosh@Sun.COM {
219*13082SJoyce.McIntosh@Sun.COM 	if (spoolss_copyfile_callback != NULL)
220*13082SJoyce.McIntosh@Sun.COM 		(*spoolss_copyfile_callback)(ipaddr, username, path, docname);
22112890SJoyce.McIntosh@Sun.COM }
22212890SJoyce.McIntosh@Sun.COM 
22312890SJoyce.McIntosh@Sun.COM static int
spoolss_s_OpenPrinter(void * arg,ndr_xa_t * mxa)2248334SJose.Borrego@Sun.COM spoolss_s_OpenPrinter(void *arg, ndr_xa_t *mxa)
2258334SJose.Borrego@Sun.COM {
2268334SJose.Borrego@Sun.COM 	struct spoolss_OpenPrinter *param = arg;
227*13082SJoyce.McIntosh@Sun.COM 	char		*name = (char *)param->printer_name;
228*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t	*id;
2298334SJose.Borrego@Sun.COM 
230*13082SJoyce.McIntosh@Sun.COM 	if (name != NULL && *name != '\0') {
231*13082SJoyce.McIntosh@Sun.COM 		if (strspn(name, "\\") > 2) {
232*13082SJoyce.McIntosh@Sun.COM 			bzero(&param->handle, sizeof (spoolss_handle_t));
233*13082SJoyce.McIntosh@Sun.COM 			param->status = ERROR_INVALID_PRINTER_NAME;
234*13082SJoyce.McIntosh@Sun.COM 			return (NDR_DRC_OK);
235*13082SJoyce.McIntosh@Sun.COM 		}
236*13082SJoyce.McIntosh@Sun.COM 
237*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_OpenPrinter: %s", name);
238*13082SJoyce.McIntosh@Sun.COM 	}
239*13082SJoyce.McIntosh@Sun.COM 
240*13082SJoyce.McIntosh@Sun.COM 	if ((id = ndr_hdalloc(mxa, NULL)) == NULL) {
24112890SJoyce.McIntosh@Sun.COM 		bzero(&param->handle, sizeof (spoolss_handle_t));
24212890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_NOT_ENOUGH_MEMORY;
24312890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
24412890SJoyce.McIntosh@Sun.COM 	}
24512890SJoyce.McIntosh@Sun.COM 
24612890SJoyce.McIntosh@Sun.COM 	bcopy(id, &param->handle, sizeof (spoolss_handle_t));
24712890SJoyce.McIntosh@Sun.COM 	param->status = 0;
24812890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
24912890SJoyce.McIntosh@Sun.COM }
25012890SJoyce.McIntosh@Sun.COM 
25112890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
25212890SJoyce.McIntosh@Sun.COM static int
spoolss_s_StartPagePrinter(void * arg,ndr_xa_t * mxa)25312890SJoyce.McIntosh@Sun.COM spoolss_s_StartPagePrinter(void *arg, ndr_xa_t *mxa)
25412890SJoyce.McIntosh@Sun.COM {
25512890SJoyce.McIntosh@Sun.COM 	struct spoolss_StartPagePrinter *param = arg;
25612890SJoyce.McIntosh@Sun.COM 
25712890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
2588334SJose.Borrego@Sun.COM 
2598334SJose.Borrego@Sun.COM 	return (NDR_DRC_OK);
2608334SJose.Borrego@Sun.COM }
2618334SJose.Borrego@Sun.COM 
2628334SJose.Borrego@Sun.COM /*ARGSUSED*/
26312890SJoyce.McIntosh@Sun.COM static int
spoolss_s_EndPagePrinter(void * arg,ndr_xa_t * mxa)26412890SJoyce.McIntosh@Sun.COM spoolss_s_EndPagePrinter(void *arg, ndr_xa_t *mxa)
26512890SJoyce.McIntosh@Sun.COM {
26612890SJoyce.McIntosh@Sun.COM 	struct spoolss_EndPagePrinter *param = arg;
26712890SJoyce.McIntosh@Sun.COM 
26812890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
26912890SJoyce.McIntosh@Sun.COM 
27012890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
27112890SJoyce.McIntosh@Sun.COM }
27212890SJoyce.McIntosh@Sun.COM 
27312890SJoyce.McIntosh@Sun.COM /*
27412890SJoyce.McIntosh@Sun.COM  * Windows XP and 2000 use this mechanism to write spool files.
275*13082SJoyce.McIntosh@Sun.COM  * Create a spool file fd to be used by spoolss_s_WritePrinter
276*13082SJoyce.McIntosh@Sun.COM  * and add it to the tail of the spool list.
27712890SJoyce.McIntosh@Sun.COM  */
27812890SJoyce.McIntosh@Sun.COM static int
spoolss_s_StartDocPrinter(void * arg,ndr_xa_t * mxa)27912890SJoyce.McIntosh@Sun.COM spoolss_s_StartDocPrinter(void *arg, ndr_xa_t *mxa)
28012890SJoyce.McIntosh@Sun.COM {
28112890SJoyce.McIntosh@Sun.COM 	struct spoolss_StartDocPrinter *param = arg;
28212890SJoyce.McIntosh@Sun.COM 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
28312890SJoyce.McIntosh@Sun.COM 	smb_spooldoc_t *spfile;
28412890SJoyce.McIntosh@Sun.COM 	spoolss_DocInfo_t *docinfo;
28512890SJoyce.McIntosh@Sun.COM 	char g_path[MAXPATHLEN];
28612890SJoyce.McIntosh@Sun.COM 	smb_share_t si;
28712890SJoyce.McIntosh@Sun.COM 	int rc;
28812890SJoyce.McIntosh@Sun.COM 	int fd;
28912890SJoyce.McIntosh@Sun.COM 
29012890SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
291*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_StartDocPrinter: invalid handle");
29212890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
29312890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
29412890SJoyce.McIntosh@Sun.COM 	}
29512890SJoyce.McIntosh@Sun.COM 
29612890SJoyce.McIntosh@Sun.COM 	if ((docinfo = param->dinfo.DocInfoContainer) == NULL) {
29712890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_PARAMETER;
29812890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
29912890SJoyce.McIntosh@Sun.COM 	}
30012890SJoyce.McIntosh@Sun.COM 
30112890SJoyce.McIntosh@Sun.COM 	if ((rc = smb_shr_get(SMB_SHARE_PRINT, &si)) != NERR_Success) {
302*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_StartDocPrinter: %s error=%d",
30312890SJoyce.McIntosh@Sun.COM 		    SMB_SHARE_PRINT, rc);
30412890SJoyce.McIntosh@Sun.COM 		param->status = rc;
30512890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
30612890SJoyce.McIntosh@Sun.COM 	}
30712890SJoyce.McIntosh@Sun.COM 
30812890SJoyce.McIntosh@Sun.COM 	if ((spfile = calloc(1, sizeof (smb_spooldoc_t))) == NULL) {
30912890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_NOT_ENOUGH_MEMORY;
31012890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
31112890SJoyce.McIntosh@Sun.COM 	}
31212890SJoyce.McIntosh@Sun.COM 
31312890SJoyce.McIntosh@Sun.COM 	if (docinfo->doc_name != NULL)
31412890SJoyce.McIntosh@Sun.COM 		(void) strlcpy(spfile->sd_doc_name,
31512890SJoyce.McIntosh@Sun.COM 		    (char *)docinfo->doc_name, MAXNAMELEN);
31612890SJoyce.McIntosh@Sun.COM 	else
31712890SJoyce.McIntosh@Sun.COM 		(void) strlcpy(spfile->sd_doc_name, "document", MAXNAMELEN);
31812890SJoyce.McIntosh@Sun.COM 
31912890SJoyce.McIntosh@Sun.COM 	if (docinfo->printer_name != NULL)
32012890SJoyce.McIntosh@Sun.COM 		(void) strlcpy(spfile->sd_printer_name,
32112890SJoyce.McIntosh@Sun.COM 		    (char *)docinfo->printer_name, MAXPATHLEN);
32212890SJoyce.McIntosh@Sun.COM 	else
32312890SJoyce.McIntosh@Sun.COM 		(void) strlcpy(spfile->sd_printer_name, "printer", MAXPATHLEN);
32412890SJoyce.McIntosh@Sun.COM 
32512890SJoyce.McIntosh@Sun.COM 	spfile->sd_ipaddr = mxa->pipe->np_user.ui_ipaddr;
32612890SJoyce.McIntosh@Sun.COM 	(void) strlcpy((char *)spfile->sd_username,
32712890SJoyce.McIntosh@Sun.COM 	    mxa->pipe->np_user.ui_account, MAXNAMELEN);
328*13082SJoyce.McIntosh@Sun.COM 	(void) memcpy(&spfile->sd_handle, &param->handle, sizeof (ndr_hdid_t));
329*13082SJoyce.McIntosh@Sun.COM 
33012890SJoyce.McIntosh@Sun.COM 	/*
33112890SJoyce.McIntosh@Sun.COM 	 *	write temporary spool file to print$
33212890SJoyce.McIntosh@Sun.COM 	 */
33312890SJoyce.McIntosh@Sun.COM 	(void) snprintf(g_path, MAXPATHLEN, "%s/%s%d", si.shr_path,
33412890SJoyce.McIntosh@Sun.COM 	    spfile->sd_username, spoolss_cnt);
33512890SJoyce.McIntosh@Sun.COM 	atomic_inc_32(&spoolss_cnt);
33612890SJoyce.McIntosh@Sun.COM 
33712890SJoyce.McIntosh@Sun.COM 	fd = open(g_path, O_CREAT | O_RDWR, 0600);
33812890SJoyce.McIntosh@Sun.COM 	if (fd == -1) {
339*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_StartDocPrinter: %s: %s",
34012890SJoyce.McIntosh@Sun.COM 		    g_path, strerror(errno));
34112890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_OPEN_FAILED;
34212890SJoyce.McIntosh@Sun.COM 		free(spfile);
34312890SJoyce.McIntosh@Sun.COM 	} else {
34412890SJoyce.McIntosh@Sun.COM 		(void) strlcpy((char *)spfile->sd_path, g_path, MAXPATHLEN);
34512890SJoyce.McIntosh@Sun.COM 		spfile->sd_fd = (uint16_t)fd;
346*13082SJoyce.McIntosh@Sun.COM 
347*13082SJoyce.McIntosh@Sun.COM 		/*
348*13082SJoyce.McIntosh@Sun.COM 		 * Add the document to the spool list.
349*13082SJoyce.McIntosh@Sun.COM 		 */
350*13082SJoyce.McIntosh@Sun.COM 		(void) rw_wrlock(&spoolss_splist.sp_rwl);
351*13082SJoyce.McIntosh@Sun.COM 		list_insert_tail(&spoolss_splist.sp_list, spfile);
352*13082SJoyce.McIntosh@Sun.COM 		spoolss_splist.sp_cnt++;
353*13082SJoyce.McIntosh@Sun.COM 		(void) rw_unlock(&spoolss_splist.sp_rwl);
354*13082SJoyce.McIntosh@Sun.COM 
35512890SJoyce.McIntosh@Sun.COM 		/*
35612890SJoyce.McIntosh@Sun.COM 		 * JobId isn't used now, but if printQ management is added
35712890SJoyce.McIntosh@Sun.COM 		 * this will have to be incremented per job submitted.
35812890SJoyce.McIntosh@Sun.COM 		 */
35912890SJoyce.McIntosh@Sun.COM 		param->JobId = 46;
36012890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_SUCCESS;
36112890SJoyce.McIntosh@Sun.COM 	}
36212890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
36312890SJoyce.McIntosh@Sun.COM }
36412890SJoyce.McIntosh@Sun.COM 
36512890SJoyce.McIntosh@Sun.COM /*
36612890SJoyce.McIntosh@Sun.COM  * Windows XP and 2000 use this mechanism to write spool files
367*13082SJoyce.McIntosh@Sun.COM  * Search the spooldoc list for a matching RPC handle and pass
368*13082SJoyce.McIntosh@Sun.COM  * the spool the file for printing.
36912890SJoyce.McIntosh@Sun.COM  */
37012890SJoyce.McIntosh@Sun.COM static int
spoolss_s_EndDocPrinter(void * arg,ndr_xa_t * mxa)37112890SJoyce.McIntosh@Sun.COM spoolss_s_EndDocPrinter(void *arg, ndr_xa_t *mxa)
37212890SJoyce.McIntosh@Sun.COM {
37312890SJoyce.McIntosh@Sun.COM 	struct spoolss_EndDocPrinter *param = arg;
374*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t	*id = (ndr_hdid_t *)&param->handle;
375*13082SJoyce.McIntosh@Sun.COM 	smb_spooldoc_t	*sp;
37612890SJoyce.McIntosh@Sun.COM 
377*13082SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
378*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_EndDocPrinter: invalid handle");
379*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
380*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
381*13082SJoyce.McIntosh@Sun.COM 	}
382*13082SJoyce.McIntosh@Sun.COM 
383*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_INVALID_HANDLE;
384*13082SJoyce.McIntosh@Sun.COM 	(void) rw_wrlock(&spoolss_splist.sp_rwl);
385*13082SJoyce.McIntosh@Sun.COM 
386*13082SJoyce.McIntosh@Sun.COM 	sp = list_head(&spoolss_splist.sp_list);
387*13082SJoyce.McIntosh@Sun.COM 	while (sp != NULL) {
388*13082SJoyce.McIntosh@Sun.COM 		if (!memcmp(id, &(sp->sd_handle), sizeof (ndr_hdid_t))) {
389*13082SJoyce.McIntosh@Sun.COM 			spoolss_copyfile(&sp->sd_ipaddr,
390*13082SJoyce.McIntosh@Sun.COM 			    sp->sd_username, sp->sd_path, sp->sd_doc_name);
391*13082SJoyce.McIntosh@Sun.COM 			(void) close(sp->sd_fd);
392*13082SJoyce.McIntosh@Sun.COM 			list_remove(&spoolss_splist.sp_list, sp);
393*13082SJoyce.McIntosh@Sun.COM 			free(sp);
394*13082SJoyce.McIntosh@Sun.COM 			param->status = ERROR_SUCCESS;
395*13082SJoyce.McIntosh@Sun.COM 			break;
396*13082SJoyce.McIntosh@Sun.COM 		}
397*13082SJoyce.McIntosh@Sun.COM 
398*13082SJoyce.McIntosh@Sun.COM 		sp = list_next(&spoolss_splist.sp_list, sp);
399*13082SJoyce.McIntosh@Sun.COM 	}
400*13082SJoyce.McIntosh@Sun.COM 
401*13082SJoyce.McIntosh@Sun.COM 	(void) rw_unlock(&spoolss_splist.sp_rwl);
402*13082SJoyce.McIntosh@Sun.COM 
403*13082SJoyce.McIntosh@Sun.COM 	if (param->status != ERROR_SUCCESS)
404*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_EndDocPrinter: document not found");
40512890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
40612890SJoyce.McIntosh@Sun.COM }
40712890SJoyce.McIntosh@Sun.COM 
40812890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
40912890SJoyce.McIntosh@Sun.COM static int
spoolss_s_AbortPrinter(void * arg,ndr_xa_t * mxa)41012890SJoyce.McIntosh@Sun.COM spoolss_s_AbortPrinter(void *arg, ndr_xa_t *mxa)
41112890SJoyce.McIntosh@Sun.COM {
41212890SJoyce.McIntosh@Sun.COM 	struct spoolss_AbortPrinter *param = arg;
41312890SJoyce.McIntosh@Sun.COM 
41412890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
41512890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
41612890SJoyce.McIntosh@Sun.COM }
41712890SJoyce.McIntosh@Sun.COM 
41812890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
41912890SJoyce.McIntosh@Sun.COM static int
spoolss_s_ResetPrinter(void * arg,ndr_xa_t * mxa)42012890SJoyce.McIntosh@Sun.COM spoolss_s_ResetPrinter(void *arg, ndr_xa_t *mxa)
42112890SJoyce.McIntosh@Sun.COM {
42212890SJoyce.McIntosh@Sun.COM 	struct spoolss_AbortPrinter *param = arg;
42312890SJoyce.McIntosh@Sun.COM 
42412890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
42512890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
42612890SJoyce.McIntosh@Sun.COM }
42712890SJoyce.McIntosh@Sun.COM 
42812890SJoyce.McIntosh@Sun.COM static int
spoolss_s_ClosePrinter(void * arg,ndr_xa_t * mxa)42912890SJoyce.McIntosh@Sun.COM spoolss_s_ClosePrinter(void *arg, ndr_xa_t *mxa)
43012890SJoyce.McIntosh@Sun.COM {
43112890SJoyce.McIntosh@Sun.COM 	struct spoolss_ClosePrinter *param = arg;
432*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t	*id = (ndr_hdid_t *)&param->handle;
433*13082SJoyce.McIntosh@Sun.COM 	ndr_handle_t	*hd;
43412890SJoyce.McIntosh@Sun.COM 
43512890SJoyce.McIntosh@Sun.COM 	if ((hd = ndr_hdlookup(mxa, id)) != NULL) {
43612890SJoyce.McIntosh@Sun.COM 		free(hd->nh_data);
43712890SJoyce.McIntosh@Sun.COM 		hd->nh_data = NULL;
43812890SJoyce.McIntosh@Sun.COM 	}
43912890SJoyce.McIntosh@Sun.COM 
44012890SJoyce.McIntosh@Sun.COM 	ndr_hdfree(mxa, id);
44112890SJoyce.McIntosh@Sun.COM 	bzero(&param->result_handle, sizeof (spoolss_handle_t));
44212890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
44312890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
44412890SJoyce.McIntosh@Sun.COM }
44512890SJoyce.McIntosh@Sun.COM 
446*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_AddForm(void * arg,ndr_xa_t * mxa)447*13082SJoyce.McIntosh@Sun.COM spoolss_s_AddForm(void *arg, ndr_xa_t *mxa)
448*13082SJoyce.McIntosh@Sun.COM {
449*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_AddForm *param = arg;
450*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
451*13082SJoyce.McIntosh@Sun.COM 
452*13082SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
453*13082SJoyce.McIntosh@Sun.COM 		bzero(param, sizeof (struct spoolss_AddForm));
454*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
455*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
456*13082SJoyce.McIntosh@Sun.COM 	}
457*13082SJoyce.McIntosh@Sun.COM 
458*13082SJoyce.McIntosh@Sun.COM 	bzero(param, sizeof (struct spoolss_AddForm));
459*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
460*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
461*13082SJoyce.McIntosh@Sun.COM }
462*13082SJoyce.McIntosh@Sun.COM 
463*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_DeleteForm(void * arg,ndr_xa_t * mxa)464*13082SJoyce.McIntosh@Sun.COM spoolss_s_DeleteForm(void *arg, ndr_xa_t *mxa)
465*13082SJoyce.McIntosh@Sun.COM {
466*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_DeleteForm *param = arg;
467*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
468*13082SJoyce.McIntosh@Sun.COM 
469*13082SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
470*13082SJoyce.McIntosh@Sun.COM 		bzero(param, sizeof (struct spoolss_DeleteForm));
471*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
472*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
473*13082SJoyce.McIntosh@Sun.COM 	}
474*13082SJoyce.McIntosh@Sun.COM 
475*13082SJoyce.McIntosh@Sun.COM 	bzero(param, sizeof (struct spoolss_DeleteForm));
476*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
477*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
478*13082SJoyce.McIntosh@Sun.COM }
479*13082SJoyce.McIntosh@Sun.COM 
480*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_EnumForms(void * arg,ndr_xa_t * mxa)48112890SJoyce.McIntosh@Sun.COM spoolss_s_EnumForms(void *arg, ndr_xa_t *mxa)
48212890SJoyce.McIntosh@Sun.COM {
48312890SJoyce.McIntosh@Sun.COM 	struct spoolss_EnumForms *param = arg;
484*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
48512890SJoyce.McIntosh@Sun.COM 
486*13082SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
487*13082SJoyce.McIntosh@Sun.COM 		bzero(param, sizeof (struct spoolss_EnumForms));
488*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
489*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
490*13082SJoyce.McIntosh@Sun.COM 	}
491*13082SJoyce.McIntosh@Sun.COM 
492*13082SJoyce.McIntosh@Sun.COM 	bzero(param, sizeof (struct spoolss_EnumForms));
493*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
49412890SJoyce.McIntosh@Sun.COM 	param->needed = 0;
49512890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
49612890SJoyce.McIntosh@Sun.COM }
49712890SJoyce.McIntosh@Sun.COM 
49812890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
499*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_AddMonitor(void * arg,ndr_xa_t * mxa)500*13082SJoyce.McIntosh@Sun.COM spoolss_s_AddMonitor(void *arg, ndr_xa_t *mxa)
501*13082SJoyce.McIntosh@Sun.COM {
502*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_AddMonitor *param = arg;
503*13082SJoyce.McIntosh@Sun.COM 
504*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
505*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
506*13082SJoyce.McIntosh@Sun.COM }
507*13082SJoyce.McIntosh@Sun.COM 
508*13082SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
509*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_DeleteMonitor(void * arg,ndr_xa_t * mxa)510*13082SJoyce.McIntosh@Sun.COM spoolss_s_DeleteMonitor(void *arg, ndr_xa_t *mxa)
511*13082SJoyce.McIntosh@Sun.COM {
512*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_DeleteMonitor *param = arg;
513*13082SJoyce.McIntosh@Sun.COM 
514*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
515*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
516*13082SJoyce.McIntosh@Sun.COM }
517*13082SJoyce.McIntosh@Sun.COM 
518*13082SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
519*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_DeletePort(void * arg,ndr_xa_t * mxa)520*13082SJoyce.McIntosh@Sun.COM spoolss_s_DeletePort(void *arg, ndr_xa_t *mxa)
521*13082SJoyce.McIntosh@Sun.COM {
522*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_DeletePort *param = arg;
523*13082SJoyce.McIntosh@Sun.COM 
524*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
525*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
526*13082SJoyce.McIntosh@Sun.COM }
527*13082SJoyce.McIntosh@Sun.COM 
528*13082SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
529*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_AddPortEx(void * arg,ndr_xa_t * mxa)530*13082SJoyce.McIntosh@Sun.COM spoolss_s_AddPortEx(void *arg, ndr_xa_t *mxa)
531*13082SJoyce.McIntosh@Sun.COM {
532*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_AddPortEx *param = arg;
533*13082SJoyce.McIntosh@Sun.COM 
534*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
535*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
536*13082SJoyce.McIntosh@Sun.COM }
537*13082SJoyce.McIntosh@Sun.COM 
538*13082SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
539*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_SetPort(void * arg,ndr_xa_t * mxa)540*13082SJoyce.McIntosh@Sun.COM spoolss_s_SetPort(void *arg, ndr_xa_t *mxa)
541*13082SJoyce.McIntosh@Sun.COM {
542*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_SetPort *param = arg;
543*13082SJoyce.McIntosh@Sun.COM 
544*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
545*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
546*13082SJoyce.McIntosh@Sun.COM }
547*13082SJoyce.McIntosh@Sun.COM 
548*13082SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
549*13082SJoyce.McIntosh@Sun.COM static int
spoolss_s_EnumJobs(void * arg,ndr_xa_t * mxa)55012890SJoyce.McIntosh@Sun.COM spoolss_s_EnumJobs(void *arg, ndr_xa_t *mxa)
55112890SJoyce.McIntosh@Sun.COM {
55212890SJoyce.McIntosh@Sun.COM 	struct spoolss_EnumJobs *param = arg;
55312890SJoyce.McIntosh@Sun.COM 	DWORD status = ERROR_SUCCESS;
55412890SJoyce.McIntosh@Sun.COM 
55512890SJoyce.McIntosh@Sun.COM 	switch (param->level) {
55612890SJoyce.McIntosh@Sun.COM 	case 1:
55712890SJoyce.McIntosh@Sun.COM 	case 2:
55812890SJoyce.McIntosh@Sun.COM 	case 3:
55912890SJoyce.McIntosh@Sun.COM 	case 4:
56012890SJoyce.McIntosh@Sun.COM 	default:
56112890SJoyce.McIntosh@Sun.COM 		break;
56212890SJoyce.McIntosh@Sun.COM 	}
56312890SJoyce.McIntosh@Sun.COM 
56412890SJoyce.McIntosh@Sun.COM 	param->status = status;
56512890SJoyce.McIntosh@Sun.COM 	param->needed = 0;
56612890SJoyce.McIntosh@Sun.COM 	param->needed2 = 0;
56712890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
56812890SJoyce.McIntosh@Sun.COM }
56912890SJoyce.McIntosh@Sun.COM 
57012890SJoyce.McIntosh@Sun.COM 
57112890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
57212890SJoyce.McIntosh@Sun.COM static int
spoolss_s_GetJob(void * arg,ndr_xa_t * mxa)57312890SJoyce.McIntosh@Sun.COM spoolss_s_GetJob(void *arg, ndr_xa_t *mxa)
57412890SJoyce.McIntosh@Sun.COM {
57512890SJoyce.McIntosh@Sun.COM 	struct spoolss_GetJob *param = arg;
57612890SJoyce.McIntosh@Sun.COM 	DWORD status = ERROR_SUCCESS;
57712890SJoyce.McIntosh@Sun.COM 
57812890SJoyce.McIntosh@Sun.COM 	if (param->BufCount == 0)
57912890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INSUFFICIENT_BUFFER;
58012890SJoyce.McIntosh@Sun.COM 	else
58112890SJoyce.McIntosh@Sun.COM 		param->status = status;
58212890SJoyce.McIntosh@Sun.COM 	param->needed = 0;
58312890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
58412890SJoyce.McIntosh@Sun.COM }
58512890SJoyce.McIntosh@Sun.COM 
58612890SJoyce.McIntosh@Sun.COM 
58712890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
58812890SJoyce.McIntosh@Sun.COM static int
spoolss_s_ScheduleJob(void * arg,ndr_xa_t * mxa)58912890SJoyce.McIntosh@Sun.COM spoolss_s_ScheduleJob(void *arg, ndr_xa_t *mxa)
59012890SJoyce.McIntosh@Sun.COM {
59112890SJoyce.McIntosh@Sun.COM 	struct spoolss_ScheduleJob *param = arg;
592*13082SJoyce.McIntosh@Sun.COM 	DWORD status = ERROR_SPL_NO_ADDJOB;
59312890SJoyce.McIntosh@Sun.COM 
59412890SJoyce.McIntosh@Sun.COM 	param->status = status;
59512890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
59612890SJoyce.McIntosh@Sun.COM }
59712890SJoyce.McIntosh@Sun.COM 
59812890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
59912890SJoyce.McIntosh@Sun.COM static int
spoolss_s_AddJob(void * arg,ndr_xa_t * mxa)60012890SJoyce.McIntosh@Sun.COM spoolss_s_AddJob(void *arg, ndr_xa_t *mxa)
60112890SJoyce.McIntosh@Sun.COM {
60212890SJoyce.McIntosh@Sun.COM 	struct spoolss_AddJob *param = arg;
60312890SJoyce.McIntosh@Sun.COM 
60412890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
60512890SJoyce.McIntosh@Sun.COM 	param->needed = 0;
60612890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
60712890SJoyce.McIntosh@Sun.COM }
60812890SJoyce.McIntosh@Sun.COM 
60912890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
61012890SJoyce.McIntosh@Sun.COM static int
spoolss_s_rfnpcnex(void * arg,ndr_xa_t * mxa)61112890SJoyce.McIntosh@Sun.COM spoolss_s_rfnpcnex(void *arg, ndr_xa_t *mxa)
61212890SJoyce.McIntosh@Sun.COM {
61312890SJoyce.McIntosh@Sun.COM 	struct spoolss_RFNPCNEX *param = arg;
61412890SJoyce.McIntosh@Sun.COM 
61512890SJoyce.McIntosh@Sun.COM 	param->ppinfo = 0;
61612890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
61712890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
61812890SJoyce.McIntosh@Sun.COM }
61912890SJoyce.McIntosh@Sun.COM 
62012890SJoyce.McIntosh@Sun.COM /*
62112890SJoyce.McIntosh@Sun.COM  * Use the RPC context handle to find the fd and write the document content.
62212890SJoyce.McIntosh@Sun.COM  */
62312890SJoyce.McIntosh@Sun.COM static int
spoolss_s_WritePrinter(void * arg,ndr_xa_t * mxa)62412890SJoyce.McIntosh@Sun.COM spoolss_s_WritePrinter(void *arg, ndr_xa_t *mxa)
62512890SJoyce.McIntosh@Sun.COM {
62612890SJoyce.McIntosh@Sun.COM 	struct spoolss_WritePrinter *param = arg;
62712890SJoyce.McIntosh@Sun.COM 	int written = 0;
62812890SJoyce.McIntosh@Sun.COM 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
62912890SJoyce.McIntosh@Sun.COM 	int spfd;
63012890SJoyce.McIntosh@Sun.COM 
63112890SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
63212890SJoyce.McIntosh@Sun.COM 		param->written = 0;
63312890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
634*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_WritePrinter: invalid handle");
63512890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
63612890SJoyce.McIntosh@Sun.COM 	}
63712890SJoyce.McIntosh@Sun.COM 
638*13082SJoyce.McIntosh@Sun.COM 	if ((spfd = spoolss_find_document(id)) < 0) {
63912890SJoyce.McIntosh@Sun.COM 		param->written = 0;
64012890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INVALID_HANDLE;
641*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_WritePrinter: document not found");
64212890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
64312890SJoyce.McIntosh@Sun.COM 	}
64412890SJoyce.McIntosh@Sun.COM 
64512890SJoyce.McIntosh@Sun.COM 	written = write(spfd, param->pBuf, param->BufCount);
64612890SJoyce.McIntosh@Sun.COM 	if (written < param->BufCount) {
647*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_WritePrinter: write failed");
64812890SJoyce.McIntosh@Sun.COM 		param->written = 0;
64912890SJoyce.McIntosh@Sun.COM 		param->status = ERROR_CANTWRITE;
65012890SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
65112890SJoyce.McIntosh@Sun.COM 	}
65212890SJoyce.McIntosh@Sun.COM 
65312890SJoyce.McIntosh@Sun.COM 	param->written = written;
65412890SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
65512890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
65612890SJoyce.McIntosh@Sun.COM }
65712890SJoyce.McIntosh@Sun.COM 
65812890SJoyce.McIntosh@Sun.COM /*
659*13082SJoyce.McIntosh@Sun.COM  * Find a document by RPC handle in the spool list and return the fd.
66012890SJoyce.McIntosh@Sun.COM  */
661*13082SJoyce.McIntosh@Sun.COM static int
spoolss_find_document(ndr_hdid_t * handle)662*13082SJoyce.McIntosh@Sun.COM spoolss_find_document(ndr_hdid_t *handle)
66312890SJoyce.McIntosh@Sun.COM {
664*13082SJoyce.McIntosh@Sun.COM 	smb_spooldoc_t *sp;
66512890SJoyce.McIntosh@Sun.COM 
666*13082SJoyce.McIntosh@Sun.COM 	(void) rw_rdlock(&spoolss_splist.sp_rwl);
66712890SJoyce.McIntosh@Sun.COM 
668*13082SJoyce.McIntosh@Sun.COM 	sp = list_head(&spoolss_splist.sp_list);
669*13082SJoyce.McIntosh@Sun.COM 	while (sp != NULL) {
670*13082SJoyce.McIntosh@Sun.COM 		if (!memcmp(handle, &(sp->sd_handle), sizeof (ndr_hdid_t))) {
671*13082SJoyce.McIntosh@Sun.COM 			(void) rw_unlock(&spoolss_splist.sp_rwl);
672*13082SJoyce.McIntosh@Sun.COM 			return (sp->sd_fd);
673*13082SJoyce.McIntosh@Sun.COM 		}
674*13082SJoyce.McIntosh@Sun.COM 		sp = list_next(&spoolss_splist.sp_list, sp);
67512890SJoyce.McIntosh@Sun.COM 	}
67612890SJoyce.McIntosh@Sun.COM 
677*13082SJoyce.McIntosh@Sun.COM 	(void) rw_unlock(&spoolss_splist.sp_rwl);
678*13082SJoyce.McIntosh@Sun.COM 	return (-1);
67912890SJoyce.McIntosh@Sun.COM }
68012890SJoyce.McIntosh@Sun.COM 
681*13082SJoyce.McIntosh@Sun.COM /*
682*13082SJoyce.McIntosh@Sun.COM  * GetPrinterData is used t obtain values from the registry for a
683*13082SJoyce.McIntosh@Sun.COM  * printer or a print server.  See [MS-RPRN] for value descriptions.
684*13082SJoyce.McIntosh@Sun.COM  * The registry returns ERROR_FILE_NOT_FOUND for unknown keys.
685*13082SJoyce.McIntosh@Sun.COM  */
68612890SJoyce.McIntosh@Sun.COM static int
spoolss_s_GetPrinterData(void * arg,ndr_xa_t * mxa)68712890SJoyce.McIntosh@Sun.COM spoolss_s_GetPrinterData(void *arg, ndr_xa_t *mxa)
68812890SJoyce.McIntosh@Sun.COM {
689*13082SJoyce.McIntosh@Sun.COM 	static spoolss_winreg_t	reg[] = {
690*13082SJoyce.McIntosh@Sun.COM 		{ "ChangeId",			0x0050acf2 },
691*13082SJoyce.McIntosh@Sun.COM 		{ "W3SvcInstalled",		0x00000000 },
692*13082SJoyce.McIntosh@Sun.COM 		{ "BeepEnabled",		0x00000000 },
693*13082SJoyce.McIntosh@Sun.COM 		{ "EventLog",			0x0000001f },
694*13082SJoyce.McIntosh@Sun.COM 		{ "NetPopup",			0x00000000 },
695*13082SJoyce.McIntosh@Sun.COM 		{ "NetPopupToComputer",		0x00000000 },
696*13082SJoyce.McIntosh@Sun.COM 		{ "MajorVersion",		0x00000003 },
697*13082SJoyce.McIntosh@Sun.COM 		{ "MinorVersion",		0x00000000 },
698*13082SJoyce.McIntosh@Sun.COM 		{ "DsPresent",			0x00000000 }
699*13082SJoyce.McIntosh@Sun.COM 	};
70012890SJoyce.McIntosh@Sun.COM 
701*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_GetPrinterData *param = arg;
702*13082SJoyce.McIntosh@Sun.COM 	char			*name = (char *)param->pValueName;
703*13082SJoyce.McIntosh@Sun.COM 	char			buf[MAXPATHLEN];
704*13082SJoyce.McIntosh@Sun.COM 	static uint8_t		reserved_buf[4];
705*13082SJoyce.McIntosh@Sun.COM 	spoolss_winreg_t	*rp;
706*13082SJoyce.McIntosh@Sun.COM 	smb_share_t		si;
707*13082SJoyce.McIntosh@Sun.COM 	smb_version_t		*osversion;
708*13082SJoyce.McIntosh@Sun.COM 	struct utsname		sysname;
709*13082SJoyce.McIntosh@Sun.COM 	smb_wchar_t		*wcs;
710*13082SJoyce.McIntosh@Sun.COM 	uint32_t		value;
711*13082SJoyce.McIntosh@Sun.COM 	uint32_t		status;
712*13082SJoyce.McIntosh@Sun.COM 	int			wcslen;
713*13082SJoyce.McIntosh@Sun.COM 	int			i;
714*13082SJoyce.McIntosh@Sun.COM 
715*13082SJoyce.McIntosh@Sun.COM 	if (name == NULL || *name == '\0') {
716*13082SJoyce.McIntosh@Sun.COM 		status = ERROR_FILE_NOT_FOUND;
717*13082SJoyce.McIntosh@Sun.COM 		goto report_error;
71812890SJoyce.McIntosh@Sun.COM 	}
71912890SJoyce.McIntosh@Sun.COM 
720*13082SJoyce.McIntosh@Sun.COM 	for (i = 0; i < sizeof (reg) / sizeof (reg[0]); ++i) {
721*13082SJoyce.McIntosh@Sun.COM 		param->pType = WINREG_DWORD;
722*13082SJoyce.McIntosh@Sun.COM 		param->Needed = sizeof (uint32_t);
723*13082SJoyce.McIntosh@Sun.COM 		rp = &reg[i];
724*13082SJoyce.McIntosh@Sun.COM 
725*13082SJoyce.McIntosh@Sun.COM 		if (strcasecmp(name, rp->name) != 0)
726*13082SJoyce.McIntosh@Sun.COM 			continue;
727*13082SJoyce.McIntosh@Sun.COM 
728*13082SJoyce.McIntosh@Sun.COM 		if (param->Size < sizeof (uint32_t)) {
729*13082SJoyce.McIntosh@Sun.COM 			param->Size = 0;
730*13082SJoyce.McIntosh@Sun.COM 			goto need_more_data;
731*13082SJoyce.McIntosh@Sun.COM 		}
73212890SJoyce.McIntosh@Sun.COM 
733*13082SJoyce.McIntosh@Sun.COM 		if ((param->Buf = NDR_NEW(mxa, uint32_t)) == NULL) {
734*13082SJoyce.McIntosh@Sun.COM 			status = ERROR_NOT_ENOUGH_MEMORY;
735*13082SJoyce.McIntosh@Sun.COM 			goto report_error;
736*13082SJoyce.McIntosh@Sun.COM 		}
73712890SJoyce.McIntosh@Sun.COM 
738*13082SJoyce.McIntosh@Sun.COM 		value = rp->value;
73912890SJoyce.McIntosh@Sun.COM 
740*13082SJoyce.McIntosh@Sun.COM 		if ((strcasecmp(name, "DsPresent") == 0) &&
741*13082SJoyce.McIntosh@Sun.COM 		    (smb_config_get_secmode() == SMB_SECMODE_DOMAIN))
742*13082SJoyce.McIntosh@Sun.COM 			value = 0x00000001;
74312890SJoyce.McIntosh@Sun.COM 
744*13082SJoyce.McIntosh@Sun.COM 		bcopy(&value, param->Buf, sizeof (uint32_t));
745*13082SJoyce.McIntosh@Sun.COM 		param->Size = sizeof (uint32_t);
746*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_SUCCESS;
747*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
74812890SJoyce.McIntosh@Sun.COM 	}
74912890SJoyce.McIntosh@Sun.COM 
750*13082SJoyce.McIntosh@Sun.COM 	if (strcasecmp(name, "OSVersion") == 0) {
751*13082SJoyce.McIntosh@Sun.COM 		param->pType = WINREG_BINARY;
752*13082SJoyce.McIntosh@Sun.COM 		param->Needed = sizeof (smb_version_t);
753*13082SJoyce.McIntosh@Sun.COM 
754*13082SJoyce.McIntosh@Sun.COM 		if (param->Size < sizeof (smb_version_t)) {
755*13082SJoyce.McIntosh@Sun.COM 			param->Size = sizeof (smb_version_t);
756*13082SJoyce.McIntosh@Sun.COM 			goto need_more_data;
757*13082SJoyce.McIntosh@Sun.COM 		}
758*13082SJoyce.McIntosh@Sun.COM 
759*13082SJoyce.McIntosh@Sun.COM 		if ((osversion = NDR_NEW(mxa, smb_version_t)) == NULL) {
760*13082SJoyce.McIntosh@Sun.COM 			status = ERROR_NOT_ENOUGH_MEMORY;
761*13082SJoyce.McIntosh@Sun.COM 			goto report_error;
762*13082SJoyce.McIntosh@Sun.COM 		}
763*13082SJoyce.McIntosh@Sun.COM 
764*13082SJoyce.McIntosh@Sun.COM 		smb_config_get_version(osversion);
765*13082SJoyce.McIntosh@Sun.COM 		param->Buf = (uint8_t *)osversion;
766*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_SUCCESS;
767*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
768*13082SJoyce.McIntosh@Sun.COM 	}
769*13082SJoyce.McIntosh@Sun.COM 
770*13082SJoyce.McIntosh@Sun.COM 	if (strcasecmp(name, "DNSMachineName") == 0) {
771*13082SJoyce.McIntosh@Sun.COM 		param->pType = WINREG_SZ;
772*13082SJoyce.McIntosh@Sun.COM 		buf[0] = '\0';
773*13082SJoyce.McIntosh@Sun.COM 		(void) smb_getfqhostname(buf, MAXHOSTNAMELEN);
774*13082SJoyce.McIntosh@Sun.COM 		goto encode_string;
775*13082SJoyce.McIntosh@Sun.COM 	}
776*13082SJoyce.McIntosh@Sun.COM 
777*13082SJoyce.McIntosh@Sun.COM 	if (strcasecmp(name, "DefaultSpoolDirectory") == 0) {
778*13082SJoyce.McIntosh@Sun.COM 		param->pType = WINREG_SZ;
779*13082SJoyce.McIntosh@Sun.COM 		buf[0] = '\0';
780*13082SJoyce.McIntosh@Sun.COM 
781*13082SJoyce.McIntosh@Sun.COM 		if (smb_shr_get(SMB_SHARE_PRINT, &si) != NERR_Success) {
782*13082SJoyce.McIntosh@Sun.COM 			status = ERROR_FILE_NOT_FOUND;
783*13082SJoyce.McIntosh@Sun.COM 			goto report_error;
784*13082SJoyce.McIntosh@Sun.COM 		}
785*13082SJoyce.McIntosh@Sun.COM 
786*13082SJoyce.McIntosh@Sun.COM 		(void) snprintf(buf, MAXPATHLEN, "C:/%s", si.shr_path);
787*13082SJoyce.McIntosh@Sun.COM 		(void) strcanon(buf, "/\\");
788*13082SJoyce.McIntosh@Sun.COM 		(void) strsubst(buf, '/', '\\');
789*13082SJoyce.McIntosh@Sun.COM 		goto encode_string;
79012890SJoyce.McIntosh@Sun.COM 	}
79112890SJoyce.McIntosh@Sun.COM 
792*13082SJoyce.McIntosh@Sun.COM 	if (strcasecmp(name, "Architecture") == 0) {
793*13082SJoyce.McIntosh@Sun.COM 		param->pType = WINREG_SZ;
79412890SJoyce.McIntosh@Sun.COM 
795*13082SJoyce.McIntosh@Sun.COM 		if (uname(&sysname) < 0)
796*13082SJoyce.McIntosh@Sun.COM 			(void) strlcpy(buf, "Solaris", MAXPATHLEN);
797*13082SJoyce.McIntosh@Sun.COM 		else
798*13082SJoyce.McIntosh@Sun.COM 			(void) snprintf(buf, MAXPATHLEN, "%s %s",
799*13082SJoyce.McIntosh@Sun.COM 			    sysname.sysname, sysname.machine);
80012890SJoyce.McIntosh@Sun.COM 
801*13082SJoyce.McIntosh@Sun.COM 		goto encode_string;
80212890SJoyce.McIntosh@Sun.COM 	}
80312890SJoyce.McIntosh@Sun.COM 
804*13082SJoyce.McIntosh@Sun.COM 	status = ERROR_FILE_NOT_FOUND;
80512890SJoyce.McIntosh@Sun.COM 
806*13082SJoyce.McIntosh@Sun.COM report_error:
807*13082SJoyce.McIntosh@Sun.COM 	bzero(param, sizeof (struct spoolss_GetPrinterData));
808*13082SJoyce.McIntosh@Sun.COM 	param->Buf = reserved_buf;
809*13082SJoyce.McIntosh@Sun.COM 	param->status = status;
810*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
81112890SJoyce.McIntosh@Sun.COM 
812*13082SJoyce.McIntosh@Sun.COM encode_string:
813*13082SJoyce.McIntosh@Sun.COM 	wcslen = smb_wcequiv_strlen(buf) + sizeof (smb_wchar_t);
814*13082SJoyce.McIntosh@Sun.COM 	if (param->Size < wcslen) {
815*13082SJoyce.McIntosh@Sun.COM 		param->Needed = wcslen;
816*13082SJoyce.McIntosh@Sun.COM 		goto need_more_data;
81712890SJoyce.McIntosh@Sun.COM 	}
81812890SJoyce.McIntosh@Sun.COM 
819*13082SJoyce.McIntosh@Sun.COM 	if ((wcs = NDR_MALLOC(mxa, wcslen)) == NULL) {
820*13082SJoyce.McIntosh@Sun.COM 		status = ERROR_NOT_ENOUGH_MEMORY;
821*13082SJoyce.McIntosh@Sun.COM 		goto report_error;
822*13082SJoyce.McIntosh@Sun.COM 	}
823*13082SJoyce.McIntosh@Sun.COM 
824*13082SJoyce.McIntosh@Sun.COM 	(void) ndr_mbstowcs(NULL, wcs, buf, wcslen);
825*13082SJoyce.McIntosh@Sun.COM 	param->Buf = (uint8_t *)wcs;
826*13082SJoyce.McIntosh@Sun.COM 	param->Needed = wcslen;
827*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_SUCCESS;
828*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
829*13082SJoyce.McIntosh@Sun.COM 
830*13082SJoyce.McIntosh@Sun.COM need_more_data:
831*13082SJoyce.McIntosh@Sun.COM 	param->Size = 0;
832*13082SJoyce.McIntosh@Sun.COM 	param->Buf = reserved_buf;
833*13082SJoyce.McIntosh@Sun.COM 	param->status = ERROR_MORE_DATA;
834*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
83512890SJoyce.McIntosh@Sun.COM }
83612890SJoyce.McIntosh@Sun.COM 
83712890SJoyce.McIntosh@Sun.COM void
smb_rpc_off(char * dst,char * src,uint32_t * offset,uint32_t * outoffset)83812890SJoyce.McIntosh@Sun.COM smb_rpc_off(char *dst, char *src, uint32_t *offset, uint32_t *outoffset)
83912890SJoyce.McIntosh@Sun.COM {
84012890SJoyce.McIntosh@Sun.COM 	int nwchars;
84112890SJoyce.McIntosh@Sun.COM 	int bytes;
84212890SJoyce.McIntosh@Sun.COM 
84312890SJoyce.McIntosh@Sun.COM 	bytes = smb_wcequiv_strlen(src) + 2;
84412890SJoyce.McIntosh@Sun.COM 	nwchars = strlen(src) + 1;
84512890SJoyce.McIntosh@Sun.COM 	*offset -= bytes;
84612890SJoyce.McIntosh@Sun.COM 	*outoffset = *offset;
84712890SJoyce.McIntosh@Sun.COM 	/*LINTED E_BAD_PTR_CAST_ALIGN*/
84812890SJoyce.McIntosh@Sun.COM 	(void) smb_mbstowcs(((smb_wchar_t *)(dst + *offset)), src, nwchars);
84912890SJoyce.McIntosh@Sun.COM }
85012890SJoyce.McIntosh@Sun.COM 
85112890SJoyce.McIntosh@Sun.COM int
spoolss_s_GetPrinter(void * arg,ndr_xa_t * mxa)85212890SJoyce.McIntosh@Sun.COM spoolss_s_GetPrinter(void *arg, ndr_xa_t *mxa)
85312890SJoyce.McIntosh@Sun.COM {
854*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_GetPrinter	*param = arg;
855*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_GetPrinter0	*pinfo0;
856*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_GetPrinter1	*pinfo1;
857*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_GetPrinter2	*pinfo2;
858*13082SJoyce.McIntosh@Sun.COM 	struct spoolss_DeviceMode	*devmode2;
859*13082SJoyce.McIntosh@Sun.COM 	ndr_hdid_t	*id = (ndr_hdid_t *)&param->handle;
860*13082SJoyce.McIntosh@Sun.COM 	spoolss_sd_t	secdesc;
861*13082SJoyce.McIntosh@Sun.COM 	char		server[MAXNAMELEN];
862*13082SJoyce.McIntosh@Sun.COM 	char		printer[MAXNAMELEN];
863*13082SJoyce.McIntosh@Sun.COM 	DWORD		status = ERROR_SUCCESS;
864*13082SJoyce.McIntosh@Sun.COM 	char		*wname;
865*13082SJoyce.McIntosh@Sun.COM 	uint32_t	offset;
866*13082SJoyce.McIntosh@Sun.COM 	uint8_t		*tmpbuf;
86712890SJoyce.McIntosh@Sun.COM 
868*13082SJoyce.McIntosh@Sun.COM 	if (ndr_hdlookup(mxa, id) == NULL) {
869*13082SJoyce.McIntosh@Sun.COM 		status = ERROR_INVALID_HANDLE;
870*13082SJoyce.McIntosh@Sun.COM 		goto error_out;
871*13082SJoyce.McIntosh@Sun.COM 	}
872*13082SJoyce.McIntosh@Sun.COM 
873*13082SJoyce.McIntosh@Sun.COM 	if (spoolss_getservername(server, MAXNAMELEN) != 0) {
874*13082SJoyce.McIntosh@Sun.COM 		status = ERROR_INTERNAL_ERROR;
87512890SJoyce.McIntosh@Sun.COM 		goto error_out;
87612890SJoyce.McIntosh@Sun.COM 	}
877*13082SJoyce.McIntosh@Sun.COM 
878*13082SJoyce.McIntosh@Sun.COM 	(void) snprintf(printer, MAXNAMELEN, "%s\\%s", server, SPOOLSS_PRINTER);
879*13082SJoyce.McIntosh@Sun.COM 
880*13082SJoyce.McIntosh@Sun.COM 	switch (param->switch_value) {
881*13082SJoyce.McIntosh@Sun.COM 	case 0:
882*13082SJoyce.McIntosh@Sun.COM 	case 1:
883*13082SJoyce.McIntosh@Sun.COM 		param->needed = 460;
884*13082SJoyce.McIntosh@Sun.COM 		break;
885*13082SJoyce.McIntosh@Sun.COM 	case 2:
886*13082SJoyce.McIntosh@Sun.COM 		param->needed = 712;
887*13082SJoyce.McIntosh@Sun.COM 		break;
888*13082SJoyce.McIntosh@Sun.COM 	default:
889*13082SJoyce.McIntosh@Sun.COM 		status = ERROR_INVALID_LEVEL;
890*13082SJoyce.McIntosh@Sun.COM 		goto error_out;
891*13082SJoyce.McIntosh@Sun.COM 	}
892*13082SJoyce.McIntosh@Sun.COM 
893*13082SJoyce.McIntosh@Sun.COM 	if (param->BufCount < param->needed) {
894*13082SJoyce.McIntosh@Sun.COM 		param->BufCount = 0;
895*13082SJoyce.McIntosh@Sun.COM 		param->Buf = NULL;
896*13082SJoyce.McIntosh@Sun.COM 		param->status = ERROR_INSUFFICIENT_BUFFER;
897*13082SJoyce.McIntosh@Sun.COM 		return (NDR_DRC_OK);
898*13082SJoyce.McIntosh@Sun.COM 	}
899*13082SJoyce.McIntosh@Sun.COM 
900*13082SJoyce.McIntosh@Sun.COM 	if ((param->Buf = NDR_MALLOC(mxa, param->BufCount)) == NULL) {
901*13082SJoyce.McIntosh@Sun.COM 		status = ERROR_NOT_ENOUGH_MEMORY;
902*13082SJoyce.McIntosh@Sun.COM 		goto error_out;
903*13082SJoyce.McIntosh@Sun.COM 	}
904*13082SJoyce.McIntosh@Sun.COM 
90512890SJoyce.McIntosh@Sun.COM 	bzero(param->Buf, param->BufCount);
906*13082SJoyce.McIntosh@Sun.COM 	wname = (char *)param->Buf;
907*13082SJoyce.McIntosh@Sun.COM 	offset = param->needed;
908*13082SJoyce.McIntosh@Sun.COM 
90912890SJoyce.McIntosh@Sun.COM 	switch (param->switch_value) {
91012890SJoyce.McIntosh@Sun.COM 	case 0:
91112890SJoyce.McIntosh@Sun.COM 		/*LINTED E_BAD_PTR_CAST_ALIGN*/
91212890SJoyce.McIntosh@Sun.COM 		pinfo0 = (struct spoolss_GetPrinter0 *)param->Buf;
91312890SJoyce.McIntosh@Sun.COM 
914*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, server, &offset, &pinfo0->servername);
915*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, printer, &offset, &pinfo0->printername);
91612890SJoyce.McIntosh@Sun.COM 		pinfo0->cjobs = 0;
91712890SJoyce.McIntosh@Sun.COM 		pinfo0->total_jobs = 6;
91812890SJoyce.McIntosh@Sun.COM 		pinfo0->total_bytes = 1040771;
91912890SJoyce.McIntosh@Sun.COM 		pinfo0->time0 = 0;
92012890SJoyce.McIntosh@Sun.COM 		pinfo0->time1 = 0;
92112890SJoyce.McIntosh@Sun.COM 		pinfo0->time2 = 3;
92212890SJoyce.McIntosh@Sun.COM 		pinfo0->time3 = 0;
92312890SJoyce.McIntosh@Sun.COM 		pinfo0->global_counter = 2162710;
92412890SJoyce.McIntosh@Sun.COM 		pinfo0->total_pages = 21495865;
92512890SJoyce.McIntosh@Sun.COM 		pinfo0->version = 10;
92612890SJoyce.McIntosh@Sun.COM 		pinfo0->session_counter = 1;
92712890SJoyce.McIntosh@Sun.COM 		pinfo0->job_error = 0x6;
92812890SJoyce.McIntosh@Sun.COM 		pinfo0->change_id  = 0x1;
92912890SJoyce.McIntosh@Sun.COM 		pinfo0->status = 0;
93012890SJoyce.McIntosh@Sun.COM 		pinfo0->c_setprinter = 0;
93112890SJoyce.McIntosh@Sun.COM 		break;
93212890SJoyce.McIntosh@Sun.COM 	case 1:
933*13082SJoyce.McIntosh@Sun.COM 		/*LINTED E_BAD_PTR_CAST_ALIGN*/
934*13082SJoyce.McIntosh@Sun.COM 		pinfo1 = (struct spoolss_GetPrinter1 *)param->Buf;
935*13082SJoyce.McIntosh@Sun.COM 
93612890SJoyce.McIntosh@Sun.COM 		pinfo1->flags = PRINTER_ENUM_ICON8;
937*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, printer, &offset, &pinfo1->flags);
938*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, printer, &offset, &pinfo1->description);
939*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, printer, &offset, &pinfo1->comment);
94012890SJoyce.McIntosh@Sun.COM 		break;
94112890SJoyce.McIntosh@Sun.COM 	case 2:
942*13082SJoyce.McIntosh@Sun.COM 		/*LINTED E_BAD_PTR_CAST_ALIGN*/
943*13082SJoyce.McIntosh@Sun.COM 		pinfo2 = (struct spoolss_GetPrinter2 *)param->Buf;
944*13082SJoyce.McIntosh@Sun.COM 
945*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, server, &offset, &pinfo2->servername);
946*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, printer, &offset, &pinfo2->printername);
94712890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, SPOOLSS_PRINTER, &offset,
94812890SJoyce.McIntosh@Sun.COM 		    &pinfo2->sharename);
94912890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "CIFS Printer Port", &offset,
95012890SJoyce.McIntosh@Sun.COM 		    &pinfo2->portname);
95112890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "", &offset, &pinfo2->drivername);
95212890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, SPOOLSS_PRINTER, &offset,
95312890SJoyce.McIntosh@Sun.COM 		    &pinfo2->comment);
95412890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "farside", &offset, &pinfo2->location);
955*13082SJoyce.McIntosh@Sun.COM 
956*13082SJoyce.McIntosh@Sun.COM 		offset -= sizeof (struct spoolss_DeviceMode);
957*13082SJoyce.McIntosh@Sun.COM 		pinfo2->devmode = offset;
958*13082SJoyce.McIntosh@Sun.COM 		/*LINTED E_BAD_PTR_CAST_ALIGN*/
959*13082SJoyce.McIntosh@Sun.COM 		devmode2 = (struct spoolss_DeviceMode *)(param->Buf + offset);
960*13082SJoyce.McIntosh@Sun.COM 
96112890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "farside", &offset, &pinfo2->sepfile);
96212890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "winprint", &offset,
96312890SJoyce.McIntosh@Sun.COM 		    &pinfo2->printprocessor);
96412890SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "RAW", &offset, &pinfo2->datatype);
965*13082SJoyce.McIntosh@Sun.COM 		smb_rpc_off(wname, "", &offset, &pinfo2->parameters);
966*13082SJoyce.McIntosh@Sun.COM 
967*13082SJoyce.McIntosh@Sun.COM 		status = spoolss_make_sd(mxa, &secdesc);
968*13082SJoyce.McIntosh@Sun.COM 		if (status == ERROR_SUCCESS) {
969*13082SJoyce.McIntosh@Sun.COM 			offset -= secdesc.sd_size;
970*13082SJoyce.McIntosh@Sun.COM 			pinfo2->secdesc = offset;
971*13082SJoyce.McIntosh@Sun.COM 			tmpbuf = (uint8_t *)(param->Buf + offset);
972*13082SJoyce.McIntosh@Sun.COM 			bcopy(secdesc.sd_buf, tmpbuf, secdesc.sd_size);
973*13082SJoyce.McIntosh@Sun.COM 		}
974*13082SJoyce.McIntosh@Sun.COM 
97512890SJoyce.McIntosh@Sun.COM 		pinfo2->attributes = 0x00001048;
97612890SJoyce.McIntosh@Sun.COM 		pinfo2->status = 0x00000000;
97712890SJoyce.McIntosh@Sun.COM 		pinfo2->starttime = 0;
97812890SJoyce.McIntosh@Sun.COM 		pinfo2->untiltime = 0;
97912890SJoyce.McIntosh@Sun.COM 		pinfo2->cjobs = 0;
98012890SJoyce.McIntosh@Sun.COM 		pinfo2->averageppm = 0;
98112890SJoyce.McIntosh@Sun.COM 		pinfo2->defaultpriority = 0;
982*13082SJoyce.McIntosh@Sun.COM 
98312890SJoyce.McIntosh@Sun.COM 		/*LINTED E_BAD_PTR_CAST_ALIGN*/
984*13082SJoyce.McIntosh@Sun.COM 		(void) smb_mbstowcs((smb_wchar_t *)devmode2->devicename,
985*13082SJoyce.McIntosh@Sun.COM 		    printer, 32);
98612890SJoyce.McIntosh@Sun.COM 		devmode2->specversion = 0x0401;
98712890SJoyce.McIntosh@Sun.COM 		devmode2->driverversion = 1024;
98812890SJoyce.McIntosh@Sun.COM 		devmode2->size = 220;
98912890SJoyce.McIntosh@Sun.COM 		devmode2->driverextra_length = 0;
99012890SJoyce.McIntosh@Sun.COM 		devmode2->fields = 0x00014713;
99112890SJoyce.McIntosh@Sun.COM 		devmode2->orientation = 1;
99212890SJoyce.McIntosh@Sun.COM 		devmode2->papersize = 1;
99312890SJoyce.McIntosh@Sun.COM 		devmode2->paperlength = 0;
99412890SJoyce.McIntosh@Sun.COM 		devmode2->paperwidth = 0;
99512890SJoyce.McIntosh@Sun.COM 		devmode2->scale = 100;
99612890SJoyce.McIntosh@Sun.COM 		devmode2->copies = 1;
99712890SJoyce.McIntosh@Sun.COM 		devmode2->defaultsource = 15;
99812890SJoyce.McIntosh@Sun.COM 		devmode2->printquality = 65532;
99912890SJoyce.McIntosh@Sun.COM 		devmode2->color = 1;
100012890SJoyce.McIntosh@Sun.COM 		devmode2->duplex = 1;
100112890SJoyce.McIntosh@Sun.COM 		devmode2->yresolution = 1;
100212890SJoyce.McIntosh@Sun.COM 		devmode2->ttoption = 1;
100312890SJoyce.McIntosh@Sun.COM 		devmode2->collate = 0;
100412890SJoyce.McIntosh@Sun.COM 		/*LINTED E_BAD_PTR_CAST_ALIGN*/
1005*13082SJoyce.McIntosh@Sun.COM 		(void) smb_mbstowcs((smb_wchar_t *)devmode2->formname,
1006*13082SJoyce.McIntosh@Sun.COM 		    "Letter", 32);
100712890SJoyce.McIntosh@Sun.COM 		devmode2->logpixels = 0;
100812890SJoyce.McIntosh@Sun.COM 		devmode2->bitsperpel = 0;
100912890SJoyce.McIntosh@Sun.COM 		devmode2->pelswidth = 0;
101012890SJoyce.McIntosh@Sun.COM 		devmode2->pelsheight = 0;
101112890SJoyce.McIntosh@Sun.COM 		devmode2->displayflags = 0;
101212890SJoyce.McIntosh@Sun.COM 		devmode2->displayfrequency = 0;
101312890SJoyce.McIntosh@Sun.COM 		devmode2->icmmethod = 0;
101412890SJoyce.McIntosh@Sun.COM 		devmode2->icmintent = 0;
101512890SJoyce.McIntosh@Sun.COM 		devmode2->mediatype = 0;
101612890SJoyce.McIntosh@Sun.COM 		devmode2->dithertype = 0;
101712890SJoyce.McIntosh@Sun.COM 		devmode2->reserved1 = 0;
101812890SJoyce.McIntosh@Sun.COM 		devmode2->reserved2 = 0;
101912890SJoyce.McIntosh@Sun.COM 		devmode2->panningwidth = 0;
102012890SJoyce.McIntosh@Sun.COM 		devmode2->panningheight = 0;
102112890SJoyce.McIntosh@Sun.COM 		break;
102212890SJoyce.McIntosh@Sun.COM 
102312890SJoyce.McIntosh@Sun.COM 	default:
102412890SJoyce.McIntosh@Sun.COM 		break;
1025*13082SJoyce.McIntosh@Sun.COM 	}
102612890SJoyce.McIntosh@Sun.COM 
1027*13082SJoyce.McIntosh@Sun.COM 	param->status = status;
1028*13082SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
1029*13082SJoyce.McIntosh@Sun.COM 
103012890SJoyce.McIntosh@Sun.COM error_out:
1031*13082SJoyce.McIntosh@Sun.COM 	smb_tracef("spoolss_s_GetPrinter: error %u", status);
1032*13082SJoyce.McIntosh@Sun.COM 	bzero(param, sizeof (struct spoolss_GetPrinter));
103312890SJoyce.McIntosh@Sun.COM 	param->status = status;
103412890SJoyce.McIntosh@Sun.COM 	return (NDR_DRC_OK);
103512890SJoyce.McIntosh@Sun.COM }
103612890SJoyce.McIntosh@Sun.COM 
1037*13082SJoyce.McIntosh@Sun.COM static int
spoolss_getservername(char * name,size_t namelen)1038*13082SJoyce.McIntosh@Sun.COM spoolss_getservername(char *name, size_t namelen)
103912890SJoyce.McIntosh@Sun.COM {
1040*13082SJoyce.McIntosh@Sun.COM 	char		hostname[MAXHOSTNAMELEN];
1041*13082SJoyce.McIntosh@Sun.COM 	char		ipstr[INET6_ADDRSTRLEN];
1042*13082SJoyce.McIntosh@Sun.COM 	smb_inaddr_t	ipaddr;
1043*13082SJoyce.McIntosh@Sun.COM 	struct hostent	*h;
1044*13082SJoyce.McIntosh@Sun.COM 	const char	*p;
1045*13082SJoyce.McIntosh@Sun.COM 	int		error;
1046*13082SJoyce.McIntosh@Sun.COM 
1047*13082SJoyce.McIntosh@Sun.COM 	if (smb_gethostname(hostname, MAXHOSTNAMELEN, 0) != 0) {
1048*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_GetPrinter: gethostname failed");
1049*13082SJoyce.McIntosh@Sun.COM 		return (-1);
1050*13082SJoyce.McIntosh@Sun.COM 	}
1051*13082SJoyce.McIntosh@Sun.COM 
1052*13082SJoyce.McIntosh@Sun.COM 	if ((h = smb_gethostbyname(hostname, &error)) == NULL) {
1053*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_GetPrinter: gethostbyname failed: %d",
1054*13082SJoyce.McIntosh@Sun.COM 		    error);
1055*13082SJoyce.McIntosh@Sun.COM 		return (-1);
1056*13082SJoyce.McIntosh@Sun.COM 	}
1057*13082SJoyce.McIntosh@Sun.COM 
1058*13082SJoyce.McIntosh@Sun.COM 	bcopy(h->h_addr, &ipaddr, h->h_length);
1059*13082SJoyce.McIntosh@Sun.COM 	ipaddr.a_family = h->h_addrtype;
1060*13082SJoyce.McIntosh@Sun.COM 	freehostent(h);
1061*13082SJoyce.McIntosh@Sun.COM 
1062*13082SJoyce.McIntosh@Sun.COM 	p = smb_inet_ntop(&ipaddr, ipstr, SMB_IPSTRLEN(ipaddr.a_family));
1063*13082SJoyce.McIntosh@Sun.COM 	if (p == NULL) {
1064*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_s_GetPrinter: inet_ntop failed");
1065*13082SJoyce.McIntosh@Sun.COM 		return (-1);
1066*13082SJoyce.McIntosh@Sun.COM 	}
1067*13082SJoyce.McIntosh@Sun.COM 
1068*13082SJoyce.McIntosh@Sun.COM 	(void) snprintf(name, namelen, "\\\\%s", ipstr);
1069*13082SJoyce.McIntosh@Sun.COM 	return (0);
1070*13082SJoyce.McIntosh@Sun.COM }
1071*13082SJoyce.McIntosh@Sun.COM 
1072*13082SJoyce.McIntosh@Sun.COM static uint32_t
spoolss_make_sd(ndr_xa_t * mxa,spoolss_sd_t * secdesc)1073*13082SJoyce.McIntosh@Sun.COM spoolss_make_sd(ndr_xa_t *mxa, spoolss_sd_t *secdesc)
1074*13082SJoyce.McIntosh@Sun.COM {
1075*13082SJoyce.McIntosh@Sun.COM 	smb_sd_t	sd;
1076*13082SJoyce.McIntosh@Sun.COM 	uint8_t		*sd_buf;
1077*13082SJoyce.McIntosh@Sun.COM 	uint32_t	sd_len;
1078*13082SJoyce.McIntosh@Sun.COM 	uint32_t	status;
107912890SJoyce.McIntosh@Sun.COM 
108012890SJoyce.McIntosh@Sun.COM 	bzero(&sd, sizeof (smb_sd_t));
108112890SJoyce.McIntosh@Sun.COM 
1082*13082SJoyce.McIntosh@Sun.COM 	if ((status = spoolss_format_sd(&sd)) != ERROR_SUCCESS)
1083*13082SJoyce.McIntosh@Sun.COM 		return (status);
1084*13082SJoyce.McIntosh@Sun.COM 
1085*13082SJoyce.McIntosh@Sun.COM 	sd_len = smb_sd_len(&sd, SMB_ALL_SECINFO);
1086*13082SJoyce.McIntosh@Sun.COM 
1087*13082SJoyce.McIntosh@Sun.COM 	if ((sd_buf = NDR_MALLOC(mxa, sd_len)) == NULL)
1088*13082SJoyce.McIntosh@Sun.COM 		return (ERROR_NOT_ENOUGH_MEMORY);
1089*13082SJoyce.McIntosh@Sun.COM 
1090*13082SJoyce.McIntosh@Sun.COM 	secdesc->sd_buf = sd_buf;
1091*13082SJoyce.McIntosh@Sun.COM 	secdesc->sd_size = sd_len;
1092*13082SJoyce.McIntosh@Sun.COM 
1093*13082SJoyce.McIntosh@Sun.COM 	status = srvsvc_sd_set_relative(&sd, sd_buf);
109412890SJoyce.McIntosh@Sun.COM 	smb_sd_term(&sd);
1095*13082SJoyce.McIntosh@Sun.COM 	return (status);
109612890SJoyce.McIntosh@Sun.COM }
109712890SJoyce.McIntosh@Sun.COM 
109812890SJoyce.McIntosh@Sun.COM static uint32_t
spoolss_format_sd(smb_sd_t * sd)1099*13082SJoyce.McIntosh@Sun.COM spoolss_format_sd(smb_sd_t *sd)
110012890SJoyce.McIntosh@Sun.COM {
110112890SJoyce.McIntosh@Sun.COM 	smb_fssd_t	fs_sd;
110212890SJoyce.McIntosh@Sun.COM 	acl_t		*acl;
110312890SJoyce.McIntosh@Sun.COM 	uint32_t	status = ERROR_SUCCESS;
110412890SJoyce.McIntosh@Sun.COM 
110512890SJoyce.McIntosh@Sun.COM 	if (acl_fromtext("everyone@:full_set::allow", &acl) != 0) {
1106*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_format_sd: NOT_ENOUGH_MEMORY");
110712890SJoyce.McIntosh@Sun.COM 		return (ERROR_NOT_ENOUGH_MEMORY);
110812890SJoyce.McIntosh@Sun.COM 	}
110912890SJoyce.McIntosh@Sun.COM 	smb_fssd_init(&fs_sd, SMB_ALL_SECINFO, SMB_FSSD_FLAGS_DIR);
111012890SJoyce.McIntosh@Sun.COM 	fs_sd.sd_uid = 0;
111112890SJoyce.McIntosh@Sun.COM 	fs_sd.sd_gid = 0;
111212890SJoyce.McIntosh@Sun.COM 	fs_sd.sd_zdacl = acl;
111312890SJoyce.McIntosh@Sun.COM 	fs_sd.sd_zsacl = NULL;
111412890SJoyce.McIntosh@Sun.COM 
1115*13082SJoyce.McIntosh@Sun.COM 	status = smb_sd_fromfs(&fs_sd, sd);
1116*13082SJoyce.McIntosh@Sun.COM 	if (status != NT_STATUS_SUCCESS) {
1117*13082SJoyce.McIntosh@Sun.COM 		smb_tracef("spoolss_format_sd: %u", status);
111812890SJoyce.McIntosh@Sun.COM 		status = ERROR_ACCESS_DENIED;
111912890SJoyce.McIntosh@Sun.COM 	}
112012890SJoyce.McIntosh@Sun.COM 	smb_fssd_term(&fs_sd);
112112890SJoyce.McIntosh@Sun.COM 	return (status);
112212890SJoyce.McIntosh@Sun.COM }
112312890SJoyce.McIntosh@Sun.COM 
112412890SJoyce.McIntosh@Sun.COM /*ARGSUSED*/
112512890SJoyce.McIntosh@Sun.COM static int
spoolss_s_stub(void * arg,ndr_xa_t * mxa)11268334SJose.Borrego@Sun.COM spoolss_s_stub(void *arg, ndr_xa_t *mxa)
11278334SJose.Borrego@Sun.COM {
11288334SJose.Borrego@Sun.COM 	return (NDR_DRC_FAULT_PARAM_0_UNIMPLEMENTED);
11298334SJose.Borrego@Sun.COM }
113012890SJoyce.McIntosh@Sun.COM 
113112890SJoyce.McIntosh@Sun.COM void
fixup_spoolss_RFNPCNEX(struct spoolss_RFNPCNEX * val)113212890SJoyce.McIntosh@Sun.COM fixup_spoolss_RFNPCNEX(struct spoolss_RFNPCNEX *val)
113312890SJoyce.McIntosh@Sun.COM {
113412890SJoyce.McIntosh@Sun.COM 	unsigned short size1 = 0;
113512890SJoyce.McIntosh@Sun.COM 	unsigned short size2 = 0;
113612890SJoyce.McIntosh@Sun.COM 	unsigned short size3 = 0;
113712890SJoyce.McIntosh@Sun.COM 	struct spoolss_RPC_V2_NOTIFY_INFO *pinfo;
113812890SJoyce.McIntosh@Sun.COM 
113912890SJoyce.McIntosh@Sun.COM 	pinfo = val->ppinfo->pinfo;
114012890SJoyce.McIntosh@Sun.COM 	switch (pinfo->aData->Reserved) {
114112890SJoyce.McIntosh@Sun.COM 	case TABLE_STRING:
114212890SJoyce.McIntosh@Sun.COM 		size1 = sizeof (struct STRING_CONTAINER);
114312890SJoyce.McIntosh@Sun.COM 		break;
114412890SJoyce.McIntosh@Sun.COM 	case TABLE_DWORD:
114512890SJoyce.McIntosh@Sun.COM 		size1 = sizeof (DWORD) * 2;
114612890SJoyce.McIntosh@Sun.COM 		break;
114712890SJoyce.McIntosh@Sun.COM 	case TABLE_TIME:
114812890SJoyce.McIntosh@Sun.COM 		size1 = sizeof (struct SYSTEMTIME_CONTAINER);
114912890SJoyce.McIntosh@Sun.COM 		break;
115012890SJoyce.McIntosh@Sun.COM 	case TABLE_DEVMODE:
115112890SJoyce.McIntosh@Sun.COM 		size1 = sizeof (struct spoolssDevmodeContainer);
115212890SJoyce.McIntosh@Sun.COM 		break;
115312890SJoyce.McIntosh@Sun.COM 	case TABLE_SECURITY_DESCRIPTOR:
115412890SJoyce.McIntosh@Sun.COM 		size1 = sizeof (struct SECURITY_CONTAINER);
115512890SJoyce.McIntosh@Sun.COM 		break;
115612890SJoyce.McIntosh@Sun.COM 	default:
115712890SJoyce.McIntosh@Sun.COM 		return;
115812890SJoyce.McIntosh@Sun.COM 	}
115912890SJoyce.McIntosh@Sun.COM 	size2 = size1 + (2 * sizeof (DWORD));
116012890SJoyce.McIntosh@Sun.COM 	size3 = size2 + sizeof (ndr_request_hdr_t) + sizeof (DWORD);
116112890SJoyce.McIntosh@Sun.COM 
116212890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO_DATA_DATA, size1);
116312890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO_DATA, size2);
116412890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO, size3);
116512890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_RFNPCNEX, size3);
116612890SJoyce.McIntosh@Sun.COM }
116712890SJoyce.McIntosh@Sun.COM 
116812890SJoyce.McIntosh@Sun.COM void
fixup_spoolss_GetPrinter(struct spoolss_GetPrinter * val)116912890SJoyce.McIntosh@Sun.COM fixup_spoolss_GetPrinter(struct spoolss_GetPrinter *val)
117012890SJoyce.McIntosh@Sun.COM {
117112890SJoyce.McIntosh@Sun.COM 	unsigned short size1 = 0;
117212890SJoyce.McIntosh@Sun.COM 	unsigned short size2 = 0;
117312890SJoyce.McIntosh@Sun.COM 	unsigned short size3 = 0;
117412890SJoyce.McIntosh@Sun.COM 
117512890SJoyce.McIntosh@Sun.COM 	switch (val->switch_value) {
117612890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 0);
117712890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 1);
117812890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 2);
117912890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 3);
118012890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 4);
118112890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 5);
118212890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 6);
118312890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 7);
118412890SJoyce.McIntosh@Sun.COM 	CASE_INFO_ENT(spoolss_GetPrinter, 8);
118512890SJoyce.McIntosh@Sun.COM 
118612890SJoyce.McIntosh@Sun.COM 	default:
118712890SJoyce.McIntosh@Sun.COM 		return;
118812890SJoyce.McIntosh@Sun.COM 	};
118912890SJoyce.McIntosh@Sun.COM 
119012890SJoyce.McIntosh@Sun.COM 	size2 = size1 + (2 * sizeof (DWORD));
119112890SJoyce.McIntosh@Sun.COM 	size3 = size2 + sizeof (ndr_request_hdr_t) + sizeof (DWORD);
119212890SJoyce.McIntosh@Sun.COM 
119312890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_GetPrinter_result_u, size1);
119412890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_GetPrinter_result, size2);
119512890SJoyce.McIntosh@Sun.COM 	FIXUP_PDU_SIZE(spoolss_GetPrinter, size3);
119612890SJoyce.McIntosh@Sun.COM }
1197