spoolss_svc.c revision 86d7016b0051dd58772baafe5b5bcee51d560b05
8d7e41661dc4633488e93b13363137523ce59977jose borrego * CDDL HEADER START
8d7e41661dc4633488e93b13363137523ce59977jose borrego * The contents of this file are subject to the terms of the
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Common Development and Distribution License (the "License").
8d7e41661dc4633488e93b13363137523ce59977jose borrego * You may not use this file except in compliance with the License.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8d7e41661dc4633488e93b13363137523ce59977jose borrego * See the License for the specific language governing permissions
8d7e41661dc4633488e93b13363137523ce59977jose borrego * and limitations under the License.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * When distributing Covered Code, include this CDDL HEADER in each
8d7e41661dc4633488e93b13363137523ce59977jose borrego * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * If applicable, add the following below this CDDL HEADER, with the
8d7e41661dc4633488e93b13363137523ce59977jose borrego * fields enclosed by brackets "[]" replaced with your own identifying
8d7e41661dc4633488e93b13363137523ce59977jose borrego * information: Portions Copyright [yyyy] [name of copyright owner]
8d7e41661dc4633488e93b13363137523ce59977jose borrego * CDDL HEADER END
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Printing and Spooling RPC service.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshtypedef struct smb_spool {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshtypedef struct smb_spooldoc {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshtypedef struct {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshtypedef struct {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshvoid (*spoolss_copyfile_callback)(smb_inaddr_t *, char *, char *, char *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshDECL_FIXUP_STRUCT(spoolss_GetPrinter_result_u);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshDECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO_DATA_DATA);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshDECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO_DATA);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshDECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshuint32_t srvsvc_sd_set_relative(smb_sd_t *, uint8_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_getservername(char *, size_t);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic uint32_t spoolss_make_sd(ndr_xa_t *, spoolss_sd_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic uint32_t spoolss_format_sd(smb_sd_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_find_document(ndr_hdid_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_OpenPrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_ClosePrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_AbortPrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_ResetPrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_GetPrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_GetPrinterData(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_AddJob(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_GetJob(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_EnumJobs(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_ScheduleJob(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_StartDocPrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_EndDocPrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_StartPagePrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_EndPagePrinter(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_rfnpcnex(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_WritePrinter(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_AddForm(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_DeleteForm(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_EnumForms(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_AddMonitor(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_DeleteMonitor(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_DeletePort(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_AddPortEx(void *, ndr_xa_t *);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshstatic int spoolss_s_SetPort(void *, ndr_xa_t *);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshstatic int spoolss_s_stub(void *, ndr_xa_t *);
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic ndr_stub_table_t spoolss_stub_table[] = {
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_EnumJobs, SPOOLSS_OPNUM_EnumJobs },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_DeletePrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_GetPrinter, SPOOLSS_OPNUM_GetPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_GetPrinterDriver },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_DeletePrinterDriver },
8d7e41661dc4633488e93b13363137523ce59977jose borrego { spoolss_s_OpenPrinter, SPOOLSS_OPNUM_OpenPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_StartDocPrinter, SPOOLSS_OPNUM_StartDocPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_WritePrinter, SPOOLSS_OPNUM_WritePrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_EndDocPrinter, SPOOLSS_OPNUM_EndDocPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_StartPagePrinter, SPOOLSS_OPNUM_StartPagePrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_EndPagePrinter, SPOOLSS_OPNUM_EndPagePrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_AbortPrinter, SPOOLSS_OPNUM_AbortPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_ResetPrinter, SPOOLSS_OPNUM_ResetPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_ScheduleJob, SPOOLSS_OPNUM_ScheduleJob },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_GetPrinterData, SPOOLSS_OPNUM_GetPrinterData },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_ClosePrinter, SPOOLSS_OPNUM_ClosePrinter },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_AddForm, SPOOLSS_OPNUM_AddForm },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_DeleteForm, SPOOLSS_OPNUM_DeleteForm },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_EnumForms, SPOOLSS_OPNUM_EnumForms },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_AddMonitor, SPOOLSS_OPNUM_AddMonitor },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_DeleteMonitor, SPOOLSS_OPNUM_DeleteMonitor },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_DeletePort, SPOOLSS_OPNUM_DeletePort },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_AddPortEx, SPOOLSS_OPNUM_AddPortEx },
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh { spoolss_s_SetPort, SPOOLSS_OPNUM_SetPort },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_GetPrinterDriver2 },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_ReplyOpenPrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_ReplyClosePrinter },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_rfnpcnex, SPOOLSS_OPNUM_RFNPCNEX },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_OpenPrinter, SPOOLSS_OPNUM_OpenPrinterEx },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_EnumPrinterData },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_EnumPrinterDataEx },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_EnumPrinterKey },
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh "12345678-1234-abcd-ef00-0123456789ab", 1, /* abstract */
8d7e41661dc4633488e93b13363137523ce59977jose borrego 0, /* no bind_instance_size */
8d7e41661dc4633488e93b13363137523ce59977jose borrego 0, /* no bind_req() */
8d7e41661dc4633488e93b13363137523ce59977jose borrego 0, /* no unbind_and_close() */
8d7e41661dc4633488e93b13363137523ce59977jose borrego 0, /* use generic_call_stub() */
8d7e41661dc4633488e93b13363137523ce59977jose borrego &TYPEINFO(spoolss_interface), /* interface ti */
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Register a copyfile callback that the spoolss service can use to
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * copy files to the spool directory.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Set a null pointer to disable the copying of files to the spool
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_register_copyfile(spoolss_copyfile_t copyfile)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_copyfile(smb_inaddr_t *ipaddr, char *username, char *path,
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (*spoolss_copyfile_callback)(ipaddr, username, path, docname);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(¶m->handle, sizeof (spoolss_handle_t));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_OpenPrinter: %s", name);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh bzero(¶m->handle, sizeof (spoolss_handle_t));
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh bcopy(id, ¶m->handle, sizeof (spoolss_handle_t));
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_StartPagePrinter(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh struct spoolss_StartPagePrinter *param = arg;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_EndPagePrinter(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Windows XP and 2000 use this mechanism to write spool files.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Create a spool file fd to be used by spoolss_s_WritePrinter
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * and add it to the tail of the spool list.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_StartDocPrinter(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_StartDocPrinter: invalid handle");
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if ((docinfo = param->dinfo.DocInfoContainer) == NULL) {
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if ((rc = smb_shr_get(SMB_SHARE_PRINT, &si)) != NERR_Success) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_StartDocPrinter: %s error=%d",
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if ((spfile = calloc(1, sizeof (smb_spooldoc_t))) == NULL) {
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (void) strlcpy(spfile->sd_doc_name, "document", MAXNAMELEN);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (void) strlcpy(spfile->sd_printer_name, "printer", MAXPATHLEN);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh spfile->sd_ipaddr = mxa->pipe->np_user.ui_ipaddr;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) memcpy(&spfile->sd_handle, ¶m->handle, sizeof (ndr_hdid_t));
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * write temporary spool file to print$
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (void) snprintf(g_path, MAXPATHLEN, "%s/%s%d", si.shr_path,
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_StartDocPrinter: %s: %s",
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (void) strlcpy((char *)spfile->sd_path, g_path, MAXPATHLEN);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Add the document to the spool list.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh list_insert_tail(&spoolss_splist.sp_list, spfile);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * JobId isn't used now, but if printQ management is added
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * this will have to be incremented per job submitted.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Windows XP and 2000 use this mechanism to write spool files
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Search the spooldoc list for a matching RPC handle and pass
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * the spool the file for printing.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_EndDocPrinter(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_EndDocPrinter: invalid handle");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (!memcmp(id, &(sp->sd_handle), sizeof (ndr_hdid_t))) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh sp->sd_username, sp->sd_path, sp->sd_doc_name);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_EndDocPrinter: document not found");
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_AbortPrinter(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_ResetPrinter(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_ClosePrinter(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh bzero(¶m->result_handle, sizeof (spoolss_handle_t));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_AddForm));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_AddForm));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_s_DeleteForm(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_DeleteForm));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_DeleteForm));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_EnumForms));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_EnumForms));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_s_AddMonitor(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_s_DeleteMonitor(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_s_DeletePort(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_ScheduleJob(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh * Use the RPC context handle to find the fd and write the document content.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_WritePrinter(void *arg, ndr_xa_t *mxa)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_WritePrinter: invalid handle");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((spfd = spoolss_find_document(id)) < 0) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_WritePrinter: document not found");
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh written = write(spfd, param->pBuf, param->BufCount);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_WritePrinter: write failed");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Find a document by RPC handle in the spool list and return the fd.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (!memcmp(handle, &(sp->sd_handle), sizeof (ndr_hdid_t))) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * GetPrinterData is used t obtain values from the registry for a
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * printer or a print server. See [MS-RPRN] for value descriptions.
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * The registry returns ERROR_FILE_NOT_FOUND for unknown keys.
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_GetPrinterData(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh for (i = 0; i < sizeof (reg) / sizeof (reg[0]); ++i) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((param->Buf = NDR_NEW(mxa, uint32_t)) == NULL) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (smb_config_get_secmode() == SMB_SECMODE_DOMAIN))
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bcopy(&value, param->Buf, sizeof (uint32_t));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((osversion = NDR_NEW(mxa, smb_version_t)) == NULL) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (strcasecmp(name, "DNSMachineName") == 0) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) smb_getfqhostname(buf, MAXHOSTNAMELEN);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (strcasecmp(name, "DefaultSpoolDirectory") == 0) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (smb_shr_get(SMB_SHARE_PRINT, &si) != NERR_Success) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) snprintf(buf, MAXPATHLEN, "C:/%s", si.shr_path);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_GetPrinterData));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh wcslen = smb_wcequiv_strlen(buf) + sizeof (smb_wchar_t);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((wcs = NDR_MALLOC(mxa, wcslen)) == NULL) {
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshsmb_rpc_off(char *dst, char *src, uint32_t *offset, uint32_t *outoffset)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh (void) smb_mbstowcs(((smb_wchar_t *)(dst + *offset)), src, nwchars);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshspoolss_s_GetPrinter(void *arg, ndr_xa_t *mxa)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (spoolss_getservername(server, MAXNAMELEN) != 0) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) snprintf(printer, MAXNAMELEN, "%s\\%s", server, SPOOLSS_PRINTER);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((param->Buf = NDR_MALLOC(mxa, param->BufCount)) == NULL) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pinfo0 = (struct spoolss_GetPrinter0 *)param->Buf;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, server, &offset, &pinfo0->servername);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo0->printername);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pinfo1 = (struct spoolss_GetPrinter1 *)param->Buf;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo1->flags);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo1->description);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo1->comment);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh pinfo2 = (struct spoolss_GetPrinter2 *)param->Buf;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, server, &offset, &pinfo2->servername);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo2->printername);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smb_rpc_off(wname, "CIFS Printer Port", &offset,
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smb_rpc_off(wname, "", &offset, &pinfo2->drivername);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smb_rpc_off(wname, "farside", &offset, &pinfo2->location);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh offset -= sizeof (struct spoolss_DeviceMode);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh devmode2 = (struct spoolss_DeviceMode *)(param->Buf + offset);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smb_rpc_off(wname, "farside", &offset, &pinfo2->sepfile);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smb_rpc_off(wname, "RAW", &offset, &pinfo2->datatype);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_rpc_off(wname, "", &offset, &pinfo2->parameters);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bcopy(secdesc.sd_buf, tmpbuf, secdesc.sd_size);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) smb_mbstowcs((smb_wchar_t *)devmode2->devicename,
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) smb_mbstowcs((smb_wchar_t *)devmode2->formname,
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_GetPrinter: error %u", status);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh bzero(param, sizeof (struct spoolss_GetPrinter));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_getservername(char *name, size_t namelen)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh const char *p;
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if (smb_gethostname(hostname, MAXHOSTNAMELEN, 0) != 0) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_GetPrinter: gethostname failed");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((h = smb_gethostbyname(hostname, &error)) == NULL) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_GetPrinter: gethostbyname failed: %d",
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh p = smb_inet_ntop(&ipaddr, ipstr, SMB_IPSTRLEN(ipaddr.a_family));
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_s_GetPrinter: inet_ntop failed");
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (void) snprintf(name, namelen, "\\\\%s", ipstr);
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintoshspoolss_make_sd(ndr_xa_t *mxa, spoolss_sd_t *secdesc)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((status = spoolss_format_sd(&sd)) != ERROR_SUCCESS)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh if ((sd_buf = NDR_MALLOC(mxa, sd_len)) == NULL)
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh status = srvsvc_sd_set_relative(&sd, sd_buf);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh if (acl_fromtext("everyone@:full_set::allow", &acl) != 0) {
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh smb_tracef("spoolss_format_sd: NOT_ENOUGH_MEMORY");
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh smb_fssd_init(&fs_sd, SMB_ALL_SECINFO, SMB_FSSD_FLAGS_DIR);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshfixup_spoolss_RFNPCNEX(struct spoolss_RFNPCNEX *val)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh unsigned short size1 = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh unsigned short size2 = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh unsigned short size3 = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh size1 = sizeof (struct SYSTEMTIME_CONTAINER);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh size1 = sizeof (struct spoolssDevmodeContainer);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh size3 = size2 + sizeof (ndr_request_hdr_t) + sizeof (DWORD);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO_DATA_DATA, size1);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO_DATA, size2);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO, size3);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintoshfixup_spoolss_GetPrinter(struct spoolss_GetPrinter *val)
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh unsigned short size1 = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh unsigned short size2 = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh unsigned short size3 = 0;
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh size3 = size2 + sizeof (ndr_request_hdr_t) + sizeof (DWORD);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh FIXUP_PDU_SIZE(spoolss_GetPrinter_result_u, size1);
cb174861876aea6950a7ab4ce944aff84b1914cdjoyce mcintosh FIXUP_PDU_SIZE(spoolss_GetPrinter_result, size2);
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross#else /* HAVE_CUPS */
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross * If not HAVE_CUPS, just provide a few "stubs".
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Rossspoolss_register_copyfile(spoolss_copyfile_t copyfile)
86d7016b0051dd58772baafe5b5bcee51d560b05Gordon Ross#endif /* HAVE_CUPS */