pam_pkcs11 0.6.8

- Main Page
- Data Structures
- Files
- Directories

- File List
- Globals

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 445 2010-08-14 16:19:36Z 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, int *match);
    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
    00131 MAPPER_EXTERN char *mapfile_find(const char *file,char *key,int ignorecase,int *match);
    00132
    00141 MAPPER_EXTERN int mapfile_match(const char *file,char *key,const char *value,int ignorecase);
    00142
    00143 /* pwent related functions */
    00144
    00151 MAPPER_EXTERN char *search_pw_entry(const char *item, int ignorecase);
    00152
    00160 MAPPER_EXTERN int compare_pw_entry(const char *item, struct passwd *pw,int ignorecase);
    00161
    00162 #undef MAPPER_EXTERN
    00163
    00164 /* ------------------------------------------------------- */
    00165
    00174 #define _DEFAULT_MAPPER_FIND_ENTRIES                                    \
    00175 static char ** mapper_find_entries(X509 *x509, void *context) {         \
    00176         return NULL;                                                    \
    00177 }
    00178
    00187 #define _DEFAULT_MAPPER_FIND_USER                                       \
    00188 static char * mapper_find_user(X509 *x509,void *context,int *match) {           \
    00189         if ( !x509 ) return NULL;                                       \
    00190         *match = 1;                                                     \
    00191         return "nobody";                                                \
    00192 }
    00193
    00204 #define _DEFAULT_MAPPER_MATCH_USER                                      \
    00205 static int mapper_match_user(X509 *x509, const char *login, void *context) { \
    00206         int match = 0;                                                  \
    00207         char *username= mapper_find_user(x509,context,&match);          \
    00208         if (!x509) return -1;                                           \
    00209         if (!login) return -1;                                          \
    00210         if (!username) return 0; /*user not found*/                     \
    00211         if ( ! strcmp(login,username) ) return 1; /* match user */      \
    00212         return 0; /* no match */                                        \
    00213 }
    00214
    00219 #define _DEFAULT_MAPPER_END                                             \
    00220 static void mapper_module_end(void *context) {                          \
    00221         free(context);                                                  \
    00222         return;                                                         \
    00223 }                                                                       \
    00224
    00225
    00232 #define _DEFAULT_MAPPER_INIT                                            \
    00233 mapper_module* mapper_module_init(scconf_block *blk,const char *name) { \
    00234         mapper_module *pt= malloc(sizeof (mapper_module));              \
    00235         if (!pt) return NULL;                                           \
    00236         pt->name    = name;                                             \
    00237         pt->context = NULL;                                             \
    00238         pt->block   = blk;                                              \
    00239         pt->dbg_level  = get_debug_level();                             \
    00240         pt->entries = mapper_find_entries;                              \
    00241         pt->finder  = mapper_find_user;                                 \
    00242         pt->matcher = mapper_match_user;                                \
    00243         pt->deinit  = mapper_module_end;                        \
    00244         return pt;                                                      \
    00245 }                                                                       \
    00246
    00247 /* end of mapper.h file */
    00248 #endif