Skip to content

Instantly share code, notes, and snippets.

@thefotios
Created October 13, 2011 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefotios/1283410 to your computer and use it in GitHub Desktop.
Save thefotios/1283410 to your computer and use it in GitHub Desktop.
A school project
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <sys/types.h>
#include <time.h>
#define emailAddrLen 33
#define IDStringLen 9
#define realNameLen 33
int main(int argc, char *argv[])
{
// Some strings
const char* usage = "Usage %s <login ID> <real name>\n";
const char* current = "can't get current user name! \n";
const char* impersonate = "\n Hey! Are you trying to impersonate someone else?\n\n";
const char* realname = "\n Hey! Do you forget you real name?\n\n";
const char* success = "\nCongrats, you have got the buffer overflow working on %s! \n\n";
const char* failure =
".\n.\n.\n"
"Hmmm... looks like you have not got the buffer overflow working.\n"
"Keep trying, once your result is correct, I will tell you.\n"
"Happy hacking :)\n"
".\n.\n.\n";
char selfEmailAddr[emailAddrLen] = "xwangc@gmu.edu";
char IDString[IDStringLen];
char toEmailAddr[emailAddrLen];
char realName[realNameLen];
struct passwd *pw;
char* username;
char* fullname;
time_t rawtime;
struct tm *timeinfo;
// Check length of arguments
if( argc < 3 ){
printf(usage, argv[0]);
exit(0);
}
// Check pwuid and set the results
if((pw = getpwuid(getuid())) == NULL){
printf(current);
exit(1);
}
username = pw->pw_name;
fullname = pw->pw_gecos;
// Copy the arguments
strcpy (IDString, argv[1]);
strcpy (realName, argv[2]);
// Checking to see if the username matches
if(strcmp(username,IDString) != 0){
printf(impersonate);
exit(2);
}
// Make sure that the name entered starts with the fullname
if( (strlen(realName) < strlen(fullname)) ||
(strncmp(fullname, realName, strlen(fullname)) != 0) ){
printf(realname);
exit(2);
}
// Compare the 2 email addresses
if(strcmp(selfEmailAddr,toEmailAddr) != 0){
printf(failure);
exit(1);
}else{
time( &rawtime );
timeinfo = localtime( &rawtime );
printf(success, asctime( timeinfo ));
exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment