Esempio n. 1
0
void do_sql_connect(dbref player, dbref cause, int key) {
   if (sql_init(player) < 0) {
    notify(player, "Database connection attempt failed.");
  } else {
    notify(player, "Database connection succeeded.");
  }   
}
Esempio n. 2
0
struct sql_db *
sql_db_cache_new(struct sql_db_cache *cache,
		 const char *db_driver, const char *connect_string)
{
	struct sql_db_cache_context *ctx;
	struct sql_db *db;
	char *key;

	key = i_strdup_printf("%s\t%s", db_driver, connect_string);
	db = hash_table_lookup(cache->dbs, key);
	if (db != NULL) {
		ctx = SQL_DB_CACHE_CONTEXT(db);
		if (ctx->refcount == 0) {
			sql_db_cache_unlink(ctx);
			ctx->prev = ctx->next = NULL;
		}
		i_free(key);
	} else {
		sql_db_cache_drop_oldest(cache);

		ctx = i_new(struct sql_db_cache_context, 1);
		ctx->cache = cache;
		ctx->key = key;

		db = sql_init(db_driver, connect_string);
		ctx->orig_deinit = db->v.deinit;
		db->v.deinit = sql_db_cache_db_deinit;

		MODULE_CONTEXT_SET(db, sql_db_cache_module, ctx);
		hash_table_insert(cache->dbs, ctx->key, db);
	}

	ctx->refcount++;
	return db;
}
Esempio n. 3
0
struct sql_connection *db_sql_init(const char *config_path, bool userdb)
{
	struct sql_connection *conn;
	const char *error;
	pool_t pool;

	conn = sql_conn_find(config_path);
	if (conn != NULL) {
		if (userdb)
			conn->userdb_used = TRUE;
		conn->refcount++;
		return conn;
	}

	if (*config_path == '\0')
		i_fatal("sql: Configuration file path not given");

	pool = pool_alloconly_create("sql_connection", 1024);
	conn = p_new(pool, struct sql_connection, 1);
	conn->pool = pool;
	conn->userdb_used = userdb;

	conn->refcount = 1;

	conn->config_path = p_strdup(pool, config_path);
	conn->set = default_sql_settings;
	if (!settings_read_nosection(config_path, parse_setting, conn, &error))
		i_fatal("sql %s: %s", config_path, error);

	if (conn->set.password_query == default_sql_settings.password_query)
		conn->default_password_query = TRUE;
	if (conn->set.user_query == default_sql_settings.user_query)
		conn->default_user_query = TRUE;
	if (conn->set.update_query == default_sql_settings.update_query)
		conn->default_update_query = TRUE;
	if (conn->set.iterate_query == default_sql_settings.iterate_query)
		conn->default_iterate_query = TRUE;

	if (conn->set.driver == NULL) {
		i_fatal("sql: driver not set in configuration file %s",
			config_path);
	}
	if (conn->set.connect == NULL) {
		i_fatal("sql: connect string not set in configuration file %s",
			config_path);
	}
	conn->db = sql_init(conn->set.driver, conn->set.connect);

	conn->next = connections;
	connections = conn;
	return conn;
}
Esempio n. 4
0
int sql_search(char *searchstring){
	char *errmsg = 0;
	int rc;
	printf("%s\r\n",searchstring);
	
	if(sql_init()){
		return 1;
	}

	rc = sqlite3_exec(db,searchstring,callback,0,&errmsg);
	if(rc!=SQLITE_OK){
		fprintf(stderr, "SQL error: %s\n", errmsg);
		sqlite3_free(errmsg);
		return 1;
	}

	return 0;
}
Esempio n. 5
0
/* 
 * Queries the database for the public / private keypair that matches the fingerprint stored in certinfo. 
 * If found, the certificate / key members of the keymaster struct are populated accordingly.
 * Returns 1 on success, 0 on failure.
 */
