18d7e4166Sjose borrego /* 28d7e4166Sjose borrego * CDDL HEADER START 38d7e4166Sjose borrego * 48d7e4166Sjose borrego * The contents of this file are subject to the terms of the 58d7e4166Sjose borrego * Common Development and Distribution License (the "License"). 68d7e4166Sjose borrego * You may not use this file except in compliance with the License. 78d7e4166Sjose borrego * 88d7e4166Sjose borrego * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 98d7e4166Sjose borrego * or http://www.opensolaris.org/os/licensing. 108d7e4166Sjose borrego * See the License for the specific language governing permissions 118d7e4166Sjose borrego * and limitations under the License. 128d7e4166Sjose borrego * 138d7e4166Sjose borrego * When distributing Covered Code, include this CDDL HEADER in each 148d7e4166Sjose borrego * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 158d7e4166Sjose borrego * If applicable, add the following below this CDDL HEADER, with the 168d7e4166Sjose borrego * fields enclosed by brackets "[]" replaced with your own identifying 178d7e4166Sjose borrego * information: Portions Copyright [yyyy] [name of copyright owner] 188d7e4166Sjose borrego * 198d7e4166Sjose borrego * CDDL HEADER END 208d7e4166Sjose borrego */ 218d7e4166Sjose borrego /* 22cb174861Sjoyce mcintosh * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 23*86d7016bSGordon Ross * Copyright 2012 Nexenta Systems, Inc. All rights reserved. 248d7e4166Sjose borrego */ 258d7e4166Sjose borrego 268d7e4166Sjose borrego /* 278d7e4166Sjose borrego * Printing and Spooling RPC service. 288d7e4166Sjose borrego */ 29fd9ee8b5Sjoyce mcintosh #include <sys/types.h> 30fd9ee8b5Sjoyce mcintosh #include <sys/stat.h> 31fd9ee8b5Sjoyce mcintosh #include <sys/utsname.h> 32cb174861Sjoyce mcintosh #include <unistd.h> 338d7e4166Sjose borrego #include <stdlib.h> 348d7e4166Sjose borrego #include <strings.h> 35fd9ee8b5Sjoyce mcintosh #include <fcntl.h> 36fd9ee8b5Sjoyce mcintosh #include <errno.h> 378d7e4166Sjose borrego #include <smbsrv/libsmb.h> 388d7e4166Sjose borrego #include <smbsrv/libmlrpc.h> 398d7e4166Sjose borrego #include <smbsrv/libmlsvc.h> 40fd9ee8b5Sjoyce mcintosh #include <smbsrv/smb.h> 418d7e4166Sjose borrego #include <smbsrv/ndl/spoolss.ndl> 42fd9ee8b5Sjoyce mcintosh #include <smbsrv/ndl/winreg.ndl> 43cb174861Sjoyce mcintosh #include <smb/nterror.h> 448d7e4166Sjose borrego #include <smbsrv/smbinfo.h> 458d7e4166Sjose borrego #include <smbsrv/nmpipes.h> 46cb174861Sjoyce mcintosh #include <mlsvc.h> 478d7e4166Sjose borrego 48*86d7016bSGordon Ross #ifdef HAVE_CUPS 49*86d7016bSGordon Ross 50fd9ee8b5Sjoyce mcintosh #define SPOOLSS_PRINTER "Postscript" 51fd9ee8b5Sjoyce mcintosh 52cb174861Sjoyce mcintosh typedef struct smb_spool { 53cb174861Sjoyce mcintosh list_t sp_list; 54cb174861Sjoyce mcintosh int sp_cnt; 55cb174861Sjoyce mcintosh rwlock_t sp_rwl; 56cb174861Sjoyce mcintosh int sp_initialized; 57cb174861Sjoyce mcintosh } smb_spool_t; 58cb174861Sjoyce mcintosh 59fd9ee8b5Sjoyce mcintosh typedef struct smb_spooldoc { 60fd9ee8b5Sjoyce mcintosh uint32_t sd_magic; 61fd9ee8b5Sjoyce mcintosh list_node_t sd_lnd; 62fd9ee8b5Sjoyce mcintosh smb_inaddr_t sd_ipaddr; 63fd9ee8b5Sjoyce mcintosh int sd_spool_num; 64fd9ee8b5Sjoyce mcintosh char sd_username[MAXNAMELEN]; 65fd9ee8b5Sjoyce mcintosh char sd_path[MAXPATHLEN]; 66fd9ee8b5Sjoyce mcintosh char sd_doc_name[MAXNAMELEN]; 67fd9ee8b5Sjoyce mcintosh char sd_printer_name[MAXPATHLEN]; 68fd9ee8b5Sjoyce mcintosh int32_t sd_fd; 69fd9ee8b5Sjoyce mcintosh ndr_hdid_t sd_handle; 70fd9ee8b5Sjoyce mcintosh } smb_spooldoc_t; 71fd9ee8b5Sjoyce mcintosh 72fd9ee8b5Sjoyce mcintosh typedef struct { 73fd9ee8b5Sjoyce mcintosh char *name; 74fd9ee8b5Sjoyce mcintosh uint32_t value; 75fd9ee8b5Sjoyce mcintosh } spoolss_winreg_t; 76fd9ee8b5Sjoyce mcintosh 77fd9ee8b5Sjoyce mcintosh typedef struct { 78fd9ee8b5Sjoyce mcintosh uint8_t *sd_buf; 79fd9ee8b5Sjoyce mcintosh uint32_t sd_size; 80fd9ee8b5Sjoyce mcintosh } spoolss_sd_t; 81fd9ee8b5Sjoyce mcintosh 82cb174861Sjoyce mcintosh static uint32_t spoolss_cnt; 83cb174861Sjoyce mcintosh static smb_spool_t spoolss_splist; 84cb174861Sjoyce mcintosh 85fd9ee8b5Sjoyce mcintosh void (*spoolss_copyfile_callback)(smb_inaddr_t *, char *, char *, char *); 86cb174861Sjoyce mcintosh 87cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_GetPrinter_result_u); 88cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_GetPrinter_result); 89cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_GetPrinter); 90cb174861Sjoyce mcintosh 91cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO_DATA_DATA); 92cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO_DATA); 93cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_RPC_V2_NOTIFY_INFO); 94cb174861Sjoyce mcintosh DECL_FIXUP_STRUCT(spoolss_RFNPCNEX); 95cb174861Sjoyce mcintosh 96cb174861Sjoyce mcintosh uint32_t srvsvc_sd_set_relative(smb_sd_t *, uint8_t *); 97fd9ee8b5Sjoyce mcintosh static int spoolss_getservername(char *, size_t); 98fd9ee8b5Sjoyce mcintosh static uint32_t spoolss_make_sd(ndr_xa_t *, spoolss_sd_t *); 99fd9ee8b5Sjoyce mcintosh static uint32_t spoolss_format_sd(smb_sd_t *); 100fd9ee8b5Sjoyce mcintosh static int spoolss_find_document(ndr_hdid_t *); 101cb174861Sjoyce mcintosh 102cb174861Sjoyce mcintosh static int spoolss_s_OpenPrinter(void *, ndr_xa_t *); 103cb174861Sjoyce mcintosh static int spoolss_s_ClosePrinter(void *, ndr_xa_t *); 104cb174861Sjoyce mcintosh static int spoolss_s_AbortPrinter(void *, ndr_xa_t *); 105cb174861Sjoyce mcintosh static int spoolss_s_ResetPrinter(void *, ndr_xa_t *); 106cb174861Sjoyce mcintosh static int spoolss_s_GetPrinter(void *, ndr_xa_t *); 107cb174861Sjoyce mcintosh static int spoolss_s_GetPrinterData(void *, ndr_xa_t *); 108cb174861Sjoyce mcintosh static int spoolss_s_AddJob(void *, ndr_xa_t *); 109cb174861Sjoyce mcintosh static int spoolss_s_GetJob(void *, ndr_xa_t *); 110cb174861Sjoyce mcintosh static int spoolss_s_EnumJobs(void *, ndr_xa_t *); 111cb174861Sjoyce mcintosh static int spoolss_s_ScheduleJob(void *, ndr_xa_t *); 112cb174861Sjoyce mcintosh static int spoolss_s_StartDocPrinter(void *, ndr_xa_t *); 113cb174861Sjoyce mcintosh static int spoolss_s_EndDocPrinter(void *, ndr_xa_t *); 114cb174861Sjoyce mcintosh static int spoolss_s_StartPagePrinter(void *, ndr_xa_t *); 115cb174861Sjoyce mcintosh static int spoolss_s_EndPagePrinter(void *, ndr_xa_t *); 116cb174861Sjoyce mcintosh static int spoolss_s_rfnpcnex(void *, ndr_xa_t *); 117cb174861Sjoyce mcintosh static int spoolss_s_WritePrinter(void *, ndr_xa_t *); 118fd9ee8b5Sjoyce mcintosh static int spoolss_s_AddForm(void *, ndr_xa_t *); 119fd9ee8b5Sjoyce mcintosh static int spoolss_s_DeleteForm(void *, ndr_xa_t *); 120cb174861Sjoyce mcintosh static int spoolss_s_EnumForms(void *, ndr_xa_t *); 121fd9ee8b5Sjoyce mcintosh static int spoolss_s_AddMonitor(void *, ndr_xa_t *); 122fd9ee8b5Sjoyce mcintosh static int spoolss_s_DeleteMonitor(void *, ndr_xa_t *); 123fd9ee8b5Sjoyce mcintosh static int spoolss_s_DeletePort(void *, ndr_xa_t *); 124fd9ee8b5Sjoyce mcintosh static int spoolss_s_AddPortEx(void *, ndr_xa_t *); 125fd9ee8b5Sjoyce mcintosh static int spoolss_s_SetPort(void *, ndr_xa_t *); 126cb174861Sjoyce mcintosh static int spoolss_s_stub(void *, ndr_xa_t *); 1278d7e4166Sjose borrego 1288d7e4166Sjose borrego static ndr_stub_table_t spoolss_stub_table[] = { 129cb174861Sjoyce mcintosh { spoolss_s_GetJob, SPOOLSS_OPNUM_GetJob }, 130cb174861Sjoyce mcintosh { spoolss_s_EnumJobs, SPOOLSS_OPNUM_EnumJobs }, 1318d7e4166Sjose borrego { spoolss_s_stub, SPOOLSS_OPNUM_DeletePrinter }, 132cb174861Sjoyce mcintosh { spoolss_s_GetPrinter, SPOOLSS_OPNUM_GetPrinter }, 1338d7e4166Sjose borrego { spoolss_s_stub, SPOOLSS_OPNUM_GetPrinterDriver }, 1348d7e4166Sjose borrego { spoolss_s_stub, SPOOLSS_OPNUM_DeletePrinterDriver }, 135cb174861Sjoyce mcintosh { spoolss_s_OpenPrinter, SPOOLSS_OPNUM_OpenPrinter }, 136cb174861Sjoyce mcintosh { spoolss_s_StartDocPrinter, SPOOLSS_OPNUM_StartDocPrinter }, 137cb174861Sjoyce mcintosh { spoolss_s_WritePrinter, SPOOLSS_OPNUM_WritePrinter }, 138cb174861Sjoyce mcintosh { spoolss_s_EndDocPrinter, SPOOLSS_OPNUM_EndDocPrinter }, 139cb174861Sjoyce mcintosh { spoolss_s_StartPagePrinter, SPOOLSS_OPNUM_StartPagePrinter }, 140cb174861Sjoyce mcintosh { spoolss_s_EndPagePrinter, SPOOLSS_OPNUM_EndPagePrinter }, 141cb174861Sjoyce mcintosh { spoolss_s_AbortPrinter, SPOOLSS_OPNUM_AbortPrinter }, 142cb174861Sjoyce mcintosh { spoolss_s_ResetPrinter, SPOOLSS_OPNUM_ResetPrinter }, 143cb174861Sjoyce mcintosh { spoolss_s_AddJob, SPOOLSS_OPNUM_AddJob }, 144cb174861Sjoyce mcintosh { spoolss_s_ScheduleJob, SPOOLSS_OPNUM_ScheduleJob }, 145cb174861Sjoyce mcintosh { spoolss_s_GetPrinterData, SPOOLSS_OPNUM_GetPrinterData }, 146cb174861Sjoyce mcintosh { spoolss_s_ClosePrinter, SPOOLSS_OPNUM_ClosePrinter }, 147fd9ee8b5Sjoyce mcintosh { spoolss_s_AddForm, SPOOLSS_OPNUM_AddForm }, 148fd9ee8b5Sjoyce mcintosh { spoolss_s_DeleteForm, SPOOLSS_OPNUM_DeleteForm }, 149cb174861Sjoyce mcintosh { spoolss_s_EnumForms, SPOOLSS_OPNUM_EnumForms }, 150fd9ee8b5Sjoyce mcintosh { spoolss_s_AddMonitor, SPOOLSS_OPNUM_AddMonitor }, 151fd9ee8b5Sjoyce mcintosh { spoolss_s_DeleteMonitor, SPOOLSS_OPNUM_DeleteMonitor }, 152fd9ee8b5Sjoyce mcintosh { spoolss_s_DeletePort, SPOOLSS_OPNUM_DeletePort }, 153fd9ee8b5Sjoyce mcintosh { spoolss_s_AddPortEx, SPOOLSS_OPNUM_AddPortEx }, 154fd9ee8b5Sjoyce mcintosh { spoolss_s_SetPort, SPOOLSS_OPNUM_SetPort }, 155cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_GetPrinterDriver2 }, 156cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_FCPN }, 1578d7e4166Sjose borrego { spoolss_s_stub, SPOOLSS_OPNUM_ReplyOpenPrinter }, 1588d7e4166Sjose borrego { spoolss_s_stub, SPOOLSS_OPNUM_ReplyClosePrinter }, 159cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_RFFPCNEX }, 160cb174861Sjoyce mcintosh { spoolss_s_rfnpcnex, SPOOLSS_OPNUM_RFNPCNEX }, 161cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_RRPCN }, 162cb174861Sjoyce mcintosh { spoolss_s_OpenPrinter, SPOOLSS_OPNUM_OpenPrinterEx }, 163cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_EnumPrinterData }, 164cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_EnumPrinterDataEx }, 165cb174861Sjoyce mcintosh { spoolss_s_stub, SPOOLSS_OPNUM_EnumPrinterKey }, 1668d7e4166Sjose borrego {0} 1678d7e4166Sjose borrego }; 1688d7e4166Sjose borrego 1698d7e4166Sjose borrego static ndr_service_t spoolss_service = { 1708d7e4166Sjose borrego "SPOOLSS", /* name */ 1718d7e4166Sjose borrego "Print Spool Service", /* desc */ 1728d7e4166Sjose borrego "\\spoolss", /* endpoint */ 1738d7e4166Sjose borrego PIPE_SPOOLSS, /* sec_addr_port */ 174cb174861Sjoyce mcintosh "12345678-1234-abcd-ef00-0123456789ab", 1, /* abstract */ 1758d7e4166Sjose borrego NDR_TRANSFER_SYNTAX_UUID, 2, /* transfer */ 1768d7e4166Sjose borrego 0, /* no bind_instance_size */ 1778d7e4166Sjose borrego 0, /* no bind_req() */ 1788d7e4166Sjose borrego 0, /* no unbind_and_close() */ 1798d7e4166Sjose borrego 0, /* use generic_call_stub() */ 1808d7e4166Sjose borrego &TYPEINFO(spoolss_interface), /* interface ti */ 1818d7e4166Sjose borrego spoolss_stub_table /* stub_table */ 1828d7e4166Sjose borrego }; 1838d7e4166Sjose borrego 1848d7e4166Sjose borrego void 1858d7e4166Sjose borrego spoolss_initialize(void) 1868d7e4166Sjose borrego { 187fd9ee8b5Sjoyce mcintosh if (!spoolss_splist.sp_initialized) { 188fd9ee8b5Sjoyce mcintosh list_create(&spoolss_splist.sp_list, 189fd9ee8b5Sjoyce mcintosh sizeof (smb_spooldoc_t), 190fd9ee8b5Sjoyce mcintosh offsetof(smb_spooldoc_t, sd_lnd)); 191fd9ee8b5Sjoyce mcintosh spoolss_splist.sp_initialized = 1; 192fd9ee8b5Sjoyce mcintosh } 193fd9ee8b5Sjoyce mcintosh 194fd9ee8b5Sjoyce mcintosh spoolss_copyfile_callback = NULL; 195fd9ee8b5Sjoyce mcintosh 1968d7e4166Sjose borrego (void) ndr_svc_register(&spoolss_service); 1978d7e4166Sjose borrego } 1988d7e4166Sjose borrego 199cb174861Sjoyce mcintosh void 200cb174861Sjoyce mcintosh spoolss_finalize(void) 201cb174861Sjoyce mcintosh { 202fd9ee8b5Sjoyce mcintosh spoolss_copyfile_callback = NULL; 203fd9ee8b5Sjoyce mcintosh } 204fd9ee8b5Sjoyce mcintosh 205fd9ee8b5Sjoyce mcintosh /* 206fd9ee8b5Sjoyce mcintosh * Register a copyfile callback that the spoolss service can use to 207fd9ee8b5Sjoyce mcintosh * copy files to the spool directory. 208fd9ee8b5Sjoyce mcintosh * 209fd9ee8b5Sjoyce mcintosh * Set a null pointer to disable the copying of files to the spool 210fd9ee8b5Sjoyce mcintosh * directory. 211fd9ee8b5Sjoyce mcintosh */ 212fd9ee8b5Sjoyce mcintosh void 213fd9ee8b5Sjoyce mcintosh spoolss_register_copyfile(spoolss_copyfile_t copyfile) 214fd9ee8b5Sjoyce mcintosh { 215fd9ee8b5Sjoyce mcintosh spoolss_copyfile_callback = copyfile; 216fd9ee8b5Sjoyce mcintosh } 217fd9ee8b5Sjoyce mcintosh 218fd9ee8b5Sjoyce mcintosh static void 219fd9ee8b5Sjoyce mcintosh spoolss_copyfile(smb_inaddr_t *ipaddr, char *username, char *path, 220fd9ee8b5Sjoyce mcintosh char *docname) 221fd9ee8b5Sjoyce mcintosh { 222fd9ee8b5Sjoyce mcintosh if (spoolss_copyfile_callback != NULL) 223fd9ee8b5Sjoyce mcintosh (*spoolss_copyfile_callback)(ipaddr, username, path, docname); 224cb174861Sjoyce mcintosh } 225cb174861Sjoyce mcintosh 226cb174861Sjoyce mcintosh static int 2278d7e4166Sjose borrego spoolss_s_OpenPrinter(void *arg, ndr_xa_t *mxa) 2288d7e4166Sjose borrego { 2298d7e4166Sjose borrego struct spoolss_OpenPrinter *param = arg; 230fd9ee8b5Sjoyce mcintosh char *name = (char *)param->printer_name; 231cb174861Sjoyce mcintosh ndr_hdid_t *id; 2328d7e4166Sjose borrego 233fd9ee8b5Sjoyce mcintosh if (name != NULL && *name != '\0') { 234fd9ee8b5Sjoyce mcintosh if (strspn(name, "\\") > 2) { 235fd9ee8b5Sjoyce mcintosh bzero(¶m->handle, sizeof (spoolss_handle_t)); 236fd9ee8b5Sjoyce mcintosh param->status = ERROR_INVALID_PRINTER_NAME; 237fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 238fd9ee8b5Sjoyce mcintosh } 239fd9ee8b5Sjoyce mcintosh 240fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_OpenPrinter: %s", name); 241fd9ee8b5Sjoyce mcintosh } 242fd9ee8b5Sjoyce mcintosh 243fd9ee8b5Sjoyce mcintosh if ((id = ndr_hdalloc(mxa, NULL)) == NULL) { 244cb174861Sjoyce mcintosh bzero(¶m->handle, sizeof (spoolss_handle_t)); 245cb174861Sjoyce mcintosh param->status = ERROR_NOT_ENOUGH_MEMORY; 246cb174861Sjoyce mcintosh return (NDR_DRC_OK); 247cb174861Sjoyce mcintosh } 2488d7e4166Sjose borrego 249cb174861Sjoyce mcintosh bcopy(id, ¶m->handle, sizeof (spoolss_handle_t)); 250cb174861Sjoyce mcintosh param->status = 0; 2518d7e4166Sjose borrego return (NDR_DRC_OK); 2528d7e4166Sjose borrego } 2538d7e4166Sjose borrego 2548d7e4166Sjose borrego /*ARGSUSED*/ 255cb174861Sjoyce mcintosh static int 256cb174861Sjoyce mcintosh spoolss_s_StartPagePrinter(void *arg, ndr_xa_t *mxa) 257cb174861Sjoyce mcintosh { 258cb174861Sjoyce mcintosh struct spoolss_StartPagePrinter *param = arg; 259cb174861Sjoyce mcintosh 260cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 261cb174861Sjoyce mcintosh 262cb174861Sjoyce mcintosh return (NDR_DRC_OK); 263cb174861Sjoyce mcintosh } 264cb174861Sjoyce mcintosh 265cb174861Sjoyce mcintosh /*ARGSUSED*/ 266cb174861Sjoyce mcintosh static int 267cb174861Sjoyce mcintosh spoolss_s_EndPagePrinter(void *arg, ndr_xa_t *mxa) 268cb174861Sjoyce mcintosh { 269cb174861Sjoyce mcintosh struct spoolss_EndPagePrinter *param = arg; 270cb174861Sjoyce mcintosh 271cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 272cb174861Sjoyce mcintosh 273cb174861Sjoyce mcintosh return (NDR_DRC_OK); 274cb174861Sjoyce mcintosh } 275cb174861Sjoyce mcintosh 276cb174861Sjoyce mcintosh /* 277cb174861Sjoyce mcintosh * Windows XP and 2000 use this mechanism to write spool files. 278fd9ee8b5Sjoyce mcintosh * Create a spool file fd to be used by spoolss_s_WritePrinter 279fd9ee8b5Sjoyce mcintosh * and add it to the tail of the spool list. 280cb174861Sjoyce mcintosh */ 281cb174861Sjoyce mcintosh static int 282cb174861Sjoyce mcintosh spoolss_s_StartDocPrinter(void *arg, ndr_xa_t *mxa) 283cb174861Sjoyce mcintosh { 284cb174861Sjoyce mcintosh struct spoolss_StartDocPrinter *param = arg; 285cb174861Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 286cb174861Sjoyce mcintosh smb_spooldoc_t *spfile; 287cb174861Sjoyce mcintosh spoolss_DocInfo_t *docinfo; 288cb174861Sjoyce mcintosh char g_path[MAXPATHLEN]; 289cb174861Sjoyce mcintosh smb_share_t si; 290cb174861Sjoyce mcintosh int rc; 291cb174861Sjoyce mcintosh int fd; 292cb174861Sjoyce mcintosh 293cb174861Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 294fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_StartDocPrinter: invalid handle"); 295cb174861Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 296cb174861Sjoyce mcintosh return (NDR_DRC_OK); 297cb174861Sjoyce mcintosh } 298cb174861Sjoyce mcintosh 299cb174861Sjoyce mcintosh if ((docinfo = param->dinfo.DocInfoContainer) == NULL) { 300cb174861Sjoyce mcintosh param->status = ERROR_INVALID_PARAMETER; 301cb174861Sjoyce mcintosh return (NDR_DRC_OK); 302cb174861Sjoyce mcintosh } 303cb174861Sjoyce mcintosh 304cb174861Sjoyce mcintosh if ((rc = smb_shr_get(SMB_SHARE_PRINT, &si)) != NERR_Success) { 305fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_StartDocPrinter: %s error=%d", 306cb174861Sjoyce mcintosh SMB_SHARE_PRINT, rc); 307cb174861Sjoyce mcintosh param->status = rc; 308cb174861Sjoyce mcintosh return (NDR_DRC_OK); 309cb174861Sjoyce mcintosh } 310cb174861Sjoyce mcintosh 311cb174861Sjoyce mcintosh if ((spfile = calloc(1, sizeof (smb_spooldoc_t))) == NULL) { 312cb174861Sjoyce mcintosh param->status = ERROR_NOT_ENOUGH_MEMORY; 313cb174861Sjoyce mcintosh return (NDR_DRC_OK); 314cb174861Sjoyce mcintosh } 315cb174861Sjoyce mcintosh 316cb174861Sjoyce mcintosh if (docinfo->doc_name != NULL) 317cb174861Sjoyce mcintosh (void) strlcpy(spfile->sd_doc_name, 318cb174861Sjoyce mcintosh (char *)docinfo->doc_name, MAXNAMELEN); 319cb174861Sjoyce mcintosh else 320cb174861Sjoyce mcintosh (void) strlcpy(spfile->sd_doc_name, "document", MAXNAMELEN); 321cb174861Sjoyce mcintosh 322cb174861Sjoyce mcintosh if (docinfo->printer_name != NULL) 323cb174861Sjoyce mcintosh (void) strlcpy(spfile->sd_printer_name, 324cb174861Sjoyce mcintosh (char *)docinfo->printer_name, MAXPATHLEN); 325cb174861Sjoyce mcintosh else 326cb174861Sjoyce mcintosh (void) strlcpy(spfile->sd_printer_name, "printer", MAXPATHLEN); 327cb174861Sjoyce mcintosh 328cb174861Sjoyce mcintosh spfile->sd_ipaddr = mxa->pipe->np_user.ui_ipaddr; 329cb174861Sjoyce mcintosh (void) strlcpy((char *)spfile->sd_username, 330cb174861Sjoyce mcintosh mxa->pipe->np_user.ui_account, MAXNAMELEN); 331fd9ee8b5Sjoyce mcintosh (void) memcpy(&spfile->sd_handle, ¶m->handle, sizeof (ndr_hdid_t)); 332fd9ee8b5Sjoyce mcintosh 333cb174861Sjoyce mcintosh /* 334cb174861Sjoyce mcintosh * write temporary spool file to print$ 335cb174861Sjoyce mcintosh */ 336cb174861Sjoyce mcintosh (void) snprintf(g_path, MAXPATHLEN, "%s/%s%d", si.shr_path, 337cb174861Sjoyce mcintosh spfile->sd_username, spoolss_cnt); 338cb174861Sjoyce mcintosh atomic_inc_32(&spoolss_cnt); 339cb174861Sjoyce mcintosh 340cb174861Sjoyce mcintosh fd = open(g_path, O_CREAT | O_RDWR, 0600); 341cb174861Sjoyce mcintosh if (fd == -1) { 342fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_StartDocPrinter: %s: %s", 343cb174861Sjoyce mcintosh g_path, strerror(errno)); 344cb174861Sjoyce mcintosh param->status = ERROR_OPEN_FAILED; 345cb174861Sjoyce mcintosh free(spfile); 346cb174861Sjoyce mcintosh } else { 347cb174861Sjoyce mcintosh (void) strlcpy((char *)spfile->sd_path, g_path, MAXPATHLEN); 348cb174861Sjoyce mcintosh spfile->sd_fd = (uint16_t)fd; 349fd9ee8b5Sjoyce mcintosh 350fd9ee8b5Sjoyce mcintosh /* 351fd9ee8b5Sjoyce mcintosh * Add the document to the spool list. 352fd9ee8b5Sjoyce mcintosh */ 353fd9ee8b5Sjoyce mcintosh (void) rw_wrlock(&spoolss_splist.sp_rwl); 354fd9ee8b5Sjoyce mcintosh list_insert_tail(&spoolss_splist.sp_list, spfile); 355fd9ee8b5Sjoyce mcintosh spoolss_splist.sp_cnt++; 356fd9ee8b5Sjoyce mcintosh (void) rw_unlock(&spoolss_splist.sp_rwl); 357fd9ee8b5Sjoyce mcintosh 358cb174861Sjoyce mcintosh /* 359cb174861Sjoyce mcintosh * JobId isn't used now, but if printQ management is added 360cb174861Sjoyce mcintosh * this will have to be incremented per job submitted. 361cb174861Sjoyce mcintosh */ 362cb174861Sjoyce mcintosh param->JobId = 46; 363cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 364cb174861Sjoyce mcintosh } 365cb174861Sjoyce mcintosh return (NDR_DRC_OK); 366cb174861Sjoyce mcintosh } 367cb174861Sjoyce mcintosh 368cb174861Sjoyce mcintosh /* 369cb174861Sjoyce mcintosh * Windows XP and 2000 use this mechanism to write spool files 370fd9ee8b5Sjoyce mcintosh * Search the spooldoc list for a matching RPC handle and pass 371fd9ee8b5Sjoyce mcintosh * the spool the file for printing. 372cb174861Sjoyce mcintosh */ 373cb174861Sjoyce mcintosh static int 374cb174861Sjoyce mcintosh spoolss_s_EndDocPrinter(void *arg, ndr_xa_t *mxa) 375cb174861Sjoyce mcintosh { 376cb174861Sjoyce mcintosh struct spoolss_EndDocPrinter *param = arg; 377fd9ee8b5Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 378fd9ee8b5Sjoyce mcintosh smb_spooldoc_t *sp; 379cb174861Sjoyce mcintosh 380fd9ee8b5Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 381fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_EndDocPrinter: invalid handle"); 382fd9ee8b5Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 383fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 384fd9ee8b5Sjoyce mcintosh } 385fd9ee8b5Sjoyce mcintosh 386fd9ee8b5Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 387fd9ee8b5Sjoyce mcintosh (void) rw_wrlock(&spoolss_splist.sp_rwl); 388fd9ee8b5Sjoyce mcintosh 389fd9ee8b5Sjoyce mcintosh sp = list_head(&spoolss_splist.sp_list); 390fd9ee8b5Sjoyce mcintosh while (sp != NULL) { 391fd9ee8b5Sjoyce mcintosh if (!memcmp(id, &(sp->sd_handle), sizeof (ndr_hdid_t))) { 392fd9ee8b5Sjoyce mcintosh spoolss_copyfile(&sp->sd_ipaddr, 393fd9ee8b5Sjoyce mcintosh sp->sd_username, sp->sd_path, sp->sd_doc_name); 394fd9ee8b5Sjoyce mcintosh (void) close(sp->sd_fd); 395fd9ee8b5Sjoyce mcintosh list_remove(&spoolss_splist.sp_list, sp); 396fd9ee8b5Sjoyce mcintosh free(sp); 397cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 398fd9ee8b5Sjoyce mcintosh break; 399fd9ee8b5Sjoyce mcintosh } 400fd9ee8b5Sjoyce mcintosh 401fd9ee8b5Sjoyce mcintosh sp = list_next(&spoolss_splist.sp_list, sp); 402fd9ee8b5Sjoyce mcintosh } 403fd9ee8b5Sjoyce mcintosh 404fd9ee8b5Sjoyce mcintosh (void) rw_unlock(&spoolss_splist.sp_rwl); 405fd9ee8b5Sjoyce mcintosh 406fd9ee8b5Sjoyce mcintosh if (param->status != ERROR_SUCCESS) 407fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_EndDocPrinter: document not found"); 408cb174861Sjoyce mcintosh return (NDR_DRC_OK); 409cb174861Sjoyce mcintosh } 410cb174861Sjoyce mcintosh 411cb174861Sjoyce mcintosh /*ARGSUSED*/ 412cb174861Sjoyce mcintosh static int 413cb174861Sjoyce mcintosh spoolss_s_AbortPrinter(void *arg, ndr_xa_t *mxa) 414cb174861Sjoyce mcintosh { 415cb174861Sjoyce mcintosh struct spoolss_AbortPrinter *param = arg; 416cb174861Sjoyce mcintosh 417cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 418cb174861Sjoyce mcintosh return (NDR_DRC_OK); 419cb174861Sjoyce mcintosh } 420cb174861Sjoyce mcintosh 421cb174861Sjoyce mcintosh /*ARGSUSED*/ 422cb174861Sjoyce mcintosh static int 423cb174861Sjoyce mcintosh spoolss_s_ResetPrinter(void *arg, ndr_xa_t *mxa) 424cb174861Sjoyce mcintosh { 425cb174861Sjoyce mcintosh struct spoolss_AbortPrinter *param = arg; 426cb174861Sjoyce mcintosh 427cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 428cb174861Sjoyce mcintosh return (NDR_DRC_OK); 429cb174861Sjoyce mcintosh } 430cb174861Sjoyce mcintosh 431cb174861Sjoyce mcintosh static int 432cb174861Sjoyce mcintosh spoolss_s_ClosePrinter(void *arg, ndr_xa_t *mxa) 433cb174861Sjoyce mcintosh { 434cb174861Sjoyce mcintosh struct spoolss_ClosePrinter *param = arg; 435cb174861Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 436cb174861Sjoyce mcintosh ndr_handle_t *hd; 437cb174861Sjoyce mcintosh 438cb174861Sjoyce mcintosh if ((hd = ndr_hdlookup(mxa, id)) != NULL) { 439cb174861Sjoyce mcintosh free(hd->nh_data); 440cb174861Sjoyce mcintosh hd->nh_data = NULL; 441cb174861Sjoyce mcintosh } 442cb174861Sjoyce mcintosh 443cb174861Sjoyce mcintosh ndr_hdfree(mxa, id); 444cb174861Sjoyce mcintosh bzero(¶m->result_handle, sizeof (spoolss_handle_t)); 445cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 446cb174861Sjoyce mcintosh return (NDR_DRC_OK); 447cb174861Sjoyce mcintosh } 448cb174861Sjoyce mcintosh 449fd9ee8b5Sjoyce mcintosh static int 450fd9ee8b5Sjoyce mcintosh spoolss_s_AddForm(void *arg, ndr_xa_t *mxa) 451fd9ee8b5Sjoyce mcintosh { 452fd9ee8b5Sjoyce mcintosh struct spoolss_AddForm *param = arg; 453fd9ee8b5Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 454fd9ee8b5Sjoyce mcintosh 455fd9ee8b5Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 456fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_AddForm)); 457fd9ee8b5Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 458fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 459fd9ee8b5Sjoyce mcintosh } 460fd9ee8b5Sjoyce mcintosh 461fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_AddForm)); 462fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 463fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 464fd9ee8b5Sjoyce mcintosh } 465fd9ee8b5Sjoyce mcintosh 466fd9ee8b5Sjoyce mcintosh static int 467fd9ee8b5Sjoyce mcintosh spoolss_s_DeleteForm(void *arg, ndr_xa_t *mxa) 468fd9ee8b5Sjoyce mcintosh { 469fd9ee8b5Sjoyce mcintosh struct spoolss_DeleteForm *param = arg; 470fd9ee8b5Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 471fd9ee8b5Sjoyce mcintosh 472fd9ee8b5Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 473fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_DeleteForm)); 474fd9ee8b5Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 475fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 476fd9ee8b5Sjoyce mcintosh } 477fd9ee8b5Sjoyce mcintosh 478fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_DeleteForm)); 479fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 480fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 481fd9ee8b5Sjoyce mcintosh } 482fd9ee8b5Sjoyce mcintosh 483fd9ee8b5Sjoyce mcintosh static int 484cb174861Sjoyce mcintosh spoolss_s_EnumForms(void *arg, ndr_xa_t *mxa) 485cb174861Sjoyce mcintosh { 486cb174861Sjoyce mcintosh struct spoolss_EnumForms *param = arg; 487fd9ee8b5Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 488cb174861Sjoyce mcintosh 489fd9ee8b5Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 490fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_EnumForms)); 491fd9ee8b5Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 492fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 493fd9ee8b5Sjoyce mcintosh } 494fd9ee8b5Sjoyce mcintosh 495fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_EnumForms)); 496fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 497cb174861Sjoyce mcintosh param->needed = 0; 498cb174861Sjoyce mcintosh return (NDR_DRC_OK); 499cb174861Sjoyce mcintosh } 500cb174861Sjoyce mcintosh 501cb174861Sjoyce mcintosh /*ARGSUSED*/ 502fd9ee8b5Sjoyce mcintosh static int 503fd9ee8b5Sjoyce mcintosh spoolss_s_AddMonitor(void *arg, ndr_xa_t *mxa) 504fd9ee8b5Sjoyce mcintosh { 505fd9ee8b5Sjoyce mcintosh struct spoolss_AddMonitor *param = arg; 506fd9ee8b5Sjoyce mcintosh 507fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 508fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 509fd9ee8b5Sjoyce mcintosh } 510fd9ee8b5Sjoyce mcintosh 511fd9ee8b5Sjoyce mcintosh /*ARGSUSED*/ 512fd9ee8b5Sjoyce mcintosh static int 513fd9ee8b5Sjoyce mcintosh spoolss_s_DeleteMonitor(void *arg, ndr_xa_t *mxa) 514fd9ee8b5Sjoyce mcintosh { 515fd9ee8b5Sjoyce mcintosh struct spoolss_DeleteMonitor *param = arg; 516fd9ee8b5Sjoyce mcintosh 517fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 518fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 519fd9ee8b5Sjoyce mcintosh } 520fd9ee8b5Sjoyce mcintosh 521fd9ee8b5Sjoyce mcintosh /*ARGSUSED*/ 522fd9ee8b5Sjoyce mcintosh static int 523fd9ee8b5Sjoyce mcintosh spoolss_s_DeletePort(void *arg, ndr_xa_t *mxa) 524fd9ee8b5Sjoyce mcintosh { 525fd9ee8b5Sjoyce mcintosh struct spoolss_DeletePort *param = arg; 526fd9ee8b5Sjoyce mcintosh 527fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 528fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 529fd9ee8b5Sjoyce mcintosh } 530fd9ee8b5Sjoyce mcintosh 531fd9ee8b5Sjoyce mcintosh /*ARGSUSED*/ 532fd9ee8b5Sjoyce mcintosh static int 533fd9ee8b5Sjoyce mcintosh spoolss_s_AddPortEx(void *arg, ndr_xa_t *mxa) 534fd9ee8b5Sjoyce mcintosh { 535fd9ee8b5Sjoyce mcintosh struct spoolss_AddPortEx *param = arg; 536fd9ee8b5Sjoyce mcintosh 537fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 538fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 539fd9ee8b5Sjoyce mcintosh } 540fd9ee8b5Sjoyce mcintosh 541fd9ee8b5Sjoyce mcintosh /*ARGSUSED*/ 542fd9ee8b5Sjoyce mcintosh static int 543fd9ee8b5Sjoyce mcintosh spoolss_s_SetPort(void *arg, ndr_xa_t *mxa) 544fd9ee8b5Sjoyce mcintosh { 545fd9ee8b5Sjoyce mcintosh struct spoolss_SetPort *param = arg; 546fd9ee8b5Sjoyce mcintosh 547fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 548fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 549fd9ee8b5Sjoyce mcintosh } 550fd9ee8b5Sjoyce mcintosh 551fd9ee8b5Sjoyce mcintosh /*ARGSUSED*/ 552fd9ee8b5Sjoyce mcintosh static int 553cb174861Sjoyce mcintosh spoolss_s_EnumJobs(void *arg, ndr_xa_t *mxa) 554cb174861Sjoyce mcintosh { 555cb174861Sjoyce mcintosh struct spoolss_EnumJobs *param = arg; 556cb174861Sjoyce mcintosh DWORD status = ERROR_SUCCESS; 557cb174861Sjoyce mcintosh 558cb174861Sjoyce mcintosh switch (param->level) { 559cb174861Sjoyce mcintosh case 1: 560cb174861Sjoyce mcintosh case 2: 561cb174861Sjoyce mcintosh case 3: 562cb174861Sjoyce mcintosh case 4: 563cb174861Sjoyce mcintosh default: 564cb174861Sjoyce mcintosh break; 565cb174861Sjoyce mcintosh } 566cb174861Sjoyce mcintosh 567cb174861Sjoyce mcintosh param->status = status; 568cb174861Sjoyce mcintosh param->needed = 0; 569cb174861Sjoyce mcintosh param->needed2 = 0; 570cb174861Sjoyce mcintosh return (NDR_DRC_OK); 571cb174861Sjoyce mcintosh } 572cb174861Sjoyce mcintosh 573cb174861Sjoyce mcintosh 574cb174861Sjoyce mcintosh /*ARGSUSED*/ 575cb174861Sjoyce mcintosh static int 576cb174861Sjoyce mcintosh spoolss_s_GetJob(void *arg, ndr_xa_t *mxa) 577cb174861Sjoyce mcintosh { 578cb174861Sjoyce mcintosh struct spoolss_GetJob *param = arg; 579cb174861Sjoyce mcintosh DWORD status = ERROR_SUCCESS; 580cb174861Sjoyce mcintosh 581cb174861Sjoyce mcintosh if (param->BufCount == 0) 582cb174861Sjoyce mcintosh param->status = ERROR_INSUFFICIENT_BUFFER; 583cb174861Sjoyce mcintosh else 584cb174861Sjoyce mcintosh param->status = status; 585cb174861Sjoyce mcintosh param->needed = 0; 586cb174861Sjoyce mcintosh return (NDR_DRC_OK); 587cb174861Sjoyce mcintosh } 588cb174861Sjoyce mcintosh 589cb174861Sjoyce mcintosh 590cb174861Sjoyce mcintosh /*ARGSUSED*/ 591cb174861Sjoyce mcintosh static int 592cb174861Sjoyce mcintosh spoolss_s_ScheduleJob(void *arg, ndr_xa_t *mxa) 593cb174861Sjoyce mcintosh { 594cb174861Sjoyce mcintosh struct spoolss_ScheduleJob *param = arg; 595fd9ee8b5Sjoyce mcintosh DWORD status = ERROR_SPL_NO_ADDJOB; 596cb174861Sjoyce mcintosh 597cb174861Sjoyce mcintosh param->status = status; 598cb174861Sjoyce mcintosh return (NDR_DRC_OK); 599cb174861Sjoyce mcintosh } 600cb174861Sjoyce mcintosh 601cb174861Sjoyce mcintosh /*ARGSUSED*/ 602cb174861Sjoyce mcintosh static int 603cb174861Sjoyce mcintosh spoolss_s_AddJob(void *arg, ndr_xa_t *mxa) 604cb174861Sjoyce mcintosh { 605cb174861Sjoyce mcintosh struct spoolss_AddJob *param = arg; 606cb174861Sjoyce mcintosh 607cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 608cb174861Sjoyce mcintosh param->needed = 0; 609cb174861Sjoyce mcintosh return (NDR_DRC_OK); 610cb174861Sjoyce mcintosh } 611cb174861Sjoyce mcintosh 612cb174861Sjoyce mcintosh /*ARGSUSED*/ 613cb174861Sjoyce mcintosh static int 614cb174861Sjoyce mcintosh spoolss_s_rfnpcnex(void *arg, ndr_xa_t *mxa) 615cb174861Sjoyce mcintosh { 616cb174861Sjoyce mcintosh struct spoolss_RFNPCNEX *param = arg; 617cb174861Sjoyce mcintosh 618cb174861Sjoyce mcintosh param->ppinfo = 0; 619cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 620cb174861Sjoyce mcintosh return (NDR_DRC_OK); 621cb174861Sjoyce mcintosh } 622cb174861Sjoyce mcintosh 623cb174861Sjoyce mcintosh /* 624cb174861Sjoyce mcintosh * Use the RPC context handle to find the fd and write the document content. 625cb174861Sjoyce mcintosh */ 626cb174861Sjoyce mcintosh static int 627cb174861Sjoyce mcintosh spoolss_s_WritePrinter(void *arg, ndr_xa_t *mxa) 628cb174861Sjoyce mcintosh { 629cb174861Sjoyce mcintosh struct spoolss_WritePrinter *param = arg; 630cb174861Sjoyce mcintosh int written = 0; 631cb174861Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 632cb174861Sjoyce mcintosh int spfd; 633cb174861Sjoyce mcintosh 634cb174861Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 635cb174861Sjoyce mcintosh param->written = 0; 636cb174861Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 637fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_WritePrinter: invalid handle"); 638cb174861Sjoyce mcintosh return (NDR_DRC_OK); 639cb174861Sjoyce mcintosh } 640cb174861Sjoyce mcintosh 641fd9ee8b5Sjoyce mcintosh if ((spfd = spoolss_find_document(id)) < 0) { 642cb174861Sjoyce mcintosh param->written = 0; 643cb174861Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 644fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_WritePrinter: document not found"); 645cb174861Sjoyce mcintosh return (NDR_DRC_OK); 646cb174861Sjoyce mcintosh } 647cb174861Sjoyce mcintosh 648cb174861Sjoyce mcintosh written = write(spfd, param->pBuf, param->BufCount); 649cb174861Sjoyce mcintosh if (written < param->BufCount) { 650fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_WritePrinter: write failed"); 651cb174861Sjoyce mcintosh param->written = 0; 652cb174861Sjoyce mcintosh param->status = ERROR_CANTWRITE; 653cb174861Sjoyce mcintosh return (NDR_DRC_OK); 654cb174861Sjoyce mcintosh } 655cb174861Sjoyce mcintosh 656cb174861Sjoyce mcintosh param->written = written; 657cb174861Sjoyce mcintosh param->status = ERROR_SUCCESS; 658cb174861Sjoyce mcintosh return (NDR_DRC_OK); 659cb174861Sjoyce mcintosh } 660cb174861Sjoyce mcintosh 661cb174861Sjoyce mcintosh /* 662fd9ee8b5Sjoyce mcintosh * Find a document by RPC handle in the spool list and return the fd. 663cb174861Sjoyce mcintosh */ 664fd9ee8b5Sjoyce mcintosh static int 665fd9ee8b5Sjoyce mcintosh spoolss_find_document(ndr_hdid_t *handle) 666cb174861Sjoyce mcintosh { 667fd9ee8b5Sjoyce mcintosh smb_spooldoc_t *sp; 668cb174861Sjoyce mcintosh 669fd9ee8b5Sjoyce mcintosh (void) rw_rdlock(&spoolss_splist.sp_rwl); 670fd9ee8b5Sjoyce mcintosh 671fd9ee8b5Sjoyce mcintosh sp = list_head(&spoolss_splist.sp_list); 672fd9ee8b5Sjoyce mcintosh while (sp != NULL) { 673fd9ee8b5Sjoyce mcintosh if (!memcmp(handle, &(sp->sd_handle), sizeof (ndr_hdid_t))) { 674fd9ee8b5Sjoyce mcintosh (void) rw_unlock(&spoolss_splist.sp_rwl); 675fd9ee8b5Sjoyce mcintosh return (sp->sd_fd); 676fd9ee8b5Sjoyce mcintosh } 677fd9ee8b5Sjoyce mcintosh sp = list_next(&spoolss_splist.sp_list, sp); 678fd9ee8b5Sjoyce mcintosh } 679fd9ee8b5Sjoyce mcintosh 680fd9ee8b5Sjoyce mcintosh (void) rw_unlock(&spoolss_splist.sp_rwl); 681fd9ee8b5Sjoyce mcintosh return (-1); 682cb174861Sjoyce mcintosh } 683cb174861Sjoyce mcintosh 684cb174861Sjoyce mcintosh /* 685fd9ee8b5Sjoyce mcintosh * GetPrinterData is used t obtain values from the registry for a 686fd9ee8b5Sjoyce mcintosh * printer or a print server. See [MS-RPRN] for value descriptions. 687fd9ee8b5Sjoyce mcintosh * The registry returns ERROR_FILE_NOT_FOUND for unknown keys. 688cb174861Sjoyce mcintosh */ 689cb174861Sjoyce mcintosh static int 690cb174861Sjoyce mcintosh spoolss_s_GetPrinterData(void *arg, ndr_xa_t *mxa) 691cb174861Sjoyce mcintosh { 692fd9ee8b5Sjoyce mcintosh static spoolss_winreg_t reg[] = { 693fd9ee8b5Sjoyce mcintosh { "ChangeId", 0x0050acf2 }, 694fd9ee8b5Sjoyce mcintosh { "W3SvcInstalled", 0x00000000 }, 695fd9ee8b5Sjoyce mcintosh { "BeepEnabled", 0x00000000 }, 696fd9ee8b5Sjoyce mcintosh { "EventLog", 0x0000001f }, 697fd9ee8b5Sjoyce mcintosh { "NetPopup", 0x00000000 }, 698fd9ee8b5Sjoyce mcintosh { "NetPopupToComputer", 0x00000000 }, 699fd9ee8b5Sjoyce mcintosh { "MajorVersion", 0x00000003 }, 700fd9ee8b5Sjoyce mcintosh { "MinorVersion", 0x00000000 }, 701fd9ee8b5Sjoyce mcintosh { "DsPresent", 0x00000000 } 702fd9ee8b5Sjoyce mcintosh }; 703fd9ee8b5Sjoyce mcintosh 704cb174861Sjoyce mcintosh struct spoolss_GetPrinterData *param = arg; 705fd9ee8b5Sjoyce mcintosh char *name = (char *)param->pValueName; 706fd9ee8b5Sjoyce mcintosh char buf[MAXPATHLEN]; 707fd9ee8b5Sjoyce mcintosh static uint8_t reserved_buf[4]; 708fd9ee8b5Sjoyce mcintosh spoolss_winreg_t *rp; 709fd9ee8b5Sjoyce mcintosh smb_share_t si; 710fd9ee8b5Sjoyce mcintosh smb_version_t *osversion; 711fd9ee8b5Sjoyce mcintosh struct utsname sysname; 712fd9ee8b5Sjoyce mcintosh smb_wchar_t *wcs; 713fd9ee8b5Sjoyce mcintosh uint32_t value; 714fd9ee8b5Sjoyce mcintosh uint32_t status; 715fd9ee8b5Sjoyce mcintosh int wcslen; 716fd9ee8b5Sjoyce mcintosh int i; 717cb174861Sjoyce mcintosh 718fd9ee8b5Sjoyce mcintosh if (name == NULL || *name == '\0') { 719fd9ee8b5Sjoyce mcintosh status = ERROR_FILE_NOT_FOUND; 720fd9ee8b5Sjoyce mcintosh goto report_error; 721cb174861Sjoyce mcintosh } 722cb174861Sjoyce mcintosh 723fd9ee8b5Sjoyce mcintosh for (i = 0; i < sizeof (reg) / sizeof (reg[0]); ++i) { 724fd9ee8b5Sjoyce mcintosh param->pType = WINREG_DWORD; 725fd9ee8b5Sjoyce mcintosh param->Needed = sizeof (uint32_t); 726fd9ee8b5Sjoyce mcintosh rp = ®[i]; 727fd9ee8b5Sjoyce mcintosh 728fd9ee8b5Sjoyce mcintosh if (strcasecmp(name, rp->name) != 0) 729fd9ee8b5Sjoyce mcintosh continue; 730fd9ee8b5Sjoyce mcintosh 731fd9ee8b5Sjoyce mcintosh if (param->Size < sizeof (uint32_t)) { 732fd9ee8b5Sjoyce mcintosh param->Size = 0; 733fd9ee8b5Sjoyce mcintosh goto need_more_data; 734cb174861Sjoyce mcintosh } 735fd9ee8b5Sjoyce mcintosh 736fd9ee8b5Sjoyce mcintosh if ((param->Buf = NDR_NEW(mxa, uint32_t)) == NULL) { 737fd9ee8b5Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 738fd9ee8b5Sjoyce mcintosh goto report_error; 739fd9ee8b5Sjoyce mcintosh } 740fd9ee8b5Sjoyce mcintosh 741fd9ee8b5Sjoyce mcintosh value = rp->value; 742fd9ee8b5Sjoyce mcintosh 743fd9ee8b5Sjoyce mcintosh if ((strcasecmp(name, "DsPresent") == 0) && 744fd9ee8b5Sjoyce mcintosh (smb_config_get_secmode() == SMB_SECMODE_DOMAIN)) 745fd9ee8b5Sjoyce mcintosh value = 0x00000001; 746fd9ee8b5Sjoyce mcintosh 747fd9ee8b5Sjoyce mcintosh bcopy(&value, param->Buf, sizeof (uint32_t)); 748fd9ee8b5Sjoyce mcintosh param->Size = sizeof (uint32_t); 749fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 750cb174861Sjoyce mcintosh return (NDR_DRC_OK); 751cb174861Sjoyce mcintosh } 752cb174861Sjoyce mcintosh 753fd9ee8b5Sjoyce mcintosh if (strcasecmp(name, "OSVersion") == 0) { 754fd9ee8b5Sjoyce mcintosh param->pType = WINREG_BINARY; 755fd9ee8b5Sjoyce mcintosh param->Needed = sizeof (smb_version_t); 756cb174861Sjoyce mcintosh 757fd9ee8b5Sjoyce mcintosh if (param->Size < sizeof (smb_version_t)) { 758fd9ee8b5Sjoyce mcintosh param->Size = sizeof (smb_version_t); 759fd9ee8b5Sjoyce mcintosh goto need_more_data; 760cb174861Sjoyce mcintosh } 761cb174861Sjoyce mcintosh 762fd9ee8b5Sjoyce mcintosh if ((osversion = NDR_NEW(mxa, smb_version_t)) == NULL) { 763fd9ee8b5Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 764fd9ee8b5Sjoyce mcintosh goto report_error; 765cb174861Sjoyce mcintosh } 766cb174861Sjoyce mcintosh 767fd9ee8b5Sjoyce mcintosh smb_config_get_version(osversion); 768fd9ee8b5Sjoyce mcintosh param->Buf = (uint8_t *)osversion; 769fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 770fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 771cb174861Sjoyce mcintosh } 772cb174861Sjoyce mcintosh 773fd9ee8b5Sjoyce mcintosh if (strcasecmp(name, "DNSMachineName") == 0) { 774fd9ee8b5Sjoyce mcintosh param->pType = WINREG_SZ; 775fd9ee8b5Sjoyce mcintosh buf[0] = '\0'; 776fd9ee8b5Sjoyce mcintosh (void) smb_getfqhostname(buf, MAXHOSTNAMELEN); 777fd9ee8b5Sjoyce mcintosh goto encode_string; 778cb174861Sjoyce mcintosh } 779cb174861Sjoyce mcintosh 780fd9ee8b5Sjoyce mcintosh if (strcasecmp(name, "DefaultSpoolDirectory") == 0) { 781fd9ee8b5Sjoyce mcintosh param->pType = WINREG_SZ; 782fd9ee8b5Sjoyce mcintosh buf[0] = '\0'; 783fd9ee8b5Sjoyce mcintosh 784fd9ee8b5Sjoyce mcintosh if (smb_shr_get(SMB_SHARE_PRINT, &si) != NERR_Success) { 785fd9ee8b5Sjoyce mcintosh status = ERROR_FILE_NOT_FOUND; 786fd9ee8b5Sjoyce mcintosh goto report_error; 787cb174861Sjoyce mcintosh } 788cb174861Sjoyce mcintosh 789fd9ee8b5Sjoyce mcintosh (void) snprintf(buf, MAXPATHLEN, "C:/%s", si.shr_path); 790fd9ee8b5Sjoyce mcintosh (void) strcanon(buf, "/\\"); 791fd9ee8b5Sjoyce mcintosh (void) strsubst(buf, '/', '\\'); 792fd9ee8b5Sjoyce mcintosh goto encode_string; 793cb174861Sjoyce mcintosh } 794cb174861Sjoyce mcintosh 795fd9ee8b5Sjoyce mcintosh if (strcasecmp(name, "Architecture") == 0) { 796fd9ee8b5Sjoyce mcintosh param->pType = WINREG_SZ; 797fd9ee8b5Sjoyce mcintosh 798fd9ee8b5Sjoyce mcintosh if (uname(&sysname) < 0) 799fd9ee8b5Sjoyce mcintosh (void) strlcpy(buf, "Solaris", MAXPATHLEN); 800fd9ee8b5Sjoyce mcintosh else 801fd9ee8b5Sjoyce mcintosh (void) snprintf(buf, MAXPATHLEN, "%s %s", 802fd9ee8b5Sjoyce mcintosh sysname.sysname, sysname.machine); 803fd9ee8b5Sjoyce mcintosh 804fd9ee8b5Sjoyce mcintosh goto encode_string; 805fd9ee8b5Sjoyce mcintosh } 806fd9ee8b5Sjoyce mcintosh 807fd9ee8b5Sjoyce mcintosh status = ERROR_FILE_NOT_FOUND; 808fd9ee8b5Sjoyce mcintosh 809fd9ee8b5Sjoyce mcintosh report_error: 810fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_GetPrinterData)); 811fd9ee8b5Sjoyce mcintosh param->Buf = reserved_buf; 812fd9ee8b5Sjoyce mcintosh param->status = status; 813fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 814fd9ee8b5Sjoyce mcintosh 815fd9ee8b5Sjoyce mcintosh encode_string: 816fd9ee8b5Sjoyce mcintosh wcslen = smb_wcequiv_strlen(buf) + sizeof (smb_wchar_t); 817fd9ee8b5Sjoyce mcintosh if (param->Size < wcslen) { 818fd9ee8b5Sjoyce mcintosh param->Needed = wcslen; 819fd9ee8b5Sjoyce mcintosh goto need_more_data; 820fd9ee8b5Sjoyce mcintosh } 821fd9ee8b5Sjoyce mcintosh 822fd9ee8b5Sjoyce mcintosh if ((wcs = NDR_MALLOC(mxa, wcslen)) == NULL) { 823fd9ee8b5Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 824fd9ee8b5Sjoyce mcintosh goto report_error; 825fd9ee8b5Sjoyce mcintosh } 826fd9ee8b5Sjoyce mcintosh 827fd9ee8b5Sjoyce mcintosh (void) ndr_mbstowcs(NULL, wcs, buf, wcslen); 828fd9ee8b5Sjoyce mcintosh param->Buf = (uint8_t *)wcs; 829fd9ee8b5Sjoyce mcintosh param->Needed = wcslen; 830fd9ee8b5Sjoyce mcintosh param->status = ERROR_SUCCESS; 831fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 832fd9ee8b5Sjoyce mcintosh 833fd9ee8b5Sjoyce mcintosh need_more_data: 834fd9ee8b5Sjoyce mcintosh param->Size = 0; 835fd9ee8b5Sjoyce mcintosh param->Buf = reserved_buf; 836fd9ee8b5Sjoyce mcintosh param->status = ERROR_MORE_DATA; 837fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 838cb174861Sjoyce mcintosh } 839cb174861Sjoyce mcintosh 840cb174861Sjoyce mcintosh void 841cb174861Sjoyce mcintosh smb_rpc_off(char *dst, char *src, uint32_t *offset, uint32_t *outoffset) 842cb174861Sjoyce mcintosh { 843cb174861Sjoyce mcintosh int nwchars; 844cb174861Sjoyce mcintosh int bytes; 845cb174861Sjoyce mcintosh 846cb174861Sjoyce mcintosh bytes = smb_wcequiv_strlen(src) + 2; 847cb174861Sjoyce mcintosh nwchars = strlen(src) + 1; 848cb174861Sjoyce mcintosh *offset -= bytes; 849cb174861Sjoyce mcintosh *outoffset = *offset; 850cb174861Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 851cb174861Sjoyce mcintosh (void) smb_mbstowcs(((smb_wchar_t *)(dst + *offset)), src, nwchars); 852cb174861Sjoyce mcintosh } 853cb174861Sjoyce mcintosh 854cb174861Sjoyce mcintosh int 855cb174861Sjoyce mcintosh spoolss_s_GetPrinter(void *arg, ndr_xa_t *mxa) 856cb174861Sjoyce mcintosh { 857cb174861Sjoyce mcintosh struct spoolss_GetPrinter *param = arg; 858cb174861Sjoyce mcintosh struct spoolss_GetPrinter0 *pinfo0; 859cb174861Sjoyce mcintosh struct spoolss_GetPrinter1 *pinfo1; 860cb174861Sjoyce mcintosh struct spoolss_GetPrinter2 *pinfo2; 861cb174861Sjoyce mcintosh struct spoolss_DeviceMode *devmode2; 862fd9ee8b5Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 863fd9ee8b5Sjoyce mcintosh spoolss_sd_t secdesc; 864fd9ee8b5Sjoyce mcintosh char server[MAXNAMELEN]; 865fd9ee8b5Sjoyce mcintosh char printer[MAXNAMELEN]; 866cb174861Sjoyce mcintosh DWORD status = ERROR_SUCCESS; 867cb174861Sjoyce mcintosh char *wname; 868cb174861Sjoyce mcintosh uint32_t offset; 869cb174861Sjoyce mcintosh uint8_t *tmpbuf; 870cb174861Sjoyce mcintosh 871fd9ee8b5Sjoyce mcintosh if (ndr_hdlookup(mxa, id) == NULL) { 872fd9ee8b5Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 873cb174861Sjoyce mcintosh goto error_out; 874cb174861Sjoyce mcintosh } 875fd9ee8b5Sjoyce mcintosh 876fd9ee8b5Sjoyce mcintosh if (spoolss_getservername(server, MAXNAMELEN) != 0) { 877fd9ee8b5Sjoyce mcintosh status = ERROR_INTERNAL_ERROR; 878fd9ee8b5Sjoyce mcintosh goto error_out; 879fd9ee8b5Sjoyce mcintosh } 880fd9ee8b5Sjoyce mcintosh 881fd9ee8b5Sjoyce mcintosh (void) snprintf(printer, MAXNAMELEN, "%s\\%s", server, SPOOLSS_PRINTER); 882fd9ee8b5Sjoyce mcintosh 883fd9ee8b5Sjoyce mcintosh switch (param->switch_value) { 884fd9ee8b5Sjoyce mcintosh case 0: 885fd9ee8b5Sjoyce mcintosh case 1: 886fd9ee8b5Sjoyce mcintosh param->needed = 460; 887fd9ee8b5Sjoyce mcintosh break; 888fd9ee8b5Sjoyce mcintosh case 2: 889fd9ee8b5Sjoyce mcintosh param->needed = 712; 890fd9ee8b5Sjoyce mcintosh break; 891fd9ee8b5Sjoyce mcintosh default: 892fd9ee8b5Sjoyce mcintosh status = ERROR_INVALID_LEVEL; 893fd9ee8b5Sjoyce mcintosh goto error_out; 894fd9ee8b5Sjoyce mcintosh } 895fd9ee8b5Sjoyce mcintosh 896fd9ee8b5Sjoyce mcintosh if (param->BufCount < param->needed) { 897fd9ee8b5Sjoyce mcintosh param->BufCount = 0; 898fd9ee8b5Sjoyce mcintosh param->Buf = NULL; 899fd9ee8b5Sjoyce mcintosh param->status = ERROR_INSUFFICIENT_BUFFER; 900fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 901fd9ee8b5Sjoyce mcintosh } 902fd9ee8b5Sjoyce mcintosh 903fd9ee8b5Sjoyce mcintosh if ((param->Buf = NDR_MALLOC(mxa, param->BufCount)) == NULL) { 904fd9ee8b5Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 905fd9ee8b5Sjoyce mcintosh goto error_out; 906fd9ee8b5Sjoyce mcintosh } 907fd9ee8b5Sjoyce mcintosh 908cb174861Sjoyce mcintosh bzero(param->Buf, param->BufCount); 909fd9ee8b5Sjoyce mcintosh wname = (char *)param->Buf; 910fd9ee8b5Sjoyce mcintosh offset = param->needed; 911fd9ee8b5Sjoyce mcintosh 912cb174861Sjoyce mcintosh switch (param->switch_value) { 913cb174861Sjoyce mcintosh case 0: 914cb174861Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 915cb174861Sjoyce mcintosh pinfo0 = (struct spoolss_GetPrinter0 *)param->Buf; 916cb174861Sjoyce mcintosh 917fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, server, &offset, &pinfo0->servername); 918fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo0->printername); 919cb174861Sjoyce mcintosh pinfo0->cjobs = 0; 920cb174861Sjoyce mcintosh pinfo0->total_jobs = 6; 921cb174861Sjoyce mcintosh pinfo0->total_bytes = 1040771; 922cb174861Sjoyce mcintosh pinfo0->time0 = 0; 923cb174861Sjoyce mcintosh pinfo0->time1 = 0; 924cb174861Sjoyce mcintosh pinfo0->time2 = 3; 925cb174861Sjoyce mcintosh pinfo0->time3 = 0; 926cb174861Sjoyce mcintosh pinfo0->global_counter = 2162710; 927cb174861Sjoyce mcintosh pinfo0->total_pages = 21495865; 928cb174861Sjoyce mcintosh pinfo0->version = 10; 929cb174861Sjoyce mcintosh pinfo0->session_counter = 1; 930cb174861Sjoyce mcintosh pinfo0->job_error = 0x6; 931cb174861Sjoyce mcintosh pinfo0->change_id = 0x1; 932cb174861Sjoyce mcintosh pinfo0->status = 0; 933cb174861Sjoyce mcintosh pinfo0->c_setprinter = 0; 934cb174861Sjoyce mcintosh break; 935cb174861Sjoyce mcintosh case 1: 936fd9ee8b5Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 937fd9ee8b5Sjoyce mcintosh pinfo1 = (struct spoolss_GetPrinter1 *)param->Buf; 938fd9ee8b5Sjoyce mcintosh 939cb174861Sjoyce mcintosh pinfo1->flags = PRINTER_ENUM_ICON8; 940fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo1->flags); 941fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo1->description); 942fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo1->comment); 943cb174861Sjoyce mcintosh break; 944cb174861Sjoyce mcintosh case 2: 945fd9ee8b5Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 946fd9ee8b5Sjoyce mcintosh pinfo2 = (struct spoolss_GetPrinter2 *)param->Buf; 947fd9ee8b5Sjoyce mcintosh 948fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, server, &offset, &pinfo2->servername); 949fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, printer, &offset, &pinfo2->printername); 950cb174861Sjoyce mcintosh smb_rpc_off(wname, SPOOLSS_PRINTER, &offset, 951cb174861Sjoyce mcintosh &pinfo2->sharename); 952cb174861Sjoyce mcintosh smb_rpc_off(wname, "CIFS Printer Port", &offset, 953cb174861Sjoyce mcintosh &pinfo2->portname); 954cb174861Sjoyce mcintosh smb_rpc_off(wname, "", &offset, &pinfo2->drivername); 955cb174861Sjoyce mcintosh smb_rpc_off(wname, SPOOLSS_PRINTER, &offset, 956cb174861Sjoyce mcintosh &pinfo2->comment); 957cb174861Sjoyce mcintosh smb_rpc_off(wname, "farside", &offset, &pinfo2->location); 958fd9ee8b5Sjoyce mcintosh 959fd9ee8b5Sjoyce mcintosh offset -= sizeof (struct spoolss_DeviceMode); 960fd9ee8b5Sjoyce mcintosh pinfo2->devmode = offset; 961fd9ee8b5Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 962fd9ee8b5Sjoyce mcintosh devmode2 = (struct spoolss_DeviceMode *)(param->Buf + offset); 963fd9ee8b5Sjoyce mcintosh 964cb174861Sjoyce mcintosh smb_rpc_off(wname, "farside", &offset, &pinfo2->sepfile); 965cb174861Sjoyce mcintosh smb_rpc_off(wname, "winprint", &offset, 966cb174861Sjoyce mcintosh &pinfo2->printprocessor); 967cb174861Sjoyce mcintosh smb_rpc_off(wname, "RAW", &offset, &pinfo2->datatype); 968fd9ee8b5Sjoyce mcintosh smb_rpc_off(wname, "", &offset, &pinfo2->parameters); 969fd9ee8b5Sjoyce mcintosh 970fd9ee8b5Sjoyce mcintosh status = spoolss_make_sd(mxa, &secdesc); 971fd9ee8b5Sjoyce mcintosh if (status == ERROR_SUCCESS) { 972fd9ee8b5Sjoyce mcintosh offset -= secdesc.sd_size; 973fd9ee8b5Sjoyce mcintosh pinfo2->secdesc = offset; 974fd9ee8b5Sjoyce mcintosh tmpbuf = (uint8_t *)(param->Buf + offset); 975fd9ee8b5Sjoyce mcintosh bcopy(secdesc.sd_buf, tmpbuf, secdesc.sd_size); 976fd9ee8b5Sjoyce mcintosh } 977fd9ee8b5Sjoyce mcintosh 978cb174861Sjoyce mcintosh pinfo2->attributes = 0x00001048; 979cb174861Sjoyce mcintosh pinfo2->status = 0x00000000; 980cb174861Sjoyce mcintosh pinfo2->starttime = 0; 981cb174861Sjoyce mcintosh pinfo2->untiltime = 0; 982cb174861Sjoyce mcintosh pinfo2->cjobs = 0; 983cb174861Sjoyce mcintosh pinfo2->averageppm = 0; 984cb174861Sjoyce mcintosh pinfo2->defaultpriority = 0; 985fd9ee8b5Sjoyce mcintosh 986cb174861Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 987fd9ee8b5Sjoyce mcintosh (void) smb_mbstowcs((smb_wchar_t *)devmode2->devicename, 988fd9ee8b5Sjoyce mcintosh printer, 32); 989cb174861Sjoyce mcintosh devmode2->specversion = 0x0401; 990cb174861Sjoyce mcintosh devmode2->driverversion = 1024; 991cb174861Sjoyce mcintosh devmode2->size = 220; 992cb174861Sjoyce mcintosh devmode2->driverextra_length = 0; 993cb174861Sjoyce mcintosh devmode2->fields = 0x00014713; 994cb174861Sjoyce mcintosh devmode2->orientation = 1; 995cb174861Sjoyce mcintosh devmode2->papersize = 1; 996cb174861Sjoyce mcintosh devmode2->paperlength = 0; 997cb174861Sjoyce mcintosh devmode2->paperwidth = 0; 998cb174861Sjoyce mcintosh devmode2->scale = 100; 999cb174861Sjoyce mcintosh devmode2->copies = 1; 1000cb174861Sjoyce mcintosh devmode2->defaultsource = 15; 1001cb174861Sjoyce mcintosh devmode2->printquality = 65532; 1002cb174861Sjoyce mcintosh devmode2->color = 1; 1003cb174861Sjoyce mcintosh devmode2->duplex = 1; 1004cb174861Sjoyce mcintosh devmode2->yresolution = 1; 1005cb174861Sjoyce mcintosh devmode2->ttoption = 1; 1006cb174861Sjoyce mcintosh devmode2->collate = 0; 1007cb174861Sjoyce mcintosh /*LINTED E_BAD_PTR_CAST_ALIGN*/ 1008fd9ee8b5Sjoyce mcintosh (void) smb_mbstowcs((smb_wchar_t *)devmode2->formname, 1009fd9ee8b5Sjoyce mcintosh "Letter", 32); 1010cb174861Sjoyce mcintosh devmode2->logpixels = 0; 1011cb174861Sjoyce mcintosh devmode2->bitsperpel = 0; 1012cb174861Sjoyce mcintosh devmode2->pelswidth = 0; 1013cb174861Sjoyce mcintosh devmode2->pelsheight = 0; 1014cb174861Sjoyce mcintosh devmode2->displayflags = 0; 1015cb174861Sjoyce mcintosh devmode2->displayfrequency = 0; 1016cb174861Sjoyce mcintosh devmode2->icmmethod = 0; 1017cb174861Sjoyce mcintosh devmode2->icmintent = 0; 1018cb174861Sjoyce mcintosh devmode2->mediatype = 0; 1019cb174861Sjoyce mcintosh devmode2->dithertype = 0; 1020cb174861Sjoyce mcintosh devmode2->reserved1 = 0; 1021cb174861Sjoyce mcintosh devmode2->reserved2 = 0; 1022cb174861Sjoyce mcintosh devmode2->panningwidth = 0; 1023cb174861Sjoyce mcintosh devmode2->panningheight = 0; 1024cb174861Sjoyce mcintosh break; 1025cb174861Sjoyce mcintosh 1026cb174861Sjoyce mcintosh default: 1027cb174861Sjoyce mcintosh break; 1028cb174861Sjoyce mcintosh } 1029fd9ee8b5Sjoyce mcintosh 1030fd9ee8b5Sjoyce mcintosh param->status = status; 1031fd9ee8b5Sjoyce mcintosh return (NDR_DRC_OK); 1032fd9ee8b5Sjoyce mcintosh 1033cb174861Sjoyce mcintosh error_out: 1034fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_GetPrinter: error %u", status); 1035fd9ee8b5Sjoyce mcintosh bzero(param, sizeof (struct spoolss_GetPrinter)); 1036cb174861Sjoyce mcintosh param->status = status; 1037cb174861Sjoyce mcintosh return (NDR_DRC_OK); 1038cb174861Sjoyce mcintosh } 1039cb174861Sjoyce mcintosh 1040fd9ee8b5Sjoyce mcintosh static int 1041fd9ee8b5Sjoyce mcintosh spoolss_getservername(char *name, size_t namelen) 1042fd9ee8b5Sjoyce mcintosh { 1043fd9ee8b5Sjoyce mcintosh char hostname[MAXHOSTNAMELEN]; 1044fd9ee8b5Sjoyce mcintosh char ipstr[INET6_ADDRSTRLEN]; 1045fd9ee8b5Sjoyce mcintosh smb_inaddr_t ipaddr; 1046fd9ee8b5Sjoyce mcintosh struct hostent *h; 1047fd9ee8b5Sjoyce mcintosh const char *p; 1048fd9ee8b5Sjoyce mcintosh int error; 1049fd9ee8b5Sjoyce mcintosh 1050fd9ee8b5Sjoyce mcintosh if (smb_gethostname(hostname, MAXHOSTNAMELEN, 0) != 0) { 1051fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_GetPrinter: gethostname failed"); 1052fd9ee8b5Sjoyce mcintosh return (-1); 1053fd9ee8b5Sjoyce mcintosh } 1054fd9ee8b5Sjoyce mcintosh 1055fd9ee8b5Sjoyce mcintosh if ((h = smb_gethostbyname(hostname, &error)) == NULL) { 1056fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_GetPrinter: gethostbyname failed: %d", 1057fd9ee8b5Sjoyce mcintosh error); 1058fd9ee8b5Sjoyce mcintosh return (-1); 1059fd9ee8b5Sjoyce mcintosh } 1060fd9ee8b5Sjoyce mcintosh 1061fd9ee8b5Sjoyce mcintosh bcopy(h->h_addr, &ipaddr, h->h_length); 1062fd9ee8b5Sjoyce mcintosh ipaddr.a_family = h->h_addrtype; 1063fd9ee8b5Sjoyce mcintosh freehostent(h); 1064fd9ee8b5Sjoyce mcintosh 1065fd9ee8b5Sjoyce mcintosh p = smb_inet_ntop(&ipaddr, ipstr, SMB_IPSTRLEN(ipaddr.a_family)); 1066fd9ee8b5Sjoyce mcintosh if (p == NULL) { 1067fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_s_GetPrinter: inet_ntop failed"); 1068fd9ee8b5Sjoyce mcintosh return (-1); 1069fd9ee8b5Sjoyce mcintosh } 1070fd9ee8b5Sjoyce mcintosh 1071fd9ee8b5Sjoyce mcintosh (void) snprintf(name, namelen, "\\\\%s", ipstr); 1072fd9ee8b5Sjoyce mcintosh return (0); 1073fd9ee8b5Sjoyce mcintosh } 1074fd9ee8b5Sjoyce mcintosh 1075fd9ee8b5Sjoyce mcintosh static uint32_t 1076fd9ee8b5Sjoyce mcintosh spoolss_make_sd(ndr_xa_t *mxa, spoolss_sd_t *secdesc) 1077cb174861Sjoyce mcintosh { 1078cb174861Sjoyce mcintosh smb_sd_t sd; 1079fd9ee8b5Sjoyce mcintosh uint8_t *sd_buf; 1080fd9ee8b5Sjoyce mcintosh uint32_t sd_len; 1081cb174861Sjoyce mcintosh uint32_t status; 1082cb174861Sjoyce mcintosh 1083cb174861Sjoyce mcintosh bzero(&sd, sizeof (smb_sd_t)); 1084cb174861Sjoyce mcintosh 1085fd9ee8b5Sjoyce mcintosh if ((status = spoolss_format_sd(&sd)) != ERROR_SUCCESS) 1086fd9ee8b5Sjoyce mcintosh return (status); 1087fd9ee8b5Sjoyce mcintosh 1088fd9ee8b5Sjoyce mcintosh sd_len = smb_sd_len(&sd, SMB_ALL_SECINFO); 1089fd9ee8b5Sjoyce mcintosh 1090fd9ee8b5Sjoyce mcintosh if ((sd_buf = NDR_MALLOC(mxa, sd_len)) == NULL) 1091fd9ee8b5Sjoyce mcintosh return (ERROR_NOT_ENOUGH_MEMORY); 1092fd9ee8b5Sjoyce mcintosh 1093fd9ee8b5Sjoyce mcintosh secdesc->sd_buf = sd_buf; 1094fd9ee8b5Sjoyce mcintosh secdesc->sd_size = sd_len; 1095fd9ee8b5Sjoyce mcintosh 1096cb174861Sjoyce mcintosh status = srvsvc_sd_set_relative(&sd, sd_buf); 1097cb174861Sjoyce mcintosh smb_sd_term(&sd); 1098fd9ee8b5Sjoyce mcintosh return (status); 1099cb174861Sjoyce mcintosh } 1100cb174861Sjoyce mcintosh 1101cb174861Sjoyce mcintosh static uint32_t 1102fd9ee8b5Sjoyce mcintosh spoolss_format_sd(smb_sd_t *sd) 1103cb174861Sjoyce mcintosh { 1104cb174861Sjoyce mcintosh smb_fssd_t fs_sd; 1105cb174861Sjoyce mcintosh acl_t *acl; 1106cb174861Sjoyce mcintosh uint32_t status = ERROR_SUCCESS; 1107cb174861Sjoyce mcintosh 1108cb174861Sjoyce mcintosh if (acl_fromtext("everyone@:full_set::allow", &acl) != 0) { 1109fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_format_sd: NOT_ENOUGH_MEMORY"); 1110cb174861Sjoyce mcintosh return (ERROR_NOT_ENOUGH_MEMORY); 1111cb174861Sjoyce mcintosh } 1112cb174861Sjoyce mcintosh smb_fssd_init(&fs_sd, SMB_ALL_SECINFO, SMB_FSSD_FLAGS_DIR); 1113cb174861Sjoyce mcintosh fs_sd.sd_uid = 0; 1114cb174861Sjoyce mcintosh fs_sd.sd_gid = 0; 1115cb174861Sjoyce mcintosh fs_sd.sd_zdacl = acl; 1116cb174861Sjoyce mcintosh fs_sd.sd_zsacl = NULL; 1117cb174861Sjoyce mcintosh 1118fd9ee8b5Sjoyce mcintosh status = smb_sd_fromfs(&fs_sd, sd); 1119fd9ee8b5Sjoyce mcintosh if (status != NT_STATUS_SUCCESS) { 1120fd9ee8b5Sjoyce mcintosh smb_tracef("spoolss_format_sd: %u", status); 1121cb174861Sjoyce mcintosh status = ERROR_ACCESS_DENIED; 1122cb174861Sjoyce mcintosh } 1123cb174861Sjoyce mcintosh smb_fssd_term(&fs_sd); 1124cb174861Sjoyce mcintosh return (status); 1125cb174861Sjoyce mcintosh } 1126cb174861Sjoyce mcintosh 1127cb174861Sjoyce mcintosh /*ARGSUSED*/ 1128cb174861Sjoyce mcintosh static int 11298d7e4166Sjose borrego spoolss_s_stub(void *arg, ndr_xa_t *mxa) 11308d7e4166Sjose borrego { 11318d7e4166Sjose borrego return (NDR_DRC_FAULT_PARAM_0_UNIMPLEMENTED); 11328d7e4166Sjose borrego } 1133cb174861Sjoyce mcintosh 1134cb174861Sjoyce mcintosh void 1135cb174861Sjoyce mcintosh fixup_spoolss_RFNPCNEX(struct spoolss_RFNPCNEX *val) 1136cb174861Sjoyce mcintosh { 1137cb174861Sjoyce mcintosh unsigned short size1 = 0; 1138cb174861Sjoyce mcintosh unsigned short size2 = 0; 1139cb174861Sjoyce mcintosh unsigned short size3 = 0; 1140cb174861Sjoyce mcintosh struct spoolss_RPC_V2_NOTIFY_INFO *pinfo; 1141cb174861Sjoyce mcintosh 1142cb174861Sjoyce mcintosh pinfo = val->ppinfo->pinfo; 1143cb174861Sjoyce mcintosh switch (pinfo->aData->Reserved) { 1144cb174861Sjoyce mcintosh case TABLE_STRING: 1145cb174861Sjoyce mcintosh size1 = sizeof (struct STRING_CONTAINER); 1146cb174861Sjoyce mcintosh break; 1147cb174861Sjoyce mcintosh case TABLE_DWORD: 1148cb174861Sjoyce mcintosh size1 = sizeof (DWORD) * 2; 1149cb174861Sjoyce mcintosh break; 1150cb174861Sjoyce mcintosh case TABLE_TIME: 1151cb174861Sjoyce mcintosh size1 = sizeof (struct SYSTEMTIME_CONTAINER); 1152cb174861Sjoyce mcintosh break; 1153cb174861Sjoyce mcintosh case TABLE_DEVMODE: 1154cb174861Sjoyce mcintosh size1 = sizeof (struct spoolssDevmodeContainer); 1155cb174861Sjoyce mcintosh break; 1156cb174861Sjoyce mcintosh case TABLE_SECURITY_DESCRIPTOR: 1157cb174861Sjoyce mcintosh size1 = sizeof (struct SECURITY_CONTAINER); 1158cb174861Sjoyce mcintosh break; 1159cb174861Sjoyce mcintosh default: 1160cb174861Sjoyce mcintosh return; 1161cb174861Sjoyce mcintosh } 1162cb174861Sjoyce mcintosh size2 = size1 + (2 * sizeof (DWORD)); 1163cb174861Sjoyce mcintosh size3 = size2 + sizeof (ndr_request_hdr_t) + sizeof (DWORD); 1164cb174861Sjoyce mcintosh 1165cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO_DATA_DATA, size1); 1166cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO_DATA, size2); 1167cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RPC_V2_NOTIFY_INFO, size3); 1168cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_RFNPCNEX, size3); 1169cb174861Sjoyce mcintosh } 1170cb174861Sjoyce mcintosh 1171cb174861Sjoyce mcintosh void 1172cb174861Sjoyce mcintosh fixup_spoolss_GetPrinter(struct spoolss_GetPrinter *val) 1173cb174861Sjoyce mcintosh { 1174cb174861Sjoyce mcintosh unsigned short size1 = 0; 1175cb174861Sjoyce mcintosh unsigned short size2 = 0; 1176cb174861Sjoyce mcintosh unsigned short size3 = 0; 1177cb174861Sjoyce mcintosh 1178cb174861Sjoyce mcintosh switch (val->switch_value) { 1179cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 0); 1180cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 1); 1181cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 2); 1182cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 3); 1183cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 4); 1184cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 5); 1185cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 6); 1186cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 7); 1187cb174861Sjoyce mcintosh CASE_INFO_ENT(spoolss_GetPrinter, 8); 1188cb174861Sjoyce mcintosh 1189cb174861Sjoyce mcintosh default: 1190cb174861Sjoyce mcintosh return; 1191cb174861Sjoyce mcintosh }; 1192cb174861Sjoyce mcintosh 1193cb174861Sjoyce mcintosh size2 = size1 + (2 * sizeof (DWORD)); 1194cb174861Sjoyce mcintosh size3 = size2 + sizeof (ndr_request_hdr_t) + sizeof (DWORD); 1195cb174861Sjoyce mcintosh 1196cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_GetPrinter_result_u, size1); 1197cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_GetPrinter_result, size2); 1198cb174861Sjoyce mcintosh FIXUP_PDU_SIZE(spoolss_GetPrinter, size3); 1199cb174861Sjoyce mcintosh } 1200*86d7016bSGordon Ross 1201*86d7016bSGordon Ross #else /* HAVE_CUPS */ 1202*86d7016bSGordon Ross 1203*86d7016bSGordon Ross /* 1204*86d7016bSGordon Ross * If not HAVE_CUPS, just provide a few "stubs". 1205*86d7016bSGordon Ross */ 1206*86d7016bSGordon Ross 1207*86d7016bSGordon Ross void 1208*86d7016bSGordon Ross spoolss_initialize(void) 1209*86d7016bSGordon Ross { 1210*86d7016bSGordon Ross } 1211*86d7016bSGordon Ross 1212*86d7016bSGordon Ross void 1213*86d7016bSGordon Ross spoolss_finalize(void) 1214*86d7016bSGordon Ross { 1215*86d7016bSGordon Ross } 1216*86d7016bSGordon Ross 1217*86d7016bSGordon Ross /*ARGSUSED*/ 1218*86d7016bSGordon Ross void 1219*86d7016bSGordon Ross spoolss_register_copyfile(spoolss_copyfile_t copyfile) 1220*86d7016bSGordon Ross { 1221*86d7016bSGordon Ross } 1222*86d7016bSGordon Ross 1223*86d7016bSGordon Ross #endif /* HAVE_CUPS */ 1224