예제 #1
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
// Copies user_info *'uentp' to ('uent'th - 1) entry of utmp.
void update_ulist(struct user_info *uentp, int uent)
{
	resolve_utmp();
	if (uent > 0 && uent <= USHM_SIZE) {
		utmpshm->uinfo[uent - 1] = *uentp;
	}
}
예제 #2
0
int main(int argc, char **argv)
{
    int i,j,k;
    char * s;
    chdir(BBSHOME);
    resolve_boards();
    resolve_ucache();
    resolve_utmp();
    memset(count, 0, 200*sizeof(int));
    apply_ulist_addr((APPLY_UTMP_FUNC)check,NULL);
    for (i=0;i<200;i++)order[i]=i;
    for (i=0;i<200;i++)
        for (j=i+1;j<200;j++)
            if (count[order[i]]<count[order[j]]) {
                k=order[i];
                order[i]=order[j];
                order[j]=k;
            }
    j=0;
    for (i=0;i<200;i++) {
        s = ModeType(order[i]);
        if (s[0]&&strcmp(s,unknown)) {
            j++;
            printf("%2d  %10s  %4d  %.2lf%%\n", j, s, count[order[i]], (double)count[order[i]]/total*100);
        }
    }
    return 0;
}
예제 #3
0
main()
{
	time_t t;
	struct tm tt;

    chdir(BBSHOME);

	if (load_birthfile()<=0){
		printf("error read birthfile\n");
		exit(0);
	}

	t=time(0);
	if (localtime_r(&t, &tt)==NULL) exit(0);

	birthmonth = tt.tm_mon + 1;
	birthday = tt.tm_mday;

    resolve_ucache();
    resolve_boards();
    resolve_utmp();

	srand(time(0));
    apply_users(mailuser,NULL);
}
예제 #4
0
파일: miscd.c 프로젝트: marvelliu/lilacsrc
int main(int argc, char *argv[])
{
    chdir(BBSHOME);
    setuid(BBSUID);
    setgid(BBSGID);
    setreuid(BBSUID, BBSUID);
    setregid(BBSGID, BBSGID);

#ifndef CYGWIN
#undef time
    bbssettime(time(0));
    sleep(1);
#define time(x) bbstime(x)
#endif

    setpublicshmreadonly(0);

#ifndef CYGWIN
    setpublicshmreadonly(1);
#endif
    init_bbslog();
    if (argc > 1) {
        if (strcasecmp(argv[1], "killuser") == 0) {
			//Added by Marvel
            resolve_utmp(); 

            if (resolve_ucache() != 0)
                return -1;
            return dokilluser();
        }
        if (strcasecmp(argv[1], "giveup") == 0) {
            if (resolve_ucache() != 0)
                return -1;
            return doupdategiveupuser();
        }
        if (strcasecmp(argv[1], "allboards") == 0)
            return dokillalldir();
        if (strcasecmp(argv[1], "daemon") == 0)
            return miscd_dodaemon(argv[1], argv[2]);
        if (strcasecmp(argv[1], "killdir") == 0)
            return dokilldir(argv[2]);
        if (strcasecmp(argv[1], "flush") == 0) {
            if (resolve_ucache() != 0)
	              return -1;
            resolve_boards();
            flushdata();
            return 0;
        }
        return miscd_dodaemon(NULL, argv[1]);
    }
    printf("Usage : %s daemon: to run as a daemon (this is the most common use)\n", argv[0]);
    printf("        %s killuser: to kill old users\n", argv[0]);
    printf("        %s giveup: to unlock given-up users\n", argv[0]);
    printf("        %s killdir <BOARDNAME>: to delete old file in <BOARDNAME>\n", argv[0]);
    printf("        %s allboards: to delete old files in all boards\n", argv[0]);
    printf("        %s flush: to synchronize .PASSWDS and .BOARDS to disk\n", argv[0]);
    printf("That's all, folks. See doc/README.SYSOP for more details\n");

    return 0;
}
예제 #5
0
파일: bootstrap.c 프로젝트: zhouqt/kbs
void bootstrap(void)
{
    int ret;
    char *prompt[] = {
        "Input SYSOP's passwd: ",
        "Input SYSOP's passwd again: ",
    };
    char *pw[2];        /* store SYSOP's password */

    /*
     * About function getpass():
     * lots of codes still use the function, so we use it,
     * though it is obsolete.
     * XXX: memory leak here is harmless.
     */
    while (1) {
        pw[0] = strdup(getpass(prompt[0]));
        if (strlen(pw[0]) > PASSLEN) {
            fprintf(stderr, "password too long, reinput\n");
            continue;
        }
        if (strlen(pw[0]) < 4) {
            fprintf(stderr, "password too short, reinput\n");
            continue;
        }
        if (!strcmp(pw[0], "SYSOP")) {
            fprintf(stderr, "password same as BBS ID, reinput\n");
            continue;
        }
        pw[1] = strdup(getpass(prompt[1]));
        if (strcmp(pw[0], pw[1])) {
            fprintf(stderr, "passwords don't match, reinput\n");
            continue;
        }
        break;
    }

    clean_ipc();
    clean_ids_boards();

    if ((ret = system(BBSHOME "/bin/miscd daemon")) != 0)
        error("error running miscd, return value = %d", ret);
    if ((ret = system(BBSHOME "/bin/bbslogd")) != 0)
        error("error running bbslogd, return value = %d", ret);

    chdir(BBSHOME);
    resolve_boards();
    resolve_utmp();
    load_ucache();

    add_bbsid("SYSOP", pw[0]);
    add_bbsid("guest", "anypassword");
    add_allboards();

    clean_ipc();
}
예제 #6
0
int main(int argc, char **argv)
{
    if(argc<=1) return 0;
    mode = atoi(argv[1]);
    chdir(BBSHOME);
    resolve_boards();
    resolve_ucache();
    resolve_utmp();
    apply_ulist_addr((APPLY_UTMP_FUNC)check,NULL);
    printf("%s: %d\n", ModeType(mode), count);
    return 0;
}
예제 #7
0
int search_ulist(struct user_info *uentp, int (*fptr)(), int farg)
{
    int     i;
    resolve_utmp();
    for (i = 0; i < USHM_SIZE; i++)
    {
        *uentp = utmpshm->uinfo[i];
        if ((*fptr) (farg, uentp))
            return i + 1;
    }
    return 0;
}
예제 #8
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
int who_callme(struct user_info *uentp, int (*fptr)(), int farg, int me)
{
	int i;

	resolve_utmp();
	for( i = 0; i < USHM_SIZE; i++ )
	{
		*uentp = utmpshm->uinfo[ i ];
		if( (*fptr)( farg, uentp ) && uentp->destuid==me )
		return i+1;
	}
	return 0;
}
예제 #9
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
// Refreshes utmp(cache for online users.)
int refresh_utmp(void)
{
	int utmpfd, ucachefd;
	struct user_info *uentp;
	int n;
	int count = 0; // Online users count.
	time_t now;

	resolve_utmp();
	if (resolve_ucache() == -1)
		return -1;
	now = time(NULL);
	// Lock caches.
	utmpfd = utmp_lock();
	if (utmpfd == -1)
		return -1;
	ucachefd = ucache_lock();
	if (ucachefd == -1)
		return -1;

	memset(uidshm->status, 0, sizeof(uidshm->status));
	for (n = 0; n < USHM_SIZE; n++) {
		uentp = &(utmpshm->uinfo[n]);
		if (uentp->active && uentp->pid) {
			 // See if pid exists.
			if (bbskill(uentp, 0) == -1) {
				memset(uentp, 0, sizeof(struct user_info));
				continue;
			} else {
				// Kick idle users out.
				if (uentp->mode != BBSNET
						&& now - uentp->idle_time > IDLE_TIMEOUT) {
					bbskill(uentp, SIGHUP);
					memset(uentp, 0, sizeof(struct user_info));
				} else {
					// Increase status.
					uidshm->status[uentp->uid - 1]++;
					// Count online users.
					++count;
				}
			}
		}
	}
	utmpshm->total_num = count;
	// Get count of all users from ucache.
	utmpshm->usersum = allusers();
	// Unlock caches.
	ucache_unlock(ucachefd);
	utmp_unlock(utmpfd);
	return count;
}
예제 #10
0
int apply_ulist_address(int (*fptr)())
{
    int     i, max;
    resolve_utmp();
    max = USHM_SIZE - 1;
    while (max > 0 && utmpshm->uinfo[max].active == 0)
        max--;
    for (i = 0; i <= max; i++)
    {
        if ((*fptr) (&(utmpshm->uinfo[i])) == QUIT)
            return QUIT;
    }
    return 0;
}
예제 #11
0
파일: lvars.c 프로젝트: wyat/kbs
int init_all(ARG_VOID)
{
    int ret=0;
    chdir(BBSHOME);
    get_publicshm();
    resolve_boards();
    ret=resolve_ucache();
    resolve_utmp();
#ifndef THREADSAFE
    init_sessiondata(getSession());
#endif
    resolve_guest_table();
    return ret;
}
예제 #12
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
int search_ulist(struct user_info *uentp,
		int (*fptr)(int, const struct user_info *), int farg)
{
	int i;
	const struct user_info *up;
	resolve_utmp();
	for (i = 0; i < USHM_SIZE; i++) {
		up = utmpshm->uinfo + i;
		if ((*fptr) (farg, up)) {
			*uentp = *up;
			return i + 1;
		}
	}
	return 0;
}
예제 #13
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
int search_ulistn(struct user_info *uentp, int (*fptr)(), int farg, int unum)
{
	int i, j;
	j = 1;
	resolve_utmp();
	for (i = 0; i < USHM_SIZE; i++) {
		*uentp = utmpshm->uinfo[i];
		if ((*fptr) (farg, uentp)) {
			if (j == unum)
			return i + 1;
			else
			j++;
		}
	}
	return 0;
}
예제 #14
0
파일: phpbbslib.c 프로젝트: zhouqt/kbs
static int initialize_ext()
{
    char old_cwd[256];
    getcwd(old_cwd, sizeof(old_cwd));

    chdir(BBSHOME);
    get_publicshm();
    resolve_ucache();
    resolve_utmp();
    resolve_boards();
    init_bbslog();
    www_data_init();
    ext_init = 1;

    chdir(old_cwd);
    return ext_init;
}
예제 #15
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
int apply_ulist(int (*fptr)())
{
	struct user_info *uentp, utmp;
	int i, max;

	resolve_utmp();
	max = USHM_SIZE - 1;
	while (max > 0 && utmpshm->uinfo[max].active == 0)
		max--;
	for (i = 0; i <= max; i++) {
		uentp = &(utmpshm->uinfo[i]);
		utmp = *uentp;
		if ((*fptr)(&utmp) == QUIT)
			return QUIT;
	}
	return 0;
}
예제 #16
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
int getnewutmpent(struct user_info *up)
{
	int utmpfd, ucachefd;
	struct user_info *uentp;
	int i;

	resolve_utmp();
	if (resolve_ucache() == -1)
		return -1;

	utmpfd=utmp_lock();
	if (utmpfd == -1) {
		return -1;
	}

	if (utmpshm->max_login_num < get_online())
		utmpshm->max_login_num = get_online();
	for (i = 0; i < USHM_SIZE; i++) {
		uentp = &(utmpshm->uinfo[i]);
		if (!uentp->active || !uentp->pid)
			break;
	}
	if (i >= USHM_SIZE) {
		utmp_unlock(utmpfd);
		return -2;
	}
	utmpshm->uinfo[i] = *up;
	utmpshm->total_num++;

	utmp_unlock(utmpfd);

	ucachefd=ucache_lock();
	uidshm->status[up->uid-1]++;
	ucache_unlock(ucachefd);

	return i + 1;
}
예제 #17
0
파일: cnv_register.c 프로젝트: wyat/kbs
int main(int argc, char **argv)
{
    FILE* fin,*fout1,*fout2;
	char genbuf[8][256];
	char* ptr;
	int i;
	struct userec * uc;
	int now;
    int exit = 0,goonsearch = 1;
	char userid[IDLEN+2];

	chdir(BBSHOME);
	
	resolve_ucache();
	resolve_utmp();

    now = time(NULL);
	if((fin = fopen("pre_register","r+")) == NULL)
	{
	    printf("open pre_register file failed.\n");
	    return 0;
	}
	if((fout1 = fopen("pre_register1","w")) == NULL)
	{
	    fclose(fin);
	    printf("open pre_register1 file failed.\n");
	    return 0;
	}
	if((fout2 = fopen("new_register","a")) == NULL)
	{
	    fclose(fin);
		fclose(fout1);
	    printf("open pre_register file failed.\n");
	    return 0;
	}

    writew_lock(fileno(fin), 0, SEEK_SET, 0);
	while(!exit){
	    for(i = 0; i < 8;i++)
		{
            if(fgets(genbuf[i], 256, fin) == NULL){
			    exit = 1;
			    break;
			}
		}
		if(exit == 1)break;
		if(goonsearch){
			strncpy(userid,genbuf[1]+8,IDLEN);
			if((ptr=strchr(userid,'\n')) != NULL)*ptr = 0;
			userid[IDLEN]=0;
			if(getuser(userid,&uc) == 0)
			{
		    	printf("genbuf[1] is %s",genbuf[1]);
		    	printf("%s not found\n",userid);
		    	continue;  //get userid's userec
			}
			if((now - uc->firstlogin) > REGISTER_WAIT_TIME)
			{
            		for(i = 0; i < 8;i++)fputs(genbuf[i],fout2);
			}
			else{
				goonsearch=0;
            			for(i = 0; i < 8;i++)fputs(genbuf[i],fout1);
			}
		}else{
			for(i = 0;i< 8; i++)fputs(genbuf[i],fout1);
		}
    }
//    rewind(fout1);
//    ftruncate(fileno(fin),0);
//    while(fgets(genbuf[0],256,fout1))
//    	fputs(genbuf[0],fin);
    un_lock(fileno(fin), 0, SEEK_SET, 0);
    fclose(fin);
    fclose(fout1);
    fclose(fout2);
	
	f_mv("pre_register1","pre_register");
}
예제 #18
0
int main(void){
	char path[256];
	struct stat st;
	time_t now;
	struct tm t;

	now = time(0);
	localtime_r( &now, &t);

    chdir(BBSHOME);
	if( stat( BONLINE_LOGDIR, &st) < 0 ){
		if(mkdir(BONLINE_LOGDIR, 0755) < 0)
			exit(0);
	}
	sprintf(path, "%s/%d", BONLINE_LOGDIR, t.tm_year+1900);
	if( stat(path, &st) < 0){
		if(mkdir(path, 0755) < 0)
			exit(0);
	}
	sprintf(path, "%s/%d/%d", BONLINE_LOGDIR, t.tm_year+1900, t.tm_mon+1);
	if( stat(path, &st) < 0){
		if(mkdir(path, 0755) < 0)
			exit(0);
	}

	sprintf(path,"%s/%d/%d/%d_useronline",BONLINE_LOGDIR,t.tm_year+1900,t.tm_mon+1,t.tm_mday);

	if((fp=fopen(path, "a"))==NULL){
		printf("cannot open log file\n");
		exit(0);
	}

	sprintf(path, "%s/%d/%d/%d_login", BONLINE_LOGDIR, t.tm_year+1900, t.tm_mon+1, t.tm_mday);

	if((fp_login=fopen(path, "a"))==NULL){
		printf("cannot open log file\n");
		exit(0);
	}

    sprintf(path, "%s/lastcount", BONLINE_LOGDIR);

    if((fp_forcount=fopen(path, "w+"))==NULL){
        printf("cannot open log file\n");
        exit(0);
    }

    resolve_utmp();
	get_publicshm();

	resolve_guest_table();

	wwwguestonline = getwwwguestcount();
	totalonline =  get_utmp_number() + wwwguestonline;

    apply_ulist_addr((APPLY_UTMP_FUNC)do_userlist, NULL);

	show_wwwguest();

	logincount = get_publicshm()->logincount;
	logoutcount = get_publicshm()->logoutcount;
	wwwlogincount = get_publicshm()->wwwlogincount;
	wwwlogoutcount = get_publicshm()->wwwlogoutcount;
	wwwguestlogincount = get_publicshm()->wwwguestlogincount;
	wwwguestlogoutcount = get_publicshm()->wwwguestlogoutcount;
	staytime = get_publicshm()->staytime;
	wwwstaytime = get_publicshm()->wwwstaytime;
	wwwgueststaytime = get_publicshm()->wwwgueststaytime;

    setpublicshmreadonly(0);
	get_publicshm()->logincount=0;
	get_publicshm()->logoutcount=0;
	get_publicshm()->wwwlogincount=0;
	get_publicshm()->wwwlogoutcount=0;
	get_publicshm()->wwwguestlogincount=0;
	get_publicshm()->wwwguestlogoutcount=0;
	get_publicshm()->staytime=0;
	get_publicshm()->wwwstaytime=0;
	get_publicshm()->wwwgueststaytime=0;
    setpublicshmreadonly(1);
	/*格式: 时间 totalonline wwwguestonline wwwnotguestonline telnetonline wwwguestschool wwwnotguestschool telnetschool */
	fprintf(fp, "%d.%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", t.tm_hour, t.tm_min/6, totalonline, wwwguestonline, wwwnotguestonline, telnetonline, wwwguestschool, wwwnotguestschool, telnetschool);
	fprintf(fp_login, "%d.%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", t.tm_hour, t.tm_min/6, logincount, logoutcount, (int)(logoutcount?(staytime/logoutcount)/10:0), wwwlogincount, wwwlogoutcount, wwwguestlogincount, wwwguestlogoutcount, (int)(wwwlogoutcount?(wwwstaytime/wwwlogoutcount)/10:0) , (int)(wwwguestlogoutcount?(wwwgueststaytime/wwwguestlogoutcount)/10:0));
	fprintf(fp_forcount, "%d\n%d\n%d\n%d\n%d\n%d\n%d\n", totalonline, wwwguestonline, wwwnotguestonline, telnetonline, wwwguestschool, wwwnotguestschool, telnetschool);
    fclose(fp);
    fclose(fp_login);
    fclose(fp_forcount);
    return 0;
}
예제 #19
0
파일: mbbsd.c 프로젝트: YanlongLai/Program
static void login_query() {
    char uid[IDLEN + 1], passbuf[PASSLEN];
    int attempts;
    char genbuf[200];
    extern struct utmpfile_t *utmpshm;
    resolve_utmp();
    attach_uhash();
    attempts = utmpshm->number;
    show_file("etc/Welcome", 1, -1, NO_RELOAD);
    output("1",1);
    if(attempts >= MAX_ACTIVE) {
	outs("由於人數太多,請您稍後再來。\n");
	refresh();
	exit(1);
    }

    /* hint */
    
    attempts = 0;
    while(1) {

	if(attempts++ >= LOGINATTEMPTS) {
	    more("etc/goodbye", NA);
	    pressanykey();
	    exit(1);
	}

	getdata(20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:",
		uid, IDLEN + 1, DOECHO);
	if(strcasecmp(uid, str_new) == 0) {
#ifdef LOGINASNEW
	    new_register();
	    break;
#else
	    outs("本系統目前無法以 new 註冊, 請用 guest 進入\n");
	    continue;
#endif
	} else if(uid[0] == '\0' || !dosearchuser(uid)) {
	    outs(err_uid);
	} else if(strcmp(uid, STR_GUEST)) {
	    getdata(21, 0, MSG_PASSWD, passbuf, PASSLEN, NOECHO);
	    passbuf[8] = '\0';
	    
	    if(!checkpasswd(cuser.passwd, passbuf) /* ||
	       (HAS_PERM(PERM_SYSOP) && !use_shell_login_mode)*/) {
		logattempt(cuser.userid, '-');
		outs(ERR_PASSWD);
	    } else {
		logattempt(cuser.userid, ' ');
		if(strcasecmp("SYSOP", cuser.userid) == 0)
		    cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE |
			PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT |
			PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT |
			PERM_DENYPOST | PERM_BM | PERM_ACCOUNTS |
			PERM_CHATROOM | PERM_BOARD | PERM_SYSOP |
			PERM_BBSADM;
		break;
	    }
	} else {	/* guest */
	    cuser.userlevel = 0;
	    cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG;
	    break;
	}
    }
    multi_user_check();
    sethomepath(genbuf, cuser.userid);
    mkdir(genbuf, 0755);
}
예제 #20
0
int t_search_ulist(struct user_info* uentp, int (*fptr)(), int farg, int show, int doTalk)
{
    int     i, num;
    char col[14];
    char col2[14];
    resolve_utmp();
    num = 0;
    for (i = 0; i < USHM_SIZE; i++)
    {
        *uentp = utmpshm->uinfo[i];
        if ((*fptr) (farg, uentp))
        {
            if (!uentp->active || !uentp->pid || isreject(uentp))
                continue;
            if (  (uentp->invisible==0)||(uentp->uid == usernum)
                    ||(uentp->invisible==1)&&(HAS_PERM(PERM_SYSOP|PERM_SEECLOAK)||canseeme(uentp)))
            {
                num++;
            }
            else
            {
                continue;
            }
            if (!show)
                continue;
            /* Efan: 增加奖章数	*/

#ifdef ALLOW_MEDALS

            if (num == 1)
                prints ("目前 %s 状态如下:   ", uentp->userid);
#else

            if (num == 1)
                prints("目前 %s 状态如下: \n", uentp->userid);
#endif
            //add by bluetent 2002-10-30 begin
            tmpmode=uentp->mode;
            if (tmpmode>20000)
            {
                tmpmode-=20000;
                iswwwmode=1;
            }
            else
            {
                iswwwmode=0;
            };
            //add by bluetent 2002-10-30 end


            if ( uentp->mode>20000)
                strcpy(col2, "");
            else
                strcpy(col2, "");
            if ( uentp->invisible )
                strcpy(col, "");
            else if ( tmpmode == POSTING || tmpmode == MARKET )
                strcpy(col,"");
            else if ( tmpmode == FIVE || tmpmode == BBSNET)
                strcpy(col,"");
            else
                strcpy(col,"");
            if(doTalk)
            {
                prints("(%d) 状态: %s%s%-10s, 来自: %.20s\n",
                       num, col, col2, ModeType(tmpmode),
                       (uentp->from[22]!='H'||hisfriend(uentp))?uentp->from:BBSIP_DOT);
            }
            else
            {
                prints("%s%s%-10s ",col, col2,ModeType(tmpmode));
                if ((num) % 5 == 0)
                    outc('\n');
            }
        }
    }
    if (show)
        outc('\n');
    return num;
}
예제 #21
0
파일: miscd.c 프로젝트: wyat/kbs
static int miscd_dodaemon(char *argv1, char *daemon)
{
    struct sigaction act;
    char *commandline;
    char commbuf[10];
    char ch;

    if (!check_file_writable(PASSFILE))
    {
        fprintf(stderr, "Error! File %s is not writable.\n", PASSFILE);
        exit(-1);
    }
    if (!check_file_writable(BOARDS))
    {
        fprintf(stderr, "Error! File %s is not writable.\n", BOARDS);
        exit(-1);
    }
    truncate(BOARDS, MAXBOARD * sizeof(struct boardheader));

    if (load_ucache() != 0) {
        printf("ft,load ucache error!");
        exit(-1);
    }

    /* init tmpfs */
    sprintf(genbuf1,"%s/home",TMPFSROOT);
    mkdir(genbuf1,0700);
    sprintf(genbuf1,"%s/boards",TMPFSROOT);
    mkdir(genbuf1,0700);
    for (ch='A';ch<='Z';ch++) {
    sprintf(genbuf1,"%s/home/%c",TMPFSROOT,ch);
    mkdir(genbuf1,0700);
    }

    resolve_boards();
    resolve_utmp();
    resolve_guest_table();

    if (argv1 != NULL) {
        switch (fork()) {
        case -1:
            printf("faint, i can't fork.\n");
            exit(0);
            break;
        case 0:
            break;
        default:
            exit(0);
            break;
        }
        commandline = argv1;
    } else {
        commandline = commbuf;
    }
    setsid();
#if defined(FREEBSD) || defined(MACOSX)
    setpgid(0, 0);
#else
    // by zixia setpgrp(0, 0);
    setpgrp();
#endif
#ifdef AIX
    act.sa_handler = NULL;
    act.sa_flags = SA_RESTART | SA_NOCLDWAIT;
    sigaction(SIGCHLD, &act, NULL);
#else
    act.sa_handler = reaper;
    act.sa_flags = SA_RESTART;
    sigaction(SIGCHLD, &act, NULL);
#endif
    if (((daemon == NULL) || (!strcmp(daemon, "timed"))) && ((argv1 == NULL) || fork())) {
        strcpy(commandline, "timed");
        timed();
        exit(0);
    }

    if (((daemon == NULL) || (!strcmp(daemon, "killd"))) && ((argv1 == NULL) || fork())) {
        strcpy(commandline, "killd");
        char line[20];
        const char *path = "var/killd.pid";
        int pidfd = open(path, O_RDWR | O_CREAT, 0660);
        if (write_lock(pidfd, 0, SEEK_SET, 0) < 0) {
            bbslog("3error", "killd had already been started!");
            exit(-1);
        }
        snprintf(line, sizeof(line), "%ld\n", (long)getpid());
        ftruncate(pidfd, 0);
        write(pidfd, line, strlen(line));

        while (1) {
            time_t ft;

            ft = getnextday4am();
            do {
                sleep(ft - time(0));
            } while (ft > time(0));

            if (argv1 == NULL) {
                dokilluser();
                //doupdategiveupuser();
            } else {
                switch (fork()) {
                case -1:
                    bbslog("3error", "fork failed\n");
                    break;
                case 0:
                    dokilluser();
                    //doupdategiveupuser();
                    exit(0);
                    break;
                default:
                    break;
                }
            }
            switch (fork()) {
                case -1:
                    bbslog("3error", "fork failed\n");
                    break;
                case 0:
                    dokillalldir();
                    exit(0);
                    break;
                default:
                    break;
            }
        };
        exit(0);
    }
    if (((daemon == NULL) || (!strcmp(daemon, "userd"))) && ((argv1 == NULL) || fork())) {
        strcpy(commandline, "userd");
        userd();
        exit(0);
    }
    if ((daemon == NULL) || (!strcmp(daemon, "flushd"))) {
        strcpy(commandline, "flushd");
        flushd();
        exit(0);
    }
    return 0;
}
예제 #22
0
int main()
{
    char TABLE[5][3] =
    {"¤@", "¤G", "¤T", "¥|", "¤­"}, buf0[256], buf1[256], *ptr, id[16];

    int i = 0, bingo, base = 0;


    FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w"),
    *fbe = fopen(VICE_BASE, "r+"), *fc = fopen(VICE_COUNT, "r");

    extern struct utmpfile_t *utmpshm;
    resolve_utmp();

    srand(utmpshm->number);

    if (!fp || !fb || !fbe)
	perror("error open file");

    fgets(buf0, 9, fbe);
    if (buf0)
	base = atoi(buf0);

    printf("base to use:%d\n", base);

    bingo = (base + rand()) % MAX_BINGO;
    fprintf(fp, "%1c²Î¤@µo²¼¤¤¼ú¸¹½X\n", ' ');
    fprintf(fp, "%1c================\n", ' ');
    fprintf(fp, "%1c¯S§O¼ú: %08d\n\n", ' ', bingo);
    fprintf(fb, "%d\n", bingo);

    while (i < 5)
    {
	bingo = (base + rand()) % MAX_BINGO;
	fprintf(fp, "%1c²Ä%s¼ú: %08d\n", ' ', TABLE[i], bingo);
	fprintf(fb, "%08d\n", bingo);
	i++;
    }
    fclose(fp);
    fclose(fb);
    while (fgets(id, 15, fc))
    {
	if (id[0] == '\n')
	    continue;
	if ((ptr = strchr(id, '\n')))
	    *ptr = 0;
	if (id[0] == ' ')
	    continue;
	sprintf(buf0, BBSHOME "/home/%c/%s/%s", id[0], id, VICE_NEW);
	sprintf(buf1, BBSHOME "/home/%c/%s/%s", id[0], id, VICE_DATA);
	printf("%s\n%s\n", buf0, buf1);
	rename(buf0, buf1);
	unlink(buf0);
    }
    base = rand() % MAX_BINGO;
    printf("%d", base);
    rewind(fbe);
    fprintf(fbe, "%08d", base);

    fclose(fbe);
    fclose(fc);
    return 0;
}
예제 #23
0
파일: mbbsd.c 프로젝트: yrchen/Athena
static void
login_query()
{
	char		uid       [IDLEN + 1], passbuf[PASSLEN];
	int		attempts;
	char		genbuf    [200];

	resolve_utmp();
	attempts = utmpshm->number;
	clear();

#ifdef CAMERA
	film_out(time(0) % 5, 0);
#else
	show_file("etc/Welcome0", 0, 20, ONLY_COLOR);
#endif

	if (attempts >= MAXACTIVE) {
		pressanykey("目前站上人數已達上限,請您稍後再來。");
		oflush();
		sleep(1);
		exit(1);
	}
	attempts = 0;
	while (1) {
		if (attempts++ >= LOGINATTEMPTS) {
			more("etc/goodbye", NA);
			pressanykey_old("錯誤太多次,掰掰~~~~~");
			exit(1);
		}
		uid[0] = '\0';
		getdata(22, 2, "您的代號:", uid, IDLEN + 1, DOECHO, 0);
		if (strcasecmp(uid, str_new) == 0) {

#ifdef LOGINASNEW
			DL_func("SO/register.so:va_new_register", 0);
			break;
#else
			pressanykey("本系統目前無法以 new 註冊, 請用 guest 進入");
			continue;
#endif
		} else if (uid[0] == '\0' /* || !dosearchuser(uid) */ )
			pressanykey(err_uid);
		else if (belong(FN_DISABLED, uid)) {
			pressanykey("該 ID 為本站禁止上站之 ID");
			logattempt(uid, '*');
		} else if (strcmp(uid, STR_GUEST)) {
			getdata(22, 30, "您的密碼:", passbuf, PASSLEN, PASS, 0);
			passbuf[8] = '\0';

			if (!dosearchuser(uid)) {
				logattempt(uid, '!');
				pressanykey(ERR_PASSWD);
			} else if (!chkpasswd(cuser.passwd, passbuf)) {
				logattempt(cuser.userid, '-');
				pressanykey(ERR_PASSWD);
			} else {
				/* SYSOP gets all permission bits */

				if (!strcasecmp(cuser.userid, str_sysop))
					cuser.userlevel = ~0;

				logattempt(cuser.userid, ' ');
				break;
			}
		} else {
			/* guest 的話 */
#ifdef LOGINASGUEST
			cuser.userlevel = 0;
			cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG;
			break;
#else
			pressanykey("本站不提供 guest 上站");
			continue;
#endif
		}
	}

	multi_user_check();
	sethomepath(genbuf, cuser.userid);
	mkdir(genbuf, 0755);
	srand(time(0) ^ getpid() ^ (getpid() << 10));
	srandom(time(0) ^ getpid() ^ (getpid() << 10));
}
예제 #24
0
int getnewutmpent( struct user_info *up)
{
    int utmpfd;
    struct user_info *uentp;
    time_t  now;
    int     i, n, num[2];
    FILE * fp;

    fp=fopen(ULIST, "rw+");
    utmpfd = fileno(fp);
    if (utmpfd < 0)
        return -1;

    flock(utmpfd, LOCK_EX);

    resolve_utmp();
    flock(utmpfd, LOCK_EX);
    if (utmpshm->max_login_num < count_users)
        utmpshm->max_login_num = count_users;
    for (i = 0; i < USHM_SIZE; i++)
    {
        uentp = &(utmpshm->uinfo[i]);
        if (!uentp->active || !uentp->pid)
            break;
    }
    if (i >= USHM_SIZE)
    {
        flock(utmpfd, LOCK_UN);
        close(utmpfd);/* add by yiyo */
        return -2;
    }
    utmpshm->uinfo[i] = *up;

    now = time(0);
    if (now > utmpshm->uptime + 60)
    {
        num[0] = num[1] = 0;
        utmpshm->uptime = now;
        for (n = 0; n < USHM_SIZE; n++)
        {
            uentp = &(utmpshm->uinfo[n]);
            if (uentp->active && uentp->pid)
            {
                //web登陆没有守护进程,pid没有意义,所以,不检测web的pid
                if (uentp->mode < 20000 && kill(uentp->pid, 0) == -1)
                {
                    //huangxu@071220:貌似不能这样
                    //kill(uentp->pid, 9);
                    //memset(uentp, 0, sizeof(struct user_info));
                    continue;
                }
                else
                {
                    num[(uentp->invisible == YEA) ? 1 : 0]++;
                    //huangxu@071203:这个数组有嘛用?还是尝试清0吧。
                    //memset(uentp, 0, sizeof(struct user_info));
                    //todo:需要一个专门的函数处理时间计算。
                }
            }
        }
        utmpshm->usersum = allusers();
        n = USHM_SIZE - 1;
        while (n > 0 && utmpshm->uinfo[n].active == 0)
            n--;
        ftruncate(utmpfd, 0);
        write(utmpfd, utmpshm->uinfo, (n + 1) * sizeof(struct user_info));
    }
    flock(utmpfd, LOCK_UN);
    close(utmpfd);
    return i + 1;
}
예제 #25
0
파일: mbbsd.c 프로젝트: yrchen/Athena
static void
user_login()
{
	char		genbuf    [200];
	struct tm      *ptime, *tmp;
	time_t		now = time(0);
	int		a;

	extern struct FROMCACHE *fcache;
	extern int	fcache_semid;

	log_usies("ENTER", fromhost);
	setproctitle("%s: %s", cuser.userid, fromhost);

	/* ------------------------ */
	/* 初始化 uinfo、flag、mode */
	/* ------------------------ */

	setup_utmp(LOGIN);
	currmode = MODE_STARTED;
	enter_uflag = cuser.uflag;

	/* get local time */
	tmp = localtime(&cuser.lastlogin);

	update_data();		/* wildcat: update user data */
	/* Ptt check 同時上線人數 */
	resolve_fcache();
	resolve_utmp();

	if ((a = utmpshm->number) > fcache->max_user) {
		sem_init(FROMSEM_KEY, &fcache_semid);
		sem_lock(SEM_ENTER, fcache_semid);
		fcache->max_user = a;
		fcache->max_time = now;
		sem_lock(SEM_LEAVE, fcache_semid);
	}
#ifdef  INITIAL_SETUP
	if (getbnum(DEFAULT_BOARD) == 0) {
		strcpy(currboard, "尚未選定");
	} else
#endif

	{
		brc_initial(DEFAULT_BOARD);
		set_board();
	}

	/* ------------ */
	/* 畫面處理開始 */
	/* ------------ */

	if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) {
		char		buf       [256];
		time_t		now;

		time(&now);
		sprintf(buf, "<<上站通知>> -- 我來囉! - %s", Etime(&now));
		do_aloha(buf);
	}
	time(&now);
	ptime = localtime(&now);

