* Re: [9fans] u9fs: dealing with user names that differ between unix and plan 9?
@ 2002-04-05 15:44 forsyth
2002-04-05 18:23 ` Axel Belinfante
0 siblings, 1 reply; 5+ messages in thread
From: forsyth @ 2002-04-05 15:44 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 71 bytes --]
you can always change the mapping code to
read in a mapping table.
[-- Attachment #2: Type: message/rfc822, Size: 1985 bytes --]
To: 9fans@cse.psu.edu
Subject: Re: [9fans] u9fs: dealing with user names that differ between unix and plan 9?
Date: Fri, 5 Apr 2002 10:33:19 -0500
Message-ID: <88cb92cf3c9085596ad4e509df4e812f@plan9.bell-labs.com>
> I have set up u9fs on a linux machine as indicated in the README,
> and it works, when my plan 9 username is the same as my linux username.
> When there is no linux user with the same name as the plan 9 user
> that does the mount (attach), it fails. Is there a way to specify,
> from the plan9 side, what linux user name should be used when doing
> the mount (attach)? (like the -l option of rlogin)
No, sorry.
> It seems that the -u command line option of u9fs can be used as
> a kind of workaround: it allows me to choose one single linux user
> name onto which then all plan 9 users will be mapped, correct?
Yes.
Russ
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] u9fs: dealing with user names that differ between unix and plan 9?
2002-04-05 15:44 [9fans] u9fs: dealing with user names that differ between unix and plan 9? forsyth
@ 2002-04-05 18:23 ` Axel Belinfante
2002-04-08 13:14 ` Axel Belinfante
0 siblings, 1 reply; 5+ messages in thread
From: Axel Belinfante @ 2002-04-05 18:23 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 377 bytes --]
Charles Forsyth suggested:
> you can always change the mapping code to
> read in a mapping table.
Perfect suggestion! I tried, and the result seems to be working.
The mapfile contains mapping lines:
plan9user unixuser
Probably I could add special plan9user name '*' to match any.
A context diff is attached; (constructive) comments are welcome!
Regards,
Axel.
[-- Attachment #2: diff --]
[-- Type: text/plain , Size: 2888 bytes --]
--- u9fs.c.original Fri Apr 5 19:54:35 2002
+++ u9fs.c Fri Apr 5 20:09:07 2002
@@ -96,6 +96,8 @@
int readonly;
int myuid;
char *onlyuser;
+char *mapfile;
+char mapbuf[1024];
void io(void);
void error(char*);
@@ -112,6 +114,7 @@
Ulong vers(struct stat*);
void errjmp(const char*);
int omode(int);
+char* remote2local(char*, char*);
char* id2name(Pass**, int);
Pass* id2pass(Pass**, int);
Pass* name2pass(Pass**, char*);
@@ -150,11 +153,12 @@
char Euid[] = "can't set uid";
char Egid[] = "can't set gid";
char Eowner[] = "not owner";
+char Emapfileerr[] = "error opening mapping file";
void
usage(void)
{
- fprintf(stderr, "u9fs [-r] [-u user uid]\n");
+ fprintf(stderr, "u9fs [-r] [-u user uid] [-m mapfile]\n");
exit(1);
}
@@ -172,6 +176,7 @@
DBG(fprintf(stderr, "u9fs\nkill %d\n", getpid()));
onlyuid = -1;
+ mapfile = 0;
ARGBEGIN{
case 'r':
readonly++;
@@ -185,6 +190,11 @@
usage();
onlyuid = atoi(s);
break;
+ case 'm':
+ mapfile = ARGF();
+ if(mapfile == 0)
+ usage();
+ break;
default:
usage();
break;
@@ -311,6 +321,7 @@
{
Rfile *rf;
Pass *p;
+ char *localname;
if(file0 == 0){
file0 = newfile();
@@ -334,14 +345,17 @@
rf = &rfile[rhdr.fid];
if(rf->busy)
errjmp(Efidactive);
- p = name2pass(uidname, rhdr.uname);
+ localname = remote2local(mapfile, rhdr.uname);
+ if(localname == 0)
+ errjmp(Eunknown);
+ p = name2pass(uidname, localname);
if(p == 0)
errjmp(Eunknown);
if(p->id == 0 || (uid_t)p->id == (uid_t)-1
|| myuid && p->id != myuid)
errjmp(Eperm);
# ifdef SOCKETS
- if(!myuid && ruserok(bsdhost, 0, rhdr.uname, rhdr.uname) < 0)
+ if(!myuid && ruserok(bsdhost, 0, rhdr.uname, localname) < 0)
errjmp(Eperm);
# endif
/* mark busy & inc ref cnt only after committed to succeed */
@@ -955,6 +969,51 @@
q |= qdev[dev]<<24;
q |= st->st_ino & 0x00FFFFFFUL;
return q;
+}
+
+char*
+remote2local(char *mapfile, char *name)
+{
+ FILE *f;
+ char *p;
+ char *r;
+ char *re;
+ char *l;
+ char *le;
+ char *res = name;
+ if (mapfile == 0)
+ return res;
+ if ((f = fopen(mapfile, "r")) == 0)
+ errjmp(Emapfileerr);
+ DBG(fprintf(stderr, "using mapfile %s\n", mapfile));
+ while(fgets(mapbuf, sizeof(mapbuf), f)) {
+ DBG(fprintf(stderr, "mapfile line: %s\n", mapbuf));
+ p = mapbuf;
+ while(*p && isspace(*p))
+ p++;
+ if (*p == '#')
+ continue;
+ r = p;
+ while(*p && !isspace(*p))
+ p++;
+ re = p;
+ while(*p && isspace(*p))
+ p++;
+ l = p;
+ while(*p && !isspace(*p))
+ p++;
+ le = p;
+ *re = '\0';
+ *le = '\0';
+ DBG(fprintf(stderr, "\tmap '%s' -> '%s'\n", r, l));
+ if (strcmp(r, name) == 0) {
+ res = l;
+ break;
+ }
+ }
+ DBG(fprintf(stderr, "mapped '%s' -> '%s'\n", name, res));
+ fclose(f);
+ return res;
}
Pass*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] u9fs: dealing with user names that differ between unix and plan 9?
2002-04-05 18:23 ` Axel Belinfante
@ 2002-04-08 13:14 ` Axel Belinfante
0 siblings, 0 replies; 5+ messages in thread
From: Axel Belinfante @ 2002-04-08 13:14 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 189 bytes --]
In addition to using the user name mapping file I now also
look for a '-l user' prefix in the attach 'aname' field
(if present, I just use it and skip the mapping file lookup).
Axel.
[-- Attachment #2: diff --]
[-- Type: text/plain , Size: 4068 bytes --]
--- u9fs.c.original Fri Apr 5 19:54:35 2002
+++ u9fs.c Mon Apr 8 14:05:30 2002
@@ -96,6 +96,8 @@
int readonly;
int myuid;
char *onlyuser;
+char *mapfile;
+char mapbuf[1024];
void io(void);
void error(char*);
@@ -112,6 +114,8 @@
Ulong vers(struct stat*);
void errjmp(const char*);
int omode(int);
+char* stripusername(char*, char**);
+char* remote2local(char*, char*);
char* id2name(Pass**, int);
Pass* id2pass(Pass**, int);
Pass* name2pass(Pass**, char*);
@@ -150,11 +154,12 @@
char Euid[] = "can't set uid";
char Egid[] = "can't set gid";
char Eowner[] = "not owner";
+char Emapfileerr[] = "error opening mapping file";
void
usage(void)
{
- fprintf(stderr, "u9fs [-r] [-u user uid]\n");
+ fprintf(stderr, "u9fs [-r] [-u user uid] [-m mapfile]\n");
exit(1);
}
@@ -172,6 +177,7 @@
DBG(fprintf(stderr, "u9fs\nkill %d\n", getpid()));
onlyuid = -1;
+ mapfile = 0;
ARGBEGIN{
case 'r':
readonly++;
@@ -185,6 +191,11 @@
usage();
onlyuid = atoi(s);
break;
+ case 'm':
+ mapfile = ARGF();
+ if(mapfile == 0)
+ usage();
+ break;
default:
usage();
break;
@@ -311,6 +322,9 @@
{
Rfile *rf;
Pass *p;
+ char *localname;
+ char *aname;
+ char *username;
if(file0 == 0){
file0 = newfile();
@@ -321,7 +335,10 @@
}
if(!okfid(rhdr.fid))
errjmp(Ebadfid);
- if(strncmp(rhdr.aname, "device", 6) == 0){
+ username = 0;
+ aname = stripusername(rhdr.aname, &username);
+ DBG(fprintf(stderr, "uname %s username:%s\n", aname, username?username:""));
+ if(strncmp(aname, "device", 6) == 0){
if(connected && !devallowed)
errjmp(Especial0);
devallowed = 1;
@@ -334,14 +351,20 @@
rf = &rfile[rhdr.fid];
if(rf->busy)
errjmp(Efidactive);
- p = name2pass(uidname, rhdr.uname);
+ if (username == 0)
+ localname = remote2local(mapfile, rhdr.uname);
+ else
+ localname = username;
+ if(localname == 0)
+ errjmp(Eunknown);
+ p = name2pass(uidname, localname);
if(p == 0)
errjmp(Eunknown);
if(p->id == 0 || (uid_t)p->id == (uid_t)-1
|| myuid && p->id != myuid)
errjmp(Eperm);
# ifdef SOCKETS
- if(!myuid && ruserok(bsdhost, 0, rhdr.uname, rhdr.uname) < 0)
+ if(!myuid && ruserok(bsdhost, 0, rhdr.uname, localname) < 0)
errjmp(Eperm);
# endif
/* mark busy & inc ref cnt only after committed to succeed */
@@ -955,6 +978,81 @@
q |= qdev[dev]<<24;
q |= st->st_ino & 0x00FFFFFFUL;
return q;
+}
+
+char*
+stripusername(char *aname, char **username)
+{
+ char *p = aname;
+ char *e;
+ DBG(fprintf(stderr, "aname: %s\n", aname));
+ while(*p && isspace(*p))
+ p++;
+ if (strncmp(p, "-l", 2) != 0)
+ return aname;
+ p++;
+ p++;
+ DBG(fprintf(stderr, "aname: found -l\n"));
+ if (! isspace(*p))
+ return aname;
+ DBG(fprintf(stderr, "aname: found space\n"));
+ while(*p && isspace(*p))
+ p++;
+ *username = p;
+ while(*p && !isspace(*p))
+ p++;
+ e = p;
+ while(*p && isspace(*p))
+ p++;
+ *e = '\0';
+ DBG(fprintf(stderr, "aname: found username: %s\n", *username));
+ DBG(fprintf(stderr, "aname: rest: %s\n", p));
+ return p;
+}
+
+char*
+remote2local(char *mapfile, char *name)
+{
+ FILE *f;
+ char *p;
+ char *r;
+ char *re;
+ char *l;
+ char *le;
+ char *res = name;
+ if (mapfile == 0)
+ return res;
+ if ((f = fopen(mapfile, "r")) == 0)
+ errjmp(Emapfileerr);
+ DBG(fprintf(stderr, "using mapfile %s\n", mapfile));
+ while(fgets(mapbuf, sizeof(mapbuf), f)) {
+ DBG(fprintf(stderr, "mapfile line: %s\n", mapbuf));
+ p = mapbuf;
+ while(*p && isspace(*p))
+ p++;
+ if (*p == '#')
+ continue;
+ r = p;
+ while(*p && !isspace(*p))
+ p++;
+ re = p;
+ while(*p && isspace(*p))
+ p++;
+ l = p;
+ while(*p && !isspace(*p))
+ p++;
+ le = p;
+ *re = '\0';
+ *le = '\0';
+ DBG(fprintf(stderr, "\tmap '%s' -> '%s'\n", r, l));
+ if (strcmp(r, name) == 0) {
+ res = l;
+ break;
+ }
+ }
+ DBG(fprintf(stderr, "mapped '%s' -> '%s'\n", name, res));
+ fclose(f);
+ return res;
}
Pass*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9fans] u9fs: dealing with user names that differ between unix and plan 9?
@ 2002-04-05 15:33 Russ Cox
0 siblings, 0 replies; 5+ messages in thread
From: Russ Cox @ 2002-04-05 15:33 UTC (permalink / raw)
To: 9fans
> I have set up u9fs on a linux machine as indicated in the README,
> and it works, when my plan 9 username is the same as my linux username.
> When there is no linux user with the same name as the plan 9 user
> that does the mount (attach), it fails. Is there a way to specify,
> from the plan9 side, what linux user name should be used when doing
> the mount (attach)? (like the -l option of rlogin)
No, sorry.
> It seems that the -u command line option of u9fs can be used as
> a kind of workaround: it allows me to choose one single linux user
> name onto which then all plan 9 users will be mapped, correct?
Yes.
Russ
^ permalink raw reply [flat|nested] 5+ messages in thread
* [9fans] u9fs: dealing with user names that differ between unix and plan 9?
@ 2002-04-05 14:23 Axel Belinfante
0 siblings, 0 replies; 5+ messages in thread
From: Axel Belinfante @ 2002-04-05 14:23 UTC (permalink / raw)
To: 9fans
I have set up u9fs on a linux machine as indicated in the README,
and it works, when my plan 9 username is the same as my linux username.
When there is no linux user with the same name as the plan 9 user
that does the mount (attach), it fails. Is there a way to specify,
from the plan9 side, what linux user name should be used when doing
the mount (attach)? (like the -l option of rlogin)
It seems that the -u command line option of u9fs can be used as
a kind of workaround: it allows me to choose one single linux user
name onto which then all plan 9 users will be mapped, correct?
Axel.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-04-08 13:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-05 15:44 [9fans] u9fs: dealing with user names that differ between unix and plan 9? forsyth
2002-04-05 18:23 ` Axel Belinfante
2002-04-08 13:14 ` Axel Belinfante
-- strict thread matches above, loose matches on Subject: below --
2002-04-05 15:33 Russ Cox
2002-04-05 14:23 Axel Belinfante
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).