2014-06-08 10:13:29 +04:00
|
|
|
/* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2013-2014 Kevin Lange
|
|
|
|
*/
|
2012-01-28 04:04:39 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
|
|
|
* Who Am I?
|
|
|
|
*
|
|
|
|
*/
|
2014-05-12 04:40:16 +04:00
|
|
|
#include <unistd.h>
|
2012-01-28 04:04:39 +04:00
|
|
|
#include <stdio.h>
|
2012-01-29 08:27:37 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-28 04:04:39 +04:00
|
|
|
|
|
|
|
#define LINE_LEN 4096
|
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
FILE * passwd = fopen("/etc/passwd", "r");
|
|
|
|
char line[LINE_LEN];
|
|
|
|
|
2014-05-12 04:40:16 +04:00
|
|
|
int uid = getuid();
|
2012-01-28 04:04:39 +04:00
|
|
|
|
|
|
|
while (fgets(line, LINE_LEN, passwd) != NULL) {
|
|
|
|
|
|
|
|
line[strlen(line)-1] = '\0';
|
|
|
|
|
|
|
|
char *p, *tokens[10], *last;
|
|
|
|
int i = 0;
|
|
|
|
for ((p = strtok_r(line, ":", &last)); p;
|
|
|
|
(p = strtok_r(NULL, ":", &last)), i++) {
|
|
|
|
if (i < 511) tokens[i] = p;
|
|
|
|
}
|
|
|
|
tokens[i] = NULL;
|
|
|
|
|
|
|
|
if (atoi(tokens[2]) == uid) {
|
|
|
|
printf("%s\n", tokens[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(passwd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|