コード例 #1
0
ファイル: knockd.c プロジェクト: bhuvi8/knock
void reload(int signum)
{
	PMList *lp;
	opendoor_t *door;

	vprint("Re-reading config file: %s\n", o_cfg);
	logprint("Re-reading config file: %s\n", o_cfg);

	for(lp = doors; lp; lp = lp->next) {
		door = (opendoor_t*)lp->data;
		close_door(door);
	}
	list_free(doors);

	parseconfig(o_cfg);

	vprint("Closing and re-opening log file: %s\n", o_logfile);
	logprint("Closing and re-opening log file: %s\n", o_logfile);

	/* close and re-open the log file */
	if(logfd) {
		fclose(logfd);
	}
	logfd = fopen(o_logfile, "a");
	if(logfd == NULL) {
		perror("warning: cannot open logfile");
	}

	return;
}
コード例 #2
0
static void
restart ()
{
  if (hup_lock)
    return;
  hup_lock = true;

  warn ("version %s, pid %d, restarted with SIGHUP\n", VERSION,
	int (getpid ()));
  server *s, *ns;
  for (s = serverlist.first; s; s = ns) {
    ns = serverlist.next (s);
    serverlist.remove (s);
    delete s;
  }
  for (sfssrv *nsp, *sp = services.first; sp; sp = nsp) {
    nsp = services.next (sp);
    delete sp;
  }

  for (sockaddr **sap = listenaddrs.base (); sap < listenaddrs.lim (); sap++)
    xfree (*sap);
  listenaddrs.clear ();
  listeners.clear ();

  parseconfig ();
  delaycb (0, 100000000, wrap (launchservers));
}
コード例 #3
0
ファイル: constellation.c プロジェクト: neg/yastg
int loadconstellations()
{
    struct config *ctree, *e;
    unsigned int ncons = 0;

    ctree = parseconfig("data/constellations");
    e = ctree->sub;

    if (!e->next)
        die("%s contained no useful data", e->key);

    e = e->next;

    while ((e) && (ncons < CONSTELLATION_MAXNUM)) {
        printf("Adding constellation %s\n", e->key);
        if (addconstellation(e->key))
            goto err;

        e = e->next;
        ncons++;
    }

    destroyctree(ctree);
    return 0;

err:
    destroyctree(ctree);
    return -1;
}
コード例 #4
0
ファイル: xfdfgen.c プロジェクト: HopsSplurt/Scaliger
int main(int argc, char *argv[])
{
    char * fconfname;
    int parseresult;

    fout = stdout; // Use stdout as default output stream

    if(argc == 2) {
        // Single argument is taken as configuration file name
        fconfname = argv[1];
        fconf = fopen(fconfname, "r");
        if(fconf == NULL) {
            fprintf(stderr, "Configuration file not found: %s\n", fconfname);
            perror(NULL);
            exit(1);
        }
        if(feof(fconf)) {
            fprintf(stderr, "Configuration file is empty: %s\n", fconfname);
        }
        parseresult = parseconfig(fconfname);
        fclose(fconf);
        if(parseresult != 0) {
            exit(parseresult);
        }
    }
    outfile();
    return 0;
}
コード例 #5
0
ファイル: lessfsck.c プロジェクト: crass/lessfs
int main(int argc, char *argv[])
{
    char *dbg = NULL;
#ifdef ENABLE_CRYPTO
    int rnd;
    char *ckpasswd;
    char *p;
#endif
    if (argc < 2)
        usage(argv[0]);

    debug=0;
    setvbuf(stdout, (char*)NULL, _IONBF, 0);
    get_opts(argc,argv);
    if ( NULL == chkoptions.configfile ) {
        usage(argv[0]);
    }
    if (-1 == r_env_cfg(chkoptions.configfile))
        usage(argv[0]);
    parseconfig(0);
    dbg = getenv("DEBUG");
    if (NULL != dbg)
        debug = atoi(dbg);

    if ( 0 == chkoptions.fast ) {
       printf("Running lessfsck on a mounted filesystem will corrupt the databases.\n");
       printf("Press ctrl-c within 5 secondes when you are not sure that the filesystem is unmounted.\n");
       sleep(5);
    }
    BLKSIZE=get_blocksize();
    if ( NULL != config->blockdatabs ){
       printf("**************************************************\n");
       printf("* Running lessfsck on a tc data store.           *\n");
       printf("**************************************************\n");
       lessfsck_tc();
    } else {
       printf("**************************************************\n");
       printf("* Running lessfsck on a file_io data store.      *\n");
       printf("**************************************************\n");
       lessfsck_file_io();
    }
    printf("\nDone.\n");
    clear_dirty();
    tc_close(0);
#ifdef ENABLE_CRYPTO
    if (config->encryptdata) {
        free(config->passwd);
        free(config->iv);
    }
#endif
    free(config);
    exit(0);
}
コード例 #6
0
int
main (int argc, char **argv)
{
  bool opt_nodaemon = false;
  setprogname (argv[0]);

  int ch;
  while ((ch = getopt (argc, argv, "df:S:")) != -1)
    switch (ch) {
    case 'd':
      opt_nodaemon = true;
      break;
    case 'f':
      if (configfile)
	usage ();
      configfile = optarg;
      break;
    case 'S':
      {
	str sfsconf (strbuf ("SFS_CONFIG=%s", optarg));
	xputenv (const_cast<char*>(sfsconf.cstr()));
      }
    case '?':
    default:
      usage ();
    }
  argc -= optind;
  argv += optind;
  if (argc > 1)
    usage ();

  sfsconst_init ();
  if (!configfile)
    configfile = sfsconst_etcfile_required ("sfssd_config");

  parseconfig ();
  if (!revocationdir)
    revocationdir = sfsdir << "srvrevoke";
  if (!opt_nodaemon && !builddir) {
    daemonize ();
    sigcb (SIGINT, wrap (termsig, SIGINT));
    sigcb (SIGTERM, wrap (termsig, SIGTERM));
  }
  warn ("version %s, pid %d\n", VERSION, int (getpid ()));
  sigcb (SIGHUP, wrap (restart));
  launchservers ();

  amain ();
}
コード例 #7
0
ファイル: knockd.c プロジェクト: airwoflgh/knock
void reload(int signum)
{
	PMList *lp;
	opendoor_t *door;
	int res_cfg;

	vprint("Re-reading config file: %s\n", o_cfg);
	logprint("Re-reading config file: %s\n", o_cfg);

	for(lp = doors; lp; lp = lp->next) {
		door = (opendoor_t*)lp->data;
		close_door(door);
	}
	list_free(doors);

	res_cfg = parseconfig(o_cfg);

	vprint("Closing log file: %s\n", o_logfile);
	logprint("Closing log file: %s\n", o_logfile);

	/* close the log file */
	if(logfd) {
		fclose(logfd);
	}

	if(res_cfg) {
		exit(1);
	}

	vprint("Re-opening log file: %s\n", o_logfile);
	logprint("Re-opening log file: %s\n", o_logfile);

	/* re-open the log file */
	logfd = fopen(o_logfile, "a");
	if(logfd == NULL) {
		perror("warning: cannot open logfile");
	}

	/* Fix issue #2 by regenerating the PCAP filter post config file re-read */
	generate_pcap_filter();

	return;
}
コード例 #8
0
ファイル: doas.c プロジェクト: ajinkya93/OpenBSD
static void __dead
checkconfig(const char *confpath, int argc, char **argv,
    uid_t uid, gid_t *groups, int ngroups, uid_t target)
{
	struct rule *rule;

	setresuid(uid, uid, uid);
	parseconfig(confpath, 0);
	if (!argc)
		exit(0);

	if (permit(uid, groups, ngroups, &rule, target, argv[0],
	    (const char **)argv + 1)) {
		printf("permit%s\n", (rule->options & NOPASS) ? " nopass" : "");
		exit(0);
	} else {
		printf("deny\n");
		exit(1);
	}
}
コード例 #9
0
ファイル: sfsconst.C プロジェクト: okws/sfslite
void
sfsconst_init (bool lite_mode)
{
  if (const_set)
    return;
  const_set = true;

  {
    char *p = safegetenv ("SFS_RELEASE");
    if (!p || !convertint (p, &sfs_release)) {
      str rel (strbuf () << "SFS_RELEASE=" << sfs_release);
      xputenv (const_cast<char*>(rel.cstr()));
    }
  }

#ifdef MAINTAINER
  if (char *p = safegetenv ("SFS_RUNINPLACE")) {
    runinplace = true;
    builddir = p;
    buildtmpdir = builddir << "/runinplace";
  }
  if (char *p = safegetenv ("SFS_ROOT"))
    if (*p == '/')
      sfsroot = p;
#endif /* MAINTAINER */
  sfsdevdb = strbuf ("%s/.devdb", sfsroot);

#ifdef MAINTAINER
  if (runinplace) {
    sfsdir = buildtmpdir;
    sfssockdir = sfsdir;
    etc3dir = etc1dir;
    etc1dir = sfsdir.cstr();
    etc2dir = xstrdup (str (builddir << "/etc"));
  }
#endif /* MAINTAINER */
  if (char *ps = safegetenv ("SFS_PORT"))
    if (int pv = atoi (ps))
      sfs_defport = pv;

  str sfs_config = safegetenv ("SFS_CONFIG");
  if (sfs_config && sfs_config[0] == '/') {
    if (!parseconfig (NULL, sfs_config))
      fatal << sfs_config << ": " << strerror (errno) << "\n";
  }
  else {
    if (!parseconfig (etc3dir, sfs_config)) {
      parseconfig (etc3dir, "sfs_config");
      if (!parseconfig (etc2dir, sfs_config)) {
	parseconfig (etc2dir, "sfs_config");
	if (!parseconfig (etc1dir, sfs_config)) 
	  parseconfig (etc1dir, "sfs_config");
      }
    }
  }

  if (!lite_mode) {
    if (!sfs_uid)
      idlookup (NULL, NULL);
  }

  if (char *p = getenv ("SFS_HASHCOST")) {
    sfs_hashcost = strtoi64 (p);
    if (sfs_hashcost > sfs_maxhashcost)
      sfs_hashcost = sfs_maxhashcost;
  }

  if (!getuid () && !runinplace) {
    mksfsdir (sfsdir, 0755);
    mksfsdir (sfssockdir, 0750);
  }
  else if (runinplace && access (sfsdir, 0) < 0) {
    struct stat sb;
    if (!stat (builddir, &sb)) {
      mode_t m = umask (0);
      if (!getuid ()) {
	if (pid_t pid = fork ())
	  waitpid (pid, NULL, 0);
	else {
	  umask (0);
	  setgid (sfs_gid);
	  setuid (sb.st_uid);
	  if (mkdir (sfsdir, 02770) >= 0)
	    rc_ignore (chown (sfsdir, (uid_t) -1, sfs_gid));
	  _exit (0);
	}
      }
      else
	mkdir (sfsdir, 0777);
      umask (m);
    }
  }
}
コード例 #10
0
ファイル: doas.c プロジェクト: ajinkya93/OpenBSD
int
main(int argc, char **argv, char **envp)
{
	const char *safepath = "/bin:/sbin:/usr/bin:/usr/sbin:"
	    "/usr/local/bin:/usr/local/sbin";
	const char *confpath = NULL;
	char *shargv[] = { NULL, NULL };
	char *sh;
	const char *cmd;
	char cmdline[LINE_MAX];
	char myname[_PW_NAME_LEN + 1];
	struct passwd *pw;
	struct rule *rule;
	uid_t uid;
	uid_t target = 0;
	gid_t groups[NGROUPS_MAX + 1];
	int ngroups;
	int i, ch;
	int sflag = 0;
	int nflag = 0;
	char cwdpath[PATH_MAX];
	const char *cwd;

	closefrom(STDERR_FILENO + 1);

	uid = getuid();

	while ((ch = getopt(argc, argv, "C:nsu:")) != -1) {
		switch (ch) {
		case 'C':
			confpath = optarg;
			break;
		case 'u':
			if (parseuid(optarg, &target) != 0)
				errx(1, "unknown user");
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		default:
			usage();
			break;
		}
	}
	argv += optind;
	argc -= optind;

	if (confpath) {
		if (sflag)
			usage();
	} else if ((!sflag && !argc) || (sflag && argc))
		usage();

	pw = getpwuid(uid);
	if (!pw)
		err(1, "getpwuid failed");
	if (strlcpy(myname, pw->pw_name, sizeof(myname)) >= sizeof(myname))
		errx(1, "pw_name too long");
	ngroups = getgroups(NGROUPS_MAX, groups);
	if (ngroups == -1)
		err(1, "can't get groups");
	groups[ngroups++] = getgid();

	if (sflag) {
		sh = getenv("SHELL");
		if (sh == NULL || *sh == '\0')
			shargv[0] = pw->pw_shell;
		else
			shargv[0] = sh;
		argv = shargv;
		argc = 1;
	}

	if (confpath) {
		checkconfig(confpath, argc, argv, uid, groups, ngroups,
		    target);
		exit(1);	/* fail safe */
	}

	parseconfig("/etc/doas.conf", 1);

	/* cmdline is used only for logging, no need to abort on truncate */
	(void) strlcpy(cmdline, argv[0], sizeof(cmdline));
	for (i = 1; i < argc; i++) {
		if (strlcat(cmdline, " ", sizeof(cmdline)) >= sizeof(cmdline))
			break;
		if (strlcat(cmdline, argv[i], sizeof(cmdline)) >= sizeof(cmdline))
			break;
	}

	cmd = argv[0];
	if (!permit(uid, groups, ngroups, &rule, target, cmd,
	    (const char**)argv + 1)) {
		syslog(LOG_AUTHPRIV | LOG_NOTICE,
		    "failed command for %s: %s", myname, cmdline);
		errc(1, EPERM, NULL);
	}

	if (!(rule->options & NOPASS)) {
		if (nflag)
			errx(1, "Authorization required");
		if (!auth_userokay(myname, NULL, "auth-doas", NULL)) {
			syslog(LOG_AUTHPRIV | LOG_NOTICE,
			    "failed password for %s", myname);
			errc(1, EPERM, NULL);
		}
	}
	envp = copyenv((const char **)envp, rule);

	pw = getpwuid(target);
	if (!pw)
		errx(1, "no passwd entry for target");
	if (setusercontext(NULL, pw, target, LOGIN_SETGROUP |
	    LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
	    LOGIN_SETUSER) != 0)
		errx(1, "failed to set user context for target");

	if (getcwd(cwdpath, sizeof(cwdpath)) == NULL)
		cwd = "(failed)";
	else
		cwd = cwdpath;

	syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
	    myname, cmdline, pw->pw_name, cwd);

	if (rule->cmd) {
		if (setenv("PATH", safepath, 1) == -1)
			err(1, "failed to set PATH '%s'", safepath);
	}
	execvpe(cmd, argv, envp);
	if (errno == ENOENT)
		errx(1, "%s: command not found", cmd);
	err(1, "%s", cmd);
}
コード例 #11
0
ファイル: doas.c プロジェクト: slicer69/doas
int
main(int argc, char **argv)
{
	const char *safepath = "/bin:/sbin:/usr/bin:/usr/sbin:"
	    "/usr/local/bin:/usr/local/sbin";
	const char *confpath = NULL;
	char *shargv[] = { NULL, NULL };
	char *sh;
	const char *cmd;
	char cmdline[LINE_MAX];
	char myname[_PW_NAME_LEN + 1];
	struct passwd *pw;
	struct rule *rule;
	uid_t uid;
	uid_t target = 0;
	gid_t groups[NGROUPS_MAX + 1];
	int ngroups;
	int i, ch;
	int sflag = 0;
	int nflag = 0;
	char cwdpath[PATH_MAX];
	const char *cwd;
	char *login_style = NULL;
	char **envp;

        #ifndef linux
	setprogname("doas");
        #endif

        #ifndef linux
	closefrom(STDERR_FILENO + 1);
        #endif

	uid = getuid();

	while ((ch = getopt(argc, argv, "a:C:nsu:")) != -1) {
/*	while ((ch = getopt(argc, argv, "a:C:Lnsu:")) != -1) { */
		switch (ch) {
		case 'a':
			login_style = optarg;
			break;
		case 'C':
			confpath = optarg;
			break;
/*		case 'L':
			i = open("/dev/tty", O_RDWR);
			if (i != -1)
				ioctl(i, TIOCCLRVERAUTH);
			exit(i != -1);
*/
		case 'u':
			if (parseuid(optarg, &target) != 0)
				errx(1, "unknown user");
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		default:
			usage();
			break;
		}
	}
	argv += optind;
	argc -= optind;

	if (confpath) {
		if (sflag)
			usage();
	} else if ((!sflag && !argc) || (sflag && argc))
		usage();

	pw = getpwuid(uid);
	if (!pw)
		err(1, "getpwuid failed");
	if (strlcpy(myname, pw->pw_name, sizeof(myname)) >= sizeof(myname))
		errx(1, "pw_name too long");

	ngroups = getgroups(NGROUPS_MAX, groups);
	if (ngroups == -1)
		err(1, "can't get groups");
	groups[ngroups++] = getgid();

	if (sflag) {
		sh = getenv("SHELL");
		if (sh == NULL || *sh == '\0') {
			shargv[0] = strdup(pw->pw_shell);
			if (shargv[0] == NULL)
				err(1, NULL);
		} else
			shargv[0] = sh;
		argv = shargv;
		argc = 1;
	}

	if (confpath) {
		checkconfig(confpath, argc, argv, uid, groups, ngroups,
		    target);
		exit(1);	/* fail safe */
	}

	if (geteuid())
		errx(1, "not installed setuid");

	parseconfig(DOAS_CONF, 1);

	/* cmdline is used only for logging, no need to abort on truncate */
	(void)strlcpy(cmdline, argv[0], sizeof(cmdline));
	for (i = 1; i < argc; i++) {
		if (strlcat(cmdline, " ", sizeof(cmdline)) >= sizeof(cmdline))
			break;
		if (strlcat(cmdline, argv[i], sizeof(cmdline)) >= sizeof(cmdline))
			break;
	}

	cmd = argv[0];
	if (!permit(uid, groups, ngroups, &rule, target, cmd,
	    (const char **)argv + 1)) {
		syslog(LOG_AUTHPRIV | LOG_NOTICE,
		    "failed command for %s: %s", myname, cmdline);
		errc(1, EPERM, NULL);
	}

	if (!(rule->options & NOPASS)) {
		if (nflag)
			errx(1, "Authorization required");

#if defined(USE_BSD_AUTH) 
		authuser(myname, login_style, rule->options & PERSIST);
#elif defined(USE_PAM)
#define PAM_END(msg) do { 						\
	syslog(LOG_ERR, "%s: %s", msg, pam_strerror(pamh, pam_err)); 	\
	warnx("%s: %s", msg, pam_strerror(pamh, pam_err));		\
	pam_end(pamh, pam_err);						\
	exit(EXIT_FAILURE);						\
} while (/*CONSTCOND*/0)
		pam_handle_t *pamh = NULL;
		int pam_err;

/* #ifndef linux */
		int temp_stdin;

		/* openpam_ttyconv checks if stdin is a terminal and
		 * if it is then does not bother to open /dev/tty.
		 * The result is that PAM writes the password prompt
		 * directly to stdout.  In scenarios where stdin is a
		 * terminal, but stdout is redirected to a file
		 * e.g. by running doas ls &> ls.out interactively,
		 * the password prompt gets written to ls.out as well.
		 * By closing stdin first we forces PAM to read/write
		 * to/from the terminal directly.  We restore stdin
		 * after authenticating. */
		temp_stdin = dup(STDIN_FILENO);
		if (temp_stdin == -1)
			err(1, "dup");
		close(STDIN_FILENO);
/* #else */
		/* force password prompt to display on stderr, not stdout */
		int temp_stdout = dup(1);
		if (temp_stdout == -1)
			err(1, "dup");
		close(1);
		if (dup2(2, 1) == -1)
			err(1, "dup2");
/* #endif */

		pam_err = pam_start("doas", myname, &pamc, &pamh);
		if (pam_err != PAM_SUCCESS) {
			if (pamh != NULL)
				PAM_END("pam_start");
			syslog(LOG_ERR, "pam_start failed: %s",
			    pam_strerror(pamh, pam_err));
			errx(EXIT_FAILURE, "pam_start failed");
		}

		switch (pam_err = pam_authenticate(pamh, PAM_SILENT)) {
		case PAM_SUCCESS:
			switch (pam_err = pam_acct_mgmt(pamh, PAM_SILENT)) {
			case PAM_SUCCESS:
				break;

			case PAM_NEW_AUTHTOK_REQD:
				pam_err = pam_chauthtok(pamh,
				    PAM_SILENT|PAM_CHANGE_EXPIRED_AUTHTOK);
				if (pam_err != PAM_SUCCESS)
					PAM_END("pam_chauthtok");
				break;

			case PAM_AUTH_ERR:
			case PAM_USER_UNKNOWN:
			case PAM_MAXTRIES:
				syslog(LOG_AUTHPRIV | LOG_NOTICE,
				    "failed auth for %s", myname);
                                errx(EXIT_FAILURE, "second authentication failed");
				break;

			default:
				PAM_END("pam_acct_mgmt");
				break;
			}
			break;

		case PAM_AUTH_ERR:
		case PAM_USER_UNKNOWN:
		case PAM_MAXTRIES:
			syslog(LOG_AUTHPRIV | LOG_NOTICE,
			    "failed auth for %s", myname);
                        errx(EXIT_FAILURE, "authentication failed");
			break;

		default:
			PAM_END("pam_authenticate");
			break;
		}
		pam_end(pamh, pam_err);

#ifndef linux
		/* Re-establish stdin */
		if (dup2(temp_stdin, STDIN_FILENO) == -1)
			err(1, "dup2");
		close(temp_stdin);
#else 
		/* Re-establish stdout */
		close(1);
		if (dup2(temp_stdout, 1) == -1)
			err(1, "dup2");
#endif 
#else
#error	No auth module!
#endif
	}

        /*
	if (pledge("stdio rpath getpw exec id", NULL) == -1)
		err(1, "pledge");
        */
	pw = getpwuid(target);
	if (!pw)
		errx(1, "no passwd entry for target");

