aboutsummaryrefslogtreecommitdiff
path: root/libnetfs/file-set-translator.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnetfs/file-set-translator.c')
-rw-r--r--libnetfs/file-set-translator.c73
1 files changed, 31 insertions, 42 deletions
diff --git a/libnetfs/file-set-translator.c b/libnetfs/file-set-translator.c
index 4307924a..a0a70dba 100644
--- a/libnetfs/file-set-translator.c
+++ b/libnetfs/file-set-translator.c
@@ -1,5 +1,5 @@
-/*
- Copyright (C) 1996 Free Software Foundation, Inc.
+/*
+ Copyright (C) 1996, 1997, 1999, 2001 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -22,8 +22,6 @@
#include <hurd/paths.h>
#include <hurd/fsys.h>
-#define makedev(maj,min) ((((maj)&0xFF)<<8)+((min)&0xFF))
-
error_t
netfs_S_file_set_translator (struct protid *user,
int passive_flags, int active_flags,
@@ -33,46 +31,37 @@ netfs_S_file_set_translator (struct protid *user,
{
struct node *np;
error_t err = 0;
- uid_t *uids, *gids;
- int nuids, ngids;
- int i;
mach_port_t control;
if (!user)
return EOPNOTSUPP;
-
+
if (!(passive_flags & FS_TRANS_SET) && !(active_flags & FS_TRANS_SET))
return 0;
-
+
if (passive && passive[passivelen - 1])
return EINVAL;
-
+
np = user->po->np;
mutex_lock (&np->lock);
-
- if (active_flags & FS_TRANS_SET)
+
+ if (active_flags & FS_TRANS_SET
+ && ! (active_flags & FS_TRANS_ORPHAN))
{
/* Validate--user must be owner */
- netfs_interpret_credential (user->credential, &uids, &nuids,
- &gids, &ngids);
- err = netfs_validate_stat (np, user->credential);
+ err = netfs_validate_stat (np, user->user);
if (err)
goto out;
- for (i = 0; i < nuids; i++)
- if (uids[i] == 0 || uids[i] == np->nn_stat.st_uid)
- break;
- if (i == nuids)
- {
- mutex_unlock (&np->lock);
- return EBUSY;
- }
+ err = fshelp_isowner (&np->nn_stat, user->user);
+ if (err)
+ goto out;
err = fshelp_fetch_control (&np->transbox, &control);
if (err)
goto out;
-
- if (control != MACH_PORT_NULL
+
+ if (control != MACH_PORT_NULL
&& (active_flags & FS_TRANS_EXCL) == 0)
{
mutex_unlock (&np->lock);
@@ -87,13 +76,13 @@ netfs_S_file_set_translator (struct protid *user,
if ((passive_flags & FS_TRANS_SET)
&& (passive_flags & FS_TRANS_EXCL))
{
- err = netfs_validate_stat (np, user->credential);
- if (!err && np->istranslated)
+ err = netfs_validate_stat (np, user->user);
+ if (!err && (np->nn_stat.st_mode & S_IPTRANS))
err = EBUSY;
if (err)
goto out;
}
-
+
if (active_flags & FS_TRANS_SET)
{
err = fshelp_set_active (&np->transbox, active,
@@ -101,7 +90,7 @@ netfs_S_file_set_translator (struct protid *user,
if (err)
goto out;
}
-
+
if (passive_flags & FS_TRANS_SET)
{
mode_t newmode = 0;
@@ -120,12 +109,12 @@ netfs_S_file_set_translator (struct protid *user,
else if (!strcmp (passive, _HURD_IFSOCK))
newmode = S_IFSOCK;
}
-
+
switch (newmode)
{
int major, minor;
char *arg;
-
+
case S_IFBLK:
case S_IFCHR:
/* Find the device number from the arguments
@@ -138,7 +127,7 @@ netfs_S_file_set_translator (struct protid *user,
return EINVAL;
}
major = strtol (arg, 0, 0);
-
+
arg = arg + strlen (arg) + 1;
assert (arg < passive + passivelen);
if (arg == passive + passivelen)
@@ -147,13 +136,13 @@ netfs_S_file_set_translator (struct protid *user,
return EINVAL;
}
minor = strtol (arg, 0, 0);
-
- err = netfs_attempt_mkdev (user->credential, np,
+
+ err = netfs_attempt_mkdev (user->user, np,
newmode, makedev (major, minor));
if (err == EOPNOTSUPP)
goto fallback;
break;
-
+
case S_IFLNK:
arg = passive + strlen (passive) + 1;
assert (arg <= passive + passivelen);
@@ -162,30 +151,30 @@ netfs_S_file_set_translator (struct protid *user,
mutex_unlock (&np->lock);
return EINVAL;
}
-
- err = netfs_attempt_mksymlink (user->credential, np, arg);
+
+ err = netfs_attempt_mksymlink (user->user, np, arg);
if (err == EOPNOTSUPP)
goto fallback;
break;
default:
- err = netfs_validate_stat (np, user->credential);
+ err = netfs_validate_stat (np, user->user);
if (!err)
- err = netfs_attempt_chmod (user->credential, np,
+ err = netfs_attempt_chmod (user->user, np,
((np->nn_stat.st_mode & ~S_IFMT)
| newmode));
if (err == EOPNOTSUPP)
goto fallback;
break;
-
+
case 0:
fallback:
- err = netfs_set_translator (user->credential, np,
+ err = netfs_set_translator (user->user, np,
passive, passivelen);
break;
}
}
-
+
out:
mutex_unlock (&np->lock);
return err;