Example #1
0
/*---------------------------------------------------------------------------*/
void inicializar_historial()
{

   FILE *fichero;
   char orden[MAXORDEN];
   char c;
   int i;

   if((fichero=fopen(get_user_info(HISTORY),"r"))==NULL)
      //fprintf(stderr, "error leyendo del archivo .smallsh_history\n");
      ;
   else {
      c=getc(fichero);
      while (c!=EOF){
	 for(i=0;c!='\n';i++) {
	    orden[i]=c;
	    c=getc(fichero);
	 }
	 orden[i]='\0';
	 cola_metecadena(hc,orden);
	 c=getc(fichero); // asi tambien pasamos del último '\n'
      }
      fclose(fichero);
   }
}
Example #2
0
void create_account()
{
	make_config();
	gtk_widget_destroy(first_window);
	gtk_main_quit();
	get_user_info(data);
	gnusocialdesktop();
}
Example #3
0
/**
 * Is the user a real user account?
 * Checks:
 *   1. Not root
 *   2. UID is above the minimum configured.
 *   3. Not in banned user list
 * Returns NULL on failure
 */
struct passwd* check_user(const char *user) {
  if (strcmp(user, "root") == 0) {
    fprintf(LOGFILE, "Running as root is not allowed\n");
    fflush(LOGFILE);
    return NULL;
  }
  char *min_uid_str = get_value(MIN_USERID_KEY);
  int min_uid = DEFAULT_MIN_USERID;
  if (min_uid_str != NULL) {
    char *end_ptr = NULL;
    min_uid = strtol(min_uid_str, &end_ptr, 10);
    if (min_uid_str == end_ptr || *end_ptr != '\0') {
      fprintf(LOGFILE, "Illegal value of %s for %s in configuration\n", 
	      min_uid_str, MIN_USERID_KEY);
      fflush(LOGFILE);
      free(min_uid_str);
      min_uid_str = NULL;
      return NULL;
    }
    free(min_uid_str);
    min_uid_str = NULL;
  }
  struct passwd *user_info = get_user_info(user);
  if (NULL == user_info) {
    fprintf(LOGFILE, "User %s not found\n", user);
    fflush(LOGFILE);
    return NULL;
  }
  if (user_info->pw_uid < min_uid) {
    fprintf(LOGFILE, "Requested user %s has id %d, which is below the "
	    "minimum allowed %d\n", user, user_info->pw_uid, min_uid);
    fflush(LOGFILE);
    free(user_info);
    user_info = NULL;
    return NULL;
  }
  char **banned_users = get_values(BANNED_USERS_KEY);
  char **banned_user = (banned_users == NULL) ? 
    (char**) DEFAULT_BANNED_USERS : banned_users;
  for(; *banned_user; ++banned_user) {
    if (strcmp(*banned_user, user) == 0) {
      free(user_info);
      user_info = NULL;
      if (banned_users != (char**)DEFAULT_BANNED_USERS) {
        free_values(banned_users);
        banned_users = NULL;
      }
      fprintf(LOGFILE, "Requested user %s is banned\n", user);
      return NULL;
    }
  }
  if (banned_users != NULL && banned_users != (char**)DEFAULT_BANNED_USERS) {
    free_values(banned_users);
    banned_users = NULL;
  }
  return user_info;
}
Example #4
0
int jed_init_userinfo (void)
{
   (void) get_user_info ();

   if (-1 == SLadd_intrin_fun_table (User_Intrinsics, NULL))
     return -1;

   return 0;
}
UserInfo InstagramParser::parse_user_info(const std::string& json){
    Json::Value root;

    if(!reader.parse(json, root, false)){
        return "Failed to parse user info";
    }
    
    const Json::Value& data = root["data"];
    return get_user_info(data);
}
Example #6
0
int validate_username_password (char *user, char *passwd)
{
    struct user_db * p = get_user_info (user);

    if (!p)
        return -1;

    if (strcmp (p->password, passwd))
        return -1;
    return 0;
}
CommentInfo InstagramParser::get_comment_info(const Json::Value& comment){
    CommentInfo comment_info{};

    comment_info.set_text(comment["text"].asString());
    comment_info.set_id(comment["id"].asString());
    comment_info.set_created_time(std::stol(comment["created_time"].asString()));
    
    const Json::Value& from = comment["from"];
    comment_info.set_user_info(get_user_info(from));

    return comment_info;
}
Example #8
0
/*---------------------------------------------------------------------------*/
void user_inicializar()
{
   //1 desactivacion de la señal sigint y sigquit
   maneja_senales_int_quit(OFF);
   if(chdir(get_user_info(MIHOME)))
      fprintf(stderr, "smallsh: error cambiando al home\n");

   //inicializamos .smallsh_history
   hc=cola_crea(MAXHISTORY);
   inicializar_historial();
   user_inicializar_var_env();

}
UsersInfo InstagramParser::parse_users_info(const std::string& json){
    Json::Value root;
    if(!reader.parse(json, root, false)){
        return "Failed to parse users info";
    }
    
    const Json::Value& data = root["data"];
    UsersInfo users_info{};
    for(const Json::Value& user_info : data){
        users_info << get_user_info(user_info);
    }

    return users_info;
}
Example #10
0
/*---------------------------------------------------------------------------*/
void finalizar_historial()
{
   int i;
   FILE *fichero;

   // w+, creamos, o abrimos y sobreescribimos
   if((fichero=fopen(get_user_info(HISTORY),"w+"))==NULL)
      fprintf(stderr, "smallsh: error, no se puede abrir .smallsh_history\n");
                                                              
   for(i=0;i<=hc->ultimo-1;i++) {
      fprintf(fichero,"%s\n",hc->buff[i]);
   }
   fclose(fichero);
}
Example #11
0
int user_del (char *username)
{
    struct user_db *del = NULL;

    if (!username)
        return -1;

    if (!(del = get_user_info (username))) {
        return -1;
    }

    memset (del, 0, sizeof(struct user_db));

    return 0;
}
Example #12
0
int main(void)
{

  int baudrate = DEFAULT_BAUDRATE;
  unsigned char ch = DEFAULT_CHAR;

#ifdef INTERACTIVE
  get_user_info(&ch, &baudrate);
#endif
#ifdef SAPC
  set_baudrate(COM1, baudrate);
#endif

  /* do experiment--you fill in */
  return 0;
}
Example #13
0
static int  update_user_info (char *username, char *password, int priv_level)
{

    struct user_db * p = NULL;

    if (!(p = get_user_info (username)))
        return -1;

    if (priv_level >= 0) {
        if (p->priv_level != priv_level)
            p->priv_level = priv_level;
    }

    strncpy (p->password, password, MAX_USER_PASSWORD);

    return 0;
}
Example #14
0
/*---------------------------------------------------------------------------*/
char *user_getPrompt(void)
{
   char *directorio;	   //directorio actual de trabajo
   char *prompt;	   //aqui el prompt completo
   char *nombre;	   //nombre del usuario 

   
   directorio=getcwd(NULL,0); //directorio actual de trabajo
   nombre=get_user_info(NAME);
   prompt=malloc((strlen(directorio)+strlen(nombre)+4)*sizeof(char));
   strcpy(prompt,nombre);
   strcat(prompt,"@");  //offf asi se queda muy bonito
   strcat(prompt,directorio);
   strcat(prompt,":");
   free(directorio);
   return prompt; 
}
Example #15
0
File: init.c Project: amapig/ipmsg
void init_ipmsg()
{
    get_user_info();
    //encode
    utf8 = 0;
    if (setlocale(LC_CTYPE, "")) {
        if (!strcmp(nl_langinfo(CODESET), "UTF-8")) {
            utf8 = 1;
        }
    }

    init_mlist();
    init_ulist();
    init_sock();
    sem_init(&msg_empty, 0, 0);
    login();
}
Example #16
0
/* User information block re-programming
 * Make sure that data is aligned on 4 bytes boundary, and that size is a multiple of 4.
 */
static int dtplug_protocol_user_flash_update(struct dtplug_protocol_handle* handle,
											 struct packet* question, void* data, int size)
{
	int ret = 0;
	/* Erase the user flash information pages */
	ret = iap_erase_info_page(0, 2);
	if (ret != 0) {
		dtplug_protocol_send_reply(handle, question, ERROR_FLASH_ERASE, 0, NULL);
		return -1;
	}
	ret = iap_copy_ram_to_flash((uint32_t)get_user_info(), (uint32_t)data, size);
	if (ret != 0) {
		dtplug_protocol_send_reply(handle, question, ERROR_FLASH_WRITE, 0, NULL);
		return -1;
	}
	return 0;
}
Example #17
0
/*---------------------------------------------------------------------------*/
int user_cd(char **cline)
{   

   if(user_clasifica_entrada(*cline)==CD) {
      if(*(cline+1)==NULL) {
	 if(chdir(get_user_info(MIHOME))) {
	    fprintf(stderr,"smallsh: error cambiando de directorio.\n");
	    return 1;
	 }
	 return 0; //todo ha ido bien
      }
      else { //caso de tener un directorio al que cambiar
	 if(chdir(*(cline+1))) {
	    fprintf(stderr,"smallsh: error cambiando de directorio.\n");
	    return 1;
	 }
	 return 0;
      }	 
   }
   return 1;
}
Example #18
0
void on_login (int fd, struct message *msg)
{
	printf ("enter on login...\n");

	struct user_info user, *info;
	memset(&user, 0, sizeof(user));
	sscanf (msg->buff, "%s %s", user.name, user.password);
	
	/* get_user_base_info 返回的是该函数的内部静态变量的内存,
	 * 不需要释放返回的内存
	 * */
	info = get_user_info (user.name);
	if (info != NULL)
	{
		if (strcmp (info->password, user.password) == 0)
		{
			/* login success
			 * 把新登录的用户加入在线用户列表
			 * 发送登录成功反馈
			 * */
			user_online (fd);
			msg->buff[0] = 0;
			memcpy (&msg->buff[1], info, sizeof (struct user_info));

		}
		else
		{
			/*  密码错误 */
			msg->buff[0] = 1;
		}
	}
	else
	{
		/* 用户不存在 */
		msg->buff[0] = 2;
	}
	send_message (fd, msg);

	printf ("exit on login...\n");
}
Example #19
0
void on_register (int fd, struct message *msg)
{
	printf ("enter on register...\n");

	struct user_info user;
	memset (&user, 0, sizeof(user));
	sscanf (msg->buff, "%s %s %s", user.name, user.password, user.email);

	if ( get_user_info (user.name) == NULL)
	{
		add_user(&user);
		msg->buff[0] = 0;
	}
	else
	{
		/* 用户名已经存在,发送一个错误信息反馈给客户端
		 * */
		msg->buff[0] = 1;
	}
	send_message (fd, msg);

	printf ("exit on register...\n");
}
Example #20
0
/* 
 * Log in and wait for rootlist to be loaded
 */
void launch(void)
{   
    printf("Welcome to spotify_terminal\n");
    printf("Using libspotify %s\n", sp_build_id());
    init();
    
    get_user_info();
    printf("Logging in user: '******'... \n", username);
    usleep(500000);
    log_in();
    while(is_logged_in != TRUE) {
        sp_session_process_events(g_session, &next_timeout);
    }
    printf("Loading playlists... \n");
    usleep(500000);
    sp_session_process_events(g_session, &next_timeout);
    while(playlist_loaded != TRUE) {
        sp_session_process_events(g_session, &next_timeout);
    }
    printf("ready!\n");
    printf("> ");
    fflush(stdout);
}
Example #21
0
bool set_undo_file(void)
{
  struct user_info* uinfo;
  size_t sz   = 0;

  uinfo = get_user_info();
  
  replace_undo_home = uinfo->userdir;

  replace_undo_dir = get_undo_dir(uinfo);
  
  replace_undo_file = REPLACE_UNDO_FILE_NAME;

  sz = strlen(replace_undo_home) + strlen(replace_undo_dir) + strlen(replace_undo_file);

  replace_undo_path = NEW_STRING(sz);

  snprintf( replace_undo_path, sz+2 , "%s/%s",  replace_undo_dir, replace_undo_file );

#ifdef DEBUG_PATH
  fprintf(stderr, "[set_undo_file] replace_undo_home  [%s] \n", replace_undo_home );
  fprintf(stderr, "[set_undo_file] replace_undo_dir   [%s] \n", replace_undo_dir  );
  fprintf(stderr, "[set_undo_file] replace_undo_file  [%s] \n", replace_undo_file );
  fprintf(stderr, "[set_undo_file] replace_undo_path  [%s] \n", replace_undo_path );
#endif

#ifndef BOEHM_GC
  free_user_info(uinfo);
#else
  free(uinfo);
#endif
  
  if ( ! replace_undo_path ) 
    return false;

  return true;
}
Example #22
0
/*
 * parseCommandLine()
 *
 *	Parses the command line (argc, argv[]) and loads structures
 */
