Esempio n. 1
0
void voice_init_section(void)
{
	xstrncpy(setup.voice.standardmsg		, setup.spool					, VOICE_MAX_MESSAGE );
	xstrncat(setup.voice.standardmsg		, "/messages/standard.msg"	, VOICE_MAX_MESSAGE );
	xstrncpy(setup.voice.beepmsg			, setup.spool					, VOICE_MAX_MESSAGE );
	xstrncat(setup.voice.beepmsg			, "/messages/beep.msg"		, VOICE_MAX_MESSAGE );
	xstrncpy(setup.voice.timeoutmsg		, setup.spool					, VOICE_MAX_MESSAGE );
	xstrncat(setup.voice.timeoutmsg		, "/messages/timeout.msg"	, VOICE_MAX_MESSAGE );
	xstrncpy(setup.voice.tclscriptname	, setup.spool					, VOICE_MAX_SCRIPT  );
	xstrncat(setup.voice.tclscriptname	, "/standard.tcl"				, VOICE_MAX_SCRIPT  );
	xstrncpy(setup.voice.checknewpath	, setup.spool					, VOICE_MAX_CHECKNEW);
	xstrncat(setup.voice.checknewpath	, "/incoming"					, VOICE_MAX_CHECKNEW);
	xstrncpy(setup.voice.callerid			, "*** Unknown ***"			, VOICE_MAX_CALLERID);
	xstrncpy(setup.voice.phone				, "*** Unknown ***"			, VOICE_MAX_PHONE	  );
	xstrncpy(setup.voice.name				, "*** Unknown ***"			, VOICE_MAX_NAME	  );
	xstrncpy(setup.voice.section			, "STANDARD"					, VOICE_MAX_SECTION );

	setup.voice.rings			= -1;
	setup.voice.ringsonnew	= -1;
	setup.voice.doanswer		= TRUE;
	setup.voice.dorecord		= TRUE;
	setup.voice.dobeep		= TRUE;
	setup.voice.domessage	= TRUE;
	setup.voice.dotimeout	= TRUE;
	setup.voice.recordtime	= TRUE;
}
Esempio n. 2
0
static int vboxgettyrc_parse(unsigned char *tty)
{
	unsigned char tempsectname[VBOX_MAX_RCLINE_SIZE + 1];

	xstrncpy(temppathname, SYSCONFDIR		 , PATH_MAX);
	xstrncat(temppathname, "/vboxgetty.conf", PATH_MAX);

		/* First time, the global ttyI settings will be	*/
		/* parsed.													*/

	xstrncpy(tempsectname, "vboxgetty-tty", VBOX_MAX_RCLINE_SIZE);

	if (rc_read(rc_getty_c, temppathname, tempsectname) == -1) return(-1);

		/* Second, the settings for the used ttyI will be	*/
		/* parsed.														*/

	xstrncpy(tempsectname, "vboxgetty-", VBOX_MAX_RCLINE_SIZE);
	xstrncat(tempsectname, tty			  , VBOX_MAX_RCLINE_SIZE);

	if (rc_read(rc_getty_c, temppathname, tempsectname) == -1) return(-1);

		/* After this, all unset variables will be filled with	*/
		/* the defaults.														*/

	log_line(LOG_D, "Filling unset configuration variables with defaults...\n");

	if (!rc_set_empty(rc_getty_c, "init"				, "ATZ&B512"		 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "badinitsexit"		, "10"				 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "initpause"			, "2500"				 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "commandtimeout"	, "4"					 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "echotimeout"		, "4"					 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "ringtimeout"		, "6"					 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "alivetimeout"		, "1800"				 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "toggledtrtime"	, "400"				 )) return(-1);
	if (!rc_set_empty(rc_getty_c, "spooldir"			, "/var/spool/vbox")) return(-1);

	modemsetup.echotimeout		= xstrtol(rc_get_entry(rc_getty_c, "echotimeout"	), 4		);
	modemsetup.commandtimeout	= xstrtol(rc_get_entry(rc_getty_c, "commandtimeout"), 4		);
	modemsetup.ringtimeout		= xstrtol(rc_get_entry(rc_getty_c, "ringtimeout"	), 6		);
	modemsetup.alivetimeout		= xstrtol(rc_get_entry(rc_getty_c, "alivetimeout"	), 1800	);
	modemsetup.toggle_dtr_time	= xstrtol(rc_get_entry(rc_getty_c, "toggledtrtime"	), 400	);

	if (!rc_get_entry(rc_getty_c, "initnumber"))
	{
		log_line(LOG_E, "Variable \"initnumber\" *must* be set!\n");
		
		return(-1);
	}

	return(0);
}
Esempio n. 3
0
BOOL cl_eval_file(char* file_name)
{
    sByteCode code;
    sConst constant;
    sVarTable gv_table;
    int max_stack;
    int gv_var_num;
    char compiled_file_name[PATH_MAX];

    /// make compiled file name ///
    xstrncpy(compiled_file_name, file_name, PATH_MAX-3);
    xstrncat(compiled_file_name, ".o", PATH_MAX);

    sByteCode_init(&code);
    sConst_init(&constant);

    if(!load_code(&code, &constant, &gv_var_num, &max_stack, compiled_file_name)) {
        fprintf(stderr, "load script file (%s) failure.\n", compiled_file_name);
        sByteCode_free(&code);
        sConst_free(&constant);
        return FALSE;
    }

    if(!cl_main(&code, &constant, gv_var_num, max_stack, CL_STACK_SIZE)) {
        sByteCode_free(&code);
        sConst_free(&constant);
        return FALSE;
    }

    sByteCode_free(&code);
    sConst_free(&constant);

    return TRUE;
}
Esempio n. 4
0
bool XMLNode::append_data(char *s, int len)
{
  // Append <len> characters of <s> to the data of this XMLNode.

  // Returns: true if fully successful, false otherwise.

  bool ret = false;

#if defined(DEBUG)
  // We don't know that <s> is NULL terminated, so don't echo it
  dlog->log_entry(DEBUG_MINTRC, "XMLNode::append_data(%d,%d)", s, len);
#endif

  if(s && len > 0)
  {
    d = xstrncat(d, s, len);

    if(d)
      ret = true;
  }
  
#if defined(DEBUG)
  dlog->log_exit(DEBUG_MINTRC, "XMLNode::append_data = %s", IOTF(ret));
#endif

  return(ret);
}
Esempio n. 5
0
BOOL initialize_tuple_object(CLObject tuple_object, int num_elements, CLObject* items, CLVALUE* stack, int var_num, CLVALUE** stack_ptr, sVMInfo* info)
{
    char class_name[CLASS_NAME_MAX+1];
    snprintf(class_name, CLASS_NAME_MAX, "Tuple%d", num_elements);
    sCLClass* klass = get_class(class_name, FALSE);

    char method_name_and_params[1024];

    method_name_and_params[0] = '\0';

    xstrncpy(method_name_and_params, "initialize(", 1024);

    int i;
    for(i=0; i<num_elements; i++) {
        char class_name[CLASS_NAME_MAX+1];
        snprintf(class_name, CLASS_NAME_MAX, "GenericsParametorClass%d", i);
        xstrncat(method_name_and_params, class_name, 1024);

        if(i == num_elements-1) {
            xstrncat(method_name_and_params, ")", 1024);
        }
        else {
            xstrncat(method_name_and_params, ",", 1024);
        }
    }

    sCLMethod* method = search_for_method_from_virtual_method_table(klass, method_name_and_params);

    (*stack_ptr)->mObjectValue = tuple_object;  // self
    (*stack_ptr)++;

    for(i=0; i<num_elements; i++) {
        (*stack_ptr)->mObjectValue = items[i];
        (*stack_ptr)++;
    }

    if(!invoke_method(klass, method, stack, var_num, stack_ptr, info)) {
        return FALSE;
    }

    (*stack_ptr)--; // pop method result

    return TRUE;
}
Esempio n. 6
0
// ----------------------------------------------------------------------------
// fefind
// Tries to find first free file name with specified extension (adding numbers
// to the name until 15).
// ----------------------------------------------------------------------------
TCHAR *fefind(TCHAR *fname, TCHAR *ext, TCHAR *newname)
{
  TCHAR name[MAXS+1], newext[MAXS+1], *s;
  struct _stat fst;
  int ii;

  xstrncpy(name, fname, MAXS);
  if ((s = strrchr(name, T('.'))) != NULL) *s = T('\0');

  xstrncpy(newname, name, MAXS);
  xstrncat(newname, ext, MAXS);
  for (ii = 0; ii <= 15; ii++) { // append 1..15 to output file name
    if (tstat(newname, &fst) < 0) break; // file not found
    snprintf(newext, MAXS, T("-%d%s"), ii+1, ext);
    xstrncpy(newname, name, MAXS);
    xstrncat(newname, newext, MAXS);
  }
  if (ii > 15) {
    xstrncpy(newname, name, MAXS);
    xstrncat(newname, ext, MAXS);
    return NULL;
  }
  return newname;
} /* fefind */
Esempio n. 7
0
CLObject create_bytes_object_by_multiply(CLObject string, int number, sVMInfo* info)
{
    unsigned char* str;
    int len;
    int i;
    CLObject result;

    len = CLBYTES(string)->mLen * number;
    str = CALLOC(1, sizeof(char)*(len + 1));
    str[0] = 0;
    for(i=0; i<number; i++) {
        xstrncat((char*)str, CLBYTES_DATA(string)->mChars, len+1);
    }

    result = create_bytes_object(str, len, gBytesTypeObject, info);

    FREE(str);

    return result;
}
Esempio n. 8
0
/* return a heap allocated string formed from fmt and ap arglist
 * returned string is allocated with xmalloc, so must free with xfree.
 *
 * args are like printf, with the addition of the following format chars:
 * - %m expands to strerror(errno)
 * - %t expands to strftime("%x %X") [ locally preferred short date/time ]
 * - %T expands to rfc2822 date time  [ "dd, Mon yyyy hh:mm:ss GMT offset" ]
 *
 * simple format specifiers are handled explicitly to avoid calls to
 * vsnprintf and allow dynamic sizing of the message buffer. If a call
 * is made to vsnprintf, however, the message will be limited to 1024 bytes.
 * (inc. newline)
 *
 */
