#include #include #include #include #include #include #include #include #include main() { int res,parent_pid,child_pid; int new_role=4,old_role,wrong_role=0; union rsbac_attribute_value_t value; union rsbac_target_id_t tid; enum rsbac_attribute_t attr; /*get current process's role ID*/ parent_pid=getpid(); tid.process=parent_pid; res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); old_role=value.u_char_dummy; printf("%i My RC Role: %u\n",res,value.u_char_dummy); /*try to set new role*/ value.dummy=new_role; res=rsbac_set_attr(T_PROCESS,&tid,A_rc_role,&value); printf("Setting new role %u to process - (GRANTED)\n",value); /*get current process role ID*/ res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); printf("%i My RC Role: %u\n",res,value.u_char_dummy); /*try to set wrong role*/ value.dummy=wrong_role; res=rsbac_set_attr(T_PROCESS,&tid,A_rc_role,&value); printf("Setting new role %u to process - (NOT GRANTED)\n",value); /*get current process role ID*/ res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); printf("%i My RC Role: %u\n",res,value.u_char_dummy); /*try to set previous role*/ value.dummy=old_role; res=rsbac_set_attr(T_PROCESS,&tid,A_rc_role,&value); printf("Setting previos role %u to process - (GRANTED)\n",value); /*get current process role ID*/ res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); printf("%i My RC Role: %u\n",res,value.u_char_dummy); if(fork()==0) { child_pid=getpid(); /*this is a child process*/ printf("child pid: %u parent pid: %u\n",child_pid,parent_pid); /*get current settings*/ tid.process=child_pid; res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); printf("%i Child RC Role: %u\n",res,value.u_char_dummy); /*try to set new role to father*/ tid.process=parent_pid; value.dummy=new_role; res=rsbac_set_attr(T_PROCESS,&tid,A_rc_role,&value); printf("Setting new role %u to Father - (NOT GRANTED)\n",value); /*get current process role ID*/ res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); printf("%i Parent RC Role: %u\n",res,value.u_char_dummy); /*try to set own new role */ tid.process=child_pid; value.dummy=new_role; res=rsbac_set_attr(T_PROCESS,&tid,A_rc_role,&value); printf("Setting own new role %u - (GRANTED)\n",value); /*get current process role ID*/ res=rsbac_get_attr(T_PROCESS,&tid,A_rc_role,&value,0); printf("%i Child RC Role: %u\n",res,value.u_char_dummy); }else{ wait(&res); } }