📄 usconfig.c
字号:
if ((pp = findpair (toks[0], 0x01)) == (struct pair *)NULL) advise (NULLCP, "unknown variable %s, line %d", toks[0], lncnt); else advise (NULLCP, "no value specified for variable %s, line %d", toks[0], lncnt); continue; case 2: break; default: advise (NULLCP, "syntax error: multiple values specified, line %d", lncnt); continue; } /* end, tokenize line *//* get variable */ if ((pp = findpair (toks[0], 0x01)) == (struct pair *)NULL) { advise (NULLCP, "unknown variable %s, line %d", toks[0], lncnt); continue; /* process another line */ } if (pp->p_val != (char *)NULL) { /* multiple values? */ advise (NULLCP, "duplicate value for variable %s found, line %d", pp->p_nm, lncnt); continue; /* process another line */ }/* make sure character set used for value is legal */ if ((pp->p_flags & P_MBOX) == P_MBOX) { for (i = 0; toks[1][i] != '\0'; ++i) if (!isascii (toks[1][i]) || toks[1][i] == '$' || toks[1][i] == '&') { advise (NULLCP, "illegal character %c (0%o) in mailbox value, line %d", toks[1][i], (toks[1][i] & 0xff), lncnt); break; } if (toks[1][i] != '\0') continue; /* process another line */ } /* end, mailbox */ else { /* not mailbox */ for (i = 0; toks[1][i] != '\0'; ++i) { if (isalpha (toks[1][i]) || isdigit (toks[1][i])) continue; /* onto next character */ switch (toks[1][i]) { /* identify character */ case 047: /* ' */ case '(': case ')': case '+': case ',': case '-': case '.': case '/': case ':': case '?': case ' ': continue; default: /* not a legal character */ if ((pp->p_flags & P_POST) == P_POST && toks[1][i] == '$') continue; /* '$' legal in postal addr. */ advise (NULLCP, "illegal character %c (0%o), line %d", toks[1][i], (toks[1][i] & 0xff), lncnt); goto out; } } /* end, foreach character */out:; if (toks[1][i] != '\0') continue; /* process next line */ } /* end, not mailbox */ pp->p_val = strdup (toks[1]); } /* end, foreach line *//* done parsing configuration file. Now do error checks and fill in things*//* make sure all mandatory values have been specified */ for (i = 0; pairs[i].p_nm != (char *)NULL; ++i) if (pairs[i].p_val == (char *)NULL && (pairs[i].p_flags & P_OPT) != P_OPT) adios (NULLCP, "value not specified for variable %s",pairs[i].p_nm);/* initialize country value */ if ((pp = findpair ("country", 0x01)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'country' variable"); if (pp->p_val == (char *)NULL) pp->p_val = strdup ("US"); else if (strlen (pp->p_val) != 2 || strcmp (pp->p_val, "US") != 0) adios (NULLCP, "This program can only be used for configuration in the US DMD!");/* check for legality of state value */ if ((pp = findpair ("state", 0x00)) == (struct pair *)NULL) adios (NULLCP, "mandatory 'state' variable not specified"); nmlen = strlen(pp->p_val); for (i = 0; usstates[i].s_nm != (char *)NULL; ++i) if (nmlen == strlen(usstates[i].s_nm) && strcmp (pp->p_val,usstates[i].s_nm) == 0) break; sp = (struct state *)NULL; if (usstates[i].s_nm == (char *)NULL) adios (NULLCP, "%s not a legal U.S. state or state equivalent", pp->p_val); else sp = (usstates + i); /* save for later use *//* initialize address, port, on which DSA listens if necessary */ if ((pp = findpair ("ipaddr",0x01)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot find 'ipaddr' pair"); if (pp->p_val == (char *)NULL) { /* ip address not specified? */ if ((hp = gethostbyname (cp = getlocalhost())) == (struct hostent *)NULL) adios (NULLCP, "%s: unknown host", cp); bzero ((char *)&sin, sizeof (struct sockaddr_in)); inaddr_copy (hp, &sin); pp->p_val = strdup (inet_ntoa (sin.sin_addr)); } /* end, ip address not specified */ else { /* ip address specified */ if ((hp = gethostbystring (pp->p_val)) == (struct hostent *)NULL) adios (NULLCP, "%s: illegal ip address", pp->p_val); } /* end, ip address specified */ if ((pp = findpair ("port", 0x01)) != (struct pair *)NULL && pp->p_val == (char *)NULL) { pp->p_val = strdup ("17003"); }/* initialize middle initial based on middle name, if necessary */ if ((pp = findpair ("middlename", 0x00)) != (struct pair *)NULL && (pp2 = findpair ("middleinitial", 0x01)) != (struct pair *)NULL && pp2->p_val == (char *)NULL) { buf[0] = pp->p_val[0]; buf[1] = '\0'; pp2->p_val = strdup (buf); }/* initialize personal phone, if possible */ if ((pp = findpair ("persphone", 0x01)) != (struct pair *)NULL && pp->p_val == (char *)NULL) if ((pp2 = findpair ("telephone", 0x00)) != (struct pair *)NULL) if ((pp3 = findpair ("extension", 0x00)) != (struct pair *)NULL) { sprintf(buf,"%s x%s",pp2->p_val,pp3->p_val); pp->p_val = strdup (buf); } else { sprintf (buf, "%s", pp2->p_val); pp->p_val = strdup (buf); }/* initialize postal address, if necessary */ if ((pp = findpair ("postaladdress", 0x01)) != (struct pair *)NULL && pp->p_val == (char *)NULL) { cp = buf; /* start at the beginning ... */ bzero (buf, BUFSIZ); /* clear buffer *//* put in organization */ if ((pp2 = findpair ("organization", 0x00)) == (struct pair *)NULL) adios (NULLCP, "'organization' not specified"); else if (strlen(pp2->p_val) > 30) { bad_postaladdress (pp2->p_val, 0x00); } sprintf(cp, "%s ", pp2->p_val); cp += (strlen (pp2->p_val) + 1);/* put in po box or street address */ if ((pp2 = findpair ("pob", 0x00)) == (struct pair *)NULL) if ((pp2 = findpair ("street", 0x00)) == (struct pair *)NULL) adios (NULLCP, "must specify one of 'postaladdress', 'street' or 'pob'"); else { /* street address exists */ if (strlen(pp2->p_val) > 30) bad_postaladdress (pp2->p_val, 0x00); sprintf(cp, "$ %s ", pp2->p_val); cp += (strlen (pp2->p_val) + 3); } /* end, street address exists */ else { /* P.O. Box exists */ if (strlen(pp2->p_val) + 4 > 30) bad_postaladdress (pp2->p_val, 0x00); sprintf(cp, "$ POB %s ", pp2->p_val); cp += (strlen (pp2->p_val) + 7); } /* end, P.O. Box exists *//* put in the town */ if ((pp2 = findpair ("town", 0x00)) == (struct pair *)NULL) adios (NULLCP, "'town' not specified"); else if (strlen(pp2->p_val) > 30) bad_postaladdress (pp2->p_val, 0x00); sprintf (cp, "$ %s ", pp2->p_val); cp += (strlen (pp2->p_val) + 3);/* put in state */ if (sp == (struct state *)NULL) /* no state? */ adios (NULLCP, "'state' not specified"); sprintf (cp, "$ %s ",sp->s_abb); cp += (strlen (sp->s_abb) + 3);/* put in zip code */ if ((pp2 = findpair ("zipcode", 0x00)) == (struct pair *)NULL) adios (NULLCP, "'zipcode' not specified"); sprintf (cp, "%s ", pp2->p_val); cp += (strlen (pp2->p_val) + 1);/* put in 'US' for country */ sprintf (cp, "$ US");/* now put value in */ pp->p_val = strdup (buf); } /* end, initialize postal address */ else { /* don't initialize postal address */ if (pp == (struct pair *)NULL) /* no 'postaladdress' pair? */ adios (NULLCP, "internal error: 'postaladdress' variable not found");/* check to make sure postal address is legal ... */ cp2 = pp->p_val; /* point at postal address */ for (cp2 = pp->p_val, i = 1; cp = strchr (cp2, (int)'$'); cp2 = cp + 1, ++i) { *cp = '\0'; /* null terminate */ if (strlen (cp2) > 30) bad_postaladdress (cp2, 0x01); *cp = '$'; } if (strlen (cp2) > 30) bad_postaladdress (cp2, 0x01); if (i > 6) adios (NULLCP, "too many items (%d) in postaladdress, 6 maximum", i); } /* end, don't init postal addr*//* done. cleanup */ fclose (cfgfp); /* close configuration file */}/* *//* bad_postaladdress () -- print error message for a bad postal address */voidbad_postaladdress (line, postdef)char *line; /* offending line */unsigned char postdef; /* postal address defined? */{ advise (NULLCP,"line:\n\t%s\nis illegal in a postal address", line); if (!postdef) advise (NULLCP, "You must explicitly define the 'postaladdress' attribute\n\ in the configuration file for your DSA.\n\n"); adios (NULLCP, "The format of the 'postaladdress' attribute is:\n\n\ postaladdress \"item1 $ item2 $ ... $ item\"\n\n\ where each item is <= 30 characters in length and there are no\n\ more than six items. Please refer to the Administrator's Guide.\n");}/* *//* build_top () -- build root, c=US */voidbuild_top (){ struct pair *pp; int i; extern void copy_edb (); extern struct pair *findpair();/* setup base directory */ if ((pp = findpair ("wildlife", 0x00)) == (struct pair *)NULL) adios (NULLCP, "cannot find name of wildlife for base directory"); if (isodetcpath == (char *)NULL) adios (NULLCP, "cannot determine ISODE ETCPATH"); sprintf (buf, "%s/quipu/%s", isodetcpath, pp->p_val); if (mkdir (buf, DIRPERM) < 0 && errno != EEXIST) adios (NULLCP, "cannot create wildlife directory %s",buf); chdir (buf);/* iterate through, creating top-level EDB files from templates. */ copy_edb (topdirs[0].dir, topdirs[0].edb, 0x00); /* root, special case */ for (i = 1; topdirs[i].dir != (char *)NULL; ++i) { if (mkdir (topdirs[i].dir, DIRPERM) < 0 && errno != EEXIST) adios (NULLCP, "cannot create directory %s", topdirs[i].dir); copy_edb (topdirs[i].dir, topdirs[i].edb, 0x00); } /* end, foreach directory */}/* *//* add_us () -- add national organization to US EDB */voidadd_us (orgcode)struct pair *orgcode; /* ansi organization code */{ extern void copy_edb (); bzero (buf, BUFSIZ); unlink (ORGENTRY); if (orgcode != (struct pair *)NULL && orgcode->p_val != (char *)NULL) sprintf (buf, "sed -f %s %s > %s\n\n", SEDFILE, ANSI_ORGTMPL, ORGENTRY); else sprintf (buf, "sed -f %s %s > %s\n\n", SEDFILE, ORGTMPL, ORGENTRY); if (system (buf) != 0) adios (NULLCP, "system failed: cannot create %s", ORGENTRY); copy_edb (USDN, ORGENTRY, 0x01);}/* *//* add_state () -- build state entry, adding organization if necessary*/voidadd_state (addorg)unsigned char addorg; /* add organization to state entry? */{ struct pair *state; /* name of state */ extern void copy_edb (); extern struct pair *findpair (); FILE *statefp;/* get name of state */ if ((state = findpair ("state", 0x00)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'state' variable");/* create directory for state */ bzero (buf, BUFSIZ); sprintf (buf, "%s/st=%s", USDN, state->p_val); if (mkdir (buf, DIRPERM) < 0 && errno != EEXIST) adios (NULLCP, "cannot create directory %s",buf);/* make sure EDB file doesn't already exist */ sprintf (file, "%s/st=%s/EDB", USDN, state->p_val); if (access (file, F_OK) == 0) { sprintf (oldfile, "%s.bak", file); if (rename (file, oldfile) < 0) adios (NULLCP, "cannot rename %s to %s", file, oldfile); }/* create skeleton state EDB */ if ((statefp = fopen (file, "w")) == (FILE *)NULL) adios (NULLCP, "cannot create %s",file); fprintf (statefp, "SLAVE\n000000000000Z\n"); fclose (statefp); if (addorg) { /* need to add organization? */ unlink (ORGENTRY); /* remove temporary org. entry *//* create organizational entry */ bzero (buf, BUFSIZ); sprintf (buf, "sed -f %s %s > %s", SEDFILE, ORGTMPL, ORGENTRY); if (system (buf) != 0) adios (NULLCP, "system failed: cannot create %s", ORGENTRY); sprintf (buf, "%s/st=%s", USDN, state->p_val); copy_edb (buf, ORGENTRY, 0x01); }}/* */voidbuild_dsa (){ unlink (DSAENTRY); bzero (buf, BUFSIZ); sprintf (buf, "sed -f %s %s > %s", SEDFILE, DSATMPL, DSAENTRY); if (system (buf) != 0) adios (NULLCP, "system failed: cannot create %s", DSAENTRY); copy_edb (USDN, DSAENTRY, 0x01);}/* *//* build_orgedb () -- build skeleton EDB for organization */voidbuild_orgedb (){ struct pair *pp; /* to get pair values */ char *orgnm; /* name of organization */ extern struct pair *findpair ();/* get name of organization */ bzero (file, BUFSIZ); if ((pp = findpair ("organization", 0x00)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'organization' variable"); orgnm = pp->p_val;/* set up location of organization */ bzero (file, BUFSIZ); if ((pp = findpair ("orgcode", 0x00)) != (struct pair *)NULL || chartered_by_congress) sprintf (file,"%s/o=%s", USDN,orgnm); else { /* org. has regional standing */ if ((pp = findpair ("state", 0x00)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'state' variable"); sprintf (file, "%s/st=%s/o=%s", USDN, pp->p_val, orgnm); } if (mkdir (file, DIRPERM) < 0 && errno != EEXIST) adios (NULLCP, "internal error: cannot create %s",file);/* make sure EDB file doesn't already exist */ strcat (file, "/EDB"); if (access (file, F_OK) == 0) { sprintf (oldfile, "%s.bak", file); if (rename (file, oldfile) < 0) adios (NULLCP, "cannot rename %s to %s", file, oldfile); }/* now create skeleton organizational entries */ sprintf (buf, "sed -f %s %s > \"%s\"", SEDFILE, ORGEDBTMPL, file); if (system (buf) != 0) adios (NULLCP, "system failed: cannot create %s", file);}/* build_ouedb () -- build skeleton EDB for organizational unit */voidbuild_ouedb (){ struct pair *pp; /* to get pair values */ char *orgnm; /* name of organization */ char *ounm; /* name of organizational unit */ extern struct pair *findpair ();/* get name of organization and organizational unit */ bzero (file, BUFSIZ); if ((pp = findpair ("organization", 0x00)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'organization' variable"); orgnm = pp->p_val; if ((pp = findpair ("unit", 0x00)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'unit' variable"); ounm = pp->p_val;/* set up location of organization */ bzero (file, BUFSIZ); if ((pp = findpair ("orgcode", 0x00)) != (struct pair *)NULL || chartered_by_congress) sprintf (file,"%s/o=%s/ou=%s", USDN, orgnm, ounm); else { /* org. has regional standing */ if ((pp = findpair ("state", 0x00)) == (struct pair *)NULL) adios (NULLCP, "internal error: cannot get 'state' variable"); sprintf (file, "%s/st=%s/o=%s/ou=%s", USDN, pp->p_val, orgnm, ounm);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -