Example #1
0
void readRegData(void) {
        char tmp2[10 + HOSTLEN], tmp[10];
        int lineread = 1, i;
        db.nsreg = fopen("nickserv/nickregs.db", "r");
        if(!db.nsreg)
          return;
        while(sfgets(tmp, 10, db.nsreg)) {
                if(tmp[0] != '-') {
                        sSend("GOPER :!ERROR! NickServ databases are corrupted (line %i)", lineread);
                        sshutdown(1);
                }
                sfgets(tmp2, 10 + HOSTLEN, db.nsreg);
                addNReg(tmp2);
                sfgets(tmp, 10, db.nsreg);
                i = atoi(tmp);
                for(i--;i;i--)
                  addNReg(tmp2);
        }
        fclose(db.nsreg);
}
Example #2
0
/**
 * \pre  fp Points to an open infile in which a multi-line dbString has been
 *          reached
 */
static char *dbReadString(FILE *fp)
{
	char tempLine[125], *p = NULL, *y;
	int fin = 0, firstLn = 0;

	while(!fin && sfgets(tempLine, 124, db.is)) {
		y = strrchr(tempLine, '~');
		assert(y != NULL);
		*y = '\0';

		if (y[1] == '$')
			fin = 1;

		strcat(tempLine, "\n");
		if (*tempLine != '\n')
			AppendBuffer(&p, tempLine);
		firstLn = 0;
		*y = '~';
	}
	if (p && *p)
		p[strlen(p) - 1] = '\0';

	return p;
}
Example #3
0
void messWithShareList (uchar bUsage, label roomname)
{
    struct messNode  nodeArray[MAXDIRECT] ;
	   int       i, j, iNode, iTopNode, iOn ;
	   uchar     fKeyFound, fAnyPrinted, fQuit, fDisplayMenu ;
	   char      ch, oldEcho,
		     path[255], buf[255], *lpch, *lpstr,
		     aHotKeys[] = "BCDEFGHIJKLMNOPQRTUVWXYZ1234567890!#$%&*(",
		     *words[256];
	   int       hFile ;

    /* Initialize the array.  */

    for (i = 0; i < MAXDIRECT; i++)
	{
	strcpy (nodeArray[i].nodeName, '\0') ;
	nodeArray[i].fShared = FALSE ;
	nodeArray[i].bHotKey = (uchar) 0 ;
	nodeArray[i].bHotKeyPos = (uchar) 0 ;
	}

    /* In one single pass, we're going to read the NODES file and fill out */
    /* our array based on all the information we find there!               */

    sprintf (path, "%s\\NODES.CIT", cfg.homepath) ;

    hFile = sopen (path, O_TEXT | O_RDONLY, SH_DENYNO) ;

    if (-1 == hFile)
	crashout ("Problem opening NODES.CIT.") ;

    iTopNode = -1 ; 

    while ( !eof(hFile) )
	{
	if (!sfgets (buf, 255, hFile))
	    break ;                            /* Error reading file. */

	if ('#' != buf[0])            /* It's not a keyword. */
	    continue ;

	if (strnicmp (buf, "#NODE", 5) == SAMESTRING)
	    {
	    parse_it (words, buf) ;

	    if (words[1] == NULL)         /* Invalid #NODE entry. */
		continue ;

	    /* We have a new node and its name! */

	    ++iTopNode ;
	    strcpy (nodeArray[iTopNode].nodeName, words[1]) ;
	    }
	else
	    {
	    if (strnicmp (buf, "#ROOM", 5) != SAMESTRING)
		continue ;

	    if (-1 == iTopNode)       /* We don't have a node yet.  */
		continue ;

	    parse_it (words, buf) ;

	    if (stricmp (words[1], roomname) == SAMESTRING)
		nodeArray[iTopNode].fShared = TRUE ;
	    }
	}
    close (hFile) ;

    /* For the short, non-interactive output, just spew it out and quit.  */

    if (SHORT_SEE_NO_MODIFY == bUsage)
	{
	if (-1 == iTopNode)
	    mPrintf ("(No nodes in NODES.CIT.)") ;
	else
	    {
	    iOn = 0 ;
	    fAnyPrinted = FALSE ;

	    while (iOn <= iTopNode)
		{
		if (TRUE == nodeArray[iOn].fShared)
		    {
		    if (fAnyPrinted)
			mPrintf ("3, 0%s", nodeArray[iOn].nodeName) ;
		    else
			{
			mPrintf ("%s", nodeArray[iOn].nodeName) ;
			fAnyPrinted = TRUE ;
			}
		    }
		++iOn ;
		}
	    if (fAnyPrinted)
		mPrintf ("3.0") ;
	    }
	return ;
	}

    if (SEE_WITH_MODIFY == bUsage)
	{
	/* If we found more nodes than we can hotkey, say so and abort.  */

	if (iTopNode >= (int) strlen (aHotKeys))
	    {
	    mPrintf ("Uh-oh!  There are too many nodes in the userlog to use this function.") ;
	    doCR() ;
	    return ;
	    }

	/* Hotkeys are determined by a priority system. First, we try to   */
	/* get the first character of the node name.  Second, we try for   */
	/* the first character following every space in the name.  Third,  */
	/* we try every character in the name.  Last, we scan the entire   */
	/* hotkey string until we find an unused key.                      */

	for (iNode = 0; iNode <= iTopNode; iNode++)
	    {
	    fKeyFound = FALSE ;

	    /* PLAN ONE: Try for the first character.  */

	    ch = (char) toupper (*nodeArray[iNode].nodeName) ;

	    lpch = strchr (aHotKeys, ch) ;

	    if (lpch)                         /* If char = valid hotkey... */
		{
		nodeArray[iNode].bHotKey = *lpch ;
		nodeArray[iNode].bHotKeyPos = 0 ;
		*lpch = FILLED ;                      /* Ptr into aHotKeys */

		continue ;                      /* Do the next node.  */
		}

	    /* PLAN TWO: Try for the first letter of every word.  Since i  */
	    /* starts at one, it's ok to check the previous character for  */
	    /* a space.                                                    */

	    lpstr = nodeArray[iNode].nodeName ;

	    i = 1 ;

	    while (lpstr[i])      /* While we're not on the final NULL...  */
		{
		if ( ' ' == lpstr[i-1] )          /* Is the prev char a space? */
		    {
		    ch = (char) toupper (lpstr[i]) ;
		    lpch = strchr (aHotKeys, ch) ;
		    if (lpch)                                /* Valid chr? */
			{
			nodeArray[iNode].bHotKey = *lpch ;
			nodeArray[iNode].bHotKeyPos = (uchar) i ;
			*lpch = FILLED ;              /* Ptr into aHotKeys */

			fKeyFound = TRUE ; /* Signal release from for iter.*/
			break ;            /* Releases from while loop.    */
			}
		    }
		++i ;
		}

	    /* If the above loop found a key, move on to the next node.  */

	    if (fKeyFound)
		continue ;

	    /* PLAN THREE:  Check every single character in the string for */
	    /* a valid hot key.                                            */

	    i = 0 ;

	    while (lpstr[i])      /* While we're not on the final NULL...  */
		{
		ch = (char) toupper (lpstr[i]) ;
		lpch = strchr (aHotKeys, ch) ;
		if (lpch)                                    /* Valid chr? */
		    {
		    nodeArray[iNode].bHotKey = *lpch ;
		    nodeArray[iNode].bHotKeyPos = (uchar) i ;
		    *lpch = FILLED ;                  /* Ptr into aHotKeys */
		    fKeyFound = TRUE ;    /* Signal release from for iter. */
		    break ;                   /* Releases from while loop. */
		    }
		++i ;
		}

	    /* If the above loop found a key, move on to the next node. */

	    if (fKeyFound)
		continue ;

	    /* PLAN FOUR: Give the node the first available hot key.       */
	    /* Checking done previously assures that we'll get one.        */

	    i = 0 ;

	    while (FILLED == aHotKeys[i])
		++i ;

	    nodeArray[iNode].bHotKey = aHotKeys[i] ;
	    nodeArray[iNode].bHotKeyPos = NOT_IN_STRING ;
	    aHotKeys[i] = FILLED ;
	    }

	fDisplayMenu = TRUE ;
	fQuit = FALSE ;

	for (;;)
	    {
	    if (fDisplayMenu)
		{
		doCR () ;

		for (iNode = 0; iNode <= iTopNode; iNode++)
		    {
		    strcpy (buf, ".........................") ;
		    lpstr = nodeArray[iNode].nodeName ;
		    i = j = 0 ;
		    while (lpstr[i] != '\0')    /* Doesn't copy the NULL */
			{
			    if ( i == (int) nodeArray[iNode].bHotKeyPos)        /* Turn on bold */
				{
				buf[j] = '' ;
				buf[j+1] = '3' ;
				buf[j+2] = lpstr[i] ;
				buf[j+3] = '' ;
				buf[j+4] = '0' ;
				j += 5 ;
				}
			    else
				{
				buf[j] = lpstr[i] ;
				++j ;
				}
			    ++i ;
			}

		    mPrintf ("<3%c0> %s %s", nodeArray[iNode].bHotKey,
			  buf,
			  nodeArray[iNode].fShared ? "YES" : "No") ;
		    doCR() ;
		    }
		}

	    /* Take user input. */

	    doCR() ;
	    mPrintf("<3S0> to save, <3A0> to abort."); doCR();
	    
	    fDisplayMenu = (BOOL)(!expert) ;

	    outFlag = IMPERVIOUS;

	    doCR();
	    mPrintf("2Add/Drop:0 ");
	
	    oldEcho = echo;
	    echo         = NEITHER;
	    ch  = (char) iChar();
	    echo         = oldEcho;

	    if (!((whichIO == CONSOLE) || gotCarrier()))
		return;

	    switch(toupper(ch))
		{
		case 'A':
		    mPrintf("Abort");   doCR();
		    if (getYesNo("Abort", TRUE))
			return;
		    break;
    
		case 'S':
		    mPrintf("Save"); doCR();
		    if (getYesNo("Save", TRUE))
			{
			saveNewReality(nodeArray, roomname, iTopNode) ;
			return ;
			}
		    break ;

		case '\r':
		case '\n':
		case '?' :
		    mPrintf("Menu"); doCR();
		    fDisplayMenu = TRUE;
		    break;

		default:        /* Check if for hotkey and toggle right entry. */
		    for (i = 0; i <= iTopNode; i++)
			if (toupper(ch) == nodeArray[i].bHotKey)
			    {
			    nodeArray[i].fShared = (uchar) !nodeArray[i].fShared ;
			    mPrintf ("%s %s", nodeArray[i].nodeName,
			       nodeArray[i].fShared ? "added." : "dropped.") ;
			    doCR() ;
			    break ;
			    }

		    /* If it fails to break above, it's not valid input. */

		    if (i > iTopNode)
			{
			mPrintf("%c ? for help", ch); doCR();
			break ;
			}
		}
	    }  /* This is in the right place.  */
	}
}
Example #4
0
void saveNewReality (struct messNode *nodeArray, char *room, int iTopNode)
{
    int   hInFile, hOutFile, i ;
    char  buf[256], originalBuf[256], *words[16], *curnode = NULL ;
    BOOL  shouldBePresent, present ;

    sprintf (buf, "%s\\NODES.CIT", cfg.homepath) ;
    hInFile = sopen (buf, O_TEXT | O_RDONLY, SH_DENYNO) ;

    sprintf (buf, "%s\\NODES.!!!", cfg.homepath) ;
    unlink (buf) ;

    hOutFile = sopen (buf, O_CREAT | O_TEXT | O_WRONLY,
			   SH_DENYNO,
			   S_IREAD | S_IWRITE) ;

    if (-1 == hInFile)
	crashout ("Problem opening NODES.CIT.  Snorp.") ;

    if (-1 == hOutFile)
	crashout ("Problem opening NODES.!!!.  Foom.") ;

    /* When we identify a #NODE, a BOOL tells us whether that #NODE shares */
    /* room.  If not, and the room is found, it's not passed through to    */
    /* the temporary file.  If so, and the roomname ISN'T found before the */
    /* next #NODE, it is ADDED just before the next #NODE (or EOF).        */

    originalBuf[0] = '\0' ;

    while ( !eof(hInFile) )
	{
	/* In every loop, the first thing we do is write the line from the */
	/* PREVIOUS loop around.                                           */

	write (hOutFile, originalBuf, strlen (originalBuf)) ;

	if (!sfgets (buf, 255, hInFile))
	    break ;				    /* Error reading file. */

	strcpy (originalBuf, buf) ;

	if ('#' != buf[0])			    /* It's not a keyword. */
	    continue ;

	parse_it (words, buf) ;

	/* We are only concerned about #NODE and #ROOM.  If we're reading  */
	/* #NODE line, first check whether a #ROOM line needs to be added  */
	/* for the previous node.                                          */

	if (SAMESTRING == stricmp (words[0], "#NODE"))
	    {
	    addRoomIfShould (curnode, shouldBePresent, present,
			     room, hOutFile) ;

	    /* In any event, find the node's memory bro and fill in BOOLs. */

	    for (i = 0; i <= iTopNode; i++)
		if (SAMESTRING == stricmp (nodeArray[i].nodeName, words[1]))
		    break ;

	    if (i > iTopNode)            /* Couldn't find node in memory.  */
		{
		curnode = NULL ;
		continue ;
		}

	    present = FALSE ;
	    shouldBePresent = nodeArray[i].fShared ;
	    curnode = nodeArray[i].nodeName ;
	    }


	/* If present is TRUE, we don't need to worry about parsing the    */
	/* rest of the #ROOMs, but instead will sit around until another   */
	/* #NODE comes along.  But if present is false, is this line the   */
	/* room we're looking for?  And should we remove it?               */

	if (present)
	    continue ;

	if (SAMESTRING == stricmp (words[0], "#ROOM"))
	    if (SAMESTRING == stricmp (words[1], room))
		{
		present = TRUE ;

		/* If we've found it and wished we hadn't, nuke the buffer */
		/* and end, so nothing gets written.                       */

		if (!shouldBePresent)
		    originalBuf[0] = '\0' ;
		}
	}

    /* Now that we're out of the file, we need to call addRoomIfShould     */
    /* once more to add a #ROOM line to the last node in the nodes file,   */
    /* if necessary.  And finally, write the last line of the file	   */

    addRoomIfShould (curnode, shouldBePresent, present, room, hOutFile) ;
    write (hOutFile, originalBuf, strlen (originalBuf)) ;

    close (hInFile) ;

    if (0 == close (hOutFile))     /* SUccessful close.  Rename... */
	{
	sprintf (buf, "%s\\NODES.CIT", cfg.homepath) ;
	sprintf (originalBuf, "%s\\NODES.!!!", cfg.homepath) ;

	unlink (buf) ;
	rename (originalBuf, buf) ;
	}
    else
	cPrintf ("Unable to close NODES.!!!  Spork.") ;
}
Example #5
0
/** 
 * \brief Loads the memo database from disk
 */
