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 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * 25 * NameService class 26 * Methods and state associated with a name service. 27 */ 28 29 package com.sun.admin.pm.server; 30 31 import java.io.*; 32 33 public class NameService 34 { 35 private String nameservice = null; 36 private String nshost = null; 37 private String user = null; 38 private String passwd = null; 39 private boolean boundtonisslave = false; 40 private boolean isauth = false; 41 42 // 43 // Constructors 44 // 45 // This constructor is used internally in the server package. NameService()46 public NameService() 47 { 48 nameservice = "system"; 49 isauth = true; 50 } 51 // This constructor should always be used by the client. NameService(String nsname)52 public NameService(String nsname) throws Exception 53 { 54 if ((nsname.equals("system")) || 55 (nsname.equals("nis")) || 56 (nsname.equals("ldap"))) { 57 nameservice = nsname; 58 } else { 59 throw new pmInternalErrorException( 60 "Unknown name service: " + nsname); 61 } 62 63 Host h = new Host(); 64 h.isNSConfigured(nameservice); 65 66 if (nsname.equals("nis")) { 67 String nm = h.getNisHost("master"); 68 String nb = h.getNisHost("bound"); 69 if (!nm.equals(nb)) { 70 boundtonisslave = true; 71 } 72 setUser("root"); 73 setNameServiceHost(nm); 74 setPasswd(""); 75 } else if (nsname.equals("ldap")) { 76 String master = h.getLDAPMaster(); 77 if (master == null) { 78 setNameServiceHost(""); 79 } else { 80 setNameServiceHost(master); 81 } 82 83 String admin = h.getDefaultAdminDN(); 84 if (admin == null) { 85 setUser(""); 86 } else { 87 setUser(admin); 88 } 89 90 setPasswd(""); 91 } 92 93 } 94 setNameServiceHost(String arg)95 public void setNameServiceHost(String arg) 96 { 97 nshost = arg; 98 } setUser(String arg)99 public void setUser(String arg) 100 { 101 user = arg; 102 } setPasswd(String arg)103 public void setPasswd(String arg) 104 { 105 passwd = arg; 106 } 107 getNameService()108 public String getNameService() 109 { 110 return (nameservice); 111 } getNameServiceHost()112 public String getNameServiceHost() 113 { 114 return (nshost); 115 } getUser()116 public String getUser() 117 { 118 return (user); 119 } getPasswd()120 public String getPasswd() 121 { 122 return (passwd); 123 } getBoundToNisSlave()124 public boolean getBoundToNisSlave() 125 { 126 return (boundtonisslave); 127 } isAuth()128 public boolean isAuth() 129 { 130 return (isauth); 131 } 132 checkAuth()133 public void checkAuth() throws Exception 134 { 135 Debug.message("SVR: NameService.checkAuth()"); 136 137 DoPrinterNS.doAuth(this); 138 isauth = true; 139 } 140 } 141