mmlib/mmat: replace some variables by literal constants
[mmondor.git] / mmsoftware / mmlib / mmreadcfg.h
CommitLineData
b232bd02 1/* $Id: mmreadcfg.h,v 1.10 2007/12/05 23:47:56 mmondor Exp $ */
47071c2b
MM
2
3/*
d4aaa170 4 * Copyright (C) 1991-2004, Matthew Mondor
47071c2b
MM
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
d4aaa170 17 * This product includes software developed by Matthew Mondor.
47071c2b
MM
18 * 4. The name of Matthew Mondor may not be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission.
d4aaa170
MM
21 * 5. Redistribution of source code may not be released under the terms of
22 * any GNU Public License derivate.
47071c2b
MM
23 *
24 * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36
37
38
39#ifndef MMREADCFG_H
40#define MMREADCFG_H
41
42
43
44
45#include <sys/types.h>
46#include <pwd.h>
47#include <grp.h>
b232bd02 48#include <stdbool.h>
47071c2b
MM
49
50#include <mmtypes.h>
13794002 51#include <mmhash.h>
47071c2b
MM
52
53
54
55
56/* Definitions for CfgArg CA_Type */
57#define CAT_STR 1 /* One string, quoted if spaces */
13794002 58#define CAT_VAL 2 /* A signed number (long) */
47071c2b
MM
59#define CAT_BOOL 3 /* A boolean value (TRUE or FALSE) */
60#define CAT_END 0 /* End of options list */
61
13794002
MM
62/* Definitions for CfgArg CA_Flags */
63#define CAF_NONE 0
64#define CAF_REQUIRED (1<<0)
65#define CAF_TOUCHED (1<<1)
66
47071c2b 67/* Definitions for CfgResult CR_Err */
f36e2a66
MM
68enum cre {
69 CRE_UNKNOWN = 0,
70 CRE_NOT_FOUND,
13794002 71 CRE_OUT_OF_MEM,
f36e2a66
MM
72 CRE_ILLEGAL_KEYWD,
73 CRE_STR_TOO_LONG,
74 CRE_STR_TOO_SHORT,
75 CRE_VAL_TOO_HIGH,
76 CRE_VAL_TOO_LOW,
77 CRE_NOT_BOOLEAN,
78 CRE_REQUIRED_KEYWD,
79 CRE_MULT_DEF_KEYWD,
80 CRE_KEYWD_TOO_LONG,
81 CRE_UNMATCHED_QUOTE,
82 CRE_NO_KEYWD_DATA,
13794002 83 CRE_UNEXPECTED_EOF,
f36e2a66
MM
84 CRE_MAX
85};
47071c2b 86
13794002
MM
87/* Maximum allowed length for a keyword, including NIL */
88#define CKW_MAX 32
89#define CKD_MAX 256
47071c2b
MM
90
91
92
93
94/* ReadCfg needed structures */
95typedef struct CfgArg
96{
13794002
MM
97 int CA_Type, CA_Flags;
98 long CA_Min, CA_Max;
99 const char *CA_Keyword;
47071c2b 100 void *CA_Data;
f36e2a66 101} carg_t;
47071c2b
MM
102
103typedef struct CfgResult
104{
13794002
MM
105 carg_t *CR_Keyword;
106 int CR_Err, CR_Line;
107 char CR_Data[CKD_MAX];
f36e2a66 108} cres_t;
47071c2b
MM
109
110typedef struct CMap
111{
13794002 112 const char *CM_Str;
47071c2b 113 long CM_Val;
f36e2a66 114} cmap_t;
47071c2b 115
13794002
MM
116struct CNode
117{
118 hashnode_t node;
119 char keyword[CKW_MAX];
120 carg_t *args;
121};
47071c2b
MM
122
123
124
0ac96f2e 125
f36e2a66 126extern const char *const mmreadcfg_strings[];
47071c2b 127
13794002 128#define mmreadcfg_strerr(a) (mmreadcfg_strings[(enum cre)(a)])
47071c2b
MM
129
130
131
0ac96f2e 132
c0d58fca 133extern bool mmreadcfg(cres_t *, carg_t *, const char *);
5c25ad0b 134extern bool mmmapstring(const cmap_t *, const char *, long *);
c0d58fca
MM
135extern gid_t * mmgetgidarray(int *, const char *);
136extern gid_t * mmfreegidarray(gid_t *);
137extern uid_t mmgetuid(const char *);
138extern gid_t mmgetgid(const char *);
139extern bool mmdropprivs(uid_t, gid_t *, int);
47071c2b
MM
140
141
47071c2b
MM
142
143
144#endif