void readMemoData(void)
{
	RegNickList *nick = NULL;
	RegNickList *from, *rnlb;
	MemoList *newmemo;
	char *command;
	char *topic;
	int done = 0;
	unsigned long linenum = 0;

	db.ms = fopen(MS_DB, "r");

	if (db.ms == NULL)
		return;

	while (!done) {
		if (!(sfgets(dbLine, 2048, db.ms))) {
			if (!done) {
				unexpected_eof(MS_DB);
			}
			done = 1;
			fclose(db.ms);
			return;
		}

		linenum++;
		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX be nicer here... */
			abort();
		}

		command = parse_getarg(&state);

		if (strcmp(command, "data") == 0) {
			nick = getRegNickData(parse_getarg(&state));
			/*! \bug Increment the arguments.. we REALLY need to fix the dbs */
			(void)parse_getarg(&state);
			(void)parse_getarg(&state);
			if (nick) {
				nick->memos->flags = atoi(parse_getarg(&state));
				nick->memos->max = atoi(parse_getarg(&state));
				if (nick->memos->max <= 0)
					nick->memos->max = MS_DEF_RCV_MAX;
			}
		} else if (strcmp(command, "mblock") == 0) {
			MemoBlock *mbitem;
			if (nick && nick->memos) {
				char *nickToBlock;

				if ((nickToBlock = parse_getarg(&state))
					&& (rnlb = getRegNickData(nickToBlock))) {

					mbitem = (MemoBlock *) oalloc(sizeof(MemoBlock));
					mbitem->blockId = rnlb->regnum;
					mbitem->next = nick->memos->firstMblock;
					nick->memos->firstMblock = mbitem;
				}
			}
		} else if (strcmp(command, "redirect") == 0) {
			nick = getRegNickData(parse_getarg(&state));
			if (nick != NULL)
				nick->memos->forward =
					getRegNickData(parse_getarg(&state));
		} else if (strcmp(command, "memo") == 0) {
			char *cn;

			cn = parse_getarg(&state);

			nick = getRegNickData(cn);
			if (nick == NULL) {
				printf("memo: %s not valid\n", cn);
				continue;
			}
			newmemo = (MemoList *) oalloc(sizeof(MemoList));
			newmemo->realto = nick;
			/*! \bug Increment the argument 1, we need to fix the db */
			(void)parse_getarg(&state);
			newmemo->flags = atoi(parse_getarg(&state));
			newmemo->sent = (time_t) atol(parse_getarg(&state));

			/* Memo expiration code */

			if ((time(NULL) - newmemo->sent) >= NICKDROPTIME
			     && !(newmemo->flags & MEMO_SAVE)) {
				FREE(newmemo);
				continue;
			}

			strncpyzt(newmemo->from, parse_getarg(&state), NICKLEN);
			from = getRegNickData(newmemo->from);
			strncpyzt(newmemo->to, parse_getarg(&state), CHANLEN);

			/* Read the memo, skipping the leading : */
			topic = parse_getallargs(&state);
			if (topic == NULL) {
				FREE(newmemo);
				continue;
			}
			newmemo->memotxt = strdup(topic);

			/* Add the memo to the users memobox */
			LIST_ENTRY_INIT(newmemo, ml_lst);
			LIST_INSERT_HEAD(&nick->memos->mb_memos, newmemo, ml_lst);
			if (from && newmemo->flags & MEMO_UNREAD)
				LIST_INSERT_HEAD(&from->memos->mb_sent, newmemo, ml_sent);
			nick->memos->memocnt++;
		} else if (strcmp(command, "done") == 0) {
			done = 1;
		} else {
			fprintf(stderr, "Error in reading memo data (%s) %lu\n",
					dbLine, linenum);
			sshutdown(-1);
		}
#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBUGCHAN " :Read memo data (%s)", MemoServ,
			  dbLine);
#endif

		parse_cleanup(&state);
	}

	fclose(db.ms);
}
Example #6
0
/** 
 * \brief Loads the ChanServ database from disk
 */
void readChanData()
{
	RegChanList *rcl;
	RegNickList *rnl;
	char *command;
	int done = 0, db_version = 1;
	int line_num = 0;
	char *pass;
	char *topic;

	rcl = NULL;
	rnl = NULL;
	db.cs = fopen(CS_DIR "chanserv.db", "r");
	if (db.cs == NULL)
		return;

	while (!done) {
		if ((sfgets(dbLine, 2048, db.cs)) == 0) {
			if (!done) {
				unexpected_eof(CS_DB);
			}
			done = 1;
			fclose(db.cs);
			return;
		}
		line_num++;

		if (parse_init(&state, dbLine) != 0) {
			fprintf(stderr,
					CS_DIR "chanserv.db:%d: " " Fatal error during read "
					" (Null line?) \n", line_num);
			abort();
		}

		command = parse_getarg(&state);
		if (!strcmp(command, "version")) {
			db_version = atoi(parse_getarg(&state));
		}
		else if (!strcmp(command, "channel")) {
			char *sChannelName, *sFounderNick;

			rcl = (RegChanList *) oalloc(sizeof(RegChanList));
			sChannelName = parse_getarg(&state);
			sFounderNick = parse_getarg(&state);
			initRegChanData(rcl);

			if (strlen(sChannelName) >= CHANLEN) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: "
						" Channel name '%.80s' exceeds " " CHANLEN.\n",
						line_num, sChannelName);
				sshutdown(-1);
			} else if (strlen(sFounderNick) >= NICKLEN) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: "
						" Founder nick name '%.80s' " " (%.80s)"
						" exceeds NICKLEN.\n", line_num, sFounderNick,
						sChannelName);
				sshutdown(-1);
			}

			if (!sChannelName || !sFounderNick) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: " " Parse error. (%p, %p)",
						line_num, sChannelName, sFounderNick);
				sshutdown(-1);
			}

			rnl = getRegNickData(sFounderNick);

			strcpy(rcl->name, sChannelName);

			if (rnl)
			{
				rcl->founderId = rnl->regnum;
				rnl->chans++;
			}
			else
				rcl->founderId = RegId(0, 0);

			rcl->mlock = atol(parse_getarg(&state));
			rcl->flags = atol(parse_getarg(&state));
			pass = parse_getarg(&state);	/*! \bug XXX verify this works */
			if (!pass) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: " " Null password?!",
						line_num);
				sshutdown(-1);
			} 

			if ((db_version < 2) || *pass == '@') {
				if (db_version < 2)
					strcpy((char *)rcl->password, pass);
				else
					strcpy((char *)rcl->password, pass + 1);

				if (strlen(pass) > (u_int)((db_version < 2) ? PASSLEN : PASSLEN+1)) {
					fprintf(stderr,
							CS_DIR "chanserv.db:%d: " " password > PASSLEN",
							line_num);
					sshutdown(-1);
				}

				xorit((char *)rcl->password);
				rcl->flags &= ~CENCRYPT;
			}
			else {
				u_char *tmpup = fromBase64(pass+1, NULL);
				int q;

				if (!tmpup)
					abort();
				for(q = 0; q < 16; q++)
					rcl->password[q] = tmpup[q];
				FREE(tmpup);
				rcl->flags |= CENCRYPT;
			}

			rcl->timereg = (time_t) atol(parse_getarg(&state));
			rcl->timestamp = (time_t) atol(parse_getarg(&state));
			strncpyzt(rcl->key, parse_getarg(&state), KEYLEN);
			rcl->limit = atol(parse_getarg(&state));
			rcl->memolevel = atoi(parse_getarg(&state));
			rcl->tlocklevel = atoi(parse_getarg(&state));
			rcl->restrictlevel = atoi(parse_getarg(&state));
			/* The rest of the line - skipping the leading : */
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->desc[0] = '\0';
			else
				strncpyzt(rcl->desc, topic, CHANDESCBUF);
			addRegChan(rcl);
			mostchans++;
		} else if (!strcmp(command, "topic")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			strncpyzt(rcl->tsetby, parse_getarg(&state), NICKLEN);
			rcl->ttimestamp = (time_t) atol(parse_getarg(&state));
			/* The rest of the topic, skipping the : in it */
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->topic = NULL;
			else
				rcl->topic = strdup(topic);
		} else if (!strcmp(command, "url")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->url = NULL;
			else
				rcl->url = strdup(topic);
		} else if (!strcmp(command, "autogreet")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->autogreet = NULL;
			else
				rcl->autogreet = strdup(topic);
		} else if (!strcmp(command, "markby")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			topic = parse_getarg(&state);
			if (topic == NULL)
				rcl->markby = NULL;
			else
				rcl->markby = strdup(topic);
		} else if (strcmp(command, "chkey") == 0) {
			char *tmpp = parse_getarg(&state);
			if (rcl && tmpp)
				rcl->chpw_key = strtoul(tmpp, (char **)0, 16);
		} else if (!strcmp(command, "op")) {
			cAccessList *lame;
			char *tmpName;

			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			tmpName = parse_getarg(&state);
			if ((rnl = getRegNickData(tmpName)) != NULL)
			{
				lame = (cAccessList *) oalloc(sizeof(cAccessList));
				lame->nickId = rnl->regnum;
				lame->uflags = atoi(parse_getarg(&state));
				addChanOp(rcl, lame);
			}
		} else if (!strcmp(command, "akick")) {
			cAkickList *lame;
			lame = (cAkickList *) oalloc(sizeof(cAkickList));
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			strncpyzt(lame->mask, parse_getarg(&state), 70);
			lame->added = (time_t) atol(parse_getarg(&state));
			/* The rest of the string... */
			topic = parse_getallargs(&state);
			if (topic == NULL)
				lame->reason[0] = '\0';
			else {
				strncpyzt(lame->reason, topic, NICKLEN + 50);
			}
			addChanAkick(rcl, lame);
		} else if (!strcmp(command, "done"))
			done = 1;
		else {
			fprintf(stderr, "GLOBOPS :Read chan data (%s)", dbLine);
			sshutdown(-1);
		}

#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBGUGCHAN " :Read chan data (%s)", ChanServ,
			  dbLine);
#endif

		parse_cleanup(&state);
	}
	fclose(db.cs);
}
Example #7
0
/**
 * \brief Loads the NickServ database from disk
 */
void readNickData()
{
	RegNickList *rnl = NULL;
	char *command, *tmpp;
	unsigned char *tmpup;
	int done = 0, db_version = 1;
	int line_num = 0, do_enc = 0;

#ifdef REQ_EMAIL
	readRegData();
#endif

	db.ns = fopen(NS_DB, "r");

	if (db.ns == NULL) {
		logDump(corelog, "Unable to open " NS_DB ": %s", strerror(errno));
		return;
	}

	while (!done) {
		if (!(sfgets(dbLine, 1024, db.ns))) {
			if (!done) {
				unexpected_eof(NS_DB);
			}
			done = 1;
			fclose(db.ns);
			return;
		}

		line_num++;

		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX make a nicer error here! */
			abort();
		}

		command = parse_getarg(&state);
		if (strcmp(command, "version") == 0) {
			tmpp = parse_getarg(&state);
			assert(tmpp);

			if (tmpp)
				db_version = atoi(tmpp);
		}
		else
		if (strcmp(command, "nick") == 0) {
			rnl = (RegNickList *) oalloc(sizeof(RegNickList));
			char *sNick, *sUser, *sHost, *sPass;

			sNick = parse_getarg(&state);
			sUser = parse_getarg(&state);
			sHost = parse_getarg(&state);
			sPass = parse_getarg(&state);

			if (strlen(sNick) >= NICKLEN) {
				fprintf(stderr,
						NS_DB ":%d: " " Nickname '%.80s' exceeds "
						" NICKLEN.\n", line_num, sNick);
				sshutdown(-1);
			} 

			strcpy(rnl->nick, sNick);
			strncpyzt(rnl->user, sUser, USERLEN);
			SetDynBuffer(&rnl->host, sHost);

			if (db_version < 2)
			{
				if (strlen(sPass) > PASSLEN) {
					fprintf(stderr,
						NS_DB ":%d: " " Password for nick '%s' "
						" exceeds PASSLEN.\n", line_num, sNick);
					sshutdown(-1);
				}

				strcpy((char *)rnl->password, xorit(sPass));
			}
			else {
				char encType = *sPass;

				if (encType == '@') {
					if (strlen(sPass+1) > PASSLEN) {
						fprintf(stderr,
							NS_DB ":%d: " " Password for nick '%s' "
							" exceeds PASSLEN.\n", line_num, sNick);
						sshutdown(-1);
					}

					strcpy((char *)rnl->password, xorit(sPass + 1));
					do_enc = 0;
				}
				else if (encType == '$') {
					int q, len;

					tmpup = fromBase64(sPass + 1, &len);
					assert(tmpup);

					for(q = 0; q < 16; q++)
						rnl->password[q] = tmpup[q];
					do_enc = 1;
					FREE(tmpup);
				}
				else
					rnl->password[0] = '\0';
			}

			rnl->timestamp = (time_t) atol(parse_getarg(&state));
			rnl->timereg = (time_t) atol(parse_getarg(&state));
			rnl->flags = atoi(parse_getarg(&state));

			if (db_version >= 3) {
				const char *idString = parse_getarg(&state);
				int av, bv;

				sscanf(idString, "%X*%X", &av, &bv);
				rnl->regnum.SetDirect(top_regnick_idnum, av, bv);				
			}
			else {
				rnl->regnum.SetNext(top_regnick_idnum);
			}

			if (do_enc)
				rnl->flags |= NENCRYPT;
			else
				rnl->flags &= ~NENCRYPT;

			rnl->opflags = 0;
			rnl->idtime = DEF_NDELAY;
			ADD_MEMO_BOX(rnl);
			addRegNick(rnl);
		} else if (strcmp(command, "is") == 0) {
			char *data = parse_getarg(&state);
			if (rnl && data)
				rnl->is_readtime = atol(data);
		} else if (strcmp(command, "oper") == 0) {
			char *opflags_s;
			if (rnl && (rnl == getRegNickData(parse_getarg(&state)))) {
				if ((opflags_s = parse_getarg(&state)))
					rnl->opflags |=
						(strtoul(opflags_s, (char **)0, 10) &
						 ~(OROOT | OSERVOP));
				if (rnl->opflags)
					addOpData(rnl);
			}
		} else if (strcmp(command, "url") == 0) {
			if (rnl && (rnl == getRegNickData(parse_getarg(&state))))
			{
				rnl->url = strdup(parse_getarg(&state));
				if (strlen(rnl->url) > (URLLEN - 1))
					rnl->url[URLLEN - 1] = '\0';
			}
		} else if (strcmp(command, "gecos") == 0) {
#ifdef TRACK_GECOS
			char *gecos = parse_getallargs(&state);
			if (gecos != NULL)
				rnl->gecos = strdup(gecos);
#endif
		} else if (strcmp(command, "akey") == 0) {
#ifdef REQ_EMAIL
			if (rnl)
				rnl->email_key = atoi(parse_getarg(&state));
#endif
		} else if (strcmp(command, "chkey") == 0) {
			char *tmpp = parse_getarg(&state);
			if (rnl && tmpp)
				rnl->chpw_key = strtoul(tmpp, (char **)0, 16);
		} else if (strcmp(command, "markby") == 0) {
			char *mby;

			rnl = getRegNickData(parse_getarg(&state));
			if (!rnl || !(mby = parse_getarg(&state)))
				continue;
			rnl->markby = strdup(mby);
		} else if (strcmp(command, "access") == 0) {
			rnl = getRegNickData(parse_getarg(&state));
			addAccItem(rnl, parse_getarg(&state));
		} else if (!strcmp(command, "email")) {
			rnl = getRegNickData(parse_getarg(&state));

			strncpyzt(rnl->email, parse_getarg(&state), EMAILLEN);

			if (!strcmp(rnl->email, "(none)"))
				strcat(rnl->email, " ");
		} else if (!strcmp(command, "idtime")) {
			rnl = getRegNickData(parse_getarg(&state));
			rnl->idtime = atoi(parse_getarg(&state));
		} else if (!strcmp(command, "done"))
			done = 1;
		else {
			fprintf(stderr, NS_DB ":%d: Error reading nick data (%s)",
					line_num, dbLine);
			sshutdown(-1);
		}
#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBUGCHAN " :Read nick data (%s)", NICKSERV,
			  dbLine);