#if defined(HAVE_LOGIN_CAP_H)
	if (setusercontext(NULL, pw, target, LOGIN_SETGROUP |
	    LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
	    LOGIN_SETUSER) != 0)
		errx(1, "failed to set user context for target");
#endif
        /*
	if (pledge("stdio rpath exec", NULL) == -1)
		err(1, "pledge");
        */

	if (getcwd(cwdpath, sizeof(cwdpath)) == NULL)
		cwd = "(failed)";
	else
		cwd = cwdpath;

	/*
        if (pledge("stdio exec", NULL) == -1)
		err(1, "pledge");
        */
#ifndef HAVE_LOGIN_CAP_H
        /* If we effectively are root, set the UID to actually be root to avoid
           permission errors. */
        if (target != 0)
           setuid(target);
        if ( geteuid() == ROOT_UID )
           setuid(ROOT_UID);
#endif

	syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
	    myname, cmdline, pw->pw_name, cwd);

	envp = prepenv(rule);

	if (rule->cmd) {
		if (setenv("PATH", safepath, 1) == -1)
			err(1, "failed to set PATH '%s'", safepath);
	}
	execvpe(cmd, argv, envp);
	if (errno == ENOENT)
		errx(1, "%s: command not found", cmd);
	err(1, "%s", cmd);
}
コード例 #12
0
ファイル: config.c プロジェクト: jrnutt/msged
void _pascal opening(char *cfgfile, char *areafile)
{
	FILE   *fp = NULL;
	int 	count = 0,i;
	char	tmp[PATHLEN];

	init();

	video_init();

	/* start looking for the config file... */

	if ((fp = fileopen("BINKLEY;OPUS;SEADOG;BBS;",cfgfile)) == NULL)
		if ((fp = fileopen("BINKLEY;OPUS;SEADOG;BBS","msged.cfg")) == NULL)
			settings();

	if (fp) {
		parseconfig(fp);
		if (videomethod != BIOS)
			video_init();
	}

	if (opusdate)
		fidozone = NO;

	for (i = 0; i < 40; i++)
		count += (macros[i] != (void *) NULL)?1:0;

	if (fp != NULL)
		fclose(fp);

	rm = (rm > maxx)?maxx:rm;
	qm = (qm > rm)?rm - 5 - strlen(quotestr):qm;

	colors.quote = (colors.quote)?colors.quote:colors.normal;

	checkareas(areafile);

	set_color(colors.normal);
	cls();
	gotoxy(6, 9);
	set_color(colors.hilite);
	bputs("msged FTS Compatible Mail Editor");
	set_color(colors.normal);
	gotoxy(6, 11);
	bputs("version " VERSION " PUBLIC DOMAIN by Jim Nutt");
	gotoxy(6,13);
	bprintf("%d by %d ",maxx,maxy);
	bputs((videomethod==DIRECT)?"direct video":(videomethod==BIOS)?"bios video":(videomethod==ANSI)?"ansi video":"fossil video");

	gotoxy(6, 15);
	bprintf("%s at %s", username, show_address(thisnode));

	if (aliascount > 1)
		bprintf(" (primary)");

	if (thisnode.point)
		bprintf(" (private net %d/%d)", pointnet,
			thisnode.point);

	if (origin != NULL) {
		gotoxy(6,16);
		bputs(origin);
		gotoxy(6,18);
	}
	else
		gotoxy(6,17);

	bprintf("%d message areas found", areas);
	gotoxy(6,wherey() + 1);
	bprintf("%d macros defined",count);
	getcwd(tmp,PATHLEN);
	if (tmp) strlwr(tmp);
	home = strdup(tmp);
	gotoxy(6,wherey() + 2);
	bprintf("home directory is %s",home);

	if (arealist == NULL) {
		puts("Oops! at least one message area must be defined.");
		puts("Exiting...");
		exit(0);
	}
}
コード例 #13
0
ファイル: config.c プロジェクト: jrnutt/msged
static void _pascal parseconfig(FILE *fp)