int lookup_key(struct keymaster *certinfo)
{
    int result_size = 0, err_code = 0, retval = 1;
    char *desc_query = NULL, *priv_query = NULL, *pub_query = NULL;

    if(sql_init(DB_NAME, DB_LOCAL) != SQLITE_OK)
    {
        goto error;
    }

    priv_query = sqlite3_mprintf("SELECT key FROM certificates WHERE fingerprint = %Q", certinfo->fingerprint);
    certinfo->key = sql_exec(priv_query, &result_size, &err_code);
    sqlite3_free(priv_query);
    if(err_code != SQLITE_OK)
    {
        goto error;
    }

    pub_query = sqlite3_mprintf("SELECT certificate FROM certificates WHERE fingerprint = %Q", certinfo->fingerprint);
    certinfo->certificate = sql_exec(pub_query, &result_size, &err_code);
    sqlite3_free(pub_query);
    if(err_code != SQLITE_OK)
    {
        goto error;
    }

    desc_query = sqlite3_mprintf("SELECT description FROM certificates WHERE fingerprint = %Q", certinfo->fingerprint);
    certinfo->description = sql_exec(desc_query, &result_size, &err_code);
    sqlite3_free(desc_query);
    if(err_code != SQLITE_OK)
    {
        goto error;
    }

    goto end;

error:
    sql_log_error();
    retval = 0;

end:
    sql_cleanup();
    return retval;
}
Esempio n. 6
0
void local_mysql_init(void) {
  /* Setup our local command and function tables */
  static CMDENT mysql_cmd_table[] = {
    {(char *) "@sql", NULL, CA_WIZARD, 0, 0, CS_ONE_ARG, 0, do_sql},
    {(char *) "@sqlconnect", NULL, CA_WIZARD, 0, 0, CS_NO_ARGS, 0, do_sql_connect},
    {(char *) "@sqldisconnect", NULL, CA_WIZARD, 0, 0, CS_NO_ARGS, 0, do_sql_shutdown},
    {(char *) NULL, NULL, 0, 0, 0, 0, 0, NULL}

  };
  
  static FUN mysql_fun_table[] = {
    {"SQL", local_fun_sql, 0, FN_VARARGS, CA_WIZARD, 0},
    {"SQLESCAPE", local_fun_sql_escape, 1, 0, CA_WIZARD, 0},
    {"SQLON", local_fun_sql_connect, 0, 0, CA_WIZARD, 0},
    {"SQLOFF", local_fun_sql_disconnect, 0, 0, CA_WIZARD, 0},
    {NULL, NULL, 0, 0, 0, 0}
  };

  CMDENT *cmdp;
  FUN *fp;
  char *buff, *cp, *dp;

  /* Add the commands to the command table */
  for (cmdp = mysql_cmd_table; cmdp->cmdname; cmdp++) {
    cmdp->cmdtype = CMD_LOCAL_e;
    hashadd(cmdp->cmdname, (int *) cmdp, &mudstate.command_htab);
  }

  /* Register the functions */
  buff = alloc_sbuf("init_mysql_functab");
  for (fp = mysql_fun_table ; fp->name ; fp++) {
     cp = (char *) fp->name;
      dp = buff;
      while (*cp) {
	*dp = ToLower(*cp);
	cp++;
	dp++;
      }
      *dp = '\0';
    hashadd2(buff, (int *) fp, &mudstate.func_htab, 1);
  }

  sql_init(-1);
}
Esempio n. 7
0
/* Dumps search results that match the provided query term */
void print_search_results(char *term)
{
    int count = 0;
    char *query = NULL, *q = NULL, *table = NULL;
    /* Format strings for the respective columns retrieved in sql_dump() */
    char *col_fmt[NUM_COLS] = {"%-25s", "%-50s", "%-25s", "%-25s", "%-15s", "%-50s"};

    if(sql_init(DB_NAME, DB_LOCAL) != SQLITE_OK)
    {
        sql_log_error();
        goto end;
    }

    /* Queries should be in the format: <table.column>=<search term> */
    table = strdup(term);
    q = strstr(table, QUERY_DELIMITER);
    if(!q)
    {
        fprintf(stderr, "ERROR: Improperly formatted query!\n");
        goto end;
    }
    memset(q, 0, 1);
    q++;

    query = sqlite3_mprintf("SELECT firmware.vendor,firmware.description,hardware.vendor,model,revision,hardware.description FROM firmware JOIN hardware ON firmware.device_id=hardware.id WHERE %s LIKE '%%%q%%'", table, q);


    /* Print out a table of all relevant database info related to this certificate */
    printf("\n%s\n%s\n", COL_HEADERS, HEADER_DELIM);
    count = sql_dump(query, col_fmt, NUM_COLS, stdout);
    printf("\nFound %d matches for '%s'.\n\n", count, q);

end:
    if(table) free(table);
    sqlite3_free(query);
    sql_cleanup();
    return;
}
Esempio n. 8
0
/* Prints out all information related to the selected certificate to stdout */
void print_all_cert_info(struct keymaster *certinfo)
{
    int count = 0;
    char *query = NULL;
    /* Format strings for the respective columns retrieved in sql_dump() */
    char *col_fmt[NUM_COLS] = {"%-25s", "%-50s", "%-25s", "%-25s", "%-15s", "%-50s"};

    if(sql_init(DB_NAME, DB_LOCAL) != SQLITE_OK)
    {
        sql_log_error();
        return;
    }

    query = sqlite3_mprintf("SELECT firmware.vendor,firmware.description,hardware.vendor,model,revision,hardware.description FROM firmware JOIN hardware ON firmware.device_id=hardware.id WHERE certificate_id = (SELECT id FROM certificates WHERE fingerprint = %Q)", certinfo->fingerprint);

    /* Print out a table of all relevant database info related to this certificate */
    printf("\n%s\n%s\n", COL_HEADERS, HEADER_DELIM);
    count = sql_dump(query, col_fmt, NUM_COLS, stdout);
    printf("\nFound %d firmware(s) using this certificate.\n\n", count);

    sqlite3_free(query);
    sql_cleanup();
    return;
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
	int c = 0;
	FILE *fp = NULL;
	int long_opt_index = 0, i = 0, channel = 0, passive = 0, mode = 0;
	int source = INTERFACE, ret_val = EXIT_FAILURE;
	struct bpf_program bpf = { 0 };
	char *out_file = NULL, *last_optarg = NULL, *target = NULL, *bssid = NULL;
	char *short_options = "i:c:n:o:b:5sfuCDh";
        struct option long_options[] = {
		{ "bssid", required_argument, NULL, 'b' },
                { "interface", required_argument, NULL, 'i' },
                { "channel", required_argument, NULL, 'c' },
		{ "out-file", required_argument, NULL, 'o' },
		{ "probes", required_argument, NULL, 'n' },
		{ "daemonize", no_argument, NULL, 'D' },
		{ "file", no_argument, NULL, 'f' },
		{ "ignore-fcs", no_argument, NULL, 'C' },
		{ "5ghz", no_argument, NULL, '5' },
		{ "scan", no_argument, NULL, 's' },
		{ "survey", no_argument, NULL, 'u' },
                { "help", no_argument, NULL, 'h' },
                { 0, 0, 0, 0 }
        };

	fprintf(stderr, "\nWash v%s WiFi Protected Setup Scan Tool\n", PACKAGE_VERSION);
        fprintf(stderr, "Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <*****@*****.**>\n\n");

	globule_init();
	sql_init();
	create_ap_table();
	set_auto_channel_select(0);
	set_wifi_band(BG_BAND);
	set_debug(INFO);
	set_validate_fcs(1);
	set_log_file(stdout);
	set_max_num_probes(DEFAULT_MAX_NUM_PROBES);

	while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)
        {
                switch(c)
                {
			case 'f':
				source = PCAP_FILE;
				break;
			case 'i':
				set_iface(optarg);
				break;
			case 'b':
				bssid = strdup(optarg);
				break;
			case 'c':
				channel = atoi(optarg);
				set_fixed_channel(1);
				break;
			case '5':
				set_wifi_band(AN_BAND);
				break;
			case 'n':
				set_max_num_probes(atoi(optarg));
				break;
			case 'o':
				out_file = strdup(optarg);
				break;
			case 's':
				mode = SCAN;
				break;
			case 'u':
				mode = SURVEY;
				break;
			case 'C':
				set_validate_fcs(0);
				break;
			case 'D':
				daemonize();
				break;
			default:
				usage(argv[0]);
				goto end;
		}

		/* Track the last optarg. This is used later when looping back through any specified pcap files. */
		if(optarg)
		{
			if(last_optarg)
			{
				free(last_optarg);
			}

			last_optarg = strdup(optarg);
		}
	}

	/* The interface value won't be set if capture files were specified; else, there should have been an interface specified */
	if(!get_iface() && source != PCAP_FILE)
	{
		usage(argv[0]);
		goto end;
	}

	if(get_iface() && source == PCAP_FILE)
	{
		cprintf(CRITICAL, "[X] ERROR: -i and -f options cannot be used together.\n");
		usage(argv[0]);
		goto end;
	}

	/* If we're reading from a file, be sure we don't try to transmit probe requests */
	if(source == PCAP_FILE)
	{
		passive = 1;
	}

	/* Open the output file, if any. If none, write to stdout. */
	if(out_file)
	{
		fp = fopen(out_file, "wb");
		if(!fp)
		{
			cprintf(CRITICAL, "[X] ERROR: Failed to open '%s' for writing\n", out_file);
			goto end;
		}

		set_log_file(fp);
	}

	/* 
	 * Loop through all of the specified capture sources. If an interface was specified, this will only loop once and the
	 * call to monitor() will block indefinitely. If capture files were specified, this will loop through each file specified
	 * on the command line and monitor() will return after each file has been processed.
	 */
	for(i=argc-1; i>0; i--)
	{
		/* If the source is a pcap file, get the file name from the command line */
		if(source == PCAP_FILE)
		{
			/* If we've gotten to the arguments, we're done */
			if((argv[i][0] == '-') ||
			   (last_optarg && (memcmp(argv[i], last_optarg, strlen(last_optarg)) == 0))
			)
			{
				break;
			}
			else
			{
				target = argv[i];
			}
		}
		/* Else, use the specified interface name */
		else
		{
			target = get_iface();
		}

		set_handle(capture_init(target));
		if(!get_handle())
		{
			cprintf(CRITICAL, "[X] ERROR: Failed to open '%s' for capturing\n", get_iface());
			goto end;
		}

		if(pcap_compile(get_handle(), &bpf, PACKET_FILTER, 0, 0) != 0)
		{
			cprintf(CRITICAL, "[X] ERROR: Failed to compile packet filter\n");
			goto end;
		}
		
		if(pcap_setfilter(get_handle(), &bpf) != 0)
		{
			cprintf(CRITICAL, "[X] ERROR: Failed to set packet filter\n");
			goto end;
		}

		/* Do it. */
		monitor(bssid, passive, source, channel, mode);
		printf("\n");
	}

	ret_val = EXIT_SUCCESS;