#ifdef CAMERA
	film_out(FILM_LOGIN, 0);
#else
	more("etc/Welcome_login", NA);
#endif

#if 0
	/* wildcat : 搬家通知用 */
	if (belong(BBSHOME "/etc/oldip", fromhost)) {
		more(BBSHOME "/etc/removal");
		abort_bbs();
	}
#endif

	if ((cuser.day == ptime->tm_mday) && (cuser.month == (ptime->tm_mon + 1)))
		currutmp->birth = 1;
	else
		currutmp->birth = 0;

	if (cuser.userlevel) {	/* not guest */
		move(t_lines - 3, 0);
		prints("      歡迎您第 %d 度拜訪本站,\
上次您是從 %s 連往本站,\n\
     我記得那天是 %s。\n",
		       ++cuser.numlogins, cuser.lasthost,
		       Etime(&cuser.lastlogin));
		pressanykey(NULL);


		/* Ptt */
		if (currutmp->birth == 1) {
#ifdef CAMERA
			film_out(FILM_WEL_BIRTH, 0);
#else
			more("etc/Welcome_birth", YEA);
#endif
			brc_initial("Greeting");
			set_board();
			do_post();
		}
		sethomefile(genbuf, cuser.userid, str_badlogin);
		if (more(genbuf, NA) != -1) {
			if (getans2(b_lines, 0, "您要刪除以上錯誤嘗試的記錄嗎?", 0, 2, 'y') != 'n')
				unlink(genbuf);
		}
		check_register();
		strncpy(cuser.lasthost, fromhost, 24);
		substitute_record(fn_passwd, &cuser, sizeof(cuser), usernum);
		cuser.lasthost[23] = '\0';
		restore_backup();
	}
예제 #26
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
// Returns (non-realtime) count of online users.
int get_online(void)
{
	resolve_utmp();
	return utmpshm->total_num;
}