#include <iostream>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
using namespace std;
class UID_GID
{
private:
uid_t uid_value;
gid_t gid_value;
struct group* group_buff;
struct passwd* passwd_buff;
char* user_name;
char* group_name;
public:
UID_GID()
{
uid_value=geteuid();
gid_value=getegid();
passwd_buff=getpwuid(uid_value);
group_buff=getgrgid(gid_value);
user_name=strdup(passwd_buff->pw_name);
group_name=strdup(group_buff->gr_name);
}
char *write_User()
{
return user_name;
}
char *write_Group()
{
return group_name;
}
};
int main(int argc, char **argv)
{
UID_GID User_Group;
cout<<"User : "<<User_Group.write_User()<<endl;
cout<<"Group: "<<User_Group.write_Group()<<endl;
return 0;
}
Brak komentarzy:
Prześlij komentarz