Пример #1
0
int
_citrus_lookup_factory_convert(FILE *out, FILE *in)
{
	struct _citrus_db_factory *df;
	struct _region r;
	char *line;
	size_t size;
	int ret;

	ret = _db_factory_create(&df, &_db_hash_std, NULL);
	if (ret)
		return (ret);

	while ((line = fgetln(in, &size)) != NULL)
		if ((ret = convert_line(df, line, size))) {
			_db_factory_free(df);
			return (ret);
		}

	ret = dump_db(df, &r);
	_db_factory_free(df);
	if (ret)
		return (ret);

	if (fwrite(_region_head(&r), _region_size(&r), 1, out) != 1)
		return (errno);

	return (0);
}
Пример #2
0
int
main(
    int		argc,
    char **	argv)
{
  int i;

  /*
   * Configure program for internationalization:
   *   1) Only set the message locale for now.
   *   2) Set textdomain for all amanda related programs to "amanda"
   *      We don't want to be forced to support dozens of message catalogs.
   */  
  setlocale(LC_MESSAGES, "C");
  textdomain("amanda"); 

  safe_fd(-1, 0);

  set_pname("infofile");

  dbopen(DBG_SUBDIR_SERVER);

  for(i = 1; i < argc; ++i) {
    if(i+1 >= argc) {
      g_fprintf(stderr,_("usage: %s host disk [host disk ...]\n"),argv[0]);
      return 1;
    }
    open_infofile("curinfo");
    dump_db(argv[i], argv[i+1]);
    i++;
    close_infofile();
  }

  return 0;
}
Пример #3
0
int main ( int argc, char *argv [] )
{
    if ( argc < 2 )
        printf ( "Usage: %s database [ table [ col ... ] ]\n", argv [ 0 ] );
    else
    {
        const KDBManager *mgr;
        rc_t rc = KDBManagerMakeRead ( & mgr, NULL );
        if ( rc == 0 )
        {
            const KDatabase *db;
            rc = KDBManagerOpenDBRead ( mgr, & db, "%s", argv [ 1 ] );
            if ( rc != 0 )
                fprintf ( stderr, "failed to open database '%s'\n", argv [ 1 ] );
            else
            {
                dump_db ( db, argc, argv );
                KDatabaseRelease ( db );
            }

            KDBManagerRelease ( mgr );
        }
    }

    return 0;
}
Пример #4
0
void execute_single_query(postman::Message query, std::shared_ptr<storage::DB> db) {
    DEBUG("Parsing Query: %s\n", query.data);
    postman::ClusterUpdate cu;
    cu.initiator = db->myself_host;
    auto ds = util::split(query.data, ' ');
    if (ds[0] == "ADD") { // ADD query
        try {
            if (ds[1] == "USER") {
                auto username = util::hexdecode(ds[2]);
                auto hashed_pass = ds[3];
                auto user = db->add_user(username, hashed_pass);
                cu.new_users.push_back(user);
                auto reply = storage::serialize_user(user) + "\nDONE\n";
                DEBUG("Replying with: %s\n", reply.c_str());
                send(query.sockfd, reply.c_str(), reply.length(), 0);
            } else if (ds[1] == "POST") {
                auto username = util::hexdecode(ds[2]);
                auto content = util::hexdecode(ds[3]);
                auto timestamp = std::stoi(ds[4]);
                auto post = db->add_post(username, content, timestamp);
                cu.new_posts.push_back(post);
                auto reply = storage::serialize_post(post) + "\nDONE\n";
                DEBUG("Replying with: %s\n", reply.c_str());
                send(query.sockfd, reply.c_str(), reply.length(), 0);
            } else if (ds[1] == "FOLLOW") {
                auto followed_username = util::hexdecode(ds[2]);
                auto follower_username = util::hexdecode(ds[3]);
                auto follow = db->add_follow(followed_username, follower_username);
                cu.new_follows.push_back(follow);
                auto reply = storage::serialize_follow(follow) + "\nDONE\n";
                DEBUG("Replying with: %s\n", reply.c_str());
                send(query.sockfd, reply.c_str(), reply.length(), 0);
            } else {
                ERR("Invalid table for ADD: %s\n", ds[1].c_str());
                // TODO: reply with info
                return;
            }
        } catch (storage::AlreadyExists ae) {
            std::string reply = "ALREADY EXISTS\nDONE\n"; // error, say already exists
            send(query.sockfd, reply.c_str(), reply.length(), 0);
        }
    } else if (ds[0] == "GET") {
        try {
            if (ds[1] == "USER" && ds[2] == "BY")  {
                if (ds[3] == "USERNAME") {
                    auto username = util::hexdecode(ds[4]);
                    auto user = db->get_user_by_username(username);
                    auto reply = storage::serialize_user(user) + "\nDONE\n";
                    DEBUG("Replying with: %s\n", reply.c_str());
                    send(query.sockfd, reply.c_str(), reply.length(), 0);
                } else {
                    ERR("Invalid field to GET USER BY: %s\n", ds[3].c_str());
                    return;
                }
            } else if (ds[1] == "POST" && ds[2] == "BY") {
                if (ds[3] == "USERNAME") {
                    auto username = util::hexdecode(ds[4]);
                    auto posts = db->get_posts_by_user(db->get_user_by_username(username));
                    for_each(posts.begin(), posts.end(), [&] (storage::Post post) {
                        auto reply = storage::serialize_post(post) + '\n';
                        DEBUG("Replying with: %s\n", reply.c_str());
                        send(query.sockfd, reply.c_str(), reply.length(), 0);
                    });
                    std::string donemsg = "DONE\n";
                    send(query.sockfd, donemsg.c_str(), donemsg.length(), 0);
                } else {
                    ERR("Invalid field to GET POST BY: %s\n", ds[3].c_str());
                    // TODO: reply with info
                    return;
                }
            } else if (ds[1] == "FOLLOWS" && ds[2] == "BY") {
                if (ds[3] == "FOLLOWER") {
                    auto follower_username = util::hexdecode(ds[4]);
                    auto follows = db->get_follows_by_follower_username(follower_username);
                    for_each(follows.begin(), follows.end(), [&] (storage::Follow follow) {
                            auto reply = storage::serialize_follow(follow) + '\n';
                            DEBUG("Replying with: %s\n", reply.c_str());
                            send(query.sockfd, reply.c_str(), reply.length(), 0);
                            });
                    std::string donemsg = "DONE\n";
                    send(query.sockfd, donemsg.c_str(), donemsg.length(), 0);
                } else if (ds[3] == "FOLLOWED") {
                    auto followed_username = util::hexdecode(ds[4]);
                    auto follows = db->get_follows_by_followed_username(followed_username);
                    for_each(follows.begin(), follows.end(), [&] (storage::Follow follow) {
                            auto reply = storage::serialize_follow(follow) + '\n';
                            DEBUG("Replying with: %s\n", reply.c_str());
                            send(query.sockfd, reply.c_str(), reply.length(), 0);
                            });
                    std::string donemsg = "DONE\n";
                    send(query.sockfd, donemsg.c_str(), donemsg.length(), 0);
                } else {
                    ERR("Invalid field to GET FOLLOWS BY: %s\n", ds[3].c_str());
                    // TODO: reply with info
                    return;
                }
            } else {
                ERR("Invalid table for GET: %s\n", ds[1].c_str());
                // TODO: reply with info
                return;
            }
        } catch (storage::NotFound nf) {
            std::string reply = "NOT FOUND\nDONE\n"; // error, say not found
            send(query.sockfd, reply.c_str(), reply.length(), 0);
        } catch (std::out_of_range oor) {
            ERR("Out of range: %s\n", oor.what());
            std::string reply = "DB ERROR\nDONE\n"; // database error
            send(query.sockfd, reply.c_str(), reply.length(), 0);
        }
    } else if (ds[0] == "DUMP") {
        dump_db(query, db);
    } else if (ds[0] == "PING") {
        std::string pong_msg = "PONG\nDONE\n";
        send(query.sockfd, pong_msg.c_str(), pong_msg.length(), 0);
    } else {
        ERR("Invalid query type %s\n", ds[0].c_str());
        // TODO: reply with info
        return;
    }
    postman::pass_update(cu, mt_gox);
}
Пример #5
0
int main(int argc, char **argv)
{
    FILE *f = NULL;
    char outfile[CI_MAX_PATH];
    char line[MAXLINE];
    int len;
    void *key, *val;
    int keysize,valsize;

    CI_DEBUG_LEVEL = 1;
    ci_cfg_lib_init();
    
    if (!ci_args_apply(argc, argv, options) || (!txtfile && !DUMP_MODE)) {
	ci_args_usage(argv[0], options);
	exit(-1);
    }
    
#if ! defined(_WIN32)
    __log_error = (void (*)(void *, const char *,...)) log_errors;     /*set c-icap library log  function */
#else
    __vlog_error = vlog_errors;        /*set c-icap library  log function for win32..... */
#endif

    if(!(allocator = ci_create_os_allocator())) {
	ci_debug_printf(1, "Error allocating mem allocator!\n");
	return -1;
    }

    if (DUMP_MODE && !dbfile) {
        ci_debug_printf(1, "\nError: You need to specify the database to dump ('-o file.db')\n\n");
        ci_args_usage(argv[0], options);
        exit(-1);
    }

    if(!dbfile) {
	strncpy(outfile, txtfile, CI_MAX_PATH);
	outfile[CI_MAX_PATH-1] = '\0';
	len=strlen(outfile);
	if(len > CI_MAX_PATH-5) {
	    ci_debug_printf(1,"The filename  %s is too long\n", outfile);
	    exit(0);
	}
	strcat(outfile,".db");
    }
    else {
	strncpy(outfile, dbfile, CI_MAX_PATH);
	outfile[CI_MAX_PATH-1] = '\0';
    }

    if (!open_db(outfile)) {
	ci_debug_printf(1, "Error opening bdb file %s\n", outfile);
        if (f)
            fclose(f);
	return -1;
    }

    if( DUMP_MODE ){
	dump_db();
    }
    else {
	if ((f = fopen(txtfile, "r+")) == NULL) {
	    ci_debug_printf(1, "Error opening file: %s\n", txtfile);
	    return -1;
	}
	
	while(fgets(line,MAXLINE,f)) {
	    line[MAXLINE-1]='\0';
	    if(!record_extract(line, &key, &keysize, &val, &valsize)) {
		ci_debug_printf(1, "Error parsing line : %s\n", line);
		break;
	    }
	    else if (key) /*if it is not comment or blank line */
		store_db(key, keysize, val, valsize);
	}
	fclose(f);
    }
   
    close_db();

    ci_mem_allocator_destroy(allocator);
    return 0;
}
Пример #6
0
/*
 * Function: destroy_client
 *
 * Purpose: destroys a client entry and removes it from the database
 *
 * Arguments:
 *
 *	client_data	(r) the client to be destroyed
 *
 * Effects:
 *
 * client_data->context is deleted with gss_delete_sec_context.
 * client_data's entry in the database is destroyed.  client_data is
 * freed.
 */
