Exemplo n.º 1
0
/*
 * Handle unpacking the request in the URI and
 * invoking the actual handler.
 */
static void
dosearch(char *search)
{
	if (strncmp(search, "dir=", 4) == 0){
		search = hurlunesc(connect, search+4);
		dols(search);
		return;
	}

	/*
	 * Otherwise, we've gotten an illegal request.
	 * spit out a non-apologetic error.
	 */
	search = hurlunesc(connect, search);
	error("Bad directory listing request",
	    "<p>Illegal formatted directory listing request:</p>\n"
	    "<p>%H</p>", search);
}
Exemplo n.º 2
0
void
main(int argc, char **argv)
{
	fmtinstall('H', httpfmt);
	fmtinstall('U', hurlfmt);
	fmtinstall('M', dirmodefmt);

	aio = Bopen("/sys/lib/webls.allowed", OREAD);
	dio = Bopen("/sys/lib/webls.denied", OREAD);

	if(argc == 2){
		hinit(&houtb, 1, Hwrite);
		hout = &houtb;
		dols(argv[1]);
		exits(nil);
	}
	close(2);

	connect = init(argc, argv);
	hout = &connect->hout;
	vermaj = connect->req.vermaj;
	if(hparseheaders(connect, HSTIMEOUT) < 0)
		exits("failed");

	if(strcmp(connect->req.meth, "GET") != 0 && strcmp(connect->req.meth, "HEAD") != 0){
		hunallowed(connect, "GET, HEAD");
		exits("not allowed");
	}
	if(connect->head.expectother || connect->head.expectcont){
		hfail(connect, HExpectFail, nil);
		exits("failed");
	}

	bind("/usr/web", "/", MREPL);

	if(connect->req.search != nil)
		dosearch(connect->req.search);
	else
		error("Bad argument", "<p>Need a search argument</p>");
	hflush(hout);
	writelog(connect, "200 webls %ld %ld\n", hout->seek, hout->seek);
	exits(nil);
}
Exemplo n.º 3
0
void
dols(char *name, int lslong)
{
        struct stat stbuf;
#if VERBOSITY > 1
	printf(__FUNCTION__"(`%s',%d) called\n", name, lslong);
#endif
        lstat(name, &stbuf);

        switch (stbuf.st_mode & S_IFMT) {
        case S_IFDIR:
        {
		DIR	*fd;
                struct dirent *de;
		int 	thisdir = open(".", O_RDONLY);

		if (thisdir == -1) {
			perror("open .");
			printf(__FUNCTION__": couldn't open current dir, "
				"errno = x%x\n", errno);
			return;
		}

		if (-1 == chdir(name)) {
			perror(name);
			printf(__FUNCTION__": chdir(`%s') failed\n", name);
			return;
		}

		/* open directory */
		fd = opendir(".");
		if (fd == 0) {
			perror("opendir .");
			printf("%s: no such file or directory\n", name);
			return;
		}

		/* iterate through directory and print items */
		while ((de = readdir(fd)) != 0) {
			if (-1 == lstat(de->d_name, &stbuf)) {
				perror("lstat");
				printf(__FUNCTION__": lstat(`%s') failed\n",
					de->d_name);
				return;
			}
			if (lslong)
				printinfo(&stbuf, de->d_name);
			else
				printf("%s%c\n", de->d_name,
					S_ISDIR(stbuf.st_mode) ? '/' : ' ');
		}

		rewinddir(fd);

		while ((de = readdir(fd)) != 0) {
			char buf[512];

			if (-1 == lstat(de->d_name, &stbuf)) {
				perror("lstat");
				printf(__FUNCTION__": stat de->d_name=`%s' "
						"failed\n", de->d_name);
				break;
			}
			if (S_ISDIR(stbuf.st_mode)) {
				strcpy(buf, de->d_name);
				if (strcmp(buf, "..") && strcmp(buf, ".")) {
					printf("\n%s:\n", buf);
					dols(buf, lslong);
				}
			}
		}
		closedir(fd);

		/* change back */
		if (-1 == fchdir(thisdir)) {
			perror("fchdir");
			return;
		}
		close(thisdir);
                break;
        }
        case S_IFREG:
        case S_IFLNK:
                if (lslong)
                        printinfo(&stbuf, name);
                else
                        printf("%s\n", name);
                break;
        default:
                printf("unknown type = x%x, DIR= x%x, REG= x%x\n",
                        stbuf.st_mode, S_IFDIR, S_IFREG);
        }
}
Exemplo n.º 4
0
main(int ac, char *av[])
{
	dols(ac > 1 ? av[1] : ".", 1);
	return 0;
}
Exemplo n.º 5
0
/*this is the main routine*/
void doshell()
{
	char line[80];

	/*run forever - the shell shouldn't end*/
	while(1==1)
	{
		/*read in a line*/
		printstring("SHELL>\0");
		readstring(line);

		/*match it against each possible command*/
		/*if the user presses return, ignore it*/
		if (line[0]==0xd)
			continue;
		else if (iscommand(line,"CLS\0")==1)
			doclear();
		else if (iscommand(line,"cls\0")==1)
			doclear();
		else if (iscommand(line,"COPY\0")==1)
			docopy();
		else if (iscommand(line,"copy\0")==1)
			docopy();
		else if (iscommand(line,"CREATE \0")==1)
			docreate(line);
		else if (iscommand(line,"create \0")==1)
			docreate(line);
		else if (iscommand(line,"DELETE \0")==1)
			dodelete(line);
		else if (iscommand(line,"delete \0")==1)
			dodelete(line);
		else if (iscommand(line,"DIR\0")==1)
			dodir();
		else if (iscommand(line,"dir\0")==1)
			dodir();
		else if (iscommand(line,"EXEC \0")==1)
			doexecute(line,1);
		else if (iscommand(line,"exec \0")==1)
			doexecute(line,1);
		else if (iscommand(line,"EXECBACK \0")==1)
			doexecute(line,0);
		else if (iscommand(line,"execback \0")==1)
			doexecute(line,0);
		else if (iscommand(line,"HELP\0")==1)
			dohelp();
		else if (iscommand(line,"help\0")==1)
			dohelp();
		else if (line[0]=='?')
			dohelp();
		else if (iscommand(line,"TYPE \0")==1)
			dotype(line);
		else if (iscommand(line,"type \0")==1)
			dotype(line);
		else if (iscommand(line,"KILL \0")==1)
			dokill(line);
		else if (iscommand(line,"kill \0")==1)
			dokill(line);
		else if (iscommand(line,"PS\0")==1)
			dops();
		else if (iscommand(line,"ps\0")==1)
			dops();
		else if (iscommand(line,"mkdir\0")==1)
			domkdir(line);
		else if (iscommand(line,"MKDIR\0")==1)
			domkdir(line);
		else if (iscommand(line,"ls\0")==1)
			dols(line);
		else if (iscommand(line,"LS\0")==1)
			dols(line);
		else
			printstring("Command not found\r\n\0");
		printstring("\r\n\0");
	}
}