1*2264Sjacobs /*
2*2264Sjacobs  * CDDL HEADER START
3*2264Sjacobs  *
4*2264Sjacobs  * The contents of this file are subject to the terms of the
5*2264Sjacobs  * Common Development and Distribution License, Version 1.0 only
6*2264Sjacobs  * (the "License").  You may not use this file except in compliance
7*2264Sjacobs  * with the License.
8*2264Sjacobs  *
9*2264Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*2264Sjacobs  * or http://www.opensolaris.org/os/licensing.
11*2264Sjacobs  * See the License for the specific language governing permissions
12*2264Sjacobs  * and limitations under the License.
13*2264Sjacobs  *
14*2264Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
15*2264Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*2264Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
17*2264Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
18*2264Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
19*2264Sjacobs  *
20*2264Sjacobs  * CDDL HEADER END
21*2264Sjacobs  */
22*2264Sjacobs /*
23*2264Sjacobs  * Copyright 1998-2003 Sun Microsystems, Inc.  All rights reserved.
24*2264Sjacobs  * Use is subject to license terms.
25*2264Sjacobs  */
26*2264Sjacobs 
27*2264Sjacobs #ifndef _NS_H
28*2264Sjacobs #define	_NS_H
29*2264Sjacobs 
30*2264Sjacobs #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*2264Sjacobs 
32*2264Sjacobs #ifdef __cplusplus
33*2264Sjacobs extern "C" {
34*2264Sjacobs #endif
35*2264Sjacobs 
36*2264Sjacobs /*
37*2264Sjacobs  *		Name Service Common Keys/types for lookup
38*2264Sjacobs  */
39*2264Sjacobs #define	NS_KEY_BSDADDR			"bsdaddr"
40*2264Sjacobs #define	NS_KEY_USE			"use"
41*2264Sjacobs #define	NS_KEY_ALL			"all"
42*2264Sjacobs #define	NS_KEY_GROUP			"group"
43*2264Sjacobs #define	NS_KEY_LIST			"list"
44*2264Sjacobs 
45*2264Sjacobs #define	NS_KEY_PRINTER_TYPE		"printer-type"
46*2264Sjacobs #define	NS_KEY_DESCRIPTION		"description"
47*2264Sjacobs 
48*2264Sjacobs /*
49*2264Sjacobs  *		Name Service reserved names for lookup
50*2264Sjacobs  */
51*2264Sjacobs #define	NS_NAME_DEFAULT		"_default"
52*2264Sjacobs #define	NS_NAME_ALL		"_all"
53*2264Sjacobs 
54*2264Sjacobs /*
55*2264Sjacobs  *		Name Services supported
56*2264Sjacobs  */
57*2264Sjacobs #define	NS_SVC_USER		"user"
58*2264Sjacobs #define	NS_SVC_PRINTCAP		"printcap"
59*2264Sjacobs #define	NS_SVC_ETC		"etc"
60*2264Sjacobs #define	NS_SVC_NIS		"nis"
61*2264Sjacobs #define	NS_SVC_NISPLUS		"nisplus"
62*2264Sjacobs #define	NS_SVC_LDAP		"ldap"
63*2264Sjacobs 
64*2264Sjacobs /*
65*2264Sjacobs  *		Known Protocol Extensions
66*2264Sjacobs  */
67*2264Sjacobs #define	NS_EXT_SOLARIS		"solaris"
68*2264Sjacobs #define	NS_EXT_GENERIC		"extensions" /* same as SOLARIS */
69*2264Sjacobs #define	NS_EXT_HPUX		"hpux"
70*2264Sjacobs #define	NS_EXT_DEC		"dec"
71*2264Sjacobs 
72*2264Sjacobs /*
73*2264Sjacobs  *	get unique or full list of printer bindings
74*2264Sjacobs  */
75*2264Sjacobs #define	NOTUNIQUE	0
76*2264Sjacobs #define	UNIQUE		1
77*2264Sjacobs #define	LOCAL_UNIQUE	2	/* include alias names */
78*2264Sjacobs 
79*2264Sjacobs /*  BSD binding address structure */
80*2264Sjacobs struct ns_bsd_addr {
81*2264Sjacobs 	char	*server;	/* server name */
82*2264Sjacobs 	char	*printer;	/* printer name or NULL */
83*2264Sjacobs 	char	*extension;	/* RFC-1179 conformance */
84*2264Sjacobs 	char  *pname;		/* Local printer name */
85*2264Sjacobs };
86*2264Sjacobs typedef struct ns_bsd_addr ns_bsd_addr_t;
87*2264Sjacobs 
88*2264Sjacobs /* Key/Value pair structure */
89*2264Sjacobs struct ns_kvp {
90*2264Sjacobs 	char *key;		/* key */
91*2264Sjacobs 	char *value;		/* value string */
92*2264Sjacobs };
93*2264Sjacobs typedef struct ns_kvp ns_kvp_t;
94*2264Sjacobs 
95*2264Sjacobs 
96*2264Sjacobs /* LDAP specific result codes */
97*2264Sjacobs 
98*2264Sjacobs typedef enum NSL_RESULT
99*2264Sjacobs {
100*2264Sjacobs 	NSL_OK			= 0,	/* Operation successful */
101*2264Sjacobs 	NSL_ERR_INTERNAL	= 1,	/* Internal coding Error */
102*2264Sjacobs 	NSL_ERR_ADD_FAILED	= 2,	/* LDAP add failed */
103*2264Sjacobs 	NSL_ERR_MOD_FAILED	= 3,	/* LDAP modify failed */
104*2264Sjacobs 	NSL_ERR_DEL_FAILED	= 4,	/* LDAP delete failed */
105*2264Sjacobs 	NSL_ERR_UNKNOWN_PRINTER	= 5,	/* Unknown Printer object */
106*2264Sjacobs 	NSL_ERR_CREDENTIALS	= 6,	/* LDAP credentials invalid */
107*2264Sjacobs 	NSL_ERR_CONNECT		= 7,	/* LDAP server connect failed */
108*2264Sjacobs 	NSL_ERR_BIND		= 8,	/* LDAP bind failed */
109*2264Sjacobs 	NSL_ERR_RENAME		= 9,	/* Object rename is not allowed */
110*2264Sjacobs 	NSL_ERR_KVP		= 10,	/* sun-printer-kvp not allowed */
111*2264Sjacobs 	NSL_ERR_BSDADDR		= 11,	/* sun-printer-bsdaddr not allowed */
112*2264Sjacobs 	NSL_ERR_PNAME		= 12,	/* printer-name not allowed */
113*2264Sjacobs 	NSL_ERR_MEMORY		= 13,	/* memory allocation failed */
114*2264Sjacobs 	NSL_ERR_MULTIOP		= 14,	/* Replace and delete operation */
115*2264Sjacobs 	NSL_ERR_NOTALLOWED	= 15,	/* KVP attribute not allowed */
116*2264Sjacobs 	NSL_ERROR		= -1	/* General error */
117*2264Sjacobs } NSL_RESULT;
118*2264Sjacobs 
119*2264Sjacobs 
120*2264Sjacobs /* LDAP bind password security type */
121*2264Sjacobs 
122*2264Sjacobs typedef enum NS_PASSWD_TYPE {
123*2264Sjacobs 	NS_PW_INSECURE = 0,
124*2264Sjacobs 	NS_PW_SECURE = 1
125*2264Sjacobs } NS_PASSWD_TYPE;
126*2264Sjacobs 
127*2264Sjacobs 
128*2264Sjacobs /*
129*2264Sjacobs  * Information needed to update a name service.
130*2264Sjacobs  * Currently only used for ldap.
131*2264Sjacobs  */
132*2264Sjacobs struct ns_cred {
133*2264Sjacobs 	char	*binddn;
134*2264Sjacobs 	char	*passwd;
135*2264Sjacobs 	char	*host;
136*2264Sjacobs 	int	port;			/* LDAP port, 0 = default */
137*2264Sjacobs 	NS_PASSWD_TYPE passwdType;	/* password security type */
138*2264Sjacobs 	uchar_t  *domainDN;		/* NS domain DN */
139*2264Sjacobs };
140*2264Sjacobs typedef struct ns_cred ns_cred_t;
141*2264Sjacobs 
142*2264Sjacobs /* LDAP specific NS Data */
143*2264Sjacobs 
144*2264Sjacobs typedef struct NS_LDAPDATA {
145*2264Sjacobs 	char **attrList;	/* list of user defined Key Value Pairs */
146*2264Sjacobs } NS_LDAPDATA;
147*2264Sjacobs 
148*2264Sjacobs /* Printer Object structure */
149*2264Sjacobs struct ns_printer {
150*2264Sjacobs 	char	*name;	 /* primary name of printer */
151*2264Sjacobs 	char	**aliases;	/* aliases for printer */
152*2264Sjacobs 	char	*source;	/* name service derived from */
153*2264Sjacobs 	ns_kvp_t  **attributes;  /* key/value pairs. */
154*2264Sjacobs 	ns_cred_t *cred;	 /* info to update name service */
155*2264Sjacobs 	void	*nsdata;	/* name service specific data */
156*2264Sjacobs };
157*2264Sjacobs typedef struct ns_printer ns_printer_t;
158*2264Sjacobs 
159*2264Sjacobs /* functions to get/put printer objects */
160*2264Sjacobs extern ns_printer_t *ns_printer_create(char *, char **, char *, ns_kvp_t **);
161*2264Sjacobs extern ns_printer_t *ns_printer_get_name(const char *, const char *);
162*2264Sjacobs extern ns_printer_t **ns_printer_get_list(const char *);
163*2264Sjacobs extern int	  ns_printer_put(const ns_printer_t *);
164*2264Sjacobs extern void	 ns_printer_destroy(ns_printer_t *);
165*2264Sjacobs 
166*2264Sjacobs extern int setprinterentry(int, char *);
167*2264Sjacobs extern int endprinterentry();
168*2264Sjacobs extern int getprinterentry(char *, int, char *);
169*2264Sjacobs extern int getprinterbyname(char *, char *, int, char *);
170*2264Sjacobs 
171*2264Sjacobs extern char *_cvt_printer_to_entry(ns_printer_t *, char *, int);
172*2264Sjacobs 
173*2264Sjacobs extern ns_printer_t *_cvt_nss_entry_to_printer(char *, char *);
174*2264Sjacobs extern ns_printer_t *posix_name(const char *);
175*2264Sjacobs 
176*2264Sjacobs 
177*2264Sjacobs 
178*2264Sjacobs /* functions to manipulate key/value pairs */
179*2264Sjacobs extern void	 *ns_get_value(const char *, const ns_printer_t *);
180*2264Sjacobs extern char	 *ns_get_value_string(const char *, const ns_printer_t *);
181*2264Sjacobs extern int	  ns_set_value(const char *, const void *, ns_printer_t *);
182*2264Sjacobs extern int	  ns_set_value_from_string(const char *, const char *,
183*2264Sjacobs 						ns_printer_t *);
184*2264Sjacobs extern ns_kvp_t	*ns_kvp_create(const char *, const char *);
185*2264Sjacobs 
186*2264Sjacobs /* for BSD bindings only */
187*2264Sjacobs extern ns_bsd_addr_t *ns_bsd_addr_get_default();
188*2264Sjacobs extern ns_bsd_addr_t *ns_bsd_addr_get_name(char *name);
189*2264Sjacobs extern ns_bsd_addr_t **ns_bsd_addr_get_all(int);
190*2264Sjacobs extern ns_bsd_addr_t **ns_bsd_addr_get_list(int);
191*2264Sjacobs 
192*2264Sjacobs /* others */
193*2264Sjacobs extern int ns_printer_match_name(ns_printer_t *, const char *);
194*2264Sjacobs extern char *ns_printer_name_list(const ns_printer_t *);
195*2264Sjacobs extern char *value_to_string(const char *, void *);
196*2264Sjacobs extern void *string_to_value(const char *, char *);
197*2264Sjacobs extern char *normalize_ns_name(char *);
198*2264Sjacobs extern char *strncat_escaped(char *, char *, int, char *);
199*2264Sjacobs 
200*2264Sjacobs 
201*2264Sjacobs 
202*2264Sjacobs #ifdef __cplusplus
203*2264Sjacobs }
204*2264Sjacobs #endif
205*2264Sjacobs 
206*2264Sjacobs #endif /* _NS_H */
207