예제 #1
0
파일: 01-hash.c 프로젝트: 511860050/onion
void *t08_thread_write(onion_dict *d){
	int n=0;
	while (n!=N_READERS){
		int i;
		n=0;
		//ONION_DEBUG("Lock read");
		onion_dict_lock_read(d);
		//ONION_DEBUG("Got read lock");
		for (i=0;i<N_READERS;i++){
			char tmp[16];
			snprintf(tmp,16,"%d",i+1);
			const char *r=onion_dict_get(d,tmp);
			if (r)
				n++;
		}
		//ONION_DEBUG("Unlock");
		onion_dict_unlock(d);
		//ONION_DEBUG("Lock write");
		onion_dict_lock_write(d);
		//ONION_DEBUG("Got write lock");
		onion_dict_add(d, "test", "test", OD_DUP_ALL|OD_REPLACE);
		//ONION_DEBUG("Unlock");
		onion_dict_unlock(d);
		ONION_DEBUG("Found %d answers, should be %d.", n, N_READERS);
		usleep(200);
	}
	
	onion_dict_free(d);
	return (char*)1;
}
예제 #2
0
파일: 01-hash.c 프로젝트: 511860050/onion
char *t08_thread_read(onion_dict *d){
	char done=0;
	char *ret=NULL;
	while (!done){
		//ONION_DEBUG("Lock read");
		onion_dict_lock_write(d);
		//ONION_DEBUG("Got read lock");
		const char *test=onion_dict_get(d,"test");
		if (test){
			//ONION_DEBUG("Unlock");
			
			//onion_dict_lock_write(d);
			//ONION_DEBUG("Got write lock");
			char tmp[16];
			snprintf(tmp,16,"%d",onion_dict_count(d));
			onion_dict_remove(d,"test");
			onion_dict_add(d,tmp,"test",OD_DUP_ALL);
			ONION_DEBUG("Write answer %d", onion_dict_count(d));
			done=1;
			//ONION_DEBUG("Unlock");
			onion_dict_unlock(d);
			ret=(char*)1;
			break;
		}
		//ONION_DEBUG("Unlock");
		onion_dict_unlock(d);
		usleep(200);
	}
	//ONION_DEBUG("dict free");
	onion_dict_free(d);
	return ret;
}
예제 #3
0
/// Plexes the request depending on arguments.
int oterm_get_data(oterm_data *data, onion_request *req, onion_response *res){
  const char *username=onion_request_get_session(req,"username");
  if (!username){
    ONION_WARNING("Trying to enter authenticated area without username.");
    return OCS_FORBIDDEN;
  }
	oterm_session *o=(oterm_session*)onion_dict_get(data->sessions, onion_request_get_session(req,"username"));
	if (!o){
		o=oterm_session_new();
		onion_dict_lock_write(data->sessions);
		onion_dict_add(data->sessions,onion_request_get_session(req,"username"),o, 0);
		onion_dict_unlock(data->sessions);
	}
  const char *path=onion_request_get_path(req);

  ONION_DEBUG("Ask path %s (%p)", path, data);
  
  if (strcmp(path,"new")==0){
    if (onion_request_get_post(req, "command")){
      free(data->exec_command);
      data->exec_command=strdup(onion_request_get_post(req, "command"));
    }
    oterm_new(data, o, onion_request_get_session(req, "username"), onion_request_get_session(req, "nopam") ? 0 : 1 );
    return onion_shortcut_response("ok", 200, req, res);
  }
  if (strcmp(path,"status")==0)
    return oterm_status(o,req, res);

  return OCS_NOT_PROCESSED;
}
예제 #4
0
파일: 01-hash.c 프로젝트: 511860050/onion
void t09_thread_war_thread(onion_dict *d){
	int i;
	char tmp[16];
	for (i=0;i<WARLOOPS;i++){
		snprintf(tmp,16,"%04X",i);
		if (rand()%1){
			onion_dict_lock_read(d);
			onion_dict_get(d,tmp);
			onion_dict_unlock(d);
		}
		else{
			onion_dict_lock_write(d);
			onion_dict_add(d,tmp,tmp,OD_DUP_ALL|OD_REPLACE);
			onion_dict_unlock(d);
		}
	}
	onion_dict_free(d);
}
예제 #5
0
파일: oterm.c 프로젝트: angrygorilla/onion
int oterm_nopam(onion_handler *next, onion_request *req, onion_response *res){
	onion_dict *session=onion_request_get_session_dict(req);
	onion_dict_lock_write(session);
	const char *username=getenv("USER");
	if (username)
		onion_dict_add(session, "username", username, 0);
	onion_dict_add(session, "nopam", "true", 0);
	onion_dict_unlock(session);
	
	return onion_handler_handle(next, req, res);
}
예제 #6
0
파일: auth_pam.c 프로젝트: Andrepuel/onion
int onion_handler_auth_pam_handler(onion_handler_auth_pam_data *d, onion_request *request, onion_response *res){
	/// Use session to know if already logged in, so do not mess with PAM so often.
	if (onion_request_get_session(request, "pam_logged_in"))
		return onion_handler_handle(d->inside, request, res);
	
	const char *o=onion_request_get_header(request, "Authorization");
	char *auth=NULL;
	char *username=NULL;
	char *passwd=NULL;
	if (o && strncmp(o,"Basic",5)==0){
		//fprintf(stderr,"auth: '%s'\n",&o[6]);
		auth=onion_base64_decode(&o[6], NULL);
		username=auth;
		int i=0;
		while (auth[i]!='\0' && auth[i]!=':') i++;
		if (auth[i]==':'){
			auth[i]='\0'; // so i have user ready
			passwd=&auth[i+1];
		}
		else
			passwd=NULL;
	}
	
	// I have my data, try to authorize
	if (username && passwd){
		int ok=authorize(d->pamname, username, passwd);
		
		if (ok){ // I save the username at the session, so it can be accessed later.
			onion_dict *session=onion_request_get_session_dict(request);
			onion_dict_lock_write(session);
			onion_dict_add(session, "username", username, OD_REPLACE|OD_DUP_VALUE);
			onion_dict_add(session, "pam_logged_in", username, OD_REPLACE|OD_DUP_VALUE);
			onion_dict_unlock(session);
			
			free(auth);
			return onion_handler_handle(d->inside, request, res);
		}
	}
	if (auth)
		free(auth);

	
	// Not authorized. Ask for it.
	char temp[256];
	sprintf(temp, "Basic realm=\"%s\"",d->realm);
	onion_response_set_header(res, "WWW-Authenticate",temp);
	onion_response_set_code(res, HTTP_UNAUTHORIZED);
	onion_response_set_length(res,sizeof(RESPONSE_UNAUTHORIZED));
	
	onion_response_write(res,RESPONSE_UNAUTHORIZED,sizeof(RESPONSE_UNAUTHORIZED));
	return OCS_PROCESSED;
}