void
parseCommandLine(int argc, char *argv[])
{
	static struct option long_options[] = {
		{"old-datadir", required_argument, NULL, 'd'},
		{"new-datadir", required_argument, NULL, 'D'},
		{"old-bindir", required_argument, NULL, 'b'},
		{"new-bindir", required_argument, NULL, 'B'},
		{"old-options", required_argument, NULL, 'o'},
		{"new-options", required_argument, NULL, 'O'},
		{"old-port", required_argument, NULL, 'p'},
		{"new-port", required_argument, NULL, 'P'},

		{"username", required_argument, NULL, 'U'},
		{"check", no_argument, NULL, 'c'},
		{"link", no_argument, NULL, 'k'},
		{"retain", no_argument, NULL, 'r'},
		{"jobs", required_argument, NULL, 'j'},
		{"verbose", no_argument, NULL, 'v'},
		{NULL, 0, NULL, 0}
	};
	int			option;			/* Command line option */
	int			optindex = 0;	/* used by getopt_long */
	int			os_user_effective_id;
	FILE	   *fp;
	char	  **filename;
	time_t		run_time = time(NULL);

	user_opts.transfer_mode = TRANSFER_MODE_COPY;

	os_info.progname = get_progname(argv[0]);

	/* Process libpq env. variables; load values here for usage() output */
	old_cluster.port = getenv("PGPORTOLD") ? atoi(getenv("PGPORTOLD")) : DEF_PGUPORT;
	new_cluster.port = getenv("PGPORTNEW") ? atoi(getenv("PGPORTNEW")) : DEF_PGUPORT;

	os_user_effective_id = get_user_info(&os_info.user);
	/* we override just the database user name;  we got the OS id above */
	if (getenv("PGUSER"))
	{
		pg_free(os_info.user);
		/* must save value, getenv()'s pointer is not stable */
		os_info.user = pg_strdup(getenv("PGUSER"));
	}

	if (argc > 1)
	{
		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
		{
			usage();
			exit(0);
		}
		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
		{
			puts("pg_upgrade (PostgreSQL) " PG_VERSION);
			exit(0);
		}
	}

	/* Allow help and version to be run as root, so do the test here. */
	if (os_user_effective_id == 0)
		pg_fatal("%s: cannot be run as root\n", os_info.progname);

	if ((log_opts.internal = fopen_priv(INTERNAL_LOG_FILE, "a")) == NULL)
		pg_fatal("cannot write to log file %s\n", INTERNAL_LOG_FILE);

	while ((option = getopt_long(argc, argv, "d:D:b:B:cj:ko:O:p:P:rU:v",
								 long_options, &optindex)) != -1)
	{
		switch (option)
		{
			case 'b':
				old_cluster.bindir = pg_strdup(optarg);
				break;

			case 'B':
				new_cluster.bindir = pg_strdup(optarg);
				break;

			case 'c':
				user_opts.check = true;
				break;

			case 'd':
				old_cluster.pgdata = pg_strdup(optarg);
				old_cluster.pgconfig = pg_strdup(optarg);
				break;

			case 'D':
				new_cluster.pgdata = pg_strdup(optarg);
				new_cluster.pgconfig = pg_strdup(optarg);
				break;

			case 'j':
				user_opts.jobs = atoi(optarg);
				break;

			case 'k':
				user_opts.transfer_mode = TRANSFER_MODE_LINK;
				break;

			case 'o':
				old_cluster.pgopts = pg_strdup(optarg);
				break;

			case 'O':
				new_cluster.pgopts = pg_strdup(optarg);
				break;

				/*
				 * Someday, the port number option could be removed and passed
				 * using -o/-O, but that requires postmaster -C to be
				 * supported on all old/new versions.
				 */
			case 'p':
				if ((old_cluster.port = atoi(optarg)) <= 0)
				{
					pg_fatal("invalid old port number\n");
					exit(1);
				}
				break;

			case 'P':
				if ((new_cluster.port = atoi(optarg)) <= 0)
				{
					pg_fatal("invalid new port number\n");
					exit(1);
				}
				break;

			case 'r':
				log_opts.retain = true;
				break;

			case 'U':
				pg_free(os_info.user);
				os_info.user = pg_strdup(optarg);
				os_info.user_specified = true;

				/*
				 * Push the user name into the environment so pre-9.1
				 * pg_ctl/libpq uses it.
				 */
				pg_putenv("PGUSER", os_info.user);
				break;

			case 'v':
				pg_log(PG_REPORT, "Running in verbose mode\n");
				log_opts.verbose = true;
				break;

			default:
				pg_fatal("Try \"%s --help\" for more information.\n",
					   os_info.progname);
				break;
		}
	}

	/* label start of upgrade in logfiles */
	for (filename = output_files; *filename != NULL; filename++)
	{
		if ((fp = fopen_priv(*filename, "a")) == NULL)
			pg_fatal("cannot write to log file %s\n", *filename);

		/* Start with newline because we might be appending to a file. */
		fprintf(fp, "\n"
		"-----------------------------------------------------------------\n"
				"  pg_upgrade run on %s"
				"-----------------------------------------------------------------\n\n",
				ctime(&run_time));
		fclose(fp);
	}

	/* Turn off read-only mode;  add prefix to PGOPTIONS? */
	if (getenv("PGOPTIONS"))
	{
		char *pgoptions = psprintf("%s %s", FIX_DEFAULT_READ_ONLY,
									getenv("PGOPTIONS"));
		pg_putenv("PGOPTIONS", pgoptions);
		pfree(pgoptions);
	}
	else
		pg_putenv("PGOPTIONS", FIX_DEFAULT_READ_ONLY);

	/* Get values from env if not already set */
	check_required_directory(&old_cluster.bindir, NULL, "PGBINOLD", "-b",
							 "old cluster binaries reside");
	check_required_directory(&new_cluster.bindir, NULL, "PGBINNEW", "-B",
							 "new cluster binaries reside");
	check_required_directory(&old_cluster.pgdata, &old_cluster.pgconfig,
							 "PGDATAOLD", "-d", "old cluster data resides");
	check_required_directory(&new_cluster.pgdata, &new_cluster.pgconfig,
							 "PGDATANEW", "-D", "new cluster data resides");
}
Example #23
0
/* Common packets handlers.
 * Return 1 when packet has been handled, or 0 if the type is not a common one and some
 *   board or application specific code should take care of it.
 */
