Sunday, February 19, 2006

Verify user in /etc/passwd

This is a product of wonder.


In file verify.c



#include <stdio.h>
#include <string.h>

#define MAX_LENGTH 1024

int is_local(char *user)
{
FILE *fd;
char line[MAX_LENGTH];
int local = 0;

if(!(fd = fopen("/etc/passwd", "r"))) {
puts("Can't read /etc/passwd, exiting.");
exit(1);
}

while(fgets(line, MAX_LENGTH, fd) > 0) {
if(!strncmp(line, user, strlen(user))) {
local = 1;
break;
}
}
fclose(fd);
return local;
}

Use at your own risk.


Disclaimer: Please refer to my first post ‘General notice’


Posted using Scott Yang’s mtsend.py python script. Thanks to Niel for his cool vim mappings.

No comments: