Esempio n. 1
0
int main(int argc, char **argv)
{
	int c, f = 0, error = 0;
	extern char *optarg;
	extern int optind;
	char isoqlogconf[256];


	while (!error && (c = getopt(argc,argv,"f:hv")) != -1) {
        	switch (c) {
        	case 'v':
			puts(VERSION_STRING);
	        	exit(0);
	        	break;
		case 'h':
			puts("Usage: isoqlog [-f isoqlog.conf]");
			exit(0);
			break;
		case 'f':
			strncpy(isoqlogconf, optarg, 256);
			f = 1;
       			break;
		default:
			error = 1;
			puts("Usage: isoqlog [-f isoqlog.conf]");
			exit(-1);
			break;
       		} 
	}

	general.from_cnt = 0;
	general.to_cnt = 0;
	general.from_byte = 0;
	
	if (f == 0) 
		readconfig(CONFIGFILE); /* CONFIGFILE variable is defined in config.h */
	else 
		readconfig(isoqlogconf);
	loadLang(langfile);

	if (strcmp(logtype, "qmail-multilog") == 0) 
		openlogdir(logstore);
	else
	if (strcmp(logtype, "qmail-syslog") == 0)
		readQmailLogFile(logstore);
	else
	if (strcmp(logtype, "sendmail") == 0)
		readSendmailLogFile(logstore);
	else
	if (strcmp(logtype, "postfix") == 0)
		readSendmailLogFile(logstore);
	else
        if (strcmp(logtype, "exim") == 0)
		readEximLogFile(logstore);

	createHtml();
	return 0;
}
Esempio n. 2
0
void loadconfig (void) {
	char filename[CONFIGMAXFILENAME];

	/* read system wide config first */	
	strncpy (filename, CONFIGDIRLOC, CONFIGMAXFILENAME);
	strncat (filename, CONFIGDIRDELIM, CONFIGMAXFILENAME);
	strncat (filename, CONFIGFILENAME, CONFIGMAXFILENAME);
	readconfig(filename);

	/* read user specific config */
	strncpy (filename, getenv("HOME"), CONFIGMAXFILENAME);
	strncat (filename, CONFIGDIRDELIM, CONFIGMAXFILENAME);
	strncat (filename, ".", CONFIGMAXFILENAME);
	strncat (filename, CONFIGFILENAME, CONFIGMAXFILENAME);
	readconfig(filename);
}
Esempio n. 3
0
static void ccf_include(adns_state ads, const char *fn, int lno, const char *buf) {
  if (!*buf) {
    configparseerr(ads,fn,lno,"`include' directive with no filename");
    return;
  }
  readconfig(ads,buf,1);
}
Esempio n. 4
0
/* initdata 

   set initial values of global datastructures

   ws2000station
   pcwsrstation
   onewirestation
   wsconf
 
*/
int 
wthd_init( ) {
  int err;

  /* default parameters valid for all stations */
  wsconf.timeout     = 30;
  wsconf.logfacility = LOG_LOCAL5;
  wsconf.verbose     = 1;
  wsconf.debug       = 1;
  wsconf.hostname    = "localhost";
  if ( wsconf.port == NULL ) {
    wsconf.port        = "2000";
  }
  wsconf.units       = "SI";
  wsconf.outfmt      = "old";

  /* WS2000 */  
  strncpy(ws2000station.config.dbfile, "ws2000.db", TBUFF);
  strncpy(ws2000station.config.device, "n.a.", TBUFF);
  strncpy(ws2000station.config.rrdpath, ".", TBUFF);
  strncpy(ws2000station.config.monitor,"Sensormonitor.rrd", TBUFF);;
  ws2000station.status.interval      = 300;  

  /* allocate sensornames WS2000 */
  strncpy(ws2000station.sensor[1].sensorname, "Sensor1", TBUFF);
  strncpy(ws2000station.sensor[2].sensorname, "Sensor2", TBUFF);
  strncpy(ws2000station.sensor[3].sensorname, "Sensor3", TBUFF);
  strncpy(ws2000station.sensor[4].sensorname, "Sensor4", TBUFF);
  strncpy(ws2000station.sensor[5].sensorname, "Sensor5", TBUFF);
  strncpy(ws2000station.sensor[6].sensorname, "Sensor6", TBUFF);
  strncpy(ws2000station.sensor[7].sensorname, "Sensor7", TBUFF);
  strncpy(ws2000station.sensor[8].sensorname, "Sensor8", TBUFF);
  strncpy(ws2000station.sensor[9].sensorname, "Rainsensor", TBUFF);
  strncpy(ws2000station.sensor[10].sensorname, "Windsensor", TBUFF);
  strncpy(ws2000station.sensor[11].sensorname, "Indoorsensor", TBUFF);

  /* PCWSR */
  strncpy(pcwsrstation.config.dbfile, "pcwsr.db", TBUFF);
  strncpy( pcwsrstation.config.device, "n.a.", TBUFF);

  /* 1-WIRE */
  strncpy(onewirestation.config.dbfile, "onewire.db", TBUFF);
  strncpy(onewirestation.config.device, "n.a.", TBUFF);
  onewirestation.config.mcycle = 10;

  /* WMR9x8 */
  strncpy(wmr9x8station.config.dbfile, "wmr9x8.db", TBUFF);
  strncpy(wmr9x8station.config.device, "n.a.", TBUFF);

  /* ULTIMETER */
  strncpy(umeterstation.config.dbfile, "umeter.db", TBUFF);
  strncpy(umeterstation.config.device, "n.a.", TBUFF);

  err = readconfig();
  //printf("%s", echoconfig( "onewirestation"));
  printf("wthd_init: readconfig done\n");

  return(err);
}
Esempio n. 5
0
void
reread_config(void)
{
    if (config_file) {
	syslog(LOG_INFO, "Got SIGHUP, re-reading configuration");
	readconfig(config_file);
    }
}
Esempio n. 6
0
int adns_init(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile) {
  adns_state ads;
  const char *res_options, *adns_res_options;
  int r;
  
  r= init_begin(&ads, flags, diagfile);
  if (r) return r;
  
  res_options= instrum_getenv(ads,"RES_OPTIONS");
  adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS");
  ccf_options(ads,"RES_OPTIONS",-1,res_options);
  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);

