コード例 #1
0
ファイル: extract.c プロジェクト: JeffAbrahamson/cryptar
static int extract_file(DBFile *dbf, DBSummary *dbs)
{
        WorkTicket *wt;
        
        g_assert(dbf);
        g_assert(dbs);
        if(int_option(kOption_verbose) & VERBOSE_DB)
                db_filename_display(dbf);
        if(int_option(kOption_verbose) & VERBOSE_DB)
                db_summary_display(dbs);
        g_assert( (wt = new_work_ticket()) );
        wt->dbf = dbf;
        wt->sig.summary = dbs;
        /* ### Really should write to the real file. But there are
               details: we don't want to overwrite it, we might have
               to create directories, we should make arrangements to
               clean up in case the transfer is aborted so the user
               sees either a complete file or no file. ### */
        wt->fp = fopen("the-recovered-file", "w");
        g_assert(wt->fp);
        g_assert(( wt->sig.blockList = cover_new() ));
        wt->action = wt_Extract;
        /* ### If file has zero length, we could skip asking for the
               block list. ### */
        request_block_list(wt);
        wt->status = wt_AwaitingBlockList;
        wt_insert(wt);
        return 0;
}
コード例 #2
0
		std::vector<int_option> factory_generator_cuda::get_int_options()
		{
			std::vector<int_option> res;

			res.push_back(int_option("cuda_reserved_thread_count", &cuda_reserved_thread_count, 1, "The number of hw threads not used for input data processing"));
			res.push_back(int_option("cuda_optimize_action_graph_assumed_chunk_size", &cuda_optimize_action_graph_assumed_chunk_size, 32, "Assumed chunk size when optimizing action graph"));

			return res;
		}
コード例 #3
0
ファイル: coprocess.c プロジェクト: JeffAbrahamson/cryptar
/* Start the remote process (server) with bi-directional pipe. */
pid_t do_cmd(const char *cmd)
{
	char *args[100];
	int i,argc=0;
	pid_t ret;
	char *tok,*dir=NULL;
        int f_in, f_out;
        
        if (!cmd) {
                g_warning("No command in do_cmd.  Sorry, can't recover.");
                return 0;
        }
        cmd = g_strdup(cmd);
        
        for (tok=strtok((char *)cmd," "); tok; tok=strtok(NULL," ")) {
                args[argc++] = tok;
        }
	args[argc] = NULL;

	if(int_option(kOption_verbose) & VERBOSE_FLOW_PLUS) {
		fprintf(stderr,"cmd=");
		for (i=0;i<argc;i++)
			fprintf(stderr,"%s ",args[i]);
		fprintf(stderr,"\n");
	}

        ret = piped_child(args, &f_in, &f_out);
        io_register_fd_pair(f_in, f_out);
        
	if (dir) free(dir);

	return ret;
}
コード例 #4
0
ファイル: extract.c プロジェクト: JeffAbrahamson/cryptar
/*
  If file is NULL, extract all files.
*/
static int extract_it(const char *file)
{
        DBF_curs *curs;
        DBFile *dbf;
        DBSummary *dbs;
        
        if(file)
                g_message("Extract: %s", file);
        else
                g_message("Extracting all files.");
        
        curs = db_filename_curs_begin();
        while((dbf = db_filename_curs_next(curs))) {
                /* I trust file more than dbf->filename not to be
                   corrupt, so use its length. */
                if(!file || strncmp(dbf->filename, file, strlen(file)) == 0) {
                        if(file && int_option(kOption_verbose) & VERBOSE_FILES)
                                g_message("Archiving file '%s'.", file);
                        dbs = db_summary_fetch_last(dbf->file_id);
                        if(dbs)
                                extract_file(dbf, dbs);
                        else
                                g_warning("File is in database, but has "
                                          "no summary record: %s",
                                          dbf->filename);
                }
                cycle_main_loop();
        }
        return 0;
}
コード例 #5
0
ファイル: requests.c プロジェクト: JeffAbrahamson/cryptar
void send_block_list(Signature *sig)
{
        IOSBuf *ios, *ios1, *ios2;
        ProtoPutBlock pb;
        guint32 length;
        void *data;
        
        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("sending block list");
        g_assert(sig);
        ios = block_list_to_stream(sig);
        g_assert(ios);
        SCsum_buffer(ios_buffer(ios), ios_buffer_size(ios),
                     sig->summary->block_list_sha1);
        memset(&pb, 0, sizeof(pb));
        pb.file_id = sig->summary->file_id;
        pb.block_id = 0;
        length = ios_buffer_size(ios);
        data = ios_buffer(ios);
        sig->summary->block_list_length = length;
        ios1 = ios_new();
        ios_set_buffer(ios1, data, length);
        ios2 = do_compress(ios1);
        pb.ios = encrypt(ios2);
        ios_free(ios1);
        ios_free(ios2);
        send_put_block(&pb);
        ios_free(ios);
        return;
}
コード例 #6
0
ファイル: workticket.c プロジェクト: JeffAbrahamson/cryptar
/* Remove a workticket from the work list.
 */
