4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/mount.h>
16 xstart("mount-cifs", "-m");
21 killall("mount-cifs", SIGTERM
);
22 eval("mount-cifs", "-u");
25 int mount_cifs_main(int argc
, char *argv
[])
33 char *on
, *unc
, *user
, *pass
, *dom
, *exec
, *servern
, *sec
;
39 if (strcmp(argv
[1], "-m") == 0) {
45 for (i
= 1; i
<= 2; ++i
) {
46 if (done
[i
]) continue;
50 sprintf(s
, "cifs%d", i
);
51 strlcpy(s
, nvram_safe_get(s
), sizeof(s
));
52 if ((vstrsep(s
, "<", &on
, &unc
, &user
, &pass
, &dom
, &exec
, &servern
, &sec
) != 8) || (*on
!= '1')) continue;
57 notice_set("cifs", "Mounting...");
62 j
= sprintf(opt
, "sep=<unc=%s", unc
);
63 if (*user
) j
+= sprintf(opt
+ j
, "<user=%s", user
);
64 if (*pass
) j
+= sprintf(opt
+ j
, "<pass=%s", pass
);
65 if (*dom
) j
+= sprintf(opt
+ j
, "<dom=%s", dom
);
66 if (*servern
) j
+= sprintf(opt
+ j
, "<servern=%s", servern
);
67 if (*sec
) j
+= sprintf(opt
+ j
, "<sec=%s", sec
);
69 sprintf(mpath
, "/cifs%d", i
);
71 if (mount("-", mpath
, "cifs", MS_NOATIME
|MS_NODIRATIME
, opt
) != 0) continue;
73 if (try > 12) try = 12; // 1 min
79 _eval(exargv
, NULL
, 0, &pid
);
82 if ((done
[1]) && (done
[2])) {
83 notice_set("cifs", "");
88 if (try == 24) { // 2 min
89 sprintf(s
, "Error mounting CIFS #%s. Still trying... ", (done
[1] == done
[2]) ? "1 and #2" : ((done
[1] == 0) ? "1" : "2"));
90 notice_set("cifs", s
);
92 else if (try > 180) { // 15 mins
99 if (strcmp(argv
[1], "-u") == 0) {
100 for (i
= 1; i
<= 2; ++i
) {
101 sprintf(mpath
, "/cifs%d", i
);
105 notice_set("cifs", "");
110 usage_exit(argv
[0], "-m|-u");