#ifndef VMS
  readconfig(ads,"/etc/resolv.conf",0);
  readconfig(ads,"/etc/resolv-adns.conf",0);
#else
  ilog(L_CRIT, "Opening IRCD$CONFDIR:RESOLV.CONF (VMS)");
  readconfig(ads,"IRCD$CONFDIR:RESOLV.CONF",0);
#endif
  readconfigenv(ads,"RES_CONF");
  readconfigenv(ads,"ADNS_RES_CONF");

  readconfigenvtext(ads,"RES_CONF_TEXT");
  readconfigenvtext(ads,"ADNS_RES_CONF_TEXT");

  ccf_options(ads,"RES_OPTIONS",-1,res_options);
  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);

  ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN"));
  ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN"));

  if (ads->configerrno && ads->configerrno != EINVAL) {
    ilog(L_CRIT, "Failed at 1");
    r= ads->configerrno;
    init_abort(ads);
    return r;
  }

  r= init_finish(ads);
  if (r) return r;

  adns__consistency(ads,0,cc_entex);
  *ads_r= ads;
  return 0;
}
Esempio n. 7
0
int adns__rereadconfig(adns_state ads)
{
  struct in_addr ia;
  adns__consistency(ads,0,cc_entex);
  ads->nservers = 0;	
#ifndef VMS
  readconfig(ads,"/etc/resolv.conf",0);
#else
  readconfig(ads,"[]resolv.conf",0);
#endif
  if (!ads->nservers)
  {
      ia.s_addr= htonl(INADDR_LOOPBACK);
      addserver(ads,ia);
  }
  adns__consistency(ads,0,cc_entex);
  return 0;
}
Esempio n. 8
0
/* initialisation of the library */
void
init(){
    openlog ("libnosync", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    inituser();
    initprocess();
    syslog (LOG_NOTICE, "loaded by program %s, user %s", process, user);
    initsymbols();
    readconfig();
}
Esempio n. 9
0
static void readconfigenv(adns_state ads, const char *envvar) {
  const char *filename;

  if (ads->iflags & adns_if_noenv) {
    adns__debug(ads,-1,0,"not checking environment variable `%s'",envvar);
    return;
  }
  filename= instrum_getenv(ads,envvar);
  if (filename) readconfig(ads,filename,1);
}
Esempio n. 10
0
void deletefileexpired()
{
	struct dirent **pCamDir;
	char dayPathExpired[256],timePathExpired[256];
	pthread_detach(pthread_self());
	
	//GetExpiredPath(dayPathExpired, timePathExpired);
    readconfig();
	traveldir(spacechecker._file_expired_checked_path,&pCamDir, &camhandler, &breakchecker);
}
Esempio n. 11
0
int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) {
  adns_state ads;
  const char *res_options, *adns_res_options;
  int r;
  
  r= init_begin(&ads, flags, diagfile ? diagfile : stderr);
  if (r) return r;
  
  res_options= instrum_getenv(ads,"RES_OPTIONS");
  adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS");
  ccf_options(ads,"RES_OPTIONS",-1,res_options);
  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);

  readconfig(ads,"/etc/resolv.conf",1);
  readconfig(ads,"/etc/resolv-adns.conf",0);
  /* checking in the current dir for cygwin */
  readconfig(ads,"resolv.conf",0);
  readconfigenv(ads,"RES_CONF");
  readconfigenv(ads,"ADNS_RES_CONF");

  readconfigenvtext(ads,"RES_CONF_TEXT");
  readconfigenvtext(ads,"ADNS_RES_CONF_TEXT");

  ccf_options(ads,"RES_OPTIONS",-1,res_options);
  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);

  ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN"));
  ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN"));

  if (ads->configerrno && ads->configerrno != EINVAL) {
    r= ads->configerrno;
    init_abort(ads);
    return r;
  }

  r= init_finish(ads);
  if (r) return r;

  adns__consistency(ads,0,cc_entex);
  *ads_r= ads;
  return 0;
}
Esempio n. 12
0
int main(int argc, char **argv)
{
	const char *dev;
	char errbuf[PCAP_ERRBUF_SIZE];
	int rv;

	pcap_t *session;
	struct bpf_program fp;

	if (argc < 2)
	{
		fprintf(stderr, "Usage: %s <device>\n", argv[0]);
		return 1;
	}

	dev = argv[1];
	struct sconfig config[64];
	
	readconfig(config);
		
	printf("\nInstruction loaded: %s", config[0].type);
	printf("\nCommand loaded: %s", config[0].command);
	printf("\n"); //I don't understand but this line just disapears
	
	session = pcap_open_live(dev, 1500, 0, 100, errbuf);

	if (!session)
	{
		fprintf(stderr, "Can't open %s for capturing: %s\n", dev, errbuf);
		return 2;
	}

	if (pcap_compile(session, &fp, filter, 0, 0) == -1)
	{
		fprintf(stderr, "Can't parse filter %s: %s\n", filter, pcap_geterr(session));
		return 3;
	}

	if (pcap_setfilter(session, &fp) == -1)
	{
		fprintf(stderr, "Can't install filter %s: %s\n", filter, pcap_geterr(session));
		return 4;
	}

	rv = pcap_loop(session, -1, packet_cb, NULL);

	if (rv)
		fprintf(stderr, "Capture loop terminated with code %d\n", rv);

	pcap_close(session);

	return rv;
}
enum nss_status _nss_shib_getgrgid_r(gid_t gid, struct group *result, char *buffer, size_t buflen, int *errnop)
{
#ifdef DEBUG
	fprintf(stderr, "\nEntering _nss_shib_getgrgid_r with gid=%d.\n", gid);
#endif

