17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5cb5caa98Sdjl * Common Development and Distribution License (the "License"). 6cb5caa98Sdjl * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22dd1104fbSMichen Chang * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _NS_CACHE_DOOR_H 277c478bd9Sstevel@tonic-gate #define _NS_CACHE_DOOR_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Definitions for client side of doors-based ldap caching 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <netdb.h> 387c478bd9Sstevel@tonic-gate #include <netinet/in.h> 397c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 407c478bd9Sstevel@tonic-gate #include <sys/socket.h> 417c478bd9Sstevel@tonic-gate #include <grp.h> 427c478bd9Sstevel@tonic-gate #include <pwd.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * statistics & control structure 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate typedef struct ldap_stat { 507c478bd9Sstevel@tonic-gate int ldap_numbercalls; /* number of times called */ 517c478bd9Sstevel@tonic-gate int ldap_ttl; /* time to live for positive entries */ 527c478bd9Sstevel@tonic-gate } ldap_stat_t; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Structure used to transfer arrays of strings. 577c478bd9Sstevel@tonic-gate * Buffer format: 587c478bd9Sstevel@tonic-gate * count 597c478bd9Sstevel@tonic-gate * array of offsets from start of buffer 607c478bd9Sstevel@tonic-gate * array of characters of strings 617c478bd9Sstevel@tonic-gate * charp = buf + ldap_offsets[n]; 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate typedef struct ldap_strlist { 657c478bd9Sstevel@tonic-gate int ldap_count; /* number of strings */ 667c478bd9Sstevel@tonic-gate int ldap_offsets[1]; /* array of offsets */ 677c478bd9Sstevel@tonic-gate } ldap_strlist_t; 687c478bd9Sstevel@tonic-gate 69e1dd0a2fSth /* 70e1dd0a2fSth * Structure used to request/inform config and server status changes. 71e1dd0a2fSth */ 72e1dd0a2fSth 73e1dd0a2fSth typedef struct ldap_get_chg_cookie { 74e1dd0a2fSth pid_t mgr_pid; /* current process id of ldap_cachemgr */ 75e1dd0a2fSth uint32_t seq_num; /* current config sequence number */ 76e1dd0a2fSth } ldap_get_chg_cookie_t; 77e1dd0a2fSth 78e1dd0a2fSth typedef struct ldap_get_change { 79e1dd0a2fSth uint32_t op; /* start or stop */ 80e1dd0a2fSth ldap_get_chg_cookie_t cookie; /* get status change cookie */ 81e1dd0a2fSth } ldap_get_change_t; 82e1dd0a2fSth 83e1dd0a2fSth typedef struct ldap_get_change_out { 84e1dd0a2fSth uint32_t type; /* config change or server change */ 85e1dd0a2fSth ldap_get_chg_cookie_t cookie; /* get status change cookie */ 86e1dd0a2fSth uint32_t server_count; /* if server change: num of servers */ 87e1dd0a2fSth uint32_t data_size; /* if server change: size of data */ 88e1dd0a2fSth char data[sizeof (int)]; /* real size is data_size */ 89e1dd0a2fSth } ldap_get_change_out_t; 90e1dd0a2fSth 91e1dd0a2fSth typedef struct ldap_config_out { 92e1dd0a2fSth ldap_get_chg_cookie_t cookie; /* get status change cookie */ 93e1dd0a2fSth uint32_t data_size; /* length of the config string */ 94e1dd0a2fSth char config_str[sizeof (int)]; /* real size is data_size */ 95e1dd0a2fSth } ldap_config_out_t; 96e1dd0a2fSth 97dd1104fbSMichen Chang typedef struct ldap_admin_mod_result { 98dd1104fbSMichen Chang uint32_t ns_err; /* ns_ldap error code */ 99dd1104fbSMichen Chang uint32_t status; /* error status */ 100dd1104fbSMichen Chang uint32_t msg_size; /* length of error message */ 101dd1104fbSMichen Chang char msg[sizeof (int)]; /* real size is msg_size */ 102dd1104fbSMichen Chang } ldap_admin_mod_result_t; 103dd1104fbSMichen Chang 1047c478bd9Sstevel@tonic-gate /* 1057c478bd9Sstevel@tonic-gate * structure returned by server for all calls 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #define BUFFERSIZE 8192 1097c478bd9Sstevel@tonic-gate #define OFFSET 36 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate typedef struct { 1127c478bd9Sstevel@tonic-gate int ldap_bufferbytesused; 1137c478bd9Sstevel@tonic-gate int ldap_return_code; 1147c478bd9Sstevel@tonic-gate int ldap_errno; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate union { 1177c478bd9Sstevel@tonic-gate char config[BUFFERSIZE - OFFSET]; /* V1 Config */ 1187c478bd9Sstevel@tonic-gate ldap_stat_t stats; 1197c478bd9Sstevel@tonic-gate char buff[4]; 1207c478bd9Sstevel@tonic-gate char ber[4]; /* BER/DER encoded packet */ 1217c478bd9Sstevel@tonic-gate ldap_strlist_t strlist; 122e1dd0a2fSth ldap_config_out_t config_str; 123e1dd0a2fSth ldap_get_change_out_t changes; 124dd1104fbSMichen Chang ldap_admin_mod_result_t admin_result; 1257c478bd9Sstevel@tonic-gate } ldap_u; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate } ldap_return_t; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * calls look like this 1317c478bd9Sstevel@tonic-gate */ 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate typedef struct { 1347c478bd9Sstevel@tonic-gate int ldap_callnumber; 1357c478bd9Sstevel@tonic-gate union { 1367c478bd9Sstevel@tonic-gate uid_t uid; 1377c478bd9Sstevel@tonic-gate gid_t gid; 1387c478bd9Sstevel@tonic-gate char domainname[sizeof (int)]; /* size is indeterminate */ 1397c478bd9Sstevel@tonic-gate struct { 1407c478bd9Sstevel@tonic-gate int a_type; 1417c478bd9Sstevel@tonic-gate int a_length; 1427c478bd9Sstevel@tonic-gate char a_data[sizeof (int)]; 1437c478bd9Sstevel@tonic-gate } addr; 1447c478bd9Sstevel@tonic-gate char servername[sizeof (int)]; /* Format: server:port */ 1457c478bd9Sstevel@tonic-gate ldap_strlist_t strlist; 146e1dd0a2fSth ldap_get_change_t get_change; 1477c478bd9Sstevel@tonic-gate } ldap_u; 1487c478bd9Sstevel@tonic-gate } ldap_call_t; 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * how the client views the call process 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate typedef union { 1547c478bd9Sstevel@tonic-gate ldap_call_t ldap_call; 1557c478bd9Sstevel@tonic-gate ldap_return_t ldap_ret; 1567c478bd9Sstevel@tonic-gate char ldap_buff[sizeof (int)]; 1577c478bd9Sstevel@tonic-gate } ldap_data_t; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* Version 1 Cache Manager calls */ 1607c478bd9Sstevel@tonic-gate /* Cache manager ping */ 1617c478bd9Sstevel@tonic-gate #define NULLCALL 0 1627c478bd9Sstevel@tonic-gate /* NativeLDAP I Get Config */ 1637c478bd9Sstevel@tonic-gate #define GETLDAPCONFIG 1 1647c478bd9Sstevel@tonic-gate #define GETLDAPCONFIGV1 1 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * administrative calls 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #define KILLSERVER 7 1717c478bd9Sstevel@tonic-gate #define GETADMIN 8 1727c478bd9Sstevel@tonic-gate #define SETADMIN 9 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * debug levels 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #define DBG_OFF 0 1797c478bd9Sstevel@tonic-gate #define DBG_CANT_FIND 1 1807c478bd9Sstevel@tonic-gate #define DBG_NETLOOKUPS 2 1817c478bd9Sstevel@tonic-gate #define DBG_SERVER_LIST_REFRESH 3 /* debug server list refresh */ 1827c478bd9Sstevel@tonic-gate #define DBG_PROFILE_REFRESH 4 /* debug profile TTL/refresh */ 1837c478bd9Sstevel@tonic-gate #define DBG_ALL 6 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* Version 2 Cache Manager calls */ 1867c478bd9Sstevel@tonic-gate /* NativeLDAP II Get Server and RootDSE Info */ 1877c478bd9Sstevel@tonic-gate #define GETLDAPSERVER 21 1887c478bd9Sstevel@tonic-gate /* NativeLDAP II Get cached data */ 1897c478bd9Sstevel@tonic-gate #define GETCACHE 22 1907c478bd9Sstevel@tonic-gate /* NativeLDAP II Set cached data */ 1917c478bd9Sstevel@tonic-gate #define SETCACHE 23 1927c478bd9Sstevel@tonic-gate /* NativeLDAP II get cache data statistics */ 1937c478bd9Sstevel@tonic-gate #define GETCACHESTAT 24 194e1dd0a2fSth /* Configuration change or server status change notification */ 195e1dd0a2fSth #define GETSTATUSCHANGE 25 196dd1104fbSMichen Chang /* perform admin modify via ldap_cachemgr */ 197dd1104fbSMichen Chang #define ADMINMODIFY 26 198*b57459abSJulian Pullen /* get admin credentials for shadow lookups */ 199*b57459abSJulian Pullen #define GETADMINCRED 27 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * GETLDAPSERVER request flags 2037c478bd9Sstevel@tonic-gate */ 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #define NS_CACHE_NEW "0" 2067c478bd9Sstevel@tonic-gate #define NS_CACHE_NORESP "1" 2077c478bd9Sstevel@tonic-gate #define NS_CACHE_NEXT "2" 2087c478bd9Sstevel@tonic-gate #define NS_CACHE_WRITE "3" 209cb5caa98Sdjl #define NS_CACHE_ADDR_HOSTNAME "H" 210cb5caa98Sdjl #define NS_CACHE_ADDR_IP "I" 2117c478bd9Sstevel@tonic-gate 212e1dd0a2fSth /* 213e1dd0a2fSth * GETSTATUSCHANGE operation: start or stop 214e1dd0a2fSth */ 215e1dd0a2fSth #define NS_STATUS_CHANGE_OP_START 1 216e1dd0a2fSth #define NS_STATUS_CHANGE_OP_STOP 2 217e1dd0a2fSth 218e1dd0a2fSth /* 219e1dd0a2fSth * GETSTATUSCHANGE change type: config or server 220e1dd0a2fSth */ 221e1dd0a2fSth #define NS_STATUS_CHANGE_TYPE_CONFIG 1 222e1dd0a2fSth #define NS_STATUS_CHANGE_TYPE_SERVER 2 223e1dd0a2fSth 224e1dd0a2fSth /* 225e1dd0a2fSth * Server status change 226e1dd0a2fSth */ 227e1dd0a2fSth #define NS_SERVER_CHANGE_UP "0" /* mapped to NS_SERVER_UP */ 228e1dd0a2fSth #define NS_SERVER_CHANGE_DOWN "1" /* mapped to NS_SERVER_DOWN */ 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * GETCACHE/SETCACHE data flags 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate #define NS_CACHE_DN2DOMAIN "DM" 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* 2357c478bd9Sstevel@tonic-gate * Max size name we allow to be passed to avoid 2367c478bd9Sstevel@tonic-gate * buffer overflow problems 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate #define LDAPMAXNAMELEN 255 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /* 2417c478bd9Sstevel@tonic-gate * defines for client-server interaction 2427c478bd9Sstevel@tonic-gate */ 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate #define LDAP_CACHE_DOOR_VERSION 1 2457c478bd9Sstevel@tonic-gate #define LDAP_CACHE_DOOR "/var/run/ldap_cache_door" 2467c478bd9Sstevel@tonic-gate #define LDAP_CACHE_DOOR_COOKIE ((void*)(0xdeadbeef^LDAP_CACHE_DOOR_VERSION)) 2477c478bd9Sstevel@tonic-gate #define UPDATE_DOOR_COOKIE ((void*)(0xdeadcafe) 2487c478bd9Sstevel@tonic-gate 249e1dd0a2fSth #define NS_CACHE_SUCCESS 0 250e1dd0a2fSth #define NS_CACHE_NOTFOUND -1 251e1dd0a2fSth #define NS_CACHE_CREDERROR -2 252e1dd0a2fSth #define NS_CACHE_SERVERERROR -3 253e1dd0a2fSth #define NS_CACHE_NOSERVER -4 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate int 2567c478bd9Sstevel@tonic-gate __ns_ldap_trydoorcall(ldap_data_t **dptr, int *ndata, int *adata); 257e1dd0a2fSth int 258e1dd0a2fSth __ns_ldap_trydoorcall_getfd(); 259e1dd0a2fSth int 260e1dd0a2fSth __ns_ldap_trydoorcall_send(ldap_data_t **dptr, int *ndata, int *adata); 261e1dd0a2fSth void 262e1dd0a2fSth __ns_ldap_doorfd_close(); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate #endif 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate #endif /* _NS_CACHE_DOOR_H */ 270