Esempio n. 1
0
main(int argc, char **argv) {
	fd_set fdvar;
	struct timeval timeout;
	bot.start = time(NULL);
	signal(SIGSEGV, sig_segv);
	signal(SIGTERM, sig_term);
	signal(SIGINT, sig_int);
	signal(SIGHUP, sig_hup);
	signal(SIGBUS, sig_bus);
	//if(fork()) exit(0);
	
	bot.server = (struct servinfo *) calloc(1, sizeof(struct servinfo));
	loadconf();
	socketfd = get_connection(bot.remotehost, bot.remoteport);
	if(socketfd == -1) exit(0);
	
	strcpy(bot.version, "Channel Service 0.1a");
	bot_init();
	
	while(1) {
		timeout.tv_sec = WAITSEC;
		timeout.tv_usec = UWAITSEC;
		FD_ZERO(&fdvar);
		FD_SET(socketfd, &fdvar);
		switch(select(NFDBITS, &fdvar, (fd_set *) 0, (fd_set *) 0, &timeout)) {
			case 0: break;
			case -1: break;
			default:
    				parse_serv(&fdvar);
				break;
		}
	}
}
Esempio n. 2
0
File: child.c Progetto: xiu/child
static void sighandler (int signal)
{
    int status;

    switch (signal) {
        case SIGHUP:
            loadconf(1);
            break;
#ifdef USE_FILTER
        case SIGUSR1:
            loadrulefile();
            break;
#endif
        case SIGUSR2:
            operlog("Got SIGUSR2, reconnecting to server");
            eos = me.retry_attempts = me.connected = 0;
            me.nextretry = time(NULL)+1;
            cleanup_reconnect();
            close(sock);
            break;
        case SIGINT:
            operlog("SIGINT signal received, exiting");
            fakekill(me.nick,"Got SIGINT, exiting");
            child_die(1);
            break;
        case SIGCHLD:
            waitpid(-1,&status,WNOHANG);
            break;
        case SIGPIPE:
            operlog("Got SIGPIPE, ignored");
            break;
    }
}
Esempio n. 3
0
int main(int argc, char** argv) {

    char* test1;
    char* test2;
    
    struct confStruct* conf = (struct confStruct*) calloc(sizeof(struct confStruct), 1);
    //struct dataStruct* data = (struct dataStruct*) calloc(sizeof(struct dataStruct), 1);
    int r=0;
    
    
    loadconf(argc, argv, conf);
    printf("Rootdir:\t%s\nMountdir:\t%s\n", conf->rootdir, conf->mountdir);
    
    //check if mountdir exists, create otherwise
    if(access(conf->mountdir, F_OK))
        r=mkdir(conf->mountdir, conf->mountdir_mod);
        if(r != 0)
            fprintf(stderr, "Could not create mount point directory.\n\tError: %i\n", r);
    
    //check if mountdir is writeable, change otherwise
    if(access(conf->mountdir, R_OK|W_OK|X_OK))
            fprintf(stderr, "Need RWX access rights on mount point directory.\n");
    
    conf->logfile = log_open(conf->logpath);
    
    printf("456\n");
    
    printf("argc = %d\n", conf->argc);
    for(r=0; r<conf->argc; r++)
        printf("\targv[%i] = %s\n", r, conf->argv[r]);
        
    printf("about to call fuse_main...");
    r = fuse_main(conf->argc, conf->argv, &thesmurFS_operations, conf);
    fprintf(stderr, "fuse_main returned");
    fprintf(stderr, "ret %i\n", r);
    
    if(r != 0)
        fprintf(stderr, "fuse_main returned with %i.\n", r);
    
    printf("Ok.\n");
    return 0;
}
Esempio n. 4
0
void parseopts(gint argc, gchar **argv)
{
    loadconf();

    GOptionContext      *context;
    const GOptionEntry  entries[] =
    {
        { "onecolumn",      'o', 0,                     G_OPTION_ARG_NONE,   &conf.onecolumn,  "output in one column",                 NULL },
        { "checkbox",       'x', 0,                     G_OPTION_ARG_NONE,   &conf.checkbox,   "show checkbox",                        NULL },
        { "numbers",        'n', 0,                     G_OPTION_ARG_NONE,   &conf.numbers,    "show numbers of lines",                NULL },
        { "underline",      'u', 0,                     G_OPTION_ARG_NONE,   &conf.underline,  "underline checked lines",              NULL },
        { "color",          'c', 0,                     G_OPTION_ARG_NONE,   &conf.color,      "highlight checked lines with color",   NULL },
        { "radiobox",       'r', 0,                     G_OPTION_ARG_NONE,   &conf.radiobox,   "only one line can be checked",         NULL },
        { "initial",        'i', 0,                     G_OPTION_ARG_NONE,   &conf.initial,    "check all lines initially",            NULL },
        { "whitelines",     'w', 0,                     G_OPTION_ARG_NONE,   &conf.whitelines, "do not skip white lines",              NULL },
        { "fullattr",       'l', 0,                     G_OPTION_ARG_NONE,   &conf.fullattr,   "draw attributes till the end of line", NULL },
        { "not-onecolumn",  'O', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.onecolumn,  "not --onecolumn",                      NULL },
        { "not-checkbox",   'X', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.checkbox,   "not --checkbox",                       NULL },
        { "not-numbers",    'N', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.numbers,    "not --numbers",                        NULL },
        { "not-underline",  'U', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.underline,  "not --underline",                      NULL },
        { "not-color",      'C', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.color,      "not --color",                          NULL },
        { "not-radiobox",   'R', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.radiobox,   "not --radiobox",                       NULL },
        { "not-initial",    'I', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.initial,    "not --initial",                        NULL },
        { "not-whitelines", 'W', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.whitelines, "not --whitelines",                     NULL },
        { "not-fullattr",   'L', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,   &conf.fullattr,   "not --fullattr",                       NULL },
        { "foreground",     'f', 0,                     G_OPTION_ARG_STRING, &conf.foreground, "foreground color to use to highlight", NULL },
        { "background",     'b', 0,                     G_OPTION_ARG_STRING, &conf.background, "background color to use to highlight", NULL },
        { NULL,              0,  0,                     0,                   NULL,             NULL,                                   NULL },
    };

    context = g_option_context_new("[FILES]");
    g_option_context_add_main_entries(context, entries, NULL);
    GError* err = NULL;
    if (!g_option_context_parse(context, &argc, &argv, &err))
        fatal("%s\n", err->message);
    g_option_context_free(context);
    conf.fg = get_curs_color(conf.foreground);
    conf.bg = get_curs_color(conf.background);

    conf.execpath   = g_strdup(argv[0]);
    conf.infiles    = argv + 1;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	pid_t pid;

	int listenfd;
	int connfd;
	
	socklen_t len;
	struct sockaddr_in cliaddr;

	loadconf("miniftp.conf");
	printf("server_addr: %s\n", server_addr);
	printf("server_port: %d\n", server_port);
	printf("server_max_connfd: %d\n", server_max_connfd);


	if (geteuid() != 0)//need root privilege.
	{
		printf("please use root privilege.\n");
		exit(0);
	}

	listenfd = startserver(NULL, 7777);

	len = sizeof(cliaddr);
	if ((connfd = accept(listenfd, (struct sockaddr*)&cliaddr, &len)) == -1)
		perror("accept");
	pid = fork();
	if (pid == -1)
		perror("fork");
	else if (pid == 0)//child
	{
		startsession(connfd);
	}

	wait(NULL); //wait for child to terminate.

	return 0;
}
Esempio n. 6
0
static int poclidek_init(struct poclidek_ctx *cctx, struct poldek_ctx *ctx)
{
    tn_hash *htcnf;
    
    n_assert(cctx->ctx == NULL);

    cctx->_flags = 0;
    cctx->ctx = poldek_link(ctx);
    cctx->pkgs_available = NULL;
    cctx->pkgs_installed = NULL;
    cctx->_dent_na = n_alloc_new(32, TN_ALLOC_OBSTACK);
    cctx->_dent_alloc = dent_alloc;
    cctx->rootdir = pkg_dent_add_dir(cctx, NULL, "/");
    cctx->currdir = cctx->rootdir;
    cctx->homedir = NULL;
    cctx->htcnf = htcnf = loadconf();
    
    init_commands(cctx,
                  htcnf? poldek_conf_get_section(htcnf, "global_aliases"):NULL,
                  htcnf? poldek_conf_get_section(htcnf, "aliases"):NULL);
    
    return 1;
}
Esempio n. 7
0
int main(int argc, char** argv){

    loadconf(path);

    storaged_init(&si);
}
Esempio n. 8
0
File: child.c Progetto: xiu/child
int main(int argc, char **argv)
{
    startuptime = time(NULL);

    InitMem();

    int retval,mysql_lastconn,newfd,i,lastcheck,lastcheck2,nbfd;
    struct sockaddr_storage sa;
    socklen_t salen = sizeof(sa);
    Eclient *eclient;

    indata.nextline = indata.chunkbufentry = indata.chunkbuf;

    emerg = emerg_req = 0;

    eos = raws = verbose = vv = 0;
    int daemonize = 1;
    char op = 0;
    me.retry_attempts = me.nextretry = me.connected = 0;

    struct sigaction sig, old;
    memset(&sig,0,sizeof(sig));
    sig.sa_handler = sighandler;
    sigaction(SIGHUP,&sig,&old);
#ifdef USE_FILTER
    sigaction(SIGUSR1,&sig,&old);
#endif
    sigaction(SIGUSR2,&sig,&old);
    sigaction(SIGINT,&sig,&old);
    sigaction(SIGCHLD,&sig,&old);
    sigaction(SIGPIPE,&sig,&old);

    struct rlimit rlim;
    if ((getrlimit(RLIMIT_CORE, &rlim)) == -1) {
        perror("getrlimit");
        return -1;
    }
    rlim.rlim_cur = RLIM_INFINITY;
    if ((setrlimit(RLIMIT_CORE, &rlim)) == -1) {
        perror("setrlimit");
        return -1;
    }

    /* Setting default values */

    strcpy(me.nick,"C");
    strcpy(me.name,"services.geeknode.org");
    strcpy(me.ident,"cserve");
    strcpy(me.host,"geeknode.org");
    strcpy(me.linkpass,"f00p4ss");
    strcpy(me.mysql_host,"localhost");
    strcpy(me.mysql_db,"child");
    strcpy(me.mysql_login,"child");
    strcpy(me.mysql_passwd,"childp4ss");
    strcpy(me.logfile,"child.log");
    strcpy(me.guest_prefix,"Geek");
    strcpy(me.pl_logfile,"partyline.log");
    strcpy(me.sendmail,"/usr/sbin/sendmail -t");
    strcpy(me.sendfrom,"*****@*****.**");
    strcpy(me.usercloak,".users.geeknode.org");
    bzero(me.mysql_anope_host,32);
    bzero(me.mysql_anope_db,32);
    bzero(me.mysql_anope_login,32);
    bzero(me.mysql_anope_passwd,32);
    bzero(me.bindip,32);
    me.port = 4400;
    me.maxclones = 5;
    me.nick_expire = 45;
    me.chan_expire = 60;
    me.chanperuser = 10;
    me.level_oper = 100;
    me.level_admin = 500;
    me.level_root = 900;
    me.level_owner = 1000;
    me.limittime = 5;
    me.savedb_interval = 60;
    me.listen_port = 0;
#ifdef USE_GNUTLS
    me.ssl = 0;
#endif
    me.enable_exec = 0;
    me.anonymous_global = 0;
    me.maxmsgtime = 2;
    me.maxmsgnb = 5;
    me.ignoretime = 60;
    me.maxloginatt = 3;
    me.chlev_sadmin = 20;
    me.chlev_admin = 10;
    me.chlev_op = 5;
    me.chlev_halfop = 4;
    me.chlev_voice = 3;
    me.chlev_invite = 1;
    me.chlev_nostatus = -1;
    me.chlev_akick = -2;
    me.chlev_akb = -3;
    me.anopemd5 = 0;
#ifdef USE_FILTER
    me.filter = 0;
#endif
    me.emailreg = 0;

    /* -- */

    int ladb=0,cdb=0;

    while ((op = getopt(argc,argv,"acdhv")) != EOF) {
        switch(op) {
            case 'a':
                ladb = 1;
                break;
            case 'c':
                cdb = 1;
                break;
            case 'd':
                daemonize = 0;
                break;
            case 'v':
                if (verbose)
                    vv = 1;
                else
                    verbose = 1;
                break;
            case 'h':
            default:
                usage(argv[0]);
        }
    }

    loadconf(0);
#ifdef USE_FILTER
    if (me.filter)
        loadrulefile();
#endif

    if (ladb) {
        if (!connect_to_db()) {
            printf("Cannot connect to db\n");
            child_clean();
        }

        loadalldb();
        mysql_close(&mysql);

        if (!connect_to_anope_db()) {
            printf("Cannot connect to anope db\n");
            child_clean();
        }

        printf("Loading anope database... ");
        fflush(stdout);

        loadanopedb();
        mysql_close(&mysql2);
        printf("done.\n");
        printf("Saving databases... ");
        fflush(stdout);
        savealldb();
        printf("done.\n");
        printf("Anope database converted\n");
        child_clean();
    }

    if (cdb) {
        if (!connect_to_db()) {
            printf("Cannot connect to db\n");
            child_clean();
        }

        printf("Creating databases ... ");
        fflush(stdout);
        char tmp[512];
        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_chans` (chname varchar(50) not null, founder varchar(50) not null, entrymsg blob not null, options int not null, mlock varchar(32) not null, autolimit int not null, lastseen int not null, regtime int not null, topic blob not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_chan_access` (chname varchar(50) not null, username varchar(255) not null, level int not null, automode int not null default 1, suspended int not null, uflags int not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_trusts` (hostname varchar(255) not null, clones int not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_users` (username varchar(50) not null, authlevel int not null, seen int not null, vhost varchar(200) not null, md5_pass varchar(32) not null, options int not null, timeout int not null, email varchar(100) not null, regtime int not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_links` (master varchar(50) not null, slave varchar(50) not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_botserv_bots` (name varchar(50) not null, ident varchar(50) not null, host varchar(50) not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_botserv_chans` (chan varchar(50) not null, bot varchar(50) not null)");
        mysql_query(&mysql,tmp);

        RunHooks(HOOK_CREATEDB,NULL,NULL,NULL,NULL);

        printf(" done.\n");
        mysql_close(&mysql);
        child_clean();
    }

    if (me.listen_port) {
        if (!Bind()) {
            fprintf(stderr,"Error while binding\n");
            child_clean();
        }
        pllog("Partyline created");
    }

    retval = ConnectToServer();
    switch(retval) {
        case -1:
            fprintf(stderr,"Failed to connect to %s:%d (connection timed out)\n",me.server,me.port);
            operlog("Failed to connect to %s:%d (connection timed out)",me.server,me.port);
            child_clean();
        case 0:
            fprintf(stderr,"Failed to connect to %s:%d",me.server,me.port);
            operlog("Failed to connect to %s:%d",me.server,me.port);
            child_clean();
    }

    if (verbose) printf("Connected to server\n");

    if (!connect_to_db()) {
        fprintf(stderr,"Cannot connect to mysql\n");
        operlog("Cannot connect to mysql db");
        child_clean();
    }

    if (verbose) printf("Connected to mysql DB\n");
    loadalldb();
    mysql_close(&mysql);
    if (verbose) printf("Logging in to server\n");
    SendInitToServer();
    me.connected = 1;
    if (verbose) printf("Logged in to server\n");

    SendRaw("EOS");

    lastcheck = lastcheck2 = mysql_lastconn = time(NULL);
    if (daemonize) daemon(1,0);
    write_pid();

    nbfd = build_poll();
    struct pollfd pfdout;
    pfdout.fd = sock;
    pfdout.events = POLLOUT;
    pfdout.revents = 0;

    while(1) {
        if (outdata.writebytes > 0) {
            retval = poll(&pfdout,1,1000);
            if (retval > 0 && (pfdout.revents & POLLOUT))
                flush_sendq();
        }
        retval = poll(ufds,nbfd,1000);
        if (retval > 0) {
            for (i=0;i<nbfd;i++) {
                if (ufds[i].revents & (POLLIN | POLLPRI)) {
                    switch(i) {
                        case 0:
                            if (!ReadChunk()) {
                                if (!me.connected || !eos) break;
                                operlog("Connection reset by peer");
                                savealldb();
                                eos = me.retry_attempts = me.connected = 0;
                                me.nextretry = time(NULL)+1;
                                cleanup_reconnect();
                                close(sock);
                                break;
                            }
                            while (GetLineFromChunk())
                                ParseLine();
                            break;
                        case 1:
                            if (!me.listen_port) break;
                            newfd = accept(esock,(struct sockaddr *)&sa,&salen);
                            if (eclient_list.size+1 >= ECL_MAXSOCK) {
                                close(newfd);
                                break;
                            }
                            fcntl(newfd,F_SETFL,O_NONBLOCK);
                            eclient = AddEclient(newfd,sa,salen);
                            sendto_all_butone(eclient,"*** Connection from %s (%s)",eclient->host,eclient->addr);
                            nbfd = build_poll(); i++;
                            break;
                        default:
                            eclient = find_eclient(ufds[i].fd);
                            if (!eclient) break;
                            int oldnbfd = nbfd;
                            int old_eclient_size = eclient_list.size;
                            if (!ReadPChunk(eclient)) {
                                if (eclient->authed == 1)
                                    sendto_all_butone(eclient,"*** User %s (%s) logged out (Connection reset by peer)",eclient->nick,eclient->host);
                                else
                                    sendto_all_butone(eclient,"*** Lost connection from %s",eclient->host);
                                close(eclient->fd);
                                DeleteEclient(eclient);
                                nbfd = build_poll();
                                i--;
                                break;
                            }
                            int tmpfd = eclient->fd;
                            while (GetLineFromPChunk(tmpfd))
                                ParseEclient(eclient);
                            if (old_eclient_size > eclient_list.size)
                                nbfd = build_poll();
                            if (nbfd < oldnbfd) i -= (oldnbfd - nbfd);
                            break;
                    }
                }
            }
        }

        int timenow = time(NULL);

        if (!me.connected && timenow - me.nextretry >= 0) {
            retval = ConnectToServer();
            if (retval == -1 || retval == 0) {
                me.retry_attempts++;
                operlog("Reconnecting attempt #%d failed (%s)",me.retry_attempts,retval ? "timeout" : "error");
                if (me.retry_attempts >= MAX_RECO_ATTEMPTS) {
                    operlog("Maximum reconnection attempts reached, exiting");
                    savealldb();
                    unloadallmod();
                    CloseAllSock();
                    child_clean();
                }
                me.nextretry = timenow + RECONNECT_DELAY;
            } else {
                SendInitToServer();
                me.connected = 1;
                me.nextretry = 0;
                SendRaw("EOS");
                operlog("Reconnected");
            }
            if (me.connected) continue;
        }

        if (timenow - mysql_lastconn >= 60*me.savedb_interval) {
            savealldb();
            mysql_lastconn = timenow;
        }

        if (timenow - lastcheck >= 1) {
            CheckGuests();
            CheckLimits();
            CheckTB();
            lastcheck = timenow;
        }

        if (timenow - lastcheck2 >= 60) {
            checkexpired();
            lastcheck2 = timenow;
        }
    }

    operlog("Program shouldn't reach this piece of code, WTF ? Saving DBs and exiting.");
    savealldb();
    unloadallmod();
    CloseAllSock();
    child_clean();

    return 0;
}