static int dtplug_protocol_common_handles(struct dtplug_protocol_handle* handle, struct packet* question)
{
	uint32_t tmp_val_swap = 0;
	/* These we can always handle */
	switch (question->info.type) {
		case PKT_TYPE_PING:
			question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */
			dtplug_protocol_send_reply(handle, question, NO_ERROR, 0, NULL); /* A ping needs no aditional data */
			dtplug_protocol_release_old_packet(handle);
			break;
		case PKT_TYPE_RESET:
			/* Software reset of the board. No way out. */
			NVIC_SystemReset();
			break;
		case PKT_TYPE_SET_TIME:
			{
				struct time_spec new_time, time_diff;
				uint32_t* seconds = (uint32_t*)question->data;
				uint16_t* msec = (uint16_t*)&(question->data[4]);
				uint8_t time_buff[6];
				if (question->info.seq_num & QUICK_DATA_PACKET) {
					dtplug_protocol_send_reply(handle, question, ERROR_IN_PKT_STRUCTURE, 0, NULL);
					break;
				}
				if (question->info.data.size != 6) {
					dtplug_protocol_send_reply(handle, question, ERROR_IN_DATA_VALUES, 0, NULL);
					break;
				}
				new_time.seconds = byte_swap_32(*seconds);
				new_time.msec = (uint16_t)byte_swap_16(*msec);
				if (!(question->info.seq_num & PACKET_NEEDS_REPLY)) {
					set_time(&new_time);
				} else {
					set_time_and_get_difference(&new_time, &time_diff);
					time_to_buff_swapped(time_buff, &time_diff);
					dtplug_protocol_send_reply(handle, question, NO_ERROR, 6, time_buff);
				}
			}
			dtplug_protocol_release_old_packet(handle);
			break;
		case PKT_TYPE_SET_USER_INFO:
			{
				uint8_t tmp_data[sizeof(struct user_info)] __attribute__ ((__aligned__(4))) = {};
				uint8_t offset = question->data[0];
				uint8_t size = question->data[1];
				if (question->info.seq_num & QUICK_DATA_PACKET) {
					dtplug_protocol_send_reply(handle, question, ERROR_IN_PKT_STRUCTURE, 0, NULL);
					break;
				}
				/* Check that amount of data provided is OK and does not go beyond user_info structure end */
				if ((question->info.data.size != (size + 2)) || ((offset + size) > sizeof(struct user_info))) {
					dtplug_protocol_send_reply(handle, question, ERROR_IN_DATA_VALUES, 0, NULL);
					break;
				}
				/* Copy all board data before flash erase */
				memcpy(tmp_data, get_user_info(), sizeof(struct user_info));
				/* Update information in the copy */
				memcpy(&(tmp_data[offset]), &(question->data[2]), size);
				/* Update the user flash information pages */
				if (dtplug_protocol_user_flash_update(handle, question, tmp_data, sizeof(struct user_info)) != 0) {
					/* Reply got sent, if return value is not 0 */
					break;
				}
			}
			/* Software reset of the board. No way out. */
			NVIC_SystemReset();
			break;
		case PKT_TYPE_GET_NUM_PACKETS:
			question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */
			tmp_val_swap = byte_swap_32(handle->packet_count);
			dtplug_protocol_send_reply(handle, question, NO_ERROR, 4, (uint8_t*)(&tmp_val_swap));
			dtplug_protocol_release_old_packet(handle);
			break;
		case PKT_TYPE_GET_ERRORS:
			question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */
			dtplug_protocol_send_reply(handle, question, NO_ERROR, 0, NULL); /* Error handling code will take care of filling the message */
			dtplug_protocol_release_old_packet(handle);
			break;
		case PKT_TYPE_GET_NUM_ERRORS:
			question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */
			tmp_val_swap = byte_swap_32(handle->errors_count);
			dtplug_protocol_send_reply(handle, question, NO_ERROR, 4, (uint8_t*)(&tmp_val_swap));
			dtplug_protocol_release_old_packet(handle);
			break;
		default:
			/* We do not handle this type, it must be a board specific one */
			return 0;
	}
	/* Packet handled */
	status_led(green_off);
	return 1;
}
Example #24
0
void update_user_info()
{
	get_user_info(data);
	gtk_widget_destroy(w1);
	gtk_main_quit();
}
Example #25
0
// generate content takes the request rec and a file_t pointing to the
// already opened file from the request
// it adds the html information surrounding the body then loops
// over the names in the file and prints their coordinates
static int generate_content(request_rec *r, apr_file_t *fd) {
	// initialization
	char buf[MAX_BUF_LENGTH];
	apr_status_t rv;
	apr_file_t *name_data;
	const char * cookies;
	char * user = NULL;
	char * groups = NULL;
	moon_svr_cfg* cfg = ap_get_module_config(r->server->module_config, &moon_module);

	// get the cookies string from the request, retrieve the data
	// about a user and set the user and groups strings
	cookies = get_cookies_from_request(r);
	if(cookies != NULL) {
		rv = get_user_info(r, cookies, &user, &groups);
		if(rv != OK) {
			return rv;
		}
	}
	
	// set the reponse content type
	ap_set_content_type(r, "text/html;charset=ascii");

	// send initial html data
	ap_rputs(DOCTYPE, r);
	ap_rputs(OPEN_HTML_AND_HEAD, r);
	ap_rputs(TITLE, r);
	
	add_user_css(r, cfg, user);
	add_group_css(r, cfg, groups);

	ap_rputs(CLOSE_HEAD_OPEN_BODY, r);
	// check headers and return cookie, if NULL then no cookie set
	if(cookies != NULL && user != NULL) {
		add_user_info(r, user, groups);
	}
	else {
		add_anonymous_info(r);
	}

	// loop over file, get the next place
	// and print information about that place
	while(1) {
		rv = get_next_place(r, fd, buf);
		if(rv != OK) {
			if(rv==DONE) {
				break;
			} else {
				return rv;
			}
		}
		rv = get_place_coordinates(r, buf);
		ap_rprintf(r, "\n\t\t<p>\n\t\tCoordinates: %s\t\t</p>", buf);
		if(rv != OK) {
			return rv;
		}
	}	

	// cleanup and return 
	ap_rputs(CLOSE_HTML, r);
	return OK;
}
UserInfo InstagramClient::get_user_info(){
    return get_user_info(SELF);
}
Example #27
0
static int
imap_login(struct imap_context *ctx, struct imap_request *req, void *priv)
{
    struct bufferevent *client_bev = ctx->client_bev;
    struct evbuffer *output;
    struct user_info user_info = {};
    char *attrs[2] = { "mailhost", NULL };
    char *p, *arg;
    ssize_t len, len_domain;
    int rc = IMAP_DONE;

    output = bufferevent_get_output(client_bev);
    arg = req->arguments.bv_val;

    // temporarily until we have a way of handling literals
    if (*arg == '{' || *arg == '"') {
        evbuffer_add_printf(output, "%s BAD Sorry, I don't handle literals yet" CRLF, req->tag.bv_val);
        return IMAP_OK;
    }

    p = strchr(arg, ' ');
    if (!p) {
        evbuffer_add_printf(output, "%s NO Invalid command" CRLF, req->tag.bv_val);
        return IMAP_OK;
    }

    len = p - arg; // length of whole "username@domain"

    p = user_info.username.bv_val = malloc(len + 1);
    memcpy(p, arg, len);
    p[len] = '\0';

    p = memchr(user_info.username.bv_val, '@', len);
    if (p) {
        len = p - user_info.username.bv_val;
        p++;
    } else {
        // use a default domain
        p = ctx->driver->config->default_host;
    }
    user_info.username.bv_len = len;
    ber_str2bv(p, 0, 0, &(user_info.domain));

    user_info.attrs = attrs;
    if (get_user_info(ctx->driver->ldap, &user_info, search_cb, ctx)) {
        evbuffer_add_printf(output, "%s NO Internal server error", req->tag.bv_val);
        rc = IMAP_SHUTDOWN;
    }

    /*
    server_bev = bufferevent_socket_new(ctx->driver->base, -1, BEV_OPT_CLOSE_ON_FREE);
    bufferevent_enable(server_bev, EV_READ|EV_WRITE);
    bufferevent_socket_connect_hostname(server_bev, ctx->driver->dnsbase, AF_UNSPEC, servername, ctx->driver->config->default_port);
    bufferevent_setcb(server_bev, NULL, NULL, server_connect_cb, ctx);

    // copy over client data, CRLF in request has been skipped, so append that
    bufferevent_write(server_bev, req->line.bv_val, req->line.bv_len);
    bufferevent_write(server_bev, CRLF, 2);

    ctx->server_bev = server_bev;
    */

    /* stop reading on the connection until we're connected to server */
    bufferevent_disable(client_bev, EV_READ);

    return rc;
}
Example #28
0
void OS_get_table()
{
    /* dir walker storage */
    DIR             *dir;
    struct dirent   *dir_ent, *dir_result;
    
    /* all our storage is going to be here */
    struct obstack  mem_pool;
    
    /* container for scaped process values */
    struct procstat *prs;

    /* string containing our local copy of format_str, elements will be
     * lower cased if we are able to figure them out */
    char            *format_str;

    /* initlize a small memory pool for this function */
    obstack_init(&mem_pool);

    /* put the dirent on the obstack, since it's rather large */
    dir_ent = obstack_alloc(&mem_pool, sizeof(struct dirent));

    if ((dir = opendir("/proc")) == NULL)
        return;

    /* Iterate through all the process entries (numeric) under /proc */
    while(readdir_r(dir, dir_ent, &dir_result) == 0 && dir_result) {

        /* Only look at this file if it's a proc id; that is, all numbers */
        if(!is_pid(dir_result->d_name))
            continue;

        /* allocate container for storing process values */
        prs = obstack_alloc(&mem_pool, sizeof(struct procstat));
        bzero(prs, sizeof(struct procstat));

        /* intilize the format string */
        obstack_printf(&mem_pool, get_string(STR_DEFAULT_FORMAT));
        obstack_1grow(&mem_pool, '\0');
        format_str = (char *) obstack_finish(&mem_pool);

        /* get process' uid/guid */
        get_user_info(dir_result->d_name, format_str, prs, &mem_pool);

        /* scrape /proc/${pid}/stat */
        if (get_proc_stat(dir_result->d_name, format_str, prs, &mem_pool) == false) {
            /* did the pid directory go away mid flight? */
            if (pid_exists(dir_result->d_name, &mem_pool) == false)
                continue;
        }

        /* correct values (times) found in /proc/${pid}/stat */
        fixup_stat_values(format_str, prs);

		/* get process' cmndline */
		get_proc_cmndline(dir_result->d_name, format_str, prs, &mem_pool);

        /* get process' cwd & exec values from the symblink */
        eval_link(dir_result->d_name, "cwd", F_CWD, &prs->cwd, format_str,
            &mem_pool);
        eval_link(dir_result->d_name, "exe", F_EXEC, &prs->exec, format_str,
            &mem_pool);

        /* scapre from /proc/{$pid}/status */
        get_proc_status(dir_result->d_name, format_str, prs, &mem_pool);

		/* calculate precent cpu & mem values */
		calc_prec(format_str, prs, &mem_pool);

        /* Go ahead and bless into a perl object */
        bless_into_proc(format_str, field_names,
            prs->uid,			
            prs->gid,			
            prs->pid,			
            prs->comm,			
            prs->ppid,			
            prs->pgrp,			
            prs->sid,			
            prs->tty,			
            prs->flags,			
            prs->minflt,		
            prs->cminflt,		
            prs->majflt,		
            prs->cmajflt,		
            prs->utime,			
            prs->stime,			
            prs->cutime,		
            prs->cstime,		
            prs->priority,		
            prs->start_time,	
            prs->vsize,			
            prs->rss,			
            prs->wchan,			
	    prs->time,			
	    prs->ctime,			
            prs->state,			
            prs->euid,
            prs->suid,
            prs->fuid,
            prs->egid,
            prs->sgid,
            prs->fgid,
            prs->pctcpu,
            prs->pctmem,
            prs->cmndline,
            prs->exec,
            prs->cwd
        );

        /* we want a new prs, for the next itteration */
        obstack_free(&mem_pool, prs);
    }
    
    closedir(dir);

    /* free all our tempoary memory */
    obstack_free(&mem_pool, NULL);
}
Example #29
0
File: option.c Project: hl0103/pgxc
/*
 * parseCommandLine()
 *
 *	Parses the command line (argc, argv[]) and loads structures
 */
