Exemple #1
0
/*
** Name: LOmkingpath	- make INGRES location's area path
**
** Description:
**	Makes missing subdirectories in a location's area path.
**
** Inputs:
**	area	"device" that the location is on
**	what	path to db, ckp, dmp, work, jnl
**	loc	set to full path of location
**	
** Outputs:
**	none
**
** Returns:
**	LO_NULL_ARG	area or what were NULL or empty
**	LO_NO_SUCH	required path component does not exist
**
** History:
**	03-dec-2003 (abbjo03)
**	    Created.
*/
STATUS
LOmkingpath(
char		*area,		/* "device" that the database is on */
char		*what,		/* path to db, ckp, dmp, work, or jnl */
LOCATION	*loc)		/* set to full path of location */
{
    STATUS	status;
    char	path[MAX_LOC+1];
    i4		flags;
    LOINFORMATION	info;

    /* check for legal arguments */
    if (area == NULL || *area == EOS || STtrmwhite(area) == 0 ||
		what == NULL || *what == EOS)
	return LO_NULL_ARG;

    LOdev_to_root(area, path);
    if ((status = LOfroms(PATH, path, loc)) != OK)
	return status;
    flags = LO_I_TYPE;
    if (LOinfo(loc, &flags, &info))
	return LO_NO_SUCH;
    if ((flags & LO_I_TYPE) == 0 || info.li_type != LO_IS_DIR)
	return LO_NO_SUCH;

    LOfaddpath(loc, SystemLocationSubdirectory, loc);
    if ((status = LOfroms(PATH, path, loc)) != OK)
	return status;
    flags = LO_I_TYPE;
    if (LOinfo(loc, &flags, &info))
    {
	if ((status = LOcreate(loc)) != OK)
	    return status;
    }
    /* Set protections */
    if (setperms(loc, PROT_SRWE_ORWE_G_WRE) != OK)
	return FAIL;
	
    LOfaddpath(loc, what, loc);
    if ((status = LOfroms(PATH, path, loc)) != OK)
	return status;
    flags = LO_I_TYPE;
    if (LOinfo(loc, &flags, &info))
    {
	if ((status = LOcreate(loc)) != OK)
	    return status;
    }
    if (setperms(loc, PROT_SRWE_ORWE_G_WRE) != OK)
	return FAIL;

    flags = LO_I_PERMS;
    if ((status = LOinfo(loc, &flags, &info)) == OK &&
		(info.li_perms & LO_P_WRITE) == 0)
	status = LO_NO_PERM;

    return status;
}
Exemple #2
0
Fichier : xyz.c Projet : fbbs/fbbs
//      pager与msg设定
//
int x_userdefine() {
	int id;
	unsigned int newlevel;
	set_user_status(ST_USERDEF);
	if (!(id = getuser(currentuser.userid))) {
		screen_move_clear(3);
		screen_printf("错误的使用者 ID...");
		pressreturn();
		screen_clear();
		return 0;
	}
	screen_move(1, 0);
	screen_clrtobot();
	screen_move(2, 0);
	use_define = 1;
	newlevel = setperms(lookupuser.userdefine, "参数", NUMDEFINES,
			showperminfo);
	screen_move(2, 0);
	if (newlevel == lookupuser.userdefine)
		screen_printf("参数没有修改...\n");
	else {
		lookupuser.userdefine = newlevel;
		currentuser.userdefine = newlevel;
		substitut_record(PASSFILE, &lookupuser, sizeof(struct userec), id);
		screen_printf("新的参数设定完成...\n\n");
	}
	pressreturn();
	screen_clear();
	use_define = 0;
	return 0;
}
Exemple #3
0
//      pager与msg设定
//
int x_userdefine() {
    int id;
    unsigned int newlevel;
    set_user_status(ST_USERDEF);
    if (!(id = getuser(currentuser.userid))) {
        screen_move_clear(3);
        //% prints("错误的使用者 ID...");
        prints("\xb4\xed\xce\xf3\xb5\xc4\xca\xb9\xd3\xc3\xd5\xdf ID...");
        pressreturn();
        screen_clear();
        return 0;
    }
    screen_move(1, 0);
    screen_clrtobot();
    screen_move(2, 0);
    use_define = 1;
    //% newlevel = setperms(lookupuser.userdefine, "参数", NUMDEFINES,
    newlevel = setperms(lookupuser.userdefine, "\xb2\xce\xca\xfd", NUMDEFINES,
                        showperminfo);
    screen_move(2, 0);
    if (newlevel == lookupuser.userdefine)
        //% prints("参数没有修改...\n");
        prints("\xb2\xce\xca\xfd\xc3\xbb\xd3\xd0\xd0\xde\xb8\xc4...\n");
    else {
        lookupuser.userdefine = newlevel;
        currentuser.userdefine = newlevel;
        substitut_record(PASSFILE, &lookupuser, sizeof(struct userec), id);
        //% prints("新的参数设定完成...\n\n");
        prints("\xd0\xc2\xb5\xc4\xb2\xce\xca\xfd\xc9\xe8\xb6\xa8\xcd\xea\xb3\xc9...\n\n");
    }
    pressreturn();
    screen_clear();
    use_define = 0;
    return 0;
}
Exemple #4
0
FILE *
ns_os_openfile(const char *filename, mode_t mode, isc_boolean_t switch_user) {
	char strbuf[ISC_STRERRORSIZE], *f;
	FILE *fp;
	int fd;

	/*
	 * Make the containing directory if it doesn't exist.
	 */
	f = strdup(filename);
	if (f == NULL) {
		isc__strerror(errno, strbuf, sizeof(strbuf));
		ns_main_earlywarning("couldn't strdup() '%s': %s",
				     filename, strbuf);
		return (NULL);
	}
	if (mkdirpath(f, ns_main_earlywarning) == -1) {
		free(f);
		return (NULL);
	}
	free(f);

	if (switch_user && runas_pw != NULL) {
#ifndef HAVE_LINUXTHREADS
		gid_t oldgid = getgid();
#endif
		/* Set UID/GID to the one we'll be running with eventually */
		setperms(runas_pw->pw_uid, runas_pw->pw_gid);

		fd = safe_open(filename, mode, ISC_FALSE);

#ifndef HAVE_LINUXTHREADS
		/* Restore UID/GID to root */
		setperms(0, oldgid);
#endif /* HAVE_LINUXTHREADS */

		if (fd == -1) {
#ifndef HAVE_LINUXTHREADS
			fd = safe_open(filename, mode, ISC_FALSE);
			if (fd != -1) {
				ns_main_earlywarning("Required root "
						     "permissions to open "
						     "'%s'.", filename);
			} else {
				ns_main_earlywarning("Could not open "
						     "'%s'.", filename);
			}
			ns_main_earlywarning("Please check file and "
					     "directory permissions "
					     "or reconfigure the filename.");
#else /* HAVE_LINUXTHREADS */
			ns_main_earlywarning("Could not open "
					     "'%s'.", filename);
			ns_main_earlywarning("Please check file and "
					     "directory permissions "
					     "or reconfigure the filename.");
#endif /* HAVE_LINUXTHREADS */
		}
	} else {
		fd = safe_open(filename, mode, ISC_FALSE);
	}

	if (fd < 0) {
		isc__strerror(errno, strbuf, sizeof(strbuf));
		ns_main_earlywarning("could not open file '%s': %s",
				     filename, strbuf);
		return (NULL);
	}

	fp = fdopen(fd, "w");
	if (fp == NULL) {
		isc__strerror(errno, strbuf, sizeof(strbuf));
		ns_main_earlywarning("could not fdopen() file '%s': %s",
				     filename, strbuf);
	}

	return (fp);
}