MutexInfo * mutex_info(){ MutexInfo * ret = la_malloc(sizeof(MutexInfo)); ret->nmutexes = mutex_count; ret->descrs = la_malloc(mutex_count*sizeof(uint8_t*)); ret->ids = la_malloc(mutex_count*sizeof(uint64_t)); MutexNode * n = nodes; for(int i=0; n!=NULL ; i++ , n = n->next){ ret->ids[i]=n->m->id; ret->descrs[i]=n->m->name; } return ret; }
ldap_config_t * ldap_config_new( void ){ ldap_config_t *c = la_malloc( sizeof( ldap_config_t ) ); if( !c ) return NULL; la_memset (c, 0, sizeof( ldap_config_t ) ); return c; }
profile_config_t * profile_config_new ( void ){ profile_config_t *c = la_malloc( sizeof( profile_config_t ) ); if( !c ) return NULL; la_memset (c, 0, sizeof( profile_config_t ) ); c->search_scope = LA_SCOPE_ONELEVEL; return c; }
Process * newProcess(void * entry_point,uint64_t rax,uint64_t rdi, uint64_t rsi, uint64_t ppid,uint8_t fg){ void * stack_base = liballoc_alloc(INIT_STACK_PAGES); Process * ans = (Process *)la_malloc(sizeof(Process)); ans->entry_point = entry_point; ans->stack_base = stack_base; ans->stack_npages = INIT_STACK_PAGES; ans->stack_pointer = fillStackFrame(entry_point,toStackAddress(stack_base,ans->stack_npages),rax,rdi,rsi); ans->pid = pids++; ans->ppid = ppid; ans->fg = fg; return ans; }
static mutex * minit(mutex * m,uint8_t * name){ uint64_t v = disableScheduler(); m->m = 0; m->id = historic; m->name = name; MutexNode * n = la_malloc(sizeof(MutexNode)); n->m = m; n->next = nodes; n->waitn = 0; n->first = n->last = NULL; nodes = n; mutex_count ++; historic ++; enableScheduler(v); return m; }
void mutex_lock(mutex * m){ if(!itrylock(&(m->m))){ uint64_t v = disableScheduler(); MutexNode * mn = mutexnode_getbyid(m->id); pidnode * pidn = la_malloc(sizeof(pidnode)); pidn->pid = currPid(); if(mn->waitn == 0){ pidn->next = NULL; mn->first = mn->last = pidn; } else { mn->last->next = pidn; pidn->next = NULL; mn->last = pidn; } mn->waitn ++; enableScheduler(v); wait(); } }
OPENVPN_EXPORT int openvpn_plugin_func_v2 (openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[], void *per_client_context, struct openvpn_plugin_string_list **return_list) { ldap_context_t *context = (ldap_context_t *) handle; auth_context_t *auth_context = NULL; action_t *action = NULL; int res = OPENVPN_PLUGIN_FUNC_ERROR; if (type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY){ /* get username/password/auth_control_file from envp string array */ const char *username = get_env ("username", envp); const char *password = get_env ("password", envp); const char *auth_control_file = get_env ( "auth_control_file", envp ); const char *pf_file = get_env ("pf_file", envp); /* required parameters check */ if (!username){ LOGERROR("No username supplied to OpenVPN plugin"); return OPENVPN_PLUGIN_FUNC_ERROR; } auth_context = auth_context_new( ); if( !auth_context ){ LOGERROR( "Could not allocate auth_context before calling thread" ); return res; } if( username ) auth_context->username = strdup( username ); if( password ) auth_context->password = strdup( password ); if( pf_file ) auth_context->pf_file = strdup( pf_file ); if( auth_control_file ) auth_context->auth_control_file = strdup( auth_control_file ); /* If some argument were missing or could not be duplicate */ if( !(auth_context->username && auth_context->password && auth_context->auth_control_file ) ){ auth_context_free( auth_context ); return res; } action = action_new( ); action->type = LDAP_AUTH_ACTION_AUTH; action->context = auth_context; action->client_context = per_client_context; action->context_free_func = (void *)auth_context_free; action_push( context->action_list, action ); return OPENVPN_PLUGIN_FUNC_DEFERRED; } else if (type == OPENVPN_PLUGIN_ENABLE_PF){ /* unfortunately, at this stage we dont know anything about the client * yet. Let assume it is enabled, we will define default somewhere */ return OPENVPN_PLUGIN_FUNC_SUCCESS; }else if( type == OPENVPN_PLUGIN_CLIENT_CONNECT_V2 ){ /* on client connect, we return conf options through return list */ const char *username = get_env ("username", envp); client_context_t *cc = per_client_context; char *ccd_options = NULL; /* sanity check */ if (!username){ LOGERROR("No username supplied to OpenVPN plugin"); return OPENVPN_PLUGIN_FUNC_ERROR; } if (!cc || !cc->profile){ LOGERROR("No profile found for user"); return OPENVPN_PLUGIN_FUNC_ERROR; } #ifdef ENABLE_LDAPUSERCONF ccd_options = ldap_account_get_options_to_string( cc->ldap_account ); #endif if( cc->profile->redirect_gateway_prefix && strlen( cc->profile->redirect_gateway_prefix ) > 0 ){ /* do the username start with prefix? */ if( strncmp( cc->profile->redirect_gateway_prefix, username, strlen( cc->profile->redirect_gateway_prefix ) ) == 0 ){ char *tmp_ccd = ccd_options; ccd_options = strdupf("push \"redirect-gateway %s\"\n%s", cc->profile->redirect_gateway_flags ? cc->profile->redirect_gateway_flags : DFT_REDIRECT_GATEWAY_FLAGS, tmp_ccd ? tmp_ccd : ""); if( tmp_ccd ) la_free( tmp_ccd ); } } if( ccd_options ){ *return_list = la_malloc( sizeof( struct openvpn_plugin_string_list ) ); if( *return_list != NULL){ (*return_list)->next = NULL; (*return_list)->name = strdup( "config" ); (*return_list)->value = ccd_options; } } return OPENVPN_PLUGIN_FUNC_SUCCESS; } #ifdef ENABLE_LDAPUSERCONF else if( type == OPENVPN_PLUGIN_CLIENT_DISCONNECT ){ /* nothing done for now * potentially, session could be logged */ return OPENVPN_PLUGIN_FUNC_SUCCESS; } #endif return res; }