1355b4669Sjacobs /* 2355b4669Sjacobs * CDDL HEADER START 3355b4669Sjacobs * 4355b4669Sjacobs * The contents of this file are subject to the terms of the 5*36e852a1SRaja Andra * Common Development and Distribution License (the "License"). 6*36e852a1SRaja Andra * You may not use this file except in compliance with the License. 7355b4669Sjacobs * 8355b4669Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9355b4669Sjacobs * or http://www.opensolaris.org/os/licensing. 10355b4669Sjacobs * See the License for the specific language governing permissions 11355b4669Sjacobs * and limitations under the License. 12355b4669Sjacobs * 13355b4669Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 14355b4669Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15355b4669Sjacobs * If applicable, add the following below this CDDL HEADER, with the 16355b4669Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 17355b4669Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 18355b4669Sjacobs * 19355b4669Sjacobs * CDDL HEADER END 20355b4669Sjacobs */ 21355b4669Sjacobs /* 22*36e852a1SRaja Andra * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23355b4669Sjacobs * Use is subject to license terms. 24355b4669Sjacobs */ 25355b4669Sjacobs 26355b4669Sjacobs #ifndef _NS_H 27355b4669Sjacobs #define _NS_H 28355b4669Sjacobs 29355b4669Sjacobs #ifdef __cplusplus 30355b4669Sjacobs extern "C" { 31355b4669Sjacobs #endif 32355b4669Sjacobs 33355b4669Sjacobs /* 34355b4669Sjacobs * Name Service Common Keys/types for lookup 35355b4669Sjacobs */ 36355b4669Sjacobs #define NS_KEY_BSDADDR "bsdaddr" 37355b4669Sjacobs #define NS_KEY_USE "use" 38355b4669Sjacobs #define NS_KEY_ALL "all" 39355b4669Sjacobs #define NS_KEY_GROUP "group" 40355b4669Sjacobs #define NS_KEY_LIST "list" 41355b4669Sjacobs 42355b4669Sjacobs #define NS_KEY_PRINTER_TYPE "printer-type" 43355b4669Sjacobs #define NS_KEY_DESCRIPTION "description" 44355b4669Sjacobs 45355b4669Sjacobs /* 46355b4669Sjacobs * Name Service reserved names for lookup 47355b4669Sjacobs */ 48355b4669Sjacobs #define NS_NAME_DEFAULT "_default" 49355b4669Sjacobs #define NS_NAME_ALL "_all" 50355b4669Sjacobs 51355b4669Sjacobs /* 52355b4669Sjacobs * Name Services supported 53355b4669Sjacobs */ 54355b4669Sjacobs #define NS_SVC_USER "user" 55355b4669Sjacobs #define NS_SVC_PRINTCAP "printcap" 56355b4669Sjacobs #define NS_SVC_ETC "etc" 57355b4669Sjacobs #define NS_SVC_NIS "nis" 58355b4669Sjacobs #define NS_SVC_LDAP "ldap" 59355b4669Sjacobs 60355b4669Sjacobs /* 61355b4669Sjacobs * Known Protocol Extensions 62355b4669Sjacobs */ 63355b4669Sjacobs #define NS_EXT_SOLARIS "solaris" 64355b4669Sjacobs #define NS_EXT_GENERIC "extensions" /* same as SOLARIS */ 65355b4669Sjacobs #define NS_EXT_HPUX "hpux" 66355b4669Sjacobs #define NS_EXT_DEC "dec" 67355b4669Sjacobs 68355b4669Sjacobs /* 69355b4669Sjacobs * get unique or full list of printer bindings 70355b4669Sjacobs */ 71355b4669Sjacobs #define NOTUNIQUE 0 72355b4669Sjacobs #define UNIQUE 1 73355b4669Sjacobs #define LOCAL_UNIQUE 2 /* include alias names */ 74355b4669Sjacobs 75355b4669Sjacobs /* BSD binding address structure */ 76355b4669Sjacobs struct ns_bsd_addr { 77355b4669Sjacobs char *server; /* server name */ 78355b4669Sjacobs char *printer; /* printer name or NULL */ 79355b4669Sjacobs char *extension; /* RFC-1179 conformance */ 80355b4669Sjacobs char *pname; /* Local printer name */ 81355b4669Sjacobs }; 82355b4669Sjacobs typedef struct ns_bsd_addr ns_bsd_addr_t; 83355b4669Sjacobs 84355b4669Sjacobs /* Key/Value pair structure */ 85355b4669Sjacobs struct ns_kvp { 86355b4669Sjacobs char *key; /* key */ 87355b4669Sjacobs char *value; /* value string */ 88355b4669Sjacobs }; 89355b4669Sjacobs typedef struct ns_kvp ns_kvp_t; 90355b4669Sjacobs 91355b4669Sjacobs 92355b4669Sjacobs /* LDAP specific result codes */ 93355b4669Sjacobs 94355b4669Sjacobs typedef enum NSL_RESULT 95355b4669Sjacobs { 96355b4669Sjacobs NSL_OK = 0, /* Operation successful */ 97355b4669Sjacobs NSL_ERR_INTERNAL = 1, /* Internal coding Error */ 98355b4669Sjacobs NSL_ERR_ADD_FAILED = 2, /* LDAP add failed */ 99355b4669Sjacobs NSL_ERR_MOD_FAILED = 3, /* LDAP modify failed */ 100355b4669Sjacobs NSL_ERR_DEL_FAILED = 4, /* LDAP delete failed */ 101355b4669Sjacobs NSL_ERR_UNKNOWN_PRINTER = 5, /* Unknown Printer object */ 102355b4669Sjacobs NSL_ERR_CREDENTIALS = 6, /* LDAP credentials invalid */ 103355b4669Sjacobs NSL_ERR_CONNECT = 7, /* LDAP server connect failed */ 104355b4669Sjacobs NSL_ERR_BIND = 8, /* LDAP bind failed */ 105355b4669Sjacobs NSL_ERR_RENAME = 9, /* Object rename is not allowed */ 106355b4669Sjacobs NSL_ERR_KVP = 10, /* sun-printer-kvp not allowed */ 107355b4669Sjacobs NSL_ERR_BSDADDR = 11, /* sun-printer-bsdaddr not allowed */ 108355b4669Sjacobs NSL_ERR_PNAME = 12, /* printer-name not allowed */ 109355b4669Sjacobs NSL_ERR_MEMORY = 13, /* memory allocation failed */ 110355b4669Sjacobs NSL_ERR_MULTIOP = 14, /* Replace and delete operation */ 111355b4669Sjacobs NSL_ERR_NOTALLOWED = 15, /* KVP attribute not allowed */ 112355b4669Sjacobs NSL_ERROR = -1 /* General error */ 113355b4669Sjacobs } NSL_RESULT; 114355b4669Sjacobs 115355b4669Sjacobs 116355b4669Sjacobs /* LDAP bind password security type */ 117355b4669Sjacobs 118355b4669Sjacobs typedef enum NS_PASSWD_TYPE { 119355b4669Sjacobs NS_PW_INSECURE = 0, 120355b4669Sjacobs NS_PW_SECURE = 1 121355b4669Sjacobs } NS_PASSWD_TYPE; 122355b4669Sjacobs 123355b4669Sjacobs 124355b4669Sjacobs /* 125355b4669Sjacobs * Information needed to update a name service. 126355b4669Sjacobs * Currently only used for ldap. 127355b4669Sjacobs */ 128355b4669Sjacobs struct ns_cred { 129355b4669Sjacobs char *binddn; 130355b4669Sjacobs char *passwd; 131355b4669Sjacobs char *host; 132355b4669Sjacobs int port; /* LDAP port, 0 = default */ 133355b4669Sjacobs NS_PASSWD_TYPE passwdType; /* password security type */ 134355b4669Sjacobs uchar_t *domainDN; /* NS domain DN */ 135355b4669Sjacobs }; 136355b4669Sjacobs typedef struct ns_cred ns_cred_t; 137355b4669Sjacobs 138355b4669Sjacobs /* LDAP specific NS Data */ 139355b4669Sjacobs 140355b4669Sjacobs typedef struct NS_LDAPDATA { 141355b4669Sjacobs char **attrList; /* list of user defined Key Value Pairs */ 142355b4669Sjacobs } NS_LDAPDATA; 143355b4669Sjacobs 144355b4669Sjacobs /* Printer Object structure */ 145355b4669Sjacobs struct ns_printer { 146355b4669Sjacobs char *name; /* primary name of printer */ 147355b4669Sjacobs char **aliases; /* aliases for printer */ 148355b4669Sjacobs char *source; /* name service derived from */ 149355b4669Sjacobs ns_kvp_t **attributes; /* key/value pairs. */ 150355b4669Sjacobs ns_cred_t *cred; /* info to update name service */ 151355b4669Sjacobs void *nsdata; /* name service specific data */ 152355b4669Sjacobs }; 153355b4669Sjacobs typedef struct ns_printer ns_printer_t; 154355b4669Sjacobs 155355b4669Sjacobs /* functions to get/put printer objects */ 156355b4669Sjacobs extern ns_printer_t *ns_printer_create(char *, char **, char *, ns_kvp_t **); 157355b4669Sjacobs extern ns_printer_t *ns_printer_get_name(const char *, const char *); 158355b4669Sjacobs extern ns_printer_t **ns_printer_get_list(const char *); 159355b4669Sjacobs extern int ns_printer_put(const ns_printer_t *); 160355b4669Sjacobs extern void ns_printer_destroy(ns_printer_t *); 161355b4669Sjacobs 162355b4669Sjacobs extern int setprinterentry(int, char *); 163355b4669Sjacobs extern int endprinterentry(); 164355b4669Sjacobs extern int getprinterentry(char *, int, char *); 165355b4669Sjacobs extern int getprinterbyname(char *, char *, int, char *); 166355b4669Sjacobs 167355b4669Sjacobs extern char *_cvt_printer_to_entry(ns_printer_t *, char *, int); 168355b4669Sjacobs 169355b4669Sjacobs extern ns_printer_t *_cvt_nss_entry_to_printer(char *, char *); 170355b4669Sjacobs extern ns_printer_t *posix_name(const char *); 171355b4669Sjacobs 172355b4669Sjacobs 173355b4669Sjacobs 174355b4669Sjacobs /* functions to manipulate key/value pairs */ 175355b4669Sjacobs extern void *ns_get_value(const char *, const ns_printer_t *); 176355b4669Sjacobs extern char *ns_get_value_string(const char *, const ns_printer_t *); 177355b4669Sjacobs extern int ns_set_value(const char *, const void *, ns_printer_t *); 178355b4669Sjacobs extern int ns_set_value_from_string(const char *, const char *, 179355b4669Sjacobs ns_printer_t *); 180355b4669Sjacobs extern ns_kvp_t *ns_kvp_create(const char *, const char *); 181355b4669Sjacobs 182355b4669Sjacobs /* for BSD bindings only */ 183355b4669Sjacobs extern ns_bsd_addr_t *ns_bsd_addr_get_default(); 184355b4669Sjacobs extern ns_bsd_addr_t *ns_bsd_addr_get_name(char *name); 185355b4669Sjacobs extern ns_bsd_addr_t **ns_bsd_addr_get_all(int); 186355b4669Sjacobs extern ns_bsd_addr_t **ns_bsd_addr_get_list(int); 187355b4669Sjacobs 188355b4669Sjacobs /* others */ 189355b4669Sjacobs extern int ns_printer_match_name(ns_printer_t *, const char *); 190355b4669Sjacobs extern char *ns_printer_name_list(const ns_printer_t *); 191355b4669Sjacobs extern char *value_to_string(const char *, void *); 192355b4669Sjacobs extern void *string_to_value(const char *, char *); 193355b4669Sjacobs extern char *normalize_ns_name(char *); 194355b4669Sjacobs extern char *strncat_escaped(char *, char *, int, char *); 195355b4669Sjacobs 196355b4669Sjacobs 197355b4669Sjacobs 198355b4669Sjacobs #ifdef __cplusplus 199355b4669Sjacobs } 200355b4669Sjacobs #endif 201355b4669Sjacobs 202355b4669Sjacobs #endif /* _NS_H */ 203