Example #1
0
void *find_module(char *name,int *type){
     void *mod;
     if((mod=find_logger(name))!=NULL){
	  *type=LOGGER;
	  return mod;
     }
     if((mod=find_servicehandler(name))!=NULL){
	  *type=SERVICE_HANDLER;
	  return mod;
     }
     if((mod=find_access_controller(name))!=NULL){
	  *type=ACCESS_CONTROLLER;
	  return mod;
     }
     if((mod=find_auth_method(name))!=NULL){
	  *type=AUTH_METHOD;
	  return mod;
     }
     if((mod=find_authenticator(name))!=NULL){
	  *type=AUTHENTICATOR;
	  return mod;
     }
     *type=UNKNOWN;
     return NULL;
}
Example #2
0
int SetLogger(char *directive,char **argv,void *setdata){
     logger_module_t *logger;
     if(argv==NULL || argv[0]==NULL){
	  debug_printf(1,"Missing arguments in directive\n");
	  return 0;
     }

     if(!(logger=find_logger(argv[0])))
	  return 0;
     default_logger=logger;
     debug_printf(1,"Setting parameter :%s=%s\n",directive,argv[0]);
     return 1;
}
Example #3
0
main(int argc, char *argv[]) {
	char *pgm, *s;
	int   ok, help;
	char *server;
	int   id, nc;
	int   i;
	char  me[256];
	char  logstr[200];

	pgm = argv[0];

	/* Get and save our original working directory */
	if (!GetWD(SelfWD, sizeof(SelfWD))) {
		fprintf(stderr, "%s: couldn't get working directory\n", pgm);
		perror(pgm);
		exit(4);
	}

	/* Get our own name and any path prefix */
	if (pgm = strrchr(argv[0], '/')) {
		*pgm++ = '\0';
		if (*argv[0] == '/') strcpy(Logdir, argv[0]);
		else                 make_path(Logdir, SelfWD, argv[0]);
		if (Verbose) printf("Logdir search is \"%s\"\n", Logdir);
	}
	else {
		strcpy(Logdir, SelfWD);
		pgm = argv[0];
	}

	++argv; --argc;

	/* See if we are running as the LOGGER */
	sprintf(logstr, "{%s,%s%s}", LOGGEREXEC, LOGGEREXEC, LOGGEREXT);
	if (strmatch(logstr, pgm)) logger(pgm, argc, argv);

	/* Default options */
	ok    = 1;
	help  = 0;

	/* Parse out command line options */
	while (argc && *argv[0] == '-') {
		char *opt;

		opt = argv[0] + 1;
		++argv; --argc;

		if      (substr(opt, "help"))    ++help;
		else if (substr(opt, "debug"))   ++Debug;
		else if (substr(opt, "nodebug")) Debug   = 0;
		else if (substr(opt, "verbose")) Verbose = 1;
		else if (substr(opt, "quiet"))   Verbose = 0;
		else if (streq(opt, "bin") || streq(opt, "dir")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			RootPath = argv[0];
			++argv; --argc;
		}
		else if (streq(opt, "wd") || streq(opt, "cd")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			WorkDir = argv[0];
			++argv; --argc;
		}
		else if (substr(opt, "logger")) {
			if (argc < 1) {
				fprintf(stderr, "%s: missing argument to -%s\n",
					pgm, opt);
				ok = 0;
				break;
			}
			if (argv[0][0] == '/') strcpy(Logger, argv[0]);
			else {
				int  len;
				char *name;

				/* Copy the current working directory */
				strcpy(Logger, SelfWD);
				len = strlen(Logger);
				if (Logger[len-1] != '/') Logger[len++] = '/';

				name = argv[0];
				if (substr("./", name)) name += 2;
				strcpy(Logger+len, name);
			}
			++argv; --argc;
		}
		else {
			fprintf(stderr, "%s: ignoring argument -%s\n", pgm, opt);
			help = 1;
			ok   = 0;
		}
	}
	if (!ok || argc == 0) {
		usage(pgm, help);
		exit(!help);
	}

	server = argv[0];
	++argv; --argc;

	/* Allow directory to be specified as last command line arg */
	if (argc) {
		if (RootPath) {
			if (!streq(RootPath, argv[0])) {
				fprintf(stderr,
					 "%s: can't use -dir (%s) and specify path (%s)\n",
					 pgm, RootPath, argv[0]);
				exit(4);
			}
		}
		else {
			RootPath = argv[0];
			++argv; --argc;
		}
	}

	/* Check for any extraneous args */
	if (argc) {
		fprintf(stderr, "%s: too many arguments starting with \"%s\"\n",
			pgm, argv[0]);
		usage(pgm, help);
		exit(!help);
	}

	/* Now change to our root directory */
	if (RootPath) {
		if (chdir(RootPath) != SYS_OK) {
			fprintf(stderr, "%s: couldn't chdir to \"%s\"\n", pgm, RootPath);
			exit(4);
		}
	}
	else fprintf(stderr, "%s: WARNING! no root directory specified - using .\n", pgm);

	/* Set up path to working directory for lauched agents */
	if (WorkDir)
	   if (*WorkDir == '/') strcpy(WorkPath, WorkDir);
	   else make_path(WorkPath, SelfWD, WorkDir);

	/* Open the executable directory to process queries */
	if (!GetWD(ExecPath, sizeof(ExecPath))) {
		fprintf(stderr, "%s: couldn't get working directory\n", pgm);
		perror(pgm);
		exit(4);
	}

	ExecDir = opendir(ExecPath);
	if (!ExecDir) {
		fprintf(stderr, "%s: couldn't open working directory \"%s\"\n", pgm, ExecPath);
		perror(pgm);
		exit(4);
	}

#ifdef win32
	/*
	 * On windows we need to run the logger as a separate helper app
	 * since the cygwin implementation of fork is not quite right.
	 * Look for it in standard places as well as looking as users $PATH
	 */
	if (!Logger[0] && !find_logger()) {
		fprintf(stderr,
			"%s: couldn't find initiator \"%s\"\n",
			pgm, LOGGEREXEC);
		exit(4);
	}
	if (Verbose) printf("Logger exec is \"%s\"\n", Logger);
#endif

	/* Make sure we found the file and it is executable */
	if (Logger[0] && access(Logger, X_OK) != SYS_OK) {
		fprintf(stderr,
			"%s: initiator \"%s\" not %s\n", pgm, Logger,
			access(Logger, F_OK)?"found":"executable");
		exit(4);
	}

	/* Deal with signals */
	siginit();

	/* local initialization */
	event_verbose(Verbose);
	event_tunnel_enable(0);
	agentd_init();

	/* Connect to our event server */
	id = event_join(server, &nc);
	if (!id) {
		fprintf(stderr, "%s: couldn't join server \"%s\"\n", pgm, server);
		exit(4);
	}
	if (Verbose) printf("%s: joined %s as client id %d (%d clients)\n", pgm, server, id, nc);

	/* Register */
	cuserid(me);

	event_register(AGENTDCLASS, AGENTDSPEC, me);

	/* Subscribe to only AGENTD type events */
	event_select_type(0, ET_MIN, ET_MAX);
	event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX);

	/* Initialize agent control structures */
	for (i = 0; i < MAX_AGENT; ++i) {
		Agent[i].pid    = 0;
		Agent[i].status = AGENTD_AGENT_FREE;
	}

	mp_init();  /*(not strcitly necessary, since done in event land)*/

	/* Allocate our locks and semaphores */
	AgentLock = mp_alloclock();

	Exitlock  = mp_alloclock();
	Exitwait  = mp_allocsema();
	ReadInit  = mp_allocsema();
	AgentInit = mp_allocsema();

	/*
	 * Loop forever processing agentd requests
	 */
	FOREVER {
		EVENT e;

		/* Wait for an event and then dispatch it */
		event_wait();
		if (!event_receive(&e)) continue;

		switch (e.ev_head.type) {
		  case ET_AGENTD_REQ:
			agent_request((EVENT_AGENTD_REQ *)&e);
			break;

		  default:
			if (Verbose)
			   printf("Ignoring event \'%s\'(%d) from %d\n",
				   event_lookup_name(e.ev_head.type),
				   e.ev_head.type, e.ev_head.from);
		}
	}
}