Changeset 445
- Timestamp:
- 08/14/10 16:19:36 (22 months ago)
- Location:
- trunk/src
- Files:
-
- 17 edited
-
mappers/cn_mapper.c (modified) (2 diffs)
-
mappers/digest_mapper.c (modified) (2 diffs)
-
mappers/generic_mapper.c (modified) (4 diffs)
-
mappers/krb_mapper.c (modified) (2 diffs)
-
mappers/ldap_mapper.c (modified) (2 diffs)
-
mappers/mail_mapper.c (modified) (4 diffs)
-
mappers/mapper.c (modified) (4 diffs)
-
mappers/mapper.h (modified) (4 diffs)
-
mappers/ms_mapper.c (modified) (2 diffs)
-
mappers/null_mapper.c (modified) (1 diff)
-
mappers/opensc_mapper.c (modified) (2 diffs)
-
mappers/openssh_mapper.c (modified) (2 diffs)
-
mappers/pwent_mapper.c (modified) (2 diffs)
-
mappers/subject_mapper.c (modified) (2 diffs)
-
mappers/uid_mapper.c (modified) (2 diffs)
-
pam_pkcs11/mapper_mgr.c (modified) (1 diff)
-
tools/pklogin_finder.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mappers/cn_mapper.c
r358 r445 61 61 parses the certificate and return the first CN entry found, or NULL 62 62 */ 63 static char * cn_mapper_find_user(X509 *x509, void *context ) {63 static char * cn_mapper_find_user(X509 *x509, void *context, int *match) { 64 64 char *res; 65 65 char **entries= cert_info(x509,CERT_CN,ALGORITHM_NULL); … … 69 69 } 70 70 DBG1("trying to map CN entry '%s'",entries[0]); 71 res = mapfile_find(mapfile,entries[0],ignorecase );71 res = mapfile_find(mapfile,entries[0],ignorecase,match); 72 72 if (!res) { 73 73 DBG("Error in map process"); -
trunk/src/mappers/digest_mapper.c
r358 r445 58 58 } 59 59 60 static char * digest_mapper_find_user(X509 *x509, void *context ) {60 static char * digest_mapper_find_user(X509 *x509, void *context, int *match) { 61 61 char **entries; 62 62 if ( !x509 ) { … … 66 66 entries = cert_info(x509,CERT_DIGEST,algorithm); 67 67 DBG1("find() Found digest '%s'",entries[0]); 68 return mapfile_find(mapfile,entries[0],1 );68 return mapfile_find(mapfile,entries[0],1,match); 69 69 } 70 70 -
trunk/src/mappers/generic_mapper.c
r358 r445 56 56 57 57 static char **get_mapped_entries(char **entries) { 58 int match = 0; 58 59 char *entry; 59 60 int n=0; … … 65 66 DBG1("Using map file '%s'",mapfile); 66 67 for(n=0, entry=entries[n]; entry; entry=entries[++n]) { 67 res = mapfile_find(mapfile,entry,ignorecase );68 res = mapfile_find(mapfile,entry,ignorecase,&match); 68 69 if (res) entries[n]=res; 69 70 } … … 83 84 } 84 85 85 static char *generic_mapper_find_user(X509 *x509, void *context ) {86 static char *generic_mapper_find_user(X509 *x509, void *context, int *match) { 86 87 char **entries; 87 88 int n; … … 101 102 for (n=0;n<CERT_INFO_SIZE;n++) { 102 103 char *str=entries[n]; 103 if (!str && !is_empty_str(str) ) return clone_str(str); 104 if (!str && !is_empty_str(str) ) { 105 *match = 1; 106 return clone_str(str); 107 } 104 108 } 105 109 /* arriving here means no map found */ -
trunk/src/mappers/krb_mapper.c
r358 r445 64 64 parses the certificate and return the email entry found, or NULL 65 65 */ 66 static char * krb_mapper_find_user(X509 *x509, void *context ) {66 static char * krb_mapper_find_user(X509 *x509, void *context, int *match) { 67 67 char *res; 68 68 char **entries= cert_info(x509,CERT_KPN,ALGORITHM_NULL); … … 72 72 } 73 73 DBG1("trying to map kpn entry '%s'",entries[0]); 74 res = mapfile_find("none",entries[0],0 );74 res = mapfile_find("none",entries[0],0,match); 75 75 if (!res) { 76 76 DBG("Error in map process"); -
trunk/src/mappers/ldap_mapper.c
r423 r445 923 923 } 924 924 925 static char * ldap_mapper_find_user(X509 *x509, void *context ) {925 static char * ldap_mapper_find_user(X509 *x509, void *context, int *match) { 926 926 struct passwd *pw = NULL; 927 927 char *found=NULL; … … 934 934 DBG1("Certificate maps to user '%s'",pw->pw_name); 935 935 found= clone_str(pw->pw_name); 936 *match = 1; 936 937 break; 937 938 } else { -
trunk/src/mappers/mail_mapper.c
r358 r445 107 107 parses the certificate and return the email entry found, or NULL 108 108 */ 109 static char * mail_mapper_find_user(X509 *x509, void *context ) {109 static char * mail_mapper_find_user(X509 *x509, void *context, int *match) { 110 110 char **entries= cert_info(x509,CERT_EMAIL,ALGORITHM_NULL); 111 111 if (!entries) { … … 114 114 } 115 115 /* TODO: What's on ignoredomain flag ?*/ 116 return mapfile_find(mapfile,entries[0],ignorecase );116 return mapfile_find(mapfile,entries[0],ignorecase,match); 117 117 } 118 118 … … 122 122 */ 123 123 static int mail_mapper_match_user(X509 *x509, const char *login, void *context) { 124 int match = 0; 124 125 char *item; 125 126 char *str; … … 132 133 for (item=*entries;item;item=*++entries) { 133 134 DBG1("Trying to match email entry '%s'",item); 134 str= mapfile_find(mapfile,item,ignorecase );135 str= mapfile_find(mapfile,item,ignorecase,&match); 135 136 if (!str) { 136 137 DBG("Mapping process failed"); -
trunk/src/mappers/mapper.c
r358 r445 32 32 #include <string.h> 33 33 #include <pwd.h> 34 #include <regex.h> 34 35 #include "../common/debug.h" 35 36 #include "../common/error.h" … … 141 142 * @param key Key to search in mapfile 142 143 * @param icase ignore case 144 * @param match Set to 1 for mapped string return, unmodified for key return 143 145 * @return mapped string on match, key on no match, NULL on error 144 146 */ 145 char *mapfile_find(const char *file, char *key, int icase ) {147 char *mapfile_find(const char *file, char *key, int icase, int *match) { 146 148 struct mapfile *mfile; 147 int done=0;148 149 if ( (!key) || is_empty_str(key) ) { 149 150 DBG("key to map is null or empty"); … … 162 163 } 163 164 while (get_mapent(mfile)) { 164 if ( (icase) && (!strcasecmp(key,mfile->key)) ) done=1; 165 if ( (!icase) && (!strcmp(key,mfile->key)) ) done=1; 165 int done = 0; 166 if (mfile->key[0]=='^' && mfile->key[strlen(mfile->key)-1]=='$') { 167 regex_t re; 168 DBG2("Trying RE '%s' match on '%s'",mfile->key,key); 169 if (regcomp(&re,mfile->key,(icase ? REG_ICASE : 0)|REG_NEWLINE)) { 170 DBG2("RE '%s' in mapfile '%s' is invalid",mfile->key,file); 171 } else { 172 done = !regexec(&re,key,0,NULL,0); 173 regfree(&re); 174 } 175 } else if (icase) 176 done = !strcasecmp(key, mfile->key); 177 else 178 done = !strcmp(key, mfile->key); 179 166 180 if (done) { 167 181 char *res=clone_str(mfile->value); 168 182 DBG2("Found mapfile match '%s' -> '%s'",key,mfile->value); 169 183 end_mapent(mfile); 184 *match = 1; 170 185 return res; 171 186 } … … 187 202 int mapfile_match(const char *file, char *key, const char *value, int icase) { 188 203 int res; 189 char *str=mapfile_find(file,key,icase); 204 int match = 0; 205 char *str=mapfile_find(file,key,icase,&match); 190 206 if (!str) return -1; 191 207 if (icase) res= (!strcasecmp(str,value))? 1:0; -
trunk/src/mappers/mapper.h
r358 r445 50 50 char **(*entries)(X509 *x509, void *context); 51 51 /** cert. login finder */ 52 char *(*finder)(X509 *x509, void *context );52 char *(*finder)(X509 *x509, void *context, int *match); 53 53 /** cert-to-login matcher*/ 54 54 int (*matcher)(X509 *x509, const char *login, void *context); … … 126 126 *@param key String to be mapped 127 127 *@param ignorecase Flag to indicate upper/lowercase ignore in string compare 128 *@param match Set to 1 for mapped string return, unmodified for key return 128 129 *@return key on no match, else a clone_str()'d of found mapping 129 130 */ 130 MAPPER_EXTERN char *mapfile_find(const char *file,char *key,int ignorecase );131 MAPPER_EXTERN char *mapfile_find(const char *file,char *key,int ignorecase,int *match); 131 132 132 133 /** … … 185 186 */ 186 187 #define _DEFAULT_MAPPER_FIND_USER \ 187 static char * mapper_find_user(X509 *x509,void *context ) { \188 static char * mapper_find_user(X509 *x509,void *context,int *match) { \ 188 189 if ( !x509 ) return NULL; \ 190 *match = 1; \ 189 191 return "nobody"; \ 190 192 } … … 202 204 #define _DEFAULT_MAPPER_MATCH_USER \ 203 205 static int mapper_match_user(X509 *x509, const char *login, void *context) { \ 204 char *username= mapper_find_user(x509,context); \ 206 int match = 0; \ 207 char *username= mapper_find_user(x509,context,&match); \ 205 208 if (!x509) return -1; \ 206 209 if (!login) return -1; \ -
trunk/src/mappers/ms_mapper.c
r358 r445 109 109 parses the certificate and return the first valid UPN entry found, or NULL 110 110 */ 111 static char * ms_mapper_find_user(X509 *x509, void *context ) {111 static char * ms_mapper_find_user(X509 *x509, void *context, int *match) { 112 112 char *str; 113 113 char **entries = cert_info(x509,CERT_UPN,ALGORITHM_NULL); … … 123 123 if (res) { 124 124 DBG2("Found valid UPN: '%s' maps to '%s' ",str,res); 125 *match = 1; 125 126 return clone_str(res); 126 127 } else { -
trunk/src/mappers/null_mapper.c
r238 r445 44 44 static int debug=0; 45 45 46 static char * mapper_find_user(X509 *x509,void *context ) {46 static char * mapper_find_user(X509 *x509,void *context,int *mp) { 47 47 if ( !x509 ) return NULL; 48 return (match)?clone_str((char *)default_user):NULL; 48 if (match) { 49 *mp = 1; 50 return clone_str((char *)default_user); 51 } 52 return NULL; 49 53 } 50 54 -
trunk/src/mappers/opensc_mapper.c
r396 r445 136 136 their ${HOME}/.eid/authorized_certificates 137 137 */ 138 static char * opensc_mapper_find_user(X509 *x509, void *context ) {138 static char * opensc_mapper_find_user(X509 *x509, void *context, int *match) { 139 139 int n = 0; 140 140 struct passwd *pw = NULL; … … 156 156 /* arriving here means user found */ 157 157 DBG1("Certificate match found for user '%s'",pw->pw_name); 158 res= clone_str(pw->pw_name); 159 endpwent(); 158 res = clone_str(pw->pw_name); 159 endpwent(); 160 *match = 1; 160 161 return res; 161 162 } /* next login */ -
trunk/src/mappers/openssh_mapper.c
r358 r445 319 319 parses the certificate and return the _first_ user that matches public key 320 320 */ 321 static char * openssh_mapper_find_user(X509 *x509, void *context ) {321 static char * openssh_mapper_find_user(X509 *x509, void *context, int *match) { 322 322 int n = 0; 323 323 struct passwd *pw = NULL; … … 345 345 /* arriving here means user found */ 346 346 DBG1("Certificate match found for user '%s'",pw->pw_name); 347 res = clone_str(pw->pw_name);347 res = clone_str(pw->pw_name); 348 348 endpwent(); 349 *match = 1; 349 350 return res; 350 351 } /* next login */ -
trunk/src/mappers/pwent_mapper.c
r358 r445 64 64 parses the certificate and return the _first_ CN entry found, or NULL 65 65 */ 66 static char * pwent_mapper_find_user(X509 *x509,void *context ) {66 static char * pwent_mapper_find_user(X509 *x509,void *context, int *match) { 67 67 char *str; 68 68 char *found_user = NULL; … … 81 81 } else { 82 82 DBG1("Found CN in pw database for user '%s'",found_user); 83 *match = 1; 84 /* WJG: Usually allocated mem is returned - memleak/problem? */ 83 85 return found_user; 84 86 } -
trunk/src/mappers/subject_mapper.c
r238 r445 57 57 parses the certificate and return the first Subject entry found, or NULL 58 58 */ 59 static char * subject_mapper_find_user(X509 *x509, void *context ) {59 static char * subject_mapper_find_user(X509 *x509, void *context, int *match) { 60 60 char **entries = cert_info(x509,CERT_SUBJECT,ALGORITHM_NULL); 61 61 if (!entries) { … … 63 63 return NULL; 64 64 } 65 return mapfile_find(filename,entries[0],ignorecase );65 return mapfile_find(filename,entries[0],ignorecase,match); 66 66 } 67 67 -
trunk/src/mappers/uid_mapper.c
r358 r445 62 62 If no UID found or map error, return NULL 63 63 */ 64 static char * uid_mapper_find_user(X509 *x509, void *context ) {64 static char * uid_mapper_find_user(X509 *x509, void *context, int *match) { 65 65 char *res; 66 66 char **entries= cert_info(x509,CERT_UID,ALGORITHM_NULL); … … 70 70 } 71 71 DBG1("trying to map uid entry '%s'",entries[0]); 72 res = mapfile_find(mapfile,entries[0],ignorecase );72 res = mapfile_find(mapfile,entries[0],ignorecase,match); 73 73 if (!res) { 74 74 DBG("Error in map process"); -
trunk/src/pam_pkcs11/mapper_mgr.c
r399 r445 265 265 DBG1("Mapper '%s' has no find() function",item->module->module_name); 266 266 } else { 267 set_debug_level(item->module->module_data->dbg_level); 268 login = (*item->module->module_data->finder)(x509,item->module->module_data->context); 267 int match = 0; 268 269 set_debug_level(item->module->module_data->dbg_level); 270 login = (*item->module->module_data->finder)(x509,item->module->module_data->context, &match); 269 271 set_debug_level(old_level); 270 if (login) return login; 272 DBG3("Mapper '%s' found %s, matched %d", item->module->module_name,login, match); 273 if (login) { 274 if (match) 275 return login; 276 free(login); 277 } 271 278 } 272 279 item=item->next; -
trunk/src/tools/pklogin_finder.c
r441 r445 146 146 user=find_user(x509); 147 147 if (!user) { 148 DBG 1("find_user() failed: %s", get_error());149 break;148 DBG2("find_user() failed for certificate #%d: %s", i + 1, get_error()); 149 continue; /* with next certificate */ 150 150 } else { 151 151 DBG1("Certificate is valid and maps to user %s",user);
Note: See TracChangeset
for help on using the changeset viewer.
