Пример #1
0
/**
 * Collect user information.
 */
static void
entropy_collect_user(SHA1Context *ctx)
{
	const char *str[3];

	str[0] = gethomedir();

#if GLIB_CHECK_VERSION(2,6,0)
	/*
	 * These functions cannot be used with an unpatched GLib 1.2 on some
	 * systems as they trigger a bug in GLib causing a crash.  On Darwin
	 * there's still a problem before GLib 2.6 due to a bug in Darwin though.
	 */

	str[1] = g_get_user_name();
	str[2] = g_get_real_name();
	entropy_array_string_collect(ctx, str, G_N_ELEMENTS(str));
#else
	{
		char user[UINT32_DEC_BUFLEN];
		char real[UINT32_DEC_BUFLEN];

		uint32_to_string_buf(entropy_rand31(), user, sizeof user);
		uint32_to_string_buf(entropy_rand31(), real, sizeof real);
		str[1] = user;
		str[2] = real;
		entropy_array_string_collect(ctx, str, G_N_ELEMENTS(str));
	}
#endif	/* GLib >= 2.0 */
}
Пример #2
0
static appenv *getappenv()
{
    #define SNAPSHOTS "snapshots"
    #define BACKUP "backup"
    #define SCREENSHOTS "screenshots"

    appenv *app = malloc(sizeof(appenv));
    pushobject(app, freeappenv);

    app->basedir = pathcombc(gethomedir(), "." PACKAGE);
    createdirectory(app->basedir);

    app->snapshots = pathcombc(strdups(app->basedir), SNAPSHOTS);
    createdirectory(app->snapshots);

    app->backup = pathcombc(strdups(app->basedir), BACKUP);
    createdirectory(app->backup);

    app->screenshots = pathcombc(strdups(app->basedir), SCREENSHOTS);
    createdirectory(app->screenshots);

#ifdef DEBUG
    app->debug = pathcombc(strdups(app->basedir), "debug");
    createdirectory(app->debug);
#endif

    return app;
}
Пример #3
0
/**
 * Collect entropy from available space on filesystem.
 */
static void
entropy_collect_free_space(SHA1Context *ctx)
{
	double fs[3];

	fs[0] = fs_free_space_pct(gethomedir());
	fs[1] = fs_free_space_pct("/");
	fs[2] = fs_free_space_pct(".");

	entropy_array_double_collect(ctx, fs, G_N_ELEMENTS(fs));
}
Пример #4
0
int		ft_cd(t_cmd *dat, t_env *env)
{
	char		*target;
	int			ret;

	if (!dat->arg[1])
	{
		if (!(target = gethomedir(env)))
			return (1);
	}
	else
	{
		if (!(target = getinput(dat, env)))
			return (2);
	}
	ret = changedir(dat, target, env);
	free(target);
	return (ret);
}
Пример #5
0
char *expandtilde(char *str)
{
  static char retval[MAXINPUTLINE];
  char tempstr[MAXINPUTLINE];
  char *homedir;
  char *tempptr;
  int counter;
  

  if (str[0] != '~') return str;      /* No tilde -- no expansion. */
  strcpy(tempstr, (str + 1));          /* Make a temporary copy of the string */
  if ((tempstr[0] == '/') || (tempstr[0] == 0))
    tempptr = (char *)NULL;
  else {                  /* Only parse up to a slash */
    /* strtok() cannot be used here because it is being used in the function
       that calls expandtilde().  Therefore, use a simple substitute. */
    if (strstr(tempstr, "/"))
      *(strstr(tempstr, "/")) = 0;
    tempptr = tempstr;
  }
  
  if ((!tempptr) || !tempptr[0]) {    /* Get user's own homedir */
    homedir = gethomedir();
  } else {                  /* Get specified user's homedir */
    homedir = getuserhomedir(tempptr);
  }

  /* Now generate the output string in retval. */

  strcpy(retval, homedir);          /* Put the homedir in there */

  /* Now take care of adding in the rest of the parameter */

  counter = 1;
  while ((str[counter]) && (str[counter] != '/')) counter++;

  strcat(retval, (str + counter));

  return retval;
}
Пример #6
0
/**
 * Collect information from file system.
 */