	int ret = NSS_STATUS_UNAVAIL;
	readconfig();
	char newurl[1024];
	sprintf(newurl, "%s", url_group);
	if (!geturl(newurl, username, password, cafile, sslcheck) || body == NULL) {
		ret = NSS_STATUS_UNAVAIL;
		goto getgrgid_err;
	}

	BODY *cursor = body;
	while (cursor)
	{
		char *cur_row = cursor->row;
		int count_separator = count_char_in_str(cur_row, ':');
		char **array = split_str(cur_row, ':');

		if (array[0] != NULL  && count_separator >= 3 && atoi(array[2]) == gid)
		{
			int setting = setgroupfromarray(array, result, buffer, buflen);
			if (setting != 0) {
				if (setting == 1) {
					if(array) free(array);

					*errnop = ERANGE;
					ret = NSS_STATUS_TRYAGAIN;
				}
				else {
					ret = NSS_STATUS_UNAVAIL;
				}
				goto getgrgid_err;
			}

#ifdef DEBUG
			fprintf(stderr, "Found item for gid=%d: [name=%s]\n", gid, array[0]);
#endif

			ret = NSS_STATUS_SUCCESS;
		}

		if(array) free(array);
		cursor = cursor->next;
	}  

getgrgid_err:
	cleanbody();
	return ret;
}
Esempio n. 14
0
int main(int argc, char *argv[])
{
	if (!loaddata()) exit(1);
	if (!readconfig()) exit(1);
	
	buildnodelist();
	EZ_Initialize(argc,argv,0);
	initgui();

	EZ_EventMainLoop();

	return 0;
}
Esempio n. 15
0
static void rehash()
{
  call_hook(HOOK_PRE_REHASH);

  noshare = 1;
  clear_userlist(userlist);
  noshare = 0;

  userlist = NULL;

  readconfig();
  /* FIXME: We should really call post rehash here as well, instead of in readconfig(). */
}
Esempio n. 16
0
static int h_include(int argc, unsigned char **argv){
	int res;
	FILE *fp1;

	fp1 = fopen((char *)argv[1], "r");
	if(!fp1){
		fprintf(stderr, "Unable to open included file: %s\n", argv[1]);
		return 1;
	}
	res = readconfig(fp1);
	fclose(fp1);
	return res;
}
Esempio n. 17
0
void usr2_error(int r)
{
    if(nosignals == 0)
    {
        nosignals=1;
        p_debug();
        p_log(LOG_INFO,-1,lngtxt(633));
        resetconfig();
        readconfig();
        loadusers();
        nosignals=0;
    }
    return;
}
Esempio n. 18
0
void deletefilesizeexceeding()
{
	struct dirent **pCamDir;
	char dayPathExpired[256],timePathExpired[256];
	pthread_detach(pthread_self());
	
	//GetExpiredPath(dayPathExpired, timePathExpired);
    readconfig();
	
	while(checkcapacity()==STAT_NOK)
	{
		traveldir(spacechecker._file_expired_checked_path,&pCamDir, &camexceedsizehandler, &breakchecker);
	}
}
Esempio n. 19
0
int main() {
   char buffer[200];
   int devfilefd, fd, i;
   float elevation, azimuth;

   readconfig();

   /* open the pseudo terminal device */
   fd=getpt();
   if (fd<0) {
      fprintf(stderr, "Unable to open serial line!\n");
      return -1;
   }
   unlockpt(fd);

   /* write the device file */

   devfilefd = open(PSEUDODEVICEFILE, O_WRONLY|O_CREAT, 0666);
   write(devfilefd, (char*)ptsname(fd), strlen((char*)ptsname(fd)));
   close(devfilefd);


   /* open the fodtrack device */

   openfodtrack(fodtrackdev);

   /* print informations about the devices */

   printf("Using %s as pseudo terminal device.\n", ptsname(fd));
   printf("Using %s as port for the fodtrack device.\n", fodtrackdev);

   /* going for the background */

   daemon(0,0);


   /* Main loop - reads from the device, and sets the antenna on the output */

   for(;;) {
      usleep(100);
      i=read(fd, buffer, 199);
      if(i>0) {
          sscanf(buffer, "AZ%f  EL%f", &azimuth, &elevation);
          /*printf("New Data:\nElevation: %f\nAzimuth: %f\n\n", elevation, azimuth);*/
          setElevation(elevation);
          setAzimuth(azimuth);
      }
   }
}
Esempio n. 20
0
int reload (void){
	FILE *fp;
	int error = -2;

	conf.paused++;
	freeconf(&conf);
	conf.paused++;

	fp = confopen();
	if(fp){
		error = readconfig(fp);
		if(error) {
			 freeconf(&conf);
		}
		if(!writable)fclose(fp);
	}
	return error;
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
	int fd;
	char dev[64];
	struct hostent *hp = NULL;

	while ((fd = getopt(argc, argv, "i:m:v")) != -1) {
		switch (fd) {
			case 'i':
				if ((hp = gethostbyname(optarg)) == NULL) {
					fprintf(stderr, "rsattach: invalid internet name/address - %s\n", optarg);
					return 1;
				}
				break;
			case 'v':
				printf("rsattach: %s\n", VERSION);
				return 0;
			case ':':
			case '?':
				fprintf(stderr, "usage: rsattach [-i inetaddr] [-v] port\n");
				return 1;
		}
	}
	
	if ((argc - optind) != 1) {
		fprintf(stderr, "usage: rsattach [-i inetaddr] [-v] port\n");
		return 1;
	}

	if (!readconfig(argv[optind]))
		return 1;

	if (!getfreedev(dev)) {
		fprintf(stderr, "rsattach: cannot find free Rose device\n");
		return 1;
	}
	
	if (!startiface(dev, hp))
		return 1;		

	printf("Rose port %s bound to device %s\n", argv[optind], dev);
		
	return 0;
}
Esempio n. 22
0
int main(void) {
	config_t config;

	config = readconfig("/etc/blag.conf");

	if(config.db == NULL)
		return EXIT_FAILURE;

	head(config.title, config.baseurl, config.desc);
	printposts(config.db, config.baseurl, 16);
	tail();

	sqlite3_close(config.db);
	free(config.title);
	free(config.baseurl);
	free(config.desc);

	return EXIT_SUCCESS;
}
Esempio n. 23
0
int main(int argc, char* argv[]) {

	const char* path; //Where can we find the config?
	if ( argc != 2 ) {
		std::cout << "usage: " << argv[0] << " filename" << std::endl;
		std::exit(1);
	} else {
		//Set config path!
		path = argv[1];
	}

	//Let our configreader parse!
	readconfig(path);

	//formatted output
	for(std::map<std::string, std::string>::iterator iterator = Config.begin(); iterator != Config.end(); iterator++) {
		std::cout << iterator->first << " = " << iterator->second << std::endl;
	}

	return 0;
}
Esempio n. 24
0
/* initdata 

   set initial values of global datastructures

   ws2000station
   pcwsrstation
   wsconf
 
*/
int 
wthd_init( ) {
  int err;
  /* default parameters valid for all stations */
  wsconf.timeout     = 30;
  wsconf.logfacility = LOG_LOCAL5;
  wsconf.verbose     = 1;
  wsconf.debug       = 1;
  wsconf.hostname    = "localhost";
  wsconf.port        = "2000";
  wsconf.wwwport     = "8880";
  wsconf.units       = "SI";
  wsconf.outfmt      = "old";
  
  strncpy(ws2000station.config.dbfile, "ws2000.db", TBUFF);
  strncpy(ws2000station.config.device, "n.a.", TBUFF);
  strncpy(ws2000station.config.rrdpath, ".", TBUFF);
  strncpy(ws2000station.config.monitor,"Sensormonitor.rrd", TBUFF);;
  ws2000station.status.interval      = 300;  

  strncpy(pcwsrstation.config.dbfile, "pcwsr.db", TBUFF);
  strncpy( pcwsrstation.config.device, "n.a.", TBUFF);
  err = readconfig();
  printf("wthd_init: readconfig done\n");

  /* allocate sensornames WS2000 */
  strncpy(ws2000station.sensor[1].sensorname, "Sensor1", TBUFF);
  strncpy(ws2000station.sensor[2].sensorname, "Sensor2", TBUFF);
  strncpy(ws2000station.sensor[3].sensorname, "Sensor3", TBUFF);
  strncpy(ws2000station.sensor[4].sensorname, "Sensor4", TBUFF);
  strncpy(ws2000station.sensor[5].sensorname, "Sensor5", TBUFF);
  strncpy(ws2000station.sensor[6].sensorname, "Sensor6", TBUFF);
  strncpy(ws2000station.sensor[7].sensorname, "Sensor7", TBUFF);
  strncpy(ws2000station.sensor[8].sensorname, "Sensor8", TBUFF);
  strncpy(ws2000station.sensor[9].sensorname, "Rainsensor", TBUFF);
  strncpy(ws2000station.sensor[10].sensorname, "Windsensor", TBUFF);
  strncpy(ws2000station.sensor[11].sensorname, "Indoorsensor", TBUFF);
  return(0);
}
Esempio n. 25
0
int main (int argc, char **argv)
{
	int argi;
	char *configfn = NULL;
	int cfgcheck = 0;
	int mibcheck = 0;

	libxymon_init(argv[0]);

	for (argi = 1; (argi < argc); argi++) {
		if (standardoption(argv[argi])) {
			if (showhelp) return 0;
		}
		else if (strcmp(argv[argi], "--cfgcheck") == 0) {
			cfgcheck = 1;
		}
		else if (strcmp(argv[argi], "--mibcheck") == 0) {
			mibcheck = 1;
		}
		else if (argnmatch(argv[argi], "--timeout=")) {
			char *p = strchr(argv[argi], '=');
			timeout = 1000000*atoi(p+1);
		}
		else if (argnmatch(argv[argi], "--retries=")) {
			char *p = strchr(argv[argi], '=');
			retries = atoi(p+1);
		}
		else if (argnmatch(argv[argi], "--concurrency=")) {
			char *p = strchr(argv[argi], '=');
			max_pending_requests = atoi(p+1);
		}
		else if (argnmatch(argv[argi], "--report=")) {
			char *p = strchr(argv[argi], '=');
			reportcolumn = strdup(p+1);
			timing = 1;
		}
		else if (*argv[argi] != '-') {
			configfn = strdup(argv[argi]);
		}
	}

	add_timestamp("xymon-snmpcollect startup");

	netsnmp_register_loghandler(NETSNMP_LOGHANDLER_STDERR, 7);
	init_snmp("xymon-snmpcollect");
	snmp_mib_toggle_options("e");	/* Like -Pe: Dont show MIB parsing errors */
	snmp_out_toggle_options("qn");	/* Like -Oqn: OID's printed as numbers, values printed without type */

	readmibs(NULL, mibcheck);

	if (configfn == NULL) {
		configfn = (char *)malloc(PATH_MAX);
		sprintf(configfn, "%s/etc/snmphosts.cfg", xgetenv("XYMONHOME"));
	}
	readconfig(configfn, mibcheck);
	if (cfgcheck) return 0;
	add_timestamp("Configuration loaded");

	resolvekeys();
	add_timestamp("Keys lookup complete");

	getdata();
	stophosts();
	add_timestamp("Data retrieved");

	sendresult();
	add_timestamp("Results transmitted");

	if (reportcolumn) egoresult(COL_GREEN, reportcolumn);

	xfree(configfn);

	return 0;
}
Esempio n. 26
0
File: mhbuild.c Progetto: ella13/nmh
int
main (int argc, char **argv)
{
    int sizesw = 1, headsw = 1;
    int *icachesw;
    char *cp, buf[BUFSIZ];
    char buffer[BUFSIZ], *compfile = NULL;
    char **argp, **arguments;
    CT ct, cts[2];
    FILE *fp = NULL;
    FILE *fp_out = NULL;

    done=unlink_done;

#ifdef LOCALE
    setlocale(LC_ALL, "");
#endif
    invo_name = r1bindex (argv[0], '/');

    /* read user profile/context */
    context_read();

    arguments = getarguments (invo_name, argc, argv, 1);
    argp = arguments;

    while ((cp = *argp++)) {
	if (cp[0] == '-' && cp[1] == '\0') {
	    if (compfile)
		adios (NULL, "cannot specify both standard input and a file");
	    else
		compfile = cp;
	    listsw = 0;		/* turn off -list if using standard in/out */
	    verbosw = 0;	/* turn off -verbose listings */
	    break;
	}
	if (*cp == '-') {
	    switch (smatch (++cp, switches)) {
	    case AMBIGSW: 
		ambigsw (cp, switches);
		done (1);
	    case UNKWNSW: 
		adios (NULL, "-%s unknown", cp);

	    case HELPSW: 
		snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
		print_help (buf, switches, 1);
		done (1);
	    case VERSIONSW:
		print_version(invo_name);
		done (1);

	    case RCACHESW:
		icachesw = &rcachesw;
		goto do_cache;
	    case WCACHESW:
		icachesw = &wcachesw;
	    do_cache: ;
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		switch (*icachesw = smatch (cp, caches)) {
		case AMBIGSW:
		    ambigsw (cp, caches);
		    done (1);
		case UNKWNSW:
		    adios (NULL, "%s unknown", cp);
		default:
		    break;
		}
		continue;

	    case CHECKSW:
		checksw++;
		continue;
	    case NCHECKSW:
		checksw = 0;
		continue;

	    case EBCDICSW:
		ebcdicsw++;
		continue;
	    case NEBCDICSW:
		ebcdicsw = 0;
		continue;

	    case HEADSW:
		headsw++;
		continue;
	    case NHEADSW:
		headsw = 0;
		continue;

	    case LISTSW:
		listsw++;
		continue;
	    case NLISTSW:
		listsw = 0;
		continue;

	    case RFC934SW:
		rfc934sw++;
		continue;
	    case NRFC934SW:
		rfc934sw = 0;
		continue;

	    case SIZESW:
		sizesw++;
		continue;
	    case NSIZESW:
		sizesw = 0;
		continue;

	    case CONTENTIDSW:
		contentidsw = 1;
		continue;
	    case NCONTENTIDSW:
		contentidsw = 0;
		continue;

	    case VERBSW: 
		verbosw++;
		continue;
	    case NVERBSW: 
		verbosw = 0;
		continue;
	    case DEBUGSW:
		debugsw = 1;
		continue;
	    }
	}
	if (compfile)
	    adios (NULL, "only one composition file allowed");
	else
	    compfile = cp;
    }

    set_endian ();

    if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1"))
	listsw  = 0;

    /*
     * Check if we've specified an additional profile
     */
    if ((cp = getenv ("MHBUILD"))) {
	if ((fp = fopen (cp, "r"))) {
	    readconfig ((struct node **) 0, fp, cp, 0);
	    fclose (fp);
	} else {
	    admonish ("", "unable to read $MHBUILD profile (%s)", cp);
	}
    }

    /*
     * Read the standard profile setup
     */
    if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) {
	readconfig ((struct node **) 0, fp, cp, 0);
	fclose (fp);
    }

    /* Check for public cache location */
    if ((cache_public = context_find (nmhcache)) && *cache_public != '/')
	cache_public = NULL;

    /* Check for private cache location */
    if (!(cache_private = context_find (nmhprivcache)))
	cache_private = ".cache";
    cache_private = getcpy (m_maildir (cache_private));

    /*
     * Check for storage directory.  If defined, we
     * will store temporary files there.  Else we
     * store them in standard nmh directory.
     */
    if ((cp = context_find (nmhstorage)) && *cp)
	tmp = concat (cp, "/", invo_name, NULL);
    else
	tmp = add (m_maildir (invo_name), NULL);

    if (!context_find ("path"))
	free (path ("./", TFOLDER));

    /* Check if we have a file to process */
    if (!compfile)
	adios (NULL, "need to specify a %s composition file", invo_name);

    /*
     * Process the composition file from standard input.
     */
    if (compfile[0] == '-' && compfile[1] == '\0') {
	/* copy standard input to temporary file */
	strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
	while (fgets (buffer, BUFSIZ, stdin))
	    fputs (buffer, fp);
	fclose (fp);
	unlink_infile = 1;

	/* build the content structures for MIME message */
	ct = build_mime (infile);
	cts[0] = ct;
	cts[1] = NULL;

	/* output MIME message to this temporary file */
	strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile));
	unlink_outfile = 1;

	/* output the message */
	output_message_fp (ct, fp_out, outfile);
        fclose(fp_out);

	/* output the temp file to standard output */
	if ((fp = fopen (outfile, "r")) == NULL)
	    adios (outfile, "unable to open");
	while (fgets (buffer, BUFSIZ, fp))
	    fputs (buffer, stdout);
	fclose (fp);

	unlink (infile);
	unlink_infile = 0;

	unlink (outfile);
	unlink_outfile = 0;

	free_content (ct);
	done (0);
    }

    /*
     * Process the composition file from a file.
     */

    /* build the content structures for MIME message */
    ct = build_mime (compfile);
    cts[0] = ct;
    cts[1] = NULL;

    /* output MIME message to this temporary file */
    strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
            sizeof(outfile));
    unlink_outfile = 1;

    /* output the message */
    output_message_fp (ct, fp_out, outfile);
    fclose(fp_out);

    /*
     * List the message info
     */
    if (listsw)
	list_all_messages (cts, headsw, sizesw, verbosw, debugsw);

    /* Rename composition draft */
    snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
    if (rename (compfile, buffer) == NOTOK) {
	adios (compfile, "unable to rename comp draft %s to", buffer);
    }

    /* Rename output file to take its place */
    if (rename (outfile, compfile) == NOTOK) {
	advise (outfile, "unable to rename output %s to", compfile);
	rename (buffer, compfile);
	done (1);
    }
    unlink_outfile = 0;

    free_content (ct);
    done (0);
    return 1;
}
Esempio n. 27
0
int main(int argc, char* argv[]) {
	int rc;
	struct sockaddr_in laddr;
	struct sockaddr_in ssladdr;
	struct sockaddr_in caddr;
	unsigned int caddrsize;
	int lsock = 0, csock, sslsock = 0;
	pthread_t tid;
	pthread_attr_t tattr;
	fd_set fds;
	fd_set rfds;
	
	#ifdef GNUTLS
	gnutlsinit();
	#endif

	readconfig(&laddr, &ssladdr);
	
	#ifdef GNUTLS
	gnutlspostinit();
	#endif
	
	siginterrupt(SIGINT, 1);
	siginterrupt(SIGTERM, 1);
	signal(SIGINT, sighandle);
	signal(SIGTERM, sighandle);
	
	if (laddr.sin_port) {
		lsock = socket(AF_INET, SOCK_STREAM, 0);
		if (!lsock) { perror("Could not open listen socket"); return 2; }
	
		rc = 1;
		setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof(int));
	
		rc = bind(lsock, (struct sockaddr*)&laddr, sizeof(laddr));
		if (rc) { perror("Could not bind to port"); return 2; }
	
		listen(lsock, 32);
	}
	
	#if defined(GNUTLS) || defined(OPENSSL)
	if (ssladdr.sin_port) {
		sslsock = socket(AF_INET, SOCK_STREAM, 0);
		if (!sslsock) { perror("Could not open SSL socket"); return 2; }
	
		rc = 1;
		setsockopt(sslsock, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof(int));
	
		rc = bind(sslsock, (struct sockaddr*)&ssladdr, sizeof(ssladdr));
		if (rc) { perror("Could not bind to SSL port"); return 2; }
	
		listen(sslsock, 32);
	}
	#endif
	
	pthread_attr_init(&tattr);
	/*For some reason I'm getting undefined reference on this?
	pthread_attr_setdetatchstate(&tattr, PTHREAD_CREATE_DETACHED);*/
	rc = pthread_attr_setstacksize(&tattr, PTHREAD_STACK_MIN);
	if (rc) fprintf(stderr, "Could not set thread stacksize, using default.\n");
	
	printf("Ready.\n");
	#ifdef DAEMON
	daemon(0, 0);
	#endif

	FD_ZERO(&fds);
	if (lsock) FD_SET(lsock, &fds);
	if (sslsock) FD_SET(sslsock, &fds);

	while (exitflag == 0) {
		caddrsize = sizeof(caddr);
		
		rfds = fds;
		rc = select(FD_SETSIZE, &rfds, NULL, NULL, NULL);
		if (rc < 0) { log("select() returned %d: %m\n", rc); break; }
		
		if (FD_ISSET(lsock, &rfds)) {
			csock = accept(lsock, (struct sockaddr*)&caddr, &caddrsize);
			if (csock <= 0) {
				log("accept() returned %d: %m\n", csock);
				break;
			}
		
			log("[%d] New connection from %s:%hu\n", 
				csock, inet_ntoa(caddr.sin_addr), ntohs(caddr.sin_port));
		
			pthread_create(&tid, NULL, connthread, (void*)(long)csock);
			pthread_detach(tid);
		}
		#ifdef GNUTLS
		if (FD_ISSET(sslsock, &rfds)) {
			csock = accept(sslsock, (struct sockaddr*)&caddr, &caddrsize);
			if (csock <= 0) {
				log("accept() returned %d: %m\n", csock);
				break;
			}
		
			log("[%d] New SSL connection from %s:%hu\n", 
				csock, inet_ntoa(caddr.sin_addr), ntohs(caddr.sin_port));
		
			pthread_create(&tid, NULL, gnutlsthread, (void*)(long)csock);
			pthread_detach(tid);		
		}
		#endif
	}
	
	if (lsock) close(lsock);
	if (sslsock) close(sslsock);
	
	log("Waiting for all threads to exit.\n");
	while (running > 0 && exitflag == 1) {
		log("Waiting... %d thread%s left.\n", running, running == 1 ? "" : "s");
		sleep(1);
	}
	
	#ifdef GNUTLS
	gnutls_global_deinit();
	#endif
	
	log("Exiting.\n");
	return 0;
}
Esempio n. 28
0
int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) {
  adns_state ads;
  const char *res_options, *adns_res_options;
  int r;
#ifdef ADNS_JGAA_WIN32
  #define SECURE_PATH_LEN (MAX_PATH - 64)
  char PathBuf[MAX_PATH];
  struct in_addr addr;
  #define ADNS_PFIXED_INFO_BLEN (2048)
  PFIXED_INFO network_info = (PFIXED_INFO)alloca(ADNS_PFIXED_INFO_BLEN);
  ULONG network_info_blen = ADNS_PFIXED_INFO_BLEN;
  DWORD network_info_result;
  PIP_ADDR_STRING pip;
  const char *network_err_str = "";
#endif
  
  r= init_begin(&ads, flags, diagfile ? diagfile : stderr);
  if (r) return r;
  
  res_options= instrum_getenv(ads,"RES_OPTIONS");
  adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS");
  ccf_options(ads,"RES_OPTIONS",-1,res_options);
  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);

