1*2264Sjacobs/* 2*2264Sjacobs * CDDL HEADER START 3*2264Sjacobs * 4*2264Sjacobs * The contents of this file are subject to the terms of the 5*2264Sjacobs * Common Development and Distribution License (the "License"). 6*2264Sjacobs * You may not use this file except in compliance with the License. 7*2264Sjacobs * 8*2264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*2264Sjacobs * or http://www.opensolaris.org/os/licensing. 10*2264Sjacobs * See the License for the specific language governing permissions 11*2264Sjacobs * and limitations under the License. 12*2264Sjacobs * 13*2264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 14*2264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*2264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 16*2264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 17*2264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 18*2264Sjacobs * 19*2264Sjacobs * CDDL HEADER END 20*2264Sjacobs */ 21*2264Sjacobs/* 22*2264Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*2264Sjacobs * Use is subject to license terms. 24*2264Sjacobs */ 25*2264Sjacobs 26*2264Sjacobs/* LINTLIBRARY */ 27*2264Sjacobs/* PROTOLIB1 */ 28*2264Sjacobs 29*2264Sjacobs#pragma ident "%Z%%M% %I% %E% SMI" 30*2264Sjacobs 31*2264Sjacobs#include <arpa/inet.h> 32*2264Sjacobs#include <dirent.h> 33*2264Sjacobs#include <dlfcn.h> 34*2264Sjacobs#include <errno.h> 35*2264Sjacobs#include <fcntl.h> 36*2264Sjacobs#include <libintl.h> 37*2264Sjacobs#include <netdb.h> 38*2264Sjacobs#include <netinet/in.h> 39*2264Sjacobs#include <pwd.h> 40*2264Sjacobs#include <rpc/rpc.h> 41*2264Sjacobs#include <rpcsvc/yp_prot.h> 42*2264Sjacobs#include <rpcsvc/ypclnt.h> 43*2264Sjacobs#include <signal.h> 44*2264Sjacobs#include <stdarg.h> 45*2264Sjacobs#include <stdio.h> 46*2264Sjacobs#include <stdlib.h> 47*2264Sjacobs#include <string.h> 48*2264Sjacobs#include <sys/mman.h> 49*2264Sjacobs#include <sys/socket.h> 50*2264Sjacobs#include <sys/stat.h> 51*2264Sjacobs#include <sys/systeminfo.h> 52*2264Sjacobs#include <sys/types.h> 53*2264Sjacobs#include <syslog.h> 54*2264Sjacobs#include <unistd.h> 55*2264Sjacobs 56*2264Sjacobstypedef struct _jobfile jobfile_t; 57*2264Sjacobstypedef struct _job job_t; 58*2264Sjacobs 59*2264Sjacobsstruct _jobfile { 60*2264Sjacobs char *jf_spl_path; /* df file */ 61*2264Sjacobs char *jf_src_path; /* source file */ 62*2264Sjacobs char *jf_name; /* title/name */ 63*2264Sjacobs char *jf_data; /* ptr to mmapped file */ 64*2264Sjacobs long jf_size; /* size of data */ 65*2264Sjacobs char jf_mmapped; /* is this mmapped or malloced */ 66*2264Sjacobs}; 67*2264Sjacobs 68*2264Sjacobsstruct _job { 69*2264Sjacobs int job_id; 70*2264Sjacobs char *job_printer; 71*2264Sjacobs char *job_server; 72*2264Sjacobs char *job_user; 73*2264Sjacobs char *job_host; 74*2264Sjacobs char *job_spool_dir; 75*2264Sjacobs jobfile_t *job_cf; 76*2264Sjacobs char job_df_next; 77*2264Sjacobs jobfile_t **job_df_list; 78*2264Sjacobs}; 79*2264Sjacobs 80*2264Sjacobsint job_store(job_t *job); 81*2264Sjacobsvoid job_free(job_t *job); 82*2264Sjacobsvoid job_destroy(job_t *job); 83*2264Sjacobsjob_t *job_create(char *printer, char *server, char *spool); 84*2264Sjacobsjob_t *job_retrieve(char *xfer_file, char *spool); 85*2264Sjacobsjob_t **job_list_append(job_t **list, char *printer, char *spool); 86*2264Sjacobs#ifndef SUNOS_4 87*2264Sjacobsint vjob_match_attribute(char *attribute, __va_list ap); 88*2264Sjacobsint vjob_cancel(job_t *job, __va_list ap); 89*2264Sjacobs#endif 90*2264Sjacobs 91*2264Sjacobs 92*2264Sjacobsvoid **list_append(void **, void *); 93*2264Sjacobsvoid **list_append_unique(void **, void *, int (*)(void *, void*)); 94*2264Sjacobsvoid **list_concatenate(void **, void **); 95*2264Sjacobsvoid * list_locate(void **, int (*)(void *, void *), void *); 96*2264Sjacobsint list_iterate(void **, int (*)(void *, __va_list), ...); 97*2264Sjacobs 98*2264Sjacobschar * get_user_name(void); 99*2264Sjacobsint check_client_spool(char *printer); 100*2264Sjacobsint get_lock(char *name, int write_pid); 101*2264Sjacobsuid_t get_user_id(void); 102*2264Sjacobschar *strcdup(char *, char); 103*2264Sjacobschar *strndup(char *, int); 104*2264Sjacobschar **strsplit(char *, char *); 105*2264Sjacobsint file_size(char *); 106*2264Sjacobsint copy_file(char *src, char *dst); 107*2264Sjacobsint map_in_file(const char *name, char **buf); 108*2264Sjacobsint write_buffer(char *name, char *buf, int len); 109*2264Sjacobsvoid start_daemon(int do_fork); 110*2264Sjacobsint kill_process(char *file); 111*2264Sjacobsvoid *dynamic_function(const char *, const char *); 112*2264Sjacobs 113*2264Sjacobsint net_open(char *host, int timeout); 114*2264Sjacobsint net_close(int nd); 115*2264Sjacobsint net_read(int nd, char *buf, int len); 116*2264Sjacobsint net_write(int nd, char *buf, int len); 117*2264Sjacobsint net_printf(int nd, char *fmt, ...); 118*2264Sjacobschar *net_gets(char *buf, int size, int nd); 119*2264Sjacobsint net_send_message(int nd, char *fmt, ...); 120*2264Sjacobsint net_response(int nd); 121*2264Sjacobsint net_send_file(int nd, char *name, char *data, int data_len, 122*2264Sjacobs int type); 123*2264Sjacobs 124*2264Sjacobs 125*2264Sjacobsstruct ns_bsd_addr { 126*2264Sjacobs char *server; /* server name */ 127*2264Sjacobs char *printer; /* printer name or NULL */ 128*2264Sjacobs char *extension; /* RFC-1179 conformance */ 129*2264Sjacobs char *pname; /* Local printer name */ 130*2264Sjacobs}; 131*2264Sjacobstypedef struct ns_bsd_addr ns_bsd_addr_t; 132*2264Sjacobs 133*2264Sjacobs/* Key/Value pair structure */ 134*2264Sjacobsstruct ns_kvp { 135*2264Sjacobs char *key; /* key */ 136*2264Sjacobs char *value; /* value string */ 137*2264Sjacobs}; 138*2264Sjacobstypedef struct ns_kvp ns_kvp_t; 139*2264Sjacobs 140*2264Sjacobs/* Printer Object structure */ 141*2264Sjacobsstruct ns_printer { 142*2264Sjacobs char *name; /* primary name of printer */ 143*2264Sjacobs char **aliases; /* aliases for printer */ 144*2264Sjacobs char *source; /* name service derived from */ 145*2264Sjacobs ns_kvp_t **attributes; /* key/value pairs. */ 146*2264Sjacobs}; 147*2264Sjacobstypedef struct ns_printer ns_printer_t; 148*2264Sjacobs 149*2264Sjacobs/* functions to get/put printer objects */ 150*2264Sjacobsns_printer_t *ns_printer_create(char *, char **, char *, ns_kvp_t **); 151*2264Sjacobsns_printer_t *ns_printer_get_name(const char *, const char *); 152*2264Sjacobsns_printer_t **ns_printer_get_list(const char *); 153*2264Sjacobsint ns_printer_put(const ns_printer_t *); 154*2264Sjacobsvoid ns_printer_destroy(ns_printer_t *); 155*2264Sjacobs 156*2264Sjacobs/* functions to manipulate key/value pairs */ 157*2264Sjacobsvoid *ns_get_value(const char *, const ns_printer_t *); 158*2264Sjacobschar *ns_get_value_string(const char *, const ns_printer_t *); 159*2264Sjacobsint ns_set_value(const char *, const void *, ns_printer_t *); 160*2264Sjacobsint ns_set_value_from_string(const char *, const char *, 161*2264Sjacobs ns_printer_t *); 162*2264Sjacobsns_kvp_t *ns_kvp_create(const char *, const char *); 163*2264Sjacobs 164*2264Sjacobs/* for BSD bindings only */ 165*2264Sjacobsns_bsd_addr_t *ns_bsd_addr_get_default(void); 166*2264Sjacobsns_bsd_addr_t *ns_bsd_addr_get_name(char *name); 167*2264Sjacobsns_bsd_addr_t **ns_bsd_addr_get_all(int); 168*2264Sjacobsns_bsd_addr_t **ns_bsd_addr_get_list(int); 169*2264Sjacobs 170*2264Sjacobs/* others */ 171*2264Sjacobsns_printer_t *posix_name(const char *); 172*2264Sjacobsint ns_printer_match_name(ns_printer_t *, const char *); 173*2264Sjacobschar *ns_printer_name_list(const ns_printer_t *); 174*2264Sjacobschar *value_to_string(const char *, void *); 175*2264Sjacobsvoid *string_to_value(const char *, char *); 176*2264Sjacobs 177*2264Sjacobs 178*2264Sjacobsns_printer_t *_cvt_pconf_entry_to_printer(char *, char *); 179*2264Sjacobschar *_cvt_printer_to_pconf_entry(ns_printer_t *); 180*2264Sjacobs 181*2264Sjacobsns_printer_t *_cvt_user_string_to_printer(char *, char *); 182*2264Sjacobschar *_cvt_printer_to_user_string(ns_printer_t *); 183*2264Sjacobs 184*2264Sjacobs 185*2264Sjacobsns_printer_t *_file_get_name(const char *, const char *, 186*2264Sjacobs ns_printer_t *(*)(char *, char *), char *); 187*2264Sjacobs 188*2264Sjacobsns_printer_t **_file_get_list(const char *, 189*2264Sjacobs ns_printer_t *(*)(char *, char *), char *); 190*2264Sjacobs 191*2264Sjacobsint _file_put_printer(const char *, const ns_printer_t *, 192*2264Sjacobs ns_printer_t *(*)(char *, char *), char *, char *(*)(ns_printer_t *)); 193*2264Sjacobs 194*2264Sjacobs 195*2264Sjacobsns_printer_t *_nis_get_name(const char *, const char *, 196*2264Sjacobs ns_printer_t *(*)(char *, char *), char *); 197*2264Sjacobs 198*2264Sjacobsns_printer_t **_nis_get_list(const char *, 199*2264Sjacobs ns_printer_t *(*)(char *, char *), char *); 200*2264Sjacobs 201*2264Sjacobsint _nis_put_printer(const char *, const ns_printer_t *, 202*2264Sjacobs ns_printer_t *(*)(char *, char *), char *, char *(*)(ns_printer_t *)); 203