Lines 61-75
enum nfsd_fsid {
Link Here
|
61 |
* Record is terminated with newline. |
61 |
* Record is terminated with newline. |
62 |
* |
62 |
* |
63 |
*/ |
63 |
*/ |
64 |
static int cache_export_ent(char *domain, struct exportent *exp, char *p); |
64 |
static int cache_export_ent(char *buf, int buflen, char *domain, struct exportent *exp, char *path); |
65 |
|
65 |
|
66 |
#define INITIAL_MANAGED_GROUPS 100 |
66 |
#define INITIAL_MANAGED_GROUPS 100 |
67 |
|
67 |
|
68 |
char *lbuf = NULL; |
|
|
69 |
int lbuflen = 0; |
70 |
extern int use_ipaddr; |
68 |
extern int use_ipaddr; |
71 |
|
69 |
|
72 |
static void auth_unix_ip(FILE *f) |
70 |
static void auth_unix_ip(int f) |
73 |
{ |
71 |
{ |
74 |
/* requests are |
72 |
/* requests are |
75 |
* class IP-ADDR |
73 |
* class IP-ADDR |
Lines 78-100
static void auth_unix_ip(FILE *f)
Link Here
|
78 |
* |
76 |
* |
79 |
* "nfsd" IP-ADDR expiry domainname |
77 |
* "nfsd" IP-ADDR expiry domainname |
80 |
*/ |
78 |
*/ |
81 |
char *cp; |
|
|
82 |
char class[20]; |
79 |
char class[20]; |
83 |
char ipaddr[INET6_ADDRSTRLEN + 1]; |
80 |
char ipaddr[INET6_ADDRSTRLEN + 1]; |
84 |
char *client = NULL; |
81 |
char *client = NULL; |
85 |
struct addrinfo *tmp = NULL; |
82 |
struct addrinfo *tmp = NULL; |
86 |
if (readline(fileno(f), &lbuf, &lbuflen) != 1) |
83 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
87 |
return; |
84 |
int blen; |
|
|
85 |
|
86 |
blen = read(f, buf, sizeof(buf)); |
87 |
if (blen <= 0 || buf[blen-1] != '\n') return; |
88 |
buf[blen-1] = 0; |
88 |
|
89 |
|
89 |
xlog(D_CALL, "auth_unix_ip: inbuf '%s'", lbuf); |
90 |
xlog(D_CALL, "auth_unix_ip: inbuf '%s'", buf); |
90 |
|
91 |
|
91 |
cp = lbuf; |
92 |
bp = buf; |
92 |
|
93 |
|
93 |
if (qword_get(&cp, class, 20) <= 0 || |
94 |
if (qword_get(&bp, class, 20) <= 0 || |
94 |
strcmp(class, "nfsd") != 0) |
95 |
strcmp(class, "nfsd") != 0) |
95 |
return; |
96 |
return; |
96 |
|
97 |
|
97 |
if (qword_get(&cp, ipaddr, sizeof(ipaddr) - 1) <= 0) |
98 |
if (qword_get(&bp, ipaddr, sizeof(ipaddr) - 1) <= 0) |
98 |
return; |
99 |
return; |
99 |
|
100 |
|
100 |
tmp = host_pton(ipaddr); |
101 |
tmp = host_pton(ipaddr); |
Lines 113-128
static void auth_unix_ip(FILE *f)
Link Here
|
113 |
freeaddrinfo(ai); |
114 |
freeaddrinfo(ai); |
114 |
} |
115 |
} |
115 |
} |
116 |
} |
116 |
qword_print(f, "nfsd"); |
117 |
bp = buf; blen = sizeof(buf); |
117 |
qword_print(f, ipaddr); |
118 |
qword_add(&bp, &blen, "nfsd"); |
118 |
qword_printtimefrom(f, DEFAULT_TTL); |
119 |
qword_add(&bp, &blen, ipaddr); |
|
|
120 |
qword_adduint(&bp, &blen, time(0) + DEFAULT_TTL); |
119 |
if (use_ipaddr) { |
121 |
if (use_ipaddr) { |
120 |
memmove(ipaddr + 1, ipaddr, strlen(ipaddr) + 1); |
122 |
memmove(ipaddr + 1, ipaddr, strlen(ipaddr) + 1); |
121 |
ipaddr[0] = '$'; |
123 |
ipaddr[0] = '$'; |
122 |
qword_print(f, ipaddr); |
124 |
qword_add(&bp, &blen, ipaddr); |
123 |
} else if (client) |
125 |
} else if (client) |
124 |
qword_print(f, *client?client:"DEFAULT"); |
126 |
qword_add(&bp, &blen, *client?client:"DEFAULT"); |
125 |
qword_eol(f); |
127 |
qword_addeol(&bp, &blen); |
|
|
128 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) |
129 |
xlog(L_ERROR, "auth_unix_ip: error writing reply"); |
130 |
|
126 |
xlog(D_CALL, "auth_unix_ip: client %p '%s'", client, client?client: "DEFAULT"); |
131 |
xlog(D_CALL, "auth_unix_ip: client %p '%s'", client, client?client: "DEFAULT"); |
127 |
|
132 |
|
128 |
free(client); |
133 |
free(client); |
Lines 130-136
static void auth_unix_ip(FILE *f)
Link Here
|
130 |
|
135 |
|
131 |
} |
136 |
} |
132 |
|
137 |
|
133 |
static void auth_unix_gid(FILE *f) |
138 |
static void auth_unix_gid(int f) |
134 |
{ |
139 |
{ |
135 |
/* Request are |
140 |
/* Request are |
136 |
* uid |
141 |
* uid |
Lines 144-150
static void auth_unix_gid(FILE *f)
Link Here
|
144 |
gid_t *more_groups; |
149 |
gid_t *more_groups; |
145 |
int ngroups; |
150 |
int ngroups; |
146 |
int rv, i; |
151 |
int rv, i; |
147 |
char *cp; |
152 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
|
|
153 |
int blen; |
148 |
|
154 |
|
149 |
if (groups_len == 0) { |
155 |
if (groups_len == 0) { |
150 |
groups = malloc(sizeof(gid_t) * INITIAL_MANAGED_GROUPS); |
156 |
groups = malloc(sizeof(gid_t) * INITIAL_MANAGED_GROUPS); |
Lines 156-166
static void auth_unix_gid(FILE *f)
Link Here
|
156 |
|
162 |
|
157 |
ngroups = groups_len; |
163 |
ngroups = groups_len; |
158 |
|
164 |
|
159 |
if (readline(fileno(f), &lbuf, &lbuflen) != 1) |
165 |
blen = read(f, buf, sizeof(buf)); |
160 |
return; |
166 |
if (blen <= 0 || buf[blen-1] != '\n') return; |
|
|
167 |
buf[blen-1] = 0; |
161 |
|
168 |
|
162 |
cp = lbuf; |
169 |
bp = buf; |
163 |
if (qword_get_uint(&cp, &uid) != 0) |
170 |
if (qword_get_uint(&bp, &uid) != 0) |
164 |
return; |
171 |
return; |
165 |
|
172 |
|
166 |
pw = getpwuid(uid); |
173 |
pw = getpwuid(uid); |
Lines 180-194
static void auth_unix_gid(FILE *f)
Link Here
|
180 |
} |
187 |
} |
181 |
} |
188 |
} |
182 |
} |
189 |
} |
183 |
qword_printuint(f, uid); |
190 |
|
184 |
qword_printtimefrom(f, DEFAULT_TTL); |
191 |
bp = buf; blen = sizeof(buf); |
|
|
192 |
qword_adduint(&bp, &blen, uid); |
193 |
qword_adduint(&bp, &blen, time(0) + DEFAULT_TTL); |
185 |
if (rv >= 0) { |
194 |
if (rv >= 0) { |
186 |
qword_printuint(f, ngroups); |
195 |
qword_adduint(&bp, &blen, ngroups); |
187 |
for (i=0; i<ngroups; i++) |
196 |
for (i=0; i<ngroups; i++) |
188 |
qword_printuint(f, groups[i]); |
197 |
qword_adduint(&bp, &blen, groups[i]); |
189 |
} else |
198 |
} else |
190 |
qword_printuint(f, 0); |
199 |
qword_adduint(&bp, &blen, 0); |
191 |
qword_eol(f); |
200 |
qword_addeol(&bp, &blen); |
|
|
201 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) |
202 |
xlog(L_ERROR, "auth_unix_gid: error writing reply"); |
192 |
} |
203 |
} |
193 |
|
204 |
|
194 |
#if USE_BLKID |
205 |
#if USE_BLKID |
Lines 659-672
static struct addrinfo *lookup_client_addr(char *dom)
Link Here
|
659 |
return ret; |
670 |
return ret; |
660 |
} |
671 |
} |
661 |
|
672 |
|
662 |
static void nfsd_fh(FILE *f) |
673 |
static void nfsd_fh(int f) |
663 |
{ |
674 |
{ |
664 |
/* request are: |
675 |
/* request are: |
665 |
* domain fsidtype fsid |
676 |
* domain fsidtype fsid |
666 |
* interpret fsid, find export point and options, and write: |
677 |
* interpret fsid, find export point and options, and write: |
667 |
* domain fsidtype fsid expiry path |
678 |
* domain fsidtype fsid expiry path |
668 |
*/ |
679 |
*/ |
669 |
char *cp; |
|
|
670 |
char *dom; |
680 |
char *dom; |
671 |
int fsidtype; |
681 |
int fsidtype; |
672 |
int fsidlen; |
682 |
int fsidlen; |
Lines 678-701
static void nfsd_fh(FILE *f)
Link Here
|
678 |
nfs_export *exp; |
688 |
nfs_export *exp; |
679 |
int i; |
689 |
int i; |
680 |
int dev_missing = 0; |
690 |
int dev_missing = 0; |
|
|
691 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
692 |
int blen; |
681 |
|
693 |
|
682 |
if (readline(fileno(f), &lbuf, &lbuflen) != 1) |
694 |
blen = read(f, buf, sizeof(buf)); |
683 |
return; |
695 |
if (blen <= 0 || buf[blen-1] != '\n') return; |
|
|
696 |
buf[blen-1] = 0; |
684 |
|
697 |
|
685 |
xlog(D_CALL, "nfsd_fh: inbuf '%s'", lbuf); |
698 |
xlog(D_CALL, "nfsd_fh: inbuf '%s'", buf); |
686 |
|
699 |
|
687 |
cp = lbuf; |
700 |
bp = buf; |
688 |
|
701 |
|
689 |
dom = malloc(strlen(cp)); |
702 |
dom = malloc(blen); |
690 |
if (dom == NULL) |
703 |
if (dom == NULL) |
691 |
return; |
704 |
return; |
692 |
if (qword_get(&cp, dom, strlen(cp)) <= 0) |
705 |
if (qword_get(&bp, dom, blen) <= 0) |
693 |
goto out; |
706 |
goto out; |
694 |
if (qword_get_int(&cp, &fsidtype) != 0) |
707 |
if (qword_get_int(&bp, &fsidtype) != 0) |
695 |
goto out; |
708 |
goto out; |
696 |
if (fsidtype < 0 || fsidtype > 7) |
709 |
if (fsidtype < 0 || fsidtype > 7) |
697 |
goto out; /* unknown type */ |
710 |
goto out; /* unknown type */ |
698 |
if ((fsidlen = qword_get(&cp, fsid, 32)) <= 0) |
711 |
if ((fsidlen = qword_get(&bp, fsid, 32)) <= 0) |
699 |
goto out; |
712 |
goto out; |
700 |
if (parse_fsid(fsidtype, fsidlen, fsid, &parsed)) |
713 |
if (parse_fsid(fsidtype, fsidlen, fsid, &parsed)) |
701 |
goto out; |
714 |
goto out; |
Lines 796-807
static void nfsd_fh(FILE *f)
Link Here
|
796 |
} |
809 |
} |
797 |
|
810 |
|
798 |
if (found) |
811 |
if (found) |
799 |
if (cache_export_ent(dom, found, found_path) < 0) |
812 |
if (cache_export_ent(buf, sizeof(buf), dom, found, found_path) < 0) |
800 |
found = 0; |
813 |
found = 0; |
801 |
|
814 |
|
802 |
qword_print(f, dom); |
815 |
bp = buf; blen = sizeof(buf); |
803 |
qword_printint(f, fsidtype); |
816 |
qword_add(&bp, &blen, dom); |
804 |
qword_printhex(f, fsid, fsidlen); |
817 |
qword_addint(&bp, &blen, fsidtype); |
|
|
818 |
qword_addhex(&bp, &blen, fsid, fsidlen); |
805 |
/* The fsid -> path lookup can be quite expensive as it |
819 |
/* The fsid -> path lookup can be quite expensive as it |
806 |
* potentially stats and reads lots of devices, and some of those |
820 |
* potentially stats and reads lots of devices, and some of those |
807 |
* might have spun-down. The Answer is not likely to |
821 |
* might have spun-down. The Answer is not likely to |
Lines 810-829
static void nfsd_fh(FILE *f)
Link Here
|
810 |
* timeout. Maybe this should be configurable on the command |
824 |
* timeout. Maybe this should be configurable on the command |
811 |
* line. |
825 |
* line. |
812 |
*/ |
826 |
*/ |
813 |
qword_printint(f, 0x7fffffff); |
827 |
qword_addint(&bp, &blen, 0x7fffffff); |
814 |
if (found) |
828 |
if (found) |
815 |
qword_print(f, found_path); |
829 |
qword_add(&bp, &blen, found_path); |
816 |
qword_eol(f); |
830 |
qword_addeol(&bp, &blen); |
817 |
out: |
831 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) |
|
|
832 |
xlog(L_ERROR, "nfsd_fh: error writing reply"); |
833 |
out: |
818 |
if (found_path) |
834 |
if (found_path) |
819 |
free(found_path); |
835 |
free(found_path); |
820 |
freeaddrinfo(ai); |
836 |
freeaddrinfo(ai); |
821 |
free(dom); |
837 |
free(dom); |
822 |
xlog(D_CALL, "nfsd_fh: found %p path %s", found, found ? found->e_path : NULL); |
838 |
xlog(D_CALL, "nfsd_fh: found %p path %s", found, found ? found->e_path : NULL); |
823 |
return; |
|
|
824 |
} |
839 |
} |
825 |
|
840 |
|
826 |
static void write_fsloc(FILE *f, struct exportent *ep) |
841 |
static void write_fsloc(char **bp, int *blen, struct exportent *ep) |
827 |
{ |
842 |
{ |
828 |
struct servers *servers; |
843 |
struct servers *servers; |
829 |
|
844 |
|
Lines 833-852
static void write_fsloc(FILE *f, struct exportent *ep)
Link Here
|
833 |
servers = replicas_lookup(ep->e_fslocmethod, ep->e_fslocdata); |
848 |
servers = replicas_lookup(ep->e_fslocmethod, ep->e_fslocdata); |
834 |
if (!servers) |
849 |
if (!servers) |
835 |
return; |
850 |
return; |
836 |
qword_print(f, "fsloc"); |
851 |
qword_add(bp, blen, "fsloc"); |
837 |
qword_printint(f, servers->h_num); |
852 |
qword_addint(bp, blen, servers->h_num); |
838 |
if (servers->h_num >= 0) { |
853 |
if (servers->h_num >= 0) { |
839 |
int i; |
854 |
int i; |
840 |
for (i=0; i<servers->h_num; i++) { |
855 |
for (i=0; i<servers->h_num; i++) { |
841 |
qword_print(f, servers->h_mp[i]->h_host); |
856 |
qword_add(bp, blen, servers->h_mp[i]->h_host); |
842 |
qword_print(f, servers->h_mp[i]->h_path); |
857 |
qword_add(bp, blen, servers->h_mp[i]->h_path); |
843 |
} |
858 |
} |
844 |
} |
859 |
} |
845 |
qword_printint(f, servers->h_referral); |
860 |
qword_addint(bp, blen, servers->h_referral); |
846 |
release_replicas(servers); |
861 |
release_replicas(servers); |
847 |
} |
862 |
} |
848 |
|
863 |
|
849 |
static void write_secinfo(FILE *f, struct exportent *ep, int flag_mask) |
864 |
static void write_secinfo(char **bp, int *blen, struct exportent *ep, int flag_mask) |
850 |
{ |
865 |
{ |
851 |
struct sec_entry *p; |
866 |
struct sec_entry *p; |
852 |
|
867 |
|
Lines 857-901
static void write_secinfo(FILE *f, struct exportent *ep, int flag_mask)
Link Here
|
857 |
return; |
872 |
return; |
858 |
} |
873 |
} |
859 |
fix_pseudoflavor_flags(ep); |
874 |
fix_pseudoflavor_flags(ep); |
860 |
qword_print(f, "secinfo"); |
875 |
qword_add(bp, blen, "secinfo"); |
861 |
qword_printint(f, p - ep->e_secinfo); |
876 |
qword_addint(bp, blen, p - ep->e_secinfo); |
862 |
for (p = ep->e_secinfo; p->flav; p++) { |
877 |
for (p = ep->e_secinfo; p->flav; p++) { |
863 |
qword_printint(f, p->flav->fnum); |
878 |
qword_addint(bp, blen, p->flav->fnum); |
864 |
qword_printint(f, p->flags & flag_mask); |
879 |
qword_addint(bp, blen, p->flags & flag_mask); |
865 |
} |
880 |
} |
866 |
|
881 |
|
867 |
} |
882 |
} |
868 |
|
883 |
|
869 |
static int dump_to_cache(FILE *f, char *domain, char *path, struct exportent *exp) |
884 |
static int dump_to_cache(int f, char *buf, int buflen, char *domain, char *path, struct exportent *exp) |
870 |
{ |
885 |
{ |
871 |
qword_print(f, domain); |
886 |
char *bp = buf; |
872 |
qword_print(f, path); |
887 |
int blen = buflen; |
|
|
888 |
time_t now = time(0); |
889 |
|
890 |
qword_add(&bp, &blen, domain); |
891 |
qword_add(&bp, &blen, path); |
873 |
if (exp) { |
892 |
if (exp) { |
874 |
int different_fs = strcmp(path, exp->e_path) != 0; |
893 |
int different_fs = strcmp(path, exp->e_path) != 0; |
875 |
int flag_mask = different_fs ? ~NFSEXP_FSID : ~0; |
894 |
int flag_mask = different_fs ? ~NFSEXP_FSID : ~0; |
876 |
|
895 |
|
877 |
qword_printtimefrom(f, exp->e_ttl); |
896 |
qword_adduint(&bp, &blen, now + exp->e_ttl); |
878 |
qword_printint(f, exp->e_flags & flag_mask); |
897 |
qword_addint(&bp, &blen, exp->e_flags & flag_mask); |
879 |
qword_printint(f, exp->e_anonuid); |
898 |
qword_addint(&bp, &blen, exp->e_anonuid); |
880 |
qword_printint(f, exp->e_anongid); |
899 |
qword_addint(&bp, &blen, exp->e_anongid); |
881 |
qword_printint(f, exp->e_fsid); |
900 |
qword_addint(&bp, &blen, exp->e_fsid); |
882 |
write_fsloc(f, exp); |
901 |
write_fsloc(&bp, &blen, exp); |
883 |
write_secinfo(f, exp, flag_mask); |
902 |
write_secinfo(&bp, &blen, exp, flag_mask); |
884 |
if (exp->e_uuid == NULL || different_fs) { |
903 |
if (exp->e_uuid == NULL || different_fs) { |
885 |
char u[16]; |
904 |
char u[16]; |
886 |
if (uuid_by_path(path, 0, 16, u)) { |
905 |
if (uuid_by_path(path, 0, 16, u)) { |
887 |
qword_print(f, "uuid"); |
906 |
qword_add(&bp, &blen, "uuid"); |
888 |
qword_printhex(f, u, 16); |
907 |
qword_addhex(&bp, &blen, u, 16); |
889 |
} |
908 |
} |
890 |
} else { |
909 |
} else { |
891 |
char u[16]; |
910 |
char u[16]; |
892 |
get_uuid(exp->e_uuid, 16, u); |
911 |
get_uuid(exp->e_uuid, 16, u); |
893 |
qword_print(f, "uuid"); |
912 |
qword_add(&bp, &blen, "uuid"); |
894 |
qword_printhex(f, u, 16); |
913 |
qword_addhex(&bp, &blen, u, 16); |
895 |
} |
914 |
} |
896 |
} else |
915 |
} else |
897 |
qword_printtimefrom(f, DEFAULT_TTL); |
916 |
qword_adduint(&bp, &blen, now + DEFAULT_TTL); |
898 |
return qword_eol(f); |
917 |
qword_addeol(&bp, &blen); |
|
|
918 |
if (blen <= 0) return -1; |
919 |
if (write(f, buf, bp - buf) != bp - buf) return -1; |
920 |
return 0; |
899 |
} |
921 |
} |
900 |
|
922 |
|
901 |
static nfs_export * |
923 |
static nfs_export * |
Lines 1245-1271
static struct exportent *lookup_junction(char *dom, const char *pathname,
Link Here
|
1245 |
return exp; |
1267 |
return exp; |
1246 |
} |
1268 |
} |
1247 |
|
1269 |
|
1248 |
static void lookup_nonexport(FILE *f, char *dom, char *path, |
1270 |
static void lookup_nonexport(int f, char *buf, int buflen, char *dom, char *path, |
1249 |
struct addrinfo *ai) |
1271 |
struct addrinfo *ai) |
1250 |
{ |
1272 |
{ |
1251 |
struct exportent *eep; |
1273 |
struct exportent *eep; |
1252 |
|
1274 |
|
1253 |
eep = lookup_junction(dom, path, ai); |
1275 |
eep = lookup_junction(dom, path, ai); |
1254 |
dump_to_cache(f, dom, path, eep); |
1276 |
dump_to_cache(f, buf, buflen, dom, path, eep); |
1255 |
if (eep == NULL) |
1277 |
if (eep == NULL) |
1256 |
return; |
1278 |
return; |
1257 |
exportent_release(eep); |
1279 |
exportent_release(eep); |
1258 |
free(eep); |
1280 |
free(eep); |
1259 |
} |
1281 |
} |
1260 |
#else /* !HAVE_NFS_PLUGIN_H */ |
1282 |
#else /* !HAVE_NFS_PLUGIN_H */ |
1261 |
static void lookup_nonexport(FILE *f, char *dom, char *path, |
1283 |
static void lookup_nonexport(int f, char *buf, int buflen, char *dom, char *path, |
1262 |
struct addrinfo *UNUSED(ai)) |
1284 |
struct addrinfo *UNUSED(ai)) |
1263 |
{ |
1285 |
{ |
1264 |
dump_to_cache(f, dom, path, NULL); |
1286 |
dump_to_cache(f, buf, buflen, dom, path, NULL); |
1265 |
} |
1287 |
} |
1266 |
#endif /* !HAVE_NFS_PLUGIN_H */ |
1288 |
#endif /* !HAVE_NFS_PLUGIN_H */ |
1267 |
|
1289 |
|
1268 |
static void nfsd_export(FILE *f) |
1290 |
static void nfsd_export(int f) |
1269 |
{ |
1291 |
{ |
1270 |
/* requests are: |
1292 |
/* requests are: |
1271 |
* domain path |
1293 |
* domain path |
Lines 1273-1298
static void nfsd_export(FILE *f)
Link Here
|
1273 |
* domain path expiry flags anonuid anongid fsid |
1295 |
* domain path expiry flags anonuid anongid fsid |
1274 |
*/ |
1296 |
*/ |
1275 |
|
1297 |
|
1276 |
char *cp; |
|
|
1277 |
char *dom, *path; |
1298 |
char *dom, *path; |
1278 |
nfs_export *found = NULL; |
1299 |
nfs_export *found = NULL; |
1279 |
struct addrinfo *ai = NULL; |
1300 |
struct addrinfo *ai = NULL; |
|
|
1301 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
1302 |
int blen; |
1280 |
|
1303 |
|
1281 |
if (readline(fileno(f), &lbuf, &lbuflen) != 1) |
1304 |
blen = read(f, buf, sizeof(buf)); |
1282 |
return; |
1305 |
if (blen <= 0 || buf[blen-1] != '\n') return; |
|
|
1306 |
buf[blen-1] = 0; |
1283 |
|
1307 |
|
1284 |
xlog(D_CALL, "nfsd_export: inbuf '%s'", lbuf); |
1308 |
xlog(D_CALL, "nfsd_export: inbuf '%s'", buf); |
1285 |
|
1309 |
|
1286 |
cp = lbuf; |
1310 |
bp = buf; |
1287 |
dom = malloc(strlen(cp)); |
1311 |
dom = malloc(blen); |
1288 |
path = malloc(strlen(cp)); |
1312 |
path = malloc(blen); |
1289 |
|
1313 |
|
1290 |
if (!dom || !path) |
1314 |
if (!dom || !path) |
1291 |
goto out; |
1315 |
goto out; |
1292 |
|
1316 |
|
1293 |
if (qword_get(&cp, dom, strlen(lbuf)) <= 0) |
1317 |
if (qword_get(&bp, dom, blen) <= 0) |
1294 |
goto out; |
1318 |
goto out; |
1295 |
if (qword_get(&cp, path, strlen(lbuf)) <= 0) |
1319 |
if (qword_get(&bp, path, blen) <= 0) |
1296 |
goto out; |
1320 |
goto out; |
1297 |
|
1321 |
|
1298 |
auth_reload(); |
1322 |
auth_reload(); |
Lines 1306-1319
static void nfsd_export(FILE *f)
Link Here
|
1306 |
found = lookup_export(dom, path, ai); |
1330 |
found = lookup_export(dom, path, ai); |
1307 |
|
1331 |
|
1308 |
if (found) { |
1332 |
if (found) { |
1309 |
if (dump_to_cache(f, dom, path, &found->m_export) < 0) { |
1333 |
if (dump_to_cache(f, buf, sizeof(buf), dom, path, &found->m_export) < 0) { |
1310 |
xlog(L_WARNING, |
1334 |
xlog(L_WARNING, |
1311 |
"Cannot export %s, possibly unsupported filesystem" |
1335 |
"Cannot export %s, possibly unsupported filesystem" |
1312 |
" or fsid= required", path); |
1336 |
" or fsid= required", path); |
1313 |
dump_to_cache(f, dom, path, NULL); |
1337 |
dump_to_cache(f, buf, sizeof(buf), dom, path, NULL); |
1314 |
} |
1338 |
} |
1315 |
} else |
1339 |
} else |
1316 |
lookup_nonexport(f, dom, path, ai); |
1340 |
lookup_nonexport(f, buf, sizeof(buf), dom, path, ai); |
1317 |
|
1341 |
|
1318 |
out: |
1342 |
out: |
1319 |
xlog(D_CALL, "nfsd_export: found %p path %s", found, path ? path : NULL); |
1343 |
xlog(D_CALL, "nfsd_export: found %p path %s", found, path ? path : NULL); |
Lines 1325-1339
static void nfsd_export(FILE *f)
Link Here
|
1325 |
|
1349 |
|
1326 |
struct { |
1350 |
struct { |
1327 |
char *cache_name; |
1351 |
char *cache_name; |
1328 |
void (*cache_handle)(FILE *f); |
1352 |
void (*cache_handle)(int f); |
1329 |
FILE *f; |
1353 |
int f; |
1330 |
char vbuf[RPC_CHAN_BUF_SIZE]; |
|
|
1331 |
} cachelist[] = { |
1354 |
} cachelist[] = { |
1332 |
{ "auth.unix.ip", auth_unix_ip, NULL, ""}, |
1355 |
{ "auth.unix.ip", auth_unix_ip, -1 }, |
1333 |
{ "auth.unix.gid", auth_unix_gid, NULL, ""}, |
1356 |
{ "auth.unix.gid", auth_unix_gid, -1 }, |
1334 |
{ "nfsd.export", nfsd_export, NULL, ""}, |
1357 |
{ "nfsd.export", nfsd_export, -1 }, |
1335 |
{ "nfsd.fh", nfsd_fh, NULL, ""}, |
1358 |
{ "nfsd.fh", nfsd_fh, -1 }, |
1336 |
{ NULL, NULL, NULL, ""} |
1359 |
{ NULL, NULL, -1 } |
1337 |
}; |
1360 |
}; |
1338 |
|
1361 |
|
1339 |
extern int manage_gids; |
1362 |
extern int manage_gids; |
Lines 1350-1360
void cache_open(void)
Link Here
|
1350 |
if (!manage_gids && cachelist[i].cache_handle == auth_unix_gid) |
1373 |
if (!manage_gids && cachelist[i].cache_handle == auth_unix_gid) |
1351 |
continue; |
1374 |
continue; |
1352 |
sprintf(path, "/proc/net/rpc/%s/channel", cachelist[i].cache_name); |
1375 |
sprintf(path, "/proc/net/rpc/%s/channel", cachelist[i].cache_name); |
1353 |
cachelist[i].f = fopen(path, "r+"); |
1376 |
cachelist[i].f = open(path, O_RDWR); |
1354 |
if (cachelist[i].f != NULL) { |
|
|
1355 |
setvbuf(cachelist[i].f, cachelist[i].vbuf, _IOLBF, |
1356 |
RPC_CHAN_BUF_SIZE); |
1357 |
} |
1358 |
} |
1377 |
} |
1359 |
} |
1378 |
} |
1360 |
|
1379 |
|
Lines 1366-1373
void cache_set_fds(fd_set *fdset)
Link Here
|
1366 |
{ |
1385 |
{ |
1367 |
int i; |
1386 |
int i; |
1368 |
for (i=0; cachelist[i].cache_name; i++) { |
1387 |
for (i=0; cachelist[i].cache_name; i++) { |
1369 |
if (cachelist[i].f) |
1388 |
if (cachelist[i].f >= 0) |
1370 |
FD_SET(fileno(cachelist[i].f), fdset); |
1389 |
FD_SET(cachelist[i].f, fdset); |
1371 |
} |
1390 |
} |
1372 |
} |
1391 |
} |
1373 |
|
1392 |
|
Lines 1380-1390
int cache_process_req(fd_set *readfds)
Link Here
|
1380 |
int i; |
1399 |
int i; |
1381 |
int cnt = 0; |
1400 |
int cnt = 0; |
1382 |
for (i=0; cachelist[i].cache_name; i++) { |
1401 |
for (i=0; cachelist[i].cache_name; i++) { |
1383 |
if (cachelist[i].f != NULL && |
1402 |
if (cachelist[i].f >= 0 && |
1384 |
FD_ISSET(fileno(cachelist[i].f), readfds)) { |
1403 |
FD_ISSET(cachelist[i].f, readfds)) { |
1385 |
cnt++; |
1404 |
cnt++; |
1386 |
cachelist[i].cache_handle(cachelist[i].f); |
1405 |
cachelist[i].cache_handle(cachelist[i].f); |
1387 |
FD_CLR(fileno(cachelist[i].f), readfds); |
1406 |
FD_CLR(cachelist[i].f, readfds); |
1388 |
} |
1407 |
} |
1389 |
} |
1408 |
} |
1390 |
return cnt; |
1409 |
return cnt; |
Lines 1397-1410
int cache_process_req(fd_set *readfds)
Link Here
|
1397 |
* % echo $domain $path $[now+DEFAULT_TTL] $options $anonuid $anongid $fsid > /proc/net/rpc/nfsd.export/channel |
1416 |
* % echo $domain $path $[now+DEFAULT_TTL] $options $anonuid $anongid $fsid > /proc/net/rpc/nfsd.export/channel |
1398 |
*/ |
1417 |
*/ |
1399 |
|
1418 |
|
1400 |
static int cache_export_ent(char *domain, struct exportent *exp, char *path) |
1419 |
static int cache_export_ent(char *buf, int buflen, char *domain, struct exportent *exp, char *path) |
1401 |
{ |
1420 |
{ |
1402 |
int err; |
1421 |
int f, err; |
1403 |
FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "w"); |
1422 |
|
1404 |
if (!f) |
1423 |
f = open("/proc/net/rpc/nfsd.export/channel", O_WRONLY); |
1405 |
return -1; |
1424 |
if (f < 0) return -1; |
1406 |
|
1425 |
|
1407 |
err = dump_to_cache(f, domain, exp->e_path, exp); |
1426 |
err = dump_to_cache(f, buf, buflen, domain, exp->e_path, exp); |
1408 |
if (err) { |
1427 |
if (err) { |
1409 |
xlog(L_WARNING, |
1428 |
xlog(L_WARNING, |
1410 |
"Cannot export %s, possibly unsupported filesystem or" |
1429 |
"Cannot export %s, possibly unsupported filesystem or" |
Lines 1445-1457
static int cache_export_ent(char *domain, struct exportent *exp, char *path)
Link Here
|
1445 |
continue; |
1464 |
continue; |
1446 |
dev = stb.st_dev; |
1465 |
dev = stb.st_dev; |
1447 |
path[l] = 0; |
1466 |
path[l] = 0; |
1448 |
dump_to_cache(f, domain, path, exp); |
1467 |
dump_to_cache(f, buf, buflen, domain, path, exp); |
1449 |
path[l] = c; |
1468 |
path[l] = c; |
1450 |
} |
1469 |
} |
1451 |
break; |
1470 |
break; |
1452 |
} |
1471 |
} |
1453 |
|
1472 |
|
1454 |
fclose(f); |
1473 |
close(f); |
1455 |
return err; |
1474 |
return err; |
1456 |
} |
1475 |
} |
1457 |
|
1476 |
|
Lines 1462-1488
static int cache_export_ent(char *domain, struct exportent *exp, char *path)
Link Here
|
1462 |
*/ |
1481 |
*/ |
1463 |
int cache_export(nfs_export *exp, char *path) |
1482 |
int cache_export(nfs_export *exp, char *path) |
1464 |
{ |
1483 |
{ |
1465 |
char buf[INET6_ADDRSTRLEN]; |
1484 |
char ip[INET6_ADDRSTRLEN]; |
1466 |
int err; |
1485 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
1467 |
FILE *f; |
1486 |
int blen, f; |
1468 |
|
1487 |
|
1469 |
f = fopen("/proc/net/rpc/auth.unix.ip/channel", "w"); |
1488 |
f = open("/proc/net/rpc/auth.unix.ip/channel", O_WRONLY); |
1470 |
if (!f) |
1489 |
if (f < 0) |
1471 |
return -1; |
1490 |
return -1; |
1472 |
|
1491 |
|
1473 |
|
1492 |
bp = buf, blen = sizeof(buf); |
1474 |
qword_print(f, "nfsd"); |
1493 |
qword_add(&bp, &blen, "nfsd"); |
1475 |
qword_print(f, |
1494 |
qword_add(&bp, &blen, host_ntop(get_addrlist(exp->m_client, 0), ip, sizeof(ip))); |
1476 |
host_ntop(get_addrlist(exp->m_client, 0), buf, sizeof(buf))); |
1495 |
qword_adduint(&bp, &blen, time(0) + exp->m_export.e_ttl); |
1477 |
qword_printtimefrom(f, exp->m_export.e_ttl); |
1496 |
qword_add(&bp, &blen, exp->m_client->m_hostname); |
1478 |
qword_print(f, exp->m_client->m_hostname); |
1497 |
qword_addeol(&bp, &blen); |
1479 |
err = qword_eol(f); |
1498 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) blen = -1; |
1480 |
|
1499 |
close(f); |
1481 |
fclose(f); |
1500 |
if (blen < 0) return -1; |
1482 |
|
1501 |
|
1483 |
err = cache_export_ent(exp->m_client->m_hostname, &exp->m_export, path) |
1502 |
return cache_export_ent(buf, sizeof(buf), exp->m_client->m_hostname, &exp->m_export, path); |
1484 |
|| err; |
|
|
1485 |
return err; |
1486 |
} |
1503 |
} |
1487 |
|
1504 |
|
1488 |
/** |
1505 |
/** |
Lines 1501-1527
int cache_export(nfs_export *exp, char *path)
Link Here
|
1501 |
struct nfs_fh_len * |
1518 |
struct nfs_fh_len * |
1502 |
cache_get_filehandle(nfs_export *exp, int len, char *p) |
1519 |
cache_get_filehandle(nfs_export *exp, int len, char *p) |
1503 |
{ |
1520 |
{ |
1504 |
FILE *f = fopen("/proc/fs/nfsd/filehandle", "r+"); |
|
|
1505 |
char buf[200]; |
1506 |
char *bp = buf; |
1507 |
int failed; |
1508 |
static struct nfs_fh_len fh; |
1521 |
static struct nfs_fh_len fh; |
|
|
1522 |
char buf[RPC_CHAN_BUF_SIZE], *bp; |
1523 |
int blen, f; |
1524 |
|
1525 |
f = open("/proc/fs/nfsd/filehandle", O_RDWR); |
1526 |
if (f < 0) { |
1527 |
f = open("/proc/fs/nfs/filehandle", O_RDWR); |
1528 |
if (f < 0) return NULL; |
1529 |
} |
1509 |
|
1530 |
|
1510 |
if (!f) |
1531 |
bp = buf, blen = sizeof(buf); |
1511 |
f = fopen("/proc/fs/nfs/filehandle", "r+"); |
1532 |
qword_add(&bp, &blen, exp->m_client->m_hostname); |
1512 |
if (!f) |
1533 |
qword_add(&bp, &blen, p); |
|
|
1534 |
qword_addint(&bp, &blen, len); |
1535 |
qword_addeol(&bp, &blen); |
1536 |
if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) { |
1537 |
close(f); |
1513 |
return NULL; |
1538 |
return NULL; |
|
|
1539 |
} |
1540 |
bp = buf; |
1541 |
blen = read(f, buf, sizeof(buf)); |
1542 |
close(f); |
1514 |
|
1543 |
|
1515 |
qword_print(f, exp->m_client->m_hostname); |
1544 |
if (blen <= 0 || buf[blen-1] != '\n') |
1516 |
qword_print(f, p); |
|
|
1517 |
qword_printint(f, len); |
1518 |
failed = qword_eol(f); |
1519 |
|
1520 |
if (!failed) |
1521 |
failed = (fgets(buf, sizeof(buf), f) == NULL); |
1522 |
fclose(f); |
1523 |
if (failed) |
1524 |
return NULL; |
1545 |
return NULL; |
|
|
1546 |
buf[blen-1] = 0; |
1547 |
|
1525 |
memset(fh.fh_handle, 0, sizeof(fh.fh_handle)); |
1548 |
memset(fh.fh_handle, 0, sizeof(fh.fh_handle)); |
1526 |
fh.fh_size = qword_get(&bp, (char *)fh.fh_handle, NFS3_FHSIZE); |
1549 |
fh.fh_size = qword_get(&bp, (char *)fh.fh_handle, NFS3_FHSIZE); |
1527 |
return &fh; |
1550 |
return &fh; |
1528 |
- |
|
|