static void destroy_client(svc_auth_gssapi_data *client_data)
{
     OM_uint32 gssstat, minor_stat;
     gss_buffer_desc out_buf;
     client_list *c, *c2;

     PRINTF(("destroy_client: destroying client_data\n"));
     L_PRINTF(2, ("destroy_client: client_data = %p\n", (void *) client_data));

#ifdef DEBUG_GSSAPI
     if (svc_debug_gssapi >= 3)
	  dump_db("before frees");
#endif

     /* destroy client struct even if error occurs */

     gssstat = gss_delete_sec_context(&minor_stat, &client_data->context,
				      &out_buf);
     if (gssstat != GSS_S_COMPLETE)
	  AUTH_GSSAPI_DISPLAY_STATUS(("deleting context", gssstat,
				      minor_stat));
     
     gss_release_buffer(&minor_stat, &out_buf);
     gss_release_name(&minor_stat, &client_data->client_name);
     if (client_data->prev_verf.length != 0)
	  gss_release_buffer(&minor_stat, &client_data->prev_verf);

     if (clients == NULL) {
	  PRINTF(("destroy_client: called on empty database\n"));
	  abort();
     } else if (clients->client == client_data) {
	  c = clients;
	  clients = clients->next;
	  free(c);
     } else {
	  c2 = clients;
	  c = clients->next;
	  while (c) {
	       if (c->client == client_data) {
		    c2->next = c->next;
		    free(c);
		    goto done;
	       } else {
		    c2 = c;
		    c = c->next;
	       }
	  }
	  PRINTF(("destroy_client: client_handle delete failed\n"));
	  abort();
     }
     
done:
     
     L_PRINTF(2, ("destroy_client: client %d destroyed\n", client_data->key));
     
     free(client_data);
     
#if 0 /*ifdef PURIFY*/
     purify_watch_n(client_data, sizeof(*client_data), "rw");
#endif
}
Пример #7
0
int main(int argc, char **argv)
{
  int i =0;
  char *config_file =NULL;
  char *listen_addr = NULL;
  int fd_arr[MAX_FD];
  int no_fds=1;
  int just_dump=0;
  fd_set fds;
  struct sockaddr_atmsvc client;
  int len;
  unsigned char buffer[P_SIZE];

  while(i!=-1) {
    i = getopt(argc, argv, "f:l:d");
    switch(i) {
    case 'd':
      printf("Dumping databasefile\n");
      just_dump=1;
      break;
    case 'f':
      if (config_file) {
	usage(argv[0]);
	exit(-1);
      }
      config_file = (char*)mem_alloc(COMP_NAME, strlen(optarg)+1);
      if (!config_file) {
	exit(-1);
      }
      memcpy(config_file, optarg, strlen(optarg)+1);
      break;
    case 'l':
      if (listen_addr) {
	usage(argv[0]);
	exit(-1);
      }
      listen_addr = (char*)mem_alloc(COMP_NAME, strlen(optarg)+1);
      if (!listen_addr)
	exit(-1);
      memcpy(listen_addr, optarg, strlen(optarg)+1);
      break;
    case -1:
      break;
    default:
      usage(argv[0]);
      exit(-1);
    }
  }
  if (argc != optind) {
    usage(argv[0]);
    exit(-1);
  }
  /* Following gets run in the beginning or when lecs is restarted */
  while (stay_alive) {

    /* Read configuration file */
    if (config_file) {
      if (load_db(config_file)<0)
	exit(-1);
    } else {
      if (load_db(DEFAULT_CONFIG)<0)
	exit(-1);
    }
    if (just_dump) {
      dump_db(NULL);
      exit(0);
    }

    /* Reserve signals */
    signal(SIGHUP, sig_reset);
    signal(SIGINT, sig_kill);
    signal(SIGQUIT, sig_kill);
    signal(SIGABRT, sig_kill);
    signal(SIGTERM, sig_kill);
    signal(SIGSEGV, sig_kill);
    
    /* CHANGE: First parameter, then configuration file! */
    fd_arr[0] = atm_create_socket(CONFIGURATION_DIRECT, 
				  get_lecs_addr());
    no_fds=1;
    if (fd_arr[0] <0) {
      stay_alive=0; /* No need to go on */
    }
    while(!reset && stay_alive) {
      FD_ZERO(&fds);
      for(i=0;i<no_fds;i++) {
	FD_SET(fd_arr[i],&fds);
      }
      
      if (select(MAX_FD, &fds, NULL, NULL, NULL)<0) {
	perror("select(MAX_FD,...)");
	stay_alive=0;
      } else {
	if (FD_ISSET(fd_arr[0],&fds)) { /* Incoming call */
	  if (no_fds == MAX_FD) {
	    close(fd_arr[1]); /* Oldest */
	    memmove(&fd_arr[1], &fd_arr[2], sizeof(int)*(MAX_FD-2));
	    no_fds--;
	  }
	  len = sizeof(client);
	  fd_arr[no_fds] = accept(fd_arr[0], (struct sockaddr*)&client,
				  &len);
	  if (fd_arr[no_fds]<0) {
	    if (errno==ENETRESET)
	      reset=1;
	    if (errno==EUNATCH)
	      stay_alive=1;
	  } else {
	    no_fds++;
	  }
	}
	for(i=1;i<no_fds;i++) {
	  if (FD_ISSET(fd_arr[i],&fds)) {
	    len = read(fd_arr[i], buffer, P_SIZE);
	    if (len <0 && (errno == ENETRESET || errno == EUNATCH)) {
	      reset=0;
	    }
	    if (len<=0) {
	      close(fd_arr[i]);
	      memmove(&fd_arr[i], &fd_arr[i+1], sizeof(int)*(--no_fds -i));
	      i--;
	    } else {
	      if(send_response(fd_arr[i], buffer, len)<0) {
		close(fd_arr[i]);
		memmove(&fd_arr[i], &fd_arr[i+1], sizeof(int)*(--no_fds -i));
	      }
	    }
	  }
	}
      }
    }
    /* This gets done if a signal has been caught, or if
       network resets/becomes unavailable */
    reset=0;
    for(i=0;i<no_fds;i++)
      close(fd_arr[i]);
    no_fds=0;
    reset_db();
  }
  return 0;
}
Пример #8
0
void idaapi run(int arg)
{
  dump_db(arg);
}