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