Created
October 28, 2020 20:19
-
-
Save atamrawi/38af7f0f75de6cd7d941e494ead791f1 to your computer and use it in GitHub Desktop.
Assignment 4 - Problem 3
This file contains 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 <string.h> | |
#include <sys/types.h> | |
#include <stdio.h> | |
struct auth { | |
char name[32]; | |
int auth; | |
}; | |
struct auth *authO; | |
char *service; | |
struct auth *authPtr; | |
int main(int argc, char **argv) { | |
char line[128]; | |
int pos = 0; | |
while(1) { | |
printf("[ auth = %p, service = %p , authPtr = %p ]\n", authO, service, authPtr); | |
if(fgets(line, sizeof(line), stdin) == NULL) { | |
break; | |
} | |
if(strncmp(line, "auth ", 5) == 0) { | |
authO = malloc(sizeof(struct auth)); | |
memset(authO, 0, sizeof(struct auth)); | |
if(strlen(line + 5) < 31) { | |
strcpy(authO->name, line + 5); | |
} | |
} | |
if(strncmp(line, "reset", 5) == 0) { | |
free(authO); | |
} | |
if(strncmp(line, "alias", 5) == 0) { | |
authPtr = authO; | |
} | |
if(strncmp(line, "service", 6) == 0) { | |
if(service == NULL) { | |
service = malloc(sizeof(line)); | |
memset(service, 0, sizeof(line)); | |
} | |
if(strlen(line + 6) < 15) { | |
strcat(service, line + 6); | |
pos += strlen(line + 6); | |
} | |
} | |
if(strncmp(line, "login", 5) == 0) { | |
if(authPtr->auth) { | |
printf("you have logged in already!\n"); | |
} else { | |
printf("please enter your password\n"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is based on a Youtube video by liveoverflow channel