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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_CACHEMGR_H
27 #define	_CACHEMGR_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <thread.h>
36 #include <synch.h>
37 #include <unistd.h>
38 #include <procfs.h>
39 #include "ns_sldap.h"
40 #include "ns_internal.h"
41 #include "ns_cache_door.h"
42 #include "cachemgr_door.h"
43 
44 #define	LOGFILE		"/var/ldap/cachemgr.log"
45 #define	KILLCACHEMGR	"/var/lib/ldap/ldap_cachemgr -K"
46 #define	MAXBITSIZE	30
47 #define	MAXDEBUG	DBG_ALL
48 #define	DEFAULTTTL	3600		/* 1 hour */
49 
50 typedef	union {
51 	ldap_data_t	data;
52 	char		space[BUFFERSIZE];
53 } dataunion;
54 
55 /*
56  * In ldap_cachemgr, it return -99 for some case, start with -100 here
57  */
58 typedef enum chg_error {
59 	CHG_SUCCESS  = 0,
60 	CHG_NO_MEMORY = -100,
61 	CHG_INVALID_PARAM = -101,
62 	CHG_NOT_FOUND_IN_WAITING_LIST = -102,
63 	CHG_EXCEED_MAX_THREADS = -103,
64 	CHG_NSCD_REPEATED_CALL = -104
65 } chg_error_t;
66 
67 typedef struct waiting_list {
68 	pid_t			pid;		/* pid of the door client */
69 	thread_t		tid;		/* thread id of the server */
70 						/* thread */
71 	int			cleanup;	/* 1: the thread will be */
72 						/* cleaned up */
73 	struct waiting_list	*prev;		/* previous node in the */
74 						/* linked list */
75 	struct waiting_list	*next;		/* next node in the linked */
76 						/* list */
77 } waiting_list_t;
78 
79 /*
80  * This structure contains the buffer for the chang data and a wating list to
81  * regester all the threads that handle GETSTATUSCHANGE START call and are
82  * waiting for the change notification.
83  * The notification threads save the data in the buffer then send broadcast
84  * to wake up the GETSTATUSCHANGE START threads to copy data to the stack and
85  * door_return().
86  */
87 typedef struct chg_info {
88 	mutex_t		chg_lock;	/* mutex for this data structure */
89 	cond_t		chg_cv;		/* cond var for synchronization */
90 	int		chg_wakeup;	/* flag used with chg_cv for */
91 					/* synchronization */
92 	waiting_list_t	*chg_w_first;	/* the head of the linked list */
93 	waiting_list_t	*chg_w_last;	/* the tail of the linked list */
94 	char		*chg_data;	/* the buffer for the change data */
95 	int		chg_data_size;	/* the size of the change data */
96 } chg_info_t;
97 
98 extern char *getcacheopt(char *s);
99 extern void logit(char *format, ...);
100 extern int load_admin_defaults(admin_t *ptr, int will_become_server);
101 extern int getldap_init(void);
102 extern void getldap_revalidate(void);
103 extern int getldap_uidkeepalive(int keep, int interval);
104 extern int getldap_invalidate(void);
105 extern void getldap_lookup(LineBuf *config_info, ldap_call_t *in);
106 extern void getldap_refresh(void);
107 extern int cachemgr_set_dl(admin_t *ptr, int value);
108 extern int cachemgr_set_ttl(ldap_stat_t *cache, char *name, int value);
109 extern int get_clearance(int callnumber);
110 extern int release_clearance(int callnumber);
111 #ifdef SLP
112 extern void discover();
113 #endif /* SLP */
114 extern void getldap_serverInfo_refresh(void);
115 extern void getldap_getserver(LineBuf *config_info, ldap_call_t *in);
116 extern void getldap_get_cacheData(LineBuf *config_info, ldap_call_t *in);
117 extern int getldap_set_cacheData(ldap_call_t *in);
118 extern void getldap_get_cacheStat(LineBuf *stat_info);
119 extern int is_called_from_nscd(pid_t pid); /* in cachemgr.c */
120 extern int chg_is_called_from_nscd_or_peruser_nscd(char *dc_str, pid_t *pidp);
121 extern void *chg_cleanup_waiting_threads(void *arg);
122 extern int chg_get_statusChange(LineBuf *config_info, ldap_call_t *in,
123 	pid_t nscd_pid);
124 extern int chg_notify_statusChange(char *str);
125 extern void chg_test_config_change(ns_config_t *new, int *change_status);
126 extern void chg_config_cookie_set(ldap_get_chg_cookie_t *cookie);
127 extern ldap_get_chg_cookie_t chg_config_cookie_get(void);
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* _CACHEMGR_H */
133