#ifdef ADNS_JGAA_WIN32
  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
  strcat(PathBuf,"\\resolv.conf");
  readconfig(ads,PathBuf,1);
  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
  strcat(PathBuf,"\\resolv-adns.conf");
  readconfig(ads,PathBuf,0);
  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
  strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv.conf");
  readconfig(ads,PathBuf,1);
  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
  strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv-adns.conf");
  readconfig(ads,PathBuf,0);
  network_info_result = GetNetworkParams(network_info, &network_info_blen);
  if (network_info_result != ERROR_SUCCESS){
    switch(network_info_result) {
    case ERROR_BUFFER_OVERFLOW: network_err_str = "ERROR_BUFFER_OVERFLOW"; break;
    case ERROR_INVALID_PARAMETER: network_err_str = "ERROR_INVALID_PARAMETER"; break;
    case ERROR_NO_DATA: network_err_str = "ERROR_NO_DATA"; break;
    case ERROR_NOT_SUPPORTED: network_err_str = "ERROR_NOT_SUPPORTED"; break;}
    adns__diag(ads,-1,0,"GetNetworkParams() failed with error [%d] %s",
      network_info_result,network_err_str);
    }
  else {
    for(pip = &(network_info->DnsServerList); pip; pip = pip->Next) {
      addr.s_addr = inet_addr(pip->IpAddress.String);
      if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE))
        addserver(ads, addr); 
    }
  }
