diff --git a/src/bin/login2/Makefile b/src/bin/login2/Makefile new file mode 100644 index 0000000..b5fa30e --- /dev/null +++ b/src/bin/login2/Makefile @@ -0,0 +1,56 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = login + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#LIBRARIES = ../../lib/libc/libc.so + +INCLUDES = -I../../include.new + +LIBRARIES = ../../lib/libc/libc.so ../../lib/ubix_api/ubix_api.so + +STARTUP = ../../lib/csu/*.o + + + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) +# strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/login2/main.c b/src/bin/login2/main.c new file mode 100644 index 0000000..d764542 --- /dev/null +++ b/src/bin/login2/main.c @@ -0,0 +1,152 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +//#include +#include +//#include +#include + +struct passwd { + char username[32]; + char password[32]; + int uid; + int gid; + char shell[128]; + char realname[256]; + char path[256]; + }; + +static char *pgets(char *string) { + int count=0,ch=0; + while (1) { + ch = fgetc(stdin); + if(ch == 10) { + printf("\n"); + break; + } + else if(ch == 8 && count > 0) count-=2; + else if(ch == 0) count--; + else string[count] = ch; + if (ch != 8) printf("*"); + count++; + } + string[count] = '\0'; + return(string); + } + +int main() { + FILE *fd; + int shellPid = 0,i = 0x0; + char userName[32]; + char passWord[32]; + char *data2 = 0x0; + struct passwd *data = 0x0; + + + if ((getuid() != 0x0) && (getgid() != 0x0)) { + printf("This Application Must Be Run As Root.\n"); + exit(-1); + } + if ((data = (struct passwd *)malloc(0x1000)) == 0x0) { + printf("Malloc Failed\n"); + exit(0x1); + } + + fd = fopen("sys:/etc/userdb","r"); + if (fd == 0x0) { + printf("Missing User Database.\n"); + exit(0x1); + } + + fread(data,0x1000,0x1,fd); + fclose(fd); + + if ((data2 = (char *)malloc(384)) == 0x0) { + printf("Malloc Failed\n"); + exit(0x1); + } + +/* we need to move this into the libc for getpwent(), etc */ +/* + foo = auth("root", "user"); + if(foo != -1) + printf("yay\n"); + else + printf("damn\n"); +*/ + + login: + printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)"); + printf("\n\nLogin: "); + printf("Test: [%i]\n",ubix_test()); + gets((char *)&userName); + printf("Password: "); + gets((char *)&passWord); + //pgets((char *)&passWord); + for (i=0x0;i<(4096/sizeof(struct passwd));i++) { + if (0x0 == strcmp(userName,data[i].username)) { + if (0x0 == strcmp(passWord,data[i].password)) { + shellPid = old_fork(); + if (shellPid == 0x0) { + if (setuid(data[i].uid) != 0x0) { + printf("Set UID Failed\n"); + } + if (setgid(data[i].gid) != 0x0) { + printf("Set GID Failed\n"); + } + fd = 0x0; + fd = fopen("sys:/etc/motd","r"); + //if ((fd = fopen("sys:/motd","r")) == 0x0) { + if (fd == 0x0) { + printf("No MOTD"); + } + else { + fread(data2,384,1,fd); + printf("%s\n",data2); + } + fclose(fd); + //chdir(data[i].path); + chdir("sys:/bin/"); + // exec(data[i].shell,0x0); + printf("Error: Problem Starting Shell\n"); + exit(-1); + } + else { +/* + while (pidStatus(shellPid) > 0) { + sched_yield(); + } +*/ + goto login; + } + } + } + } + printf("Login Incorrect!\n"); + goto login; + return(0x0); + } + diff --git a/src/include.new/ubixos/api.h b/src/include.new/ubixos/api.h new file mode 100644 index 0000000..9bd8422 --- /dev/null +++ b/src/include.new/ubixos/api.h @@ -0,0 +1 @@ +int ubix_test(); diff --git a/src/include/api/ubix.h b/src/include/api/ubix.h index 9bd8422..d372150 100644 --- a/src/include/api/ubix.h +++ b/src/include/api/ubix.h @@ -1 +1,2 @@ int ubix_test(); +pid_t old_fork(); \ No newline at end of file diff --git a/src/lib/ubix_api/Makefile b/src/lib/ubix_api/Makefile index ceb1c17..55e3fb8 100644 --- a/src/lib/ubix_api/Makefile +++ b/src/lib/ubix_api/Makefile @@ -9,13 +9,14 @@ OBJS = #Sub Sections -SUBS = ./test/*.o +SUBS = ./test/*.o ./sys/*.o #Output OUTPUT = ubix_api.so lib.so: $(OBJS) (cd test;make) + (cd sys;make) $(CC) -nostdlib -shared -Wl,-soname,ubix_api.so -o $(OUTPUT) $(OBJS) $(SUBS) # Compile the source files @@ -38,3 +39,4 @@ clean: $(REMOVE) $(OBJS) $(OUTPUT) (cd test;make clean) + (cd sys;make clean) diff --git a/src/lib/ubix_api/sys/Makefile b/src/lib/ubix_api/sys/Makefile new file mode 100644 index 0000000..3c4ac1a --- /dev/null +++ b/src/lib/ubix_api/sys/Makefile @@ -0,0 +1,34 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = old_fork.o + +#Output +OUTPUT = ubix_api.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -I../../../include -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/ubix_api/sys/old_fork.c b/src/lib/ubix_api/sys/old_fork.c new file mode 100644 index 0000000..5772a65 --- /dev/null +++ b/src/lib/ubix_api/sys/old_fork.c @@ -0,0 +1,77 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +pid_t old_fork() { + volatile pid_t pid = 0x0; + asm volatile( + "pushl %%eax\n" + "pushl %%ecx\n" + "movl $4,%%eax\n" + "push %%ss\n" + "movl %%esp,%%ecx\n" + "sub $4,%%ecx\n" + "pushl %%ecx\n" + "int $0x80 \n" + "popl %%esp\n" + "pop %%ax\n" + "popl %%ecx\n" + "popl %%eax\n" + : + : "b" (&pid) + ); + return(pid); + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:30:21 reddawg + UbixOS + + Revision 1.6 2004/08/25 22:02:41 reddawg + task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly + + Revision 1.5 2004/08/24 23:33:45 reddawg + Fixed + + Revision 1.4 2004/08/02 18:50:13 reddawg + Updates to make some variable volatile to make work with gcc 3.3. However there are still some issues but we have not caused new issues with gcc 2.95 + + Revision 1.3 2004/08/01 20:14:18 reddawg + Fixens + + Revision 1.2 2004/08/01 19:59:19 reddawg + *** empty log message *** + + END + ***/ + + diff --git a/src/sys/Makefile.inc b/src/sys/Makefile.inc index 35a9c80..f75ebf0 100644 --- a/src/sys/Makefile.inc +++ b/src/sys/Makefile.inc @@ -2,5 +2,5 @@ # global 'sys' options INCLUDES = -I../include -CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O -DNOTIMP #-DVMMDEBUG -DDEBUG +CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O -DNOTIMP #-DVFSDEBUG #-DVMMDEBUG -DDEBUG KERNEL = ubix.elf diff --git a/src/sys/include/sys/sysproto.h b/src/sys/include/sys/sysproto.h index 2d07a86..d8cf2c3 100644 --- a/src/sys/include/sys/sysproto.h +++ b/src/sys/include/sys/sysproto.h @@ -47,6 +47,9 @@ #endif //Protos +struct fork_args { + register_t dummy; + }; struct read_args { char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; @@ -63,8 +66,8 @@ char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; }; struct close_args { - char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; -}; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + }; struct setitimer_args { char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; @@ -185,6 +188,7 @@ }; //Func Defs +int fork(struct thread *td,struct fork_args *uap); int read(struct thread *td,struct read_args *uap); int write(struct thread *td, struct write_args *uap); int open(struct thread *td, struct open_args *uap); diff --git a/src/sys/include/ubixos/kpanic.h b/src/sys/include/ubixos/kpanic.h index 3b96ef6..7905951 100644 --- a/src/sys/include/ubixos/kpanic.h +++ b/src/sys/include/ubixos/kpanic.h @@ -30,7 +30,7 @@ #ifndef _KPANIC_H #define _KPANIC_H -#define K_PANIC(msg) kpanic("Error: (%s), File: %s, Line: %i\n",msg ,__FILE__,__LINE__); +#define K_PANIC(msg) kpanic("\nKernel Panic!!!!\nError: (%s), File: %s, Function: %s, Line: %i\n",msg ,__FILE__,__FUNCTION__,__LINE__); void kpanic(const char *fmt, ...); diff --git a/src/sys/include/ubixos/syscalls_new.h b/src/sys/include/ubixos/syscalls_new.h index 73afec0..3240417 100644 --- a/src/sys/include/ubixos/syscalls_new.h +++ b/src/sys/include/ubixos/syscalls_new.h @@ -64,7 +64,7 @@ functionPTR systemCalls_new[] = { invalid_call, /** 0 **/ sysExit, /** 1 **/ - invalid_call, /** 2 **/ + fork, /** 2 **/ read, /** 3 **/ write, /** 4 **/ open, /** 5 **/ diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 0c2fb11..42b813d 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -145,8 +145,8 @@ execThread(systemTask, (uInt32)sysTask+0x2000,0x0); execFile("sys:/bin/init",0x0,0x0,0x0); /* OS Initializer */ - execFile("sys:/bin/login",0x0,0x0,0x1); - execFile("sys:/bin/login",0x0,0x0,0x2); +// execFile("sys:/bin/login",0x0,0x0,0x1); +// execFile("sys:/bin/login",0x0,0x0,0x2); irqEnable(0x0); diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index 7cea13e..6f3175c 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,7 @@ Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, long esp,long ss) - + Desc: This function will copy a process Notes: @@ -51,10 +52,10 @@ volatile struct taskStruct * tmpProcPtr = newProcess; assert(newProcess); assert(_current); - + /* Set Up New Tasks Information */ memcpy(newProcess->oInfo.cwd,_current->oInfo.cwd,1024); - + newProcess->tss.eip = eip; newProcess->oInfo.vmStart = _current->oInfo.vmStart; newProcess->term = _current->term; @@ -89,21 +90,22 @@ /* Create A Copy Of The VM Space For New Task */ newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); newProcess->state = FORK; - + /* Fix gcc optimization problems */ while (tmpProcPtr->state == FORK) sched_yield(); /* Return Id of Proccess */ return(newProcess->id); } - + /***************************************************************************************** Functoin: void sysFork(); - - Desc: This function will fork a new task + + Desc: This function + will fork a new task Notes: - + 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I Chose The Best Path To Impliment It I Guess We Will See What The Future May Bring @@ -127,7 +129,13 @@ " ret \n" ); +int fork(struct thread *td,struct fork_args *uap) { + td->td_retval[0] = 0x0; + td->td_retval[1] = 0x0; + return(0x0); + K_PANIC("Error: The new fork syscall is not yet implimented"); + } + /*** END ***/ - diff --git a/src/sys/kernel/kern_descrip.c b/src/sys/kernel/kern_descrip.c index e5490e4..41ab597 100644 --- a/src/sys/kernel/kern_descrip.c +++ b/src/sys/kernel/kern_descrip.c @@ -104,7 +104,7 @@ struct file *fp = 0x0; #ifdef NOTIMP - kprintf("[%s:%i]",__FILE__,__LINE__); + kprintf("[%s:%i]",__FILE__,__LINE__,__FUNCTION__); #endif fp = (struct file *)_current->td.o_files[uap->fd]; @@ -136,8 +136,14 @@ #ifdef DEBUG kprintf("[%s:%i]",__FILE__,__LINE__); + kprintf("GetFD: [%i]\n",fd); #endif + if (fd < 5) { + kprintf("Trying to open a system descriptor\n"); + while (1); + } + *fp = (struct file *)td->o_files[fd]; if (fp == 0x0) diff --git a/src/sys/kernel/kpanic.c b/src/sys/kernel/kpanic.c index d370eec..7aae31b 100644 --- a/src/sys/kernel/kpanic.c +++ b/src/sys/kernel/kpanic.c @@ -49,7 +49,7 @@ /* It's important that we print on the current terminal so let's reset foreground */ tty_foreground = NULL; - kprintf("kPanic: %s", buf); + kprint(buf); /* Halt The System */ //asm("cli"); diff --git a/src/sys/vfs/vfs_syscalls.c b/src/sys/vfs/vfs_syscalls.c index 51a64e2..6708485 100644 --- a/src/sys/vfs/vfs_syscalls.c +++ b/src/sys/vfs/vfs_syscalls.c @@ -44,6 +44,10 @@ int error = 0x0; struct file *fd = 0x0; + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + getfd(td,&fd,uap->fd); switch (uap->whence) { case SEEK_END: @@ -76,26 +80,51 @@ */ int read(struct thread *td,struct read_args *uap) { int error = 0x0; + int ch = 0x0; + int i = 0x0; size_t count = 0x0; struct file *fd = 0x0; char *data = 0x0; #ifdef VFSDEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); #endif - error = getfd(td,&fd,uap->fd); + if (uap->fd < 5) { + /* Special File Descriptors */ + switch (uap->fd) { + case 0: + data = uap->buf; + for (i = 0x0;i < uap->nbyte;i++) { + while ((ch = getch()) == 0x0); + data[i] = ch; + kprintf("%c",ch); + if (data[i] == '\n') + break; + } + //kprintf("Read: [%i]\n",i + 1); + count = i + 1; + break; + default: + kprintf("Invalid Descriptor\n"); + count = 0; + break; + } + } + else { + /* Standard File Descriptors */ + error = getfd(td,&fd,uap->fd); - if (error) - return(error); + if (error) + return(error); - count = fread(uap->buf,uap->nbyte,0x1,fd->fd); + count = fread(uap->buf,uap->nbyte,0x1,fd->fd); + } #ifdef VFSDEBUG kprintf("count: %i - %i\n",count,uap->nbyte); #endif td->td_retval[0] = count; - return(error); } /* end func */ @@ -111,6 +140,10 @@ char *buffer = 0x0; char *in = 0x0; + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + if (uap->fd == 2) { in = (char *)uap->buf; if (uap->nbyte > 1) { @@ -153,6 +186,10 @@ int index = 0x0; struct file *nfp = 0x0; + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + error = falloc(td,&nfp,&index); if (error) @@ -177,9 +214,10 @@ } /* end func open */ int close(struct thread *td,struct close_args *uap) { - #ifdef DEBUG - kprintf("[%s:%i]",__FILE__,__LINE__); + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); #endif + kfree((void *)td->o_files[uap->fd]); td->o_files[uap->fd] = 0x0; td->td_retval[0] = 0x0; diff --git a/ubixos.kdevelop.filelist b/ubixos.kdevelop.filelist index b56194b..66f4232 100644 --- a/ubixos.kdevelop.filelist +++ b/ubixos.kdevelop.filelist @@ -11,3 +11,4 @@ src/sys/include/vmm/vmm.h src/sys/include/vmm/paging.h src/sys/vfs/vfs_syscalls.c +src/sys/isa/ne2k.c diff --git a/ubixos.kdevelop.pcs b/ubixos.kdevelop.pcs index 404e462..6b518a5 100644 --- a/ubixos.kdevelop.pcs +++ b/ubixos.kdevelop.pcs Binary files differ diff --git a/ubixos.kdevses b/ubixos.kdevses index 11fb667..cff38b5 100644 --- a/ubixos.kdevses +++ b/ubixos.kdevses @@ -1,7 +1,23 @@ - + + + + + + + + + + + + + + + + +