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