void wt_remove(WorkTicket *wt)
{
        g_assert(wt);

        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("Removing work ticket 0x%lX", (unsigned long)wt);
        work_list = g_slist_remove(work_list, wt);
        return;
}
コード例 #7
0
ファイル: pppol2tp.c プロジェクト: WiseMan787/ralink_sdk
static int setdevname_pppol2tp(char **argv)
{
 union {
 char buffer[128];
 struct sockaddr pppol2tp;
 } s;
 int len = sizeof(s);
 char **a;
 int tmp;
 int tmp_len = sizeof(tmp);

 if (device_got_set)
 return 0;

 if (!int_option(*argv, &pppol2tp_fd))
 return 0;

 if(getsockname(pppol2tp_fd, (struct sockaddr *)&s, &len) < 0) {
 fatal("Given FD for PPPoL2TP socket invalid (%s)",
      strerror(errno));
 }
 if(s.pppol2tp.sa_family != AF_PPPOX) {
 fatal("Socket of not a PPPoX socket");
 }

 /* Do a test getsockopt() to ensure that the kernel has the necessary
 * feature available.
 */
 if (getsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_DEBUG,
       &tmp, &tmp_len) < 0) {
 fatal("PPPoL2TP kernel driver not installed");
 }

 /* Setup option defaults. Compression options are disabled! */

 modem = 0;

 lcp_allowoptions[0].neg_accompression = 1;
 lcp_wantoptions[0].neg_accompression = 0;

 lcp_allowoptions[0].neg_pcompression = 1;
 lcp_wantoptions[0].neg_pcompression = 0;

 ccp_allowoptions[0].deflate = 0;
 ccp_wantoptions[0].deflate = 0;

 ipcp_allowoptions[0].neg_vj = 0;
 ipcp_wantoptions[0].neg_vj = 0;

 ccp_allowoptions[0].bsd_compress = 0;
 ccp_wantoptions[0].bsd_compress = 0;

 the_channel = &pppol2tp_channel;
 device_got_set = 1;

 return 1;
}
コード例 #8
0
		std::vector<int_option> factory_generator_plain::get_int_options()
		{
			std::vector<int_option> res;

			#ifdef _OPENMP
			res.push_back(int_option("plain_openmp_thread_count", &plain_openmp_thread_count, omp_get_max_threads(), "count of threads to be used in OpenMP."));
			#endif

			return res;
		}
