Annotation of 43BSDTahoe/new/xns/morexnslib/ch/CHdefault.c, revision 1.1.1.1

1.1       root        1: /* $Header: CHdefault.c,v 1.2 86/10/11 15:12:52 jqj Exp $ */
                      2: 
                      3: /* contains:
                      4:  * CH_NameDefault
                      5:  */
                      6: 
                      7: /* $Log:       CHdefault.c,v $
                      8:  * Revision 1.2  86/10/11  15:12:52  jqj
                      9:  * add support for DOMAIN and ORGANIZATION environment variables
                     10:  * 
                     11:  * Revision 1.1  86/10/11  15:04:48  jqj
                     12:  * Initial revision
                     13:  * 
                     14:  */
                     15: #include <stdio.h>
                     16: #include <sys/types.h>
                     17: #include <netns/ns.h>
                     18: #include <xnscourier/Clearinghouse2.h>
                     19: 
                     20: /*
                     21:  * path for the default names file
                     22:  */
                     23: #ifndef CHDEFPATH
                     24: #define CHDEFPATH "/usr/new/lib/xnscourier/CH.default"
                     25: #endif
                     26: 
                     27: /*
                     28:  * path to look for the addresses file on
                     29:  * (I wish I'd picked a shorter name, so we could rendezvous in /etc.
                     30:  *  But long file names in /etc are very unpopular!).
                     31:  */
                     32: char *chaddrpath[] = {
                     33: #ifdef CHADDRS
                     34:                        CHADDRS,
                     35: #endif
                     36:                        "/usr/new/lib/xnscourier/clearinghouse.addresses",
                     37:                        "/etc/CH.addrs",
                     38:                        "/usr/local/lib/xnscourier/clearinghouse.addresses",
                     39:                        0 };
                     40: 
                     41: 
                     42: /*
                     43:  * Set defaults for organization and domain, based on an environment
                     44:  * variable, on the file /usr/new/lib/xnscourier/CH.default, or on
                     45:  * /usr/new/lib/xnscourier/clearinghouse.addresses
                     46:  * (should get the local clearinghouse and set defaults based on
                     47:  * ListDomainsServed
                     48:  */
                     49: CH_NameDefault(defaultobjnamep)
                     50:        Clearinghouse2_ObjectName *defaultobjnamep;
                     51: {
                     52:        FILE *chfile;
                     53:        int i, nmatch;
                     54:        char buf[BUFSIZ], *bp;
                     55:        static char orgbuf[21], domainbuf[21];
                     56:        extern char *getenv();
                     57: 
                     58:        defaultobjnamep->object = "";
                     59:        if ((bp = getenv("CHDEFAULTS")) != NULL &&
                     60:            sscanf(bp,":%[^:]:%[^\n]", domainbuf, orgbuf) == 2) {
                     61:                defaultobjnamep->domain = domainbuf;
                     62:                defaultobjnamep->organization = orgbuf;
                     63:                return; /* done */
                     64:        }
                     65:        else if ((defaultobjnamep->domain = getenv("DOMAIN")) != NULL &&
                     66:                 (defaultobjnamep->organization = getenv("ORGANIZATION")) !=
                     67:                         NULL)
                     68:                return; /* done */
                     69:        if ((chfile = fopen(CHDEFPATH,"r")) !=
                     70:                        (FILE *) NULL) {
                     71:                while (fgets(buf, BUFSIZ, chfile) != NULL)
                     72:                    if (sscanf(buf,":%[^:]:%[^\n]", domainbuf, orgbuf) == 2) {
                     73:                        defaultobjnamep->domain = domainbuf;
                     74:                        defaultobjnamep->organization = orgbuf;
                     75:                        fclose(chfile);
                     76:                        return;
                     77:                }
                     78:                fclose(chfile);
                     79:        }
                     80:        /* oh well.  Use CHADDRS */
                     81:        for (i=0; chaddrpath[i] != NULL; i++) {
                     82:                chfile = fopen(chaddrpath[i],"r");
                     83:                if (chfile == (FILE*)0)
                     84:                        continue;
                     85:                while (fgets(buf, BUFSIZ, chfile) != NULL)
                     86:                        if ((buf[0] != '#') &&
                     87:                            (sscanf(buf,"%*[^ \t\n] \":%[^:]:%[^\"]",
                     88:                                        domainbuf, orgbuf) == 2)) {
                     89:                                fclose(chfile);
                     90:                                defaultobjnamep->domain = domainbuf;
                     91:                                defaultobjnamep->organization = orgbuf;
                     92:                                return; /* done */
                     93:                }
                     94:                fclose(chfile);
                     95:        }
                     96:        defaultobjnamep->organization = "";
                     97:        defaultobjnamep->domain = "";
                     98:        return;
                     99: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.