mapper.h

Go to the documentation of this file.
00001 /*
00002  * PAM-PKCS11 mapping modules
00003  * Copyright (C) 2005 Juan Antonio Martinez <jonsito@teleline.es>
00004  * pam-pkcs11 is copyright (C) 2003-2004 of Mario Strasser <mast@gmx.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  * $Id: mapper.h 238 2007-04-11 07:04:53Z ludovic.rousseau $
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 * mapper.c prototype functions
00094 */
00095 #ifndef __MAPPER_C_
00096 #define MAPPER_EXTERN extern
00097 #else
00098 #define MAPPER_EXTERN
00099 #endif
00100 
00101 /* mapfile related functions */
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 /* pwent related functions */
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; /*user not found*/                     \
00208         if ( ! strcmp(login,username) ) return 1; /* match user */      \
00209         return 0; /* no match */                                        \
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 /* end of mapper.h file */
00245 #endif

Generated on Mon May 21 23:11:10 2007 for pam_pkcs11 by  doxygen 1.5.1