Example #1
0
static void FixDayDow(CronLine * line)
{
	short i;
	short weekUsed = 0;
	short daysUsed = 0;

	for (i = 0; i < arysize(line->cl_Dow); ++i) {
		if (line->cl_Dow[i] == 0) {
			weekUsed = 1;
			break;
		}
	}
	for (i = 0; i < arysize(line->cl_Days); ++i) {
		if (line->cl_Days[i] == 0) {
			daysUsed = 1;
			break;
		}
	}
	if (weekUsed && !daysUsed) {
		memset(line->cl_Days, 0, sizeof(line->cl_Days));
	}
	if (daysUsed && !weekUsed) {
		memset(line->cl_Dow, 0, sizeof(line->cl_Dow));
	}
}
Example #2
0
void report(UWORD errtype, BYTE *prefix, BYTE *msg, ...) {
	va_list argptr;
	static BYTE *errtypes[] = { MSG_NOTICE, MSG_WARNING, MSG_ERROR, MSG_FATAL,
			MSG_FAULT };
	++msgcnt[errtype];

	if (errtype >= arysize(errtypes))
		return;

	if (errtype < errorlevel)
		return;

	printf(errtypes[errtype]);
	if (prefix != NULL)
		printf(" %s", prefix);
	else
		printf(": ");

	va_start(argptr, msg);
	vprintf(msg, argptr);
	va_end(argptr);
	printf("\n");

	if ((errtype == E_FATAL) || (errtype == E_FAULT))
		abend();
}
Example #3
0
void
NNTPHelp(Connection *conn, char **pptr)
{
    Command *scan;

    MBLogPrintf(conn, &conn->co_TMBuf, "100 Legal commands\r\n");
    for (scan = &Cmds[0]; scan < &Cmds[arysize(Cmds)]; ++scan) {
	int ok = 0;

	if (conn->co_Flags & COF_SERVER) {
	    if (scan->cmd_Flags & CMDF_SERVER) {
		ok = 1;
		if ((scan->cmd_Flags & CMDF_NOTFEEDONLY) &&
		    (conn->co_Auth.dr_Flags & DF_FEEDONLY)
		) {
		    ok = 0;
		}
	    }
	} else {
	    if (scan->cmd_Flags & CMDF_READER)
		ok = 1;
	    if (!conn->co_Auth.dr_ReaderDef->rd_AllowNewnews &&
				(strcmp(scan->cmd_Name, "newnews") == 0))
		ok = 0;
	}
	if (ok)
	    MBPrintf(&conn->co_TMBuf, "  %s %s\r\n", scan->cmd_Name, scan->cmd_Help);
    }
    MBPrintf(&conn->co_TMBuf, ".\r\n");
    NNCommand(conn);
}
Example #4
0
void
FixDayDow(CronLine *line)
{
	unsigned short i,j;
	short weekUsed = 0;
	short daysUsed = 0;

	for (i = 0; i < arysize(line->cl_Dow); ++i) {
		if (line->cl_Dow[i] == 0) {
			weekUsed = 1;
			break;
		}
	}
	for (i = 0; i < arysize(line->cl_Days); ++i) {
		if (line->cl_Days[i] == 0) {
			if (weekUsed) {
				if (!daysUsed) {
					daysUsed = 1;
					/* change from "every Mon" to "ith Mon"
					 * 6th,7th... Dow are treated as 1st,2nd... */
					for (j = 0; j < arysize(line->cl_Dow); ++j) {
						line->cl_Dow[j] &= 1 << (i-1)%5;
					}
				} else {
					/* change from "nth Mon" to "nth or ith Mon" */
					for (j = 0; j < arysize(line->cl_Dow); ++j) {
						if (line->cl_Dow[j])
							line->cl_Dow[j] |= 1 << (i-1)%5;
					}
				}
				/* continue cycling through cl_Days */
			}
			else {
				daysUsed = 1;
				break;
			}
		}
	}
	if (weekUsed) {
		memset(line->cl_Days, 0, sizeof(line->cl_Days));
	}
	if (daysUsed && !weekUsed) {
		memset(line->cl_Dow, 0, sizeof(line->cl_Dow));
	}
}
Example #5
0
void
NNCommand2(Connection *conn)
{
    char *ptr;
    char *cmd;
    char *buf;
    Command *scan;
    int len;

    conn->co_Func = NNCommand2;
    conn->co_State = "waitcmd";

    /*
     * we have to be careful in regards to recursive operation, nor do
     * we want one descriptor to hog the process.  We can't set RFds
     * because the next command may already be entirely loaded into an
     * MBuf so setting RFds may not unblock us.  Instead, we set WFds
     * which basically forces a wakeup at some point in the future.
     */

    if (conn->co_FCounter) {
	FD_SET(conn->co_Desc->d_Fd, &WFds);
	/*
	 * if the other side closed the connection, select() is
	 * not going to wake up for write(!) so set RFds too.
	 */
	if (conn->co_TMBuf.mh_WError)
	    FD_SET(conn->co_Desc->d_Fd, &RFds);
	return;
    }
    ++conn->co_FCounter;

    /*
     * if there is still output pending, do not process the next
     * command.
     */
    if (conn->co_TMBuf.mh_Bytes > 0 && !conn->co_TMBuf.mh_WError)
	return;

    /*
     * get command
     */

    if ((len = MBReadLine(&conn->co_RMBuf, &buf)) == 0) {
	StatusUpdate(conn, "(idle)");
	return;
    }

    conn->co_ByteCountType = DRBC_NONE;

    /*
     * check EOF
     */

    if (len < 0 || conn->co_TMBuf.mh_WError) {
	NNTerminate(conn);
	return;
    }

    /*
     * strip CR LF
     */

    ptr = buf;

    if (len > 1 && ptr[len-2] == '\r')
	ptr[len-2] = 0;

    if (DebugOpt)
	printf("command: %s\n", ptr);

    if (strncasecmp(ptr, "authinfo pass ", 14)) {
        LogCmd(conn, '<', ptr);
    } else {
        LogCmd(conn, '<', "authinfo pass **unlogged**");
    }

    if (conn->co_Auth.dr_Flags & DF_USEPROXIED) {
      struct sockaddr_in sin;
      char *pt = NULL;

      if (strncasecmp(ptr, "proxied ", 8) || ! ((pt = strrchr(ptr, ':')))) {
          MBLogPrintf(conn,
              &conn->co_TMBuf,
              "400 %s: Proxy authentication failure.\r\n",
              conn->co_Auth.dr_VServerDef->vs_HostName
          );
          NNTerminate(conn);
      }

      *pt++ = '\0';
      ptr += 8;

      bzero((void *)&sin, sizeof(&sin));
      sin.sin_family = AF_INET;
      sin.sin_port = htons(atoi(pt));
      sin.sin_addr.s_addr = inet_addr(ptr);
      bcopy(&sin, &conn->co_Auth.dr_Addr, sizeof(conn->co_Auth.dr_Addr));

      conn->co_Auth.dr_Flags &= ~DF_USEPROXIED;
      conn->co_Auth.dr_ResultFlags = DR_REQUIRE_DNS;
      return;
    }

    /*
     * extract command (note: StatusUpdate() will limit the line length)
     */

    StatusUpdate(conn, "%s", ptr);

    if ((cmd = parseword(&ptr, " \t")) == NULL) {
	NNCommand(conn);
	return;
    }
    {
	int i;

	for (i = 0; cmd[i]; ++i)
	    cmd[i] = tolower((int)(unsigned char)cmd[i]);
    }

    /*
     * Locate and execute command
     */

    for (scan = &Cmds[0]; scan < &Cmds[arysize(Cmds)]; ++scan) {
	if (strcmp(cmd, scan->cmd_Name) == 0) {
	    if (conn->co_Flags & COF_SERVER) {
		if (scan->cmd_Flags & CMDF_SERVER) {
		    if ((conn->co_Auth.dr_Flags & DF_FEEDONLY) == 0)
			break;
		    if ((scan->cmd_Flags & CMDF_NOTFEEDONLY) == 0)
			break;
		}
	    } else {
		if (scan->cmd_Flags & CMDF_READER)
		    break;
	    }
	}
    }
    if (scan < &Cmds[arysize(Cmds)]) {
	if ((scan->cmd_Flags & CMDF_AUTH) &&
	    (conn->co_Auth.dr_Flags & DF_AUTHREQUIRED)
	) {
	    MBLogPrintf(conn, &conn->co_TMBuf, "480 Authentication required for command\r\n");
	    NNCommand(conn);
	} else {
	    conn->co_ByteCountType = scan->cmd_DRBC_Type;
	    scan->cmd_Func(conn, &ptr);
	}
    } else {
	NNUnknownCommand(conn);
    }
}