#endif

		parse_cleanup(&state);
	}
	fclose(db.ns);

	readMemoData();
}
Example #8
0
/** 
 * \brief Loads the InfoServ database from disk
 */
void readInfoData(void)
{
	char *command;
	int done = 0;
	SomeNews *news, *tmpnews;

	is_listhead = NULL;
	db.is = fopen(IS_DB, "r");

	if (db.is == NULL)
		return;

		/**
         * There was still a crash bug in what was here before...
         * cleaning this up .. allocate memory when it's
         * needed, don't allocate it in the beginning and
         * give it up later if superflous in a linked list
         * load.
         * -Mysidia
         */

	while (!done) {
		if (!(sfgets(dbLine, 2048, db.is))) {
			if (!done) {
				unexpected_eof(IS_DB);
			}
			done = 1;
			fclose(db.is);
			return;
		}

		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX be nicer here... */
			abort();
		}

		command = parse_getarg(&state);

		if (!strcmp(command, "article")) {
			char *temp;

			news = (SomeNews *) oalloc(sizeof(SomeNews));
			if (!is_listhead)
				is_listhead = news;
			else {
				for (tmpnews = is_listhead; tmpnews->next;
					 tmpnews = tmpnews->next);
				tmpnews->next = news;
			}
			news->importance = atoi(parse_getarg(&state));
			strncpyzt(news->from, parse_getarg(&state), NICKLEN);
			news->timestamp = atol(parse_getarg(&state));
			temp = parse_getallargs(&state);
			if (temp)
				news->header = strdup(temp);
			news->content = dbReadString(db.is);

			if (news->timestamp > is_last_post_time)
				is_last_post_time = news->timestamp;
		}

		else if (!strcmp(command, "done"))
			done = 1;
		else
			sshutdown(-1);

		parse_cleanup(&state);
	}
	fclose(db.is);
}
Example #9
0
/** 
 * \brief Loads the clone rule database from disk
 */
