Re: External ACL Problem

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Sat, 6 Jul 2002 20:49:09 +0200

On Saturday 06 July 2002 17.39, Guido Serassio wrote:

> >Note: If you need code for dealing with such strings there is a
> >suitable strwordtok function in external_acl.c.. (not yet fully
> >complete, but good enought for the job).
> >
> >Regards
> >Henrik
>
> I have just looked it, but do You can explain how exactly works,
> I'm not sure that I have understand this correctly.

the strworktok function works sort of like strtok, except that it
understands the \ escape syntax (partially) and quoting and unwinds
it automatically, returning each string piece separately

Example C skeleton for a external_acl group helper using the mentioned
strwordtok function :

#include <stdio.h>
#include <syslog.h>
#include <string.h>

int main()
{
    char buf[1024];
    char *user, *group;
    setbuf(stdout, NULL);
    openlog("helpername", 0, LOG_AUTHPRIV);
    while(fgets(buf, sizeof(buf), stdin)) {
        /* Some error management to deal with oversized lines */
        if (!strchr(buf, '\n')) {
            while(fgets(buf, sizeof(buf), stdin))
                if (strchr(buf, '\n'))
                    break;
            syslog(LOG_NOTICE, "oversized request");
            printf("ERR\n");
            continue;
        }
     
        /* Split the input line in username and group */
        user = strwordtok(buf);
        group = strworktok(NULL);

        if (user_in_group(user, group))
            printf("OK\n");
        else
            printf("ERR\n");
    }
}

Regards
Henrik
Received on Sat Jul 06 2002 - 12:52:12 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:15:47 MST