static void
entropy_collect_filesystem(SHA1Context *ctx)
{
	const char *path[RANDOM_SHUFFLE_MAX];
	size_t i;

	i = 0;
	path[i++] = gethomedir();
	path[i++] = ".";
	path[i++] = "..";
	path[i++] = "/";

	g_assert(i <= G_N_ELEMENTS(path));

	entropy_array_stat_collect(ctx, path, i);

	i = 0;

	if (is_running_on_mingw()) {
		path[i++] = "C:/";
		path[i++] = mingw_get_admin_tools_path();
		path[i++] = mingw_get_common_appdata_path();
		path[i++] = mingw_get_common_docs_path();
		path[i++] = mingw_get_cookies_path();
		path[i++] = mingw_get_fonts_path();
		path[i++] = mingw_get_history_path();

		g_assert(i <= G_N_ELEMENTS(path));

		entropy_array_stat_collect(ctx, path, i);

		i = 0;
		path[i++] = mingw_get_home_path();
		path[i++] = mingw_get_internet_cache_path();
		path[i++] = mingw_get_mypictures_path();
		path[i++] = mingw_get_personal_path();
		path[i++] = mingw_get_program_files_path();
		path[i++] = mingw_get_startup_path();
		path[i++] = mingw_get_system_path();
		path[i++] = mingw_get_windows_path();

		g_assert(i <= G_N_ELEMENTS(path));

		entropy_array_stat_collect(ctx, path, i);
	} else {
		path[i++] = "/bin";
		path[i++] = "/boot";
		path[i++] = "/dev";
		path[i++] = "/etc";
		path[i++] = "/home";
		path[i++] = "/lib";
		path[i++] = "/mnt";
		path[i++] = "/opt";

		g_assert(i <= G_N_ELEMENTS(path));

		entropy_array_stat_collect(ctx, path, i);

		i = 0;
		path[i++] = "/proc";
		path[i++] = "/root";
		path[i++] = "/sbin";
		path[i++] = "/sys";
		path[i++] = "/tmp";
		path[i++] = "/usr";
		path[i++] = "/var";

		g_assert(i <= G_N_ELEMENTS(path));

		entropy_array_stat_collect(ctx, path, i);
	}
}
Пример #7
0
/**
 * Needs brief description here.
 *
 * Substitutes variables from string:
 *
 * - The leading "~" is replaced by the home directory.
 * - Variables like "$PATH" or "${PATH}" are replaced by their value, as
 *   fetched from the environment, or the empty string if not found.
 *
 * If given a NULL input, we return NULL.
 *
 * @return string constant, which is not meant to be freed until exit time.
 */