static char *vxstrfmt(const char *fmt, va_list ap)
{
	char        *buf = NULL;
	char        *p   = NULL;
	size_t      len = (size_t) 0;
	char        tmp[LINEBUFSIZE];
	int         unprocessed = 0;
	int         long_long = 0;

	while (*fmt != '\0') {

		if ((p = (char *)strchr(fmt, '%')) == NULL) {
			/* no more format chars */
			xstrcat(buf, fmt);
			break;

		} else {        /* *p == '%' */
			/* take difference from fmt to just before `%' */
			len = (size_t) ((long)(p) - (long)fmt);
			/* append from fmt to p into buf if there's
			 * anythere there
			 */
			if (len > 0)
				xstrncat(buf, fmt, len);

			switch (*(++p)) {
		        case '%':	/* "%%" => "%" */
				xstrcatchar(buf, '%');
				break;

			case 'm':	/* "%m" => strerror(errno) */
				xslurm_strerrorcat(buf);
				break;

			case 't': 	/* "%t" => locally preferred date/time*/
				xstrftimecat(buf, "%x %X");
				break;
			case 'T': 	/* "%T" => "dd, Mon yyyy hh:mm:ss off" */
				xstrftimecat(buf, "%a, %d %b %Y %H:%M:%S %z");
				break;
#if defined USE_USEC_CLOCK
			case 'M':       /* "%M" => "usec"                    */
				snprintf(tmp, sizeof(tmp), "%ld", clock());
				xstrcat(buf, tmp);
				break;
#elif defined USE_RFC5424_TIME
			case 'M': /* "%M" => "yyyy-mm-ddThh:mm:ss(+/-)hh:mm" */
				xrfc5424timecat(buf);
				break;
#elif defined USE_ISO_8601
			case 'M':       /* "%M" => "yyyy-mm-ddThh:mm:ss"     */
				xstrftimecat(buf, "%Y-%m-%dT%T");
				break;
#else
			case 'M':       /* "%M" => "Mon DD hh:mm:ss"         */
				xstrftimecat(buf, "%b %d %T");
				break;
#endif
			case 's':	/* "%s" => append string */
				/* we deal with this case for efficiency */
				if (unprocessed == 0)
					xstrcat(buf, va_arg(ap, char *));
				else
					xstrcat(buf, "%s");
				break;
			case 'f': 	/* "%f" => append double */
				/* again, we only handle this for efficiency */
				if (unprocessed == 0) {
					snprintf(tmp, sizeof(tmp), "%f",
						 va_arg(ap, double));
					xstrcat(buf, tmp);
				} else
					xstrcat(buf, "%f");
				break;
			case 'd':
				if (unprocessed == 0) {
					snprintf(tmp, sizeof(tmp), "%d",
						 va_arg(ap, int));
					xstrcat(buf, tmp);
				} else
Esempio n. 9
0
// ----------------------------------------------------------------------------
// tmain
// ----------------------------------------------------------------------------
int tmain(int argc, TCHAR *argv[])
{
  int ii, ac, opt;
  TCHAR *s, *av[MAXC], *errtxt;
  TCHAR geoid[MAXS+1];
  int value, tr, rev, warn;
  TCHAR inpname[MAXS+1], outname[MAXS+1], prjname[MAXS+1];
  static GEOGRA ifl, ofl; static GEOUTM ixy, oxy;
  struct timespec start, stop;
  double tdif;
  SHPHandle iSHP, oSHP;
  DBFHandle iDBF, oDBF;
  int nShapeType, nEntities; //, nVertices, nParts;
  int nEntity, nVertex, nPart;
  double adfMinBound[4], adfMaxBound[4];
  SHPObject *psShape;
  TCHAR *pszPartType, *pszPlus;
  TCHAR *iTuple, *oTuple;
  FILE *out; TCHAR *proj;
  int nPercentBefore, nPercent;

  // Get program name
  if ((prog = strrchr(argv[0], DIRSEP)) == NULL) prog = argv[0];
  else prog++;
  if ((s = strstr(prog, T(".exe"))) != NULL) *s = T('\0');
  if ((s = strstr(prog, T(".EXE"))) != NULL) *s = T('\0');

  // Default global flags
  debug = 0;   // no debug
  tr = 1;      // default transformation: xy (d96tm) --> fila (etrs89)
  rev = 0;     // don't reverse xy/fila
  geoid[0] = T('\0');
  gid_wgs = 1; // slo2000
  hsel = -1;   // no default height processing (use internal recommendations)

  // Parse command line
  ac = 0; opt = 1;
  for (ii = 1; ii < argc && ac < MAXC; ii++) {
    if (opt && *argv[ii] == T('-')) {
      if (strcasecmp(argv[ii], T("-g")) == 0) { // geoid
        ii++; if (ii >= argc) goto usage;
        xstrncpy(geoid, argv[ii], MAXS);
        if (strlen(geoid) == 0) goto usage;
        if (strncasecmp(geoid, T("slo"), 1) == 0) gid_wgs = 1;      // slo2000
        else if (strncasecmp(geoid, T("egm"), 1) == 0) gid_wgs = 2; // egm2008
        else goto usage;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-t")) == 0) { // transformation
        ii++; if (ii >= argc) goto usage;
        if (strlen(argv[ii]) == 0) goto usage;
        errno = 0; value = strtol(argv[ii], &s, 10);
        if (errno || *s) goto usage;
        if (value < 1 || value > 10) goto usage;
        tr = value;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-ht")) == 0) { // transformed height
        hsel = 0;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-hc")) == 0) { // copy height
        hsel = 1;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-hg")) == 0) { // geoid height
        hsel = 2;
        continue;
      }
      else if (strcasecmp(argv[ii], T("--")) == 0) { // end of options
        opt = 0;
        continue;
      }
      s = argv[ii];
      while (*++s) {
        switch (*s) {
          case T('d'): // debug
            debug++;
            break;
          case T('r'): // reverse xy/fila
            rev = 1;
            break;
          case T('v'): // version
            usage(prog, 1); // show version only
            exit(0);
            break;
          default: // usage
usage:      usage(prog, 0);
            exit(1);
        }
      }
      continue;
    } // if opt
    av[ac] = (TCHAR *)malloc(MAXS+1);
    if (av[ac] == NULL) {
      errtxt = xstrerror();
      if (errtxt != NULL) {
        fprintf(stderr, T("malloc(av): %s\n"), errtxt); free(errtxt);
      } else
        fprintf(stderr, T("malloc(av): Unknown error\n"));
      exit(3);
    }
    xstrncpy(av[ac++], argv[ii], MAXS);
  } // for each argc
  av[ac] = NULL;

  ellipsoid_init();
  params_init();

  if (ac < 2) goto usage;

  if ((s = strrchr(av[0], T('.'))) != NULL) *s = T('\0'); // clear current extension
  xstrncat(av[0], T(".shp"), MAXS); // look for <name>.shp

  convert_shp_file(av[0], av[1], NULL);

  return 0;
} /* main */
Esempio n. 10
0
int init_program(char *device, char *gettyrc)
{
	struct passwd *passwd;

	setup.modem.device	= device;
	setup.vboxrc			= NULL;
	setup.vboxrcname[0]	= '\0';
	setup.vboxctrl[0]		= '\0';
	setup.spool[0]			= '\0';
	setup.freespace		= 0;

	/* 
	 * Initialize the log and start the session. The name of the log
	 * is stored into the global setup.
	 */

	if (!log_init()) returnerror();

	log(L_INFO, "-----------------------[Begin session]----------------------\n");
	log(L_INFO, "Running vbox version %s...\n", VERSION);

	/*
	 * Check the version of the tcl interpreter. On bad version only
	 * a warning is displayed.
	 */

	script_check_interpreter();

	/*
	 * Parse vboxgetty.conf. This function will init the most fields
	 * in the global structure.
	 */

	if (!getty_get_settings(gettyrc)) returnerror();

	/*
	 * If the UID or GID is 0 (no user is set) return with error and
	 * exit.
	 */

	if ((setup.users.uid == 0) || (setup.users.gid == 0))
	{
		log(L_FATAL, "You *must* set a user/group (not root)!\n");

		returnerror();
	}

	/*
	 * Get the user settings from /etc/passwd. The name and the home
	 * directory are stored into the global structure.
	 */

	if (!(passwd = getpwuid(setup.users.uid)))
	{
		log(L_FATAL, "Can't get passwd entry for userid %d.\n", setup.users.uid);

		returnerror();
	}

	xstrncpy(setup.users.name, passwd->pw_name, USER_MAX_NAME);
	xstrncpy(setup.users.home, passwd->pw_dir , USER_MAX_HOME);

	if (!*setup.spool)
	{
		xstrncpy(setup.spool, SPOOLDIR		  , SETUP_MAX_SPOOLNAME);
		xstrncat(setup.spool, "/"				  , SETUP_MAX_SPOOLNAME);
		xstrncat(setup.spool, setup.users.name, SETUP_MAX_SPOOLNAME);
	}

	if (!*setup.vboxrcname)
	{
		xstrncpy(setup.vboxrcname, setup.spool , SETUP_MAX_VBOXRC);
		xstrncat(setup.vboxrcname, "/vbox.conf", SETUP_MAX_VBOXRC);
	}

	log(L_INFO, "User %s's messagebox is \"%s\"...\n", setup.users.name, setup.spool);
	log(L_INFO, "User %s's vbox.conf is \"%s\"...\n", setup.users.name, setup.vboxrcname);

	/*
	 * Create the spool directory and set the permissions to the current
	 * user (with umask).
	 */

	if ((mkdir(setup.spool, S_IRWXU) == -1) && (errno != EEXIST))
	{
		log(L_FATAL, "Can't create \"%s\" (%s).\n", setup.spool, strerror(errno));

		returnerror();
	}

	if (!permissions_set(setup.spool, setup.users.uid, setup.users.gid, S_IRWXU|S_IRWXG|S_IRWXO, setup.users.umask))
	{
		returnerror();
	}

	/*
	 * Now we check if 'vboxctrl-stop' exists. If true, loop and watch
	 * if the files is deleted.
	 */

	if (ctrl_ishere(setup.spool, CTRL_NAME_STOP))
	{
		log(L_INFO, "Control file \"%s\" exists - waiting...\n", CTRL_NAME_STOP);

		while (ctrl_ishere(setup.spool, CTRL_NAME_STOP))
		{
			log(L_JUNK, "Control file \"%s\" exists - waiting...\n", CTRL_NAME_STOP);

			xpause(5000);
		}

		log(L_INFO, "Control file deleted - back in business...\n");
	}

	if (ctrl_ishere(setup.spool, CTRL_NAME_ANSWERNOW))
	{
		if (!ctrl_remove(setup.spool, CTRL_NAME_ANSWERNOW))
		{
			log(L_WARN, "Can't remove control file \"%s\"!\n", CTRL_NAME_ANSWERNOW);
		}
	}

	if (ctrl_ishere(setup.spool, CTRL_NAME_REJECT))
	{
		if (!ctrl_remove(setup.spool, CTRL_NAME_REJECT))
		{
			log(L_WARN, "Can't remove control file \"%s\"!\n", CTRL_NAME_REJECT);
		}
	}

	/*
	 * Open the modem device - this *must* done under the rights of
	 * the root user!
	 */

	if (!modem_open_port()) returnerror();

	/*
	 * Lock the modem port and create the pid file. After this the
	 * filepermissions will set to the user, so he can delete this
	 * files if the getty quit.
	 */

	if (!lock_type_lock(LCK_PID  )) returnerror();
	if (!lock_type_lock(LCK_MODEM)) returnerror();

	/*
	 * Drop root privilegs to the current user and set the correct
	 * umask.
	 */

	if (!permissions_drop(setup.users.uid, setup.users.gid, setup.users.name, setup.users.home))
	{
		returnerror();
	}

	umask(setup.users.umask);

	/*
	 * Load vbox's configuration into memory and initialize the voice
	 * defaults.
	 */

	if (!(setup.vboxrc = streamio_open(setup.vboxrcname)))
	{
		log(L_FATAL, "Can't open \"%s\".\n", setup.vboxrcname);

		returnerror();
	}

	voice_init_section();

	/*
	 * Now the complete global setup structure is filled and can be
	 * used.
	 */

	returnok();
}
Esempio n. 11
0
static int userrc_parse(struct vboxuser *vboxuser, unsigned char *home)
{
	unsigned char   tempsectname[VBOX_MAX_RCLINE_SIZE + 1];
	struct passwd	*pwdent;
	struct group	*grpent;
	unsigned char  *varusr;
	unsigned char  *vargrp;
	unsigned char  *varspc;
	unsigned char  *varmsk;
	int				 havegroup;

	static struct vboxrc rc_user_c[] =
	{
		{ "user"		, NULL },
		{ "group"	, NULL },
		{ "umask"	, NULL },
		{ "hdspace"	, NULL },
		{ NULL		, NULL }
	};

	xstrncpy(temppathname, SYSCONFDIR		 , PATH_MAX);
	xstrncat(temppathname, "/vboxgetty.conf", PATH_MAX);

	xstrncpy(tempsectname, "vboxgetty-phone-"	 , VBOX_MAX_RCLINE_SIZE);
	xstrncat(tempsectname, vboxuser->localphone, VBOX_MAX_RCLINE_SIZE);

	if (rc_read(rc_user_c, temppathname, tempsectname) < 0) return(-1);

	varusr = rc_get_entry(rc_user_c, "user"	);
	vargrp = rc_get_entry(rc_user_c, "group"	);
	varspc = rc_get_entry(rc_user_c, "hdspace");
	varmsk = rc_get_entry(rc_user_c, "umask"  );

	vboxuser->uid		= 0;
	vboxuser->gid		= 0;
	vboxuser->space	= 0;
	vboxuser->umask	= 0;

	strcpy(vboxuser->home, "");
	strcpy(vboxuser->name, "");

	if ((!varusr) || (!*varusr))
	{
		log_line(LOG_E, "You *must* specify a user name or a user id!\n");

		rc_free(rc_user_c);

		return(-1);
	}

	if (*varusr == '#')
		pwdent = getpwuid((uid_t)xstrtol(&varusr[1], 0));
	else
		pwdent = getpwnam(varusr);

	if (!pwdent)
	{
		log_line(LOG_E, "Unable to locate \"%s\" in systems passwd list.\n", varusr);

		rc_free(rc_user_c);

		return(-1);
	}

	vboxuser->uid = pwdent->pw_uid;
	vboxuser->gid = pwdent->pw_gid;

	if ((strlen(home) + strlen(pwdent->pw_name) + 2) < (PATH_MAX - 100))
	{
		xstrncpy(vboxuser->name, pwdent->pw_name, VBOXUSER_USERNAME);

		printstring(vboxuser->home, "%s/%s", home, pwdent->pw_name);
	}
	else
	{
		log_line(LOG_E, "Oops! Spool directory name and user name too long!\n");

		rc_free(rc_user_c);

		return(-1);
	}

	if ((vargrp) && (*vargrp))
	{
		havegroup = 0;

		setgrent();
					
		while ((grpent = getgrent()))
		{
			if (*vargrp == '#')
			{
				if (grpent->gr_gid == (gid_t)xstrtol(&vargrp[1], 0))
				{
					vboxuser->gid = grpent->gr_gid;
					havegroup	  = 1;
								
					break;
				}
			}
			else
			{
				if (strcmp(grpent->gr_name, vargrp) == 0)
				{
					vboxuser->gid = grpent->gr_gid;
					havegroup	  = 1;
								
					break;
				}
			}
		}
					
		endgrent();

		if (!havegroup)
		{
			log_line(LOG_E, "Unable to locate \"%s\" in systems group list.\n", vargrp);

			rc_free(rc_user_c);

			return(-1);
		}
	}

	if (varspc) vboxuser->space = xstrtol(varspc, 0);
	if (varmsk) vboxuser->umask = xstrtoo(varmsk, 0);

	log_line(LOG_D, "User \"%s\" (%d.%d) [%04o] will be used...\n", vboxuser->name, vboxuser->uid, vboxuser->gid, vboxuser->umask);

	rc_free(rc_user_c);

	return(0);
}
Esempio n. 12
0
static int scanmacho_fatobj(fatobj *fobj)
{
	unsigned long i;
	char found_needed, found_interp, found_soname, found_lib, found_file;
	static char *out_buffer = NULL;
	static size_t out_len;

	found_needed = found_interp = found_soname = \
	found_lib = found_file = 0;

	if (be_verbose > 2)
		printf("%s: scanning file {%s,%s}\n", fobj->filename,
		       get_machocputype(fobj),
		       get_machosubcputype(fobj));
	else if (be_verbose > 1)
		printf("%s: scanning file\n", fobj->filename);

	/* init output buffer */
	if (!out_buffer) {
		out_len = sizeof(char) * 80;
		out_buffer = xmalloc(out_len);
	}
	*out_buffer = '\0';

	/* show the header */
	if (!be_quiet && show_banner) {
		for (i = 0; out_format[i]; ++i) {
			if (!IS_MODIFIER(out_format[i])) continue;

			switch (out_format[++i]) {
			case '+': break;
			case '%': break;
			case '#': break;
			case 'F':
			case 'p':
			case 'f': prints("FILE "); found_file = 1; break;
			case 'o': prints("  TYPE   "); break;
			case 'M': prints("CPU "); break;
			case 'n': prints("NEEDED "); break;
			case 'i': prints("DYLINKER "); break;
			case 'b': prints("FLAGS "); break;
			case 'Z': prints("SIZE "); break;
			case 'S': prints("INSTALLNAME "); break;
			case 'N': prints("LIB "); break;
			case 'a': prints("ARCH "); break;
			case 'O': prints("PERM "); break;
			case 'D': prints("ENDIAN "); break;
			default: warnf("'%c' has no title ?", out_format[i]);
			}
		}
		if (!found_file) prints("FILE ");
		prints("\n");
		found_file = 0;
		show_banner = 0;
	}

	/* dump all the good stuff */
	for (i = 0; out_format[i]; ++i) {
		const char *out;
		const char *tmp;
		static char ubuf[sizeof(unsigned long)*2];
		if (!IS_MODIFIER(out_format[i])) {
			xchrcat(&out_buffer, out_format[i], &out_len);
			continue;
		}

		out = NULL;
		be_wewy_wewy_quiet = (out_format[i] == '#');
		be_semi_verbose = (out_format[i] == '+');
		switch (out_format[++i]) {
		case '+':
		case '%':
		case '#':
			xchrcat(&out_buffer, out_format[i], &out_len); break;
		case 'F':
			found_file = 1;
			if (be_wewy_wewy_quiet) break;
			xstrcat(&out_buffer, fobj->filename, &out_len);
			break;
		case 'p':
			found_file = 1;
			if (be_wewy_wewy_quiet) break;
			tmp = fobj->filename;
			if (search_path) {
				ssize_t len_search = strlen(search_path);
				ssize_t len_file = strlen(fobj->filename);
				if (!strncmp(fobj->filename, search_path, len_search) && \
				    len_file > len_search)
					tmp += len_search;
				if (*tmp == '/' && search_path[len_search-1] == '/') tmp++;
			}
			xstrcat(&out_buffer, tmp, &out_len);
			break;
		case 'f':
			found_file = 1;
			if (be_wewy_wewy_quiet) break;
			xstrcat(&out_buffer, fobj->base_filename, &out_len);
			break;
		case 'o': out = get_machomhtype(fobj); break;
		case 'M': out = get_machocputype(fobj); break;
		case 'D': out = get_machoendian(fobj); break;
		case 'O': out = strfileperms(fobj->filename); break;
		case 'n':
		case 'N': out = macho_file_needed_lib(fobj, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break;
		case 'i': out = macho_file_interp(fobj, &found_interp); break;
		case 'b': get_machomhflags(fobj, &out_buffer, &out_len); break;
		case 'S': out = macho_file_soname(fobj, &found_soname); break;
		case 'a': out = get_machomtype(fobj); break;
		case 'Z': snprintf(ubuf, sizeof(ubuf), "%llu", (unsigned long long int)fobj->len); out = ubuf; break;;
		default: warnf("'%c' has no scan code?", out_format[i]);
		}
		if (out) {
			/* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */
			if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL)
				xstrncat(&out_buffer, out, &out_len, (tmp-out));
			else
				xstrcat(&out_buffer, out, &out_len);
		}
	}

#define FOUND_SOMETHING() \
	( found_needed || found_interp || found_soname || found_lib )

	if (!found_file && (!be_quiet || (be_quiet && FOUND_SOMETHING()))) {
		xchrcat(&out_buffer, ' ', &out_len);
		xstrcat(&out_buffer, fobj->filename, &out_len);
	}
	if (!be_quiet || (be_quiet && FOUND_SOMETHING())) {
		puts(out_buffer);
		fflush(stdout);
	}

	return 0;
}
Esempio n. 13
0
File: log.c Progetto: cread/slurm
/*
 * return a heap allocated string formed from fmt and ap arglist
 * returned string is allocated with xmalloc, so must free with xfree.
 *
 * args are like printf, with the addition of the following format chars:
 * - %m expands to strerror(errno)
 * - %M expand to time stamp, format is configuration dependent
 * - %t expands to strftime("%x %X") [ locally preferred short date/time ]
 * - %T expands to rfc2822 date time  [ "dd, Mon yyyy hh:mm:ss GMT offset" ]
 *
 * these formats are expanded first, leaving all others to be passed to
 * vsnprintf() to complete the expansion using the ap arglist.
 */
static char *vxstrfmt(const char *fmt, va_list ap)
{
	char	*intermediate_fmt = NULL;
	char	*out_string = NULL;
	char	*p;
	int	found_other_formats = 0;

	while (*fmt != '\0') {
		int is_our_format = 0;
		p = (char *)strchr(fmt, '%');
		if (p == NULL) {
			/*
			 * no more format sequences, append the rest of
			 * fmt and exit the loop:
			 */
			xstrcat(intermediate_fmt, fmt);
			break;
		}

		/*
		 * make sure it's one of our format specifiers, skipping
		 * any that aren't:
		 */
		do {
			switch (*(p + 1)) {
				case 'm':
				case 't':
				case 'T':
				case 'M':
					is_our_format = 1;
					break;
				default:
					found_other_formats = 1;
					break;
			}
		} while (!is_our_format &&
			 (p = (char *)strchr(p + 1, '%')));

		if (is_our_format) {
			char	*substitute = NULL;
			char	substitute_on_stack[256];
			int	should_xfree = 1;

			/*
			 * p points to the leading % of one of our formats;
			 * append anything from fmt up to p to the intermediate
			 * format string:
			 */
			xstrncat(intermediate_fmt, fmt, p - fmt);
			fmt = p + 1;

			/*
			 * fill the substitute buffer with whatever text we want
			 * to substitute for the format sequence in question:
			 */
			switch (*fmt) {
			case 'm':	/* "%m" => strerror(errno) */
				substitute = slurm_strerror(errno);
				should_xfree = 0;
				break;
			case 't': 	/* "%t" => locally preferred date/time*/
				xstrftimecat(substitute,
					     "%x %X");
				break;
			case 'T': 	/* "%T" => "dd, Mon yyyy hh:mm:ss off" */
				xstrftimecat(substitute,
					     "%a, %d %b %Y %H:%M:%S %z");
				break;
			case 'M':
				if (!log) {
					xiso8601timecat(substitute, true);
					break;
				}
				switch (log->fmt) {
				case LOG_FMT_ISO8601_MS:
					/* "%M" => "yyyy-mm-ddThh:mm:ss.fff"  */
					xiso8601timecat(substitute, true);
					break;
				case LOG_FMT_ISO8601:
					/* "%M" => "yyyy-mm-ddThh:mm:ss.fff"  */
					xiso8601timecat(substitute, false);
					break;
				case LOG_FMT_RFC5424_MS:
					/* "%M" => "yyyy-mm-ddThh:mm:ss.fff(+/-)hh:mm" */
					xrfc5424timecat(substitute, true);
					break;
				case LOG_FMT_RFC5424:
					/* "%M" => "yyyy-mm-ddThh:mm:ss.fff(+/-)hh:mm" */
					xrfc5424timecat(substitute, false);
					break;
				case LOG_FMT_CLOCK:
					/* "%M" => "usec" */
#if defined(__FreeBSD__)
					snprintf(substitute_on_stack,
						 sizeof(substitute_on_stack),
						 "%d", clock());
#else
					snprintf(substitute_on_stack,
						 sizeof(substitute_on_stack),
						 "%ld", clock());
#endif
					substitute = substitute_on_stack;
					should_xfree = 0;
					break;
				case LOG_FMT_SHORT:
					/* "%M" => "Mon DD hh:mm:ss" */
					xstrftimecat(substitute, "%b %d %T");
					break;
				case LOG_FMT_THREAD_ID:
					set_idbuf(substitute_on_stack);
					substitute = substitute_on_stack;
					should_xfree = 0;
					break;
				}
				break;
			}
			fmt++;

			if (substitute) {
				char *s = substitute;

				while (*s && (p = (char *)strchr(s, '%'))) {
					/* append up through the '%' */
					xstrncat(intermediate_fmt, s, p - s);
					xstrcat(intermediate_fmt, "%%");
					s = p + 1;
				}
				if (*s) {
					/* append whatever's left of the substitution: */
					xstrcat(intermediate_fmt, s);
				}

				/* deallocate substitute if necessary: */
				if (should_xfree) {
					xfree(substitute);
				}
			}
		} else {
			/*
			 * no more format sequences for us, append the rest of
			 * fmt and exit the loop:
			 */
			xstrcat(intermediate_fmt, fmt);
			break;
		}
	}

	if (intermediate_fmt && found_other_formats) {
		char	tmp[LINEBUFSIZE];
		int	actual_len;
		va_list	ap_copy;

		va_copy(ap_copy, ap);
		actual_len = vsnprintf(tmp, sizeof(tmp),
				       intermediate_fmt, ap_copy);
		va_end(ap_copy);

		if (actual_len >= 0) {
			if (actual_len < sizeof(tmp)) {
				out_string = xstrdup(tmp);
			} else {
				/*
				 * our C library's vsnprintf() was nice enough
				 * to return the necessary size of the buffer!
				 */
				out_string = xmalloc(actual_len + 1);
				if (out_string) {
					va_copy(ap_copy, ap);
					vsnprintf(out_string, actual_len + 1,
						  intermediate_fmt, ap_copy);
					va_end(ap_copy);
				}
			}
		} else {
			size_t	growable_tmp_size = LINEBUFSIZE;
			char	*growable_tmp = NULL;

			/*
			 * our C library's vsnprintf() doesn't return the
			 * necessary buffer size on overflow, it considers that
			 * an error condition.  So we need to iteratively grow
			 * a buffer until it accommodates the vsnprintf() call
			 */
			do {
				growable_tmp_size += LINEBUFSIZE;
				growable_tmp = xrealloc(growable_tmp,
							growable_tmp_size);
				if (!growable_tmp)
					break;
				va_copy(ap_copy, ap);
				actual_len = vsnprintf(growable_tmp,
						       growable_tmp_size,
						       intermediate_fmt,
						       ap_copy);
				va_end(ap_copy);
			} while (actual_len < 0);
			out_string = growable_tmp;
		}
		xfree(intermediate_fmt);
	} else if (intermediate_fmt) {
		/*
		 * no additional format sequences, so we can just return the
		 * intermediate_fmt string
		 */
		out_string = intermediate_fmt;
	}

	return out_string;
}
Esempio n. 14
0
/*
 * FIXME - It would be nice to parse the multi-prog array just once
 *	to retrieve the argv arrays for each task on this node, rather
 *	than calling multi_prog_get_argv once for each task.
 */
extern int multi_prog_get_argv(char *config_data, char **prog_env,
			       int task_rank, uint32_t *argc, char ***argv,
			       int global_argc, char **global_argv)
{
	char *line = NULL;
	int i, line_num = 0;
	int task_offset;
	char *p = NULL, *ptrptr = NULL;
	char *rank_spec = NULL, *args_spec = NULL;
	int prog_argc = 0;
	char **prog_argv = NULL;
	char *local_data = NULL;
	size_t tmp_buf_len = 256;
	char tmp_buf[tmp_buf_len];
	char *arg_buf = NULL;
	bool last_line_break = false, line_break = false;
	int line_len;


	prog_argv = (char **)xmalloc(sizeof(char *) * MAX_ARGC);

	if (task_rank < 0) {
		error("Invalid task rank %d", task_rank);
		*argc = 1;
		*argv = prog_argv;
		return -1;
	}

	local_data = xstrdup(config_data);
	line = strtok_r(local_data, "\n", &ptrptr);
	while (line) {
		if (line_num > 0)
			line = strtok_r(NULL, "\n", &ptrptr);
		if (line == NULL) {
			error("No executable program specified for this task");
			goto fail;
		}
		line_num++;
		line_len = strlen(line);
		if ((line_len > 0) && (line[line_len - 1] == '\\'))
			line_break = true;
		else
			line_break = false;
		if (last_line_break) {
			last_line_break = line_break;
			continue;
		}
		last_line_break = line_break;
		p = line;
		while ((*p != '\0') && isspace (*p)) /* remove leading spaces */
			p++;

		if (*p == '#') /* only whole-line comments handled */
			continue;

		if (*p == '\0') /* blank line ignored */
			continue;

		rank_spec = p;

		while ((*p != '\0') && !isspace (*p))
			p++;
		if (*p == '\0') {
			error("Invalid MPMD configuration line %d", line_num);
			goto fail;
		}
		*p++ = '\0';

		if (!_in_range(task_rank, rank_spec, &task_offset))
			continue;

		/* skip all whitspace after the range spec */
		while ((*p != '\0') && isspace (*p))
			p++;

		args_spec = p;
		while (*args_spec != '\0') {
			/* Only simple quote and escape supported */
			if (arg_buf) {
				prog_argv[prog_argc++] = arg_buf;
				arg_buf=NULL;
			}
			if ((prog_argc + 1) >= MAX_ARGC) {
				info("Exceeded multi-prog argc limit");
				break;
			}
		CONT:	p = args_spec;
			while ((*args_spec != '\0') && (*args_spec != '\\') &&
			       (*args_spec != '%')  && (*args_spec != '\'') &&
			       !isspace(*args_spec)) {
				args_spec++;
			}
			xstrncat(arg_buf, p, (args_spec - p));
			if (*args_spec == '\0') {
				/* the last argument */
				break;

			} else if (*args_spec == '%') {
				args_spec++;
				if (*args_spec == 't') {
					/* task rank */
					snprintf(tmp_buf, tmp_buf_len, "%d",
						 task_rank);
					xstrcat(arg_buf, tmp_buf);
				} else if (*args_spec == 'o') {
					/* task offset */
					snprintf(tmp_buf, tmp_buf_len, "%d",
						 task_offset);
					xstrcat(arg_buf, tmp_buf);
				}
				args_spec++;
				goto CONT;

			} else if (*args_spec == '\\') {
				/* escape, just remove the backslash */
				args_spec++;
				if (*args_spec != '\0') {
					xstrcatchar(arg_buf, *args_spec);
					args_spec++;
				} else {
					line = strtok_r(NULL, "\n", &ptrptr);
					if (!line)
						break;
					line_num++;
					args_spec = line;
				}
				goto CONT;

			} else if (*args_spec == '\'') {
				/* single quote,
				 * preserve all characters quoted. */
				p = ++args_spec;
		LINE_BREAK:	while ((*args_spec != '\0') &&
				       (*args_spec != '\'')) {
					args_spec++;
				}
				if (*args_spec == '\0') {
					/* closing quote not found */
					if (*(args_spec - 1) == '\\') {
						line = strtok_r(NULL, "\n",
								&ptrptr);
						if (line) {
							line_num++;
							args_spec = line;
							goto LINE_BREAK;
						}
					}
					error("Program arguments specification format invalid: %s.",
					      prog_argv[prog_argc - 1]);
					goto fail;
				}
				xstrncat(arg_buf, p, (args_spec - p));
				args_spec++;
				goto CONT;

			} else {
				/* space */
				while ((*args_spec != '\0') &&
				       isspace(*args_spec)) {
					args_spec++;
				}
			}

		}
		if (arg_buf) {
			prog_argv[prog_argc++] = arg_buf;
			arg_buf = NULL;
		}

		for (i = 2; i < global_argc; i++) {
			if ((prog_argc + 1) >= MAX_ARGC) {
				info("Exceeded multi-prog argc limit");
				break;
			}
			prog_argv[prog_argc++] = xstrdup(global_argv[i]);
		}
		prog_argv[prog_argc] = NULL;

		*argc = prog_argc;
		*argv = prog_argv;
		xfree(local_data);
		return 0;
	}

	error("Program for task rank %d not specified.", task_rank);
fail:
	xfree(local_data);
	*argc = 1;
	prog_argv[0] = NULL;
	*argv = prog_argv;
	return -1;
}