1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-13 13:18:06 +03:00

added basic chmod(), chown() and utime() support (not fully

implemented).

this is enough to be able to edit files using emacs on the smbwrapper
filesystem
(This used to be commit e5c3f36ef2)
This commit is contained in:
Andrew Tridgell 1998-10-03 10:24:49 +00:00
parent cce5f09a90
commit 909ca3a887
7 changed files with 257 additions and 4 deletions

View File

@ -198,7 +198,8 @@ SMBWRAPPER_OBJ = smbwrapper/open.o smbwrapper/stat.o \
smbwrapper/lstat.o smbwrapper/close.o smbwrapper/getdents.o \
smbwrapper/fcntl.o smbwrapper/access.o smbwrapper/chdir.o \
smbwrapper/write.o smbwrapper/readlink.o smbwrapper/unlink.o \
smbwrapper/rename.o \
smbwrapper/rename.o smbwrapper/utime.o smbwrapper/chown.o \
smbwrapper/chmod.o \
$(LIBSMB_OBJ) $(PARAM_OBJ) \
$(UBIQX_OBJ) $(LIB_OBJ)

View File

@ -0,0 +1,32 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int chmod(const char *name,mode_t mode)
{
if (smbw_path(name)) {
return smbw_chmod(name, mode);
}
return real_chmod(name, mode);
}

View File

@ -0,0 +1,32 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int chown(const char *name,uid_t owner, gid_t group)
{
if (smbw_path(name)) {
return smbw_chown(name, owner, group);
}
return real_chown(name, owner, group);
}

View File

@ -225,6 +225,8 @@ char *smbw_parse_path(const char *fname, char *server, char *share, char *path)
char *p, *p2;
int len;
*server = *share = *path = 0;
if (fname[0] == '/') {
pstrcpy(s, fname);
} else {
@ -299,7 +301,11 @@ BOOL smbw_path(const char *path)
fstring server, share;
pstring s;
char *cwd;
int l;
int l=strlen(SMBW_PREFIX)-1;
if (path[0] == '/' && strncmp(path,SMBW_PREFIX,l)) {
return False;
}
if (smbw_busy) return False;
@ -309,8 +315,6 @@ BOOL smbw_path(const char *path)
cwd = smbw_parse_path(path, server, share, s);
l = strlen(SMBW_PREFIX)-1;
if (strncmp(cwd,SMBW_PREFIX,l) == 0 &&
(cwd[l] == '/' || cwd[l] == 0)) {
return True;
@ -430,6 +434,15 @@ struct smbw_server *smbw_server(char *server, char *share)
goto failed;
}
/* some programs play with file descriptors fairly intimately. We
try to get out of the way by duping to a high fd number */
if (fcntl(SMBW_CLI_FD, F_GETFD) && errno == EBADF) {
if (dup2(srv->cli.fd, SMBW_CLI_FD) == SMBW_CLI_FD) {
close(srv->cli.fd);
srv->cli.fd = SMBW_CLI_FD;
}
}
DLIST_ADD(smbw_srvs, srv);
return srv;
@ -1250,3 +1263,145 @@ int smbw_rename(const char *oldname, const char *newname)
smbw_busy--;
return -1;
}
/*****************************************************
a wrapper for utime()
*******************************************************/
int smbw_utime(const char *fname, struct utimbuf *buf)
{
struct smbw_server *srv;
fstring server, share;
pstring path;
uint32 mode;
DEBUG(4,("%s (%s)\n", __FUNCTION__, fname));
if (!fname) {
errno = EINVAL;
return -1;
}
smbw_init();
smbw_busy++;
/* work out what server they are after */
smbw_parse_path(fname, server, share, path);
/* get a connection to the server */
srv = smbw_server(server, share);
if (!srv) {
/* smbw_server sets errno */
goto failed;
}
if (!cli_getatr(&srv->cli, path, &mode, NULL, NULL)) {
errno = smbw_errno(&srv->cli);
goto failed;
}
if (!cli_setatr(&srv->cli, path, mode, buf->modtime)) {
errno = smbw_errno(&srv->cli);
goto failed;
}
smbw_busy--;
return 0;
failed:
smbw_busy--;
return -1;
}
/*****************************************************
a wrapper for chown()
*******************************************************/
int smbw_chown(const char *fname, uid_t owner, gid_t group)
{
struct smbw_server *srv;
fstring server, share;
pstring path;
uint32 mode;
DEBUG(4,("%s (%s)\n", __FUNCTION__, fname));
if (!fname) {
errno = EINVAL;
return -1;
}
smbw_init();
smbw_busy++;
/* work out what server they are after */
smbw_parse_path(fname, server, share, path);
/* get a connection to the server */
srv = smbw_server(server, share);
if (!srv) {
/* smbw_server sets errno */
goto failed;
}
if (!cli_getatr(&srv->cli, path, &mode, NULL, NULL)) {
errno = smbw_errno(&srv->cli);
goto failed;
}
/* assume success */
smbw_busy--;
return 0;
failed:
smbw_busy--;
return -1;
}
/*****************************************************
a wrapper for chmod()
*******************************************************/
int smbw_chmod(const char *fname, mode_t newmode)
{
struct smbw_server *srv;
fstring server, share;
pstring path;
uint32 mode;
DEBUG(4,("%s (%s)\n", __FUNCTION__, fname));
if (!fname) {
errno = EINVAL;
return -1;
}
smbw_init();
smbw_busy++;
/* work out what server they are after */
smbw_parse_path(fname, server, share, path);
/* get a connection to the server */
srv = smbw_server(server, share);
if (!srv) {
/* smbw_server sets errno */
goto failed;
}
if (!cli_getatr(&srv->cli, path, &mode, NULL, NULL)) {
errno = smbw_errno(&srv->cli);
goto failed;
}
/* assume success for the moment - need to add attribute mapping */
smbw_busy--;
return 0;
failed:
smbw_busy--;
return -1;
}

View File

@ -22,6 +22,7 @@
#define SMBW_PREFIX "/smb/"
#define SMBW_FD_OFFSET 1024
#define SMBW_CLI_FD 1023
#define SMBW_MAX_OPEN 2048
#define SMBW_FILE_MODE (S_IFREG | 0644)

View File

@ -0,0 +1,31 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB wrapper functions
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "wrapper.h"
int utime(const char *name,struct timeval *tvp)
{
if (smbw_path(name)) {
return smbw_utime(name, tvp);
}
return real_utime(name, tvp);
}

View File

@ -6,5 +6,6 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "kernel_stat.h"
#include "realcalls.h"