Example #1
0
void autoreport(char* title,char* str, int toboard, char* userid)
{
    FILE *se;
    char fname[STRLEN];
    int  savemode;
    struct boardheader fh;
    extern int cmpbnames();
    search_record(BOARDS, &fh, sizeof(fh), cmpbnames, currboard);
    savemode = uinfo.mode;
    report(title);
    sprintf(fname,"tmp/%s.%s.%05d",BBSID,currentuser.userid,uinfo.pid);
    if((se=fopen(fname,"w"))!=NULL)
    {
        fprintf(se,"%s",str);
        fclose(se);
        if(userid != NULL)
            mail_file(fname,userid,title);
        if(toboard)
            Postfile( fname,currboard,title,1);
        if(userid!=NULL && fh.level == 0)
            Postfile(fname, "Punishment", title,2);//add by bluetent - 2002.11.5
        unlink(fname);
        modify_user_mode( savemode );
    }
}
Example #2
0
int bbsfadd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	const char *id = getparm("id");
	const char *desc = getparm("desc");
	if (*id != '\0') {
		override_t ov;
		memset(&ov, 0, sizeof(ov));
		strlcpy(ov.id, id, sizeof(ov.id));
		if (!searchuser(ov.id))
			return BBS_ENOUSR;
		strlcpy(ov.exp, desc, sizeof(ov.exp));
		char file[HOMELEN];
		sethomefile(file, currentuser.userid, "friends");
		if (get_num_records(file, sizeof(ov)) == MAXFRIENDS)
			return BBS_EFRNDQE;
		// TODO: be atomic
		if (!search_record(file, NULL, sizeof(ov), cmpname, ov.id))
			append_record(file, &ov, sizeof(ov));
		printf("Location: fall\n\n");
		return 0;
	}
	xml_header("bbs");
	printf("<bbsfadd ");
	print_session();
	printf(">%s</bbsfadd>", id);
	return 0;
}
Example #3
0
/*
 * Parse the UsnJrnl block buffer.
 *
 * Recover the record size from the header.
 *
 * If the record does not fit in the entire buffer, returns to the callee
 * its offset for alignment.
 *
 * If the buffer is big enough, parses the USN record.
 *
 * Returns -1 on error, 0 in case the action callback decided to stop,
 * a number greater than 0 if the buffer is not big enough.
 */
static int
parse_buffer(const unsigned char *buf, ssize_t bufsize,
             TSK_ENDIAN_ENUM endian, TSK_FS_USNJENTRY_WALK_CB action, void *ptr)
{
    TSK_OFF_T offset = 0;
    TSK_WALK_RET_ENUM ret = 0;
    TSK_USN_RECORD_HEADER header;

    while ((offset = search_record(buf, offset, bufsize)) < bufsize) {
        parse_record_header(&buf[offset], &header, endian);

        /* The buffer does not contain the entire record */
        if (offset + header.length > bufsize)
            return bufsize - offset;

        ret = parse_record(&buf[offset], &header, endian, action, ptr);
        if (ret == TSK_WALK_ERROR)
            return -1;
        else if (ret == TSK_WALK_STOP)
            return 0;

        offset += header.length;
    }

    return offset;
}
Example #4
0
list_t* find_and_report(const char* datafile, const char mode, int pkgc, list_t* argv)
{
	// set quiet to avoid print results of search_record()
	unsigned short int hold_quiet=quiet;
	quiet = 1;

	int i=0;
	int found = 0;
	unsigned short int fcount = 0;
	unsigned short int mcount = 0;
	
	list_t* founded = new_list(0);
	list_t* missing = new_list(0);
	
	for (i=0; i<pkgc; i++)
	{	
		char* pkg  = get_list(argv,i);
		char buf[1024];
		strcpy(buf, pkg);
		
		char* tk = strtok(buf, "|");
		while(tk != NULL)
		{
			found = 0;
			if(search_record(datafile, tk))
			{
				found = 1;
				break;
			}
			tk = strtok(NULL, " ,");
		}
	
		if(found == 1)
		{
			fcount = fcount+1;
			resize_list(founded,fcount);
			add_list(founded,fcount-1,tk);
		} else {
			mcount = mcount+1;
			resize_list(missing,mcount);
			add_list(missing,mcount-1,pkg);
		}
	}
	quiet = hold_quiet;
	
	switch(mode)
	{
		case 'f' :
			return(founded);
		case 'm' :
			return(missing);
	}
	
	destroy_list(founded);
	destroy_list(missing);
	return(NULL);
}
Example #5
0
/******************************************************
 Search/Insert/Delete
 based on input flag determines whether to go to the search insert or delete function
 */
