2 * user.c: APR wrapper functions for Subversion
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
25 #include <apr_pools.h>
32 /* Get the current user's name from the OS */
34 get_os_username(apr_pool_t *pool)
41 if (apr_uid_current(&uid, &gid, pool) == APR_SUCCESS &&
42 apr_uid_name_get(&username, uid, pool) == APR_SUCCESS)
49 /* Return a UTF8 version of STR, or NULL on error.
50 Use POOL for any necessary allocation. */
52 utf8_or_nothing(const char *str, apr_pool_t *pool) {
56 svn_error_t *err = svn_utf_cstring_to_utf8(&utf8_str, str, pool);
65 svn_user_get_name(apr_pool_t *pool)
67 const char *username = get_os_username(pool);
68 return utf8_or_nothing(username, pool);
72 svn_user_get_homedir(apr_pool_t *pool)
77 if (apr_env_get(&homedir, "HOME", pool) == APR_SUCCESS)
78 return utf8_or_nothing(homedir, pool);
80 username = get_os_username(pool);
81 if (username != NULL &&
82 apr_uid_homepath_get(&homedir, username, pool) == APR_SUCCESS)
83 return utf8_or_nothing(homedir, pool);