#else
  readconfig(ads,"/etc/resolv.conf",1);
  readconfig(ads,"/etc/resolv-adns.conf",0);
#endif

  readconfigenv(ads,"RES_CONF");
  readconfigenv(ads,"ADNS_RES_CONF");

  readconfigenvtext(ads,"RES_CONF_TEXT");
  readconfigenvtext(ads,"ADNS_RES_CONF_TEXT");

  ccf_options(ads,"RES_OPTIONS",-1,res_options);
  ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);

  ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN"));
  ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN"));

  if (ads->configerrno && ads->configerrno != EINVAL) {
    r= ads->configerrno;
    init_abort(ads);
    return r;
  }

  r= init_finish(ads);
  if (r) return r;

  adns__consistency(ads,0,cc_entex);
  *ads_r= ads;
  return 0;
}
Esempio n. 29
0
File: mhstore.c Progetto: dscho/nmh
int
main (int argc, char **argv)
{
    int msgnum, *icachesw;
    char *cp, *file = NULL, *outfile = NULL, *folder = NULL;
    char *maildir, buf[100], **argp;
    char **arguments;
    struct msgs_array msgs = { 0, 0, NULL };
    struct msgs *mp = NULL;
    CT ct, *ctp;
    FILE *fp;

    if (nmh_init(argv[0], 1)) { return 1; }

    done=freects_done;

    arguments = getarguments (invo_name, argc, argv, 1);
    argp = arguments;

    /*
     * Parse arguments
     */
    while ((cp = *argp++)) {
	if (*cp == '-') {
	    switch (smatch (++cp, switches)) {
	    case AMBIGSW: 
		ambigsw (cp, switches);
		done (1);
	    case UNKWNSW: 
		adios (NULL, "-%s unknown", cp);

	    case HELPSW: 
		snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
			invo_name);
		print_help (buf, switches, 1);
		done (0);
	    case VERSIONSW:
		print_version(invo_name);
		done (0);

	    case AUTOSW:
		autosw++;
		continue;
	    case NAUTOSW:
		autosw = 0;
		continue;

	    case RCACHESW:
		icachesw = &rcachesw;
		goto do_cache;
	    case WCACHESW:
		icachesw = &wcachesw;
do_cache:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		switch (*icachesw = smatch (cp, caches)) {
		case AMBIGSW:
		    ambigsw (cp, caches);
		    done (1);
		case UNKWNSW:
		    adios (NULL, "%s unknown", cp);
		default:
		    break;
		}
		continue;

	    case CHECKSW:
		checksw++;
		continue;
	    case NCHECKSW:
		checksw = 0;
		continue;

	    case PARTSW:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		if (npart >= NPARTS)
		    adios (NULL, "too many parts (starting with %s), %d max",
			   cp, NPARTS);
		parts[npart++] = cp;
		continue;

	    case TYPESW:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
		if (ntype >= NTYPES)
		    adios (NULL, "too many types (starting with %s), %d max",
			   cp, NTYPES);
		types[ntype++] = cp;
		continue;

	    case FILESW:
		if (!(cp = *argp++) || (*cp == '-' && cp[1]))
		    adios (NULL, "missing argument to %s", argp[-2]);
		file = *cp == '-' ? cp : path (cp, TFILE);
		continue;

	    case OUTFILESW:
		if (!(cp = *argp++) || (*cp == '-' && cp[1]))
		    adios (NULL, "missing argument to %s", argp[-2]);
		outfile = *cp == '-' ? cp : path (cp, TFILE);
		continue;

	    case VERBSW: 
		verbosw = 1;
		continue;
	    case NVERBSW: 
		verbosw = 0;
		continue;
            case CLOBBERSW:
		if (!(cp = *argp++) || *cp == '-')
		    adios (NULL, "missing argument to %s", argp[-2]);
                if (save_clobber_policy (cp)) {
                  adios (NULL, "invalid argument, %s, to %s", argp[-1],
                         argp[-2]);
                }
		continue;
	    case DEBUGSW:
		debugsw = 1;
		continue;
	    }
	}
	if (*cp == '+' || *cp == '@') {
	    if (folder)
		adios (NULL, "only one folder at a time!");
	    else
		folder = pluspath (cp);
	} else
		app_msgarg(&msgs, cp);
    }

    /* null terminate the list of acceptable parts/types */
    parts[npart] = NULL;
    types[ntype] = NULL;

    /*
     * Check if we've specified an additional profile
     */
    if ((cp = getenv ("MHSTORE"))) {
	if ((fp = fopen (cp, "r"))) {
	    readconfig ((struct node **) 0, fp, cp, 0);
	    fclose (fp);
	} else {
	    admonish ("", "unable to read $MHSTORE profile (%s)", cp);
	}
    }

    /*
     * Read the standard profile setup
     */
    if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) {
	readconfig ((struct node **) 0, fp, cp, 0);
	fclose (fp);
    }

    /* Check for public cache location */
    if ((cache_public = context_find (nmhcache)) && *cache_public != '/')
	cache_public = NULL;

    /* Check for private cache location */
    if (!(cache_private = context_find (nmhprivcache)))
	cache_private = ".cache";
    cache_private = getcpy (m_maildir (cache_private));

    /*
     * Cache the current directory before we do any chdirs()'s.
     */
    cwd = getcpy (pwd());

    if (!context_find ("path"))
	free (path ("./", TFOLDER));

    if (file && msgs.size)
	adios (NULL, "cannot specify msg and file at same time!");

    /*
     * check if message is coming from file
     */
    if (file) {
	if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts))))
	    adios (NULL, "out of memory");
	ctp = cts;

	if ((ct = parse_mime (file))) {
	    *ctp++ = ct;
	    if (outfile) {
		ct->c_storage = outfile;
	    }
        }
    } else {
	/*
	 * message(s) are coming from a folder
	 */
	if (!msgs.size)
	    app_msgarg(&msgs, "cur");
	if (!folder)
	    folder = getfolder (1);
	maildir = m_maildir (folder);

	if (chdir (maildir) == NOTOK)
	    adios (maildir, "unable to change directory to");

	/* read folder and create message structure */
	if (!(mp = folder_read (folder, 1)))
	    adios (NULL, "unable to read folder %s", folder);

	/* check for empty folder */
	if (mp->nummsg == 0)
	    adios (NULL, "no messages in %s", folder);

	/* parse all the message ranges/sequences and set SELECTED */
	for (msgnum = 0; msgnum < msgs.size; msgnum++)
	    if (!m_convert (mp, msgs.msgs[msgnum]))
		done (1);
	seq_setprev (mp);	/* set the previous-sequence */

	if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts))))
	    adios (NULL, "out of memory");
	ctp = cts;

	for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
	    if (is_selected(mp, msgnum)) {
		char *msgnam;

		msgnam = m_name (msgnum);
		if ((ct = parse_mime (msgnam))) {
		    *ctp++ = ct;
		    if (outfile) {
			ct->c_storage = add (outfile, NULL);
		    }
                }
	    }
	}
    }

    if (!*cts)
	done (1);

    userrs = 1;
    SIGNAL (SIGQUIT, quitser);
    SIGNAL (SIGPIPE, pipeser);

    /*
     * Get the associated umask for the relevant contents.
     */
    for (ctp = cts; *ctp; ctp++) {
	struct stat st;

	ct = *ctp;
	if (type_ok (ct, 1) && !ct->c_umask) {
	    if (stat (ct->c_file, &st) != NOTOK)
		ct->c_umask = ~(st.st_mode & 0777);
	    else
		ct->c_umask = ~m_gmprot();
	}
    }

    /*
     * Store the message content
     */
    store_all_messages (cts);

    /* Now free all the structures for the content */
    for (ctp = cts; *ctp; ctp++)
	free_content (*ctp);

    free ((char *) cts);
    cts = NULL;

    /* If reading from a folder, do some updating */
    if (mp) {
	context_replace (pfolder, folder);/* update current folder  */
	seq_setcur (mp, mp->hghsel);	  /* update current message */
	seq_save (mp);			  /* synchronize sequences  */
	context_save ();		  /* save the context file  */
    }

    done (files_not_clobbered);
    return 1;
}
Esempio n. 30
0
int
main(int argc, char *argv[])
{
    char *ptr;
    char option;
    struct stat st;
    char *conffile = NULL;
    const char *const myname = "rnews";

    ln_log_open(myname);
    if (!initvars(argv[0], 0))
	init_failed(myname);

    while ((option = getopt(argc, argv, GLOBALOPTS "")) != -1) {
	if (parseopt(myname, option, optarg, &conffile))
	    continue;
	switch(option) {
	    default:
		usage();
		exit(EXIT_FAILURE);
	}
    }

    if (readconfig(conffile) != 0) {
	ln_log(LNLOG_SERR, LNLOG_CTOP, "Reading configuration failed: %m.\n");
	exit(2);
    }
    if (conffile)
	free(conffile);

    if (filterfile && !readfilter(filterfile)) {
	ln_log(LNLOG_SERR, LNLOG_CTOP,
		"%s: Cannot read filterfile %s, aborting.",
		argv[0], filterfile);
	log_unlink(lockfile, 0);
	exit(EXIT_FAILURE);
    }

    if (!init_post())
	init_failed(myname);

    umask((mode_t) 077);

    if (attempt_lock(LOCKWAIT)) {
	exit(EXIT_FAILURE);
    }

    rereadactive();
    readlocalgroups();
    if (!argv[optind])
	fprocessfile(stdin);	/* process stdin */
    while ((ptr = argv[optind++])) {
	if (stat(ptr, &st) == 0) {
	    if (S_ISDIR(st.st_mode))
		processdir(ptr);
	    else if (S_ISREG(st.st_mode))
		processfile(ptr);
	    else
		ln_log(LNLOG_SERR, LNLOG_CTOP,
		       "%s: cannot open %s\n", argv[0], ptr);
	} else
	    ln_log(LNLOG_SERR, LNLOG_CTOP,
		   "%s: cannot stat %s\n", argv[0], ptr);
    }
    writeactive();		/* write groupinfo file */
    freeallfilter(filter);
    log_unlink(lockfile, 0);
    exit(0);
}