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 /* 22*e1dd0a2fSth * Copyright 2008 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 #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * Definitions for client side of doors-based ldap caching 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <netdb.h> 407c478bd9Sstevel@tonic-gate #include <netinet/in.h> 417c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 427c478bd9Sstevel@tonic-gate #include <sys/socket.h> 437c478bd9Sstevel@tonic-gate #include <grp.h> 447c478bd9Sstevel@tonic-gate #include <pwd.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * statistics & control structure 497c478bd9Sstevel@tonic-gate */ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate typedef struct ldap_stat { 527c478bd9Sstevel@tonic-gate int ldap_numbercalls; /* number of times called */ 537c478bd9Sstevel@tonic-gate int ldap_ttl; /* time to live for positive entries */ 547c478bd9Sstevel@tonic-gate } ldap_stat_t; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* 587c478bd9Sstevel@tonic-gate * Structure used to transfer arrays of strings. 597c478bd9Sstevel@tonic-gate * Buffer format: 607c478bd9Sstevel@tonic-gate * count 617c478bd9Sstevel@tonic-gate * array of offsets from start of buffer 627c478bd9Sstevel@tonic-gate * array of characters of strings 637c478bd9Sstevel@tonic-gate * charp = buf + ldap_offsets[n]; 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate typedef struct ldap_strlist { 677c478bd9Sstevel@tonic-gate int ldap_count; /* number of strings */ 687c478bd9Sstevel@tonic-gate int ldap_offsets[1]; /* array of offsets */ 697c478bd9Sstevel@tonic-gate } ldap_strlist_t; 707c478bd9Sstevel@tonic-gate 71*e1dd0a2fSth /* 72*e1dd0a2fSth * Structure used to request/inform config and server status changes. 73*e1dd0a2fSth */ 74*e1dd0a2fSth 75*e1dd0a2fSth typedef struct ldap_get_chg_cookie { 76*e1dd0a2fSth pid_t mgr_pid; /* current process id of ldap_cachemgr */ 77*e1dd0a2fSth uint32_t seq_num; /* current config sequence number */ 78*e1dd0a2fSth } ldap_get_chg_cookie_t; 79*e1dd0a2fSth 80*e1dd0a2fSth typedef struct ldap_get_change { 81*e1dd0a2fSth uint32_t op; /* start or stop */ 82*e1dd0a2fSth ldap_get_chg_cookie_t cookie; /* get status change cookie */ 83*e1dd0a2fSth } ldap_get_change_t; 84*e1dd0a2fSth 85*e1dd0a2fSth typedef struct ldap_get_change_out { 86*e1dd0a2fSth uint32_t type; /* config change or server change */ 87*e1dd0a2fSth ldap_get_chg_cookie_t cookie; /* get status change cookie */ 88*e1dd0a2fSth uint32_t server_count; /* if server change: num of servers */ 89*e1dd0a2fSth uint32_t data_size; /* if server change: size of data */ 90*e1dd0a2fSth char data[sizeof (int)]; /* real size is data_size */ 91*e1dd0a2fSth } ldap_get_change_out_t; 92*e1dd0a2fSth 93*e1dd0a2fSth typedef struct ldap_config_out { 94*e1dd0a2fSth ldap_get_chg_cookie_t cookie; /* get status change cookie */ 95*e1dd0a2fSth uint32_t data_size; /* length of the config string */ 96*e1dd0a2fSth char config_str[sizeof (int)]; /* real size is data_size */ 97*e1dd0a2fSth } ldap_config_out_t; 98*e1dd0a2fSth 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * structure returned by server for all calls 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #define BUFFERSIZE 8192 1047c478bd9Sstevel@tonic-gate #define OFFSET 36 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate typedef struct { 1077c478bd9Sstevel@tonic-gate int ldap_bufferbytesused; 1087c478bd9Sstevel@tonic-gate int ldap_return_code; 1097c478bd9Sstevel@tonic-gate int ldap_errno; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate union { 1127c478bd9Sstevel@tonic-gate char config[BUFFERSIZE - OFFSET]; /* V1 Config */ 1137c478bd9Sstevel@tonic-gate ldap_stat_t stats; 1147c478bd9Sstevel@tonic-gate char buff[4]; 1157c478bd9Sstevel@tonic-gate char ber[4]; /* BER/DER encoded packet */ 1167c478bd9Sstevel@tonic-gate ldap_strlist_t strlist; 117*e1dd0a2fSth ldap_config_out_t config_str; 118*e1dd0a2fSth ldap_get_change_out_t changes; 1197c478bd9Sstevel@tonic-gate } ldap_u; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate } ldap_return_t; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * calls look like this 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate typedef struct { 1287c478bd9Sstevel@tonic-gate int ldap_callnumber; 1297c478bd9Sstevel@tonic-gate union { 1307c478bd9Sstevel@tonic-gate uid_t uid; 1317c478bd9Sstevel@tonic-gate gid_t gid; 1327c478bd9Sstevel@tonic-gate char domainname[sizeof (int)]; /* size is indeterminate */ 1337c478bd9Sstevel@tonic-gate struct { 1347c478bd9Sstevel@tonic-gate int a_type; 1357c478bd9Sstevel@tonic-gate int a_length; 1367c478bd9Sstevel@tonic-gate char a_data[sizeof (int)]; 1377c478bd9Sstevel@tonic-gate } addr; 1387c478bd9Sstevel@tonic-gate char servername[sizeof (int)]; /* Format: server:port */ 1397c478bd9Sstevel@tonic-gate ldap_strlist_t strlist; 140*e1dd0a2fSth ldap_get_change_t get_change; 1417c478bd9Sstevel@tonic-gate } ldap_u; 1427c478bd9Sstevel@tonic-gate } ldap_call_t; 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * how the client views the call process 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate typedef union { 1487c478bd9Sstevel@tonic-gate ldap_call_t ldap_call; 1497c478bd9Sstevel@tonic-gate ldap_return_t ldap_ret; 1507c478bd9Sstevel@tonic-gate char ldap_buff[sizeof (int)]; 1517c478bd9Sstevel@tonic-gate } ldap_data_t; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* Version 1 Cache Manager calls */ 1547c478bd9Sstevel@tonic-gate /* Cache manager ping */ 1557c478bd9Sstevel@tonic-gate #define NULLCALL 0 1567c478bd9Sstevel@tonic-gate /* NativeLDAP I Get Config */ 1577c478bd9Sstevel@tonic-gate #define GETLDAPCONFIG 1 1587c478bd9Sstevel@tonic-gate #define GETLDAPCONFIGV1 1 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * administrative calls 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #define KILLSERVER 7 1657c478bd9Sstevel@tonic-gate #define GETADMIN 8 1667c478bd9Sstevel@tonic-gate #define SETADMIN 9 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * debug levels 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #define DBG_OFF 0 1737c478bd9Sstevel@tonic-gate #define DBG_CANT_FIND 1 1747c478bd9Sstevel@tonic-gate #define DBG_NETLOOKUPS 2 1757c478bd9Sstevel@tonic-gate #define DBG_SERVER_LIST_REFRESH 3 /* debug server list refresh */ 1767c478bd9Sstevel@tonic-gate #define DBG_PROFILE_REFRESH 4 /* debug profile TTL/refresh */ 1777c478bd9Sstevel@tonic-gate #define DBG_ALL 6 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* Version 2 Cache Manager calls */ 1807c478bd9Sstevel@tonic-gate /* NativeLDAP II Get Server and RootDSE Info */ 1817c478bd9Sstevel@tonic-gate #define GETLDAPSERVER 21 1827c478bd9Sstevel@tonic-gate /* NativeLDAP II Get cached data */ 1837c478bd9Sstevel@tonic-gate #define GETCACHE 22 1847c478bd9Sstevel@tonic-gate /* NativeLDAP II Set cached data */ 1857c478bd9Sstevel@tonic-gate #define SETCACHE 23 1867c478bd9Sstevel@tonic-gate /* NativeLDAP II get cache data statistics */ 1877c478bd9Sstevel@tonic-gate #define GETCACHESTAT 24 188*e1dd0a2fSth /* Configuration change or server status change notification */ 189*e1dd0a2fSth #define GETSTATUSCHANGE 25 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * GETLDAPSERVER request flags 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #define NS_CACHE_NEW "0" 1967c478bd9Sstevel@tonic-gate #define NS_CACHE_NORESP "1" 1977c478bd9Sstevel@tonic-gate #define NS_CACHE_NEXT "2" 1987c478bd9Sstevel@tonic-gate #define NS_CACHE_WRITE "3" 199cb5caa98Sdjl #define NS_CACHE_ADDR_HOSTNAME "H" 200cb5caa98Sdjl #define NS_CACHE_ADDR_IP "I" 2017c478bd9Sstevel@tonic-gate 202*e1dd0a2fSth /* 203*e1dd0a2fSth * GETSTATUSCHANGE operation: start or stop 204*e1dd0a2fSth */ 205*e1dd0a2fSth #define NS_STATUS_CHANGE_OP_START 1 206*e1dd0a2fSth #define NS_STATUS_CHANGE_OP_STOP 2 207*e1dd0a2fSth 208*e1dd0a2fSth /* 209*e1dd0a2fSth * GETSTATUSCHANGE change type: config or server 210*e1dd0a2fSth */ 211*e1dd0a2fSth #define NS_STATUS_CHANGE_TYPE_CONFIG 1 212*e1dd0a2fSth #define NS_STATUS_CHANGE_TYPE_SERVER 2 213*e1dd0a2fSth 214*e1dd0a2fSth /* 215*e1dd0a2fSth * Server status change 216*e1dd0a2fSth */ 217*e1dd0a2fSth #define NS_SERVER_CHANGE_UP "0" /* mapped to NS_SERVER_UP */ 218*e1dd0a2fSth #define NS_SERVER_CHANGE_DOWN "1" /* mapped to NS_SERVER_DOWN */ 2197c478bd9Sstevel@tonic-gate /* 2207c478bd9Sstevel@tonic-gate * GETCACHE/SETCACHE data flags 2217c478bd9Sstevel@tonic-gate */ 2227c478bd9Sstevel@tonic-gate #define NS_CACHE_DN2DOMAIN "DM" 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * Max size name we allow to be passed to avoid 2267c478bd9Sstevel@tonic-gate * buffer overflow problems 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate #define LDAPMAXNAMELEN 255 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * defines for client-server interaction 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate #define LDAP_CACHE_DOOR_VERSION 1 2357c478bd9Sstevel@tonic-gate #define LDAP_CACHE_DOOR "/var/run/ldap_cache_door" 2367c478bd9Sstevel@tonic-gate #define LDAP_CACHE_DOOR_COOKIE ((void*)(0xdeadbeef^LDAP_CACHE_DOOR_VERSION)) 2377c478bd9Sstevel@tonic-gate #define UPDATE_DOOR_COOKIE ((void*)(0xdeadcafe) 2387c478bd9Sstevel@tonic-gate 239*e1dd0a2fSth #define NS_CACHE_SUCCESS 0 240*e1dd0a2fSth #define NS_CACHE_NOTFOUND -1 241*e1dd0a2fSth #define NS_CACHE_CREDERROR -2 242*e1dd0a2fSth #define NS_CACHE_SERVERERROR -3 243*e1dd0a2fSth #define NS_CACHE_NOSERVER -4 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate int 2467c478bd9Sstevel@tonic-gate __ns_ldap_trydoorcall(ldap_data_t **dptr, int *ndata, int *adata); 247*e1dd0a2fSth int 248*e1dd0a2fSth __ns_ldap_trydoorcall_getfd(); 249*e1dd0a2fSth int 250*e1dd0a2fSth __ns_ldap_trydoorcall_send(ldap_data_t **dptr, int *ndata, int *adata); 251*e1dd0a2fSth void 252*e1dd0a2fSth __ns_ldap_doorfd_close(); 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate #endif 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate #endif /* _NS_CACHE_DOOR_H */ 260