Пример #1
0
void fileaction_setowngrp(char *filename, int fileref)
{
    int uid, gid;
    uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
    gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
    chown (filename, uid, gid);
}
Пример #2
0
/*
 * adduser will take a login_name as its first parameter.
 *
 * home
 * shell
 * gecos
 *
 * can be customized via command-line parameters.
 * ________________________________________________________________________ */
int adduser_main(int argc, char **argv)
{
	struct passwd pw;
	const char *login;
	const char *gecos = default_gecos;
	const char *home = NULL;
	const char *shell = DEFAULT_SHELL;
	const char *usegroup = NULL;
	int flags;
	int setpass = 1;
	int makehome = 1;

	/* init */
	if (argc < 2) {
		bb_show_usage();
	}
	/* get args */
	flags = bb_getopt_ulflags(argc, argv, "h:g:s:G:DSH", &home, &gecos, &shell, &usegroup);

	if (flags & SETPASS) {
		setpass = 0;
	}
	if (flags & MAKEHOME) {
		makehome = 0;
	}

	/* got root? */
	if_i_am_not_root();

	/* get login */
	if (optind >= argc) {
		bb_error_msg_and_die( "no user specified");
	}
	login = argv[optind];

	/* create string for $HOME if not specified already */
	if (!home) {
		home = concat_path_file(default_home_prefix, login);
	}
#ifdef CONFIG_FEATURE_SHADOWPASSWDS
	/* is /etc/shadow in use? */
	shadow_enabled = (0 == access(bb_path_shadow_file, F_OK));
#endif

	/* create a passwd struct */
	pw.pw_name = (char *)login;
	pw.pw_passwd = (char *)default_passwd;
	pw.pw_uid = 0;
	pw.pw_gid = 0;
	pw.pw_gecos = (char *)gecos;
	pw.pw_dir = (char *)home;
	pw.pw_shell = (char *)shell;

	if (usegroup) {
		/* Add user to a group that already exists */
		pw.pw_gid = bb_xgetgrnam(usegroup);
		/* exits on error */
	}

	/* grand finale */
	return adduser(bb_path_passwd_file, &pw, makehome, setpass);
}