Blame


1 18824b58 2008-08-03 rsc #include "a.h"
2 18824b58 2008-08-03 rsc
3 18824b58 2008-08-03 rsc char *keypattern = "";
4 18824b58 2008-08-03 rsc char *sessid;
5 18824b58 2008-08-03 rsc Json *userinfo;
6 18824b58 2008-08-03 rsc int printerrors;
7 18824b58 2008-08-03 rsc
8 18824b58 2008-08-03 rsc void
9 18824b58 2008-08-03 rsc usage(void)
10 18824b58 2008-08-03 rsc {
11 18824b58 2008-08-03 rsc fprint(2, "usage: smugfs [-k keypattern] [-m mtpt] [-s srv]\n");
12 18824b58 2008-08-03 rsc threadexitsall("usage");
13 18824b58 2008-08-03 rsc }
14 18824b58 2008-08-03 rsc
15 18824b58 2008-08-03 rsc void
16 18824b58 2008-08-03 rsc smuglogin(void)
17 18824b58 2008-08-03 rsc {
18 18824b58 2008-08-03 rsc Json *v;
19 18824b58 2008-08-03 rsc char *s;
20 18824b58 2008-08-03 rsc UserPasswd *up;
21 18824b58 2008-08-03 rsc
22 18824b58 2008-08-03 rsc printerrors = 1;
23 18824b58 2008-08-03 rsc up = auth_getuserpasswd(auth_getkey,
24 18824b58 2008-08-03 rsc "proto=pass role=client server=smugmug.com "
25 18824b58 2008-08-03 rsc "user? !password? %s", keypattern);
26 18824b58 2008-08-03 rsc if(up == nil)
27 18824b58 2008-08-03 rsc sysfatal("cannot get username/password: %r");
28 18824b58 2008-08-03 rsc
29 18824b58 2008-08-03 rsc v = ncsmug("smugmug.login.withPassword",
30 18824b58 2008-08-03 rsc "EmailAddress", up->user,
31 18824b58 2008-08-03 rsc "Password", up->passwd,
32 18824b58 2008-08-03 rsc nil);
33 18824b58 2008-08-03 rsc if(v == nil)
34 18824b58 2008-08-03 rsc sysfatal("login failed: %r");
35 18824b58 2008-08-03 rsc
36 18824b58 2008-08-03 rsc memset(up->user, 'X', strlen(up->user));
37 18824b58 2008-08-03 rsc memset(up->passwd, 'X', strlen(up->passwd));
38 18824b58 2008-08-03 rsc free(up);
39 18824b58 2008-08-03 rsc
40 18824b58 2008-08-03 rsc sessid = jstring(jwalk(v, "Login/Session/id"));
41 18824b58 2008-08-03 rsc if(sessid == nil)
42 18824b58 2008-08-03 rsc sysfatal("no session id");
43 18824b58 2008-08-03 rsc sessid = estrdup(sessid);
44 18824b58 2008-08-03 rsc s = jstring(jwalk(v, "Login/User/NickName"));
45 18824b58 2008-08-03 rsc if(s == nil)
46 18824b58 2008-08-03 rsc sysfatal("no nick name");
47 18824b58 2008-08-03 rsc if(nickindex(s) != 0)
48 18824b58 2008-08-03 rsc sysfatal("bad nick name");
49 18824b58 2008-08-03 rsc userinfo = jincref(jwalk(v, "Login"));
50 18824b58 2008-08-03 rsc jclose(v);
51 18824b58 2008-08-03 rsc printerrors = 0;
52 18824b58 2008-08-03 rsc }
53 18824b58 2008-08-03 rsc
54 18824b58 2008-08-03 rsc void
55 18824b58 2008-08-03 rsc threadmain(int argc, char **argv)
56 18824b58 2008-08-03 rsc {
57 18824b58 2008-08-03 rsc char *mtpt, *name;
58 18824b58 2008-08-03 rsc
59 18824b58 2008-08-03 rsc mtpt = nil;
60 18824b58 2008-08-03 rsc name = nil;
61 18824b58 2008-08-03 rsc ARGBEGIN{
62 18824b58 2008-08-03 rsc case 'D':
63 18824b58 2008-08-03 rsc chatty9p++;
64 18824b58 2008-08-03 rsc break;
65 18824b58 2008-08-03 rsc case 'F':
66 18824b58 2008-08-03 rsc chattyfuse++;
67 18824b58 2008-08-03 rsc break;
68 18824b58 2008-08-03 rsc case 'H':
69 18824b58 2008-08-03 rsc chattyhttp++;
70 18824b58 2008-08-03 rsc break;
71 18824b58 2008-08-03 rsc case 'm':
72 18824b58 2008-08-03 rsc mtpt = EARGF(usage());
73 18824b58 2008-08-03 rsc break;
74 18824b58 2008-08-03 rsc case 's':
75 18824b58 2008-08-03 rsc name = EARGF(usage());
76 18824b58 2008-08-03 rsc break;
77 18824b58 2008-08-03 rsc case 'k':
78 18824b58 2008-08-03 rsc keypattern = EARGF(usage());
79 18824b58 2008-08-03 rsc break;
80 18824b58 2008-08-03 rsc default:
81 18824b58 2008-08-03 rsc usage();
82 18824b58 2008-08-03 rsc }ARGEND
83 18824b58 2008-08-03 rsc
84 18824b58 2008-08-03 rsc if(argc != 0)
85 18824b58 2008-08-03 rsc usage();
86 18824b58 2008-08-03 rsc
87 18824b58 2008-08-03 rsc if(name == nil && mtpt == nil)
88 18824b58 2008-08-03 rsc mtpt = "/n/smug";
89 18824b58 2008-08-03 rsc
90 18824b58 2008-08-03 rsc /*
91 18824b58 2008-08-03 rsc * Check twice -- if there is an exited smugfs instance
92 18824b58 2008-08-03 rsc * mounted there, the first access will fail but unmount it.
93 18824b58 2008-08-03 rsc */
94 18824b58 2008-08-03 rsc if(mtpt && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0)
95 18824b58 2008-08-03 rsc sysfatal("mountpoint %s does not exist", mtpt);
96 18824b58 2008-08-03 rsc
97 18824b58 2008-08-03 rsc fmtinstall('H', encodefmt);
98 18824b58 2008-08-03 rsc fmtinstall('[', encodefmt); // base-64
99 18824b58 2008-08-03 rsc fmtinstall('J', jsonfmt);
100 18824b58 2008-08-03 rsc fmtinstall('M', dirmodefmt);
101 18824b58 2008-08-03 rsc fmtinstall('T', timefmt);
102 18824b58 2008-08-03 rsc fmtinstall('U', urlencodefmt);
103 18824b58 2008-08-03 rsc
104 18824b58 2008-08-03 rsc xinit();
105 18824b58 2008-08-03 rsc smuglogin();
106 18824b58 2008-08-03 rsc threadpostmountsrv(&xsrv, name, mtpt, 0);
107 18824b58 2008-08-03 rsc threadexits(nil);
108 18824b58 2008-08-03 rsc }