xref: /titanic_41/usr/src/cmd/lp/cmd/lpadmin/do_printer.c (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #include <errno.h>
357c478bd9Sstevel@tonic-gate #include <limits.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*45916cd2Sjpk #include <sys/zone.h>
387c478bd9Sstevel@tonic-gate #include <stdlib.h>
397c478bd9Sstevel@tonic-gate #include <libintl.h>
40*45916cd2Sjpk #include <sys/tsol/label_macro.h>
41*45916cd2Sjpk #include <bsm/devices.h>
427c478bd9Sstevel@tonic-gate #include "lp.h"
437c478bd9Sstevel@tonic-gate #include "class.h"
44*45916cd2Sjpk #if defined PS_FAULTED
45*45916cd2Sjpk #undef	PS_FAULTED
46*45916cd2Sjpk #endif
477c478bd9Sstevel@tonic-gate #include "printers.h"
487c478bd9Sstevel@tonic-gate #include "msgs.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	WHO_AM_I	I_AM_LPADMIN
517c478bd9Sstevel@tonic-gate #include	"oam.h"
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #include "lpadmin.h"
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern	void	fromallclasses();
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #if     !defined(PATH_MAX)
587c478bd9Sstevel@tonic-gate # define PATH_MAX       1024
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate #if     PATH_MAX < 1024
617c478bd9Sstevel@tonic-gate # undef PATH_MAX
627c478bd9Sstevel@tonic-gate # define PATH_MAX       1024
637c478bd9Sstevel@tonic-gate #endif
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate extern char		*label;
66*45916cd2Sjpk 
677c478bd9Sstevel@tonic-gate static void		configure_printer();
687c478bd9Sstevel@tonic-gate static char		*fullpath();
697c478bd9Sstevel@tonic-gate char			*nameit();
70*45916cd2Sjpk static void		pack_white(char *ptr);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /**
737c478bd9Sstevel@tonic-gate  ** do_printer() - CREATE OR CHANGE PRINTER
747c478bd9Sstevel@tonic-gate  **/
757c478bd9Sstevel@tonic-gate 
do_printer()767c478bd9Sstevel@tonic-gate void			do_printer ()
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate 	int			rc;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/*
817c478bd9Sstevel@tonic-gate 	 * Set or change the printer configuration.
827c478bd9Sstevel@tonic-gate 	 */
837c478bd9Sstevel@tonic-gate 	if (strlen(modifications))
847c478bd9Sstevel@tonic-gate 		configure_printer (modifications);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	/*
877c478bd9Sstevel@tonic-gate 	 * Allow/deny forms.
887c478bd9Sstevel@tonic-gate 	 */
897c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
907c478bd9Sstevel@tonic-gate 		if (!oldp)
917c478bd9Sstevel@tonic-gate 			if (allow_form_printer(getlist(NAME_NONE, "", ","), p) == -1) {
927c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
937c478bd9Sstevel@tonic-gate 				done(1);
947c478bd9Sstevel@tonic-gate 			}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 		if (f_allow || f_deny) {
977c478bd9Sstevel@tonic-gate 			if (f_allow && allow_form_printer(f_allow, p) == -1) {
987c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
997c478bd9Sstevel@tonic-gate 				done(1);
1007c478bd9Sstevel@tonic-gate 			}
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 			if (f_deny && deny_form_printer(f_deny, p) == -1) {
1037c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1047c478bd9Sstevel@tonic-gate 				done(1);
1057c478bd9Sstevel@tonic-gate 			}
1067c478bd9Sstevel@tonic-gate 		}
1077c478bd9Sstevel@tonic-gate 	END_CRITICAL
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	/* Add/remove types of paper */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
1127c478bd9Sstevel@tonic-gate 		if (!oldp)
1137c478bd9Sstevel@tonic-gate 			if (add_paper_to_printer(getlist(NAME_NONE, "", ","),p) == -1) {
1147c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1157c478bd9Sstevel@tonic-gate 				done(1);
1167c478bd9Sstevel@tonic-gate 			}
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 			if (p_add && add_paper_to_printer(p_add, p) == -1) {
1207c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1217c478bd9Sstevel@tonic-gate 				done(1);
1227c478bd9Sstevel@tonic-gate 			}
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 			if (p_remove && remove_paper_from_printer(p_remove, p) == -1) {
1257c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1267c478bd9Sstevel@tonic-gate 				done(1);
1277c478bd9Sstevel@tonic-gate 			}
1287c478bd9Sstevel@tonic-gate 	END_CRITICAL
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * Allow/deny users.
1327c478bd9Sstevel@tonic-gate 	 */
1337c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
1347c478bd9Sstevel@tonic-gate 		if (!oldp)
1357c478bd9Sstevel@tonic-gate 			if (allow_user_printer(getlist(NAME_ALL, "", ","), p) == -1) {
1367c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1377c478bd9Sstevel@tonic-gate 				done(1);
1387c478bd9Sstevel@tonic-gate 			}
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 		if (u_allow || u_deny) {
1417c478bd9Sstevel@tonic-gate 			if (u_allow && allow_user_printer(u_allow, p) == -1) {
1427c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1437c478bd9Sstevel@tonic-gate 				done(1);
1447c478bd9Sstevel@tonic-gate 			}
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 			if (u_deny && deny_user_printer(u_deny, p) == -1) {
1477c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_ACCESSINFO, PERROR);
1487c478bd9Sstevel@tonic-gate 				done(1);
1497c478bd9Sstevel@tonic-gate 			}
1507c478bd9Sstevel@tonic-gate 		}
1517c478bd9Sstevel@tonic-gate 	END_CRITICAL
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	/*
1547c478bd9Sstevel@tonic-gate 	 * Tell the Spooler about the printer
1557c478bd9Sstevel@tonic-gate 	 */
1567c478bd9Sstevel@tonic-gate 	send_message(S_LOAD_PRINTER, p, "", "");
1577c478bd9Sstevel@tonic-gate 	rc = output(R_LOAD_PRINTER);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	switch (rc) {
1607c478bd9Sstevel@tonic-gate 	case MOK:
1617c478bd9Sstevel@tonic-gate 		break;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	case MNODEST:
1647c478bd9Sstevel@tonic-gate 	case MERRDEST:
1657c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_ERRDEST);
1667c478bd9Sstevel@tonic-gate 		done (1);
1677c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	case MNOSPACE:
1707c478bd9Sstevel@tonic-gate 		LP_ERRMSG (WARNING, E_ADM_NOPSPACE);
1717c478bd9Sstevel@tonic-gate 		break;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	case MNOPERM:	/* taken care of up front */
1747c478bd9Sstevel@tonic-gate 	default:
1757c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
1767c478bd9Sstevel@tonic-gate 		done (1);
1777c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	/*
1817c478bd9Sstevel@tonic-gate 	 * Now that the Spooler knows about the printer,
1827c478bd9Sstevel@tonic-gate 	 * we can do the balance of the changes.
1837c478bd9Sstevel@tonic-gate 	 */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	/*
1867c478bd9Sstevel@tonic-gate 	 * Mount or unmount form, print-wheel.
1877c478bd9Sstevel@tonic-gate 	 */
1887c478bd9Sstevel@tonic-gate 	if (M)
1897c478bd9Sstevel@tonic-gate 		do_mount(p, (f? f : (char *)0), (S? *S : (char *)0));
1907c478bd9Sstevel@tonic-gate 	else if (t) do_max_trays(p);
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	/*
1937c478bd9Sstevel@tonic-gate 	 * Display the alert type.
1947c478bd9Sstevel@tonic-gate 	 */
1957c478bd9Sstevel@tonic-gate 	if (A && STREQU(A, NAME_LIST)) {
1967c478bd9Sstevel@tonic-gate 		if (label)
1977c478bd9Sstevel@tonic-gate 			(void) printf(gettext("Printer %s: "), label);
1987c478bd9Sstevel@tonic-gate 		printalert (stdout, &(oldp->fault_alert), 1);
1997c478bd9Sstevel@tonic-gate 	}
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * -A quiet.
2037c478bd9Sstevel@tonic-gate 	 */
2047c478bd9Sstevel@tonic-gate 	if (A && STREQU(A, NAME_QUIET)) {
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 		send_message(S_QUIET_ALERT, p, (char *)QA_PRINTER, "");
2077c478bd9Sstevel@tonic-gate 		rc = output(R_QUIET_ALERT);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 		switch(rc) {
2107c478bd9Sstevel@tonic-gate 		case MOK:
2117c478bd9Sstevel@tonic-gate 			break;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 		case MNODEST:	/* not quite, but not a lie either */
2147c478bd9Sstevel@tonic-gate 		case MERRDEST:
2157c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (WARNING, E_LP_NOQUIET, p);
2167c478bd9Sstevel@tonic-gate 			break;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 		case MNOPERM:	/* taken care of up front */
2197c478bd9Sstevel@tonic-gate 		default:
2207c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
2217c478bd9Sstevel@tonic-gate 			done (1);
2227c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
2237c478bd9Sstevel@tonic-gate 		}
2247c478bd9Sstevel@tonic-gate 	}
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	/*
2277c478bd9Sstevel@tonic-gate 	 * Add printer p to class c
2287c478bd9Sstevel@tonic-gate 	 */
2297c478bd9Sstevel@tonic-gate 	if (c)  {
2307c478bd9Sstevel@tonic-gate 		CLASS			*pc,
2317c478bd9Sstevel@tonic-gate 					clsbuf;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 		if (STREQU(c, NAME_ANY))
2347c478bd9Sstevel@tonic-gate 			c = NAME_ALL;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate Loop:		if (!(pc = getclass(c))) {
2377c478bd9Sstevel@tonic-gate 			if (STREQU(c, NAME_ALL))
2387c478bd9Sstevel@tonic-gate 				goto Done;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 			if (errno != ENOENT) {
2417c478bd9Sstevel@tonic-gate 				LP_ERRMSG2 (
2427c478bd9Sstevel@tonic-gate 					ERROR,
2437c478bd9Sstevel@tonic-gate 					E_LP_GETCLASS,
2447c478bd9Sstevel@tonic-gate 					c,
2457c478bd9Sstevel@tonic-gate 					PERROR
2467c478bd9Sstevel@tonic-gate 				);
2477c478bd9Sstevel@tonic-gate 				done (1);
2487c478bd9Sstevel@tonic-gate 			}
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 			/*
2517c478bd9Sstevel@tonic-gate 			 * Create the class
2527c478bd9Sstevel@tonic-gate 			 */
2537c478bd9Sstevel@tonic-gate 			clsbuf.name = strdup(c);
2547c478bd9Sstevel@tonic-gate 			clsbuf.members = 0;
2557c478bd9Sstevel@tonic-gate 			if (addlist(&clsbuf.members, p) == -1) {
2567c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_LP_MALLOC);
2577c478bd9Sstevel@tonic-gate 				done (1);
2587c478bd9Sstevel@tonic-gate 			}
2597c478bd9Sstevel@tonic-gate 			pc = &clsbuf;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 		} else if (searchlist(p, pc->members))
2627c478bd9Sstevel@tonic-gate 			LP_ERRMSG2 (WARNING, E_ADM_INCLASS, p, pc->name);
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 		else if (addlist(&pc->members, p) == -1) {
2657c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MALLOC);
2667c478bd9Sstevel@tonic-gate 			done (1);
2677c478bd9Sstevel@tonic-gate 		}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		BEGIN_CRITICAL
2707c478bd9Sstevel@tonic-gate 			if (putclass(pc->name, pc) == -1) {
2717c478bd9Sstevel@tonic-gate 				LP_ERRMSG2 (
2727c478bd9Sstevel@tonic-gate 					ERROR,
2737c478bd9Sstevel@tonic-gate 					E_LP_PUTCLASS,
2747c478bd9Sstevel@tonic-gate 					pc->name,
2757c478bd9Sstevel@tonic-gate 					PERROR
2767c478bd9Sstevel@tonic-gate 				);
2777c478bd9Sstevel@tonic-gate 				done(1);
2787c478bd9Sstevel@tonic-gate 			}
2797c478bd9Sstevel@tonic-gate 		END_CRITICAL
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 		send_message (S_LOAD_CLASS, pc->name);
2827c478bd9Sstevel@tonic-gate 		rc = output(R_LOAD_CLASS);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		switch(rc) {
2857c478bd9Sstevel@tonic-gate 		case MOK:
2867c478bd9Sstevel@tonic-gate 			break;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		case MNODEST:
2897c478bd9Sstevel@tonic-gate 		case MERRDEST:
2907c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_ERRDEST);
2917c478bd9Sstevel@tonic-gate 			done (1);
2927c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 		case MNOSPACE:
2957c478bd9Sstevel@tonic-gate 			LP_ERRMSG (WARNING, E_ADM_NOCSPACE);
2967c478bd9Sstevel@tonic-gate 			break;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 		case MNOPERM:	/* taken care of up front */
2997c478bd9Sstevel@tonic-gate 		default:
3007c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
3017c478bd9Sstevel@tonic-gate 			done (1);
3027c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 		if (STREQU(c, NAME_ALL))
3067c478bd9Sstevel@tonic-gate 			goto Loop;
3077c478bd9Sstevel@tonic-gate 	}
3087c478bd9Sstevel@tonic-gate Done:
3097c478bd9Sstevel@tonic-gate 	/*
3107c478bd9Sstevel@tonic-gate 	 * Remove printer p from class r
3117c478bd9Sstevel@tonic-gate 	 */
3127c478bd9Sstevel@tonic-gate 	if (r) {
3137c478bd9Sstevel@tonic-gate 		if (STREQU(r, NAME_ALL) || STREQU(r, NAME_ANY))
3147c478bd9Sstevel@tonic-gate 			fromallclasses(p);
3157c478bd9Sstevel@tonic-gate 		else
3167c478bd9Sstevel@tonic-gate 			fromclass(p, r);
3177c478bd9Sstevel@tonic-gate 	}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	return;
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /**
3237c478bd9Sstevel@tonic-gate  ** configure_printer() - SET OR CHANGE CONFIGURATION OF PRINTER
3247c478bd9Sstevel@tonic-gate  **/
3257c478bd9Sstevel@tonic-gate 
configure_printer(list)3267c478bd9Sstevel@tonic-gate static void		configure_printer (list)
3277c478bd9Sstevel@tonic-gate 	char			*list;
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	register PRINTER	*prbufp;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	PRINTER			printer_struct;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	char			type;
3347c478bd9Sstevel@tonic-gate 	char *	infile_opts = NULL;
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	if (oldp) {
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 		prbufp = oldp;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 		if (!T)
3427c478bd9Sstevel@tonic-gate 			T = prbufp->printer_types;
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 		if (!i && !e && !m)
3457c478bd9Sstevel@tonic-gate 			/*
3467c478bd9Sstevel@tonic-gate 			 * Don't copy the original interface program
3477c478bd9Sstevel@tonic-gate 			 * again, but do keep the name of the original.
3487c478bd9Sstevel@tonic-gate 			 */
3497c478bd9Sstevel@tonic-gate 			ignprinter = BAD_INTERFACE;
3507c478bd9Sstevel@tonic-gate 		else
3517c478bd9Sstevel@tonic-gate 			ignprinter = 0;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 		/*
3547c478bd9Sstevel@tonic-gate 		 * If we are making this a remote printer,
3557c478bd9Sstevel@tonic-gate 		 * make sure that local-only attributes are
3567c478bd9Sstevel@tonic-gate 		 * cleared.
3577c478bd9Sstevel@tonic-gate 		 */
3587c478bd9Sstevel@tonic-gate 		if (s) {
3597c478bd9Sstevel@tonic-gate 			prbufp->banner = 0;
3607c478bd9Sstevel@tonic-gate 			prbufp->cpi.val = 0;
3617c478bd9Sstevel@tonic-gate 			prbufp->cpi.sc = 0;
3627c478bd9Sstevel@tonic-gate 			prbufp->device = 0;
3637c478bd9Sstevel@tonic-gate 			prbufp->dial_info = 0;
3647c478bd9Sstevel@tonic-gate 			prbufp->fault_rec = 0;
3657c478bd9Sstevel@tonic-gate 			prbufp->interface = 0;
3667c478bd9Sstevel@tonic-gate 			prbufp->lpi.val = 0;
3677c478bd9Sstevel@tonic-gate 			prbufp->lpi.sc = 0;
3687c478bd9Sstevel@tonic-gate 			prbufp->plen.val = 0;
3697c478bd9Sstevel@tonic-gate 			prbufp->plen.sc = 0;
3707c478bd9Sstevel@tonic-gate 			prbufp->login = 0;
3717c478bd9Sstevel@tonic-gate 			prbufp->speed = 0;
3727c478bd9Sstevel@tonic-gate 			prbufp->stty = 0;
3737c478bd9Sstevel@tonic-gate 			prbufp->pwid.val = 0;
3747c478bd9Sstevel@tonic-gate 			prbufp->pwid.sc = 0;
3757c478bd9Sstevel@tonic-gate 			prbufp->fault_alert.shcmd = strdup(NAME_NONE);
3767c478bd9Sstevel@tonic-gate 			prbufp->fault_alert.Q = 0;
3777c478bd9Sstevel@tonic-gate 			prbufp->fault_alert.W = 0;
3787c478bd9Sstevel@tonic-gate #if	defined(CAN_DO_MODULES)
3797c478bd9Sstevel@tonic-gate 			prbufp->modules = 0;
3807c478bd9Sstevel@tonic-gate #endif
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 		/*
3837c478bd9Sstevel@tonic-gate 		 * If we are making this a local printer, make
3847c478bd9Sstevel@tonic-gate 		 * sure that some local-only attributes are set.
3857c478bd9Sstevel@tonic-gate 		 * (If the user has specified these as well, his/her
3867c478bd9Sstevel@tonic-gate 		 * values will overwrite what we set here.)
3877c478bd9Sstevel@tonic-gate 		 */
3887c478bd9Sstevel@tonic-gate 		} else if (oldp->remote) {
3897c478bd9Sstevel@tonic-gate 			prbufp->banner = BAN_ALWAYS;
3907c478bd9Sstevel@tonic-gate 			prbufp->interface = makepath(Lp_Model, STANDARD, (char *)0);
3917c478bd9Sstevel@tonic-gate 			prbufp->fault_alert.shcmd = nameit(NAME_MAIL);
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 			/*
3947c478bd9Sstevel@tonic-gate 			 * Being here means "!s && oldp->remote" is true,
3957c478bd9Sstevel@tonic-gate 			 * i.e. this printer never had an interface pgm
3967c478bd9Sstevel@tonic-gate 			 * before. Thus we can safely clear the following.
3977c478bd9Sstevel@tonic-gate 			 * This is needed to let "putprinter()" copy the
3987c478bd9Sstevel@tonic-gate 			 * (default) interface program.
3997c478bd9Sstevel@tonic-gate 			 */
4007c478bd9Sstevel@tonic-gate 			ignprinter = 0;
4017c478bd9Sstevel@tonic-gate 		}
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 	} else {
4047c478bd9Sstevel@tonic-gate 		/*
4057c478bd9Sstevel@tonic-gate 		 * The following takes care of the lion's share
4067c478bd9Sstevel@tonic-gate 		 * of the initialization of a new printer structure.
4077c478bd9Sstevel@tonic-gate 		 * However, special initialization (e.g. non-zero,
4087c478bd9Sstevel@tonic-gate 		 * or substructure members) needs to be considered
4097c478bd9Sstevel@tonic-gate 		 * for EACH NEW MEMBER added to the structure.
4107c478bd9Sstevel@tonic-gate 		 */
4117c478bd9Sstevel@tonic-gate 		(void)memset (&printer_struct, 0, sizeof(printer_struct));
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 		prbufp = &printer_struct;
4147c478bd9Sstevel@tonic-gate 		prbufp->banner = BAN_ALWAYS;
4157c478bd9Sstevel@tonic-gate 		prbufp->cpi.val = 0;
4167c478bd9Sstevel@tonic-gate 		prbufp->cpi.sc = 0;
4177c478bd9Sstevel@tonic-gate 		if (!s)
4187c478bd9Sstevel@tonic-gate 			prbufp->interface = makepath(Lp_Model, m, (char *)0);
4197c478bd9Sstevel@tonic-gate 		prbufp->lpi.val = 0;
4207c478bd9Sstevel@tonic-gate 		prbufp->lpi.sc = 0;
4217c478bd9Sstevel@tonic-gate 		prbufp->plen.val = 0;
4227c478bd9Sstevel@tonic-gate 		prbufp->plen.sc = 0;
4237c478bd9Sstevel@tonic-gate 		prbufp->pwid.val = 0;
4247c478bd9Sstevel@tonic-gate 		prbufp->pwid.sc = 0;
4257c478bd9Sstevel@tonic-gate 		if (!s && !A)
4267c478bd9Sstevel@tonic-gate 			prbufp->fault_alert.shcmd = nameit(NAME_MAIL);
4277c478bd9Sstevel@tonic-gate 		prbufp->fault_alert.Q = 0;
4287c478bd9Sstevel@tonic-gate 		prbufp->fault_alert.W = 0;
4297c478bd9Sstevel@tonic-gate 		prbufp->options = NULL;
4307c478bd9Sstevel@tonic-gate 	}
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 	while ((type = *list++) != '\0')  switch(type) {
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	case 'A':
4357c478bd9Sstevel@tonic-gate 		if (!s) {
4367c478bd9Sstevel@tonic-gate 			if (STREQU(A, NAME_MAIL) || STREQU(A, NAME_WRITE))
4377c478bd9Sstevel@tonic-gate 				prbufp->fault_alert.shcmd = nameit(A);
4387c478bd9Sstevel@tonic-gate 			else if (!STREQU(A, NAME_QUIET))
4397c478bd9Sstevel@tonic-gate 				prbufp->fault_alert.shcmd = A;
4407c478bd9Sstevel@tonic-gate 		}
4417c478bd9Sstevel@tonic-gate 		break;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	case 'b':
4447c478bd9Sstevel@tonic-gate 		if (!s)
4457c478bd9Sstevel@tonic-gate 			prbufp->banner = banner;
4467c478bd9Sstevel@tonic-gate 		break;
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	case 'c':
4497c478bd9Sstevel@tonic-gate 		if (!s)
4507c478bd9Sstevel@tonic-gate 			prbufp->cpi = cpi_sdn;
4517c478bd9Sstevel@tonic-gate 		break;
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	case 'D':
4547c478bd9Sstevel@tonic-gate 		prbufp->description = D;
4557c478bd9Sstevel@tonic-gate 		break;
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	case 'e':
4587c478bd9Sstevel@tonic-gate 		if (!s) {
4597c478bd9Sstevel@tonic-gate 			prbufp->interface = makepath(
4607c478bd9Sstevel@tonic-gate 				Lp_A_Interfaces,
4617c478bd9Sstevel@tonic-gate 				e,
4627c478bd9Sstevel@tonic-gate 				(char *)0
4637c478bd9Sstevel@tonic-gate 			);
4647c478bd9Sstevel@tonic-gate 		}
4657c478bd9Sstevel@tonic-gate 		break;
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	case 'F':
4687c478bd9Sstevel@tonic-gate 		if (!s)
4697c478bd9Sstevel@tonic-gate 			prbufp->fault_rec = F;
4707c478bd9Sstevel@tonic-gate 		break;
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate #if	defined(CAN_DO_MODULES)
4737c478bd9Sstevel@tonic-gate 	case 'H':
4747c478bd9Sstevel@tonic-gate 		if (!s)
4757c478bd9Sstevel@tonic-gate 			prbufp->modules = H;
4767c478bd9Sstevel@tonic-gate 		break;
4777c478bd9Sstevel@tonic-gate #endif
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	case 'h':
4807c478bd9Sstevel@tonic-gate 		if (!s)
4817c478bd9Sstevel@tonic-gate 			prbufp->login = 0;
4827c478bd9Sstevel@tonic-gate 		break;
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	case 'i':
4857c478bd9Sstevel@tonic-gate 		if (!s)
4867c478bd9Sstevel@tonic-gate 			prbufp->interface = fullpath(i);
4877c478bd9Sstevel@tonic-gate 		break;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	case 'I':
4907c478bd9Sstevel@tonic-gate 		prbufp->input_types = I;
4917c478bd9Sstevel@tonic-gate 		break;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	case 'l':
4947c478bd9Sstevel@tonic-gate 		if (!s)
4957c478bd9Sstevel@tonic-gate 			prbufp->login = 1;
4967c478bd9Sstevel@tonic-gate 		break;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 	case 'L':
4997c478bd9Sstevel@tonic-gate 		if (!s)
5007c478bd9Sstevel@tonic-gate 			prbufp->plen = length_sdn;
5017c478bd9Sstevel@tonic-gate 		break;
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	case 'm':
5047c478bd9Sstevel@tonic-gate 		if (!s)
5057c478bd9Sstevel@tonic-gate 			prbufp->interface = makepath(Lp_Model, m, (char *)0);
5067c478bd9Sstevel@tonic-gate 		break;
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	case 'M':
5097c478bd9Sstevel@tonic-gate 		if (!s)
5107c478bd9Sstevel@tonic-gate 			prbufp->lpi = lpi_sdn;
5117c478bd9Sstevel@tonic-gate 		break;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
5147c478bd9Sstevel@tonic-gate 	case 'n':
5157c478bd9Sstevel@tonic-gate 	{
5167c478bd9Sstevel@tonic-gate 		if (n_opt != NULL)
5177c478bd9Sstevel@tonic-gate 		{
5187c478bd9Sstevel@tonic-gate 			if (*n_opt == '/')
5197c478bd9Sstevel@tonic-gate 			{
5207c478bd9Sstevel@tonic-gate 				prbufp->ppd = fullpath(n_opt);
5217c478bd9Sstevel@tonic-gate 			}
5227c478bd9Sstevel@tonic-gate 			else
5237c478bd9Sstevel@tonic-gate 			{
5247c478bd9Sstevel@tonic-gate 				prbufp->ppd =
5257c478bd9Sstevel@tonic-gate 				    makepath(Lp_Model, "ppd", n_opt, (char *)0);
5267c478bd9Sstevel@tonic-gate 			}
5277c478bd9Sstevel@tonic-gate 			ppdopt = 1;
5287c478bd9Sstevel@tonic-gate 		}
5297c478bd9Sstevel@tonic-gate 		break;
5307c478bd9Sstevel@tonic-gate 	}
5317c478bd9Sstevel@tonic-gate #endif
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	case 'o':
5347c478bd9Sstevel@tonic-gate 		/*
5357c478bd9Sstevel@tonic-gate 		 * The "undefined" key-value -o options
5367c478bd9Sstevel@tonic-gate 		 *
5377c478bd9Sstevel@tonic-gate 		 * Options requires special handling. It is a
5387c478bd9Sstevel@tonic-gate 		 * list whose members are to be handled
5397c478bd9Sstevel@tonic-gate 		 * individually.
5407c478bd9Sstevel@tonic-gate 		 *
5417c478bd9Sstevel@tonic-gate 		 * Need to: set new options, keep old options if not
5427c478bd9Sstevel@tonic-gate 		 * redefined, remove old options if defined as "key=".
5437c478bd9Sstevel@tonic-gate 		 *
5447c478bd9Sstevel@tonic-gate 		 *
5457c478bd9Sstevel@tonic-gate 		 * "p" is a global containing the printer name
5467c478bd9Sstevel@tonic-gate 		 */
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 		if (!s) {
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate 			if ((infile_opts = getpentry(p, PR_OPTIONS)) == NULL)
5517c478bd9Sstevel@tonic-gate 				prbufp->options = o_options;
5527c478bd9Sstevel@tonic-gate 			else {
5537c478bd9Sstevel@tonic-gate 				prbufp->options =
5547c478bd9Sstevel@tonic-gate 					pick_opts(infile_opts, o_options);
5557c478bd9Sstevel@tonic-gate 			}
5567c478bd9Sstevel@tonic-gate 		}
5577c478bd9Sstevel@tonic-gate 		break;
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	case 'R':
5607c478bd9Sstevel@tonic-gate 		if (s) {
5617c478bd9Sstevel@tonic-gate 			prbufp->remote = s;
5627c478bd9Sstevel@tonic-gate 			prbufp->dial_info = 0;
5637c478bd9Sstevel@tonic-gate 			prbufp->device = 0;
5647c478bd9Sstevel@tonic-gate 		} else
5657c478bd9Sstevel@tonic-gate 			prbufp->remote = 0;
5667c478bd9Sstevel@tonic-gate 		break;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	case 's':
5697c478bd9Sstevel@tonic-gate 		if (!s) {
5707c478bd9Sstevel@tonic-gate 			/*
5717c478bd9Sstevel@tonic-gate 			 * lpadmin always defers to stty
5727c478bd9Sstevel@tonic-gate 			 */
5737c478bd9Sstevel@tonic-gate 			prbufp->speed = 0;
5747c478bd9Sstevel@tonic-gate 			prbufp->stty = stty_opt;
5757c478bd9Sstevel@tonic-gate 		}
5767c478bd9Sstevel@tonic-gate 		break;
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 	case 'S':
5797c478bd9Sstevel@tonic-gate 		if (!M)
5807c478bd9Sstevel@tonic-gate 			if (STREQU(*S, NAME_NONE))
5817c478bd9Sstevel@tonic-gate 				prbufp->char_sets = 0;
5827c478bd9Sstevel@tonic-gate 			else
5837c478bd9Sstevel@tonic-gate 				prbufp->char_sets = S;
5847c478bd9Sstevel@tonic-gate 		break;
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	case 'T':
5877c478bd9Sstevel@tonic-gate 		prbufp->printer_types = T;
5887c478bd9Sstevel@tonic-gate 		break;
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	case 'U':
5917c478bd9Sstevel@tonic-gate 		if (!s) {
5927c478bd9Sstevel@tonic-gate 			prbufp->dial_info = U;
5937c478bd9Sstevel@tonic-gate 			prbufp->device = 0;
5947c478bd9Sstevel@tonic-gate 			prbufp->remote = 0;
5957c478bd9Sstevel@tonic-gate 		}
5967c478bd9Sstevel@tonic-gate 		break;
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 	case 'v':
5997c478bd9Sstevel@tonic-gate 		if (!s) {
6007c478bd9Sstevel@tonic-gate 			prbufp->device = v;
6017c478bd9Sstevel@tonic-gate 			prbufp->dial_info = 0;
6027c478bd9Sstevel@tonic-gate 			prbufp->remote = 0;
6037c478bd9Sstevel@tonic-gate 		}
6047c478bd9Sstevel@tonic-gate 		break;
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	case 'w':
6077c478bd9Sstevel@tonic-gate 		if (!s)
6087c478bd9Sstevel@tonic-gate 			prbufp->pwid = width_sdn;
6097c478bd9Sstevel@tonic-gate 		break;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	case 'W':
6127c478bd9Sstevel@tonic-gate 		if (!s)
6137c478bd9Sstevel@tonic-gate 			prbufp->fault_alert.W = W;
6147c478bd9Sstevel@tonic-gate 		break;
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	}
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
6207c478bd9Sstevel@tonic-gate 		if (putprinter(p, prbufp) == -1) {
6217c478bd9Sstevel@tonic-gate 			if (
6227c478bd9Sstevel@tonic-gate 				errno == EINVAL
6237c478bd9Sstevel@tonic-gate 			     && (badprinter & BAD_INTERFACE)
6247c478bd9Sstevel@tonic-gate 			)
6257c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (
6267c478bd9Sstevel@tonic-gate 					ERROR,
6277c478bd9Sstevel@tonic-gate 					E_ADM_BADINTF,
6287c478bd9Sstevel@tonic-gate 					prbufp->interface
6297c478bd9Sstevel@tonic-gate 				);
6307c478bd9Sstevel@tonic-gate 			else
6317c478bd9Sstevel@tonic-gate 				LP_ERRMSG2 (
6327c478bd9Sstevel@tonic-gate 					ERROR,
6337c478bd9Sstevel@tonic-gate 					E_LP_PUTPRINTER,
6347c478bd9Sstevel@tonic-gate 					p,
6357c478bd9Sstevel@tonic-gate 					PERROR
6367c478bd9Sstevel@tonic-gate 				);
6377c478bd9Sstevel@tonic-gate 			done(1);
6387c478bd9Sstevel@tonic-gate 		}
639*45916cd2Sjpk 
640*45916cd2Sjpk 		if ((getzoneid() == GLOBAL_ZONEID) && system_labeled &&
641*45916cd2Sjpk 		    (prbufp->device != NULL))
642*45916cd2Sjpk 			update_dev_dbs(p, prbufp->device, "ADD");
643*45916cd2Sjpk 
6447c478bd9Sstevel@tonic-gate 	END_CRITICAL
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	return;
6477c478bd9Sstevel@tonic-gate }
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate /**
6507c478bd9Sstevel@tonic-gate  ** fullpath()
6517c478bd9Sstevel@tonic-gate  **/
6527c478bd9Sstevel@tonic-gate 
fullpath(str)6537c478bd9Sstevel@tonic-gate static char		*fullpath (str)
6547c478bd9Sstevel@tonic-gate 	char			*str;
6557c478bd9Sstevel@tonic-gate {
6567c478bd9Sstevel@tonic-gate 	register char		*cur_dir,
6577c478bd9Sstevel@tonic-gate 				*path;
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	while (*str && *str == ' ')
6617c478bd9Sstevel@tonic-gate 		str++;
6627c478bd9Sstevel@tonic-gate 	if (*str == '/')
6637c478bd9Sstevel@tonic-gate 		return (str);
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	if (!(cur_dir = malloc(PATH_MAX + 1)))
6667c478bd9Sstevel@tonic-gate 		return (str);
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	getcwd (cur_dir, PATH_MAX);
6697c478bd9Sstevel@tonic-gate 	path = makepath(cur_dir, str, (char *)0);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 	/*
6727c478bd9Sstevel@tonic-gate 	 * Here we could be nice and strip out /./ and /../
6737c478bd9Sstevel@tonic-gate 	 * stuff, but it isn't necessary.
6747c478bd9Sstevel@tonic-gate 	 */
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	return (path);
6777c478bd9Sstevel@tonic-gate }
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate /**
6807c478bd9Sstevel@tonic-gate  ** nameit() - ADD USER NAME TO COMMAND
6817c478bd9Sstevel@tonic-gate  **/
6827c478bd9Sstevel@tonic-gate 
nameit(cmd)6837c478bd9Sstevel@tonic-gate char			*nameit (cmd)
6847c478bd9Sstevel@tonic-gate 	char			*cmd;
6857c478bd9Sstevel@tonic-gate {
6867c478bd9Sstevel@tonic-gate 	register char		*nm = getname(),
6877c478bd9Sstevel@tonic-gate 				*copy = malloc(
6887c478bd9Sstevel@tonic-gate 					(unsigned) (strlen(cmd) + 1 +
6897c478bd9Sstevel@tonic-gate 					strlen(nm) + 1)
6907c478bd9Sstevel@tonic-gate 	);
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	(void) strcpy (copy, cmd);
6937c478bd9Sstevel@tonic-gate 	(void) strcat (copy, " ");
6947c478bd9Sstevel@tonic-gate 	(void) strcat (copy, nm);
6957c478bd9Sstevel@tonic-gate 	return (copy);
6967c478bd9Sstevel@tonic-gate }
697*45916cd2Sjpk 
698*45916cd2Sjpk /*
699*45916cd2Sjpk  * update_dev_dbs - ADD/REMOVE ENTRIES FOR THE PRINTER IN DEVICE
700*45916cd2Sjpk  * 			ALLOCATION FILES
701*45916cd2Sjpk  *
702*45916cd2Sjpk  * We intentionally ignore errors, since we don't want the printer
703*45916cd2Sjpk  * installation to be viewed as failing just because we didn't add
704*45916cd2Sjpk  * the device_allocate entry.
705*45916cd2Sjpk  *
706*45916cd2Sjpk  *	Input:
707*45916cd2Sjpk  *		prtname - printer name
708*45916cd2Sjpk  *		devname - device associated w/ this printer
709*45916cd2Sjpk  *		func - [ADD|REMOVE] entries in /etc/security/device_allocate
710*45916cd2Sjpk  *			and /etc/security/device_maps
711*45916cd2Sjpk  *
712*45916cd2Sjpk  *	Return:
713*45916cd2Sjpk  *		Always 'quiet' return.  Failures are ignored.
714*45916cd2Sjpk  */
715*45916cd2Sjpk void
update_dev_dbs(char * prtname,char * devname,char * func)716*45916cd2Sjpk update_dev_dbs(char *prtname, char *devname, char *func)
717*45916cd2Sjpk {
718*45916cd2Sjpk 	int		fd, status;
719*45916cd2Sjpk 	pid_t		pid;
720*45916cd2Sjpk 
721*45916cd2Sjpk 	pid = fork();
722*45916cd2Sjpk 	switch (pid) {
723*45916cd2Sjpk 	case -1:
724*45916cd2Sjpk 		/* fork failed, just return quietly */
725*45916cd2Sjpk 		return;
726*45916cd2Sjpk 	case 0:
727*45916cd2Sjpk 		/* child */
728*45916cd2Sjpk 		/* redirect to /dev/null */
729*45916cd2Sjpk 		(void) close(1);
730*45916cd2Sjpk 		(void) close(2);
731*45916cd2Sjpk 		fd = open("/dev/null", O_WRONLY);
732*45916cd2Sjpk 		fd = dup(fd);
733*45916cd2Sjpk 
734*45916cd2Sjpk 		if (strcmp(func, "ADD") == 0) {
735*45916cd2Sjpk 			execl("/usr/sbin/add_allocatable", "add_allocatable",
736*45916cd2Sjpk 			    "-n", prtname, "-t", "lp", "-l", devname,
737*45916cd2Sjpk 			    "-o", "minlabel=admin_low:maxlabel=admin_high",
738*45916cd2Sjpk 			    "-a", "*", "-c", "/bin/true", NULL);
739*45916cd2Sjpk 		} else {
740*45916cd2Sjpk 			if (strcmp(func, "REMOVE") == 0) {
741*45916cd2Sjpk 				execl("/usr/sbin/remove_allocatable",
742*45916cd2Sjpk 				    "remove_allocatable", "-n", prtname, NULL);
743*45916cd2Sjpk 			}
744*45916cd2Sjpk 		}
745*45916cd2Sjpk 		_exit(1);
746*45916cd2Sjpk 		/* NOT REACHED */
747*45916cd2Sjpk 	default:
748*45916cd2Sjpk 		waitpid(pid, &status, 0);
749*45916cd2Sjpk 		return;
750*45916cd2Sjpk 	}
751*45916cd2Sjpk }
752*45916cd2Sjpk 
753*45916cd2Sjpk /*
754*45916cd2Sjpk  * pack_white(ptr) trims off multiple occurances of white space from a NULL
755*45916cd2Sjpk  * terminated string pointed to by "ptr".
756*45916cd2Sjpk  */
757*45916cd2Sjpk static void
pack_white(char * ptr)758*45916cd2Sjpk pack_white(char *ptr)
759*45916cd2Sjpk {
760*45916cd2Sjpk 	char	*tptr;
761*45916cd2Sjpk 	char	*mptr;
762*45916cd2Sjpk 	int	cnt;
763*45916cd2Sjpk 
764*45916cd2Sjpk 	if (ptr == NULL)
765*45916cd2Sjpk 		return;
766*45916cd2Sjpk 	cnt = strlen(ptr);
767*45916cd2Sjpk 	if (cnt == 0)
768*45916cd2Sjpk 		return;
769*45916cd2Sjpk 	mptr = (char *)calloc((unsigned)cnt+1, sizeof (char));
770*45916cd2Sjpk 	if (mptr == NULL)
771*45916cd2Sjpk 		return;
772*45916cd2Sjpk 	tptr = strtok(ptr, " \t");
773*45916cd2Sjpk 	while (tptr != NULL) {
774*45916cd2Sjpk 		(void) strcat(mptr, tptr);
775*45916cd2Sjpk 		(void) strcat(mptr, " ");
776*45916cd2Sjpk 		tptr = strtok(NULL, " \t");
777*45916cd2Sjpk 	}
778*45916cd2Sjpk 	cnt = strlen(mptr);
779*45916cd2Sjpk 	(void) strcpy(ptr, mptr);
780*45916cd2Sjpk 	free(mptr);
781*45916cd2Sjpk }
782