void searchOrInsert(FILE *fp, int insertflag, FILE **fpInput)
{
    
    char line[100];
    long address;
    char *lastname;
    char *firstname;
    int id;
    char * idstring;
    double amount=0.0;
    char *amtstring;
    char *end;
    
    if (insertflag==2)
        printf("\nDELETE\n");
    else if (insertflag==1)
        printf("\nINSERT\n");
    else
        printf("\nSEARCH\n");

    while(printf("Enter student id, last name, first name, and amount or quit to stop: "), fgets(line, sizeof(line), stdin), strcmp(line, "quit\n") != 0)
    {
        idstring = strtok(line, "\040\t");
        id=atoi(idstring);
        lastname=strtok(NULL, "\040\t");
        firstname=strtok(NULL, "\040\t");
        amtstring=strtok(NULL, "\n");
        if (amtstring)
        {
            amount=strtod(amtstring, &end);
            if (*end == '\0')
                printf("\n");
            else
                printf("Not a number: it contains %c!\n", *end);
        }
        
        isValid(lastname, firstname, id, amount);
        printf("%d %s %s %.2f\n", id, lastname, firstname, amount);
        
        address = hash(idstring, 100);
        if (insertflag==2)
        {
            delete_record(lastname, firstname, id, amount, address, fp);
        }
        else if (insertflag==1)
        {
            insert_record(lastname, firstname, id, amount, address, fp);
        }
        else
        {
            search_record(lastname, firstname, id, amount, address, fp);
        }
    }
    return;
}
Example #6
0
//���ð���ͶƱ�ı�־,           
//bname:������,flag�����־
//1:����ͶƱ,0:�ر�ͶƱ ����ֵ:��..
int setvoteflag(char *bname, int flag) {
	int pos;
	struct boardheader fh;

	pos = search_record(BOARDS, &fh, sizeof(fh), cmpbnames, bname);
	if (flag == 0)
		fh.flag = fh.flag & ~BOARD_VOTE_FLAG;
	else
		fh.flag = fh.flag | BOARD_VOTE_FLAG;
	if (substitute_record(BOARDS, &fh, sizeof(fh), pos) == -1)
		prints("Error updating BOARDS file...\n");
}
Example #7
0
/*****************************************************************
 Hashing to disk: search or insert
 */