{
	char	buffer[TEXTLEN];
	char   *keyword = NULL;
	char   *value = NULL;
	char   *s = NULL;

	memset(buffer, 0, TEXTLEN);

	while (!feof(fp)) {

		if (fgets(buffer, TEXTLEN, fp) == NULL)
			return;

		keyword = strtok(buffer, " \t\n\r");
		if (keyword) strlwr(keyword); else continue;
		if ((*keyword) == ';')
			continue;

		value = strtok(NULL, ";\n\r");

		if (value != NULL) {
			s = value + strlen(value) - 1;
			while ((s > value) && isspace(*s))
				*s-- = '\0';
		}

		while (value && *value && isspace(*value))
			if ((*value == '\n') || (*value == ';'))
				break;
			else
				value++;

		if (strcmp("attribution", keyword) == 0) {
			free(attribline);
			if (value)
				attribline = strdup(value);
			else
				attribline = NULL;
			continue;
		}

		if (!value) continue;

		if (strcmp("name",keyword) == 0) {
			check(value);
			username = strdup(value);
			check(username);
		}

		else if (strcmp("include", keyword) == 0) {
			FILE *ifp;
			if ((ifp = fopen(value,"rt")) != NULL) {
				parseconfig(ifp);
				fclose(ifp);
			}
		}

		else if (strcmp("outfile", keyword) == 0) {
			free(outfile);
			outfile = strdup(value);
		}

		else if (strcmp("uucp", keyword) == 0) {
			uucp_gate = parsenode(value);
			uucp_gate.notfound = 0;
		}

		else if (strcmp("lastread", keyword) == 0) {
			free(lastread);
			lastread = strdup(value);
		}

		else if (strcmp("tosslog", keyword) == 0) {
			free(confmail);
			confmail = strdup(value);
		}
#ifndef NOSPELL
		else if (strcmp("speller", keyword) == 0) {
			free(speller);
			speller = strdup(value);
		}
#endif

		else if (strcmp("quickbbs", keyword) == 0) {
			int i;
			if (quickbbs != NULL)
				free(quickbbs);
			quickbbs = strdup(value);
			i = strlen(quickbbs);
			if ((*(quickbbs + i - 1) != '\\') && 
			    (*(quickbbs + i - 1) != '/')) {
				char *s = calloc(1,i+2);
				strcat(strcpy(s,quickbbs),"/");
				free(quickbbs);
				quickbbs = strdup(s);
				free(s);
			}
		}

		else if (strcmp("video",keyword) == 0) {
			if (value) strlwr(value);
			if (strncmp(value,"direct",6) == 0)
				videomethod = DIRECT;
			else if (strncmp(value,"bios",4) == 0)
				videomethod = BIOS;
			else if (strncmp(value,"fossil",6) == 0)
				videomethod = FOSSIL;
			else if (strncmp(value,"ansi",4) == 0)
				videomethod = ANSI;
		}

		else if (strcmp("gate",keyword) == 0) {
			if (gate == 7)
				gate = 0;
			if (value) strlwr(value);
			if (strncmp(value,"zones",5) == 0)
				gate |= GZONES;
			else if (strncmp(value,"domains",7) == 0)
				gate |= GDOMAINS;
			else if (strncmp(value,"both",4) == 0)
				gate = GDOMAINS | GZONES;
			else if (strncmp(value,"none",4) == 0)
				gate = 0;
		}

		else if (strcmp("function",keyword) == 0) {
			int i;
			char *s;

			i = (int) strtol(value,&s,0);
			s = striplwhite(s);

			if ((i >= 0) && (i <= 40))
				macros[i] = parse_macro(s);
		}

		else if (strcmp("userlist", keyword) == 0) {
			fidolist = strdup(strtok(value,",\n"));
			if ((userlist = strtok(NULL,",\n")) != NULL)
				userlist = strdup(userlist);
		}

		else if (strcmp("address", keyword) == 0) {
			if (alias == NULL) {
				alias = (ADDRESS *) calloc(1, sizeof(ADDRESS));
				aliascount = 1;
			}
			else
				alias = (ADDRESS *) realloc(alias,++aliascount * sizeof(ADDRESS));
			alias[aliascount - 1] = parsenode(value);
		}

		else if (strcmp("videoseg", keyword) == 0)
			vbase = (int) strtol(value,NULL,0);

		else if (strcmp("privatenet", keyword) == 0)
			pointnet = (int) strtol(value,NULL,0);

		else if (strcmp("maxx", keyword) == 0)
			maxx = (int) strtol(value,NULL,0);

		else if (strcmp("maxy", keyword) == 0)
			maxy = (int) strtol(value,NULL,0);

		else if (strcmp("tabsize", keyword) == 0)
			tabsize = (int) strtol(value,NULL,0);

		else if (strcmp("right", keyword) == 0)
			rm = (int) strtol(value,NULL,0);

		else if (strcmp("quoteright", keyword) == 0)
			qm = (int) strtol(value,NULL,0);

		else if (strcmp("no",keyword) == 0) {
			if (value) strlwr(value);
			softcr ^=		 (strcmp("softcr", value) == 0);
			seenbys ^=		 (strcmp("seen-bys", value) == 0);
			tearline ^= 	 (strcmp("tearline", value) == 0);
			shownotes ^=	 (strcmp("shownotes", value) == 0);
			confirmations ^= (strcmp("confirm", value) == 0);
			msgids ^=		 (strcmp("msgids",value) == 0);
			stripnotes ^=	 (strcmp("strip",value) == 0);
			opusdate ^=      (strcmp("opusdate",value) == 0);
			swapping ^= (strcmp("swapping",value) == 0);
		}

		else if (!(strcmp("editkey", keyword))||!(strcmp("readkey",keyword))) { /*WRA*/
			int scancode;

			if (value) {
				strlwr(value);
				scancode = (int) strtol(value,&value,0);
				value = striplwhite(value);
			}
			if (*keyword == 'e')
				e_assignkey(scancode,value);
			else
				r_assignkey(scancode,value);
		}

		else if (strcmp("quote", keyword) == 0) {
			char *s;
			if (quotestr != NULL)
				free(quotestr);
			s = quotestr = strdup(value);
			while (*s) {
				*s = (*s == (char) '_')?(char)' ':*s;
				s++;
			}
		}

		else if (strcmp("origin", keyword) == 0) {
			if (origin != NULL)
				free(origin);
			origin = strdup(value);
		}

		else if ((strcmp("quick", keyword) == 0) ||
			 (strcmp("fido", keyword) == 0)) {
			parsemail(keyword,value);
		}

		else if (strcmp("color", keyword) == 0) {
			keyword = strtok(value," \t");
			value	= strtok(NULL,"\0");
			set_colors(keyword,value);
		}

		memset(buffer, 0, TEXTLEN);
	}
}
コード例 #14
0
ファイル: main.cpp プロジェクト: M-griffin/Enthral
/**
 * Main Program
 */