void readTriggerData(void)
{
	CloneRule *rule = NULL;
	char *command, *text;
	int done = 0;
	unsigned long linenum = 0;

	db.trigger = fopen(TRG_DB, "r");

	if (db.trigger == NULL) {
		logDump(corelog,
				"Unable to open trigger database for read access: %s",
				strerror(errno));
		return;
	}

	while (!done) {
		if (!(sfgets(dbLine, 2048, db.trigger))) {
			if (!done) {
				unexpected_eof(TRG_DB);
			}
			done = 1;
			fclose(db.trigger);
			return;
		}
		linenum++;

		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX be nicer here... */
			abort();
		}

		command = parse_getarg(&state);

		if (strcmp(command, "Trigger") == 0) {
			rule = NewCrule();
			rule->kill_msg = NULL;
			rule->warn_msg = NULL;
			strncpyzt(rule->mask, parse_getarg(&state),
					  sizeof(rule->mask));
			rule->mask[sizeof(rule->mask) - 1] = '\0';
			rule->trigger = atoi(parse_getarg(&state));
			rule->utrigger = atoi(parse_getarg(&state));
			rule->flags = atol(parse_getarg(&state));
			AddCrule(rule, -2);	/* -2 is magic for append to end */
		} else if (strcmp(command, "Killmsg") == 0) {
			text = parse_getallargs(&state);
			if (text && rule)
				rule->kill_msg = strdup(text);
		} else if (strcmp(command, "Warnmsg") == 0) {
			text = parse_getallargs(&state);
			if (text && rule)
				rule->warn_msg = strdup(text);
		} else if (strcmp(command, "done") == 0) {
			done = 1;
		} else {
			fprintf(stderr, "Error in reading trigger data (%s) %lu\n",
					dbLine, linenum);
			parse_cleanup(&state);
			return;
		}
#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBUGCHAN " :Read trigger data (%s)",
			  OperServ, dbLine);
#endif

		parse_cleanup(&state);
	}

	fclose(db.trigger);
}