xref: /titanic_51/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/DoPrinterMod.java (revision 62d717f5277d7b19b63db2d800310f877b57c197)
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 /*
22  * ident	"%Z%%M%	%I%	%E% SMI"
23  *
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  *
27  * DoPrinterMod class
28  * Worker class for modifying a printer.
29  */
30 
31 package com.sun.admin.pm.server;
32 
33 import java.io.*;
34 
35 public class  DoPrinterMod {
36 
37     //
38     // main for testing
39     //
40     public static void main(String[] args) {
41 	NameService ns = new NameService();
42 
43 	String[] arr;
44 	arr = new String[1];
45 
46 	Printer p = new Printer();
47 
48 	p.setPrinterName("javatest");
49 	p.setPrinterType("hplaser");
50 	p.setPrintServer("zelkova");
51 	p.setComment("This is a new comment");
52 	p.setDevice("/var/tmp/test");
53 	p.setNotify("none");
54 	p.setProtocol("bsd");
55 	p.setDestination("");
56 	p.setIsDefaultPrinter(true);
57 	p.setBanner("never");
58 	p.setEnable(true);
59 	p.setAccept(false);
60 
61 	arr[0] = "any";
62 	p.setFileContents(arr);
63 	arr[0] = "one";
64 	p.setUserAllowList(arr);
65 	arr[0] = "two";
66 	p.setUserDenyList(arr);
67 
68 	p.setLocale(null);
69 
70 	try {
71 		modify(p, ns);
72 	}
73 	catch (Exception e)
74 	{
75 		System.out.println(e);
76 		System.exit(1);
77 	}
78 	System.out.println("Commands:\n" + p.getCmdLog());
79 	System.out.println("Errors:\n" + p.getErrorLog());
80 	System.out.println("Warnings:\n" + p.getWarnLog());
81 	System.exit(0);
82 
83     }
84 
85     //
86     // Interface to Printer object.
87     //
88     public static void modify(
89 	Printer p,
90 	NameService ns) throws Exception
91     {
92 	Debug.message("SVR: DoPrinterMod.modify()");
93 
94 	Printer curr = new Printer(ns);
95 	curr.setPrinterName(p.getPrinterName());
96 	try {
97 		DoPrinterView.view(curr, ns);
98 	}
99 	catch (Exception e) {
100 		String err = curr.getErrorLog();
101 		p.setErrorLog(err);
102 		throw new pmCmdFailedException(err);
103 	}
104 
105 	boolean islocal = DoPrinterUtil.isLocal(p.getPrinterName());
106 	if (islocal) {
107 		modifyLocal(p, curr, ns);
108 	} else {
109 		modifyRemote(p, curr, ns);
110 	}
111 	return;
112     }
113 
114     //
115     // Do the work of modifying a local printer.
116     //
117     private static void modifyLocal(
118 	Printer p,
119 	Printer curr,
120 	NameService ns) throws Exception
121     {
122 	Debug.message("SVR: DoPrinterMod.modifyLocal()");
123 
124 	String err = null;
125 	String cmd = null;
126 	SysCommand syscmd = null;
127 
128 	// Since it's local set extensions
129 	// Eventually the gui should do this.
130 	p.setExtensions("Solaris");
131 
132 	String nameservice = ns.getNameService();
133 
134 	String printername = p.getPrinterName();
135 	String printertype = null;
136 	String printserver = null;
137 	String comment = null;
138 	String device = null;
139 	String notify = null;
140 	String make = null;
141 	String model = null;
142 	String ppd = null;
143 	String protocol = null;
144 	String destination = null;
145 	String[] file_contents = null;
146 	String[] user_allow_list = null;
147 	String[] user_deny_list = null;
148 	boolean default_printer = false;
149 	String banner = null;
150 	boolean enable = false;
151 	boolean accept = false;
152 	boolean isURI = false;
153 
154 	boolean allow_changed = false;
155 	boolean default_printer_changed = false;
156 	boolean banner_req_changed = false;
157 	boolean enable_changed = false;
158 	boolean accept_changed = false;
159 
160 	String ppdfile = null;
161 
162 
163 	//
164 	// Set the things that have changed.
165 	//
166 	if (!strings_equal(curr.getPrinterType(), p.getPrinterType()))
167 		printertype = p.getPrinterType();
168 	if (!strings_equal(curr.getComment(), p.getComment())) {
169 		comment = p.getComment();
170 		if (comment == null) {
171 			// Comment changed to empty.
172 			p.setComment("");
173 			comment = "";
174 		}
175 	}
176 	if (!strings_equal(curr.getDevice(), p.getDevice()))
177 		device = p.getDevice();
178 
179 	if (!strings_equal(curr.getNotify(), p.getNotify()))
180 		notify = p.getNotify();
181 
182 	if (!strings_equal(curr.getProtocol(), p.getProtocol())) {
183 		protocol = p.getProtocol();
184 	}
185 
186 	// Need to know if the new protocol is uri or if the
187 	// protocol did not change and the current one is uri
188 	if (((protocol == null) && (curr.getProtocol() == "uri")) ||
189 		((protocol != null) && (protocol.equals("uri"))))  {
190 		isURI = true;
191 	}
192 	Debug.message("SVR:DoPrinterMod:isURI: " + isURI);
193 	Debug.message("SVR:DoPrinterMod:protocol: " + protocol);
194 	Debug.message(
195 	    "SVR:DoPrinterMod:curr.getProtocol(): " + curr.getProtocol());
196 	Debug.message("SVR:DoPrinterMod:p.getProtocol(): " + p.getProtocol());
197 
198 	if (!strings_equal(curr.getDestination(), p.getDestination()))
199 		destination = p.getDestination();
200 
201 	if ((!strings_equal(curr.getMake(), p.getMake())) ||
202 		(!strings_equal(curr.getModel(), p.getModel())) ||
203 		(!strings_equal(curr.getPPD(), p.getPPD()))) {
204 
205 			model = p.getModel();
206 			make = p.getMake();
207 			ppd = p.getPPD();
208 		}
209 
210 
211 	if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) {
212 		default_printer = p.getIsDefaultPrinter();
213 		default_printer_changed = true;
214 	}
215 	if (curr.getEnable() != p.getEnable()) {
216 		enable = p.getEnable();
217 		enable_changed = true;
218 	}
219 
220 	if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) {
221 		default_printer = p.getIsDefaultPrinter();
222 		default_printer_changed = true;
223 	}
224 	if (curr.getEnable() != p.getEnable()) {
225 		enable = p.getEnable();
226 		enable_changed = true;
227 	}
228 
229 	if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) {
230 		default_printer = p.getIsDefaultPrinter();
231 		default_printer_changed = true;
232 	}
233 	if (curr.getEnable() != p.getEnable()) {
234 		enable = p.getEnable();
235 		enable_changed = true;
236 	}
237 	if (curr.getAccept() != p.getAccept()) {
238 		accept = p.getAccept();
239 		accept_changed = true;
240 	}
241 	if (!strings_equal(curr.getBanner(), p.getBanner())) {
242 		banner = p.getBanner();
243 		banner_req_changed = true;
244 	}
245 
246 	if (!arrays_equal(curr.getFileContents(), p.getFileContents()))
247 		file_contents = p.getFileContents();
248 
249 	if (!arrays_equal(curr.getUserAllowList(), p.getUserAllowList())) {
250 		allow_changed = true;
251 		// If the current value is "none" and the new
252 		// value is null nothing is changing.
253 		String[] arr = curr.getUserAllowList();
254 		if ((arr != null) && (arr.length != 0)) {
255 			if (arr[0].equals("none")) {
256 				if (p.getUserAllowList() == null) {
257 					allow_changed = false;
258 				}
259 			}
260 		}
261 	}
262 	if (!arrays_equal(curr.getUserDenyList(), p.getUserDenyList())) {
263 		allow_changed = true;
264 	}
265 	if (allow_changed) {
266 		user_allow_list = p.getUserAllowList();
267 		user_deny_list = p.getUserDenyList();
268 	}
269 
270 	//
271 	// Return if nothing changed.
272 	//
273 	if ((printertype == null) &&
274 	    (comment == null) &&
275 	    (device == null) &&
276 	    (notify == null) &&
277 	    (protocol == null) &&
278 	    (destination == null) &&
279 	    (make == null) &&
280 	    (model == null) &&
281 	    (ppd == null) &&
282 	    (file_contents == null) &&
283 	    (!allow_changed) &&
284 	    (!default_printer_changed) &&
285 	    (!enable_changed) &&
286 	    (!accept_changed) &&
287 	    (!banner_req_changed)) {
288 		return;
289 	}
290 
291 	// If this is the default printer set it.
292 	if (default_printer_changed) {
293 		if (default_printer) {
294 			cmd = "/usr/sbin/lpadmin -d " + printername;
295 		} else {
296 			cmd = "/usr/sbin/lpadmin -x _default";
297 		}
298 		p.setCmdLog(cmd);
299 		syscmd = new SysCommand();
300 		syscmd.exec(cmd);
301 		err = syscmd.getError();
302 		if (syscmd.getExitValue() != 0) {
303 			p.setErrorLog(err);
304 			syscmd = null;
305 			throw new pmCmdFailedException(err);
306 		} else if (err != null) {
307 			p.setWarnLog(err);
308 		}
309 		syscmd = null;
310 	}
311 
312 	//
313 	// If this is only a default printer change then possibly
314 	// update the name service and return.
315 	if ((printertype == null) &&
316 	    (comment == null) &&
317 	    (device == null) &&
318 	    (notify == null) &&
319 	    (protocol == null) &&
320 	    (destination == null) &&
321 	    (make == null) &&
322 	    (model == null) &&
323 	    (ppd == null) &&
324 	    (file_contents == null) &&
325 	    (!allow_changed) &&
326 	    (!enable_changed) &&
327 	    (!accept_changed) &&
328 	    (!banner_req_changed)) {
329 		if (nameservice.equals("system")) {
330 			return;
331 		}
332 		p.modhints = "defaultonly";
333 
334 		DoPrinterNS.set("modify", p, ns);
335 		p.modhints = "";
336 		return;
337 	}
338 
339 	//
340 	// Do enable/accept
341 	//
342 	if (enable_changed) {
343 		if (p.getEnable() == true) {
344 			cmd = "/usr/bin/enable " + printername;
345 		} else {
346 			cmd = "/usr/bin/disable " + printername;
347 		}
348 		p.setCmdLog(cmd);
349 		syscmd = new SysCommand();
350 		syscmd.exec(cmd);
351 		err = syscmd.getError();
352 		if (syscmd.getExitValue() != 0) {
353 			p.setErrorLog(err);
354 			syscmd = null;
355 			throw new pmCmdFailedException(err);
356 		} else if (err != null) {
357 			p.setWarnLog(err);
358 		}
359 		syscmd = null;
360 	}
361 	if (accept_changed) {
362 		if (p.getAccept() == true) {
363 			cmd = "/usr/sbin/accept " + printername;
364 		} else {
365 			cmd = "/usr/sbin/reject " + printername;
366 		}
367 		p.setCmdLog(cmd);
368 		syscmd = new SysCommand();
369 		syscmd.exec(cmd);
370 		err = syscmd.getError();
371 		if (syscmd.getExitValue() != 0) {
372 			p.setErrorLog(err);
373 			syscmd = null;
374 			throw new pmCmdFailedException(err);
375 		} else if (err != null) {
376 			p.setWarnLog(err);
377 		}
378 		syscmd = null;
379 	}
380 
381 
382 	//
383 	// Do some slight of hand to deal with overloading of destination
384 	// with device for uri protocol
385 	// Done at the last moment to prevent modifying logic for old/new
386 	// properties of the queue
387 
388 	if (isURI) {
389 		if (destination != null)
390 			device = destination;
391 		else
392 			device = curr.getDestination();
393 		destination = null;
394 		protocol = null;
395 	} else {
396 		if (protocol != null) {
397 			device = "/dev/null";
398 		}
399 	}
400 
401 
402 
403 	//
404 	// Build the modify command
405 	//
406 
407 	cmd = "/usr/sbin/lpadmin -p " + printername;
408 
409 	if (printername != null)
410 		if (DoPrinterUtil.isLocalhost(printername)) {
411 			cmd = cmd.concat(" -s localhost");
412 			Debug.message("SVR:DoModifyPrinter:isLocalhost:true");
413 	}
414 
415 	if (device != null) {
416 		cmd = cmd.concat(" -v " + device);
417 	}
418 
419 	// Network printer
420 	if (isURI) {
421                 cmd = cmd.concat(" -m uri");
422 
423 	} else if (protocol != null) {
424 
425 		if (curr.getPPD() != null)
426                		cmd = cmd.concat(" -m netstandard_foomatic");
427 		else
428                		cmd = cmd.concat(" -m netstandard");
429 	}
430 
431 	if (printertype != null)
432 		cmd = cmd.concat(" -T " + printertype);
433 
434 	if (ppd != null) {
435 		ppdfile = new String(DoPrinterUtil.getPPDFile(make,
436 				model, ppd));
437 
438 	Debug.message("SVR:modifyLocal:ppdfile: " + ppdfile);
439 
440 		cmd = cmd.concat(" -n " + ppdfile);
441 	}
442 
443 	if (notify != null)
444 		cmd = cmd.concat(" -A " + notify);
445 
446 	// destination is overloaded to hold uri device for network printers
447 	// if the protocol is uri, don't set either destination or protocol
448 	// the device has been set to the destination above
449 
450 	if (isURI) {
451 			cmd = cmd.concat(" -o dest=");
452 			cmd = cmd.concat(" -o protocol=");
453 	} else {
454 		if (destination != null)
455 		    cmd = cmd.concat(" -o dest=" + destination);
456 		if (protocol != null)
457 		    cmd = cmd.concat(" -o protocol=" + protocol);
458 	}
459 
460 	if ((file_contents != null) && (file_contents.length != 0)) {
461 		String tmpstr = file_contents[0];
462 		for (int i = 1; i < file_contents.length; i++) {
463 			tmpstr = tmpstr.concat("," + file_contents[i]);
464 		}
465 		cmd = cmd.concat(" -I " + tmpstr);
466 	}
467 
468 	if (banner_req_changed) {
469 		if (banner != null) {
470 			cmd = cmd.concat(" -o banner=" + banner);
471 		}
472 	}
473 
474 	//
475 	// Has any of the above changed.
476 	//
477 	if (!cmd.equals("/usr/sbin/lpadmin -p " + printername)) {
478 		p.setCmdLog(cmd);
479 		syscmd = new SysCommand();
480 		syscmd.exec(cmd);
481 		err = syscmd.getError();
482 		if (syscmd.getExitValue() != 0) {
483 			p.setErrorLog(err);
484 			syscmd = null;
485 			throw new pmCmdFailedException(err);
486 		} else if (err != null) {
487 			p.setWarnLog(err);
488 		}
489 		syscmd = null;
490 	}
491 
492 	//
493 	// If the user allow list changed delete all then re-add
494 	//
495 	if (allow_changed) {
496 		cmd = "/usr/sbin/lpadmin -p " + printername +
497 			" -u allow:none";
498 		p.setCmdLog(cmd);
499 		syscmd = new SysCommand();
500 		syscmd.exec(cmd);
501 		err = syscmd.getError();
502 		if (syscmd.getExitValue() != 0) {
503 			p.setErrorLog(err);
504 			syscmd = null;
505 			throw new pmCmdFailedException(err);
506 		} else if (err != null) {
507 			p.setWarnLog(err);
508 		}
509 		syscmd = null;
510 
511 		if ((user_deny_list != null) &&
512 		    (user_deny_list.length != 0)) {
513 			String tmpstr = user_deny_list[0];
514 			for (int i = 1; i < user_deny_list.length; i++) {
515 				tmpstr = tmpstr.concat(","
516 				    + user_deny_list[i]);
517 			}
518 			cmd = "/usr/sbin/lpadmin -p " + printername +
519 			    " -u deny:" + tmpstr;
520 			p.setCmdLog(cmd);
521 			syscmd = new SysCommand();
522 			syscmd.exec(cmd);
523 			err = syscmd.getError();
524 			if (syscmd.getExitValue() != 0) {
525 				p.setErrorLog(err);
526 				syscmd = null;
527 				throw new pmCmdFailedException(err);
528 			} else if (err != null) {
529 				p.setWarnLog(err);
530 			}
531 			syscmd = null;
532 		}
533 
534 		if ((user_allow_list != null) &&
535 		    (user_allow_list.length != 0) &&
536 		    (!user_allow_list[0].equals("none"))) {
537 			String tmpstr = user_allow_list[0];
538 			for (int i = 1; i < user_allow_list.length; i++) {
539 				tmpstr = tmpstr.concat(","
540 				    + user_allow_list[i]);
541 			}
542 			cmd = "/usr/sbin/lpadmin -p " + printername +
543 			    " -u allow:" + tmpstr;
544 			p.setCmdLog(cmd);
545 			syscmd = new SysCommand();
546 			syscmd.exec(cmd);
547 			err = syscmd.getError();
548 			if (syscmd.getExitValue() != 0) {
549 				p.setErrorLog(err);
550 				syscmd = null;
551 				throw new pmCmdFailedException(err);
552 			} else if (err != null) {
553 				p.setWarnLog(err);
554 			}
555 			syscmd = null;
556 		}
557 	}
558 
559 	if (comment != null) {
560 		//
561 		// Have to use a command array here since
562 		// exec(String) doesn't parse quoted strings.
563 		// Use lpadmin so the comment in /etc/printers.conf
564 		// and /etc/lp/printers/comment stay in sync.
565 		//
566 		String cmd_array[] =
567 			{ "/usr/sbin/lpadmin", "-D",
568 				comment, "-p", printername };
569 		cmd = "/usr/sbin/lpadmin -D " +
570 			"\"" + comment + "\"" + " -p " + printername;
571 		p.setCmdLog(cmd);
572 		syscmd = new SysCommand();
573 		syscmd.exec(cmd_array);
574 		err = syscmd.getError();
575 		if (syscmd.getExitValue() != 0) {
576 			p.setErrorLog(err);
577 			syscmd = null;
578 			throw new pmCmdFailedException(err);
579 		} else if (err != null) {
580 			p.setWarnLog(err);
581 		}
582 		syscmd = null;
583 		if (comment.equals("")) {
584 			//
585 			// LPADMIN BUG. Comment not cleared in printers.conf
586 			// so force it with lpset.
587 			//
588 			cmd = "/usr/bin/lpset -a description= " + printername;
589 			syscmd = new SysCommand();
590 			syscmd.exec(cmd);
591 			if (syscmd.getExitValue() != 0) {
592 				err = syscmd.getError();
593 				p.setWarnLog(err);
594 			}
595 			syscmd = null;
596 		}
597 	}
598 
599 	//
600 	// Return if we don't need to touch the name service.
601 	//
602 	if (nameservice.equals("system")) {
603 		return;
604 	}
605 	if ((comment == null) && (!default_printer_changed)) {
606 		return;
607 	}
608 
609 	DoPrinterNS.set("modify", p, ns);
610 	return;
611     }
612 
613     //
614     // Do the work of modifying a remote printer.
615     //
616     private static void modifyRemote(
617 	Printer p,
618 	Printer curr,
619 	NameService ns) throws Exception
620     {
621 	int exitvalue = 0;
622 	String err = null;
623 	String cmd = null;
624 	String cmd_array[] = new String[4];
625 	SysCommand syscmd = null;
626 
627         String printername = null;
628         String printserver = null;
629         String comment = null;
630 	String extensions = null;
631         boolean default_printer = false;
632 	boolean default_printer_changed = false;
633 
634         String nameservice = ns.getNameService();
635 
636 	printername = p.getPrinterName();
637 	if (!strings_equal(curr.getPrintServer(), p.getPrintServer()))
638 		printserver = p.getPrintServer();
639 
640 	if (!strings_equal(curr.getComment(), p.getComment())) {
641 		comment = p.getComment();
642 		if (comment == null) {
643 			// The comment changed to empty.
644 			p.setComment("");
645 			comment = "";
646 		}
647 	}
648 //
649 // Don't support extensions in the gui yet.
650 // If they exist leave them alone.
651 // EXTENSIONS
652 	p.setExtensions(curr.getExtensions());
653 	if (!strings_equal(curr.getExtensions(), p.getExtensions()))
654 		extensions = p.getExtensions();
655 	if (curr.getIsDefaultPrinter() != p.getIsDefaultPrinter()) {
656 		default_printer = p.getIsDefaultPrinter();
657 		default_printer_changed = true;
658 	}
659 
660 	//
661 	// Return if nothing changed.
662 	//
663 	if ((printserver == null) &&
664 	    (extensions == null) &&
665 	    (comment == null) &&
666 	    (!default_printer_changed)) {
667 		return;
668 	}
669 
670 	//
671 	// If this is only a default printer change then set modhints
672 	//
673 	if ((printserver == null) &&
674 	    (extensions == null) &&
675 	    (comment == null)) {
676 		p.modhints = "defaultonly";
677 	}
678 
679 
680         //
681         // Find out if we are the nis master
682         //
683         boolean isnismaster = false;
684 	if (nameservice.equals("nis")) {
685         	String nshost = ns.getNameServiceHost();
686         	Host h = new Host();
687         	String lh = h.getLocalHostName();
688         	if (lh.equals(nshost))
689                 	isnismaster = true;
690 		h = null;
691 	}
692 
693 	//
694 	// If we are not updating system and we are not the nis
695 	// master then update the name service and return.
696 	//
697 	if ((!nameservice.equals("system")) && (!isnismaster)) {
698 		DoPrinterNS.set("modify", p, ns);
699 		p.modhints = "";
700 		return;
701 	}
702 	p.modhints = "";
703 
704 	//
705 	// Take care of the bsdaddr attribute
706 	//
707 	// EXTENSIONS
708 	// The gui doesn't support extensions yet so the goal
709 	// here is to prepare for it but don't actually
710 	// modify them.
711 	//
712 	if ((printserver != null) || (extensions != null)) {
713 		// If printserver is null we are changing
714 		// extensions. Set printserver to its current
715 		// value.
716 		if (printserver == null) {
717 			printserver = curr.getPrintServer();
718 		}
719 		String bsdaddr = "bsdaddr=" + printserver + ","
720 			+ printername;
721 		//
722 		// Leave the extensions alone
723 		// EXTENSIONS
724 		//
725 		extensions = curr.getExtensions();
726 		if (extensions != null) {
727 			bsdaddr = bsdaddr.concat("," + extensions);
728 		}
729 		cmd = "/usr/bin/lpset -a " + bsdaddr + " " + printername;
730 		p.setCmdLog(cmd);
731 		syscmd = new SysCommand();
732 		syscmd.exec(cmd);
733 		err = syscmd.getError();
734 		if (syscmd.getExitValue() != 0) {
735 			p.setErrorLog(err);
736 			syscmd = null;
737 			throw new pmCmdFailedException(err);
738 		}
739 		if (err != null) {
740 			p.setWarnLog(err);
741 		}
742 		syscmd = null;
743 	}
744 	if (comment != null) {
745 		cmd = "/usr/bin/lpset" + " -a description=" +
746 			"\"" + comment + "\"" +
747 			" " + printername;
748 		cmd_array[0] = "/usr/bin/lpset";
749 		cmd_array[1] = "-a";
750 		cmd_array[2] = "description=" + comment;
751 		cmd_array[3] = printername;
752 
753 		p.setCmdLog(cmd);
754 		syscmd = new SysCommand();
755 		syscmd.exec(cmd_array);
756 		err = syscmd.getError();
757 		if (syscmd.getExitValue() != 0) {
758 			p.setErrorLog(err);
759 			syscmd = null;
760 			throw new pmCmdFailedException(err);
761 		}
762 		if (err != null) {
763 			p.setWarnLog(err);
764 		}
765 		syscmd = null;
766 	}
767 
768 	// If this is the default printer set it.
769 	if (default_printer_changed) {
770 		if (default_printer) {
771 			cmd = "/usr/sbin/lpadmin -d " + printername;
772 		} else {
773 			cmd = "/usr/sbin/lpadmin -x _default";
774 		}
775 		p.setCmdLog(cmd);
776 		syscmd = new SysCommand();
777 		syscmd.exec(cmd);
778 		err = syscmd.getError();
779 		if (syscmd.getExitValue() != 0) {
780 			p.setErrorLog(err);
781 			syscmd = null;
782 			throw new pmCmdFailedException(err);
783 		}
784 		if (err != null) {
785 			p.setWarnLog(err);
786 		}
787 		syscmd = null;
788 	}
789 
790 	//
791 	// If it's nis and we are here then we are the nis
792 	// master. This call will do the make for us.
793 	//
794 	if (nameservice.equals("nis")) {
795 		DoPrinterNS.set("modify", p, ns);
796 	}
797 	return;
798     }
799 
800     private static boolean arrays_equal(String[] arr1, String[] arr2)
801     {
802 	if ((arr1 == null) && (arr2 == null)) {
803 		return (true);
804 	}
805 	if ((arr1 == null) || (arr2 == null)) {
806 		return (false);
807 	}
808 	if (arr1.length != arr2.length) {
809 		return (false);
810 	}
811 
812 	int i, j;
813 	String str;
814 	boolean found;
815 	for (i = 0; i < arr1.length; i++) {
816 		found = false;
817 		str = arr1[i];
818 		for (j = 0; j < arr2.length; j++) {
819 			if (str.equals(arr2[j])) {
820 				found = true;
821 			}
822 		}
823 		if (found == false) {
824 			return (false);
825 		}
826 	}
827 	return (true);
828     }
829 
830     private static boolean strings_equal(String str1, String str2)
831     {
832 	if ((str1 == null) && (str2 == null)) {
833 		return (true);
834 	}
835 	if ((str1 == null) || (str2 == null)) {
836 		return (false);
837 	}
838 
839 	return (str1.equals(str2));
840     }
841 }
842