const char *
eval_subst(const char *str)
{
	char buf[MAX_STRING];
	char *end = &buf[sizeof(buf)];
	char *p;
	size_t len;
	char c;

	if (str == NULL)
		return NULL;

	len = g_strlcpy(buf, str, sizeof buf);
	if (len >= sizeof buf) {
		g_warning("%s(): string too large for substitution (%zu bytes)",
			G_STRFUNC, len);
		return constant_str(str);
	}


	if (common_dbg > 3)
		g_debug("%s: on entry: \"%s\"", G_STRFUNC, buf);

	for (p = buf, c = *p++; c; c = *p++) {
		const char *val = NULL;
		char *start = p - 1;

		switch (c) {
		case '~':
			if (start == buf && ('\0' == buf[1] || '/' == buf[1])) {
				/* Leading ~ only */
				val = gethomedir();
				g_assert(val);
				memmove(start, &start[1], len - (start - buf));
				len--;

				g_assert(size_is_non_negative(len));
			}
			break;
		case '$':
			{
				const char *after;

				val = get_variable(p, &after);
				g_assert(val);
				memmove(start, after, len + 1 - (after - buf));
				len -= after - start;		/* Also removing leading '$' */

				g_assert(size_is_non_negative(len));
			}
			break;
		}

		if (val != NULL) {
			char *next;

			next = insert_value(val, start, start - buf, len, sizeof buf - 1);
			len += next - start;
			p = next;

			g_assert(len < sizeof buf);
			g_assert(p < end);
		}

		g_assert(p <= &buf[len]);
	}

	if (common_dbg > 3)
		g_debug("%s: on exit: \"%s\"", G_STRFUNC, buf);

	g_assert(len == strlen(buf));

	return constant_str(buf);
}
Пример #8
0
core_getpath	/* wrapped below: expand fname, return full path */
#else
char *
getpath	/* expand fname, return full path */
#endif
(
	char  *fname,
	char  *searchpath,
	int  mode
)
{
	static char  pname[PATH_MAX];
	char uname[512];
	char  *cp;
	int i;

	if (fname == NULL) { return(NULL); }

	pname[0] = '\0';		/* check for full specification */

	if (ISABS(fname)) { /* absolute path */
		strncpy(pname, fname, sizeof(pname)-1);
	} else {
		switch (*fname) {
			case '.':				/* relative to cwd */
				strncpy(pname, fname, sizeof(pname)-1);
				break;
			case '~':				/* relative to home directory */
				fname++;
				cp = uname;
				for (i=0;i<sizeof(uname)&&*fname!='\0'&&!ISDIRSEP(*fname);i++)
					*cp++ = *fname++;
				*cp = '\0';
				cp = gethomedir(uname, pname, sizeof(pname));
				if(cp == NULL) return NULL;
				strncat(pname, fname, sizeof(pname)-strlen(pname)-1);
				break;
		}
	}
	if (pname[0])		/* got it, check access if search requested */
		return(searchpath==NULL||access(pname,mode)==0 ? pname : NULL);

	if (searchpath == NULL) {			/* don't search */
		strncpy(pname, fname, sizeof(pname)-1);
		return(pname);
	}
	/* check search path */
	do {
		cp = pname;
		while (*searchpath && (*cp = *searchpath++) != PATHSEP) {
			cp++;
		}
		if (cp > pname && !ISDIRSEP(cp[-1])) {
			*cp++ = DIRSEP;
		}
		strncpy(cp, fname, sizeof(pname)-strlen(pname)-1);
		if (access(pname, mode) == 0)		/* file accessable? */
			return(pname);
	} while (*searchpath);
	/* not found */
	return(NULL);
}
Пример #9
0
/*
 * For the pine composer, we don't want to take over the whole screen
 * for editing.  the first some odd lines are to be used for message 
 * header information editing.
 */
void
edinit(char bname[])
{
    register BUFFER *bp;
    register WINDOW *wp;

    if(Pmaster)
      func_init();

    bp = bfind(bname, TRUE, BFWRAPOPEN);    /* First buffer         */
    wp = (WINDOW *) malloc(sizeof(WINDOW)); /* First window         */

    if (bp==NULL || wp==NULL){
	if(Pmaster)
	  return;
	else
	  exit(1);
    }

    curbp  = bp;                            /* Make this current    */
    wheadp = wp;
    curwp  = wp;
    wp->w_wndp  = NULL;                     /* Initialize window    */
    wp->w_bufp  = bp;
    bp->b_nwnd  = 1;                        /* Displayed.           */
    wp->w_linep = bp->b_linep;
    wp->w_dotp  = bp->b_linep;
    wp->w_doto  = 0;
    wp->w_markp = wp->w_imarkp = NULL;
    wp->w_marko = wp->w_imarko = 0;
    bp->b_linecnt = -1;

    if(Pmaster){
	term.t_mrow = Pmaster->menu_rows;
	wp->w_toprow = ComposerTopLine = COMPOSER_TOP_LINE;
	wp->w_ntrows = term.t_nrow - COMPOSER_TOP_LINE - term.t_mrow;
	fillcol = Pmaster->fillcolumn;
	strncpy(opertree,
	       (Pmaster->oper_dir && strlen(Pmaster->oper_dir) < NLINE)
	         ? Pmaster->oper_dir : "", sizeof(opertree));
	opertree[sizeof(opertree)-1] = '\0';
	input_cs = Pmaster->input_cs;
    }
    else{
	if(sup_keyhelp)
	  term.t_mrow = 0;
	else
	  term.t_mrow = 2;

        wp->w_toprow = 2;
        wp->w_ntrows = term.t_nrow - 2 - term.t_mrow;
	if(userfillcol > 0)			/* set fill column */
	  fillcol = userfillcol;
	else
	  fillcol = term.t_ncol - 6;
    }

    /*
     * MDSCUR mode implies MDTREE mode with a opertree of home directory,
     * unless opertree has been set differently.
     */
    if((gmode & MDSCUR) && !opertree[0]){
      strncpy(opertree, gethomedir(NULL), sizeof(opertree));
      opertree[sizeof(opertree)-1] = '\0';
    }

    if(*opertree)
      fixpath(opertree, sizeof(opertree));

    wp->w_force = 0;
    wp->w_flag  = WFMODE|WFHARD;            /* Full.                */
}
Пример #10
0
MI_Result Initialize()
{
    MI_Result r;
    static size_t nbufsize = 256;
    g_batch = Batch_New(64);
    if (!g_batch)
        return MI_RESULT_SERVER_LIMITS_EXCEEDED;

    g_dirpath = (char*)Batch_Get(g_batch, nbufsize);
    g_logfilepath = (char*)Batch_Get(g_batch, nbufsize);
    if (!g_logfilepath || !g_dirpath)
    {
        r = MI_RESULT_SERVER_LIMITS_EXCEEDED;
        goto error;
    }

    sprintf(g_dirpath, dirformat, gethomedir(), "indicationlog");
    if (Isdir(g_dirpath) == PAL_FALSE)
    {
        if (Mkdir(g_dirpath, 0777) != 0)
        {
            r = MI_RESULT_FAILED;
            goto error;
        }
    }
    sprintf(g_logfilepath, filenameformat, g_dirpath, "provider", "log");

#if !defined(_MSC_VER)
    {
        //
        // Delete file if larger than certain size
        //
        struct stat buf;
        if (stat(g_logfilepath, &buf) == 0)
        {
            if ( (unsigned long)buf.st_size > 0x800000UL )
                File_Remove(g_logfilepath);
        }
    }
#endif

    g_logfile = File_Open(g_logfilepath, "a+");
    if (!g_logfile)
    {
        r = MI_RESULT_FAILED;
        goto error;
    }

    Config_Initialize(&cfgTest_Indication);
    Config_Initialize(&cfgL_IndicationC1);
    Config_Initialize(&cfgL_IndicationC2);
    Config_Initialize(&cfgL_IndicationC3);
    Config_Initialize(&cfgR_IndicationC1);
    Config_Initialize(&cfgR_IndicationC2);
    Config_Initialize(&cfgR_IndicationC3);
    Config_Initialize(&cfgTest_Class);
    Config_Initialize(&cfgL_LifecycleC1);
    Config_Initialize(&cfgL_LifecycleC2);
    Config_Initialize(&cfgR_LifecycleC1);
    Config_Initialize(&cfgR_LifecycleC2);
    

    ReloadConfig();

    LOGMSG(("\r\n\r\n\r\n\r\n==================================================="));
    LOGMSG(("Initialize"));

    return MI_RESULT_OK;

error:
    if (g_logfile)
    {
        File_Close(g_logfile);
        g_logfile = NULL;
    }
    if (g_batch)
    {
        Batch_Delete(g_batch);
        g_batch = NULL;
    }
    return r;
}