pam_pkcs11  0.6.10
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 
40 typedef struct mapper_module_st {
42  const char *name;
46  int dbg_level;
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 
63 struct 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 
88 mapper_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 
108 MAPPER_EXTERN struct mapfile *set_mapent(const char *uri);
109 
115 MAPPER_EXTERN int get_mapent(struct mapfile *mfile);
116 
121 MAPPER_EXTERN void end_mapent(struct mapfile *mfile);
122 
131 MAPPER_EXTERN char *mapfile_find(const char *file,char *key,int ignorecase,int *match);
132 
141 MAPPER_EXTERN int mapfile_match(const char *file,char *key,const char *value,int ignorecase);
142 
143 /* pwent related functions */
144 
151 MAPPER_EXTERN char *search_pw_entry(const char *item, int ignorecase);
152 
160 MAPPER_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 \
175 static char ** mapper_find_entries(X509 *x509, void *context) { \
176  return NULL; \
177 }
178 
187 #define _DEFAULT_MAPPER_FIND_USER \
188 static 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 \
205 static 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 \
220 static void mapper_module_end(void *context) { \
221  free(context); \
222  return; \
223 } \
224 
225 
232 #define _DEFAULT_MAPPER_INIT \
233 mapper_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
_scconf_block
Definition: scconf.h:77
MAPPER_EXTERN
#define MAPPER_EXTERN
Definition: mapper.h:96
mapfile::length
size_t length
lenght of buffer
Definition: mapper.h:69
set_mapent
MAPPER_EXTERN struct mapfile * set_mapent(const char *uri)
Initialize a mapper entry table.
mapper_module_st::matcher
int(* matcher)(X509 *x509, const char *login, void *context)
cert-to-login matcher
Definition: mapper.h:54
mapper_module_st::dbg_level
int dbg_level
debug level to set before call entry points
Definition: mapper.h:46
mapfile
This struct is used in processing map files a map file is a list of "key" " -> " "value" text lines.
Definition: mapper.h:63
mapfile_match
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.
mapfile::key
char * key
key entry in current buffer
Definition: mapper.h:73
mapfile::buffer
char * buffer
buffer to content of mapfile
Definition: mapper.h:67
mapper_module_st
Structure to be filled on mapper module initialization.
Definition: mapper.h:40
mapper_module_st::block
scconf_block * block
mapper configuration block
Definition: mapper.h:44
compare_pw_entry
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.
mapfile::value
char * value
value assigned to key
Definition: mapper.h:75
mapper_module_st::deinit
void(* deinit)(void *context)
module de-initialization
Definition: mapper.h:56
mapper_module_init
mapper_module * mapper_module_init(scconf_block *ctx, const char *mapper_name)
Initialize module and mapper_module_st structure.
mapfile::pt
char * pt
pointer to last readed entry in buffer
Definition: mapper.h:71
mapper_module
struct mapper_module_st mapper_module
Structure to be filled on mapper module initialization.
mapper_module_st::context
void * context
pointer to mapper local data
Definition: mapper.h:48
mapfile_find
MAPPER_EXTERN char * mapfile_find(const char *file, char *key, int ignorecase, int *match)
Try to map "key" to provided mapfile.
mapfile::uri
const char * uri
URL of mapfile.
Definition: mapper.h:65
search_pw_entry
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_module_st::name
const char * name
mapper name
Definition: mapper.h:42
get_mapent
MAPPER_EXTERN int get_mapent(struct mapfile *mfile)
Retrieve next entry of given map file.
end_mapent
MAPPER_EXTERN void end_mapent(struct mapfile *mfile)
Release a mapentry structure.