void insertFromInFile(FILE *fp, int insertflag, FILE **fpInput)
{
    
    char line[100];
    long address;
    char *lastname;
    char *firstname;
    int id;
    char * idstring;
    double amount;
    char *amtstring;
    char *end;
    
    printf("%s\n", insertflag ? "\nINSERT" : "\nSEARCH");
    while(fgets(line, sizeof(line), *fpInput)!=NULL)
    {
        idstring = strtok(line, "\040\t");
        id=atoi(idstring);
        lastname=strtok(NULL, "\040\t");
        firstname=strtok(NULL, "\040\t");
        amtstring=strtok(NULL, "\n");
        amount=strtod(amtstring, &end);
        if (*end == '\0')
            //printf("%f\n", amount);
            printf("\n");
        else
            printf("Not a number: it contains %c!\n", *end);
        
        
        printf("%d %s %s %.2f\n", id, lastname, firstname, amount);
        isValid(lastname, firstname, id, amount);
        address = hash(idstring, 100);
        if (insertflag)
        {
            insert_record(lastname, firstname, id, amount, address, fp);
        }
        else
        {
            search_record(lastname, firstname, id, amount, address, fp);
        }
    }
    return;
}
Example #8
0
File: chat.c Project: wyat/kbs
void call_listen(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1997.11.28 */
    char path[40];
    char uident[IDLEN + 1];
    char ignoreuser[IDLEN + 1];
    int nIdx;

    if (!*arg) {
        printchatline(pthis, "*** 请输入用户的ID ***");
    } else if (!strcasecmp(arg, getCurrentUser()->userid))
        printchatline(pthis, "*** 这是你自己的ID ***");
    else {
        strncpy(uident, arg, IDLEN + 1);
        uident[IDLEN] = 0;
        if (!searchuser(uident))
            /* change getuser -> searchuser, by dong, 1999.10.26 */
            printchatline(pthis, "*** 没有这个ID ***");
        else {
            sethomefile(path, getCurrentUser()->userid, "/ignores");
            nIdx =
                search_record(path, ignoreuser, IDLEN + 1,
                              (RECORD_FUNC_ARG) cmpinames, uident);
            if (nIdx <= 0)
                printchatline(pthis,
                              "*** 该用户的聊天讯息没有被忽略啊 ***");
            else if (delete_record(path, IDLEN + 1, nIdx, NULL, NULL) == 0) {
                bbslog("user", "listen %s", uident);
                printchatline(pthis,
                              "*** 已恢复对该用户聊天讯息的接收 ***");
                sprintf(uident, "/listen %s\n", uident);
                chat_send(pthis, uident);
            } else {
                bbslog("3error", "listen %s failed", uident);
                printchatline(pthis, "*** system error ***");
            }
        }
    }
}
Example #9
0
int b_notes_edit()
{
	char buf[STRLEN], buf2[STRLEN];
	char ans[4];
	int aborted;
	int notetype;

	if (!chkBM(currbp, &currentuser))
		return 0;
	clear();
	move(0, 0);
	prints("�趨��\n\n  (1)һ�㱸��¼\n  (2)���ܱ���¼\n");
	prints("  (3)����ǰ׺��\n  (4)�Ƿ�ǿ��ʹ��ǰ׺\n");
	while (1) {
		getdata(7, 0,"��ǰѡ��[1](0~4): ", ans, 2, DOECHO, YEA);
		if (ans[0] == '0')
		return FULLUPDATE;
		if (ans[0] == '\0')
		strcpy(ans, "1");
		if (ans[0] >= '1' && ans[0] <= '4' )
		break;
	}
	makevdir(currboard); //��������¼Ŀ¼
	notetype = ans[0] - '0';
	if (notetype == 2) {
		setvfile(buf, currboard, "secnotes");
	} else if (notetype == 3) {
		setvfile(buf, currboard, "prefix");
	} else if (notetype == 1) {
		setvfile(buf, currboard, "notes");
	} else if (notetype == 4 ) {
		int pos;
		struct boardheader fh;
		pos = search_record(BOARDS, &fh, sizeof(fh), cmpbnames, currboard);

		if (askyn("�Ƿ�ǿ��ʹ��ǰ׺��", (fh.flag & BOARD_PREFIX_FLAG)?YEA:NA,NA)) {
			fh.flag |= BOARD_PREFIX_FLAG;
		} else {
			fh.flag &= ~BOARD_PREFIX_FLAG;
		}
		substitute_record(BOARDS, &fh, sizeof(fh), pos);
		return FULLUPDATE;
	}
	sprintf(buf2, "(E)�༭ (D)ɾ�� %4s? [E]: ",
			(notetype == 3)?"����ǰ׺��":(notetype == 1) ? "һ�㱸��¼" : "���ܱ���¼");
	getdata(8, 0, buf2, ans, 2, DOECHO, YEA); //ѯ�ʱ༭����ɾ��
	if (ans[0] == 'D' || ans[0] == 'd') { //ɾ������¼
		move(9, 0);
		sprintf(buf2, "���Ҫɾ��ô��");
		if (askyn(buf2, NA, NA)) {
			move(10, 0);
			prints("�Ѿ�ɾ��...\n");
			pressanykey();
			unlink(buf);
			aborted = 1;
		} else
		aborted = -1;
	} else
	aborted = vedit(buf, NA, YEA); //�༭����¼
	if (aborted == -1) {
		pressreturn();
	} else {
		if (notetype == 1)
		setvfile(buf, currboard, "noterec");
		else
		setvfile(buf, currboard, "notespasswd");
		unlink(buf);
	}

	return FULLUPDATE;
}
Example #10
0
File: chat.c Project: wyat/kbs
void call_ignore(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1997.11.28 */
    char buf[STRLEN], buf2[76];
    FILE *fp;
    char uident[IDLEN + 1];
    char path[40];
    char ignoreuser[IDLEN + 1];
    int nIdx;

    sethomefile(path, getCurrentUser()->userid, "/ignores");
    if (!*arg) {
        nIdx = 0;
        if ((fp = fopen(path, "r")) != NULL) {
            strcpy(buf2, "【忽略其讯息的用户ID列表】");
            while (fread(buf, IDLEN + 1, 1, fp) > -0) {
                if (nIdx % 4 == 0) {
                    printchatline(pthis, buf2);
                    *buf2 = '\0';
                }
                nIdx++;
                sprintf(buf2 + strlen(buf2), "  %-13s", buf);
            }
            fclose(fp);
        }
        if (nIdx > 0)
            printchatline(pthis, buf2);
        else
            printchatline(pthis, "*** 尚未设定忽略用户的名单 ***");
    } else if (!strcasecmp(arg, getCurrentUser()->userid))
        printchatline(pthis, "*** 无法忽略自己的信息 ***");
    else {
        strncpy(uident, arg, IDLEN + 1);
        uident[IDLEN] = 0;
        if (!searchuser(uident))
            /* change getuser -> searchuser, by dong, 1999.10.26 */
            printchatline(pthis, "*** 没有这个 ID ***");
        else {
            nIdx =
                search_record(path, ignoreuser, IDLEN + 1,
                              (RECORD_FUNC_ARG) cmpinames, uident);
            if (nIdx > 0)
                printchatline(pthis, "*** 该ID已经被忽略了 ***");
            else {
                fp = fopen(path, "r");
                if (fp != NULL) {
                    fseek(fp, 0, SEEK_END);
                    if (ftell(fp) >= (IDLEN + 1) * MAX_IGNORE) {
                        fclose(fp);
                        printchatline(pthis, "*** 忽略用户名单已满 ***");
                        return;
                    }
                    fclose(fp);
                }
                if (append_record(path, uident, IDLEN + 1) == 0) {
                    printchatline(pthis, "*** 忽略已经设定 ***");
                    bbslog("user", "ignore %s", uident);
                    sprintf(buf, "/ignore %s", uident);
                    chat_send(pthis, buf);
                } else {
                    printchatline(pthis, "*** 系统错误 ***");
                    bbslog("3error", "ignore %s failed", uident);
                }
            }
        }
    }
}
Example #11
0
int kick_user( struct user_info *userinfo )
{
    int     id, ind;
    struct user_info uin;
    struct userec kuinfo;
    char    kickuser[40], buffer[40];

    if (uinfo.mode != LUSERS && uinfo.mode != OFFLINE && uinfo.mode != FRIEND)
    {
        modify_user_mode(ADMIN);
        stand_title("踢使用者下站");
        move(1, 0);
        usercomplete("输入使用者帐号: ", kickuser);
        if (*kickuser == '\0')
        {
            clear();
            return 0;
        }
        if (!(id = getuser(kickuser)))
        {
            move(3, 0);
            prints("无效的用户 ID!");
            clrtoeol();
            pressreturn();
            clear();
            return 0;
        }
        move(1, 0);
        clrtoeol();
        sprintf(genbuf,"踢掉使用者 : [%s].", kickuser);
        move(2, 0);
        if (askyn(genbuf, NA, NA) == NA)
        {
            move(2, 0);
            prints("取消踢使用者..\n");
            pressreturn();
            clear();
            return 0;
        }
        search_record(PASSFILE, &kuinfo, sizeof(kuinfo), cmpuids, kickuser);
        ind = search_ulist(&uin, t_cmpuids, id);
    }
    else
    {
        uin = *userinfo;
        strcpy(kickuser, uin.userid);
        ind = YEA;
    }
    if (!ind||!uin.active||(uin.pid && kill(uin.pid, 0)==-1))
    {
        if(uinfo.mode!=LUSERS&&uinfo.mode!=OFFLINE&&uinfo.mode!=FRIEND)
        {
            move(3, 0);
            prints("用户 [%s] 不在线上",kickuser);
            clrtoeol();
            pressreturn();
            clear();
        }
        return 0;
    }
    kill(uin.pid, SIGHUP);
    //sprintf(buffer, "kicked %s", kickuser);
    //report(buffer);
    if(strcmp(currentuser.userid , kickuser))
    {
        char    secu[STRLEN];
        sprintf(secu, "将用户[%s]踢下站", kickuser);
        securityreport(secu);
    }
    sprintf(genbuf, "%s (%s)", kuinfo.userid, kuinfo.username);
    log_usies("KICK ", genbuf);
    move(2, 0);
    if(uinfo.mode!=LUSERS&&uinfo.mode!=OFFLINE&&uinfo.mode!=FRIEND)
    {
        prints("用户 [%s] 已经被踢下站.\n",kickuser);
        pressreturn();
        clear();
    }
    return 1;
}