コード例 #9
0
ファイル: pppol2tp.c プロジェクト: macressler/asuswrt-merlin
static int setdevname_pppol2tp(char **argv)
{
	struct sockaddr_pppol2tp sax;
	int len = sizeof(sax);

	if (device_got_set)
		return 0;

	if (!int_option(*argv, &pppol2tp_fd))
		return 0;

	if(getsockname(pppol2tp_fd, (struct sockaddr *)&sax, &len) < 0) {
		fatal("Given FD for PPPoL2TP socket invalid (%s)",
		      strerror(errno));
	}
	if(sax.sa_family != AF_PPPOX || sax.sa_protocol != PX_PROTO_OL2TP) {
		fatal("Socket is not a PPPoL2TP socket");
	}

	/* Do a test getsockopt() to ensure that the kernel has the necessary
	 * feature available.
	 * driver returns -ENOTCONN until session established!
	if (getsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_DEBUG,
		       &tmp, &tmp_len) < 0) {
		fatal("PPPoL2TP kernel driver not installed");
	} */

	/* Setup option defaults. Compression options are disabled! */

	modem = 0;

	lcp_allowoptions[0].neg_accompression = 1;
	lcp_wantoptions[0].neg_accompression = 0;

	lcp_allowoptions[0].neg_pcompression = 1;
	lcp_wantoptions[0].neg_pcompression = 0;

	ccp_allowoptions[0].deflate = 0;
	ccp_wantoptions[0].deflate = 0;

	ipcp_allowoptions[0].neg_vj = 0;
	ipcp_wantoptions[0].neg_vj = 0;

	ccp_allowoptions[0].bsd_compress = 0;
	ccp_wantoptions[0].bsd_compress = 0;

	the_channel = &pppol2tp_channel;
	device_got_set = 1;

	return 1;
}
コード例 #10
0
ファイル: workticket.c プロジェクト: JeffAbrahamson/cryptar
/* Insert a new workticket into the work list for consideration by the
   I/O loop.
 */
void wt_insert(WorkTicket *wt)
{
        g_assert(wt);

        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("Inserting work ticket 0x%lX", (unsigned long)wt);
        if(wt_queue_full())
                g_warning("Inserting work ticket even though the work list is full.");
        work_list = g_slist_append(work_list, wt);
        /* We need to reference the write buffer just to make sure
           it's registered, otherwise the main event loop might not
           consider it for output. */
        (void)io_write_buf();
        return;
}
コード例 #11
0
ファイル: extract.c プロジェクト: JeffAbrahamson/cryptar
int do_extract()
{
        guint i;
        ProtoBye pb;
        
        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("begin do_extract");
        
        if(g_args->len == 0) {
                extract_it(NULL);
        } else {
                for(i = 0; i < g_args->len; i++)
                        extract_it((const char *)g_ptr_array_index(g_args, i));
        }

        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("end do_extract");
        if(!wt_more()) {
                memset(&pb, 0, sizeof(pb));
                pb.error = pbe_OK;
                send_bye(&pb);
        }
        return 0;
}
コード例 #12
0
ファイル: ipcp.c プロジェクト: AlexShiLucky/rtems
/*
 * setvjslots - set maximum number of connection slots for VJ compression
 */
static int
setvjslots(
    char **argv)
{
    int value;

    if (!int_option(*argv, &value))
	return 0;
    if (value < 2 || value > 16) {
	option_error("vj-max-slots value must be between 2 and 16");
	return 0;
    }
    ipcp_wantoptions [0].maxslotindex =
        ipcp_allowoptions[0].maxslotindex = value - 1;
    return 1;
}
コード例 #13
0
ファイル: workticket.c プロジェクト: JeffAbrahamson/cryptar
/* Work ticket is finished, so write summary to database and remove
   from the work list.
*/
void wt_finish(WorkTicket *wt)
{
        DBSummary *dba;

        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("Finishing work ticket 0x%lX, file id %d", (unsigned long)wt, wt->dbf->file_id);
        g_assert(wt);
        dba = wt->sig.summary;
        g_assert(dba);
#if LATER
        /* Requires having a file_id to summary_id table. See comment
           in db_summary_new().  Without such a table we can't control
           keeping historical data or not.  */
        dba->summary_id = 0;    /* force to increment */
#endif
        db_summary_add(wt->sig.summary);
        wt_remove(wt);
        if(wt->fp)
                fclose(wt->fp);
        g_free(wt);
        return;
}
コード例 #14
0
/**
 * create the test suite for sanei config related tests
 */