int main(int argc, char **argv)
{
    TelnetDaemon daemon;

    std::string loginpath;
    std::string user;
    std::string login;
    std::string cdw = get_working_path();

    int num = 0;
    for (int i = 0; ; i++)
    {
        if (cdw[i] == '\0') break;
        if (cdw[i] == '/') num = i;
    }
    if (num != 0)
    {
        for (int i = 0; i < num+1; i++)
        {
            PATH[i] = cdw[i];
        }
    }
    else
    {
        strcpy(PATH,cdw.c_str());
    }


    // If Config Exists Run
    if (configdataexists())
    {
        parseconfig();
    }


    // Unique filename to pass to BBS for
    // Reading in Detected Client Terminal.
    daemon.make_uuid(ENTHRAL_TEMP_PATH);

    // Lookup info for the passed socket descriptor
    daemon.get_host_info();


    // Parameter for Login Program and User Login ID.
    int c = '\0';
    for (;;)
    {
        c = getopt( argc, argv, "l:u:");

        if (c == EOF) break;
        switch (c)
        {
        case 'u':
            user = strdup(optarg);
            break;
        case 'l':
            login = strdup(optarg);
            break;

        default:
            printf("%c\n", c);
            show_usage();
            exit(1);
        }
    }

    if(login.size() > 0)
    {
        loginpath = login;
        login.erase();
    }
    else
    {
        loginpath = "/bin/login";
    }

    argv_init[0] = strdup(loginpath.c_str());
    argv_init[1] = (char *)daemon.m_hostaddr_string.c_str();
    argv_init[2] = (char *)daemon.m_hostname_string.c_str();

    // Pass Login user for External Process
    if(user.size() > 0)
    {
        argv_init[3] = strdup("-f");
        argv_init[4] = strdup(user.c_str());
    }

    // Filename for passing the TERM to the external program.
    if(daemon.m_term_passing.size() > 0)
    {
        argv_init[5] = strdup(daemon.m_term_passing.c_str());
    }

    // Startup Syslogd.
    openlog("telnet_daemon", LOG_PID, LOG_SYSLOG);

    syslog(LOG_INFO, "telnet_daemon in.telnetd PATH: %s", PATH);
    daemon.errlog((char *)"telnet_daemon in.telnetd PATH: %s", PATH);

    // Log Connection
    syslog(LOG_INFO, "telnet_daemon in.telnetd [%s] [Server Path]", loginpath.c_str());
    daemon.errlog((char *)"telnet_daemon in.telnetd [%s] [Server Path]", (char *)loginpath.c_str());

    syslog(LOG_INFO, "telnet_daemon in.telnetd [IP %s] [Host %s] [Connection Logged]",
           daemon.m_hostaddr_string.c_str(),
           daemon.m_hostname_string.c_str()
          );

    daemon.errlog((char *)"telnet_daemon in.telnetd [IP %s] [Host %s] [Connection Logged]",
                  (char *)daemon.m_hostaddr_string.c_str(),
                  (char *)daemon.m_hostname_string.c_str()
                 );

    // Send Startup Telnet Sequences to connecting client.
    // Ready for Terminal / NAWS Detection and setting defaults.
    daemon.errlog((char *)"send_startup_iac");
    daemon.send_startup_iac();

    // Look intitial TELOPT codes with (2) second pause then (2) second detection loop
    // To Catch Terminal Type and NAWS.
    daemon.errlog((char *)"loop_detection");
    daemon.loop_detection();
    daemon.errlog((char *)"loop_detection completed.");

    // Display Detected Term, Rows, Cols.
    daemon.errlog((char *)"Term Type: %s", (char *)daemon.getTermType().c_str());
    daemon.errlog((char *)"Term Cols: %i", daemon.getTermCols());
    daemon.errlog((char *)"Term Rows: %i", daemon.getTermRows());


    if (daemon.getTermType() == "undetected" || daemon.getTermType() == "VT220" || daemon.getTermType() == "")
    {
        daemon.errlog((char *)"No Term Detected, Disconnecting.");
        closelog();
        exit(1);
    }

    // Terminal Type Detection completed, write out to file for extrnal program
    // So the Forked process can read it in.
    std::ofstream out;
    out.open(daemon.m_term_passing.c_str(),ios::trunc);
    if (out.is_open())
    {
        out << daemon.getTermType() << endl;
        out.close();
    }


    daemon.errlog((char *)"Starting BBS Server forkpty()");

    // If the Connection is good, fork and start the BBS
    pid = forkpty(&ptyfd, NULL, NULL, NULL);

    daemon.errlog((char *)"ptyfd: %i", ptyfd);


    // Pid 0 Start Child Process.
    if (pid == 0)
    {
        setsid();
        tcsetpgrp(0, getpid());

        // exec shell, with correct argv and env
        execv(loginpath.c_str(), argv_init);
        syslog(LOG_INFO, "child process created for [IP %s] pid == 0", daemon.m_hostaddr_string.c_str());
        daemon.errlog((char *)"child process created for [IP %s] pid == 0", (char*)daemon.m_hostaddr_string.c_str());
        exit(1);

    }
    // Pid -1 is an error
    else if(pid == -1)
    {
        syslog(LOG_INFO, "fork() Error, exiting [IP %s] pid == -1", daemon.m_hostaddr_string.c_str());
        daemon.errlog((char *)"fork() Error, exiting [IP %s] pid == -1", (char*)daemon.m_hostaddr_string.c_str());
        closelog();
        exit(1);
    }
    else if(pid > 0)
    {
        // Parent process.
        syslog(LOG_INFO, "parent process for [IP %s] pid > 0", daemon.m_hostaddr_string.c_str());
        daemon.errlog((char *)"parent process for [IP %s] pid > 0", (char*)daemon.m_hostaddr_string.c_str());
    }

    // Setup Detected Screen Size.
    struct winsize ws;

    // setup Term
    init_termbuf();
#ifdef TIOCSWINSZ
    if (daemon.getTermCols() || daemon.getTermRows())
    {
        memset(&ws, 0, sizeof(ws));
        ws.ws_col = daemon.getTermCols();
        ws.ws_row = daemon.getTermRows();
        ioctl(ptyfd, TIOCSWINSZ, (char *)&ws);
    }
#endif


    // Start Main Parent Loop for communication with child (BBS)
    daemon.errlog((char *)"Starting Parent Loop");
    daemon.loop_parent_process(ptyfd);
    daemon.errlog((char *)"Closing Parent Loop");

    raise(SIGHUP);

    syslog(LOG_INFO, "in.telnetd [IP %s] [Closed Connection]", daemon.m_hostaddr_string.c_str());
    daemon.errlog((char *)"in.telnetd [IP %s] [Closed Connection]", (char*)daemon.m_hostaddr_string.c_str());

    closelog();

    remove(daemon.m_term_passing.c_str());

    _exit(0);


}
コード例 #15
0
ファイル: knockd.c プロジェクト: airwoflgh/knock
int main(int argc, char **argv)
{
	struct ifaddrs *ifaddr, *ifa;
	ip_literal_t *myip;
	char pcapErr[PCAP_ERRBUF_SIZE] = "";
	int opt, ret, optidx = 1;

	static struct option opts[] =
	{
		{"verbose",   no_argument,       0, 'v'},
		{"debug",     no_argument,       0, 'D'},
		{"daemon",    no_argument,       0, 'd'},
		{"lookup",    no_argument,       0, 'l'},
		{"interface", required_argument, 0, 'i'},
		{"config",    required_argument, 0, 'c'},
		{"help",      no_argument,       0, 'h'},
		{"pidfile",   required_argument, 0, 'p'},
		{"logfile",   required_argument, 0, 'g'},
		{"version",   no_argument,       0, 'V'},
		{0, 0, 0, 0}
	};

	while((opt = getopt_long(argc, argv, "vDdli:c:p:g:hV", opts, &optidx))) {
		if(opt < 0) {
			break;
		}
		switch(opt) {
			case 0:   break;
			case 'v': o_verbose = 1; break;
			case 'D': o_debug = 1; break;
			case 'd': o_daemon = 1; break;
			case 'l': o_lookup = 1; break;
			case 'i': strncpy(o_int, optarg, sizeof(o_int)-1);
								o_int[sizeof(o_int)-1] = '\0';
								break;
			case 'c': strncpy(o_cfg, optarg, sizeof(o_cfg)-1);
								o_cfg[sizeof(o_cfg)-1] = '\0';
								break;
			case 'p': strncpy(o_pidfile, optarg, sizeof(o_pidfile)-1);
								o_pidfile[sizeof(o_pidfile)-1] = '\0';
								break;
			case 'g': strncpy(o_logfile, optarg, sizeof(o_logfile)-1);
								o_logfile[sizeof(o_logfile)-1] = '\0';
								break;
			case 'V': ver();
			case 'h': /* fallthrough */
			default: usage(0);
		}
	}

	if(parseconfig(o_cfg)) {
		usage(1);
	}

	/* set o_int to a default value if it has not been set by the -i switch nor by
	 * the config file */
	if(strlen(o_int) == 0) {
		strncpy(o_int, "eth0", sizeof(o_int));	/* no explicit termination needed */
	}
	if(o_usesyslog) {
		openlog("knockd", 0, LOG_USER);
	}
	if(strlen(o_logfile)) {
		/* open the log file */
		logfd = fopen(o_logfile, "a");
		if(logfd == NULL) {
			perror("warning: cannot open logfile");
		}
	}

	/* 50ms timeout for packet capture. See pcap(3pcap) manpage, which
	 * recommends that a timeout of 0 not be used. */
	cap = pcap_open_live(o_int, 65535, 0, 50, pcapErr);
	if(strlen(pcapErr)) {
		fprintf(stderr, "could not open %s: %s\n", o_int, pcapErr);
	}
	if(cap == NULL) {
		exit(1);
	}

	lltype = pcap_datalink(cap);
	switch(lltype) {
		case DLT_EN10MB:
			dprint("ethernet interface detected\n");
			break;
#ifdef __linux__
		case DLT_LINUX_SLL:
			dprint("ppp interface detected (linux \"cooked\" encapsulation)\n");
			break;
#endif
		case DLT_RAW:
			dprint("raw interface detected, no encapsulation\n");
			break;
		default:
			fprintf(stderr, "error: unsupported link-layer type: %d\n", lltype);
			cleanup(1);
			break;
	}

	/* get our local IP addresses */
	if(getifaddrs(&ifaddr) != 0) {
		fprintf(stderr, "error: could not get IP address for %s: %s\n", o_int, strerror(errno));
		cleanup(1);
	} else {
		for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
			if (ifa->ifa_addr == NULL)
				continue;

			if((strcmp(ifa->ifa_name, o_int) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
				if((myip = calloc(1, sizeof(ip_literal_t))) == NULL) {
					perror("malloc");
					exit(1);
				} else if ((myip->value = calloc(1,NI_MAXHOST)) == NULL) {
					perror("malloc");
					exit(1);
				} else {
					if(getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), myip->value, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0) {
						fprintf(stderr, "error: could not get IP address for %s: %s\n", o_int, strerror(errno));
						freeifaddrs(ifaddr);
						cleanup(1);
					} else {
						if(myips)
							myip->next = myips;
						myips = myip;
						dprint("Local IP: %s\n", myip->value);
					}
				}
			}
		}
		freeifaddrs(ifaddr);
	}

	generate_pcap_filter();

	if(o_daemon) {
		FILE *pidfp;
		if(daemon(0, 0) < 0) {
			perror("daemon");
			cleanup(1);
		}
		/* write our PID to the pidfile*/
		if((pidfp = fopen(o_pidfile, "w"))) {
			fprintf(pidfp, "%d\n", getpid());
			fclose(pidfp);
		} else {
			dprint("could not create pid file %s: %s\n", o_pidfile, strerror(errno));
			logprint("could not create pid file %s: %s", o_pidfile, strerror(errno));
		}
	}

	signal(SIGINT, cleanup);
	signal(SIGTERM, cleanup);
	signal(SIGCHLD, child_exit);
	signal(SIGHUP, reload);

	vprint("listening on %s...\n", o_int);
	logprint("starting up, listening on %s", o_int);
	ret = 1;
	while(ret >= 0) {
		ret = pcap_dispatch(cap, -1, sniff, NULL);
	}
	dprint("bailed out of main loop! (ret=%d)\n", ret);
	pcap_perror(cap, "pcap");

	cleanup(0);
	/* notreached */
	exit(0);
}
コード例 #16
0
ファイル: flatfs1.c プロジェクト: OPSF/uClinux
int flat1_restorefs(int version, int dowrite)
{
	unsigned int size, n = 0;
	struct flatent ent;
	char filename[128];
	unsigned char buf[BUF_SIZE];
	char *confbuf;
	mode_t mode;
	int fdfile, rc;

	if ((rc = flat1_checkfs()) != 0)
		return rc;

	/*
	 * Get back to the real data we want.
	 */
	if (flat_seek(sizeof(struct flathdr1), SEEK_SET) != sizeof(struct flathdr1))
		return ERROR_CODE();

	for (numfiles = 0, numbytes = 0; ; numfiles++) {
		/* Get the name of next file. */
		if (flat_read(&ent, sizeof(ent)) != sizeof(ent))
			return ERROR_CODE();

		if (ent.filelen == FLATFS_EOF)
			break;

		n = ((ent.namelen + 3) & ~0x3);
		if (n > sizeof(filename))
			return ERROR_CODE();

		if (flat_read(&filename[0], n) != n)
			return ERROR_CODE();

		if (version >= 2) {
			if (flat_read(&mode, sizeof(mode)) != sizeof(mode)) {
				flat_close(1, 0);
				return ERROR_CODE();
			}
		} else {
			mode = 0644;
		}

		if (strcmp(filename, FLATFSD_CONFIG) == 0) {
			/* Read our special flatfsd config file into memory */
			if (ent.filelen == 0) {
#ifndef HAS_RTC
				/* This file was not written correctly, so just ignore it */
				syslog(LOG_WARNING, "%s is zero length, ignoring", filename);
#endif
			}
			else if ((confbuf = malloc(ent.filelen)) == 0) {
				syslog(LOG_ERR, "Failed to allocate memory for %s -- ignoring it", filename);
			}
			else {
				if (flat_read(confbuf, ent.filelen) != ent.filelen) {
					free(confbuf);
					return ERROR_CODE();
				}

#ifndef HAS_RTC
				parseconfig(confbuf);
#endif
				free(confbuf);
			}
		} else {
			/* Write contents of file out for real. */
			fdfile = open(filename, (O_WRONLY | O_TRUNC | O_CREAT), mode);
			if (fdfile < 0)
				return ERROR_CODE();
			
			for (size = ent.filelen; (size > 0); size -= n) {
				n = (size > sizeof(buf)) ? sizeof(buf) : size;
				if (flat_read(&buf[0], n) != n)
					return ERROR_CODE();
				if (write(fdfile, (void *) &buf[0], n) != n)
					return ERROR_CODE();
			}

			close(fdfile);
		}

		/* Read alignment padding */
		n = ((ent.filelen + 3) & ~0x3) - ent.filelen;
		if (flat_read(&buf[0], n) != n)
			return ERROR_CODE();

		numbytes += ent.filelen;
	}

	return 0;
}
コード例 #17
0
ファイル: testmain.c プロジェクト: TecDroiD/rocs
int main(int argc, char **argv) {
	SDL_Init(0);
	SDL_Thread *thread;

	int opt;
	t_rocsmq_message message;
	int x_it = 0;
	
	// parse config file 
	parseconfig(CONFIGFILE, &baseconfig, 0, 0 ,0);
	
	
	// open log
	log_message(DEBUG, "logging to file.. '%s'\n", baseconfig.logfile);
	openlog((char const *)baseconfig.clientname, (char const*)baseconfig.logfile);
	log_message(DEBUG, "loglevel = %d\n", baseconfig.loglevel);
		
	// set loglevel	
	log_setlevel(baseconfig.loglevel);
	
	log_message(DEBUG, "clientname: %s", baseconfig.clientname);
	strncpy (message.sender, baseconfig.clientname, 20);
	memset  (message.tail, 0, 1000);
	strncpy (message.id, "", ROCS_IDSIZE);

	// get command line options
	while ((opt = getopt(argc, argv, "n:i:m:f:x")) != -1) {
		switch(opt) {
			case 'n':
				strcpy(baseconfig.clientname, optarg);
				break;
			case 'i':
				strncpy(message.id,optarg, ROCS_IDSIZE);
				break;
			case 'm': 
				strncpy(message.tail,optarg, 1000);
				break;
			case 'x':
				x_it = 1;
				break;
			case 'f':
				parseconfig(optarg, &baseconfig,0, 0,0);	
			default:
				printf("usage:\n %s [-n name] [-i message-id] [-m message] [-x]\n", argv[0]);
				printf(" -n - name of the client\n");
				printf(" -i - identifier of the message\n");
				printf(" -m - body of the message\n");
				printf(" -x - exit after sending, goes into listening mode else.\n");
		}
		
	}


	sock = rocsmq_init(&baseconfig);
	if (!sock) {
		SDL_Quit();
		printf("could not connect to Server: %s\n", rocsmq_error());
		exit(1);
	}


	// start network listener
	thread = rocsmq_start_thread(sock);

	if (message.id != 0) {
			log_message( INFO, "sending message\n ->id:\t%d\n ->tail:\t'%s'\n",message.id, message.tail);
			if (! rocsmq_send(sock,&message,0)) {
				log_message(ERROR,"could not send: %s\n",rocsmq_error());
			}
	}

	if (! x_it) 
	while (rocsmq_thread_is_running()) {
		while(rocsmq_has_messages()) {

			rocsmq_get_message(&message);
			log_message( INFO, "incoming message\n ->id:\t%d\n ->tail:\t'%s'\n",message.id, message.tail);
			if (strcmp("quit",message.tail) == 0) {
				rocsmq_thread_set_running(0);
				log_message(INFO,"quitting..\n");
			}

		}
		SDL_Delay(100);
		printf(".");
	}

	rocsmq_destroy_thread(thread);
	rocsmq_exit(sock);
	SDL_Quit();
	return 0;
}