Skip to main content

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.

Comments

Popular posts from this blog

Architecture Complexity

Here are the items to consider: Coding to an interface Service Oriented Architecture Automated Testing Domain Driven Design Custom Data Access Layer Layered architecture Complexity is relatively equal the number of lines of code. Note that complexity is not bad. It must be justified.

Android Studio:Unknown Host Error

After installing Android Studio, I got the following error: Unknown host 'services.gradle.org'. Please ensure the host name is correct. If you are behind an HTTP proxy, please configure the proxy settings either in Android Studio or Gradle. Consult IDE log for more details (Help | Show Log) Solution File --> Settings --> HTTP Proxy --> Auto-detect proxy settings

Brain as the tool of the spirit

The mind as the bridge between pure consciousness and the body in which that consciousness temporarily resides.