예제 #1
0
파일: queue.c 프로젝트: yumm007/C
int queue_de(int *data)
{
      if (__isempty()) {
	    return -1;
      }

      *data = queue[de_ind++];
      if (de_ind == QUEUE_NUM) {
	    de_ind = 0;
      }
      return 0;
}
예제 #2
0
/*
 * Returns 0 if positive match, -1 if _not_ ok.
 */
static int
__ivaliduser2(FILE *hostf, u_int32_t raddr,	const char *luser,
              const char *ruser, const char *rhost)
{
    register const char *user;
    register char *p;
    int hcheck, ucheck;
    char *buf = NULL;
    size_t bufsize = 0;
    int retval = -1;

    while (getline (&buf, &bufsize, hostf) > 0) {
        buf[bufsize - 1] = '\0'; /* Make sure it's terminated.  */
        p = buf;

        /* Skip empty or comment lines */
        if (__isempty (p)) {
            continue;
        }

        /* Skip lines that are too long. */
        if (strchr (p, '\n') == NULL) {
            int ch = getc_unlocked (hostf);

            while (ch != '\n' && ch != EOF)
                ch = getc_unlocked (hostf);
            continue;
        }

        for (; *p && !isspace(*p); ++p) {
            *p = tolower (*p);
        }

        /* Next we want to find the permitted name for the remote user.  */
        if (*p == ' ' || *p == '\t') {
            /* <nul> terminate hostname and skip spaces */
            for (*p++='\0'; *p && isspace (*p); ++p);

            user = p;                   /* this is the user's name */
            while (*p && !isspace (*p))
                ++p;                    /* find end of user's name */
        } else
            user = p;

        *p = '\0';              /* <nul> terminate username (+host?) */

        /* buf -> host(?) ; user -> username(?) */

        /* First check host part */
        hcheck = __icheckhost (raddr, buf, rhost);

        if (hcheck < 0)
            break;

        if (hcheck) {
            /* Then check user part */
            if (! (*user))
                user = luser;

            ucheck = __icheckuser (user, ruser);

            /* Positive 'host user' match? */
            if (ucheck > 0) {
                retval = 0;
                break;
            }

            /* Negative 'host -user' match? */
            if (ucheck < 0)
                break;

            /* Neither, go on looking for match */
        }
    }

    free (buf);

    return retval;
}
예제 #3
0
static int
__ivaliduser (pam_handle_t *pamh, struct _options *opts,
	      FILE *hostf, U32 raddr,
	      const char *luser, const char *ruser, const char *rhost)
{
    register const char *user;
    register char *p;
    int hcheck, ucheck;
    char buf[MAXHOSTNAMELEN + 128];                       /* host + login */

    buf[sizeof (buf)-1] = '\0';                 	/* terminate line */

    while (fgets(buf, sizeof(buf), hostf) != NULL) {   /* hostf file line */
        p = buf;                              /* from beginning of file.. */

	/* Skip empty or comment lines */
	if (__isempty(p)) {
	    continue;
	}

	/* Skip lines that are too long. */
	if (strchr(p, '\n') == NULL) {
	    int ch = getc(hostf);

	    while (ch != '\n' && ch != EOF)
		ch = getc(hostf);
	    continue;
	}

	/*
	 * If there is a hostname at the start of the line.  Set it to
	 * lower case. A leading ' ' or '\t' indicates no hostname
	 */

	for (;*p && !isspace(*p); ++p) {
	    *p = tolower(*p);
	}

	/*
	 * next we want to find the permitted name for the remote user
	 */

	if (*p == ' ' || *p == '\t') {

	    /* <nul> terminate hostname and skip spaces */
	    for (*p++='\0'; *p && isspace(*p); ++p);

	    user = p;                   /* this is the user's name */
	    while (*p && !isspace(*p))
		++p;                    /* find end of user's name */
	} else 
	    user = p;

	*p = '\0';              /* <nul> terminate username (+host?) */

	/* buf -> host(?) ; user -> username(?) */

	/* First check host part */
	hcheck=__icheckhost(pamh, opts, raddr, buf, rhost);

	if (hcheck<0)
	    return(1);

	if (hcheck) {
	    /* Then check user part */
	    if (! (*user))
		user = luser;

	    ucheck=__icheckuser(pamh, opts, user, ruser, rhost);

	    /* Positive 'host user' match? */
	    if (ucheck>0)
		return(0);

	    /* Negative 'host -user' match? */
	    if (ucheck<0)
		return(1);

	    /* Neither, go on looking for match */
	}
    }

    return (1);
}