xref: /illumos-gate/usr/src/cmd/ldapcachemgr/cachemgr_parse.c (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  *   routine to parse configuration file
29  *
30  *   returns -1 on error, 0 on success.  Error messages to log.
31  */
32 
33 #include <errno.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <synch.h>
37 #include <sys/door.h>
38 #include <unistd.h>
39 #include "cachemgr.h"
40 
41 extern admin_t current_admin;
42 
43 static int
44 cachemgr_set_integer(int *addr, char *facility, char *cachename,
45 		int value, int min, int max)
46 {
47 	if (value < min || value > max) {
48 		logit("attempted to set value of %s for %s to %d, "
49 		    "which is not %d <= x <= %d\n",
50 		    facility, cachename, value, min, max);
51 
52 		return	(-1);
53 	}
54 
55 	if ((addr != NULL) && (*addr != value)) {
56 		if (current_admin.debug_level ||
57 			strcmp(facility, "Debug level") == 0)
58 			logit("Setting %s for %s to %d\n",
59 			    facility, cachename, value);
60 		*addr = value;
61 
62 		return (1);
63 	}
64 
65 	return (0);
66 }
67 
68 int
69 cachemgr_set_dl(admin_t *ptr, int value)
70 {
71 	if (ptr == NULL)
72 		return (-1);
73 
74 	return (cachemgr_set_integer(&(ptr->debug_level),
75 		"Debug level", "cachemgr", value, 0, MAXDEBUG));
76 }
77 
78 int
79 cachemgr_set_ttl(ldap_stat_t *cache, char *name, int value)
80 {
81 	int result;
82 
83 	if (cache == NULL)
84 		return (-1);
85 
86 	result = cachemgr_set_integer(&(cache->ldap_ttl),
87 		"Time to live", name,
88 		value, 0, 1<<MAXBITSIZE);
89 
90 	return (result);
91 }
92