⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usconfig.c

📁 ftam等标准协议服务器和客户端的源代码。
💻 C
📖 第 1 页 / 共 3 页
字号:
/* usconfig.c -- build database directory */#ifndef lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/quipu/tools/dsaconfig/RCS/usconfig.c,v 9.0 1992/06/16 12:43:56 isode Rel $";#endif /* lint *//* * $Header: /xtel/isode/isode/others/quipu/tools/dsaconfig/RCS/usconfig.c,v 9.0 1992/06/16 12:43:56 isode Rel $ * * $Log: usconfig.c,v $ * Revision 9.0  1992/06/16  12:43:56  isode * Release 8.0 * *//* *				NOTICE * *   Acquisition, use, and distribution of this module and related *   materials are subject to the restrictions of a license agreement. *   Consult the Preface in the User's Manual for the full terms of *   this agreement. * */#include <stdio.h>#include <ctype.h>#include <sys/types.h>#include <errno.h>#include <varargs.h>#include <string.h>#include <sys/file.h>#include <pwd.h>#include <grp.h>#include "general.h"#include "manifest.h"#include "internet.h"#include "psap.h"#include "tailor.h"/* ^L *//* DATA */char *prgnm;unsigned char chartered_by_congress;	/* standing derived from congress? *//* buffers that are used so extensively that they are worth making global */char buf[BUFSIZ];			/* general purpose buffer */char line[BUFSIZ];			/* configuration line */char file[BUFSIZ];			/* a file name */char oldfile[BUFSIZ];			/* file name (as above) with suffix */extern void adios (), advise ();extern int errno;extern char *isodetcpath;extern char *isodebinpath;extern char *isodesbinpath;extern char *quipuversion;struct pair {				/* name/value pair */    char *    p_nm;			/* name of pair */    char *    p_val;			/* value of pair */    unsigned char    p_flags;		/* flags */#define P_NONE	(unsigned char)0x00	/* no flags */#define P_OPT	(unsigned char)0x80	/* optional */#define P_MBOX	(unsigned char)0x40	/* a mailbox */#define P_POST	(unsigned char)0x20	/* a postal address */};static struct pair pairs[] = {	{ "country",		(char *)NULL,	P_OPT },	{ "wildlife",		(char *)NULL,	P_NONE },	{ "owner",		(char *)NULL,	P_OPT },	{ "groupid",		(char *)NULL,	P_OPT },	{ "state",		(char *)NULL,	P_NONE },	{ "dsa",		(char *)NULL,	P_NONE },	{ "ipaddr",		(char *)NULL,	P_OPT },	{ "port",		(char *)NULL,	P_OPT },	{ "organization",	(char *)NULL,	P_NONE },	{ "unit",		(char *)NULL,	P_NONE },	{ "domain",		(char *)NULL,	P_NONE },	{ "street",		(char *)NULL,	P_OPT },	{ "town",		(char *)NULL,	P_NONE },	{ "zipcode",		(char *)NULL,	P_NONE },	{ "telephone",		(char *)NULL,	P_OPT },	{ "pob",		(char *)NULL,	P_OPT },	{ "fax",		(char *)NULL,	P_OPT },	{ "description",	(char *)NULL,	P_OPT },	{ "orgcode",		(char *)NULL,	P_OPT },	{ "firstname",		(char *)NULL,	P_NONE },	{ "lastname",		(char *)NULL,	P_NONE },	{ "middlename",		(char *)NULL,	P_OPT },	{ "middleinitial",	(char *)NULL,	P_OPT },	{ "mailbox",		(char *)NULL,	P_MBOX },	{ "title",		(char *)NULL,	P_OPT },	{ "password",		(char *)NULL,	P_NONE },	{ "persphone",		(char *)NULL,	P_OPT },	{ "extension",		(char *)NULL,	P_OPT },	{ "userid",		(char *)NULL,	P_NONE },	{ "postaladdress",	(char *)NULL,	(P_OPT | P_POST) },/* DO NOT DELETE THIS -- THIS TERMINATES THE ARRAY */	{ (char *)NULL,		(char *)NULL,	P_NONE }};struct state {    char *    s_nm;			/* full name of state */    char *    s_abb;			/* 2 letter abbreviation */    short     s_fips;			/* FIPS numeric code */    short     s_region;			/* region */};struct state usstates[] = {	{ "Alabama",				"AL",		 1,	0 },	{ "Alaska",				"AK",		 2,	1 },	{ "Arizona",				"AZ",		 4,	2 },	{ "Arkansas",				"AR",		 5,	2 },	{ "California",				"CA",		 6,	1 },	{ "Colorado",				"CO",		 8,	2 },	{ "Connecticut",			"CT",		 9,	0 },	{ "Delaware",				"DE",		10,	0 },	{ "District of Columbia",		"DC",		11,	0 },	{ "Florida",				"FL",		12,	0 },	{ "Georgia",				"GA",		13,	0 },	{ "Hawaii",				"HI",		15,	1 },	{ "Idaho",				"ID",		16,	2 },	{ "Illinois",				"IL",		17,	2 },	{ "Indiana",				"IN",		18,	2 },	{ "Iowa",				"IA",		19,	2 },	{ "Kansas",				"KS",		20,	2 },	{ "Kentucky",				"KY",		21,	0 },	{ "Louisiana",				"LA",		22,	2 },	{ "Maine",				"ME",		23,	0 },	{ "Maryland",				"MD",		24,	0 },	{ "Massachusetts",			"MA",		25,	0 },	{ "Michigan",				"MI",		26,	2 },	{ "Minnesota",				"MN",		27,	2 },	{ "Mississippi",			"MS",		28,	2 },	{ "Missouri",				"MO",		29,	2 },	{ "Montana",				"MT",		30,	2 },	{ "Nebraska",				"NE",		31,	2 },	{ "Nevada",				"NV",		32,	1 },	{ "New Hampshire",			"NH",		33,	0 },	{ "New Jersey",				"NJ",		34,	0 },	{ "New Mexico",				"NM",		35,	2 },	{ "New York",				"NY",		36,	0 },	{ "North Carolina",			"NC",		37,	0 },	{ "North Dakota",			"ND",		38,	2 },	{ "Ohio",				"OH",		39,	0 },	{ "Oklahoma",				"OK",		40,	2 },	{ "Oregon",				"OR",		41,	1 },	{ "Pennsylvania",			"PA",		42,	0 },	{ "Rhode Island",			"RI",		44,	0 },	{ "South Carolina",			"SC",		45,	0 },	{ "South Dakota",			"SD",		46,	2 },	{ "Tennessee",				"TN",		47,	0 },	{ "Texas",				"TX",		48,	2 },	{ "Utah",				"UT",		49,	2 },	{ "Vermont",				"VT",		50,	0 },	{ "Virginia",				"VA",		51,	0 },	{ "Washington",				"WA",		53,	1 },	{ "West Virginia",			"WV",		54,	0 },	{ "Wisconsin",				"WI",		55,	2 },	{ "Wyoming",				"WY",		56,	2 },	{ "American Samoa",			"AS",		60,	1 },	{ "Federated States of Micronesia",	"FM",		64,	1 },	{ "Guam",				"GU",		66,	1 },	{ "Marshall Islands",			"MH",		68,	1 },	{ "Northern Mariana Islands",		"MP",		69,	1 },	{ "Palau",				"PW",		70,	1 },	{ "Puerto Rico",			"PR",		72,	2 },	{ "U.S. Minor Outlying Islands",	"PM",		74,	1 },	{ "Virgin Islands of the U.S.",		"VI",		78,	1 },/* DO NOT DELETE THIS -- THIS TERMINATES THE ARRAY */	{ (char *)NULL,				(char *)NULL,	 0,	0 }};struct region {    char *    dsa_name;				/* name of parent dsa */    char *    dsa_addr;				/* address of parent dsa */};#define N_REGIONS	3			/* regions for states above */struct region regional_dsas[N_REGIONS+1];struct edbdir {    char *    dir;				/* path */    char *    edb;				/* name of 'template' file */};struct edbdir topdirs[] = {	{ ".",			"../templates/root.edb" },	{ "c=US",		"../templates/us/us.edb" },/* DO NOT DELETE THIS -- THIS TERMINATES THE ARRAY */	{ (char *)NULL,		(char *)NULL, }}; /* locations of temporary entries */#define ORGENTRY	"org.tmp"		/* temporary org. entry */#define DSAENTRY	"dsa.tmp"		/* temporary dsa entry *//* template files */#define ORGTMPL		"../templates/us/organization.edb" /* org. entry */#define ANSI_ORGTMPL	"../templates/us/ansiorg.edb" /* ansi org. entry */#define DSATMPL		"../templates/us/dsa.edb" /*  DSA template */#define ORGEDBTMPL	"../templates/us/orgedb.edb" /* org. entries template */#define OUEDBTMPL	"../templates/us/ouedb.edb" /* ou. entries template */#define QUIPUTMPL	"../templates/us/quiputailor" /* US quiputailor */#define DSAPTMPL	"../templates/us/dsaptailor" /* US dsaptailor */#define STARTUPTMPL	"../templates/startup.sh" /* startup.sh */#define NIGHTLYTMPL	"../templates/nightly.sh" /* nightly.sh */#define FREDTMPL	"../templates/fredrc"	/* fredrc */#define UFNTMPL		"../templates/us/ufnrc"	/* ufnrc *//* general #defines */#define DIRPERM			0711		/* directory permissions */#define SEDFILE			"sed.tmp"	/* sed filename */#define USDN			"c=US"		/* DN for the US *//*  *//* ARGSUSED *//* main () -- main function for program */voidmain (argc, argv)int  argc;char **argv;{    struct pair *pp;			/* pair pointer */    extern struct pair * findpair ();    extern void arginit (), read_config (), read_dsas ();    extern void build_top (), add_us (), add_state (), build_dsa ();    extern void build_orgedb (), build_ouedb ();    extern void build_tailor (), build_scripts (), build_uifl();    extern void create_sedfile (), build_mesgfl ();    extern void set_permissions ();    chartered_by_congress = 0x00;	/* assume not congress-chartered *//* get configuration */    arginit (argc, argv);		/* initialize from command line */    read_dsas ();			/* read in regional dsas */    read_config ();			/* read configuration file *//* create database directory */    if ((pp = findpair ("wildlife", 0x00)) == (struct pair *)NULL)       adios (NULLCP, "no database directory found in configuration");    else      if (access (pp->p_val, F_OK) == 0)        adios (NULLCP, "\"%s\" already exists -- use another name", pp->p_val);/*build root, c=US *//*    an important side-effect of this function is to change the working   directory for this program to $(ETCDIR)/quipu/wildlife*/    build_top ();			/* build top-level of DIT *//* create sed file. depends on being in $(ETCDIR)/quipu/wildlife */    create_sedfile ();			/* create sed file *//* build organizational entry */    if ((pp = findpair ("orgcode", 0x00)) == (struct pair *)NULL)      if (chartered_by_congress) {        add_us ((struct pair *)NULL);	/* build US EDB with org. in it */        add_state (0x00);		/* build empty state EDB */      }      else {				/* org. has regional standing */        /* organization with regional standing */        add_state (0x01);		/* build state EDB with organization */      }    else {				/* organization with national standing*/      add_us (pp);			/*build US EDB with organization in it*/      add_state (0x00);			/* build empty state EDB */    }/* build DSA entry in c=US */    build_dsa ();/* build skeleton EDB for organization and organizational unit */    build_orgedb ();    build_ouedb ();/* build tailor, script and configuration files */    build_tailor ();			/* build tailor files */    build_scripts ();			/* build scripts */    build_uifl ();			/* build user interface configurations*/    unlink (SEDFILE);/* create message file */    build_mesgfl();/* set owner/group permissions */    set_permissions ();    exit (0);}/*  *//* arginit () -- parse command line, and initialize from it */voidarginit (ac,av)int ac;char **av;{    int i,j,k;    struct pair *wildlife;    extern struct pair *findpair ();    extern void make_usstates ();/* get name of program */    if ((prgnm = strrchr (av[0], (int)'/')) == (char *)NULL)      prgnm = av[0];			/* use entire token as program name */    else      prgnm++;				/* skip past trailing '/' *//* tailor application */    isodetailor (prgnm, 1);/* get pointer to wildlife pair structure */    if ((wildlife = findpair ("wildlife", 0x01)) == (struct pair *)NULL)      adios (NULLCP, "internal error: cannot find wildlife pair");/* parse command line -- currently there are no command line options */    for (i = 1; i < ac; ++i)		/* iterate through command line */       if (av[i][0] == '-')		/* command line option? */         for (j = 1; av[i][j] != '\0'; ++j) /* iterate through all options */            switch (av[i][j]) {		/* identify command line option */	      case 'c':			/* chartered by congress */                chartered_by_congress = 0x7f;	        break;	      case 'l':			/* list U.S. states */                for (k = 0; usstates[k].s_nm != (char *)NULL; ++k)		   printf ("%s\n", usstates[k].s_nm);	        exit (0);/** INTERNAL OPTIONS -- for the use of wpp-manager */              case 's':			/* generate U.S. state entries */                make_usstates ();                exit (0);              default:		advise(NULLCP, "illegal switch -%c", av[i][j]);		break;            }				/* end, switch */       else         if (wildlife->p_val != (char *)NULL) /* file already specified? */           advise (NULLCP,		   "wildlife directory already specified -- ignoring %s",		   av[i]);         else	   wildlife->p_val = av[i];    if (wildlife->p_val == (char *)NULL)      adios (NULLCP, "usage: %s config-file",prgnm);}/*  *//* read_dsas () -- read in identities and locations of regional DSAs */voidread_dsas (){    u_short lncnt;			/* linecount */    char *cp;				/* character pointer */    char *toks[NVEC+1];			/* tokens on line */    FILE *fp;				/* file pointer */    int i;				/* index and counter *//* initializations */    bzero (line, BUFSIZ);    bzero (file, BUFSIZ);    bzero ((char *)(regional_dsas), (N_REGIONS+1 * sizeof (struct region)));/* open file containing names/identities of regional dsas */    sprintf (file, "templates/us/dsas");    if ((fp = fopen (file, "r")) == (FILE *)NULL)      adios (file, "unable to read");    lncnt = 0;    for (lncnt = 1, i = 0;         i < N_REGIONS && fgets (line, BUFSIZ-1, fp) != (char *)NULL;         lncnt++) {/* check for comment line ... */       if (line[0] == '#')		/* a comment? */         continue;/* get rid of trailing NL */       if ((cp = index (line, '\n')) != (char *)NULL)         *cp = '\0';			/* get rid of NL *//* tokenize line */       switch (str2vec (line, toks)) {	/* tokenize line */         case 0:			/* blank line */           continue;         case 1:			/* syntax error ... */           advise (NULLCP, "syntax error, line %d: insufficient parameters",		   lncnt);           continue;         case 2:           break;         default:           advise (NULLCP, "syntax error, line %d: too many parameters",		   lncnt);           continue;       }				/* end, tokenize line *//* fill in regional_dsas structure */       regional_dsas[i].dsa_name = strdup (toks[0]);       regional_dsas[i++].dsa_addr = strdup (toks[1]);    }					/* end, foreach line */    if (i != N_REGIONS)			/* too few dsas */      adios (NULLCP, "dsas specified for too few regions, %d", i);    fclose (fp);}/*  *//* read_config () -- parse configuration file, and initialize from it */voidread_config (){    u_short lncnt;			/* linecount */    char *toks[NVEC+1];			/* tokens on line */    char *cp,*cp2;			/* character pointers */    struct pair *pp, *pp2, *pp3;	/* pointers to a pair struct. */    FILE *cfgfp;			/* configuration file ptr. */    int i;				/* index and counter */    short nmlen;			/* length of a name */    struct hostent *hp;			/* for host structure */    struct sockaddr_in sin;		/* for local address */    struct state *sp;			/* to save 'state' */    extern struct pair *findpair ();    extern char * strdup ();    extern void bad_postaladdress ();    lncnt = 0;    bzero (buf, BUFSIZ);		/* clear global general purpose buffer*/    bzero (line, BUFSIZ);		/* clear global general purpose line */    bzero (file, BUFSIZ);		/* clear global general purpose file *//* open configuration file */    if ((pp = findpair ("wildlife", 0x00)) == (struct pair *)NULL)      adios (NULLCP, "no configuration file specified");    sprintf(file,"%s.dsa",pp->p_val);    if ((cfgfp = fopen (file, "r")) == (FILE *)NULL)      adios (file, "unable to read");/* run through each line of configuration file */    while (fgets(line, BUFSIZ-1, cfgfp) != (char *)NULL) {       lncnt++;				/* add to linecount */       if (line[0] == '#')		/* comment line? */         continue;       if ((cp = index (line, '\n')) != (char *)NULL)         *cp = '\0';			/* get rid of NL */       switch (str2vec (line, toks)) {	/* tokenize line */          case 0:	    continue;          case 1:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -