00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MAPPER_H_
00024 #define __MAPPER_H_
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030 #include <sys/types.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <pwd.h>
00034 #include <../common/cert_st.h>
00035 #include "../scconf/scconf.h"
00036
00040 typedef struct mapper_module_st {
00042 const char *name;
00044 scconf_block *block;
00046 int dbg_level;
00048 void *context;
00050 char **(*entries)(X509 *x509, void *context);
00052 char *(*finder)(X509 *x509, void *context);
00054 int (*matcher)(X509 *x509, const char *login, void *context);
00056 void (*deinit)( void *context);
00057 } mapper_module;
00058
00063 struct mapfile {
00065 const char *uri;
00067 char *buffer;
00069 size_t length;
00071 char *pt;
00073 char *key;
00075 char *value;
00076 };
00077
00078
00079
00088 mapper_module * mapper_module_init(scconf_block *ctx,const char *mapper_name);
00089
00090
00091
00092
00093
00094
00095 #ifndef __MAPPER_C_
00096 #define MAPPER_EXTERN extern
00097 #else
00098 #define MAPPER_EXTERN
00099 #endif
00100
00101
00102
00108 MAPPER_EXTERN struct mapfile *set_mapent(const char *uri);
00109
00115 MAPPER_EXTERN int get_mapent(struct mapfile *mfile);
00116
00121 MAPPER_EXTERN void end_mapent(struct mapfile *mfile);
00122
00130 MAPPER_EXTERN char *mapfile_find(const char *file,char *key,int ignorecase);
00131
00140 MAPPER_EXTERN int mapfile_match(const char *file,char *key,const char *value,int ignorecase);
00141
00142
00143
00150 MAPPER_EXTERN char *search_pw_entry(const char *item, int ignorecase);
00151
00159 MAPPER_EXTERN int compare_pw_entry(const char *item, struct passwd *pw,int ignorecase);
00160
00161 #undef MAPPER_EXTERN
00162
00163
00164
00173 #define _DEFAULT_MAPPER_FIND_ENTRIES \
00174 static char ** mapper_find_entries(X509 *x509, void *context) { \
00175 return NULL; \
00176 }
00177
00186 #define _DEFAULT_MAPPER_FIND_USER \
00187 static char * mapper_find_user(X509 *x509,void *context) { \
00188 if ( !x509 ) return NULL; \
00189 return "nobody"; \
00190 }
00191
00202 #define _DEFAULT_MAPPER_MATCH_USER \
00203 static int mapper_match_user(X509 *x509, const char *login, void *context) { \
00204 char *username= mapper_find_user(x509,context); \
00205 if (!x509) return -1; \
00206 if (!login) return -1; \
00207 if (!username) return 0; \
00208 if ( ! strcmp(login,username) ) return 1; \
00209 return 0; \
00210 }
00211
00216 #define _DEFAULT_MAPPER_END \
00217 static void mapper_module_end(void *context) { \
00218 free(context); \
00219 return; \
00220 } \
00221
00222
00229 #define _DEFAULT_MAPPER_INIT \
00230 mapper_module* mapper_module_init(scconf_block *blk,const char *name) { \
00231 mapper_module *pt= malloc(sizeof (mapper_module)); \
00232 if (!pt) return NULL; \
00233 pt->name = name; \
00234 pt->context = NULL; \
00235 pt->block = blk; \
00236 pt->dbg_level = get_debug_level(); \
00237 pt->entries = mapper_find_entries; \
00238 pt->finder = mapper_find_user; \
00239 pt->matcher = mapper_match_user; \
00240 pt->deinit = mapper_module_end; \
00241 return pt; \
00242 } \
00243
00244
00245 #endif