void HISmaint() { FILE *hismaint; time_t lasthist, now; char maintbuff[4096]; char *ptr; if (!isfile(HISTORY)) { makedbz(HISTORY, DEFAULT_HIST_SIZE); } hismaint = fopen(HISTORY, "r"); if (hismaint == NULL) { return; } fgets(maintbuff, sizeof(maintbuff), hismaint); ptr = (char *) strchr(maintbuff, '\t'); if (ptr != NULL) { ptr++; lasthist = atol(ptr); time(&now); if (lasthist + 86400 * Expiredays * 2 < now) { char newhistpath[1024]; char newhistdirpath[1024]; char newhistpagpath[1024]; (void) HISclose(); sprintf(newhistpath, "%s.n", HISTORY); sprintf(newhistdirpath, "%s.n.dir", HISTORY); sprintf(newhistpagpath, "%s.n.pag", HISTORY); if (!isfile(newhistdirpath)) { makedbz(newhistpath, DEFAULT_HIST_SIZE); } myHISsetup(newhistpath); while (fgets(maintbuff, sizeof(maintbuff), hismaint) != NULL) { datum key; ptr = (char *) strchr(maintbuff, '\t'); if (ptr != NULL) { *ptr = '\0'; ptr++; lasthist = atol(ptr); } else { continue; } if (lasthist + 99600 * Expiredays < now) continue; key.dptr = maintbuff; key.dsize = strlen(maintbuff); myHISwrite(&key, ptr); } (void) HISclose(); rename(HISTORY, (char *) fileglue("%s.o", HISTORY)); rename(newhistpath, HISTORY); rename(newhistdirpath, (char *) fileglue("%s.dir", HISTORY)); rename(newhistpagpath, (char *) fileglue("%s.pag", HISTORY)); (void) HISsetup(); } } fclose(hismaint); }
int receive_control() { char *boardhome, *fname; char firstpath[MAXPATHLEN], *firstpathbase; char **splitptr, *ngptr; newsfeeds_t *nf; innbbsdlog("control post %s\n", HEADER[CONTROL_H]); boardhome = (char *) fileglue("%s/boards/control", BBSHOME); testandmkdir(boardhome); *firstpath = '\0'; if (isdir(boardhome)) { fname = (char *) post_article(boardhome, FROM, "control", bbspost_write_control, NULL, firstpath); if (fname != NULL) { if (firstpath[0] == '\0') sprintf(firstpath, "%s/boards/control/%s", BBSHOME, fname); if (storeDB(HEADER[MID_H], (char *) fileglue("control/%s", fname)) < 0) { } bbsfeedslog(fileglue("control/%s", fname), 'C'); firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); splitptr = (char **) BNGsplit(GROUPS); for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) { if (*ngptr == '\0') continue; nf = (newsfeeds_t *) search_group(ngptr); if (nf == NULL) continue; if (nf->board == NULL) continue; if (nf->path == NULL) continue; feedfplog(nf, firstpathbase, 'C'); } } } return 0; }
int main(int argc, char **argv) { char *ptr, *server, *active; int c, errflag=0; int lockfd; char *inputtype; DefaultNntpProtocol = NntpIhaveProtocol; *DefaultNewsgroups = '\0'; *DefaultModerator = '\0'; *DefaultOrganization = '\0'; *DefaultTrustFrom = '\0'; *DefaultTrustfrom = '\0'; inputtype = NntpInputType; while ((c = getopt(argc,argv,"f:F:m:o:g:w:r:p:a:s:t:h?ncv"))!= -1) switch (c) { case 'v': verboseon("bbsnnrp.log"); break; case 'c': ResetActive = 1; break; case 'g': strncpy(DefaultNewsgroups, optarg, sizeof DefaultNewsgroups); break; case 'm': strncpy(DefaultModerator, optarg, sizeof DefaultModerator); break; case 'o': strncpy(DefaultOrganization, optarg, sizeof DefaultOrganization); break; case 'f': strncpy(DefaultTrustfrom, optarg, sizeof DefaultTrustfrom); break; case 'F': strncpy(DefaultTrustFrom, optarg, sizeof DefaultTrustFrom); break; case 'r': { char *hostptr; AskLocal = 0; DefaultRemoteHost = optarg; if ((hostptr = strchr(optarg,':')) != NULL) { *hostptr = '\0'; DefaultRemoteHost = hostptr+1; if (strcasecmp( optarg, "post" ) == 0) DefaultNntpProtocol = NntpPostProtocol; *hostptr = ':'; } break; } case 'w': RunOnce = 0; DefaultWait = atoi(optarg); if (DefaultWait < MIN_WAIT) DefaultWait = MIN_WAIT; break; case 'p': if (AskLocal == 0) { DefaultPort = optarg; } else { DefaultPath = optarg; } break; case 'n': StatHistory = 0; break; case 'a': Max_Arts = atol(optarg); if (Max_Arts < 0) Max_Arts = 0; break; case 's': Max_Stats = atol(optarg); if (Max_Stats < 0) Max_Stats = 0; break; case 't': if ( strcasecmp(optarg,StdinInputType) == 0) { inputtype = StdinInputType; } break; case 'h': case '?': default: errflag ++; } if (errflag > 0) { usage(argv[0]); return(1); } if (inputtype == NntpInputType && argc - optind < 2) { usage(argv[0]); exit(1); } if (inputtype == NntpInputType) { server = argv[optind]; active = argv[optind+1]; if ( isfile(active) ) { strncpy(BBSNNRP.activefile, active, sizeof BBSNNRP.activefile); } else if ( strchr(active,'/') == NULL) { sprintf(BBSNNRP.activefile, "%s/innd/%.*s",BBSHOME, sizeof BBSNNRP.activefile - 7 - strlen(BBSHOME), active); } else { strncpy(BBSNNRP.activefile, active, sizeof BBSNNRP.activefile); } strncpy(LockFile , (char*)fileglue("%s.lock",active), sizeof LockFile); if ((lockfd = open(LockFile, O_RDONLY)) >= 0) { char buf[10]; int pid; if (read(lockfd, buf, sizeof buf) > 0 && (pid = atoi(buf))>0 && kill(pid,0)==0) { fprintf(stderr, "another process [%d] running\n", pid); exit(1); } else { fprintf(stderr, "no process [%d] running, but lock file existed, unlinked\n", pid); unlink(LockFile); } close(lockfd); } if ((lockfd = open(LockFile, O_RDWR|O_CREAT|O_EXCL,0644)) < 0) { fprintf( stderr, "maybe another %s process running\n",argv[0]); exit(1); } else { char buf[10]; int pid; sprintf(buf,"%-.8d\n",getpid()); write(lockfd, buf, strlen(buf)); close(lockfd); } for (;;) { if (!initial_bbs(NULL)) { fprintf(stderr, "Initial BBS failed\n"); exit(1); } initsockets(server, &BBSNNRP, inputtype); ptr = (char*)strrchr(active,'/'); if (ptr != NULL) ptr++; else ptr = active; sprintf(BBSNNRP.rcfile,"%s/.newsrc.%s.%s",INNDHOME, server, ptr); initrcfiles(&BBSNNRP); signal(SIGTERM, doterm); signal(SIGKILL, doterm); signal(SIGHUP, doterm); signal(SIGPIPE, doterm); readnews(&BBSNNRP); writerc(&BBSNNRP); closesockets(); if (RunOnce) break; sleep(DefaultWait); } unlink(LockFile); } /* NntpInputType */ else { if (!initial_bbs(NULL)) { fprintf(stderr, "Initial BBS failed\n"); exit(1); } initsockets(server, &BBSNNRP, inputtype); signal(SIGTERM, doterm); signal(SIGKILL, doterm); signal(SIGHUP, doterm); signal(SIGPIPE, doterm); stdinreadnews(&BBSNNRP); closesockets(); } /* stdin input type */ return 0; }
/* process cancel write */ int receive_article() { char *user, *userptr; char *ngptr, *pathptr; char **splitptr; static char userid[32]; static char xdate[32]; static char xpath[180]; time_t datevalue; newsfeeds_t *nf; char *boardhome; char hispaths[4096]; char firstpath[MAXPATHLEN], *firstpathbase; char *lesssym, *nameptrleft, *nameptrright; static char sitebuf[80]; if (FROM == NULL) { innbbsdlog(":Err: article without usrid %s\n", MSGID); return 0; } if (strchr(FROM, '<') && (FROM[strlen(FROM) - 1] == '>')) user = (char *) strrchr(FROM, '@'); else user = (char *) strchr(FROM, '@'); lesssym = (char *) strchr(FROM, '<'); nameptrleft = NULL, nameptrright = NULL; if (lesssym == NULL || lesssym >= user) { lesssym = FROM; nameptrleft = strchr(FROM, '('); if (nameptrleft != NULL) nameptrleft++; nameptrright = strrchr(FROM, ')'); } else { nameptrleft = FROM; nameptrright = strrchr(FROM, '<'); lesssym++; } if (user != NULL) { *user = '******'; userptr = (char *) strchr(FROM, '.'); if (userptr != NULL) { *userptr = '\0'; strncpy(userid, lesssym, sizeof userid); *userptr = '.'; } else { strncpy(userid, lesssym, sizeof userid); } *user = '******'; } else { strncpy(userid, lesssym, sizeof userid); } if (!isalnum(userid[0])) strcpy(userid, "Unknown"); strcat(userid, "."); datevalue = parsedate(DATE, NULL); if (datevalue > 0) { char *p; strncpy(xdate, ctime(&datevalue), sizeof(xdate)); p = (char *) strchr(xdate, '\n'); if (p != NULL) *p = '\0'; DATE = xdate; } if (SITE && strcasecmp("Computer Science & Information Engineering NCTU", SITE) == 0) { SITE = NCTUCSIETxt; } else if (SITE && strcasecmp("Dep. Computer Sci. & Information Eng., Chiao Tung Univ., Taiwan, R.O.C", SITE) == 0) { SITE = NCTUCSIETxt; } else if (SITE == NULL || *SITE == '\0') { if (nameptrleft != NULL && nameptrright != NULL) { char savech = *nameptrright; *nameptrright = '\0'; strncpy(sitebuf, nameptrleft, sizeof sitebuf); *nameptrright = savech; SITE = sitebuf; } else /* * SITE = "(Unknown)"; */ SITE = ""; } if (strlen(MYBBSID) > 70) { innbbsdlog(" :Err: your bbsid %s too long\n", MYBBSID); return 0; } sprintf(xpath, "%s!%.*s", MYBBSID, (int)(sizeof(xpath) - strlen(MYBBSID) - 2), PATH); PATH = xpath; for (pathptr = PATH; pathptr != NULL && (pathptr = strstr(pathptr, ".edu.tw")) != NULL;) { if (pathptr != NULL) { strcpy(pathptr, pathptr + 7); } } xpath[71] = '\0'; echomaillog(); *hispaths = '\0'; splitptr = (char **) BNGsplit(GROUPS); firstpath[0] = '\0'; firstpathbase = firstpath; /* * try to split newsgroups into separate group and check if any * duplicated */ /* * try to use hardlink */ /* * for ( ngptr = GROUPS, nngptr = (char*) strchr(ngptr,','); ngptr != * NULL && *ngptr != '\0'; nngptr = (char*)strchr(ngptr,',')) { */ for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) { char *boardptr, *nboardptr; /* * if (nngptr != NULL) { nngptr = '\0'; } */ if (*ngptr == '\0') continue; nf = (newsfeeds_t *) search_group(ngptr); /* * printf("board %s\n",nf->board); */ if (nf == NULL) { innbbsdlog("unwanted \'%s\'\n", ngptr); /* * if( strstr( ngptr, "tw.bbs" ) != NULL ) { } */ continue; } if (nf->board == NULL || !*nf->board) continue; if (nf->path == NULL || !*nf->path) continue; for (boardptr = nf->board, nboardptr = (char *) strchr(boardptr, ','); boardptr != NULL && *boardptr != '\0'; nboardptr = (char *) strchr(boardptr, ',')) { if (nboardptr != NULL) { *nboardptr = '\0'; } if (*boardptr == '\t') { goto boardcont; } boardhome = (char *) fileglue("%s/boards/%s", BBSHOME, boardptr); if (!isdir(boardhome)) { innbbsdlog(":Err: unable to write %s\n", boardhome); } else { char *fname; /* * if ( !isdir( boardhome )) { innbbsdlog( ":Err: * unable to write %s\n",boardhome); * testandmkdir(boardhome); } */ fname = (char *) post_article(boardhome, userid, boardptr, bbspost_write_post, NULL, firstpath); if (fname != NULL) { fname = (char *) fileglue("%s/%s", boardptr, fname); if (firstpath[0] == '\0') { sprintf(firstpath, "%s/boards/%s", BBSHOME, fname); firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); } if (strlen(fname) + strlen(hispaths) + 1 < sizeof(hispaths)) { strcat(hispaths, fname); strcat(hispaths, " "); } } else { innbbsdlog("fname is null %s\n", boardhome); return -1; } } boardcont: if (nboardptr != NULL) { *nboardptr = ','; boardptr = nboardptr + 1; } else break; } /* for board1,board2,... */ /* * if (nngptr != NULL) ngptr = nngptr + 1; else break; */ if (*firstpathbase) feedfplog(nf, firstpathbase, 'P'); } if (*hispaths) bbsfeedslog(hispaths, 'P'); if (Junkhistory || *hispaths) { if (storeDB(HEADER[MID_H], hispaths) < 0) { innbbsdlog("store DB fail\n"); /* * I suspect here will introduce duplicated articles */ /* * return -1; */ } } return 0; }