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