[Exim] netinfo support

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Giuliano Gavazzi
Datum:  
To: exim-users
Betreff: [Exim] netinfo support
Hello,

has anybody worked on netinfo support (Darwin/MacOSX) for lookup queries?

I have had a look at lookup/nis.c for inspiration and it looks like the equivalent of:

     ${lookup nisplus {[name=$local_part],passwd.org_dir:passwd} \
       {$value}fail}


could be:

     ${lookup netinfo {domain,path,key,index} \
       {$value}fail}


with
domain = localhost/local (for simplicity only tagged domains)
path = /users/$local_part
key = passwd
index = 0
(we could have also passed an options string to specify timeout/retry/tagged-non-tagged/etc)

A prototype function to do a netinfo query is do_readval from the niutil sources (Apple).

The equivalent for void * nis_open(uschar *filename, uschar **errmsg)
could be:

void *netinfo_open (uschar *domainname, uschar **errmsg)
{
    char *myname = "netinfo_open";
    void *domain;
    if (do_open(myname, domainname, &domain, TRUE, // this is a tagged domain
        30,//the timeout in sec.
        NULL, NULL) != 0)
    {    *errmsg = string_sprintf("failed to get netinfo %s domain",domain);
    }
    else
        return domain;
}


and for nis_find(void *handle, uschar *filename, uschar *keystring, int length,
uschar **result, uschar **errmsg)

I would say:

(but how do I pass the index, see above? For the moment I am setting it to 0)

int netinfo_find(void *domain, uschar *path, uschar *key, int length,
  uschar **result, uschar **errmsg)
{    //ignored: length
        /* argv[1] should be a directory specification */
    char *myname = "netinfo_find";
        ni_id dir;
        ni_status ret;
        ni_namelist nl;


        ret = ni2_pathsearch(domain, &dir, path);
        if (ret != NI_OK) {
                *errmsg = string_sprintf("%s: can't open directory %s: %s",
                        myname, path, ni_error(ret));
                ni_free(domain);
        return (ret == NI_NODIR || ret == NI_BADID || ret == NI_NONAME)? FAIL : DEFER;
        }


        /* get the property values for key] */
        NI_INIT(&nl);
        ret = ni_lookupprop(domain, &dir, key, &nl);
        if (ret != NI_OK) {
                fprintf(stderr, "%s: can't get property %s in directory %s: %s",
                        myname, key, path, ni_error(ret));
                ni_free(domain);
        return (ret == NI_NOPROP)? FAIL : DEFER;
        }


        // vn = atoi(index); // HOW DO I PASS THE index?
    vn = 0; //DEFAULT
        if (vn >= nl.ni_namelist_len) {
                                *errmsg = string_sprintf("%s: property %s in directory %s has no value at index %d",
                        myname, key, path, vn);
                ni_free(domain);
                return FAIL;
        }


        *result = string_sprintf ("%s", nl.ni_namelist_val[vn]);


        ni_namelist_free(&nl);
        ni_free(domain);





}


Please note that this code uses private headers from the NetInfo private framework. The real implementation should look at the code in nilib2.c in the NetInfo project for the ni2_pathsearch and do_open functions. Also, I am not so sure about the error codes (NI_NODIR, etc.).

Comments?

Giuliano
--
H U M P H
|| |||
software

Java & C++ Server/Client/Human Interface applications on MacOS - MacOS X
http://www.humph.com/