end:
	globule_deinit();
	sql_cleanup();
	if(bssid) free(bssid);
	if(out_file) free(out_file);
	if(wpsmon.fp) fclose(wpsmon.fp);
	return ret_val;
}
Esempio n. 10
0
int sql_query ( dbref player, char *q_string, char *buff, char **bufc, const Delim *row_delim, const Delim *field_delim )
{
    PGresult *pgres;
    ExecStatusType pgstat;
    PGconn *pgsql;
    char *pg_data;
    int num_rows, got_rows, got_fields;
    int i, j;
    int retries;
    /*
     * If we have no connection, and we don't have auto-reconnect on (or
     * we try to auto-reconnect and we fail), this is an error generating
     * a #-1. Notify the player, too, and set the return code.
     */
    pgsql = pgsql_struct;

    if ( ( !pgsql ) && ( mod_db_sql_config.reconnect != 0 ) ) {
        /*
         * Try to reconnect.
         */
        retries = 0;

        while ( ( retries < PGSQL_RETRY_TIMES ) && !pgsql ) {
            sleep ( 1 );
            sql_init ( 0, 0, NULL, NULL );
            pgsql = pgsql_struct;
            retries++;
        }
    }

    if ( !pgsql ) {
        notify ( player, "No SQL database connection." );

        if ( buff )
            safe_str ( "#-1", buff, bufc );

        return -1;
    }

    if ( !q_string || !*q_string )
        return 0;

    /*
     * Send the query.
     */
    pgres = PQexec ( pgsql, q_string );
    pgstat = PQresultStatus ( pgres );

    if ( pgstat != PGRES_COMMAND_OK && pgstat != PGRES_TUPLES_OK ) {
        notify ( player, PQresultErrorMessage ( pgres ) );

        if ( buff )
            safe_str ( "#-1", buff, bufc );

        PQclear ( pgres );
        return -1;
    }

    /*
     * A number of affected rows greater than 0 means it wasn't a SELECT
     */
    num_rows = atoi ( PQcmdTuples ( pgres ) );

    if ( num_rows > 0 ) {
        notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "SQL query touched %d %s.", num_rows, ( num_rows == 1 ) ? "row" : "rows" );
        PQclear ( pgres );
        return 0;
    }

    /*
     * Check to make sure we got rows back.
     */
    got_rows = PQntuples ( pgres );

    if ( got_rows == 0 ) {
        PQclear ( pgres );
        return 0;
    }

    /*
     * Construct properly-delimited data.
     */

    if ( buff ) {
        for ( i = 0; i < got_rows; i++ ) {
            if ( i > 0 ) {
                print_sep ( row_delim, buff, bufc );
            }

            got_fields = PQnfields ( pgres );

            if ( got_fields ) {
                for ( j = 0; j < got_fields; j++ ) {
                    pg_data = PQgetvalue ( pgres, i, j );

                    if ( j > 0 ) {
                        print_sep ( field_delim, buff,
                                    bufc );
                    }

                    if ( pg_data && *pg_data )
                        safe_str ( pg_data, buff, bufc );
                }
            }
        }
    } else {
        for ( i = 0; i < got_rows; i++ ) {
            got_fields = PQnfields ( pgres );

            if ( got_fields ) {
                for ( j = 0; j < got_fields; j++ ) {
                    pg_data = PQgetvalue ( pgres, i, j );

                    if ( pg_data && *pg_data ) {
                        notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "Row %d, Field %d: %s", i + 1, j + 1, pg_data );
                    } else {
                        notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "Row %d, Field %d: NULL", i + 1, j + 1 );
                    }
                }
            } else {
                notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "Row %d: NULL", i + 1 );
            }
        }
    }

    PQclear ( pgres );
    return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
	int i, result;

	progname = strrchr(argv[0], '/');
	progname = progname ? progname + 1 : argv[0];

	is_module = 0;
	ipc_init_struct();
	gettimeofday(&self.start, NULL);


	/*
	 * Solaris doesn't support MSG_NOSIGNAL, so
	 * we ignore SIGPIPE globally instead
	 */
	signal(SIGPIPE, SIG_IGN);

	for (i = 1; i < argc; i++) {
		char *opt, *arg = argv[i];

		if (*arg != '-') {
			if (!merlin_conf) {
				merlin_conf = arg;
				continue;
			}
			goto unknown_argument;
		}

		if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
			usage(NULL);
		if (!strcmp(arg, "-k") || !strcmp(arg, "--kill")) {
			killing = 1;
			continue;
		}
		if (!strcmp(arg, "-d") || !strcmp(arg, "--debug")) {
			debug++;
			continue;
		}

		if ((opt = strchr(arg, '=')))
			opt++;
		else if (i < argc - 1)
			opt = argv[i + 1];
		else
			usage("Unknown argument, or argument '%s' requires a parameter", arg);

		i++;
		if (!strcmp(arg, "--config") || !strcmp(arg, "-c")) {
			merlin_conf = opt;
			continue;
		}
		unknown_argument:
		usage("Unknown argument: %s", arg);
	}

	if (!merlin_conf)
		usage("No config-file specified\n");

	if (!grok_config(merlin_conf)) {
		fprintf(stderr, "%s contains errors. Bailing out\n", merlin_conf);
		return 1;
	}

	if (!pidfile)
		pidfile = "/var/run/merlin.pid";

	if (killing)
		return kill_daemon(pidfile);

	if (use_database && !import_program) {
		lwarn("Using database, but no import program configured. Are you sure about this?");
		lwarn("If not, make sure you specify the import_program directive in");
		lwarn("the \"daemon\" section of your merlin configuration file");
	}

	ipc.action = ipc_action_handler;
	result = ipc_init();
	if (result < 0) {
		printf("Failed to initalize ipc socket: %s\n", strerror(errno));
		return 1;
	}
	if (net_init() < 0) {
		printf("Failed to initialize networking: %s\n", strerror(errno));
		return 1;
	}

	if (!debug) {
		if (daemonize(merlin_user, NULL, pidfile, 0) < 0)
			exit(EXIT_FAILURE);

		/*
		 * we'll leak these file-descriptors, but that
		 * doesn't really matter as we just want accidental
		 * output to go somewhere where it'll be ignored
		 */
		fclose(stdin);
		open("/dev/null", O_RDONLY);
		fclose(stdout);
		open("/dev/null", O_WRONLY);
		fclose(stderr);
		open("/dev/null", O_WRONLY);
	}

	signal(SIGINT, clean_exit);
	signal(SIGTERM, clean_exit);
	signal(SIGUSR1, sigusr_handler);
	signal(SIGUSR2, sigusr_handler);

	sql_init();
	if (use_database) {
		sql_query("TRUNCATE TABLE program_status");
		sql_query("INSERT INTO program_status(instance_id, instance_name, is_running) "
		          "VALUES(0, 'Local Nagios daemon', 0)");
		for (i = 0; i < (int)num_nodes; i++) {
			char *node_name;
			merlin_node *node = noc_table[i];

			sql_quote(node->name, &node_name);
			sql_query("INSERT INTO program_status(instance_id, instance_name, is_running) "
			          "VALUES(%d, %s, 0)", node->id + 1, node_name);
			safe_free(node_name);
		}
	}
	state_init();
	linfo("Merlin daemon %s successfully initialized", merlin_version);
	polling_loop();

	clean_exit(0);

	return 0;
}
Esempio n. 12
0
mymysql::mymysql() {
	// TODO Auto-generated constructor stub
	sql_init();
}
Esempio n. 13
0
void *frame_analy(void *msg){
	ue_acc = 0;
	printf("frame analyzing...\n");
	fflush(stdout);
	struct frame_buf *fbuf = ((struct get_msg *)msg)->fbuf;
	struct msidhash *mhash = ((struct get_msg *)msg)->mhash;
	struct radiushash *rhash = ((struct get_msg *)msg)->rhash;
	struct TK_MSID *tkmsid;
	struct RADIUS_MSG *rdsmsg;
	struct listhdr *l=NULL;
	u_char *frame=NULL, *tar=NULL;
	FILE *output = fopen("./packet", "wb");
	FILE *log = fopen("./log", "wb");
	struct listhash packet_hash;
	struct signalhdr sh;
	struct framehdr fh;
	//p分析过的帧数,ip_acc获得的ip数据包数,pld_len组包后获得的pdu长度
	int p=0, ip_acc=0, hash_pos=0, pld_len=0;
	int t=0;//t临时变量
	_Int16 *type;
	short *lifetime = (short *)malloc(2);
	time_t *tm;
	sql_init();
	hash_init(&packet_hash);

	do{
		if(fbuf->front == fbuf->rear){
			if(fbuf->quit == QUIT)
				break;
		}else{
			p++;
			frame = fbuf->mframe[fbuf->front];
			fbuf->mframe[fbuf->front] = NULL;
			fbuf->front = (fbuf->front+1)%FRAME_BUF_SIZE;

			type = (_Int16 *)(frame+12);
			if(*type==VIRTUAL_LAN && frame[27]==UDP_FLAG){
				signalhdr_make(&sh, frame);
				//A11信令处理
				if(sh.udp->src_port==ACCESSNW && sh.udp->dst_port==ACCESSNW){
					switch(frame[SGNLHDR_LEN]){
						case REG_REQUEST:
							lifetime[0] = frame[49];
							lifetime[1] = frame[48];
							if(*lifetime!=0 && frame[114]==A11_ACTIVE_START){
								tm = (time_t *)(frame+65);
								tkmsid=tkmsid_make((frame+SGNLHDR_LEN+24),sh.ip->total_len-52,&sh,tm);
								msidhash_join(mhash, tkmsid);
							}
							else if(*lifetime==0){
								tkmsid=tkmsid_make((frame+SGNLHDR_LEN+24),sh.ip->total_len-52,&sh,NULL);
								msidhash_quit(mhash, tkmsid);
								free(tkmsid);
								tkmsid = NULL;
							}
							break;
						default:
							break;
					}
				}
				//RADIUS数据处理
				else{
					switch(frame[SGNLHDR_LEN]){
						case RADIUS_ACCT_REQ:
							if(frame[106] == ACCT_STATUS_START){
								rdsmsg = rdsmsg_make((frame+SGNLHDR_LEN+20), sh.ip->total_len-48, p);
								radiushash_join(rhash, rdsmsg);
							}else if(frame[106] == ACCT_STATUS_STOP){
								rdsmsg = rdsmsg_make((frame+SGNLHDR_LEN+20), sh.ip->total_len-48, p);
								radiushash_quit(rhash, rdsmsg);
								free(rdsmsg);
								rdsmsg = NULL;
							}
							break;
						default:
							break;
					}
				}
			}
			else if(*type==VIRTUAL_LAN && frame[27]==GRE_FLAG){
				//用户数据处理
				framehdr_make(&fh, frame);
				t = fh.ip->total_len + ETH_AND_VLAN;//去掉帧结尾的补位
				if(frame[FRAME_HEADER_LEN]==PPP_FLAG&&frame[t-1]==PPP_FLAG)
					//封装完整
					ip_acc+=ppp_complt((frame+FRAME_HEADER_LEN),
							t-FRAME_HEADER_LEN,&fh,mhash,rhash,output);
				//			else{
				//				//封装不完整
				//				hash_pos = HASH(fh.gre->key, PDU_HASH_ACC);
				//				l = ppp_incomplt(frame,&fh,&packet_hash.list[hash_pos],output,p);
				//				//跳转到组包程序
				//				pld_len = packet_restructure(&tar, l, log);
				//				if(pld_len > 0){
				//					t = ppp_complt(tar, pld_len, &fh, mhash, rhash, output);
				//					ip_acc+=t;
				//					fprintf(log, "packets:%d\n", t);
				//				}else if(pld_len == 0)
				//					fprintf(log, "packets:%d\n", 0);
				//				if(l->pld_list == NULL)
				//					listhdr_destroy(&packet_hash.list[hash_pos], l);
				//				free(tar);
				//				tar = NULL;
				//			}
			}
			free(frame);
			frame = NULL;
		}
	}while(1);

	ip_acc+=hash_free(&packet_hash, output, log);
	fclose(output);
	fclose(log);
	free(lifetime);
	printf("\nframe analysis finished\nget %d ip packets\n", ip_acc);
	pthread_exit((void *)2);
}
Esempio n. 14
0
int sql_query(dbref player, char *q_string, char *buff, char **bufc, const Delim *row_delim, const Delim *field_delim) {
    sqlite3 *sqlite;

    const unsigned char *col_data;

    int num_rows, got_rows, got_fields;

    int i, j;

    int retries;

    int retval;

    sqlite3_stmt *stmt;

    const char *rest;

    /*
     * If we have no connection, and we don't have auto-reconnect on (or
     * we try to auto-reconnect and we fail), this is an error generating
     * a #-1. Notify the player, too, and set the return code.
     */

    sqlite = sqlite3_struct;
    if ((!sqlite) && (mod_db_sql_config.reconnect != 0))
    {
        /*
         * Try to reconnect.
         */
        retries = 0;
        while ((retries < SQLITE_RETRY_TIMES) && !sqlite)
        {
            sleep(1);
            sql_init(0,0,NULL,NULL);
            sqlite = sqlite3_struct;
            retries++;
        }
    }
    if (!sqlite)
    {
        notify_quiet(player, "No SQL database connection.");
        if (buff)
            safe_str("#-1", buff, bufc);
        return -1;
    }
    if (!q_string || !*q_string)
        return 0;

    /*
     * Prepare the query.
     */
    retval = sqlite3_prepare_v2(sqlite, q_string, -1, &stmt, &rest);
    if (retval != SQLITE_OK)
    {
        notify_quiet(player, sqlite3_errmsg(sqlite));
        if (buff)
            safe_str("#-1", buff, bufc);
        sqlite3_finalize(stmt);
        return -1;
    }
    /*
     * Construct properly-delimited data.
     */
    if (buff)
    {
        i = 0;
        while (sqlite3_step(stmt) == SQLITE_ROW)
        {
            if (i++ > 0)
            {
                print_sep(row_delim, buff, bufc);
            }
            got_fields = sqlite3_column_count(stmt);
            if (got_fields)
            {
                for (j = 0; j < got_fields; j++)
                {
                    col_data =
                        sqlite3_column_text(stmt, j);
                    if (j > 0)
                    {
                        print_sep(field_delim, buff,
                                  bufc);
                    }
                    if (col_data && *col_data)
                        safe_str((char *)col_data,
                                 buff, bufc);
                }
            }
        }
    }
    else
    {
        i = 0;
        while (sqlite3_step(stmt) == SQLITE_ROW)
        {
            if (i++ > 0)
            {
                print_sep(row_delim, buff, bufc);
            }
            got_fields = sqlite3_column_count(stmt);
            if (got_fields)
            {
                for (j = 0; j < got_fields; j++)
                {
                    col_data =
                        sqlite3_column_text(stmt, j);
                    if (j > 0)
                    {
                        notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Row %d, Field %d: %s", i, j + 1, col_data);
                    }
                    if (col_data && *col_data)
                    {
                        notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Row %d, Field %d: NULL", i, j + 1);
                    }
                }
            }
        }
    }

    if (i == 0)
    {
        num_rows = sqlite3_changes(sqlite);
        if (num_rows > 0)
        {
            notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "SQL query touched %d %s.", num_rows, (num_rows == 1) ? "row" : "rows");
        }
    }
    sqlite3_finalize(stmt);
    return 0;
}
Esempio n. 15
0
void mod_db_sql_fun_shutdown(char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs) {
        sql_init(player, cause, buff, bufc);
}
Esempio n. 16
0
void mod_db_sql_do_connect(dbref player, dbref cause, int key) {
        sql_init(player, cause, NULL, NULL);
}