示例#1
0
/* append a new user to the passwd file */
static int addgroup(char *group, gid_t gid, const char *user)
{
	FILE *file;
	struct group gr;

	/* make sure gid and group haven't already been allocated */
	gr.gr_gid = gid;
	gr.gr_name = group;
	if (group_study(&gr))
		return 1;

	/* add entry to group */
	file = bb_xfopen(bb_path_group_file, "a");
	/* group:passwd:gid:userlist */
	fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user);
	fclose(file);

#if ENABLE_FEATURE_SHADOWPASSWDS
	file = bb_xfopen(bb_path_gshadow_file, "a");
	fprintf(file, "%s:!::\n", group);
	fclose(file);
#endif

	/* return 1; */
	return 0;
}
示例#2
0
/* append a new user to the passwd file */
static int addgroup(const char *filename, char *group, gid_t gid)
{
	FILE *etc_group;

#ifdef TLG_FEATURE_SHADOWPASSWDS
	FILE *etc_gshadow;
	char *gshadow = GSHADOW_FILE;
#endif							/* TLG_FEATURE_SHADOWPASSWDS */

	struct group gr;

	/* group:passwd:gid:userlist */
	const char *entryfmt = "%s:%s:%d:%s\n";

	/* make sure gid and group haven't already been allocated */
	gr.gr_gid = gid;
	gr.gr_name = group;
	if (group_study(filename, &gr))
		return 1;

	/* add entry to group */
	etc_group = fopen(filename, "a");
	if (!etc_group) {
		perror_msg_and_die("%s", filename);
	}
	fprintf(etc_group, entryfmt, group, default_passwd, gr.gr_gid, "");
	fclose(etc_group);

#ifdef TLG_FEATURE_SHADOWPASSWDS
	/* add entry to gshadow if necessary */
	if (access(gshadow, W_OK) == 0) {
		etc_gshadow = fopen(gshadow, "a");
		if (!etc_gshadow) {
			perror_msg_and_die("%s", gshadow);
		}
		fprintf(etc_gshadow, "%s:!::\n", group);
		fclose(etc_gshadow);
	}
#endif							/* TLG_FEATURE_SHADOWPASSWDS */

	/* return 1; */
	return 0;
}
示例#3
0
/* append a new user to the passwd file */
static int addgroup(const char *filename, char *group, gid_t gid, const char *user)
{
	FILE *etc_group;

#ifdef CONFIG_FEATURE_SHADOWPASSWDS
	FILE *etc_gshadow;
#endif

	struct group gr;

	/* group:passwd:gid:userlist */
	static const char entryfmt[] = "%s:%s:%d:%s\n";

	/* make sure gid and group haven't already been allocated */
	gr.gr_gid = gid;
	gr.gr_name = group;
	if (group_study(filename, &gr))
		return 1;

	/* add entry to group */
	etc_group = bb_xfopen(filename, "a");

	fprintf(etc_group, entryfmt, group, default_passwd, gr.gr_gid, user);
	fclose(etc_group);


#ifdef CONFIG_FEATURE_SHADOWPASSWDS
	/* add entry to gshadow if necessary */
	if (access(bb_path_gshadow_file, F_OK|W_OK) == 0) {
		etc_gshadow = bb_xfopen(bb_path_gshadow_file, "a");
		fprintf(etc_gshadow, "%s:!::\n", group);
		fclose(etc_gshadow);
	}
#endif

	/* return 1; */
	return 0;
}