Created
April 9, 2018 14:15
-
-
Save sergioperez/919238b7da1825ee239a0985d672036b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <pwd.h> | |
int main() | |
{ | |
register struct passwd *pw; | |
register uid_t uid; | |
uid = geteuid(); //Get userID | |
pw = getpwuid(uid); //Get userID data | |
if(pw) | |
{ | |
//Print username | |
printf("Executed as {%s}\n.", pw->pw_name); | |
exit(EXIT_SUCCESS); | |
} | |
fprintf(stderr, "cannot find username for UID %u/n", (unsigned)uid); | |
exit(EXIT_FAILURE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment