示例#1
0
文件: ln.c 项目: Abioy/FUZIX
int main(int argc, char *argv[])
{
    int  dirflag;
    char *srcname, *destname, *lastarg;

    /* Symbolic link? */

    if (argv[1][0] == '-') {
#if defined(S_ISLNK) && 0	/* FIXME */
	if (strcmp(argv[1], "-s") == 0) {
	    if (argc != 4) {
		fprintf(stderr, "%s: wrong number of arguments for symbolic link\n", argv[0]);
		return 1;
	    }

	    if (symlink(argv[2], argv[3]) < 0) {
		perror(argv[3]);
		return 1;
	    }
	    return 0;

	}
#endif
	fprintf(stderr, "%s: unknown option %s\n", argv[0], argv[1]);
	return 1;
    }

    /* Here for normal hard links. */

    lastarg = argv[argc - 1];
    dirflag = isadir(lastarg);

    if ((argc > 3) && !dirflag) {
        fprintf(stderr, "%s: not a directory\n", lastarg);
	return 1;
    }

    while (argc-- > 2) {
	srcname = *(++argv);
	if (access(srcname, 0) < 0) {
	    perror(srcname);
	    continue;
	}

	destname = lastarg;
	if (dirflag)
	    destname = buildname(destname, srcname);

	if (link(srcname, destname) < 0) {
	    perror(destname);
	    continue;
	}
    }

    return 0;
}
示例#2
0
文件: diru.c 项目: bgpsecurity/rpstir
char *r2adir(
    char *indir)
{
    char *mydir;
    char *outdir;
    char *ptr;

    if (indir == NULL || indir[0] == 0)
    {
        LOG(LOG_ERR, "indir must not be NULL or an empty string");
        return (NULL);
    }
    if (isadir(indir) <= 0)
        return (NULL);
    // get current dir
    mydir = (char *)calloc(PATH_MAX, sizeof(char));
    if (mydir == NULL)
    {
        LOG(LOG_ERR, "out of memory");
        return (NULL);
    }
    outdir = (char *)calloc(PATH_MAX, sizeof(char));
    if (outdir == NULL)
    {
        free((void *)mydir);
        LOG(LOG_ERR, "out of memory");
        return (NULL);
    }
    ptr = getcwd(mydir, PATH_MAX);
    if (ptr == NULL)
    {
        free((void *)mydir);
        free((void *)outdir);
        ERR_LOG(errno, NULL, "failed to get current working directory");
        return (NULL);
    }
    if (chdir(indir) < 0)
    {
        free((void *)mydir);
        free((void *)outdir);
        ERR_LOG(errno, NULL, "failed to change directory to %s", indir);
        return (NULL);
    }
    ptr = getcwd(outdir, PATH_MAX);
    if (chdir(mydir))
        abort();
    free((void *)mydir);
    if (ptr == NULL)
    {
        free((void *)outdir);
        ERR_LOG(errno, NULL, "unable to get current working directory");
        return (NULL);
    }
    return (outdir);
}
void process_rq(char* rq , int fd)
{
    char cmd[BUFSIZ] , arg[BUFSIZ] ;

    if(fork() != 0)
        return ;

    strcpy(arg , "./");
    if(sscanf(rq , "%s %s" , cmd , arg+2) != 2)
        return ;

    if(strcmp(cmd , "GET") != 0)
    {
        if(strcmp(cmd , "HEAD") != 0)
            cannot_do(fd);
        else if(not_exist(arg))
            do_404(arg , fd);
        else
        {
            if(isadir(arg))
            {
                strcat(arg , "index.html");
                printf("modified arg : %s\n"  ,arg);
                if(not_exist(arg))
                    do_404(arg , fd);
            }

            do_process_head(arg , fd);
        }
    }
    else if(not_exist(arg))
        do_404(arg , fd);
    else if(isadir(arg))
        do_ls(arg , fd);
    else if(ends_in_cgi(arg))
        do_exec(arg ,fd);
    else
        do_cat(arg , fd);
}
示例#4
0
/* ------------------------------------------------------ *
   process_rq( char *rq, int fd )
   do what the request asks for and write reply to fd 
   handles request in a new process
   rq is HTTP command:  GET /foo/bar.html HTTP/1.0
   ------------------------------------------------------ */
process_rq( char *rq, int fd)
{
	char	cmd[BUFSIZ], arg[BUFSIZ];

	if ( sscanf(rq, "%s%s", cmd, arg) != 2 )
		return;
	sanitize(arg);
	printf("sanitized version is %s\n", arg);

	if ( strcmp(cmd,"GET") != 0 )
		not_implemented();
	else if ( built_in(arg, fd) )
		;
	else if ( not_exist( arg ) )
		do_404(arg, fd);
	else if ( isadir( arg ) )
		do_ls( arg, fd );
	else
		do_cat( arg, fd );
}
示例#5
0
文件: webserv.c 项目: ychmrsk/unixtp
void process_rq(char *rq, int fd)
{
  char cmd[BUFSIZ], arg[BUFSIZ];

  if (fork() != 0)
    return;

  strcpy(arg, "./");
  if (sscanf(rq, "%s%s", cmd, arg+2) != 2)
    return;

  if (strcmp(cmd, "GET") != 0)
    cannot_do(fd);
  else if (not_exist(arg))
    do_404(arg, fd);
  else if (isadir(arg))
    do_ls(arg, fd);
  else if (ends_in_cgi(arg))
    do_exec(arg, fd);
  else
    do_cat(arg, fd);
}
process_rq( char *rq, int fd )
{
    char	cmd[BUFSIZ], arg[BUFSIZ];

    /* create a new process and return if not the child */
    if ( fork() != 0 )
        return;

    strcpy(arg, "./");		/* precede args with ./ */
    if ( sscanf(rq, "%s%s", cmd, arg+2) != 2 )
        return;

    if ( strcmp(cmd,"GET") != 0 )
        cannot_do(fd);
    else if ( not_exist( arg ) )
        do_404(arg, fd );
    else if ( isadir( arg ) )
        do_ls( arg, fd );
    else if ( ends_in_cgi( arg ) )
        do_exec( arg, fd );
    else
        do_cat( arg, fd );
}