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 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 #include "stdio.h"
30 #include "ctype.h"
31 #include "errno.h"
32 #include "sys/types.h"
33
34 #include "lp.h"
35 #include "msgs.h"
36 #include "access.h"
37 #include "class.h"
38 #include "printers.h"
39
40 #define WHO_AM_I I_AM_LPADMIN
41 #include "oam.h"
42
43 #include "lpadmin.h"
44
45 extern void fromallclasses();
46
47 /**
48 ** rmdest() - REMOVE DESTINATION
49 **/
50
rmdest(aclass,dest)51 void rmdest (aclass, dest)
52 int aclass;
53 char *dest;
54 {
55 int rc,
56 type;
57
58
59 if (!aclass)
60 type = S_UNLOAD_PRINTER;
61 else
62 type = S_UNLOAD_CLASS;
63
64
65 send_message(type, dest, "", "");
66 rc = output(type + 1);
67
68 switch (rc) {
69 case MOK:
70 case MNODEST:
71 BEGIN_CRITICAL
72 if (
73 aclass && delclass(dest) == -1
74 || !aclass && delprinter(dest) == -1
75 ) {
76 if (rc == MNODEST && errno == ENOENT)
77 LP_ERRMSG1 (
78 ERROR,
79 E_ADM_NODEST,
80 dest
81 );
82
83 else
84 LP_ERRMSG2 (
85 ERROR,
86 (rc == MNODEST? (aclass? E_LP_DELCLASS : E_LP_DELPRINTER) : E_ADM_DELSTRANGE),
87 dest,
88 PERROR
89 );
90
91 done(1);
92 }
93 END_CRITICAL
94
95 /*
96 * S_UNLOAD_PRINTER tells the Spooler to remove
97 * the printer from all classes (in its internal
98 * tables, of course). So it's okay for us to do
99 * the same with the disk copies.
100 */
101 if (!aclass)
102 fromallclasses (dest);
103
104 if (STREQU(getdflt(), dest))
105 newdflt (NAME_NONE);
106
107 if (system_labeled) {
108 update_dev_dbs(dest, NULL, "REMOVE");
109 }
110 break;
111
112 case MBUSY:
113 LP_ERRMSG1 (ERROR, E_ADM_DESTBUSY, dest);
114 done (1);
115
116 case MNOPERM: /* taken care of up front */
117 default:
118 LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
119 done (1);
120 break;
121
122 }
123 return;
124 }
125