29 #include <oc_system_cfg.h> 37 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 42 .
Name =
"user manager" ,
45 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 53 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 57 oC_ErrorCode_t oC_UserMan_TurnOn(
void )
59 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
61 if(oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag ==
false , oC_ErrorCode_ModuleIsTurnedOn))
63 Users = oC_List_New(&
Allocator,AllocationFlags_NoWait);
68 errorCode = oC_ErrorCode_None;
69 oC_User_t root = oC_User_New(&
Allocator , AllocationFlags_NoWait ,
"root" , CFG_STRING_ROOT_PASSWORD , oC_User_Permissions_Root );
73 bool added = oC_List_PushBack(Users,root,&
Allocator);
74 oC_AssignErrorCodeIfFalse(&errorCode,added,oC_ErrorCode_CannotAddObjectToList);
78 errorCode = oC_ErrorCode_AllocationError;
84 errorCode = oC_ErrorCode_AllocationError;
93 oC_ErrorCode_t oC_UserMan_TurnOff(
void )
95 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
97 if(oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag ==
true , oC_ErrorCode_ModuleNotStartedYet))
100 errorCode = oC_ErrorCode_None;
102 oC_List_Foreach(Users,user)
104 if(oC_User_Delete(&user)==
false)
106 errorCode = oC_ErrorCode_CannotDeleteObject;
109 if(oC_List_Delete(Users,AllocationFlags_CanWaitForever) ==
false)
111 errorCode = oC_ErrorCode_ReleaseError;
120 oC_ErrorCode_t oC_UserMan_AddUser(
oC_User_t User )
122 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
126 ErrorCondition( oC_User_IsCorrect(User) , oC_ErrorCode_ObjectNotCorrect ) &&
127 ErrorCondition( !List_Contains((
oC_List_t)Users, &User,
sizeof(
oC_User_t)) , oC_ErrorCode_UserExists ) &&
128 ErrorCondition( iscurroot() || !oC_User_IsRoot(User) , oC_ErrorCode_PermissionDenied ) &&
129 ErrorCondition( 0 != strcmp(oC_User_GetName(User) ,
"unknown") , oC_ErrorCode_InvalidUserName )
132 bool added = oC_List_PushBack(Users, User, &
Allocator);
136 errorCode = oC_ErrorCode_None;
140 errorCode = oC_ErrorCode_CannotAddObjectToList;
149 oC_ErrorCode_t oC_UserMan_CreateAndAddUser(
const char * Name,
const char * Password, oC_User_Permissions_t Permissions )
151 oC_User_t user = oC_User_New(&
Allocator , AllocationFlags_CanWait1Second , Name , Password , Permissions );
152 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
156 errorCode = oC_ErrorCode_WrongParameters;
160 errorCode = oC_UserMan_AddUser(user);
163 if(oC_ErrorOccur(errorCode) && user !=
NULL)
165 oC_User_Delete(&user);
173 oC_ErrorCode_t oC_UserMan_RemoveUser(
oC_User_t User )
175 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
179 ErrorCondition( oC_User_IsCorrect(User) , oC_ErrorCode_ObjectNotCorrect) &&
180 ErrorCondition( User != getcuruser() , oC_ErrorCode_UserInUse) &&
181 ErrorCondition( !oC_User_IsRoot(User) , oC_ErrorCode_CannotRemoveRoot) &&
182 ErrorCondition( oC_User_CheckPermissions(getcuruser(), oC_User_GetPermissions(User)) , oC_ErrorCode_PermissionDenied) &&
183 ErrorCondition( List_Contains((
oC_List_t)Users, &User,
sizeof(
oC_User_t)) , oC_ErrorCode_UserNotExists)
186 bool removed = oC_List_RemoveAll(Users,User);
190 errorCode = oC_ErrorCode_None;
194 errorCode = oC_ErrorCode_CannotRemoveObjectFromList;
203 oC_List(
oC_User_t) oC_UserMan_GetList(
void )
216 oC_List_Foreach(Users,user)
218 if(oC_User_IsRoot(user))
230 oC_User_t oC_UserMan_GetUser(
const char * Name )
236 oC_List_Foreach(Users,user)
238 if(strcmp(oC_User_GetName(user),Name)==0)
251 oC_ErrorCode_t oC_UserMan_Rename(
oC_User_t User ,
const char * NewName )
253 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
257 ErrorCondition( oC_User_IsCorrect(User) , oC_ErrorCode_ObjectNotCorrect) &&
258 ErrorCondition( User != getcuruser() , oC_ErrorCode_UserInUse) &&
259 ErrorCondition( !oC_User_IsRoot(User) , oC_ErrorCode_PermissionDenied) &&
260 ErrorCondition( oC_User_CheckPermissions(getcuruser(), oC_User_GetPermissions(User)) , oC_ErrorCode_PermissionDenied ) &&
261 ErrorCondition( List_Contains((
oC_List_t)Users, &User,
sizeof(
oC_User_t)) , oC_ErrorCode_UserNotExists) &&
262 ErrorCondition( isaddresscorrect(NewName) , oC_ErrorCode_InvalidUserName) &&
263 ErrorCondition( 0 != strcmp(oC_User_GetName(User),
"root") , oC_ErrorCode_PermissionDenied) &&
264 ErrorCondition( 0 != strcmp(NewName ,
"root") , oC_ErrorCode_PermissionDenied) &&
265 ErrorCondition( 0 != strcmp(NewName ,
"unknown") , oC_ErrorCode_InvalidUserName)
268 if(oC_User_Rename(User, NewName))
270 errorCode = oC_ErrorCode_None;
274 errorCode = oC_ErrorCode_CannotRenameUser;
282 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
static bool ModuleEnabledFlag
identifier for allocations
File with interface for user system manager.
Definition of the null pointer.
static const oC_Allocator_t Allocator
#define NULL
pointer to a zero