Skip to content

Commit c2e20f6

Browse files
author
Marc Stern
authored
Merge pull request #2956 from marcstern/v2/mst/username
Centralized function to get user name Remark: only differences in persist_dbm.c are the calls to the centralized function, even if github cannot display individual diffs
2 parents 8549232 + afe4e12 commit c2e20f6

File tree

4 files changed

+822
-850
lines changed

4 files changed

+822
-850
lines changed

apache2/msc_logging.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,7 @@ static char *construct_auditlog_filename(apr_pool_t *mp, const char *uniqueid) {
234234
* This is required for mpm-itk & mod_ruid2, though should be harmless for other implementations
235235
* It also changes the return statement.
236236
*/
237-
char *userinfo;
238-
apr_status_t rc;
239-
apr_uid_t uid;
240-
apr_gid_t gid;
241-
apr_uid_current(&uid, &gid, mp);
242-
rc = apr_uid_name_get(&userinfo, uid, mp);
243-
if (rc != APR_SUCCESS) {
244-
userinfo = apr_psprintf(mp, "%u", uid);
245-
}
237+
char *userinfo = get_username(mp);
246238

247239
apr_time_exp_lt(&t, apr_time_now());
248240

apache2/msc_util.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,3 +2843,14 @@ char* strtok_r(
28432843
}
28442844
#endif
28452845

2846+
// Function compatible with Linux & Windows, also with mpm-itk & mod_ruid2
2847+
char* get_username(apr_pool_t* mp) {
2848+
char* username;
2849+
apr_uid_t uid;
2850+
apr_gid_t gid;
2851+
int rc = apr_uid_current(&uid, &gid, mp);
2852+
if (rc != APR_SUCCESS) return "apache";
2853+
rc = apr_uid_name_get(&username, uid, mp);
2854+
if (rc != APR_SUCCESS) return "apache";
2855+
return username;
2856+
}

apache2/msc_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ int DSOLOCAL tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
159159
int DSOLOCAL ip_tree_from_param(apr_pool_t *pool,
160160
char *param, TreeRoot **rtree, char **error_msg);
161161

162+
char DSOLOCAL *get_username(apr_pool_t* mp);
163+
162164
#ifdef WITH_CURL
163165
int ip_tree_from_uri(TreeRoot **rtree, char *uri,
164166
apr_pool_t *mp, char **error_msg);

0 commit comments

Comments
 (0)