xref: /illumos-gate/usr/src/cmd/lp/cmd/lpadmin/rmdest.c (revision 2a8bcb4e)
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 
24*45916cd2Sjpk /*
25*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
26*45916cd2Sjpk  * Use is subject to license terms.
27*45916cd2Sjpk  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "stdio.h"
307c478bd9Sstevel@tonic-gate #include "ctype.h"
317c478bd9Sstevel@tonic-gate #include "errno.h"
327c478bd9Sstevel@tonic-gate #include "sys/types.h"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include "lp.h"
357c478bd9Sstevel@tonic-gate #include "msgs.h"
367c478bd9Sstevel@tonic-gate #include "access.h"
377c478bd9Sstevel@tonic-gate #include "class.h"
387c478bd9Sstevel@tonic-gate #include "printers.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	WHO_AM_I	I_AM_LPADMIN
417c478bd9Sstevel@tonic-gate #include "oam.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include "lpadmin.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate extern void		fromallclasses();
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /**
487c478bd9Sstevel@tonic-gate  ** rmdest() - REMOVE DESTINATION
497c478bd9Sstevel@tonic-gate  **/
507c478bd9Sstevel@tonic-gate 
rmdest(aclass,dest)517c478bd9Sstevel@tonic-gate void			rmdest (aclass, dest)
527c478bd9Sstevel@tonic-gate 	int			aclass;
537c478bd9Sstevel@tonic-gate 	char			*dest;
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	int			rc,
567c478bd9Sstevel@tonic-gate 				type;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	if (!aclass)
607c478bd9Sstevel@tonic-gate 		type = S_UNLOAD_PRINTER;
617c478bd9Sstevel@tonic-gate 	else
627c478bd9Sstevel@tonic-gate 		type = S_UNLOAD_CLASS;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	send_message(type, dest, "", "");
667c478bd9Sstevel@tonic-gate 	rc = output(type + 1);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	switch (rc) {
697c478bd9Sstevel@tonic-gate 	case MOK:
707c478bd9Sstevel@tonic-gate 	case MNODEST:
717c478bd9Sstevel@tonic-gate 		BEGIN_CRITICAL
727c478bd9Sstevel@tonic-gate 			if (
737c478bd9Sstevel@tonic-gate 				aclass && delclass(dest) == -1
747c478bd9Sstevel@tonic-gate 			     || !aclass && delprinter(dest) == -1
757c478bd9Sstevel@tonic-gate 			) {
767c478bd9Sstevel@tonic-gate 				if (rc == MNODEST && errno == ENOENT)
777c478bd9Sstevel@tonic-gate 					LP_ERRMSG1 (
787c478bd9Sstevel@tonic-gate 						ERROR,
797c478bd9Sstevel@tonic-gate 						E_ADM_NODEST,
807c478bd9Sstevel@tonic-gate 						dest
817c478bd9Sstevel@tonic-gate 					);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 				else
847c478bd9Sstevel@tonic-gate 					LP_ERRMSG2 (
857c478bd9Sstevel@tonic-gate 						ERROR,
867c478bd9Sstevel@tonic-gate (rc == MNODEST? (aclass? E_LP_DELCLASS : E_LP_DELPRINTER) : E_ADM_DELSTRANGE),
877c478bd9Sstevel@tonic-gate 						dest,
887c478bd9Sstevel@tonic-gate 						PERROR
897c478bd9Sstevel@tonic-gate 					);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 				done(1);
927c478bd9Sstevel@tonic-gate 			}
937c478bd9Sstevel@tonic-gate 		END_CRITICAL
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 		/*
967c478bd9Sstevel@tonic-gate 		 * S_UNLOAD_PRINTER tells the Spooler to remove
977c478bd9Sstevel@tonic-gate 		 * the printer from all classes (in its internal
987c478bd9Sstevel@tonic-gate 		 * tables, of course). So it's okay for us to do
997c478bd9Sstevel@tonic-gate 		 * the same with the disk copies.
1007c478bd9Sstevel@tonic-gate 		 */
1017c478bd9Sstevel@tonic-gate 		if (!aclass)
1027c478bd9Sstevel@tonic-gate 			fromallclasses (dest);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 		if (STREQU(getdflt(), dest))
1057c478bd9Sstevel@tonic-gate 			newdflt (NAME_NONE);
1067c478bd9Sstevel@tonic-gate 
107*45916cd2Sjpk 		if (system_labeled) {
108*45916cd2Sjpk 			update_dev_dbs(dest, NULL, "REMOVE");
109*45916cd2Sjpk 		}
1107c478bd9Sstevel@tonic-gate 		break;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	case MBUSY:
1137c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_ADM_DESTBUSY, dest);
1147c478bd9Sstevel@tonic-gate 		done (1);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	case MNOPERM:	/* taken care of up front */
1177c478bd9Sstevel@tonic-gate 	default:
1187c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
1197c478bd9Sstevel@tonic-gate 		done (1);
1207c478bd9Sstevel@tonic-gate 		break;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	}
1237c478bd9Sstevel@tonic-gate 	return;
1247c478bd9Sstevel@tonic-gate }
125