void
parseCommandLine(int argc, char *argv[])
{
	static struct option long_options[] = {
		{"old-datadir", required_argument, NULL, 'd'},
		{"new-datadir", required_argument, NULL, 'D'},
		{"old-bindir", required_argument, NULL, 'b'},
		{"new-bindir", required_argument, NULL, 'B'},
		{"old-port", required_argument, NULL, 'p'},
		{"new-port", required_argument, NULL, 'P'},

		{"user", required_argument, NULL, 'u'},
		{"check", no_argument, NULL, 'c'},
		{"debug", no_argument, NULL, 'g'},
		{"debugfile", required_argument, NULL, 'G'},
		{"link", no_argument, NULL, 'k'},
		{"logfile", required_argument, NULL, 'l'},
		{"verbose", no_argument, NULL, 'v'},
		{NULL, 0, NULL, 0}
	};
	int			option;			/* Command line option */
	int			optindex = 0;	/* used by getopt_long */
	int			os_user_effective_id;

	user_opts.transfer_mode = TRANSFER_MODE_COPY;

	os_info.progname = get_progname(argv[0]);

	/* Process libpq env. variables; load values here for usage() output */
	old_cluster.port = getenv("PGPORT") ? atoi(getenv("PGPORT")) : DEF_PGPORT;
	new_cluster.port = getenv("PGPORT") ? atoi(getenv("PGPORT")) : DEF_PGPORT;

	os_user_effective_id = get_user_info(&os_info.user);
	/* we override just the database user name;  we got the OS id above */
	if (getenv("PGUSER"))
	{
		pg_free(os_info.user);
		/* must save value, getenv()'s pointer is not stable */
		os_info.user = pg_strdup(getenv("PGUSER"));
	}

	if (argc > 1)
	{
		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ||
			strcmp(argv[1], "-?") == 0)
		{
			usage();
			exit(0);
		}
		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
		{
			puts("pg_upgrade (PostgreSQL) " PG_VERSION);
			exit(0);
		}
	}

	/* Allow help and version to be run as root, so do the test here. */
	if (os_user_effective_id == 0)
		pg_log(PG_FATAL, "%s: cannot be run as root\n", os_info.progname);

	getcwd(os_info.cwd, MAXPGPATH);

	while ((option = getopt_long(argc, argv, "d:D:b:B:cgG:kl:p:P:u:v",
								 long_options, &optindex)) != -1)
	{
		switch (option)
		{
			case 'b':
				old_cluster.bindir = pg_strdup(optarg);
				break;

			case 'B':
				new_cluster.bindir = pg_strdup(optarg);
				break;

			case 'c':
				user_opts.check = true;
				break;

			case 'd':
				old_cluster.pgdata = pg_strdup(optarg);
				break;

			case 'D':
				new_cluster.pgdata = pg_strdup(optarg);
				break;

			case 'g':
				pg_log(PG_REPORT, "Running in debug mode\n");
				log_opts.debug = true;
				break;

			case 'G':
				if ((log_opts.debug_fd = fopen(optarg, "w")) == NULL)
				{
					pg_log(PG_FATAL, "cannot open debug file\n");
					exit(1);
				}
				break;

			case 'k':
				user_opts.transfer_mode = TRANSFER_MODE_LINK;
				break;

			case 'l':
				log_opts.filename = pg_strdup(optarg);
				break;

			case 'p':
				if ((old_cluster.port = atoi(optarg)) <= 0)
				{
					pg_log(PG_FATAL, "invalid old port number\n");
					exit(1);
				}
				break;

			case 'P':
				if ((new_cluster.port = atoi(optarg)) <= 0)
				{
					pg_log(PG_FATAL, "invalid new port number\n");
					exit(1);
				}
				break;

			case 'u':
				pg_free(os_info.user);
				os_info.user = pg_strdup(optarg);

				/*
				 * Push the user name into the environment so pre-9.1
				 * pg_ctl/libpq uses it.
				 */
				pg_putenv("PGUSER", os_info.user);
				break;

			case 'v':
				pg_log(PG_REPORT, "Running in verbose mode\n");
				log_opts.verbose = true;
				break;

			default:
				pg_log(PG_FATAL,
					   "Try \"%s --help\" for more information.\n",
					   os_info.progname);
				break;
		}
	}

	if (log_opts.filename != NULL)
	{
		/*
		 * We must use append mode so output generated by child processes via
		 * ">>" will not be overwritten, and we want the file truncated on
		 * start.
		 */
		/* truncate */
		if ((log_opts.fd = fopen(log_opts.filename, "w")) == NULL)
			pg_log(PG_FATAL, "cannot write to log file %s\n", log_opts.filename);
		fclose(log_opts.fd);
		if ((log_opts.fd = fopen(log_opts.filename, "a")) == NULL)
			pg_log(PG_FATAL, "cannot write to log file %s\n", log_opts.filename);
	}
	else
		log_opts.filename = strdup(DEVNULL);

	/* if no debug file name, output to the terminal */
	if (log_opts.debug && !log_opts.debug_fd)
	{
		log_opts.debug_fd = fopen(DEVTTY, "w");
		if (!log_opts.debug_fd)
			pg_log(PG_FATAL, "cannot write to terminal\n");
	}

	/* Get values from env if not already set */
	validateDirectoryOption(&old_cluster.bindir, "OLDBINDIR", "-b",
							"old cluster binaries reside");
	validateDirectoryOption(&new_cluster.bindir, "NEWBINDIR", "-B",
							"new cluster binaries reside");
	validateDirectoryOption(&old_cluster.pgdata, "OLDDATADIR", "-d",
							"old cluster data resides");
	validateDirectoryOption(&new_cluster.pgdata, "NEWDATADIR", "-D",
							"new cluster data resides");

	get_pkglibdirs();
}
Example #30
0
int
main(int argc, char *argv[])
{
    int             retval = 0,
                    result = 0,
                    debuglvl = 0;
    VuurmuurScript  vr_script;

    static char     optstring[] = "CRDMPLB:AOo:g:n:z:s:i:r:V:S:hc:d:v";
    static int      version_flag = 0;
    static int      apply_flag = 0;
    static int      no_apply_flag = 0;
    static int      reload_flag = 0;
    static int      print_linenum_flag = 0;
    char            tmp_set[sizeof(vr_script.set)] = "";
    char            *str = NULL;

    static struct option long_options[] =
    {
        /* commands */
        {"create",      0, NULL, 'C'},
        {"delete",      0, NULL, 'D'},
        {"rename",      0, NULL, 'R'},
        {"modify",      0, NULL, 'M'},
        {"print",       0, NULL, 'P'},
        {"list",        0, NULL, 'L'},

        {"block",       1, NULL, 0},
        {"unblock",     1, NULL, 0},
        {"list-blocked",0, NULL, 0},
        {"list-paths",  0, NULL, 0},

        /* object name */
        {"variable",    1, NULL, 'V'},
        {"set",         1, NULL, 'S'},

        {"append",      0, NULL, 'A'},
        {"overwrite",   0, NULL, 'O'},

        /* object types */
        {"host",        1, NULL, 'o'},  /* h we use for help */
        {"group",       1, NULL, 'g'},
        {"network",     1, NULL, 'n'},
        {"zone",        1, NULL, 'z'},
        {"service",     1, NULL, 's'},
        {"interface",   1, NULL, 'i'},
        {"rule",        1, NULL, 'r'},

        /* options */
        {"apply",       0, &apply_flag, 1},
        {"no-apply",    0, &no_apply_flag, 1},
        {"reload",      0, &reload_flag, 1},

        /* print options */
        {"rule-numbers",0, &print_linenum_flag, 1},

        {"verbose",     0, NULL, 'v'},
        {"debug",       0, NULL, 'd'},
        {"version",     0, &version_flag, 1},
        {"help",        0, NULL, 'h'},
        {NULL,          0, NULL, 0}
    };
    int opt = 0,
        longopt_index = 0;

    /* initialize our central data structure */
    memset(&vr_script, 0, sizeof(vr_script));
    vr_script.overwrite = TRUE;

    /* get the current user */
    get_user_info(debuglvl, &user_data);

    /*  exit if the user is not root. */
    if(user_data.user > 0 || user_data.group > 0)
    {
        fprintf(stdout, "Error: you are not root! Exitting.\n");
        exit(VRS_ERR_COMMANDLINE);
    }

    /* assemble version string */
    snprintf(version_string, sizeof(version_string), "%s (using libvuurmuur %s)", VUURMUUR_VERSION, libvuurmuur_get_version());

    /* init the print functions: all to stdout */
    vrprint.logger = "vuurmuur_scrp";
    vrprint.error = libvuurmuur_stdoutprint_error;
    vrprint.warning = libvuurmuur_stdoutprint_warning;
    vrprint.info = libvuurmuur_stdoutprint_info;
    vrprint.debug = libvuurmuur_stdoutprint_debug;
    vrprint.username = user_data.realusername;
    vrprint.audit = libvuurmuur_stdoutprint_audit;

    /* registering signals we use */
    if(signal(SIGINT, &catch_sigint) == SIG_ERR)
    {
        fprintf(stdout, "Error: couldn't attach the signal SIGINT to the signal handler.\n");
        exit(VRS_ERR_INTERNAL);
    }
    if(signal(SIGHUP, &catch_sighup) == SIG_ERR)
    {
        fprintf(stdout, "Error: couldn't attach the signal SIGHUP to the signal handler.\n");
        exit(VRS_ERR_INTERNAL);
    }

    /* handle commandline options that don't require a config so they can be
     * used by the wizard. */
    if (argc > 1 && strcmp(argv[1], "--list-devices") == 0) {
        script_list_devices(debuglvl);
        exit(EXIT_SUCCESS);
    }

    /* some initilization */
    if(pre_init_config(&conf) < 0)
        exit(VRS_ERR_INTERNAL);

    /* prepare for later shm connection */
    shm_table = NULL;
    sem_id = 0;

    /* Process commandline options */
    longopt_index = 0;
    optind = 0; /* reset optind */
    while((opt = getopt_long(argc, argv, optstring, long_options, &longopt_index)) >= 0)
    {
        switch(opt)
        {
            /* first handle the longoption only options */
            case 0:
                /* If this option set a flag, do nothing else now. */

                if(long_options[longopt_index].flag != NULL)
                    break;
                if(strcmp(long_options[longopt_index].name, "block") == 0)
                {
                    /* block
                     *
                     * usage is vuurmuur_script --block 1.2.3.4
                     * this means we have to add a rule to the blocklist like this:
                     * vuurmuur_script -M -r blocklist -V RULE --set "block 1.2.3.4" --append --apply
                     */
                    vr_script.cmd = CMD_BLK;    /* we will change this to -M later */

                    /* -V RULE */
                    if(strlcpy(vr_script.var, "RULE", sizeof(vr_script.var)) >= sizeof(vr_script.var))
                    {
                        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR,
                                "could not set variable: internal argument 'RULE' too long (max: %d).",
                                (int)sizeof(vr_script.var)-1);
                        exit(VRS_ERR_COMMANDLINE);
                    }

                    /* --set "block 1.2.3.4" */
                    if(snprintf(tmp_set, sizeof(tmp_set), "block %s", optarg) >= (int)sizeof(tmp_set))
                    {
                        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR,
                                "could not set ip address: argument too long (max: %d).",
                                (int)sizeof(tmp_set)-1);
                        exit(VRS_ERR_COMMANDLINE);
                    }
                    if(strlcpy(vr_script.set, tmp_set, sizeof(vr_script.set)) >= sizeof(vr_script.set))
                    {
                        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR,
                                "could not set ip address: argument too long (max: %d).",
                                (int)sizeof(vr_script.set)-1);
                        exit(VRS_ERR_COMMANDLINE);
                    }

                    /* -r blocklist */
                    vr_script.type = TYPE_RULE;

                    if(strlcpy(vr_script.name, "blocklist", sizeof(vr_script.name)) >= sizeof(vr_script.name))
                    {
                        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR,
                                "rule (-r/--rule): internal argument too long (max: %d).",
                                (int)sizeof(vr_script.name)-1);
                        exit(VRS_ERR_COMMANDLINE);
                    }

                    /* --apply */
                    vr_script.apply = TRUE;
                }
                else if(strcmp(long_options[longopt_index].name, "unblock") == 0)
                {
                    /* unblock an ip
                     * more difficult than blocking... for the logic see script_unblock.c!
                     */
                    vr_script.cmd = CMD_UBL;

                    if(strlcpy(vr_script.set, optarg, sizeof(vr_script.set)) >= sizeof(vr_script.set))
                    {
                        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR,
                            "could not set object to unblock: argument too long (max: %d).",
                            (int)sizeof(vr_script.set)-1);
                        exit(VRS_ERR_COMMANDLINE);
                    }

                    vr_script.type = TYPE_RULE;

                    /* --apply */
                    vr_script.apply = TRUE;
                    break;
                }
                else if(strcmp(long_options[longopt_index].name, "list-blocked") == 0)
                {
                    vr_script.type = TYPE_RULE;
                    vr_script.cmd = CMD_LBL;
                    break;
                }
                else if(strcmp(long_options[longopt_index].name, "list-paths") == 0)
                {
                    printf("SYSCONFDIR %s\n", conf.etcdir);
                    printf("VUURMUURCONFDIR %s/vuurmuur\n", conf.etcdir);
                    printf("CONFIGFILE %s\n", conf.configfile);
                    printf("PLUGINDIR %s\n", conf.plugdir);
                    printf("DATADIR %s\n", conf.datadir);
                    exit(EXIT_SUCCESS);
                }
                else
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR,
                        "unknown option '%s'. See --help for valid options.",
                        long_options[longopt_index].name);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'c' :

                /* config file */
                if(conf.verbose_out == TRUE)
                    fprintf(stdout, "Using this configfile: %s\n", optarg);

                if(strlcpy(conf.configfile, optarg, sizeof(conf.configfile)) >= sizeof(conf.configfile))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "configfile (-c): argument too long (max: %d).", (int)sizeof(conf.configfile)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'd' :

                /* debugging */
                fprintf(stdout, "vuurmuur: debugging enabled.\n");

                /* convert the debug string and check the result */
                debuglvl = atoi(optarg);
                if(debuglvl < 0 || debuglvl > HIGH)
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "illegal debug level: %d (max: %d)", debuglvl, HIGH);
                    exit(VRS_ERR_COMMANDLINE);
                }

                fprintf(stdout, "vuurmuur: debug level: %d\n", debuglvl);
                break;


            case '?' :
            case 'h' :

                /* help */
                fprintf(stdout, "Usage: vuurmuur_script [OPTIONS]\n");
                fprintf(stdout, "\n");
                fprintf(stdout, "Options:\n");
                fprintf(stdout, " -d [1 - 3]\t\t\tenables debugging, 1 low, 3 high\n");
                fprintf(stdout, " -h, --help\t\t\tgives this help\n");
                fprintf(stdout, " -v, --verbose\t\t\tverbose mode.\n");
                fprintf(stdout, "\n");

                fprintf(stdout, "Commands:\n");
                fprintf(stdout, "     --block <name>\t\tblock host/group or ipaddress.\n");
                fprintf(stdout, "     --unblock <name>\t\tunblock host/group or ipaddress.\n");
                fprintf(stdout, "     --list-blocked\t\tlist the hosts/group and ipaddresses that are blocked.\n");
                fprintf(stdout, "     --reload\t\t\tmake Vuurmuur reload it's config\n");
                fprintf(stdout, "\n");
                fprintf(stdout, " -C, --create\t\t\tcreate object.\n");
                fprintf(stdout, " -D, --delete\t\t\tdelete object.\n");
                fprintf(stdout, " -R, --rename\t\t\trename object.\n");
                fprintf(stdout, " -M, --modify\t\t\tmodify object.\n");
                fprintf(stdout, " -L, --list  \t\t\tlist objects.\n");
                fprintf(stdout, " -P, --print \t\t\tprint data of object.\n");
                fprintf(stdout, "\n");

                fprintf(stdout, "Object:\n");
                fprintf(stdout, " -o, --host <name>\t\thost.\n");
                fprintf(stdout, " -g, --group <name>\t\tgroup.\n");
                fprintf(stdout, " -n, --network <name>\t\tnetwork.\n");
                fprintf(stdout, " -z, --zone <name>\t\tzone.\n");
                fprintf(stdout, " -s, --service <name>\t\tservice.\n");
                fprintf(stdout, " -i, --interface <name>\t\tinterface.\n");
                fprintf(stdout, " -r, --rule <name>\t\trule.\n");
                fprintf(stdout, "\n");

                fprintf(stdout, " -V, --variable <variable>\tvariable to modify/print.\n");
                fprintf(stdout, " -S, --set <value>\t\tvalue to set on modify,\n");
                fprintf(stdout, "                  \t\tor new name when renaming.\n");
                fprintf(stdout, "\n");

                fprintf(stdout, " -A, --append\t\t\tappend the variable on modify\n");
                fprintf(stdout, " -O, --overwrite\t\toverwrite the variable on modify\n");
                fprintf(stdout, "\n");

                fprintf(stdout, "     --rule-numbers\t\tprint rule numbers\n");
                fprintf(stdout, "     --apply\t\t\ttry to apply the changes directly to Vuurmuur\n");
                fprintf(stdout, "     --no-apply\t\t\tdon't try to apply the changes to Vuurmuur\n");

                fprintf(stdout, "\n");

                exit(EXIT_SUCCESS);

            case 'v' :

                /* verbose */
                conf.verbose_out = TRUE;
                break;

            case 'C' :
                vr_script.cmd = CMD_ADD;
                break;
            case 'D' :
                vr_script.cmd = CMD_DEL;
                break;
            case 'R' :
                vr_script.cmd = CMD_REN;
                break;
            case 'M' :
                vr_script.cmd = CMD_MOD;
                break;
            case 'P' :
                vr_script.cmd = CMD_PRT;
                break;
            case 'L' :
                vr_script.cmd = CMD_LST;
                break;

            case 'o' :  /* host */

                vr_script.type = TYPE_HOST;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "host (-o/--host): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'g' :  /* group */

                vr_script.type = TYPE_GROUP;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "group (-g/--group): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'n' :  /* network */

                vr_script.type = TYPE_NETWORK;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "network (-n/--network): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'z' :  /* zone */

                vr_script.type = TYPE_ZONE;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "zone (-z/--zone): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 's' :  /* service */

                vr_script.type = TYPE_SERVICE;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "service (-s/--service): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'i' :  /* interface */

                vr_script.type = TYPE_INTERFACE;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "host (-i/--interface): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'r' :  /* rule */

                vr_script.type = TYPE_RULE;

                if(strlcpy(vr_script.name, optarg, sizeof(vr_script.name)) >= sizeof(vr_script.name))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "rule (-r/--rule): argument too long (max: %d).", (int)sizeof(vr_script.name)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'S' :

                if(strlcpy(vr_script.set, optarg, sizeof(vr_script.set)) >= sizeof(vr_script.set))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "set (-S/--set): argument too long (max: %d).", (int)sizeof(vr_script.set)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'V' :

                if(strlcpy(vr_script.var, optarg, sizeof(vr_script.var)) >= sizeof(vr_script.var))
                {
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "var (-V/--var): argument too long (max: %d).", (int)sizeof(vr_script.var)-1);
                    exit(VRS_ERR_COMMANDLINE);
                }
                break;

            case 'O' :

                vr_script.overwrite = TRUE;
                break;

            case 'A' :

                vr_script.overwrite = FALSE;
                break;

            default:

                (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "unknown option '%c'. See --help for valid options.", opt);
                exit(VRS_ERR_COMMANDLINE);
        }
    }

    if(version_flag == 1)
    {
        fprintf(stdout, "Vuurmuur_script %s\n", version_string);
        fprintf(stdout, "Copyright (C) 2002-2008 by Victor Julien\n");
        exit(VRS_SUCCESS);
    }

    if(conf.verbose_out == TRUE)
    {
        /* print some nice info about me being the coolest of 'm all ;-) */
        (void)vrprint.info("Info", "This is Vuurmuur_script %s", version_string);
        (void)vrprint.info("Info", "Copyright (C) 2002-2008 by Victor Julien");
    }

    /* setup regexes */
    if(setup_rgx(1, &vr_script.reg) < 0)
    {
        (void)vrprint.error(VRS_ERR_INTERNAL, VR_INTERR, "setting up regular expressions failed.");
        exit(VRS_ERR_INTERNAL);
    }

    /* apply and no-apply */
    if(apply_flag == 1)
        vr_script.apply = TRUE;
    if(no_apply_flag == 1)
        vr_script.apply = FALSE;

    /* reload the config */
    if (reload_flag == 1)
    {
        vr_script.cmd = CMD_RLD;
        vr_script.apply = TRUE;
    }

    /*
        handling the command
    */
    if(vr_script.cmd == CMD_UNSET)
    {
        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "missing command option, use --help to see a list of possible commands.");
        exit(VRS_ERR_COMMANDLINE);
    }

    if(vr_script.cmd == CMD_ADD)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'add' selected.");
    }
    else if(vr_script.cmd == CMD_DEL)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'delete' selected.");
    }
    else if(vr_script.cmd == CMD_MOD)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'modify' selected.");
    }
    else if(vr_script.cmd == CMD_REN)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'rename' selected.");
    }
    else if(vr_script.cmd == CMD_LST)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'list' selected.");
    }
    else if(vr_script.cmd == CMD_PRT)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'print' selected.");
    }
    else if(vr_script.cmd == CMD_BLK)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'block' selected.");
    }
    else if(vr_script.cmd == CMD_UBL)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'unblock' selected.");
    }
    else if(vr_script.cmd == CMD_LBL)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'list-blocked' selected.");
    }
    else if(vr_script.cmd == CMD_RLD)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "command 'reload-config' selected.");
    }
    else
    {
        (void)vrprint.error(VRS_ERR_INTERNAL, VR_INTERR, "unknown command option %d.", vr_script.cmd);
        exit(VRS_ERR_INTERNAL);
    }


    /*
        handling the type
    */
    if(vr_script.type == TYPE_UNSET && vr_script.cmd != CMD_RLD)
    {
        (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "type option not set. Please see --help for options.");
        exit(VRS_ERR_COMMANDLINE);
    }

    if(vr_script.type == TYPE_HOST)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'host' selected.");
    }
    else if(vr_script.type == TYPE_GROUP)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'group' selected.");
    }
    else if(vr_script.type == TYPE_NETWORK)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'network' selected.");
    }
    else if(vr_script.type == TYPE_ZONE)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'zone' selected.");
    }
    else if(vr_script.type == TYPE_SERVICE)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'service' selected.");
    }
    else if(vr_script.type == TYPE_INTERFACE)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'interface' selected.");
    }
    else if(vr_script.type == TYPE_RULE)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "type 'rule' selected.");
    }
    else if(vr_script.cmd == CMD_RLD)
    {
        if(conf.verbose_out == TRUE)
            (void)vrprint.info(VR_INFO, "reload has no option.");
    }
    else
    {
        (void)vrprint.error(VRS_ERR_INTERNAL, VR_INTERR, "unknown type option %d.", vr_script.type);
        exit(VRS_ERR_INTERNAL);
    }

    /*
        handling the name
    */
    if(vr_script.name[0] == '\0')
    {
        (void)strlcpy(vr_script.name, "any", sizeof(vr_script.name));
    }
    else if(strcasecmp(vr_script.name, "any") == 0)
    {
        /* ignore any */
    }
    else
    {
        if( vr_script.type == TYPE_ZONE || vr_script.type == TYPE_NETWORK ||
            vr_script.type == TYPE_HOST || vr_script.type == TYPE_GROUP)
        {
            /* validate and split the new name */
            if(validate_zonename(debuglvl, vr_script.name, 0, vr_script.name_zone, vr_script.name_net, vr_script.name_host, vr_script.reg.zonename, VALNAME_VERBOSE) != 0)
            {
                if(vr_script.type == TYPE_ZONE)
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid zone name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                else if(vr_script.type == TYPE_NETWORK)
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid network name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                else if(vr_script.type == TYPE_HOST)
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid host name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                else if(vr_script.type == TYPE_GROUP)
                    (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid group name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                
                exit(VRS_ERR_COMMANDLINE);
            }
            if(debuglvl >= HIGH)
                (void)vrprint.debug(__FUNC__, "name: '%s': host/group '%s', net '%s', zone '%s'.",
                                        vr_script.name, vr_script.name_host,
                                        vr_script.name_net, vr_script.name_zone);
        }
        else if(vr_script.type == TYPE_SERVICE)
        {
            if(validate_servicename(debuglvl, vr_script.name, vr_script.reg.servicename, VALNAME_QUIET) != 0)
            {
                (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid service name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                exit(VRS_ERR_COMMANDLINE);
            }
        }
        else if(vr_script.type == TYPE_INTERFACE)
        {
            if(validate_interfacename(debuglvl, vr_script.name, vr_script.reg.interfacename) != 0)
            {
                (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid interface name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                exit(VRS_ERR_COMMANDLINE);
            }
        }
        else if(vr_script.type == TYPE_RULE)
        {
            if( strcmp(vr_script.name, "blocklist") == 0 ||
                strcmp(vr_script.name, "rules") == 0)
            {
                /* ok */
            }
            else
            {
                /* error */
                (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "invalid ruleset name '%s' (in: %s:%d).", vr_script.name, __FUNC__, __LINE__);
                exit(VRS_ERR_COMMANDLINE);
            }
        }
        else
        {
            /* error */
            (void)vrprint.error(VRS_ERR_INTERNAL, VR_INTERR, "unknown type option %d.", vr_script.type);
            exit(VRS_ERR_INTERNAL);
        }
    }

    /* set var to any if var is empty */
    if(vr_script.var[0] == '\0')
        (void)strlcpy(vr_script.var, "any", sizeof(vr_script.var));

    /* see if we need to print rule numbers */
    if(print_linenum_flag == 1)
        vr_script.print_rule_numbers = TRUE;

    /* initialize the config from the config file */
    if(debuglvl >= MEDIUM)
        (void)vrprint.debug(__FUNC__, "initializing config... calling init_config()");

    result = init_config(debuglvl, &conf);
    if(result >= VR_CNF_OK)
    {
        if(debuglvl >= MEDIUM)
            (void)vrprint.debug(__FUNC__, "initializing config complete and succesful.");
    }
    else
    {
        fprintf(stdout, "Initializing config failed.\n");
        exit(EXIT_FAILURE);
    }


    /* now we know the logfile locations, so init the log functions */
    if(conf.verbose_out == TRUE)
    {
        /* if we use verbose output, we still print the logfiles as well */
        vrprint.error = libvuurmuur_logstdoutprint_error;
        vrprint.warning = libvuurmuur_logstdoutprint_warning;
        vrprint.info = libvuurmuur_logstdoutprint_info;
        vrprint.debug = libvuurmuur_logstdoutprint_debug;
    }
    else
    {
        vrprint.error = libvuurmuur_logprint_error;
        vrprint.warning = libvuurmuur_logprint_warning;
        vrprint.info = libvuurmuur_logprint_info;
        vrprint.debug = libvuurmuur_logprint_debug;
    }
    /* audit only to the log, no matter if we are in verbose mode or not
       because it prints: username: message... example:
       
       victor : interface 'abcd' added.
    */
    vrprint.audit = libvuurmuur_logprint_audit;


    /* load the backends */
    result = load_backends(debuglvl, &PluginList);
    if(result < 0)
    {
        fprintf(stdout, "Error: loading backends failed\n");
        exit(EXIT_FAILURE);
    }

    /* main part: handle the different commands */
    if(vr_script.cmd == CMD_LST)
    {
        retval = script_list(debuglvl, &vr_script);
    }
    else if(vr_script.cmd == CMD_PRT)
    {
        if(strcasecmp(vr_script.name,"any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot use command 'print' on object 'any'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else
        {
            retval = script_print(debuglvl, &vr_script);
        }
    }
    else if(vr_script.cmd == CMD_ADD)
    {
        if(strcasecmp(vr_script.name,"any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot use command 'add' on object 'any'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else
        {
            retval = script_add(debuglvl, &vr_script);
        }
    }
    else if(vr_script.cmd == CMD_DEL)
    {
        if(strcasecmp(vr_script.name,"any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot use command 'del' on object 'any'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else
        {
            retval = script_delete(debuglvl, &vr_script);
        }
    }
    else if(vr_script.cmd == CMD_MOD || vr_script.cmd == CMD_BLK)
    {
        /* workaround for the problem that we don't want to append into
         * append into an empty list then using --block */
        if (vr_script.cmd == CMD_BLK) {
            /* append or overwrite mode (fix ticket #49) */
            if ((rf->ask(debuglvl, rule_backend, "blocklist", "RULE",
                            vr_script.bdat, sizeof(vr_script.bdat), TYPE_RULE, 1) == 1))
            {
                /* we got a rule from the backend so we have to append */
                vr_script.overwrite = FALSE;
            } else {
                /* there are no rules in the backend so we overwrite */
                vr_script.overwrite = TRUE;
            }

            /* switch to mod here */
            vr_script.cmd = CMD_MOD;
        }

        if(strcasecmp(vr_script.name,"any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot use command 'modify' on object 'any'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else if(vr_script.var[0] == '\0' || strcasecmp(vr_script.var, "any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "please set the variable to modify with --variable.");
            retval = VRS_ERR_COMMANDLINE;
        }
        /* allow empty 'set' if we overwrite, since that way we can clear variables */
        else if(vr_script.set[0] == '\0' && vr_script.overwrite == FALSE)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "please set the new value with --set.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else
        {
            retval = script_modify(debuglvl, &vr_script);
        }
    }
    else if(vr_script.cmd == CMD_REN)
    {
        if(strcasecmp(vr_script.name,"any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot use command 'rename' on object 'any'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else if(strcasecmp(vr_script.set,"any") == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot rename a object to 'any'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else if(strncasecmp(vr_script.set,"firewall", 8) == 0)
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "cannot rename a object to a name that starts with 'firewall'.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else if(vr_script.set[0] == '\0')
        {
            (void)vrprint.error(VRS_ERR_COMMANDLINE, VR_ERR, "please set the new name with --set.");
            retval = VRS_ERR_COMMANDLINE;
        }
        else
        {
            retval = script_rename(debuglvl, &vr_script);
        }
    }
    else if(vr_script.cmd == CMD_UBL)
    {
        retval = script_unblock(debuglvl, &vr_script);
    }
    else if(vr_script.cmd == CMD_LBL)
    {
        while((result = rf->ask(debuglvl, rule_backend, "blocklist", "RULE", vr_script.bdat, sizeof(vr_script.bdat), TYPE_RULE, 1) == 1))
        {
            rules_encode_rule(debuglvl, vr_script.bdat, sizeof(vr_script.bdat));
            str = remove_leading_part(vr_script.bdat);
            printf("%s\n", str);
            free(str);
        }
        /* check the result */
        if(result == 0)
            retval = 0;
        else
            retval = VRS_ERR_COMMAND_FAILED;
    }
    else if(vr_script.cmd == CMD_RLD)
    {
        retval = VRS_SUCCESS;
    }
    else
    {
        printf("FIXME: command not implemented\n");
        retval = VRS_ERR_COMMANDLINE;
    }

    /* if all went well (retval == 0) we can apply now */
    if(vr_script.apply == TRUE && retval == VRS_SUCCESS)
    {
        retval = script_apply(debuglvl, &vr_script);
    }

    /* unload the backends */
    result = unload_backends(debuglvl, &PluginList);
    if(result < 0)
    {
        fprintf(stdout, "Error: unloading backends failed.\n");
        exit(EXIT_FAILURE);
    }

    /*
        Destroy the data structures
    */

    /* cleanup regexes */
    (void)setup_rgx(0, &vr_script.reg);

    if(debuglvl >= HIGH)
        (void)vrprint.debug(__FUNC__, "** end **, return = %d", retval);

    return(retval);
}