static void
sanei_config_suite (void)
{
    /* tests */
    inexistent_config ();
    empty_config ();
    null_config ();
    null_attach ();
    string_option ();
    int_option ();
    string_list_option ();
    word_array_option ();
    bool_option ();
    fixed_option ();
    wrong_range_int_option ();
    wrong_string_list_option ();
    wrong_bool_option ();
    wrong_fixed_option ();

    /* backend real conf inspired cases */
    umax_pp ();
    snapscan ();
}
コード例 #15
0
ファイル: hash.c プロジェクト: JeffAbrahamson/cryptar
/* Insert value into the hash table in the bucket specified by key.
 */
void hash_insert(guint32 key, guint32 value)
{
        guint16 hash_index;
        HashBucket this_bucket;
        HashEntry *entry;

        hash_index = key & 0xffff;
        this_bucket = hash_table[hash_index];
#if GATHER_HASH_STATISTICS
        hash_entries++;
        if(this_bucket)
                hash_collisions++;
        if(int_option(kOption_verbose) & VERBOSE_FLOW_PLUS)
                g_message("[WCsum] (%d,%d) 0x%x %d",
                          hash_entries, hash_collisions, hash_index, value);
#endif
        entry = g_chunk_new(HashEntry, entry_pool);
        g_assert(entry);
        entry->key = hash_index;
        entry->value = value;
        this_bucket = g_slist_append(this_bucket, entry);
        hash_table[hash_index] = this_bucket;
        return;
}
コード例 #16
0
ファイル: coprocess.c プロジェクト: JeffAbrahamson/cryptar
/* Note that in the child STDIN is set to blocking and STDOUT is set
   to non-blocking. This is necessary as rsh relies on stdin being
   blocking and ssh relies on stdout being non-blocking. (But people
   should always use ssh anyway.)

   If blocking_io is set then use blocking io on both fds. That can be
   used to cope with badly broken rsh implementations like the one on
   solaris.

   These comments are from rsync, are they true in our context? We
   probably always talk over a local pipe and let the process we talk
   to (ssh, whatever) deal with the network.
 */
static pid_t piped_child(char **command, int *f_in, int *f_out)
{
	pid_t pid;
	int to_child_pipe[2];
	int from_child_pipe[2];
        
	if (int_option(kOption_verbose) & VERBOSE_FLOW) {
		print_child_argv(command);
	}

	if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) {
		g_warning("pipe: %s\n", strerror(errno));
		g_assert_not_reached();
	}

	pid = fork();
	if (pid < 0) {
		g_warning("fork: %s\n", strerror(errno));
		g_assert_not_reached();
	}

	if (pid == 0) {
                /* child */
                close(to_child_pipe[1]);
                close(from_child_pipe[0]);
                
		if(to_child_pipe[0] != STDIN_FILENO) {
                        if(dup2(to_child_pipe[0], STDIN_FILENO) < 0) {
                                g_warning("Failed to dup/close : %s\n",
                                        strerror(errno));
                                g_assert_not_reached();
                        }
                        close(to_child_pipe[0]);
                }
		if(from_child_pipe[1] != STDOUT_FILENO) {
                        if(dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
                                g_warning("Failed to dup/close : %s\n",
                                        strerror(errno));
                                g_assert_not_reached();
                        }
                        close(from_child_pipe[1]);
                }
			
		set_blocking(STDIN_FILENO);
                set_blocking(STDOUT_FILENO);
		execvp(command[0], command);
		g_warning("Failed to exec %s : %s\n",
			command[0], strerror(errno));
		g_assert_not_reached();
	}

        /* parent */
        if(int_option(kOption_verbose) & VERBOSE_FLOW)
                g_message("server local pid = %d", pid);
	if (close(from_child_pipe[1]) < 0 || close(to_child_pipe[0]) < 0) {
		g_warning("Failed to close : %s\n", strerror(errno));
		g_assert_not_reached();
	}

	*f_out = to_child_pipe[1];
	*f_in = from_child_pipe[0];
        set_nonblocking(*f_out);
        set_nonblocking(*f_in);

	return pid;
}