<commit_before>/*
 * PAM-PKCS11 generic mapper skeleton
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 * pam-pkcs11 is copyright (C) 2003-2004 of <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * $Id$
 */

#define __GENERIC_MAPPER_C_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*#include <openssl/evp.h> */
#include "../common/cert_st.h"
#include "../scconf/scconf.h"
#include "../common/debug.h"
#include "../common/error.h"
#include "../common/strings.h"
#include "../common/cert_info.h"
#include "mapper.h"
#include "generic_mapper.h"

/*
* Skeleton for mapper modules
*/

static const char *mapfile = "none";
static int usepwent = 0;
static int ignorecase = 0;
static int id_type = CERT_CN;
static int debug = 0;

static char **generic_mapper_find_entries(X509 *x509, void *context) {
        if (!x509) {
                DBG("NULL certificate provided");
                return NULL;
        }
	return cert_info(x509, id_type, ALGORITHM_NULL); 
}

static char **get_mapped_entries(char **entries) {
	char *entry;
	int n=0;
	char *res=NULL;
	/* if mapfile is provided, map entries according it */
	if ( !strcmp(mapfile,"none") ) {
	    DBG("Use map file is disabled");
	} else {
	    DBG1("Using map file '%s'",mapfile);
	    for(n=0, entry=entries[n]; entry; entry=entries[++n]) {
		res = mapfile_find(mapfile,entry,ignorecase);
		if (res) entries[n]=res;
	    }
	}
	/* if NSS is set, re-map entries against it */
	if ( usepwent==0 ) {
	    DBG("Use Naming Services is disabled");
	} else {
	    char *res=NULL;
	    DBG("Using Naming Services");
	    for(n=0,entry=entries[n];entry;entry=entries[++n]) {
		res = search_pw_entry(entry,ignorecase);
		if (res) entries[n]=res;
	    }
	}
	return entries;
}

static char *generic_mapper_find_user(X509 *x509, void *context) {
	char **entries;
	int n;
        if (!x509) {
                DBG("NULL certificate provided");
                return NULL;
        }
	/* get entries from certificate */
	entries= generic_mapper_find_entries(x509,context);
	if (!entries) {<commit_msg>get_mapped_entries(): remove a duplicate variable declaration generic_mapper.c:75: warning: declaration of 'res' shadows a previous local<commit_after>/*
 * PAM-PKCS11 generic mapper skeleton
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 * pam-pkcs11 is copyright (C) 2003-2004 of <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * $Id$
 */

#define __GENERIC_MAPPER_C_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*#include <openssl/evp.h> */
#include "../common/cert_st.h"
#include "../scconf/scconf.h"
#include "../common/debug.h"
#include "../common/error.h"
#include "../common/strings.h"
#include "../common/cert_info.h"
#include "mapper.h"
#include "generic_mapper.h"

/*
* Skeleton for mapper modules
*/

static const char *mapfile = "none";
static int usepwent = 0;
static int ignorecase = 0;
static int id_type = CERT_CN;
static int debug = 0;

static char **generic_mapper_find_entries(X509 *x509, void *context) {
        if (!x509) {
                DBG("NULL certificate provided");
                return NULL;
        }
	return cert_info(x509, id_type, ALGORITHM_NULL); 
}

static char **get_mapped_entries(char **entries) {
	char *entry;
	int n=0;
	char *res=NULL;
	/* if mapfile is provided, map entries according it */
	if ( !strcmp(mapfile,"none") ) {
	    DBG("Use map file is disabled");
	} else {
	    DBG1("Using map file '%s'",mapfile);
	    for(n=0, entry=entries[n]; entry; entry=entries[++n]) {
		res = mapfile_find(mapfile,entry,ignorecase);
		if (res) entries[n]=res;
	    }
	}
	/* if NSS is set, re-map entries against it */
	if ( usepwent==0 ) {
	    DBG("Use Naming Services is disabled");
	} else {
	    res=NULL;
	    DBG("Using Naming Services");
	    for(n=0,entry=entries[n];entry;entry=entries[++n]) {
		res = search_pw_entry(entry,ignorecase);
		if (res) entries[n]=res;
	    }
	}
	return entries;
}

static char *generic_mapper_find_user(X509 *x509, void *context) {
	char **entries;
	int n;
        if (!x509) {
                DBG("NULL certificate provided");
                return NULL;
        }
	/* get entries from certificate */
	entries= generic_mapper_find_entries(x509,context);
	if (!entries) {
{'fraction_non_alphanumeric': 0.12544674767691208, 'fraction_numerical': 0.023230879199428164, 'mean_word_length': 3.5173527037933816, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4200579', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1793, 'n_words': 603}