mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Centralized function compatible with Linux & Windows (also with mpm-itk & mod_ruid2) to get username
This commit is contained in:
parent
11f85b82e1
commit
c7b28f0e13
@ -2843,3 +2843,14 @@ char* strtok_r(
|
||||
}
|
||||
#endif
|
||||
|
||||
// Function compatible with Linux & Windows, also with mpm-itk & mod_ruid2
|
||||
char* get_username(apr_pool_t* mp) {
|
||||
char* username;
|
||||
apr_uid_t uid;
|
||||
apr_gid_t gid;
|
||||
int rc = apr_uid_current(&uid, &gid, mp);
|
||||
if (rc != APR_SUCCESS) return "apache";
|
||||
rc = apr_uid_name_get(&username, uid, mp);
|
||||
if (rc != APR_SUCCESS) return "apache";
|
||||
return username;
|
||||
}
|
||||
|
@ -159,6 +159,8 @@ int DSOLOCAL tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
|
||||
int DSOLOCAL ip_tree_from_param(apr_pool_t *pool,
|
||||
char *param, TreeRoot **rtree, char **error_msg);
|
||||
|
||||
char DSOLOCAL *get_username(apr_pool_t* mp);
|
||||
|
||||
#ifdef WITH_CURL
|
||||
int ip_tree_from_uri(TreeRoot **rtree, char *uri,
|
||||
apr_pool_t *mp, char **error_msg);
|
||||
|
@ -100,18 +100,7 @@ static apr_table_t *collection_retrieve_ex(apr_sdbm_t *existing_dbm, modsec_rec
|
||||
apr_table_entry_t *te;
|
||||
int expired = 0;
|
||||
int i;
|
||||
|
||||
/**
|
||||
* This is required for mpm-itk & mod_ruid2, though should be harmless for other implementations
|
||||
*/
|
||||
char *userinfo;
|
||||
apr_uid_t uid;
|
||||
apr_gid_t gid;
|
||||
apr_uid_current(&uid, &gid, msr->mp);
|
||||
rc = apr_uid_name_get(&userinfo, uid, msr->mp);
|
||||
if (rc != APR_SUCCESS) {
|
||||
userinfo = apr_psprintf(msr->mp, "%u", uid);
|
||||
}
|
||||
char *userinfo = get_username(msr->mp);
|
||||
|
||||
if (msr->txcfg->data_dir == NULL) {
|
||||
msr_log(msr, 1, "collection_retrieve_ex: Unable to retrieve collection (name \"%s\", key \"%s\"). Use "
|
||||
@ -345,7 +334,7 @@ cleanup:
|
||||
apr_sdbm_close(dbm);
|
||||
#ifdef GLOBAL_COLLECTION_LOCK
|
||||
apr_global_mutex_unlock(msr->modsecurity->dbm_lock);
|
||||
#endif
|
||||
ÿ |