📄 cc.c
字号:
char *av[];{ static char YES[] = "y"; char *p; p = av[0]; if (Reservation && EQ(p, Reservation)) { DISPOSE(Reservation); Reservation = NULL; } if (RejectReason && EQ(p, RejectReason)) { DISPOSE(RejectReason); RejectReason = NULL; } if (Mode == OMrunning) return "1 Already running"; if (*p && !EQ(p, ModeReason)) return "1 Wrong reason"; DISPOSE(ModeReason); ModeReason = NULL; Mode = OMrunning; if (NNRPReason && NNRPFollows) { av[0] = YES; av[1] = p; (void)CCreaders(av); } if (ErrorCount < 0) ErrorCount = IO_ERROR_COUNT; HISsetup(); syslog(L_NOTICE, "%s running", LogName); if (ICDneedsetup) ICDsetup(TRUE); SCHANwakeup((POINTER)&Mode); return NULL;}/*** Hangup a channel.*/STATIC STRINGCChangup(av) char *av[];{ register CHANNEL *cp; register int fd; register char *p; int i; /* Parse the argument, a channel number. */ for (p = av[0], fd = 0; *p; p++) { if (!CTYPE(isdigit, *p)) return "1 Bad channel number"; fd = fd * 10 + *p - '0'; } /* Loop over all channels for the desired one. */ for (i = 0; (cp = CHANiter(&i, CTany)) != NULL; ) if (cp->fd == fd) { p = CHANname(cp); switch (cp->Type) { default: (void)sprintf(CCreply.Data, "1 Can't close %s", p); return CCreply.Data; case CTexploder: case CTprocess: case CTfile: case CTnntp: syslog(L_NOTICE, "%s hangup", p); CHANclose(cp, p); return NULL; } } return "1 Not active";}/*** Return our operating mode.*//* ARGSUSED */STATIC STRINGCCmode(av) char *av[];{ register char *p; register int i; int h; char buff[BUFSIZ]; p = buff; p += strlen(strcpy(buff, "0 Server ")); /* Server's mode. */ switch (Mode) { default: (void)sprintf(p, "Unknown %d", Mode); p += strlen(p); break; case OMrunning: p += strlen(strcpy(p, "running")); break; case OMpaused: p += strlen(strcpy(p, "paused ")); p += strlen(strcpy(p, ModeReason)); break; case OMthrottled: p += strlen(strcpy(p, "throttled ")); p += strlen(strcpy(p, ModeReason)); break; } *p++ = '\n'; if (RejectReason) { p += strlen(strcpy(p, "Rejecting ")); p += strlen(strcpy(p, RejectReason)); } else p += strlen(strcpy(p, "Allowing remote connections")); /* Server parameters. */ for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; ) i++; *p++ = '\n'; (void)sprintf(p, "Parameters c %ld i %d (%d) l %ld o %d t %ld %s %s", (long)Cutoff / (24L * 60L * 60L), MaxIncoming, i, LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec, AmSlave ? "slave" : "normal", AnyIncoming ? "any" : "specified"); p += strlen(p); /* Reservation. */ *p++ = '\n'; if (Reservation) { (void)sprintf(p, "Reserved %s", Reservation); p += strlen(p); } else p += strlen(strcpy(p, "Not reserved")); /* Newsreaders. */ *p++ = '\n'; p += strlen(strcpy(p, "Readers ")); if (NNRPFollows) p += strlen(strcpy(p, "follow ")); else p += strlen(strcpy(p, "separate ")); if (NNRPReason == NULL) p += strlen(strcpy(p, "enabled")); else { (void)sprintf(p, "disabled %s", NNRPReason); p += strlen(p); } i = strlen(buff); if (CCreply.Size <= i) { CCreply.Size = i; RENEW(CCreply.Data, char, CCreply.Size + 1); } (void)strcpy(CCreply.Data, buff); return CCreply.Data;}/*** Name the channels. ("Name the bats -- simple names.")*/STATIC STRINGCCname(av) char *av[];{ static char NL[] = "\n"; static char NIL[] = "\0"; register CHANNEL *cp; register char *p; register int count; int i; p = av[0]; if (*p != '\0') { if ((cp = CHANfromdescriptor(atoi(p))) == NULL) return COPY(CCnochannel); (void)sprintf(CCreply.Data, "0 %s", CHANname(cp)); return CCreply.Data; } BUFFset(&CCreply, "0 ", 2); for (count = 0, i = 0; (cp = CHANiter(&i, CTany)) != NULL; ) { if (cp->Type == CTfree) continue; if (++count > 1) BUFFappend(&CCreply, NL, 1); p = CHANname(cp); BUFFappend(&CCreply, p, strlen(p)); } BUFFappend(&CCreply, NIL, 1); return CCreply.Data;}/*** Create a newsgroup.*/STATIC STRINGCCnewgroup(av) char *av[];{ static char TIMES[] = _PATH_ACTIVETIMES; static char WHEN[] = "updating active.times"; register int fd; register char *p; NEWSGROUP *ngp; char *Name; char *Rest; STRING who; char buff[SMBUF]; Name = av[0]; if (Name[0] == '.' || strspn(Name, "0123456789") == strlen(Name)) return "1 Illegal newsgroup name"; for (p = Name; *p; p++) if (*p == '.') { if (p[1] == '.' || p[1] == '\0') return "1 Double or trailing period in newsgroup name"; } else if (ISWHITE(*p) || *p == ':' || *p == '!') return "1 Illegal character in newsgroup name"; Rest = av[1]; if (Rest[0] != NF_FLAG_ALIAS) { Rest[1] = '\0'; if (CTYPE(isupper, Rest[0])) Rest[0] = tolower(Rest[0]); } if ((ngp = NGfind(Name)) != NULL) return CCdochange(ngp, Rest); /* Update the log of groups created. Don't use stdio because SunOS * 4.1 has broken libc which can't handle fd's greater than 127. */ if ((fd = open(TIMES, O_WRONLY | O_APPEND | O_CREAT, 0664)) < 0) { IOError(WHEN); syslog(L_ERROR, "%s cant fopen %s %m", LogName, TIMES); } else { who = av[2]; if (*who == '\0') who = NEWSMASTER; (void)sprintf(buff, "%s %ld %s\n", Name, Now.time, who); if (xwrite(fd, buff, strlen(buff)) < 0) { IOError(WHEN); syslog(L_ERROR, "%s cant write %s %m", LogName, TIMES); } if (close(fd) < 0) { IOError(WHEN); syslog(L_ERROR, "%s cant close %s %m", LogName, TIMES); } if (AmRoot) xchown(TIMES); } /* Update the in-core data. */ if (!ICDnewgroup(Name, Rest)) return "1 Failed"; syslog(L_NOTICE, "%s newgroup %s as %s", LogName, Name, Rest); if (*Rest != NF_FLAG_ALIAS) { /* Create the spool directory. */ for (p = Name; *p; p++) if (*p == '.') *p = '/'; if (!MakeSpoolDirectory(Name)) syslog(L_NOTICE, "%s cant mkdir %s %m", LogName, Name); } return NULL;}/*** Parse and set a boolean flag.*/STATIC BOOLCCparsebool(name, bp, value) char name; BOOL *bp; char value;{ switch (value) { default: return FALSE; case 'y': *bp = FALSE; break; case 'n': *bp = TRUE; break; } syslog(L_NOTICE, "%s changed -%c %c", LogName, name, value); return TRUE;}/*** Change a running parameter.*/STATIC STRINGCCparam(av) char *av[];{ static char BADVAL[] = "1 Bad value"; char *p; p = av[1]; switch (av[0][0]) { default: return "1 Unknown parameter"; case 'a': if (!CCparsebool('a', &AnyIncoming, *p)) return BADVAL; break; case 'c': Cutoff = atoi(p) * 24 * 60 * 60; syslog(L_NOTICE, "%s changed -c %d", LogName, Cutoff); break; case 'i': MaxIncoming = atoi(p); syslog(L_NOTICE, "%s changed -i %d", LogName, MaxIncoming); break; case 'l': LargestArticle = atol(p); syslog(L_NOTICE, "%s changed -l %ld", LogName, LargestArticle); break; case 'n': if (!CCparsebool('n', &NNRPFollows, *p)) return BADVAL; break; case 'o': MaxOutgoing = atoi(p); syslog(L_NOTICE, "%s changed -o %d", LogName, MaxOutgoing); break; case 't': TimeOut.tv_sec = atol(p); syslog(L_NOTICE, "%s changed -t %ld", LogName, (long)TimeOut.tv_sec); break; } return NULL;}/*** Common code to implement a pause or throttle.*/STRINGCCblock(NewMode, reason) OPERATINGMODE NewMode; char *reason;{ static char NO[] = "n"; STRING av[2]; if (*reason == '\0') return CCnoreason; if (Reservation) { if (!EQ(reason, Reservation)) { (void)sprintf(CCreply.Data, "1 Reserved \"%s\"", Reservation); return CCreply.Data; } DISPOSE(Reservation); Reservation = NULL; } ICDwrite(); HISclose(); Mode = NewMode; if (ModeReason) DISPOSE(ModeReason); ModeReason = COPY(reason); if (NNRPReason == NULL && NNRPFollows) { av[0] = NO; av[1] = ModeReason; (void)CCreaders(av); } syslog(L_NOTICE, "%s %s %s", LogName, NewMode == OMpaused ? "paused" : "throttled", reason); return NULL;}/*** Enter paused mode.*/STATIC STRINGCCpause(av) char *av[];{ switch (Mode) { case OMrunning: return CCblock(OMpaused, av[0]); case OMpaused: return "1 Already paused"; case OMthrottled: return "1 Already throttled"; } return "1 Unknown mode";}/*** Allow or disallow newsreaders.*/STATIC STRINGCCreaders(av) char *av[];{ char *p; switch (av[0][0]) { default: return "1 Bad flag"; case 'y': if (NNRPReason == NULL) return "1 Already allowing readers"; p = av[1]; if (*p && !EQ(p, NNRPReason)) return "1 Wrong reason"; DISPOSE(NNRPReason); NNRPReason = NULL; break; case 'n': if (NNRPReason) return "1 Already not allowing readers"; p = av[1]; if (*p == '\0') return CCnoreason; NNRPReason = COPY(p); break; } return NULL;}/*** Re-exec ourselves.*/STATIC STRINGCCxexec(av) char *av[];{ static char INND[] = _PATH_INND; static char INNDSTART[] = _PATH_INNDSTART; char *p; if (CCargv == NULL) return "1 no argv!"; /* Get the pathname. */ p = av[0]; if (*p == '\0') CCargv[0] = AmRoot ? INND : INNDSTART; else if (EQ(p, "innd")) CCargv[0] = INND; else if (EQ(p, "inndstart")) CCargv[0] = INNDSTART; else return "1 Bad value"; JustCleanup(); syslog(L_FATAL, "%s execv %s", LogName, CCargv[0]); (void)execv(CCargv[0], CCargv); syslog(L_FATAL, "%s cant execv %s %m", LogName, CCargv[0]); _exit(1); /* NOTREACHED */}/*** Refile an article.*/STATIC STRINGCCrefile(av) char *av[];{ char *head; /* xxx multiple groups? */ if (NGfind(av[1]) == NULL) return CCnogroup; head = ARTreadheader(av[0]); if (head == NULL) return "1 No such article"; return "1 Not yet implemented";}/*** Reject remote readers.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -