EPICS Base  7.0.6.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
asLib.h
1 /* asLib.h */
2 /*************************************************************************\
3 * Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne
4 * National Laboratory.
5 * Copyright (c) 2002 The Regents of the University of California, as
6 * Operator of Los Alamos National Laboratory.
7 * SPDX-License-Identifier: EPICS
8 * EPICS BASE is distributed subject to a Software License Agreement found
9 * in file LICENSE that is included with this distribution.
10 \*************************************************************************/
11 /* Author: Marty Kraimer Date: 09-27-93*/
12 
13 #ifndef INCasLibh
14 #define INCasLibh
15 
16 #include "libComAPI.h"
17 #include "ellLib.h"
18 #include "errMdef.h"
19 #include "errlog.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /* 0 - Use (unverified) client provided host name string.
26  * 1 - Use actual client IP address. HAG() are resolved to IPs at ACF load time.
27  */
28 LIBCOM_API extern int asCheckClientIP;
29 
30 typedef struct asgMember *ASMEMBERPVT;
31 typedef struct asgClient *ASCLIENTPVT;
32 typedef int (*ASINPUTFUNCPTR)(char *buf,int max_size);
33 typedef enum{
34  asClientCOAR /*Change of access rights*/
35  /*For now this is all*/
36 } asClientStatus;
37 
38 typedef void (*ASCLIENTCALLBACK) (ASCLIENTPVT,asClientStatus);
39 
40 /* The following routines are macros with the following syntax
41 long asCheckGet(ASCLIENTPVT asClientPvt);
42 long asCheckPut(ASCLIENTPVT asClientPvt);
43 */
44 #define asCheckGet(asClientPvt) \
45  (!asActive || ((asClientPvt)->access >= asREAD))
46 #define asCheckPut(asClientPvt) \
47  (!asActive || ((asClientPvt)->access >= asWRITE))
48 
49 /* More convenience macros
50 void *asTrapWriteWithData(ASCLIENTPVT asClientPvt,
51  const char *userid, const char *hostid, void *addr,
52  int dbrType, int no_elements, void *data);
53 void asTrapWriteAfter(ASCLIENTPVT asClientPvt);
54 */
55 #define asTrapWriteWithData(asClientPvt, user, host, addr, type, count, data) \
56  ((asActive && (asClientPvt)->trapMask) \
57  ? asTrapWriteBeforeWithData((user), (host), (addr), (type), (count), (data)) \
58  : 0)
59 #define asTrapWriteAfter(pvt) \
60  if (pvt) asTrapWriteAfterWrite(pvt)
61 
62 /* This macro is for backwards compatibility, upgrade any code
63  calling it to use asTrapWriteWithData() instead ASAP:
64 void *asTrapWriteBefore(ASCLIENTPVT asClientPvt,
65  const char *userid, const char *hostid, void *addr);
66 */
67 #define asTrapWriteBefore(asClientPvt, user, host, addr) \
68  asTrapWriteWithData(asClientPvt, user, host, addr, 0, 0, NULL)
69 
70 
71 LIBCOM_API long epicsStdCall asInitialize(ASINPUTFUNCPTR inputfunction);
72 LIBCOM_API long epicsStdCall asInitFile(
73  const char *filename,const char *substitutions);
74 LIBCOM_API long epicsStdCall asInitFP(FILE *fp,const char *substitutions);
75 LIBCOM_API long epicsStdCall asInitMem(const char *acf, const char *substitutions);
76 /*caller must provide permanent storage for asgName*/
77 LIBCOM_API long epicsStdCall asAddMember(
78  ASMEMBERPVT *asMemberPvt,const char *asgName);
79 LIBCOM_API long epicsStdCall asRemoveMember(ASMEMBERPVT *asMemberPvt);
80 /*caller must provide permanent storage for newAsgName*/
81 LIBCOM_API long epicsStdCall asChangeGroup(
82  ASMEMBERPVT *asMemberPvt,const char *newAsgName);
83 LIBCOM_API void * epicsStdCall asGetMemberPvt(ASMEMBERPVT asMemberPvt);
84 LIBCOM_API void epicsStdCall asPutMemberPvt(
85  ASMEMBERPVT asMemberPvt,void *userPvt);
86 /*client must provide permanent storage for user and host*/
87 LIBCOM_API long epicsStdCall asAddClient(
88  ASCLIENTPVT *asClientPvt,ASMEMBERPVT asMemberPvt,
89  int asl,const char *user,char *host);
90 /*client must provide permanent storage for user and host*/
91 LIBCOM_API long epicsStdCall asChangeClient(
92  ASCLIENTPVT asClientPvt,int asl,const char *user,char *host);
93 LIBCOM_API long epicsStdCall asRemoveClient(ASCLIENTPVT *asClientPvt);
94 LIBCOM_API void * epicsStdCall asGetClientPvt(ASCLIENTPVT asClientPvt);
95 LIBCOM_API void epicsStdCall asPutClientPvt(
96  ASCLIENTPVT asClientPvt,void *userPvt);
97 LIBCOM_API long epicsStdCall asRegisterClientCallback(
98  ASCLIENTPVT asClientPvt, ASCLIENTCALLBACK pcallback);
99 LIBCOM_API long epicsStdCall asComputeAllAsg(void);
100 /* following declared below after ASG is declared
101 LIBCOM_API long epicsStdCall asComputeAsg(ASG *pasg);
102 */
103 LIBCOM_API long epicsStdCall asCompute(ASCLIENTPVT asClientPvt);
104 LIBCOM_API int epicsStdCall asDump(
105  void (*memcallback)(ASMEMBERPVT,FILE *),
106  void (*clientcallback)(ASCLIENTPVT,FILE *),int verbose);
107 LIBCOM_API int epicsStdCall asDumpFP(FILE *fp,
108  void (*memcallback)(ASMEMBERPVT,FILE *),
109  void (*clientcallback)(ASCLIENTPVT,FILE *),int verbose);
110 LIBCOM_API int epicsStdCall asDumpUag(const char *uagname);
111 LIBCOM_API int epicsStdCall asDumpUagFP(FILE *fp,const char *uagname);
112 LIBCOM_API int epicsStdCall asDumpHag(const char *hagname);
113 LIBCOM_API int epicsStdCall asDumpHagFP(FILE *fp,const char *hagname);
114 LIBCOM_API int epicsStdCall asDumpRules(const char *asgname);
115 LIBCOM_API int epicsStdCall asDumpRulesFP(FILE *fp,const char *asgname);
116 LIBCOM_API int epicsStdCall asDumpMem(const char *asgname,
117  void (*memcallback)(ASMEMBERPVT,FILE *),int clients);
118 LIBCOM_API int epicsStdCall asDumpMemFP(FILE *fp,const char *asgname,
119  void (*memcallback)(ASMEMBERPVT,FILE *),int clients);
120 LIBCOM_API int epicsStdCall asDumpHash(void);
121 LIBCOM_API int epicsStdCall asDumpHashFP(FILE *fp);
122 
123 LIBCOM_API void * epicsStdCall asTrapWriteBeforeWithData(
124  const char *userid, const char *hostid, void *addr,
125  int dbrType, int no_elements, void *data);
126 
127 LIBCOM_API void epicsStdCall asTrapWriteAfterWrite(void *pvt);
128 
129 #define S_asLib_clientsExist (M_asLib| 1) /*Client Exists*/
130 #define S_asLib_noUag (M_asLib| 2) /*User Access Group does not exist*/
131 #define S_asLib_noHag (M_asLib| 3) /*Host Access Group does not exist*/
132 #define S_asLib_noAccess (M_asLib| 4) /*access security: no access allowed*/
133 #define S_asLib_noModify (M_asLib| 5) /*access security: no modification allowed*/
134 #define S_asLib_badConfig (M_asLib| 6) /*access security: bad configuration file*/
135 #define S_asLib_badCalc (M_asLib| 7) /*access security: bad calculation espression*/
136 #define S_asLib_dupAsg (M_asLib| 8) /*Duplicate Access Security Group */
137 #define S_asLib_InitFailed (M_asLib| 9) /*access security: Init failed*/
138 #define S_asLib_asNotActive (M_asLib|10) /*access security is not active*/
139 #define S_asLib_badMember (M_asLib|11) /*access security: bad ASMEMBERPVT*/
140 #define S_asLib_badClient (M_asLib|12) /*access security: bad ASCLIENTPVT*/
141 #define S_asLib_badAsg (M_asLib|13) /*access security: bad ASG*/
142 #define S_asLib_noMemory (M_asLib|14) /*access security: no Memory */
143 
144 /*Private declarations */
145 LIBCOM_API extern int asActive;
146 
147 /* definition of access rights*/
148 typedef enum{asNOACCESS,asREAD,asWRITE} asAccessRights;
149 
150 struct gphPvt;
151 
152 /*Base pointers for access security*/
153 typedef struct asBase{
154  ELLLIST uagList;
155  ELLLIST hagList;
156  ELLLIST asgList;
157  struct gphPvt *phash;
158 } ASBASE;
159 
160 LIBCOM_API extern volatile ASBASE *pasbase;
161 
162 /*Defs for User Access Groups*/
163 typedef struct{
164  ELLNODE node;
165  char *user;
166 } UAGNAME;
167 typedef struct uag{
168  ELLNODE node;
169  char *name;
170  ELLLIST list; /*list of UAGNAME*/
171 } UAG;
172 /*Defs for Host Access Groups*/
173 typedef struct{
174  ELLNODE node;
175  char host[1];
176 } HAGNAME;
177 typedef struct hag{
178  ELLNODE node;
179  char *name;
180  ELLLIST list; /*list of HAGNAME*/
181 } HAG;
182 /*Defs for Access SecurityGroups*/
183 typedef struct {
184  ELLNODE node;
185  UAG *puag;
186 }ASGUAG;
187 typedef struct {
188  ELLNODE node;
189  HAG *phag;
190 }ASGHAG;
191 #define AS_TRAP_WRITE 1
192 typedef struct{
193  ELLNODE node;
194  asAccessRights access;
195  int level;
196  unsigned long inpUsed; /*bitmap of which inputs are used*/
197  int result; /*Result of calc converted to TRUE/FALSE*/
198  char *calc;
199  void *rpcl;
200  ELLLIST uagList; /*List of ASGUAG*/
201  ELLLIST hagList; /*List of ASGHAG*/
202  int trapMask;
203 } ASGRULE;
204 typedef struct{
205  ELLNODE node;
206  char *inp;
207  void *capvt;
208  struct asg *pasg;
209  int inpIndex;
210 }ASGINP;
211 
212 typedef struct asg{
213  ELLNODE node;
214  char *name;
215  ELLLIST inpList;
216  ELLLIST ruleList;
217  ELLLIST memberList;
218  double *pavalue; /*pointer to array of input values*/
219  unsigned long inpBad; /*bitmap of which inputs are bad*/
220  unsigned long inpChanged; /*bitmap of inputs that changed*/
221 } ASG;
222 typedef struct asgMember {
223  ELLNODE node;
224  ASG *pasg;
225  ELLLIST clientList;
226  const char *asgName;
227  void *userPvt;
228 } ASGMEMBER;
229 
230 typedef struct asgClient {
231  ELLNODE node;
232  ASGMEMBER *pasgMember;
233  const char *user;
234  char *host;
235  void *userPvt;
236  ASCLIENTCALLBACK pcallback;
237  int level;
238  asAccessRights access;
239  int trapMask;
240 } ASGCLIENT;
241 
242 LIBCOM_API long epicsStdCall asComputeAsg(ASG *pasg);
243 /*following is "friend" function*/
244 LIBCOM_API void * epicsStdCall asCalloc(size_t nobj,size_t size);
245 LIBCOM_API char * epicsStdCall asStrdup(unsigned char *str);
246 LIBCOM_API void asFreeAll(ASBASE *pasbase);
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif /*INCasLibh*/
Definition: asLib.h:192
List node type.
Definition: ellLib.h:46
Functions for interacting with the errlog task.
Definition: asLib.h:183
Definition: asLib.h:187
Definition: asLib.h:177
Definition: asLib.h:173
Definition: asLib.h:163
Definition: asLib.h:212
Definition: asLib.h:153
A doubly-linked list library.
List header type.
Definition: ellLib.h:57
Definition: asLib.h:204
Definition: asLib.h:167