dsaconfig.c
来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 1,351 行 · 第 1/2 页
C
1,351 行
while (fgets (buffer, sizeof buffer, fp)) { if (lexnequ (buffer, "dsa_address", sizeof "dsa_address" - 1) || (cp = index (buffer, '"')) == NULL || lexnequ (++cp, dsa + 3, i = strlen (dsa + 3)) || *(cp += i ) != '"') continue; for (cp++; isspace (*cp); cp++) continue; if (*cp == NULL) {malformed: ; adios (NULLCP, "malformed entry in dsaptailor for DSA %s", dsa); } for (dp = stuff; *cp; *dp++ = *cp++) { switch (*cp) { case '\n': break; case '\'': *dp++ = '\\'; /* and fall... */ case '\\': *dp++ = '\\'; continue; default: continue; } break; } *dp = NULL; if (*cp != '\n') goto malformed; *addr = strdup (stuff); goto hit; } adios (NULLCP, "unable to find presentationAddress for DSA %s", dsa);hit: ; (void) fclose (fp);}/* */generate_sed () { FILE *fp; register struct pair *p; (void) sprintf (sedfil, "/tmp/%sXXXXXX", myname); (void) unlink (mktemp (sedfil)); if ((fp = fopen (sedfil, "w")) == NULL) adios (sedfil, "unable to create"); for (p = pairs; p -> p_name; p++) if (!(p -> p_flags & P_MBOX) && p -> p_value) fprintf (fp, "s!@(%s)!%s!\n", p -> p_name, p -> p_value); if (ferror (fp)) adios (sedfil, "error writing"); (void) fclose (fp);}/* */static struct pair *n2p (name, any)char *name;int any;{ register struct pair *p; for (p = pairs; p -> p_name; p++) if (strcmp (p -> p_name, name) == 0) return (any || (p -> p_value && !(p -> p_flags & P_ZAP)) ? p : NULL); adios (NULLCP, "internal error -- unable to find \"%s\"", name); /* NOTREACHED */}/* */static munge (fp, entries)FILE *fp;char *entries[];{ register char c, *bp, *cp, *dp, **pp; char buffer[BUFSIZ]; register struct pair *p; for (pp = entries; cp = *pp; pp++) { bp = buffer; while (c = *cp++) { if (c != '@' || *cp != '(') { *bp++ = c; continue; } if ((dp = index (++cp, ')')) == NULL) adios (NULLCP, "internal error -- you lose big"); *dp = NULL; if ((p = n2p (cp, 0)) == NULL) { bp = buffer; goto no_match; } (void) strcpy (bp, p -> p_value); bp += strlen (bp); cp = ++dp; } *bp = NULL; fprintf (fp, "%s\n", buffer);no_match: ; }}/* EDB */static build_root () { if (debug) fprintf (stderr, "mkdir %s\n", wildlife); if (mkdir (wildlife, 0700) == NOTOK) adios (wildlife, "unable to create directory"); make_file ("root.edb", "EDB", 0600, 0);}/* */static char *c_TLC[] = { "o=@(organization)", "masterDSA= c=@(country)@cn=@(dsa)#", "acl= group # c=@(country)@o=@(organization)@cn=Manager # write # entry", "acl= others # read # entry", "acl= group # c=@(country)@o=@(organization)@cn=Manager # write # default", "acl= others # read # default", "acl= group # c=@(country)@o=@(organization)@cn=Manager # write # attributes # userPassword", "acl= others # compare # attributes # userPassword", "o= @(organization)", "streetAddress= @(street)", "postOfficeBox= @(pob)", "physicalDeliveryOfficeName= @(town)", "stateOrProvinceName= @(state)", "postalCode= @(zipcode)", "postalAddress= @(postaladdress)", "telephoneNumber= @(telephone)", "facsimileTelephoneNumber= @(fax)", "localityName= @(locality)", "description= @(description)", "associatedDomain= @(domain)", "objectClass= top & quipuObject & quipuNonLeafObject", "objectClass= domainRelatedObject", "objectClass= organization", "", "cn=@(dsa)", "acl= group # c=@(country)@o=@(organization)@cn=Manager # write # entry", "acl= others # read # entry", "acl= group # c=@(country)@o=@(organization)@cn=Manager # write # default", "acl= others # read # default", "cn= @(dsa)", "eDBinfo= # @(rootDSA) #", "eDBinfo= c=@(country) # @(countryDSA) #", "eDBinfo= c=@(country)@o=@(organization) # # @(countryDSA)", "eDBinfo= c=@(country)@o=@(organization) # # @(rootDSA)", "eDBinfo= c=@(country)@o=@(organization) # # @(otherDSA)", "presentationAddress= '0101'H/Internet=@(ipaddr)+@(port)", "manager= c=@(country)@o=@(organization)@cn=Manager#", "manager= c=@(country)@cn=Manager#", "userPassword= @(wildlife)", "quipuVersion= @(quipuversion)", "localityName= @(locality)", "description= The Endangered @(dsa)", "description= Master DSA for @(organization) in the @(country)", "objectClass= top & quipuObject", "objectClass= applicationEntity & dSA & quipuDSA", "supportedApplicationContext= x500DSP & x500DAP & quipuDSP", "info= @(firstname) @(lastname) (@(extension)) <@(mailbox)>", "", NULL};static build_TLC () { char buffer[BUFSIZ]; (void) sprintf (buffer, "%s/c=%s", wildlife, n2p ("country", 1) -> p_value); make_edb (buffer, "SLAVE", "0000000000Z", c_TLC);}/* */static char *o_I[] = { "cn=Manager", "acl=", "cn= Manager", "aliasedObjectName= c=@(country)@o=@(organization)@ou=@(unit)@cn=@(firstname) @(lastname)#", "objectClass= top & quipuObject", "objectClass= alias", "", "cn=Postmaster", "acl=", "cn= Postmaster", "aliasedObjectName= c=@(country)@o=@(organization)@ou=@(unit)@cn=@(firstname) @(lastname)#", "objectClass= top & quipuObject", "objectClass= alias", "", "ou=@(unit)", "masterDSA= c=@(country)@cn=@(dsa)#", "acl= others # read # entry", "acl= others # read # default", "acl= others # compare # attributes # userPassword", "ou= @(unit)", "objectClass= top & quipuObject & quipuNonLeafObject", "objectClass= organizationalUnit", "", NULL}; static build_organization () { char buffer[BUFSIZ]; (void) sprintf (buffer, "%s/c=%s/o=%s", wildlife, n2p ("country", 1) -> p_value, n2p ("organization", 1) -> p_value); make_edb (buffer, "MASTER", version (), o_I);}/* */static char *u_J[] = { "cn=@(firstname) @(lastname)", "acl= self # write # entry", "acl= others # read # entry", "acl= self # write # default", "acl= others # read # default", "acl= self # write # attributes # userPassword", "acl= others # compare # attributes # userPassword", "rfc822Mailbox= @(mailbox)", "otherMailbox = internet $ @(mailbox)", "title= @(title)", "userid= @(userid)", "userPassword= @(password)", "telephoneNumber= @(extension)", "surname= @(lastname)", "cn= @(firstname) @(lastname)", "cn= @(firstname) @(middleinitial). @(lastname)", "cn= @(firstname) @(middlename) @(lastname)", "objectClass= top & quipuObject", "objectClass= person & thornPerson & pilotPerson", "", NULL};static build_unit () { char buffer[BUFSIZ]; (void) sprintf (buffer, "%s/c=%s/o=%s/ou=%s", wildlife, n2p ("country", 1) -> p_value, n2p ("organization", 1) -> p_value, n2p ("unit", 1) -> p_value); make_edb (buffer, "MASTER", version (), u_J);}/* */static make_edb (dir, type, date, entries)char *dir, *type, *date;char *entries[];{ char edb[BUFSIZ]; FILE *fp; if (debug) fprintf (stderr, "mkdir %s\n", dir); if (mkdir (dir, 0700) == NOTOK) adios (dir, "unable to create directory"); (void) sprintf (edb, "%s/EDB", dir); if (debug) fprintf (stderr, "create %s\n", edb); if ((fp = fopen (edb, "w")) == NULL) adios (edb, "unable to create"); fprintf (fp, "%s\n%s\n", type, date); munge (fp, entries); if (ferror (fp)) adios (edb, "error writing"); (void) fclose (fp); (void) chmod (edb, 0600);}/* */static char *version () { long clock; struct UTCtime ut; static char buffer[BUFSIZ]; (void) time (&clock); tm2ut (gmtime (&clock), &ut); (void) strcpy (buffer, gent2str (&ut)); return buffer;}/* FILES */static build_tailor () { make_file ("quiputailor", "quiputailor", 0644, 1); }static build_startup () { make_file ("startup.sh", "startup.sh", 0755, 1); }static build_nightly () { make_file ("nightly.sh", "nightly.sh", 0755, 1); }/* */static make_file (infile, outfile, mode, dosed)char *infile, *outfile;int mode, dosed;{ char buffer[BUFSIZ]; if (dosed)/* (void) sprintf (buffer, "sed -f %s < templates/%s > %s/%s", sedfil, infile, wildlife, outfile);*/ (void) sprintf (buffer, "sed -f %s < templates/%s > /tmp/%s", sedfil, infile, outfile); else (void) sprintf (buffer, "cp templates/%s %s/%s", infile, wildlife, outfile); if (debug) fprintf (stderr, "%s\n", buffer); if (system (buffer) != 0) adios (NULLCP, "%s of %s failed", dosed ? "sed" : "cp", infile); (void) sprintf (buffer, "%s/%s", wildlife, outfile); (void) chmod (buffer, mode);}/* SED */static build_dsap () { fudge_file ("dsaptailor"); }static build_fred () { fudge_file ("fredrc"); fudge_file ("ufnrc"); }/* */static fudge_file (name)char *name;{ char buffer[BUFSIZ], file[BUFSIZ], oldfil[BUFSIZ], tmpfil[BUFSIZ]; (void) strcpy (file, isodefile (name, 0)); (void) sprintf (buffer, "%sXXXXXX", myname); (void) strcpy (tmpfil, isodefile (buffer, 0)); (void) unlink (mktemp (tmpfil)); (void) sprintf (buffer, "sed -f %s < %s > %s", sedfil, file, tmpfil); if (debug) fprintf (stderr, "%s\n", buffer); if (system (buffer) != 0) { (void) unlink (tmpfil); adios (NULLCP, "sed failed"); } (void) sprintf (oldfil, "%s.old", file); if (access (oldfil, 0x00) == NOTOK) (void) rename (file, oldfil); if (rename (tmpfil, file) == NOTOK) adios (file, "unable to rename %s to", tmpfil);}/* ARGINIT */static arginit (vec)char **vec;{ register char *ap; if (myname = rindex (*vec, '/')) myname++; if (myname == NULL || *myname == NULL) myname = *vec; isodetailor (myname, 1); for (vec++; ap = *vec; vec++) { if (*ap == '-') { while (*++ap) switch (*ap) { case 'd': debug++; break; case 'c': parse_3166 (); exit (0); case 't': table_3166 (); exit (0); default: adios (NULLCP, "unknown switch -%c", *ap); } continue; } if (wildlife) {usage: ; adios (NULLCP, "usage: %s config-file", myname); } wildlife = ap; } if (!wildlife) goto usage;}/* */static parse_3166 (){ int bitno; unsigned int bits_size; register char *cp, *dp; char d, *ep, buffer[BUFSIZ + 1], file[BUFSIZ], *vec[NVEC + NSLACK + 1]; unsigned char *bits_3166; FILE *fp; (void) strcpy (file, isodefile ("quipu/iso3166", 0)); if ((fp = fopen (file, "r")) == NULL) adios (file, "unable to open"); bits_size = ((26 * 26) >> 3) + 1; if ((bits_3166 = (unsigned char *) calloc (bits_size, sizeof *bits_3166)) == NULL) adios (NULLCP, "out of memory"); ep = (dp = buffer) + sizeof buffer; while (fgets (dp, ep - dp, fp)) { if (*buffer == '#') continue; if (cp = index (buffer, '\n')) { *cp = NULL; if ((d = getc (fp)) != EOF) (void) ungetc (d, fp); switch (d) { case '#': case '\n': case EOF: break; default: *cp++ = ' '; if ((dp = cp) + 1 >= ep) { *ep = NULL; adios (NULLCP, "virtual line too long in %s: \"%s\"", file, cp); } continue; } } dp = buffer; switch (str2vec (buffer, vec)) { case 3: /* basic entry */ case 7: /* standard entry */ case 8: cp = vec[0]; bitno = (((*cp - 'A') & 0xff) * 26) + ((cp[1] - 'A') & 0xff); bits_3166[bitno >> 3] |= 1 << (bitno % 8); break; default: break; } continue; } { register unsigned char *bp; unsigned char *xp; printf ("static unsigned char bits_3166[%u] = {\n", bits_size); for (xp = (bp = bits_3166) + bits_size; bp < xp; bp++) printf (" 0x%02x,\n", *bp & 0xff); printf ("};\n"); } (void) fclose (fp);}/* */static table_3166 (){ register char *cp, *dp; char d, *ep, buffer[BUFSIZ + 1], file[BUFSIZ], *vec[NVEC + NSLACK + 1]; FILE *fp; (void) strcpy (file, isodefile ("quipu/iso3166", 0)); if ((fp = fopen (file, "r")) == NULL) adios (file, "unable to open"); ep = (dp = buffer) + sizeof buffer; while (fgets (dp, ep - dp, fp)) { if (*buffer == '#') continue; if (cp = index (buffer, '\n')) { *cp = NULL; if ((d = getc (fp)) != EOF) (void) ungetc (d, fp); switch (d) { case '#': case '\n': case EOF: break; default: *cp++ = ' '; if ((dp = cp) + 1 >= ep) { *ep = NULL; adios (NULLCP, "virtual line too long in %s: \"%s\"", file, cp); } continue; } } dp = buffer; switch (str2vec (buffer, vec)) { case 3: /* basic entry */ case 7: /* standard entry */ case 8: printf ("%s&\t%s&\t%s\\\\\n", vec[0], vec[1], vec[2]); break; default: break; } continue; } (void) fclose (fp);}/* ERRORS */#ifndef lintvoid _advise ();static void adios (va_alist)va_dcl{ va_list ap; va_start (ap); _advise (ap); va_end (ap); _exit (1);}#else/* VARARGS */static void adios (what, fmt)char *what, *fmt;{ adios (what, fmt);}#endif#ifndef lintstatic void advise (va_alist)va_dcl{ va_list ap; va_start (ap); _advise (ap); va_end (ap);}static void _advise (ap)va_list ap;{ char buffer[BUFSIZ]; asprintf (buffer, ap); (void) fflush (stdout); fprintf (stderr, "%s: ", myname); (void) fputs (buffer, stderr); (void) fputc ('\n', stderr); (void) fflush (stderr);}#else/* VARARGS */static void advise (what, fmt)char *what, *fmt;{ advise (what, fmt);}#endif/* MISCELLANY */#ifndef lintstatic char *strdup (s)char *s;{ char *p; if ((p = malloc((unsigned) (strlen (s) + 1))) == NULL) adios (NULLCP, "out of memory"); (void) strcpy (p, s); return p;}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?