Nov 22, 2009

My Unix Project "unix" - A Story about a Unix Project

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Operating Systems > UNIX (Other Flavours)

My Unix Project "unix" - A Story about a Unix Project

HannahI
Hey, Guys.
Moderators, If there is a better place for this, please move it! biggrin.gif
Let's begin.

I made a project that ran on Unix. bUt that project was not any old project. It was special! It was special becuase it was Unix, except it was running on Unix. If you would like to take it for a test run your self, just leave me a comment to post it! Plus, it looks like Unix.

Bye

Comment/Reply (w/o sign-up)

yordan
Hmm! Really very misterious! So, it's Unix, but it's Unix, and it runs on Unix but it's Unix! Am I already sleeping, or are you kidding?

Comment/Reply (w/o sign-up)

HannahI
Here is the code.
Start.c
CODE

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "start.h"
#define TRUE 1
#define FALSE 0

int login() {
printf("Welcome to the Computer!\n");
printf("Type your username:\n");
printf("new-host-2:~ user$ ");

char username[256];
scanf("%s", username);

if(strcmp(username, "Hannah") != 0) {
printf("\n Wrong! Type again:\n");
printf("new-host-2:~ user$ ");
scanf("%s", username);

if(strcmp(username, "Hannah") != 0) {
printf("\n Hint: You; Type:\n");
printf("new-host-2:~ user$ ");
scanf("%s", username);

if(strcmp(username, "Hannah") != 0) {
exit(0);
}
}
}


printf("\n Great! Password, Type ~ at the end:\n");
printf("new-host-2:~ user$ ");

char password[256];
scanf("%s", password);
if(strcmp(password, "password") != 0) {
printf("Type Again:\n");
printf("new-host-2:~ user$ ");
scanf("%s", password);

if(strcmp(password, "password") != 0) {
printf("Hint: Girl; Type:\n");
printf("new-host-2:~ user$ ");
scanf("%s", password);

if(strcmp(password, "password") != 0) {
exit(0);
}
}
}

return 0;

}

char usernames[16][256];

char passwords[16][256];

void setuser(char* username, char* password, int userID)
{
int x;
int bFound = FALSE;

if(userID>15) return;
if(userID<0){

for(x=0;x<16;x++){
if(usernames[x]==0){
userID = x; bFound = TRUE; break;
}
}



if(bFound == FALSE) {
printf("Your account could not be created. Try again later.");
return;
}
}

strcpy(usernames[userID], username);
strcpy(passwords[userID], password);

}

int loadUserDatabase()
{
FILE *fp;
if(!(fp=fopen("users.dat","rb"))){
memset(usernames, 0, sizeof(usernames));
memset(passwords, 0, sizeof(passwords));

} else {
fread( usernames, sizeof(usernames), 1, fp);
fread( passwords, sizeof(passwords), 1, fp);
}
return 0;
}

int saveUserDatabase()
{
FILE* fp;
if(!(fp=fopen("users.dat","wb"))){
fwrite(usernames, sizeof(usernames), 1, fp);
fwrite(passwords, sizeof(passwords), 1, fp);
}
return 0;
}

Start.h
CODE

int login();
void setuser(char* username, char* password, int userID);
int saveUserDatabase();
int loadUserDatabase();

Main.c
CODE

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

void write() {
for(;;){
printf("Would you like to type; 4 lines only? Type Yes or No:\n");
char line1[256];
char line2[256];
char line3[256];
char line4[256];
char response[256];

printf("new-host-2:~ user$ ");
scanf("%s", response);
if(strcmp(response, "Yes") == 0) {
scanf("%s", line1);
printf("\n");
scanf("%s", line2);
printf("\n");
scanf("%s", line3);
printf("\n");
scanf("%s", line4);
} else if(strcmp(response, "No") == 0) {
break;
} else {
printf("-bash unknown command\n");
}
}

}

void ask() {
for(;;) {
char response[256];
printf("Would you like to do any of the following\n");
printf("Writing, Logout\n ");
printf("new-host-2:~ user$ ");
scanf("%s",response);
if(strcmp(response, "Writing") == 0) {
write();
} else if(strcmp(response, "Logout") == 0) {
break;
} else {
printf("-bash unkwown command\n");
}
}
}


int main (int argc, const char * argv[]) {

loadUserDatabase();
setuser("Derek", "Hannah", 1);
login();
ask();
saveUserDatabase();
return 1;
}

 

 

 


Comment/Reply (w/o sign-up)

yordan
Hm!
I would say that this is not Unix.
This is close to emulating "getty", the process in charge of connecting the users.
getty is not Unix.
It's in charge of opening the communication channel (usually a tty), ask for the username and password, verify in /etc/passwords, and then fork a shell.
And even this shell is not Unix, the shell is a command line interpreter.
Then comes the master philosophical problem : what is Unix ?
I would say that Unix is "init", the father of all the processes in a running Unix machine.

Comment/Reply (w/o sign-up)

HannahI
But still, pretty cool?

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for My, Unix, Project, "unix"
advertisement



My Unix Project "unix" - A Story about a Unix Project

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com