tmailfs: add -u user argument - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 0c9524b72197871c435464d064fdcc3dd5437581
parent 2fc68b6d8ebc0479318fa9764bfaa7ff58165fc3
Author: David du Colombier <0intro@gmail.com>
Date:   Mon, 28 Nov 2011 09:21:01 -0500

mailfs: add -u user argument

R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5435052

Diffstat:
  M src/cmd/upas/nfs/imap.c             |      10 ++++++++--
  M src/cmd/upas/nfs/imap.h             |       2 +-
  M src/cmd/upas/nfs/main.c             |      10 +++++++---

3 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/src/cmd/upas/nfs/imap.c b/src/cmd/upas/nfs/imap.c
t@@ -18,6 +18,7 @@ struct Imap
         int                ticks;        /* until boom! */
         char*        server;
         char*        root;
+        char*        user;
         int                mode;
         int                fd;
         Biobuf        b;
t@@ -91,7 +92,7 @@ static Sx*                zBrdsx(Imap*);
  */
 
 Imap*
-imapconnect(char *server, int mode, char *root)
+imapconnect(char *server, int mode, char *root, char *user)
 {
         Imap *z;
 
t@@ -101,6 +102,7 @@ imapconnect(char *server, int mode, char *root)
         z = emalloc(sizeof *z);
         z->server = estrdup(server);
         z->mode = mode;
+        z->user = user;
         if(root)
                 if(root[0] != 0 && root[strlen(root)-1] != '/')
                         z->root = smprint("%s/", root);
t@@ -200,7 +202,11 @@ imaplogin(Imap *z)
         Sx *sx;
         UserPasswd *up;
 
-        if((up = auth_getuserpasswd(auth_getkey, "proto=pass role=client service=imap server=%q", z->server)) == nil){
+        if(z->user != nil)
+                up = auth_getuserpasswd(auth_getkey, "proto=pass role=client service=imap server=%q user=%q", z->server, z->user);
+        else
+                up = auth_getuserpasswd(auth_getkey, "proto=pass role=client service=imap server=%q", z->server);
+        if(up == nil){
                 werrstr("getuserpasswd - %r");
                 return -1;
         }
diff --git a/src/cmd/upas/nfs/imap.h b/src/cmd/upas/nfs/imap.h
t@@ -2,7 +2,7 @@ typedef struct Imap Imap;
 #pragma incomplete Imap
 
 void                imapcheckbox(Imap *z, Box *b);
-Imap*                imapconnect(char *server, int mode, char *root);
+Imap*                imapconnect(char *server, int mode, char *root, char *user);
 int                imapcopylist(Imap *z, char *nbox, Msg **m, uint nm);
 void                imapfetchraw(Imap *z, Part *p);
 void                imapfetchrawbody(Imap *z, Part *p);
diff --git a/src/cmd/upas/nfs/main.c b/src/cmd/upas/nfs/main.c
t@@ -22,14 +22,14 @@ Imap *imap;
 void
 usage(void)
 {
-        fprint(2, "usage: mailfs [-DVtx] [-m mtpt] [-s srvname] [-r root] server\n");
+        fprint(2, "usage: mailfs [-DVtx] [-m mtpt] [-s srvname] [-r root] [-u user] server\n");
         threadexitsall("usage");
 }
 
 void
 threadmain(int argc, char **argv)
 {
-        char *server, *srvname, *root;
+        char *server, *srvname, *root, *user;
         int mode;
         char *mtpt;
 
t@@ -37,6 +37,7 @@ threadmain(int argc, char **argv)
         root = "";
         mode = Unencrypted;
         mtpt = nil;
+        user = nil;
         ARGBEGIN{
         default:
                 usage();
t@@ -55,6 +56,9 @@ threadmain(int argc, char **argv)
         case 't':
                 mode = Tls;
                 break;
+        case 'u':
+                user = EARGF(usage());
+                break;
         case 'x':
                 mode = Cmd;
                 break;
t@@ -74,7 +78,7 @@ threadmain(int argc, char **argv)
         boxinit();
         fsinit0();
 
-        if((imap = imapconnect(server, mode, root)) == nil)
+        if((imap = imapconnect(server, mode, root, user)) == nil)
                 sysfatal("imapconnect: %r");
         threadpostmountsrv(&fs, srvname, mtpt, 0);
 }