Esempio n. 1
0
static void check_magic(files_struct *fsp,connection_struct *conn)
{
	if (!*lp_magicscript(SNUM(conn)))
		return;

	DEBUG(5,("checking magic for %s\n",fsp->fsp_name));

	{
		char *p;
		if (!(p = strrchr_m(fsp->fsp_name,'/')))
			p = fsp->fsp_name;
		else
			p++;

		if (!strequal(lp_magicscript(SNUM(conn)),p))
			return;
	}

	{
		int ret;
		pstring magic_output;
		pstring fname;
		SMB_STRUCT_STAT st;
		int tmp_fd, outfd;

		pstrcpy(fname,fsp->fsp_name);
		if (*lp_magicoutput(SNUM(conn)))
			pstrcpy(magic_output,lp_magicoutput(SNUM(conn)));
		else
			slprintf(magic_output,sizeof(fname)-1, "%s.out",fname);

		chmod(fname,0755);
		ret = smbrun(fname,&tmp_fd);
		DEBUG(3,("Invoking magic command %s gave %d\n",fname,ret));
		unlink(fname);
		if (ret != 0 || tmp_fd == -1) {
			if (tmp_fd != -1)
				close(tmp_fd);
			return;
		}
		outfd = open(magic_output, O_CREAT|O_EXCL|O_RDWR, 0600);
		if (outfd == -1) {
			close(tmp_fd);
			return;
		}

		if (sys_fstat(tmp_fd,&st) == -1) {
			close(tmp_fd);
			close(outfd);
			return;
		}

		transfer_file(tmp_fd,outfd,(SMB_OFF_T)st.st_size);
		close(tmp_fd);
		close(outfd);
	}
}
Esempio n. 2
0
static NTSTATUS check_magic(struct files_struct *fsp)
{
	int ret;
	const char *magic_output = NULL;
	SMB_STRUCT_STAT st;
	int tmp_fd, outfd;
	TALLOC_CTX *ctx = NULL;
	const char *p;
	struct connection_struct *conn = fsp->conn;
	char *fname = NULL;
	NTSTATUS status;

	if (!*lp_magicscript(SNUM(conn))) {
		return NT_STATUS_OK;
	}

	DEBUG(5,("checking magic for %s\n", fsp_str_dbg(fsp)));

	ctx = talloc_stackframe();

	fname = fsp->fsp_name->base_name;

	if (!(p = strrchr_m(fname,'/'))) {
		p = fname;
	} else {
		p++;
	}

	if (!strequal(lp_magicscript(SNUM(conn)),p)) {
		status = NT_STATUS_OK;
		goto out;
	}

	if (*lp_magicoutput(SNUM(conn))) {
		magic_output = lp_magicoutput(SNUM(conn));
	} else {
		magic_output = talloc_asprintf(ctx,
				"%s.out",
				fname);
	}
	if (!magic_output) {
		status = NT_STATUS_NO_MEMORY;
		goto out;
	}

	/* Ensure we don't depend on user's PATH. */
	p = talloc_asprintf(ctx, "./%s", fname);
	if (!p) {
		status = NT_STATUS_NO_MEMORY;
		goto out;
	}

	if (chmod(fname, 0755) == -1) {
		status = map_nt_error_from_unix(errno);
		goto out;
	}
	ret = smbrun(p,&tmp_fd);
	DEBUG(3,("Invoking magic command %s gave %d\n",
		p,ret));

	unlink(fname);
	if (ret != 0 || tmp_fd == -1) {
		if (tmp_fd != -1) {
			close(tmp_fd);
		}
		status = NT_STATUS_UNSUCCESSFUL;
		goto out;
	}
	outfd = open(magic_output, O_CREAT|O_EXCL|O_RDWR, 0600);
	if (outfd == -1) {
		int err = errno;
		close(tmp_fd);
		status = map_nt_error_from_unix(err);
		goto out;
	}

	if (sys_fstat(tmp_fd, &st, false) == -1) {
		int err = errno;
		close(tmp_fd);
		close(outfd);
		status = map_nt_error_from_unix(err);
		goto out;
	}

	if (transfer_file(tmp_fd,outfd,(SMB_OFF_T)st.st_ex_size) == (SMB_OFF_T)-1) {
		int err = errno;
		close(tmp_fd);
		close(outfd);
		status = map_nt_error_from_unix(err);
		goto out;
	}
	close(tmp_fd);
	if (close(outfd) == -1) {
		status = map_nt_error_from_unix(errno);
		goto out;
	}

	status = NT_STATUS_OK;

 out:
	TALLOC_FREE(ctx);
	return status;
}
Esempio n. 3
0
static void check_magic(struct files_struct *fsp)
{
    int ret;
    const char *magic_output = NULL;
    SMB_STRUCT_STAT st;
    int tmp_fd, outfd;
    TALLOC_CTX *ctx = NULL;
    const char *p;
    struct connection_struct *conn = fsp->conn;

    if (!*lp_magicscript(SNUM(conn))) {
        return;
    }

    DEBUG(5,("checking magic for %s\n",fsp->fsp_name));

    if (!(p = strrchr_m(fsp->fsp_name,'/'))) {
        p = fsp->fsp_name;
    } else {
        p++;
    }

    if (!strequal(lp_magicscript(SNUM(conn)),p)) {
        return;
    }

    ctx = talloc_stackframe();

    if (*lp_magicoutput(SNUM(conn))) {
        magic_output = lp_magicoutput(SNUM(conn));
    } else {
        magic_output = talloc_asprintf(ctx,
                                       "%s.out",
                                       fsp->fsp_name);
    }
    if (!magic_output) {
        TALLOC_FREE(ctx);
        return;
    }

    /* Ensure we don't depend on user's PATH. */
    p = talloc_asprintf(ctx, "./%s", fsp->fsp_name);
    if (!p) {
        TALLOC_FREE(ctx);
        return;
    }

    if (chmod(fsp->fsp_name,0755) == -1) {
        TALLOC_FREE(ctx);
        return;
    }
    ret = smbrun(p,&tmp_fd);
    DEBUG(3,("Invoking magic command %s gave %d\n",
             p,ret));

    unlink(fsp->fsp_name);
    if (ret != 0 || tmp_fd == -1) {
        if (tmp_fd != -1) {
            close(tmp_fd);
        }
        TALLOC_FREE(ctx);
        return;
    }
    outfd = open(magic_output, O_CREAT|O_EXCL|O_RDWR, 0600);
    if (outfd == -1) {
        close(tmp_fd);
        TALLOC_FREE(ctx);
        return;
    }

    if (sys_fstat(tmp_fd,&st) == -1) {
        close(tmp_fd);
        close(outfd);
        return;
    }

#ifdef AVM_VERY_SMALL
    AVM_VERY_SMALL_LOG
#else
    transfer_file(tmp_fd,outfd,(SMB_OFF_T)st.st_size);
#endif

    close(tmp_fd);
    close(outfd);
    TALLOC_FREE(ctx);
}