commit 530bb5c584f9d96065a3d5f6df880336fd403ddd parent f4dc0887a905d40623c76ae4b993345903f43b1b Author: qorg11 <qorg@vxempire.xyz> Date: Mon, 15 Jun 2020 14:41:29 +0200 Added chown.c Please someone use strtok() to get the group -R flag is needed as always Diffstat:
A | src/chown.c | | | 28 | ++++++++++++++++++++++++++++ |
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/chown.c b/src/chown.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <pwd.h> + +/* TODO: use strtok() to get the group */ + +int +main(int argc, char *argv[]) +{ + if(argc == 1) + { + fprintf(stderr,"No command given\n"); + return 1; + } + const char *user = argv[1]; + + struct passwd *data = getpwnam(user); + uid_t uid = data->pw_gid; + gid_t gid = data->pw_gid; /* Change this with the strtok() thing */ + + for(int i = 2; i<=argc; i++) + { + chown(argv[i],uid,gid); + } + + return 0; +}