![]() |
|
|||
File indexing completed on 2025-05-11 08:24:14
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup LibIOEnv 0007 * @brief User Environment Support 0008 */ 0009 0010 /* 0011 * COPYRIGHT (c) 1989-2011. 0012 * On-Line Applications Research Corporation (OAR). 0013 * 0014 * Modifications to support reference counting in the file system are 0015 * Copyright (c) 2012 embedded brains GmbH & Co. KG 0016 * 0017 * Redistribution and use in source and binary forms, with or without 0018 * modification, are permitted provided that the following conditions 0019 * are met: 0020 * 1. Redistributions of source code must retain the above copyright 0021 * notice, this list of conditions and the following disclaimer. 0022 * 2. Redistributions in binary form must reproduce the above copyright 0023 * notice, this list of conditions and the following disclaimer in the 0024 * documentation and/or other materials provided with the distribution. 0025 * 0026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0027 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0029 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0030 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0031 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0032 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0033 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0034 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0035 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0036 * POSSIBILITY OF SUCH DAMAGE. 0037 */ 0038 0039 #ifndef _RTEMS_USERENV_H 0040 #define _RTEMS_USERENV_H 0041 0042 /* 0043 * According to IEEE Std 1003.1-2001, 0044 * limits.h is supposed to provide _POSIX_LOGIN_NAME_MAX 0045 * XXX: We do not rely on this. 0046 */ 0047 #include <sys/param.h> 0048 #include <limits.h> 0049 0050 #include <rtems.h> 0051 #include <rtems/fs.h> 0052 0053 #ifdef __cplusplus 0054 extern "C" { 0055 #endif 0056 0057 /** 0058 * @defgroup LibIOEnv User Environment 0059 * 0060 * @ingroup LibIO 0061 * 0062 * @brief Provides a POSIX like user environment for tasks. 0063 */ 0064 /**@{**/ 0065 0066 #ifndef LOGIN_NAME_MAX 0067 #ifdef _POSIX_LOGIN_NAME_MAX 0068 #define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX 0069 #else 0070 /* Fallback */ 0071 #define LOGIN_NAME_MAX 9 0072 #endif 0073 #endif 0074 0075 typedef struct rtems_user_env_t rtems_user_env_t; 0076 0077 /** 0078 * @brief User environment. 0079 */ 0080 struct rtems_user_env_t { 0081 /** 0082 * @brief The anchor directory for relative paths. 0083 */ 0084 rtems_filesystem_global_location_t *current_directory; 0085 0086 /** 0087 * @brief The anchor directory for absolute paths. 0088 */ 0089 rtems_filesystem_global_location_t *root_directory; 0090 0091 /** 0092 * @brief The file mode creation mask. 0093 */ 0094 mode_t umask; 0095 0096 /** 0097 * @brief The real user ID. 0098 */ 0099 uid_t uid; 0100 0101 /** 0102 * @brief The real group ID. 0103 */ 0104 gid_t gid; 0105 0106 /** 0107 * @brief The effective user ID. 0108 */ 0109 uid_t euid; 0110 0111 /** 0112 * @brief The effective group ID. 0113 */ 0114 gid_t egid; 0115 0116 /** 0117 * @brief The login buffer. 0118 */ 0119 char login_buffer[LOGIN_NAME_MAX]; 0120 0121 /** 0122 * @brief The process group ID. 0123 */ 0124 pid_t pgrp; 0125 0126 /** 0127 * @brief The count of supplementary group IDs. 0128 */ 0129 size_t ngroups; 0130 0131 /** 0132 * @brief The list of supplementary group IDs. 0133 */ 0134 gid_t groups[NGROUPS]; 0135 }; 0136 0137 extern rtems_user_env_t rtems_global_user_env; 0138 0139 /** 0140 * @brief Fetch the pointer to the current user environment. 0141 * 0142 * If the task has a private user environment the pointer to it will be 0143 * returned. Otherwise the pointer to rtems_global_user_env will be returned. 0144 */ 0145 rtems_user_env_t * rtems_current_user_env_get(void); 0146 0147 #define rtems_current_user_env rtems_current_user_env_get() 0148 0149 #define rtems_filesystem_current (rtems_current_user_env->current_directory) 0150 #define rtems_filesystem_root (rtems_current_user_env->root_directory) 0151 #define rtems_filesystem_umask (rtems_current_user_env->umask) 0152 0153 #define _POSIX_types_Uid (rtems_current_user_env->uid) 0154 #define _POSIX_types_Gid (rtems_current_user_env->gid) 0155 #define _POSIX_types_Euid (rtems_current_user_env->euid) 0156 #define _POSIX_types_Egid (rtems_current_user_env->egid) 0157 #define _POSIX_types_Getlogin_buffer (rtems_current_user_env->login_buffer) 0158 0159 /** 0160 * @brief Creates a private environment. 0161 * 0162 * If the task has already a private environment nothing will be changed. This 0163 * function must be called from normal thread context and may block on a mutex. 0164 * Thread dispatching is disabled to protect some critical sections. 0165 * 0166 * The private environment internally uses a POSIX key. The key is added to the 0167 * configuration implicitly. But for each thread that uses a private environment 0168 * a key value pair has to be configured by the application. If only the global 0169 * environment is used there is no need to configure a key value pair. 0170 * 0171 * @retval RTEMS_SUCCESSFUL Successful operation. 0172 * @retval RTEMS_NO_MEMORY Not enough memory. 0173 * @retval RTEMS_UNSATISFIED Cloning of the current environment failed. 0174 * @retval RTEMS_TOO_MANY Cannot register the private environment. 0175 */ 0176 rtems_status_code rtems_libio_set_private_env(void); 0177 0178 /** 0179 * @brief Use the global environment. 0180 * 0181 * A private environment will be released. This function may be called from 0182 * every thread context. Thread dispatching is disabled to protect the 0183 * critical sections. 0184 */ 0185 void rtems_libio_use_global_env(void); 0186 0187 /** 0188 * @brief Gets the supplementary group IDs using the current user ID and 0189 * updates the table of supplementary group IDs in the current user 0190 * environment. 0191 * 0192 * In case of an error, the count of supplementary group IDs is set to zero. 0193 */ 0194 void rtems_current_user_env_getgroups(void); 0195 0196 /** @} */ 0197 0198 #ifdef __cplusplus 0199 } 0200 #endif 0201 0202 #endif 0203 /* end of include file */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |