Apache Portable Runtime
apr_user.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef APR_USER_H
00018 #define APR_USER_H
00019 
00020 /**
00021  * @file apr_user.h
00022  * @brief APR User ID Services 
00023  */
00024 
00025 #include "apr.h"
00026 #include "apr_errno.h"
00027 #include "apr_pools.h"
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif /* __cplusplus */
00032 
00033 /**
00034  * @defgroup apr_user User and Group ID Services
00035  * @ingroup APR 
00036  * @{
00037  */
00038 
00039 /**
00040  * Structure for determining user ownership.
00041  */
00042 #ifdef WIN32
00043 typedef PSID                      apr_uid_t;
00044 #else
00045 typedef uid_t                     apr_uid_t;
00046 #endif
00047 
00048 /**
00049  * Structure for determining group ownership.
00050  */
00051 #ifdef WIN32
00052 typedef PSID                      apr_gid_t;
00053 #else
00054 typedef gid_t                     apr_gid_t;
00055 #endif
00056 
00057 #if APR_HAS_USER 
00058 
00059 /**
00060  * Get the userid (and groupid) of the calling process
00061  * @param userid   Returns the user id
00062  * @param groupid  Returns the user's group id
00063  * @param p The pool from which to allocate working space
00064  * @remark This function is available only if APR_HAS_USER is defined.
00065  */
00066 APR_DECLARE(apr_status_t) apr_uid_current(apr_uid_t *userid,
00067                                           apr_gid_t *groupid,
00068                                           apr_pool_t *p);
00069 
00070 /**
00071  * Get the user name for a specified userid
00072  * @param username Pointer to new string containing user name (on output)
00073  * @param userid The userid
00074  * @param p The pool from which to allocate the string
00075  * @remark This function is available only if APR_HAS_USER is defined.
00076  */
00077 APR_DECLARE(apr_status_t) apr_uid_name_get(char **username, apr_uid_t userid,
00078                                            apr_pool_t *p);
00079 
00080 /**
00081  * Get the userid (and groupid) for the specified username
00082  * @param userid   Returns the user id
00083  * @param groupid  Returns the user's group id
00084  * @param username The username to lookup
00085  * @param p The pool from which to allocate working space
00086  * @remark This function is available only if APR_HAS_USER is defined.
00087  */
00088 APR_DECLARE(apr_status_t) apr_uid_get(apr_uid_t *userid, apr_gid_t *groupid,
00089                                       const char *username, apr_pool_t *p);
00090 
00091 /**
00092  * Get the home directory for the named user
00093  * @param dirname Pointer to new string containing directory name (on output)
00094  * @param username The named user
00095  * @param p The pool from which to allocate the string
00096  * @remark This function is available only if APR_HAS_USER is defined.
00097  */
00098 APR_DECLARE(apr_status_t) apr_uid_homepath_get(char **dirname, 
00099                                                const char *username, 
00100                                                apr_pool_t *p);
00101 
00102 /**
00103  * Compare two user identifiers for equality.
00104  * @param left One uid to test
00105  * @param right Another uid to test
00106  * @return APR_SUCCESS if the apr_uid_t strutures identify the same user,
00107  * APR_EMISMATCH if not, APR_BADARG if an apr_uid_t is invalid.
00108  * @remark This function is available only if APR_HAS_USER is defined.
00109  */
00110 #if defined(WIN32)
00111 APR_DECLARE(apr_status_t) apr_uid_compare(apr_uid_t left, apr_uid_t right);
00112 #else
00113 #define apr_uid_compare(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH)
00114 #endif
00115 
00116 /**
00117  * Get the group name for a specified groupid
00118  * @param groupname Pointer to new string containing group name (on output)
00119  * @param groupid The groupid
00120  * @param p The pool from which to allocate the string
00121  * @remark This function is available only if APR_HAS_USER is defined.
00122  */
00123 APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname, 
00124                                              apr_gid_t groupid, apr_pool_t *p);
00125 
00126 /**
00127  * Get the groupid for a specified group name
00128  * @param groupid Pointer to the group id (on output)
00129  * @param groupname The group name to look up
00130  * @param p The pool from which to allocate the string
00131  * @remark This function is available only if APR_HAS_USER is defined.
00132  */
00133 APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *groupid, 
00134                                       const char *groupname, apr_pool_t *p);
00135 
00136 /**
00137  * Compare two group identifiers for equality.
00138  * @param left One gid to test
00139  * @param right Another gid to test
00140  * @return APR_SUCCESS if the apr_gid_t strutures identify the same group,
00141  * APR_EMISMATCH if not, APR_BADARG if an apr_gid_t is invalid.
00142  * @remark This function is available only if APR_HAS_USER is defined.
00143  */
00144 #if defined(WIN32)
00145 APR_DECLARE(apr_status_t) apr_gid_compare(apr_gid_t left, apr_gid_t right);
00146 #else
00147 #define apr_gid_compare(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH)
00148 #endif
00149 
00150 #endif  /* ! APR_HAS_USER */
00151 
00152 /** @} */
00153 
00154 #ifdef __cplusplus
00155 }
00156 #endif
00157 
00158 #endif  /* ! APR_USER_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines