This commit is contained in:
Your Name 2024-05-31 18:06:54 +03:00
parent a51d35681b
commit 6c318515a3
3 changed files with 9 additions and 12 deletions

2
configs/group Normal file
View File

@ -0,0 +1,2 @@
root::0:root

4
configs/os-release Normal file
View File

@ -0,0 +1,4 @@
NAME="Plain Os"
ID=plainos
VERSION_ID=0.1
PRETTY_NAME="PlainOs/Linux 0.1 "

View File

@ -16,19 +16,11 @@ char r_flag;
char u_flag;
int print_groups(const struct passwd *pwd, const char *fmt, const int flag) {
int ngroups = 0;
getgrouplist(pwd->pw_name, pwd->pw_gid, NULL, &ngroups);
if (ngroups <= 0)
gid_t groups[NGROUPS_MAX];
int ngroups = NGROUPS_MAX;
if (getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups) < 0)
return 1;
gid_t *groups = malloc(ngroups * sizeof(gid_t *));
if (groups == NULL) {
fprintf(stderr, "id: malloc failed\n");
return 1;
}
getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups);
for (int i = 0; i < ngroups; i++) {
struct group *grp = getgrgid(groups[i]);
if (grp && !n_flag)
@ -43,7 +35,6 @@ int print_groups(const struct passwd *pwd, const char *fmt, const int flag) {
putchar(' ');
}
free(groups);
return 0;
}