pam_pkcs11 0.6.12
mapper.h
Go to the documentation of this file.
1/*
2 * PAM-PKCS11 mapping modules
3 * Copyright (C) 2005 Juan Antonio Martinez <jonsito@teleline.es>
4 * pam-pkcs11 is copyright (C) 2003-2004 of Mario Strasser <mast@gmx.net>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * $Id$
21 */
22
23#ifndef __MAPPER_H_
24#define __MAPPER_H_
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30#include <sys/types.h>
31#include <stdlib.h>
32#include <string.h>
33#include <pwd.h>
34#include <../common/cert_st.h>
35#include "../scconf/scconf.h"
36
40typedef struct mapper_module_st {
42 const char *name;
48 void *context;
50 char **(*entries)(X509 *x509, void *context);
52 char *(*finder)(X509 *x509, void *context, int *match);
54 int (*matcher)(X509 *x509, const char *login, void *context);
56 void (*deinit)( void *context);
58
63struct mapfile {
65 const char *uri;
67 char *buffer;
69 size_t length;
71 char *pt;
73 char *key;
75 char *value;
76};
77
78/* ------------------------------------------------------- */
79
88mapper_module * mapper_module_init(scconf_block *ctx,const char *mapper_name);
89
90/* ------------------------------------------------------- */
91
92/*
93* mapper.c prototype functions
94*/
95#ifndef __MAPPER_C_
96#define MAPPER_EXTERN extern
97#else
98#define MAPPER_EXTERN
99#endif
100
101/* mapfile related functions */
102
108MAPPER_EXTERN struct mapfile *set_mapent(const char *uri);
109
116
121MAPPER_EXTERN void end_mapent(struct mapfile *mfile);
122
131MAPPER_EXTERN char *mapfile_find(const char *file,char *key,int ignorecase,int *match);
132
141MAPPER_EXTERN int mapfile_match(const char *file,char *key,const char *value,int ignorecase);
142
143/* pwent related functions */
144
151MAPPER_EXTERN char *search_pw_entry(const char *item, int ignorecase);
152
160MAPPER_EXTERN int compare_pw_entry(const char *item, struct passwd *pw,int ignorecase);
161
162#undef MAPPER_EXTERN
163
164/* ------------------------------------------------------- */
165
174#define _DEFAULT_MAPPER_FIND_ENTRIES \
175static char ** mapper_find_entries(X509 *x509, void *context) { \
176 return NULL; \
177}
178
187#define _DEFAULT_MAPPER_FIND_USER \
188static char * mapper_find_user(X509 *x509,void *context,int *match) { \
189 if ( !x509 ) return NULL; \
190 *match = 1; \
191 return "nobody"; \
192}
193
204#define _DEFAULT_MAPPER_MATCH_USER \
205static int mapper_match_user(X509 *x509, const char *login, void *context) { \
206 int match = 0; \
207 char *username= mapper_find_user(x509,context,&match); \
208 if (!x509) return -1; \
209 if (!login) return -1; \
210 if (!username) return 0; /*user not found*/ \
211 if ( ! strcmp(login,username) ) return 1; /* match user */ \
212 return 0; /* no match */ \
213}
214
219#define _DEFAULT_MAPPER_END \
220static void mapper_module_end(void *context) { \
221 free(context); \
222 return; \
223} \
224
225
232#define _DEFAULT_MAPPER_INIT \
233mapper_module* mapper_module_init(scconf_block *blk,const char *name) { \
234 mapper_module *pt= malloc(sizeof (mapper_module)); \
235 if (!pt) return NULL; \
236 pt->name = name; \
237 pt->context = NULL; \
238 pt->block = blk; \
239 pt->dbg_level = get_debug_level(); \
240 pt->entries = mapper_find_entries; \
241 pt->finder = mapper_find_user; \
242 pt->matcher = mapper_match_user; \
243 pt->deinit = mapper_module_end; \
244 return pt; \
245} \
246
247/* end of mapper.h file */
248#endif
#define MAPPER_EXTERN
Definition mapper.h:96
MAPPER_EXTERN int get_mapent(struct mapfile *mfile)
Retrieve next entry of given map file.
MAPPER_EXTERN char * search_pw_entry(const char *item, int ignorecase)
find the user login that matches pw_name or pw_gecos with provided item
MAPPER_EXTERN int compare_pw_entry(const char *item, struct passwd *pw, int ignorecase)
Test if provided item matches pw_name or pw_gecos of provided password structure.
MAPPER_EXTERN struct mapfile * set_mapent(const char *uri)
Initialize a mapper entry table.
MAPPER_EXTERN int mapfile_match(const char *file, char *key, const char *value, int ignorecase)
Try to match provided key to provided name by mean of a mapfile.
mapper_module * mapper_module_init(scconf_block *ctx, const char *mapper_name)
Initialize module and mapper_module_st structure.
struct mapper_module_st mapper_module
Structure to be filled on mapper module initialization.
MAPPER_EXTERN void end_mapent(struct mapfile *mfile)
Release a mapentry structure.
MAPPER_EXTERN char * mapfile_find(const char *file, char *key, int ignorecase, int *match)
Try to map "key" to provided mapfile.
struct _scconf_block scconf_block
Definition scconf.h:55
This struct is used in processing map files a map file is a list of "key" " -> " "value" text lines.
Definition mapper.h:63
char * value
value assigned to key
Definition mapper.h:75
char * key
key entry in current buffer
Definition mapper.h:73
const char * uri
URL of mapfile.
Definition mapper.h:65
char * pt
pointer to last readed entry in buffer
Definition mapper.h:71
size_t length
lenght of buffer
Definition mapper.h:69
char * buffer
buffer to content of mapfile
Definition mapper.h:67
Structure to be filled on mapper module initialization.
Definition mapper.h:40
void(* deinit)(void *context)
module de-initialization
Definition mapper.h:56
int(* matcher)(X509 *x509, const char *login, void *context)
cert-to-login matcher
Definition mapper.h:54
const char * name
mapper name
Definition mapper.h:42
int dbg_level
debug level to set before call entry points
Definition mapper.h:46
scconf_block * block
mapper configuration block
Definition mapper.h:44
void * context
pointer to mapper local data
Definition mapper.h:48