1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 #pragma ident "%Z%%M% %I% %E% SMI"
26
27 /*
28 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
30 */
31
32 #include "stdio.h"
33 #include "ctype.h"
34 #include "errno.h"
35 #include "sys/types.h"
36
37 #include "lp.h"
38 #include "msgs.h"
39 #include "access.h"
40 #include "class.h"
41 #include "printers.h"
42
43 #define WHO_AM_I I_AM_LPADMIN
44 #include "oam.h"
45
46 #include "lpadmin.h"
47
48 extern void fromallclasses();
49
50 /**
51 ** rmdest() - REMOVE DESTINATION
52 **/
53
rmdest(aclass,dest)54 void rmdest (aclass, dest)
55 int aclass;
56 char *dest;
57 {
58 int rc,
59 type;
60
61
62 if (!aclass)
63 type = S_UNLOAD_PRINTER;
64 else
65 type = S_UNLOAD_CLASS;
66
67
68 send_message(type, dest, "", "");
69 rc = output(type + 1);
70
71 switch (rc) {
72 case MOK:
73 case MNODEST:
74 BEGIN_CRITICAL
75 if (
76 aclass && delclass(dest) == -1
77 || !aclass && delprinter(dest) == -1
78 ) {
79 if (rc == MNODEST && errno == ENOENT)
80 LP_ERRMSG1 (
81 ERROR,
82 E_ADM_NODEST,
83 dest
84 );
85
86 else
87 LP_ERRMSG2 (
88 ERROR,
89 (rc == MNODEST? (aclass? E_LP_DELCLASS : E_LP_DELPRINTER) : E_ADM_DELSTRANGE),
90 dest,
91 PERROR
92 );
93
94 done(1);
95 }
96 END_CRITICAL
97
98 /*
99 * S_UNLOAD_PRINTER tells the Spooler to remove
100 * the printer from all classes (in its internal
101 * tables, of course). So it's okay for us to do
102 * the same with the disk copies.
103 */
104 if (!aclass)
105 fromallclasses (dest);
106
107 if (STREQU(getdflt(), dest))
108 newdflt (NAME_NONE);
109
110 if (system_labeled) {
111 update_dev_dbs(dest, NULL, "REMOVE");
112 }
113 break;
114
115 case MBUSY:
116 LP_ERRMSG1 (ERROR, E_ADM_DESTBUSY, dest);
117 done (1);
118
119 case MNOPERM: /* taken care of up front */
120 default:
121 LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
122 done (1);
123 break;
124
125 }
126 return;
127 }
128