Print this page
7569 statd support to run on a fixed port
Portions contributed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
7577 mountd support to run on a fixed port
Portions contributed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libshare/nfs/libshare_nfs.c
+++ new/usr/src/lib/libshare/nfs/libshare_nfs.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2016 Nexenta Systems, Inc.
25 + * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
25 26 */
26 27
27 28 /*
28 29 * NFS specific functions
29 30 */
30 31 #include <stdio.h>
31 32 #include <string.h>
32 33 #include <ctype.h>
33 34 #include <stdlib.h>
34 35 #include <unistd.h>
35 36 #include <zone.h>
36 37 #include <errno.h>
37 38 #include <locale.h>
38 39 #include <signal.h>
39 40 #include <strings.h>
40 41 #include "libshare.h"
41 42 #include "libshare_impl.h"
42 43 #include <nfs/export.h>
43 44 #include <pwd.h>
44 45 #include <grp.h>
45 46 #include <limits.h>
46 47 #include <libscf.h>
47 48 #include <syslog.h>
48 49 #include <rpcsvc/daemon_utils.h>
49 50 #include "nfslog_config.h"
50 51 #include "nfslogtab.h"
51 52 #include "libshare_nfs.h"
52 53 #include <nfs/nfs.h>
53 54 #include <nfs/nfssys.h>
54 55 #include <netconfig.h>
55 56 #include "smfcfg.h"
56 57
57 58 /* should really be in some global place */
58 59 #define DEF_WIN 30000
59 60 #define OPT_CHUNK 1024
60 61
61 62 int debug = 0;
62 63
63 64 #define NFS_SERVER_SVC "svc:/network/nfs/server:default"
64 65 #define NFS_CLIENT_SVC (char *)"svc:/network/nfs/client:default"
65 66
66 67 /* internal functions */
67 68 static int nfs_init();
68 69 static void nfs_fini();
69 70 static int nfs_enable_share(sa_share_t);
70 71 static int nfs_disable_share(sa_share_t, char *);
71 72 static int nfs_validate_property(sa_handle_t, sa_property_t, sa_optionset_t);
72 73 static int nfs_validate_security_mode(char *);
73 74 static int nfs_is_security_opt(char *);
74 75 static int nfs_parse_legacy_options(sa_group_t, char *);
75 76 static char *nfs_format_options(sa_group_t, int);
76 77 static int nfs_set_proto_prop(sa_property_t);
77 78 static sa_protocol_properties_t nfs_get_proto_set();
78 79 static char *nfs_get_status();
79 80 static char *nfs_space_alias(char *);
80 81 static uint64_t nfs_features();
81 82
82 83 /*
83 84 * ops vector that provides the protocol specific info and operations
84 85 * for share management.
85 86 */
86 87
87 88 struct sa_plugin_ops sa_plugin_ops = {
88 89 SA_PLUGIN_VERSION,
89 90 "nfs",
90 91 nfs_init,
91 92 nfs_fini,
92 93 nfs_enable_share,
93 94 nfs_disable_share,
94 95 nfs_validate_property,
95 96 nfs_validate_security_mode,
96 97 nfs_is_security_opt,
97 98 nfs_parse_legacy_options,
98 99 nfs_format_options,
99 100 nfs_set_proto_prop,
100 101 nfs_get_proto_set,
101 102 nfs_get_status,
102 103 nfs_space_alias,
103 104 NULL, /* update_legacy */
104 105 NULL, /* delete_legacy */
105 106 NULL, /* change_notify */
106 107 NULL, /* enable_resource */
107 108 NULL, /* disable_resource */
108 109 nfs_features,
109 110 NULL, /* transient shares */
110 111 NULL, /* notify resource */
111 112 NULL, /* rename_resource */
112 113 NULL, /* run_command */
113 114 NULL, /* command_help */
114 115 NULL /* delete_proto_section */
115 116 };
116 117
117 118 /*
118 119 * list of support services needed
119 120 * defines should come from head/rpcsvc/daemon_utils.h
120 121 */
121 122
122 123 static char *service_list_default[] =
123 124 { STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, REPARSED, NULL };
124 125 static char *service_list_logging[] =
125 126 { STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, NFSLOGD, REPARSED,
126 127 NULL };
127 128
128 129 /*
129 130 * option definitions. Make sure to keep the #define for the option
130 131 * index just before the entry it is the index for. Changing the order
131 132 * can cause breakage. E.g OPT_RW is index 1 and must precede the
132 133 * line that includes the SHOPT_RW and OPT_RW entries.
133 134 */
134 135
135 136 struct option_defs optdefs[] = {
136 137 #define OPT_RO 0
137 138 {SHOPT_RO, OPT_RO, OPT_TYPE_ACCLIST},
138 139 #define OPT_RW 1
139 140 {SHOPT_RW, OPT_RW, OPT_TYPE_ACCLIST},
140 141 #define OPT_ROOT 2
141 142 {SHOPT_ROOT, OPT_ROOT, OPT_TYPE_ACCLIST},
142 143 #define OPT_SECURE 3
143 144 {SHOPT_SECURE, OPT_SECURE, OPT_TYPE_DEPRECATED},
144 145 #define OPT_ANON 4
145 146 {SHOPT_ANON, OPT_ANON, OPT_TYPE_USER},
146 147 #define OPT_WINDOW 5
147 148 {SHOPT_WINDOW, OPT_WINDOW, OPT_TYPE_NUMBER},
148 149 #define OPT_NOSUID 6
149 150 {SHOPT_NOSUID, OPT_NOSUID, OPT_TYPE_BOOLEAN},
150 151 #define OPT_ACLOK 7
151 152 {SHOPT_ACLOK, OPT_ACLOK, OPT_TYPE_BOOLEAN},
152 153 #define OPT_NOSUB 8
153 154 {SHOPT_NOSUB, OPT_NOSUB, OPT_TYPE_BOOLEAN},
154 155 #define OPT_SEC 9
155 156 {SHOPT_SEC, OPT_SEC, OPT_TYPE_SECURITY},
156 157 #define OPT_PUBLIC 10
157 158 {SHOPT_PUBLIC, OPT_PUBLIC, OPT_TYPE_BOOLEAN, OPT_SHARE_ONLY},
158 159 #define OPT_INDEX 11
159 160 {SHOPT_INDEX, OPT_INDEX, OPT_TYPE_FILE},
160 161 #define OPT_LOG 12
161 162 {SHOPT_LOG, OPT_LOG, OPT_TYPE_LOGTAG},
162 163 #define OPT_CKSUM 13
163 164 {SHOPT_CKSUM, OPT_CKSUM, OPT_TYPE_STRINGSET},
164 165 #define OPT_NONE 14
165 166 {SHOPT_NONE, OPT_NONE, OPT_TYPE_ACCLIST},
166 167 #define OPT_ROOT_MAPPING 15
167 168 {SHOPT_ROOT_MAPPING, OPT_ROOT_MAPPING, OPT_TYPE_USER},
168 169 #define OPT_CHARSET_MAP 16
169 170 {"", OPT_CHARSET_MAP, OPT_TYPE_ACCLIST},
170 171 #define OPT_NOACLFAB 17
171 172 {SHOPT_NOACLFAB, OPT_NOACLFAB, OPT_TYPE_BOOLEAN},
172 173 #define OPT_UIDMAP 18
173 174 {SHOPT_UIDMAP, OPT_UIDMAP, OPT_TYPE_MAPPING},
174 175 #define OPT_GIDMAP 19
175 176 {SHOPT_GIDMAP, OPT_GIDMAP, OPT_TYPE_MAPPING},
176 177 #ifdef VOLATILE_FH_TEST /* XXX added for testing volatile fh's only */
177 178 #define OPT_VOLFH 20
178 179 {SHOPT_VOLFH, OPT_VOLFH},
179 180 #endif /* VOLATILE_FH_TEST */
180 181 NULL
181 182 };
182 183
183 184 /*
184 185 * Codesets that may need to be converted to UTF-8 for file paths.
185 186 * Add new names here to add new property support. If we ever get a
186 187 * way to query the kernel for character sets, this should become
187 188 * dynamically loaded. Make sure changes here are reflected in
188 189 * cmd/fs.d/nfs/mountd/nfscmd.c
189 190 */
190 191
191 192 static char *legal_conv[] = {
192 193 "euc-cn",
193 194 "euc-jp",
194 195 "euc-jpms",
195 196 "euc-kr",
196 197 "euc-tw",
197 198 "iso8859-1",
198 199 "iso8859-2",
199 200 "iso8859-5",
200 201 "iso8859-6",
201 202 "iso8859-7",
202 203 "iso8859-8",
203 204 "iso8859-9",
204 205 "iso8859-13",
205 206 "iso8859-15",
206 207 "koi8-r",
207 208 NULL
208 209 };
209 210
210 211 /*
211 212 * list of properties that are related to security flavors.
212 213 */
213 214 static char *seclist[] = {
214 215 SHOPT_RO,
215 216 SHOPT_RW,
216 217 SHOPT_ROOT,
217 218 SHOPT_WINDOW,
218 219 SHOPT_NONE,
219 220 SHOPT_ROOT_MAPPING,
220 221 SHOPT_UIDMAP,
221 222 SHOPT_GIDMAP,
222 223 NULL
223 224 };
224 225
225 226 /* structure for list of securities */
226 227 struct securities {
227 228 sa_security_t security;
228 229 struct securities *next;
229 230 };
230 231
231 232 /*
232 233 * findcharset(charset)
233 234 *
234 235 * Returns B_TRUE if the charset is a legal conversion otherwise
235 236 * B_FALSE. This will need to be rewritten to be more efficient when
236 237 * we have a dynamic list of legal conversions.
237 238 */
238 239
239 240 static boolean_t
240 241 findcharset(char *charset)
241 242 {
242 243 int i;
243 244
244 245 for (i = 0; legal_conv[i] != NULL; i++)
245 246 if (strcmp(charset, legal_conv[i]) == 0)
246 247 return (B_TRUE);
247 248 return (B_FALSE);
248 249 }
249 250
250 251 /*
251 252 * findopt(name)
252 253 *
253 254 * Lookup option "name" in the option table and return the table
254 255 * index.
255 256 */
256 257
257 258 static int
258 259 findopt(char *name)
259 260 {
260 261 int i;
261 262 if (name != NULL) {
262 263 for (i = 0; optdefs[i].tag != NULL; i++) {
263 264 if (strcmp(optdefs[i].tag, name) == 0)
264 265 return (optdefs[i].index);
265 266 }
266 267 if (findcharset(name))
267 268 return (OPT_CHARSET_MAP);
268 269 }
269 270 return (-1);
270 271 }
271 272
272 273 /*
273 274 * gettype(name)
274 275 *
275 276 * Return the type of option "name".
276 277 */
277 278
278 279 static int
279 280 gettype(char *name)
280 281 {
281 282 int optdef;
282 283
283 284 optdef = findopt(name);
284 285 if (optdef != -1)
285 286 return (optdefs[optdef].type);
286 287 return (OPT_TYPE_ANY);
287 288 }
288 289
289 290 /*
290 291 * nfs_validate_security_mode(mode)
291 292 *
292 293 * is the specified mode string a valid one for use with NFS?
293 294 */
294 295
295 296 static int
296 297 nfs_validate_security_mode(char *mode)
297 298 {
298 299 seconfig_t secinfo;
299 300 int err;
300 301
301 302 (void) memset(&secinfo, '\0', sizeof (secinfo));
302 303 err = nfs_getseconfig_byname(mode, &secinfo);
303 304 if (err == SC_NOERROR)
304 305 return (1);
305 306 return (0);
306 307 }
307 308
308 309 /*
309 310 * nfs_is_security_opt(tok)
310 311 *
311 312 * check to see if tok represents an option that is only valid in some
312 313 * security flavor.
313 314 */
314 315
315 316 static int
316 317 nfs_is_security_opt(char *tok)
317 318 {
318 319 int i;
319 320
320 321 for (i = 0; seclist[i] != NULL; i++) {
321 322 if (strcmp(tok, seclist[i]) == 0)
322 323 return (1);
323 324 }
324 325 return (0);
325 326 }
326 327
327 328 /*
328 329 * find_security(seclist, sec)
329 330 *
330 331 * Walk the current list of security flavors and return true if it is
331 332 * present, else return false.
332 333 */
333 334
334 335 static int
335 336 find_security(struct securities *seclist, sa_security_t sec)
336 337 {
337 338 while (seclist != NULL) {
338 339 if (seclist->security == sec)
339 340 return (1);
340 341 seclist = seclist->next;
341 342 }
342 343 return (0);
343 344 }
344 345
345 346 /*
346 347 * make_security_list(group, securitymodes, proto)
347 348 * go through the list of securitymodes and add them to the
348 349 * group's list of security optionsets. We also keep a list of
349 350 * those optionsets so we don't have to find them later. All of
350 351 * these will get copies of the same properties.
351 352 */
352 353
353 354 static struct securities *
354 355 make_security_list(sa_group_t group, char *securitymodes, char *proto)
355 356 {
356 357 char *tok, *next = NULL;
357 358 struct securities *curp, *headp = NULL, *prev;
358 359 sa_security_t check;
359 360 int freetok = 0;
360 361
361 362 for (tok = securitymodes; tok != NULL; tok = next) {
362 363 next = strchr(tok, ':');
363 364 if (next != NULL)
364 365 *next++ = '\0';
365 366 if (strcmp(tok, "default") == 0) {
366 367 /* resolve default into the real type */
367 368 tok = nfs_space_alias(tok);
368 369 freetok = 1;
369 370 }
370 371 check = sa_get_security(group, tok, proto);
371 372
372 373 /* add to the security list if it isn't there already */
373 374 if (check == NULL || !find_security(headp, check)) {
374 375 curp = (struct securities *)calloc(1,
375 376 sizeof (struct securities));
376 377 if (curp != NULL) {
377 378 if (check == NULL) {
378 379 curp->security = sa_create_security(
379 380 group, tok, proto);
380 381 } else {
381 382 curp->security = check;
382 383 }
383 384 /*
384 385 * note that the first time through the loop,
385 386 * headp will be NULL and prev will be
386 387 * undefined. Since headp is NULL, we set
387 388 * both it and prev to the curp (first
388 389 * structure to be allocated).
389 390 *
390 391 * later passes through the loop will have
391 392 * headp not being NULL and prev will be used
392 393 * to allocate at the end of the list.
393 394 */
394 395 if (headp == NULL) {
395 396 headp = curp;
396 397 prev = curp;
397 398 } else {
398 399 prev->next = curp;
399 400 prev = curp;
400 401 }
401 402 }
402 403 }
403 404
404 405 if (freetok) {
405 406 freetok = 0;
406 407 sa_free_attr_string(tok);
407 408 }
408 409 }
409 410 return (headp);
410 411 }
411 412
412 413 static void
413 414 free_security_list(struct securities *sec)
414 415 {
415 416 struct securities *next;
416 417 if (sec != NULL) {
417 418 for (next = sec->next; sec != NULL; sec = next) {
418 419 next = sec->next;
419 420 free(sec);
420 421 }
421 422 }
422 423 }
423 424
424 425 /*
425 426 * nfs_alistcat(str1, str2, sep)
426 427 *
427 428 * concatenate str1 and str2 into a new string using sep as a separate
428 429 * character. If memory allocation fails, return NULL;
429 430 */
430 431
431 432 static char *
432 433 nfs_alistcat(char *str1, char *str2, char sep)
433 434 {
434 435 char *newstr;
435 436 size_t len;
436 437
437 438 len = strlen(str1) + strlen(str2) + 2;
438 439 newstr = (char *)malloc(len);
439 440 if (newstr != NULL)
440 441 (void) snprintf(newstr, len, "%s%c%s", str1, sep, str2);
441 442 return (newstr);
442 443 }
443 444
444 445 /*
445 446 * add_security_prop(sec, name, value, persist, iszfs)
446 447 *
447 448 * Add the property to the securities structure. This accumulates
448 449 * properties for as part of parsing legacy options.
449 450 */
450 451
451 452 static int
452 453 add_security_prop(struct securities *sec, char *name, char *value,
453 454 int persist, int iszfs)
454 455 {
455 456 sa_property_t prop;
456 457 int ret = SA_OK;
457 458
458 459 for (; sec != NULL; sec = sec->next) {
459 460 if (value == NULL) {
460 461 if (strcmp(name, SHOPT_RW) == 0 ||
461 462 strcmp(name, SHOPT_RO) == 0)
462 463 value = "*";
463 464 else
464 465 value = "true";
465 466 }
466 467
467 468 /*
468 469 * Get the existing property, if it exists, so we can
469 470 * determine what to do with it. The ro/rw/root
470 471 * properties can be merged if multiple instances of
471 472 * these properies are given. For example, if "rw"
472 473 * exists with a value "host1" and a later token of
473 474 * rw="host2" is seen, the values are merged into a
474 475 * single rw="host1:host2".
475 476 */
476 477 prop = sa_get_property(sec->security, name);
477 478
478 479 if (prop != NULL) {
479 480 char *oldvalue;
480 481 char *newvalue;
481 482
482 483 /*
483 484 * The security options of ro/rw/root/uidmap/gidmap
484 485 * might appear multiple times. If they do, the values
485 486 * need to be merged. If it was previously empty, the
486 487 * new value alone is added.
487 488 */
488 489 oldvalue = sa_get_property_attr(prop, "value");
489 490 if (oldvalue != NULL) {
490 491 char sep = ':';
491 492
492 493 if (strcmp(name, SHOPT_UIDMAP) == 0 ||
493 494 strcmp(name, SHOPT_GIDMAP) == 0)
494 495 sep = '~';
495 496
496 497 /*
497 498 * The general case is to concatenate the new
498 499 * value onto the old value for multiple
499 500 * rw(ro/root/uidmap/gidmap) properties. For
500 501 * rw/ro/root a special case exists when either
501 502 * the old or new is the "all" case. In the
502 503 * special case, if both are "all", then it is
503 504 * "all", else if one is an access-list, that
504 505 * replaces the "all".
505 506 */
506 507 if (strcmp(oldvalue, "*") == 0) {
507 508 /* Replace old value with new value. */
508 509 newvalue = strdup(value);
509 510 } else if (strcmp(value, "*") == 0 ||
510 511 strcmp(oldvalue, value) == 0) {
511 512 /*
512 513 * Keep old value and ignore
513 514 * the new value.
514 515 */
515 516 newvalue = NULL;
516 517 } else {
517 518 /*
518 519 * Make a new list of old plus new
519 520 * access-list.
520 521 */
521 522 newvalue = nfs_alistcat(oldvalue,
522 523 value, sep);
523 524 }
524 525
525 526 if (newvalue != NULL) {
526 527 (void) sa_remove_property(prop);
527 528 prop = sa_create_property(name,
528 529 newvalue);
529 530 ret = sa_add_property(sec->security,
530 531 prop);
531 532 free(newvalue);
532 533 }
533 534
534 535 sa_free_attr_string(oldvalue);
535 536 }
536 537 } else {
537 538 prop = sa_create_property(name, value);
538 539 ret = sa_add_property(sec->security, prop);
539 540 }
540 541 if (ret == SA_OK && !iszfs) {
541 542 ret = sa_commit_properties(sec->security, !persist);
542 543 }
543 544 }
544 545 return (ret);
545 546 }
546 547
547 548 /*
548 549 * check to see if group/share is persistent.
549 550 */
550 551 static int
551 552 is_persistent(sa_group_t group)
552 553 {
553 554 char *type;
554 555 int persist = 1;
555 556
556 557 type = sa_get_group_attr(group, "type");
557 558 if (type != NULL && strcmp(type, "persist") != 0)
558 559 persist = 0;
559 560 if (type != NULL)
560 561 sa_free_attr_string(type);
561 562 return (persist);
562 563 }
563 564
564 565 /*
565 566 * invalid_security(options)
566 567 *
567 568 * search option string for any invalid sec= type.
568 569 * return true (1) if any are not valid else false (0)
569 570 */
570 571 static int
571 572 invalid_security(char *options)
572 573 {
573 574 char *copy, *base, *token, *value;
574 575 int ret = 0;
575 576
576 577 copy = strdup(options);
577 578 token = base = copy;
578 579 while (token != NULL && ret == 0) {
579 580 token = strtok(base, ",");
580 581 base = NULL;
581 582 if (token != NULL) {
582 583 value = strchr(token, '=');
583 584 if (value != NULL)
584 585 *value++ = '\0';
585 586 if (strcmp(token, SHOPT_SEC) == 0) {
586 587 /* HAVE security flavors so check them */
587 588 char *tok, *next;
588 589 for (next = NULL, tok = value; tok != NULL;
589 590 tok = next) {
590 591 next = strchr(tok, ':');
591 592 if (next != NULL)
592 593 *next++ = '\0';
593 594 ret = !nfs_validate_security_mode(tok);
594 595 if (ret)
595 596 break;
596 597 }
597 598 }
598 599 }
599 600 }
600 601 if (copy != NULL)
601 602 free(copy);
602 603 return (ret);
603 604 }
604 605
605 606 /*
606 607 * nfs_parse_legacy_options(group, options)
607 608 *
608 609 * Parse the old style options into internal format and store on the
609 610 * specified group. Group could be a share for full legacy support.
610 611 */
611 612
612 613 static int
613 614 nfs_parse_legacy_options(sa_group_t group, char *options)
614 615 {
615 616 char *dup;
616 617 char *base;
617 618 char *token;
618 619 sa_optionset_t optionset;
619 620 struct securities *security_list = NULL;
620 621 sa_property_t prop;
621 622 int ret = SA_OK;
622 623 int iszfs = 0;
623 624 sa_group_t parent;
624 625 int persist = 0;
625 626 char *lasts;
626 627
627 628 /* do we have an existing optionset? */
628 629 optionset = sa_get_optionset(group, "nfs");
629 630 if (optionset == NULL) {
630 631 /* didn't find existing optionset so create one */
631 632 optionset = sa_create_optionset(group, "nfs");
632 633 } else {
633 634 /*
634 635 * Have an existing optionset . Ideally, we would need
635 636 * to compare options in order to detect errors. For
636 637 * now, we assume that the first optionset is the
637 638 * correct one and the others will be the same. An
638 639 * empty optionset is the same as no optionset so we
639 640 * don't want to exit in that case. Getting an empty
640 641 * optionset can occur with ZFS property checking.
641 642 */
642 643 if (sa_get_property(optionset, NULL) != NULL)
643 644 return (ret);
644 645 }
645 646
646 647 if (strcmp(options, SHOPT_RW) == 0) {
647 648 /*
648 649 * there is a special case of only the option "rw"
649 650 * being the default option. We don't have to do
650 651 * anything.
651 652 */
652 653 return (ret);
653 654 }
654 655
655 656 /*
656 657 * check if security types are present and validate them. If
657 658 * any are not legal, fail.
658 659 */
659 660
660 661 if (invalid_security(options)) {
661 662 return (SA_INVALID_SECURITY);
662 663 }
663 664
664 665 /*
665 666 * in order to not attempt to change ZFS properties unless
666 667 * absolutely necessary, we never do it in the legacy parsing.
667 668 */
668 669 if (sa_is_share(group)) {
669 670 char *zfs;
670 671 parent = sa_get_parent_group(group);
671 672 if (parent != NULL) {
672 673 zfs = sa_get_group_attr(parent, "zfs");
673 674 if (zfs != NULL) {
674 675 sa_free_attr_string(zfs);
675 676 iszfs++;
676 677 }
677 678 }
678 679 } else {
679 680 iszfs = sa_group_is_zfs(group);
680 681 }
681 682
682 683 /* We need a copy of options for the next part. */
683 684 dup = strdup(options);
684 685 if (dup == NULL)
685 686 return (SA_NO_MEMORY);
686 687
687 688 /*
688 689 * we need to step through each option in the string and then
689 690 * add either the option or the security option as needed. If
690 691 * this is not a persistent share, don't commit to the
691 692 * repository. If there is an error, we also want to abort the
692 693 * processing and report it.
693 694 */
694 695 persist = is_persistent(group);
695 696 base = dup;
696 697 token = dup;
697 698 lasts = NULL;
698 699 while (token != NULL && ret == SA_OK) {
699 700 token = strtok_r(base, ",", &lasts);
700 701 base = NULL;
701 702 if (token != NULL) {
702 703 char *value;
703 704 /*
704 705 * if the option has a value, it will have an '=' to
705 706 * separate the name from the value. The following
706 707 * code will result in value != NULL and token
707 708 * pointing to just the name if there is a value.
708 709 */
709 710 value = strchr(token, '=');
710 711 if (value != NULL) {
711 712 *value++ = '\0';
712 713 }
713 714 if (strcmp(token, SHOPT_SEC) == 0 ||
714 715 strcmp(token, SHOPT_SECURE) == 0) {
715 716 /*
716 717 * Once in security parsing, we only
717 718 * do security. We do need to move
718 719 * between the security node and the
719 720 * toplevel. The security tag goes on
720 721 * the root while the following ones
721 722 * go on the security.
722 723 */
723 724 if (security_list != NULL) {
724 725 /*
725 726 * have an old list so close it and
726 727 * start the new
727 728 */
728 729 free_security_list(security_list);
729 730 }
730 731 if (strcmp(token, SHOPT_SECURE) == 0) {
731 732 value = "dh";
732 733 } else {
733 734 if (value == NULL) {
734 735 ret = SA_SYNTAX_ERR;
735 736 break;
736 737 }
737 738 }
738 739 security_list = make_security_list(group,
739 740 value, "nfs");
740 741 } else {
741 742 /*
742 743 * Note that the "old" syntax allowed a
743 744 * default security model. This must be
744 745 * accounted for and internally converted to
745 746 * "standard" security structure.
746 747 */
747 748 if (nfs_is_security_opt(token)) {
748 749 if (security_list == NULL) {
749 750 /*
750 751 * need to have a
751 752 * security
752 753 * option. This will
753 754 * be "closed" when a
754 755 * defined "sec="
755 756 * option is
756 757 * seen. This is
757 758 * technically an
758 759 * error but will be
759 760 * allowed with
760 761 * warning.
761 762 */
762 763 security_list =
763 764 make_security_list(group,
764 765 "default",
765 766 "nfs");
766 767 }
767 768 if (security_list != NULL) {
768 769 ret = add_security_prop(
769 770 security_list, token,
770 771 value, persist, iszfs);
771 772 } else {
772 773 ret = SA_NO_MEMORY;
773 774 }
774 775 } else {
775 776 /* regular options */
776 777 if (value == NULL) {
777 778 if (strcmp(token, SHOPT_RW) ==
778 779 0 || strcmp(token,
779 780 SHOPT_RO) == 0) {
780 781 value = "*";
781 782 } else {
782 783 value = "global";
783 784 if (strcmp(token,
784 785 SHOPT_LOG) != 0) {
785 786 value = "true";
786 787 }
787 788 }
788 789 }
789 790 /*
790 791 * In all cases, create the
791 792 * property specified. If the
792 793 * value was NULL, the default
793 794 * value will have been
794 795 * substituted.
795 796 */
796 797 prop = sa_create_property(token, value);
797 798 ret = sa_add_property(optionset, prop);
798 799 if (ret != SA_OK)
799 800 break;
800 801
801 802 if (!iszfs) {
802 803 ret = sa_commit_properties(
803 804 optionset, !persist);
804 805 }
805 806 }
806 807 }
807 808 }
808 809 }
809 810 if (security_list != NULL)
810 811 free_security_list(security_list);
811 812
812 813 free(dup);
813 814 return (ret);
814 815 }
815 816
816 817 /*
817 818 * is_a_number(number)
818 819 *
819 820 * is the string a number in one of the forms we want to use?
820 821 */
821 822
822 823 static int
823 824 is_a_number(char *number)
824 825 {
825 826 int ret = 1;
826 827 int hex = 0;
827 828
828 829 if (strncmp(number, "0x", 2) == 0) {
829 830 number += 2;
830 831 hex = 1;
831 832 } else if (*number == '-') {
832 833 number++; /* skip the minus */
833 834 }
834 835 while (ret == 1 && *number != '\0') {
835 836 if (hex) {
836 837 ret = isxdigit(*number++);
837 838 } else {
838 839 ret = isdigit(*number++);
839 840 }
840 841 }
841 842 return (ret);
842 843 }
843 844
844 845 /*
845 846 * Look for the specified tag in the configuration file. If it is found,
846 847 * enable logging and set the logging configuration information for exp.
847 848 */
848 849 static void
849 850 configlog(struct exportdata *exp, char *tag)
850 851 {
851 852 nfsl_config_t *configlist = NULL, *configp;
852 853 int error = 0;
853 854 char globaltag[] = DEFAULTTAG;
854 855
855 856 /*
856 857 * Sends config errors to stderr
857 858 */
858 859 nfsl_errs_to_syslog = B_FALSE;
859 860
860 861 /*
861 862 * get the list of configuration settings
862 863 */
863 864 error = nfsl_getconfig_list(&configlist);
864 865 if (error) {
865 866 (void) fprintf(stderr,
866 867 dgettext(TEXT_DOMAIN, "Cannot get log configuration: %s\n"),
867 868 strerror(error));
868 869 }
869 870
870 871 if (tag == NULL)
871 872 tag = globaltag;
872 873 if ((configp = nfsl_findconfig(configlist, tag, &error)) == NULL) {
873 874 nfsl_freeconfig_list(&configlist);
874 875 (void) fprintf(stderr,
875 876 dgettext(TEXT_DOMAIN, "No tags matching \"%s\"\n"), tag);
876 877 /* bad configuration */
877 878 error = ENOENT;
878 879 goto err;
879 880 }
880 881
881 882 if ((exp->ex_tag = strdup(tag)) == NULL) {
882 883 error = ENOMEM;
883 884 goto out;
884 885 }
885 886 if ((exp->ex_log_buffer = strdup(configp->nc_bufferpath)) == NULL) {
886 887 error = ENOMEM;
887 888 goto out;
888 889 }
889 890 exp->ex_flags |= EX_LOG;
890 891 if (configp->nc_rpclogpath != NULL)
891 892 exp->ex_flags |= EX_LOG_ALLOPS;
892 893 out:
893 894 if (configlist != NULL)
894 895 nfsl_freeconfig_list(&configlist);
895 896
896 897 err:
897 898 if (error != 0) {
898 899 free(exp->ex_tag);
899 900 free(exp->ex_log_buffer);
900 901 (void) fprintf(stderr,
901 902 dgettext(TEXT_DOMAIN, "Cannot set log configuration: %s\n"),
902 903 strerror(error));
903 904 }
904 905 }
905 906
906 907 /*
907 908 * fill_export_from_optionset(export, optionset)
908 909 *
909 910 * In order to share, we need to set all the possible general options
910 911 * into the export structure. Share info will be filled in by the
911 912 * caller. Various property values get turned into structure specific
912 913 * values.
913 914 */
914 915
915 916 static int
916 917 fill_export_from_optionset(struct exportdata *export, sa_optionset_t optionset)
917 918 {
918 919 sa_property_t option;
919 920 int ret = SA_OK;
920 921
921 922 for (option = sa_get_property(optionset, NULL);
922 923 option != NULL; option = sa_get_next_property(option)) {
923 924 char *name;
924 925 char *value;
925 926 uint32_t val;
926 927
927 928 /*
928 929 * since options may be set/reset multiple times, always do an
929 930 * explicit set or clear of the option. This allows defaults
930 931 * to be set and then the protocol specific to override.
931 932 */
932 933
933 934 name = sa_get_property_attr(option, "type");
934 935 value = sa_get_property_attr(option, "value");
935 936 switch (findopt(name)) {
936 937 case OPT_ANON:
937 938 if (value != NULL && is_a_number(value)) {
938 939 val = strtoul(value, NULL, 0);
939 940 } else {
940 941 struct passwd *pw;
941 942 pw = getpwnam(value != NULL ? value : "nobody");
942 943 if (pw != NULL) {
943 944 val = pw->pw_uid;
944 945 } else {
945 946 val = UID_NOBODY;
946 947 }
947 948 endpwent();
948 949 }
949 950 export->ex_anon = val;
950 951 break;
951 952 case OPT_NOSUID:
952 953 if (value != NULL && (strcasecmp(value, "true") == 0 ||
953 954 strcmp(value, "1") == 0))
954 955 export->ex_flags |= EX_NOSUID;
955 956 else
956 957 export->ex_flags &= ~EX_NOSUID;
957 958 break;
958 959 case OPT_ACLOK:
959 960 if (value != NULL && (strcasecmp(value, "true") == 0 ||
960 961 strcmp(value, "1") == 0))
961 962 export->ex_flags |= EX_ACLOK;
962 963 else
963 964 export->ex_flags &= ~EX_ACLOK;
964 965 break;
965 966 case OPT_NOSUB:
966 967 if (value != NULL && (strcasecmp(value, "true") == 0 ||
967 968 strcmp(value, "1") == 0))
968 969 export->ex_flags |= EX_NOSUB;
969 970 else
970 971 export->ex_flags &= ~EX_NOSUB;
971 972 break;
972 973 case OPT_PUBLIC:
973 974 if (value != NULL && (strcasecmp(value, "true") == 0 ||
974 975 strcmp(value, "1") == 0))
975 976 export->ex_flags |= EX_PUBLIC;
976 977 else
977 978 export->ex_flags &= ~EX_PUBLIC;
978 979 break;
979 980 case OPT_INDEX:
980 981 if (value != NULL && (strcmp(value, "..") == 0 ||
981 982 strchr(value, '/') != NULL)) {
982 983 /* this is an error */
983 984 (void) printf(dgettext(TEXT_DOMAIN,
984 985 "NFS: index=\"%s\" not valid;"
985 986 "must be a filename.\n"),
986 987 value);
987 988 break;
988 989 }
989 990 if (value != NULL && *value != '\0' &&
990 991 strcmp(value, ".") != 0) {
991 992 /* valid index file string */
992 993 if (export->ex_index != NULL) {
993 994 /* left over from "default" */
994 995 free(export->ex_index);
995 996 }
996 997 /* remember to free */
997 998 export->ex_index = strdup(value);
998 999 if (export->ex_index == NULL) {
999 1000 (void) printf(dgettext(TEXT_DOMAIN,
1000 1001 "NFS: out of memory setting "
1001 1002 "index property\n"));
1002 1003 break;
1003 1004 }
1004 1005 export->ex_flags |= EX_INDEX;
1005 1006 }
1006 1007 break;
1007 1008 case OPT_LOG:
1008 1009 if (value == NULL)
1009 1010 value = strdup("global");
1010 1011 if (value != NULL)
1011 1012 configlog(export,
1012 1013 strlen(value) ? value : "global");
1013 1014 break;
1014 1015 case OPT_CHARSET_MAP:
1015 1016 /*
1016 1017 * Set EX_CHARMAP when there is at least one
1017 1018 * charmap conversion property. This will get
1018 1019 * checked by the nfs server when it needs to.
1019 1020 */
1020 1021 export->ex_flags |= EX_CHARMAP;
1021 1022 break;
1022 1023 case OPT_NOACLFAB:
1023 1024 if (value != NULL && (strcasecmp(value, "true") == 0 ||
1024 1025 strcmp(value, "1") == 0))
1025 1026 export->ex_flags |= EX_NOACLFAB;
1026 1027 else
1027 1028 export->ex_flags &= ~EX_NOACLFAB;
1028 1029 break;
1029 1030 default:
1030 1031 /* have a syntactic error */
1031 1032 (void) printf(dgettext(TEXT_DOMAIN,
1032 1033 "NFS: unrecognized option %s=%s\n"),
1033 1034 name != NULL ? name : "",
1034 1035 value != NULL ? value : "");
1035 1036 break;
1036 1037 }
1037 1038 if (name != NULL)
1038 1039 sa_free_attr_string(name);
1039 1040 if (value != NULL)
1040 1041 sa_free_attr_string(value);
1041 1042 }
1042 1043 return (ret);
1043 1044 }
1044 1045
1045 1046 /*
1046 1047 * cleanup_export(export)
1047 1048 *
1048 1049 * Cleanup the allocated areas so we don't leak memory
1049 1050 */
1050 1051
1051 1052 static void
1052 1053 cleanup_export(struct exportdata *export)
1053 1054 {
1054 1055 int i;
1055 1056
1056 1057 free(export->ex_index);
1057 1058
1058 1059 for (i = 0; i < export->ex_seccnt; i++) {
1059 1060 struct secinfo *s = &export->ex_secinfo[i];
1060 1061
1061 1062 while (s->s_rootcnt > 0)
1062 1063 free(s->s_rootnames[--s->s_rootcnt]);
1063 1064
1064 1065 free(s->s_rootnames);
1065 1066 }
1066 1067 free(export->ex_secinfo);
1067 1068 }
1068 1069
1069 1070 /*
1070 1071 * Given a seconfig entry and a colon-separated
1071 1072 * list of names, allocate an array big enough
1072 1073 * to hold the root list, then convert each name to
1073 1074 * a principal name according to the security
1074 1075 * info and assign it to an array element.
1075 1076 * Return the array and its size.
1076 1077 */
1077 1078 static caddr_t *
1078 1079 get_rootnames(seconfig_t *sec, char *list, int *count)
1079 1080 {
1080 1081 caddr_t *a;
1081 1082 int c, i;
1082 1083 char *host, *p;
1083 1084
1084 1085 /*
1085 1086 * Count the number of strings in the list.
1086 1087 * This is the number of colon separators + 1.
1087 1088 */
1088 1089 c = 1;
1089 1090 for (p = list; *p; p++)
1090 1091 if (*p == ':')
1091 1092 c++;
1092 1093 *count = c;
1093 1094
1094 1095 a = (caddr_t *)malloc(c * sizeof (char *));
1095 1096 if (a == NULL) {
1096 1097 (void) printf(dgettext(TEXT_DOMAIN,
1097 1098 "get_rootnames: no memory\n"));
1098 1099 *count = 0;
1099 1100 } else {
1100 1101 for (i = 0; i < c; i++) {
1101 1102 host = strtok(list, ":");
1102 1103 if (!nfs_get_root_principal(sec, host, &a[i])) {
1103 1104 while (i > 0)
1104 1105 free(a[--i]);
1105 1106 free(a);
1106 1107 a = NULL;
1107 1108 *count = 0;
1108 1109 break;
1109 1110 }
1110 1111 list = NULL;
1111 1112 }
1112 1113 }
1113 1114
1114 1115 return (a);
1115 1116 }
1116 1117
1117 1118 /*
1118 1119 * fill_security_from_secopts(sp, secopts)
1119 1120 *
1120 1121 * Fill the secinfo structure from the secopts optionset.
1121 1122 */
1122 1123
1123 1124 static int
1124 1125 fill_security_from_secopts(struct secinfo *sp, sa_security_t secopts)
1125 1126 {
1126 1127 sa_property_t prop;
1127 1128 char *type;
1128 1129 int longform;
1129 1130 int err = SC_NOERROR;
1130 1131 uint32_t val;
1131 1132
1132 1133 type = sa_get_security_attr(secopts, "sectype");
1133 1134 if (type != NULL) {
1134 1135 /* named security type needs secinfo to be filled in */
1135 1136 err = nfs_getseconfig_byname(type, &sp->s_secinfo);
1136 1137 sa_free_attr_string(type);
1137 1138 if (err != SC_NOERROR)
1138 1139 return (err);
1139 1140 } else {
1140 1141 /* default case */
1141 1142 err = nfs_getseconfig_default(&sp->s_secinfo);
1142 1143 if (err != SC_NOERROR)
1143 1144 return (err);
1144 1145 }
1145 1146
1146 1147 err = SA_OK;
1147 1148 for (prop = sa_get_property(secopts, NULL);
1148 1149 prop != NULL && err == SA_OK;
1149 1150 prop = sa_get_next_property(prop)) {
1150 1151 char *name;
1151 1152 char *value;
1152 1153
1153 1154 name = sa_get_property_attr(prop, "type");
1154 1155 value = sa_get_property_attr(prop, "value");
1155 1156
1156 1157 longform = value != NULL && strcmp(value, "*") != 0;
1157 1158
1158 1159 switch (findopt(name)) {
1159 1160 case OPT_RO:
1160 1161 sp->s_flags |= longform ? M_ROL : M_RO;
1161 1162 break;
1162 1163 case OPT_RW:
1163 1164 sp->s_flags |= longform ? M_RWL : M_RW;
1164 1165 break;
1165 1166 case OPT_ROOT:
1166 1167 sp->s_flags |= M_ROOT;
1167 1168 /*
1168 1169 * if we are using AUTH_UNIX, handle like other things
1169 1170 * such as RO/RW
1170 1171 */
1171 1172 if (sp->s_secinfo.sc_rpcnum == AUTH_UNIX)
1172 1173 break;
1173 1174 /* not AUTH_UNIX */
1174 1175 if (value != NULL) {
1175 1176 sp->s_rootnames = get_rootnames(&sp->s_secinfo,
1176 1177 value, &sp->s_rootcnt);
1177 1178 if (sp->s_rootnames == NULL) {
1178 1179 err = SA_BAD_VALUE;
1179 1180 (void) fprintf(stderr,
1180 1181 dgettext(TEXT_DOMAIN,
1181 1182 "Bad root list\n"));
1182 1183 }
1183 1184 }
1184 1185 break;
1185 1186 case OPT_NONE:
1186 1187 sp->s_flags |= M_NONE;
1187 1188 break;
1188 1189 case OPT_WINDOW:
1189 1190 if (value != NULL) {
1190 1191 sp->s_window = atoi(value);
1191 1192 /* just in case */
1192 1193 if (sp->s_window < 0)
1193 1194 sp->s_window = DEF_WIN;
1194 1195 }
1195 1196 break;
1196 1197 case OPT_ROOT_MAPPING:
1197 1198 if (value != NULL && is_a_number(value)) {
1198 1199 val = strtoul(value, NULL, 0);
1199 1200 } else {
1200 1201 struct passwd *pw;
1201 1202 pw = getpwnam(value != NULL ? value : "nobody");
1202 1203 if (pw != NULL) {
1203 1204 val = pw->pw_uid;
1204 1205 } else {
1205 1206 val = UID_NOBODY;
1206 1207 }
1207 1208 endpwent();
1208 1209 }
1209 1210 sp->s_rootid = val;
1210 1211 break;
1211 1212 case OPT_UIDMAP:
1212 1213 case OPT_GIDMAP:
1213 1214 sp->s_flags |= M_MAP;
1214 1215 break;
1215 1216 default:
1216 1217 break;
1217 1218 }
1218 1219 if (name != NULL)
1219 1220 sa_free_attr_string(name);
1220 1221 if (value != NULL)
1221 1222 sa_free_attr_string(value);
1222 1223 }
1223 1224 /* if rw/ro options not set, use default of RW */
1224 1225 if ((sp->s_flags & NFS_RWMODES) == 0)
1225 1226 sp->s_flags |= M_RW;
1226 1227 return (err);
1227 1228 }
1228 1229
1229 1230 /*
1230 1231 * This is for testing only
1231 1232 * It displays the export structure that
1232 1233 * goes into the kernel.
1233 1234 */
1234 1235 static void
1235 1236 printarg(char *path, struct exportdata *ep)
1236 1237 {
1237 1238 int i, j;
1238 1239 struct secinfo *sp;
1239 1240
1240 1241 if (debug == 0)
1241 1242 return;
1242 1243
1243 1244 (void) printf("%s:\n", path);
1244 1245 (void) printf("\tex_version = %d\n", ep->ex_version);
1245 1246 (void) printf("\tex_path = %s\n", ep->ex_path);
1246 1247 (void) printf("\tex_pathlen = %ld\n", (ulong_t)ep->ex_pathlen);
1247 1248 (void) printf("\tex_flags: (0x%02x) ", ep->ex_flags);
1248 1249 if (ep->ex_flags & EX_NOSUID)
1249 1250 (void) printf("NOSUID ");
1250 1251 if (ep->ex_flags & EX_ACLOK)
1251 1252 (void) printf("ACLOK ");
1252 1253 if (ep->ex_flags & EX_PUBLIC)
1253 1254 (void) printf("PUBLIC ");
1254 1255 if (ep->ex_flags & EX_NOSUB)
1255 1256 (void) printf("NOSUB ");
1256 1257 if (ep->ex_flags & EX_LOG)
1257 1258 (void) printf("LOG ");
1258 1259 if (ep->ex_flags & EX_CHARMAP)
1259 1260 (void) printf("CHARMAP ");
1260 1261 if (ep->ex_flags & EX_LOG_ALLOPS)
1261 1262 (void) printf("LOG_ALLOPS ");
1262 1263 if (ep->ex_flags == 0)
1263 1264 (void) printf("(none)");
1264 1265 (void) printf("\n");
1265 1266 if (ep->ex_flags & EX_LOG) {
1266 1267 (void) printf("\tex_log_buffer = %s\n",
1267 1268 (ep->ex_log_buffer ? ep->ex_log_buffer : "(NULL)"));
1268 1269 (void) printf("\tex_tag = %s\n",
1269 1270 (ep->ex_tag ? ep->ex_tag : "(NULL)"));
1270 1271 }
1271 1272 (void) printf("\tex_anon = %d\n", ep->ex_anon);
1272 1273 (void) printf("\tex_seccnt = %d\n", ep->ex_seccnt);
1273 1274 (void) printf("\n");
1274 1275 for (i = 0; i < ep->ex_seccnt; i++) {
1275 1276 sp = &ep->ex_secinfo[i];
1276 1277 (void) printf("\t\ts_secinfo = %s\n", sp->s_secinfo.sc_name);
1277 1278 (void) printf("\t\ts_flags: (0x%02x) ", sp->s_flags);
1278 1279 if (sp->s_flags & M_ROOT) (void) printf("M_ROOT ");
1279 1280 if (sp->s_flags & M_RO) (void) printf("M_RO ");
1280 1281 if (sp->s_flags & M_ROL) (void) printf("M_ROL ");
1281 1282 if (sp->s_flags & M_RW) (void) printf("M_RW ");
1282 1283 if (sp->s_flags & M_RWL) (void) printf("M_RWL ");
1283 1284 if (sp->s_flags & M_NONE) (void) printf("M_NONE ");
1284 1285 if (sp->s_flags & M_MAP) (void) printf("M_MAP ");
1285 1286 if (sp->s_flags == 0) (void) printf("(none)");
1286 1287 (void) printf("\n");
1287 1288 (void) printf("\t\ts_window = %d\n", sp->s_window);
1288 1289 (void) printf("\t\ts_rootid = %d\n", sp->s_rootid);
1289 1290 (void) printf("\t\ts_rootcnt = %d ", sp->s_rootcnt);
1290 1291 (void) fflush(stdout);
1291 1292 for (j = 0; j < sp->s_rootcnt; j++)
1292 1293 (void) printf("%s ", sp->s_rootnames[j] ?
1293 1294 sp->s_rootnames[j] : "<null>");
1294 1295 (void) printf("\n\n");
1295 1296 }
1296 1297 }
1297 1298
1298 1299 /*
1299 1300 * count_security(opts)
1300 1301 *
1301 1302 * Count the number of security types (flavors). The optionset has
1302 1303 * been populated with the security flavors as a holding mechanism.
1303 1304 * We later use this number to allocate data structures.
1304 1305 */
1305 1306
1306 1307 static int
1307 1308 count_security(sa_optionset_t opts)
1308 1309 {
1309 1310 int count = 0;
1310 1311 sa_property_t prop;
1311 1312 if (opts != NULL) {
1312 1313 for (prop = sa_get_property(opts, NULL); prop != NULL;
1313 1314 prop = sa_get_next_property(prop)) {
1314 1315 count++;
1315 1316 }
1316 1317 }
1317 1318 return (count);
1318 1319 }
1319 1320
1320 1321 /*
1321 1322 * nfs_sprint_option(rbuff, rbuffsize, incr, prop, sep)
1322 1323 *
1323 1324 * provides a mechanism to format NFS properties into legacy output
1324 1325 * format. If the buffer would overflow, it is reallocated and grown
1325 1326 * as appropriate. Special cases of converting internal form of values
1326 1327 * to those used by "share" are done. this function does one property
1327 1328 * at a time.
1328 1329 */
1329 1330
1330 1331 static int
1331 1332 nfs_sprint_option(char **rbuff, size_t *rbuffsize, size_t incr,
1332 1333 sa_property_t prop, int sep)
1333 1334 {
1334 1335 char *name;
1335 1336 char *value;
1336 1337 int curlen;
1337 1338 char *buff = *rbuff;
1338 1339 size_t buffsize = *rbuffsize;
1339 1340 int printed = B_FALSE;
1340 1341
1341 1342 name = sa_get_property_attr(prop, "type");
1342 1343 value = sa_get_property_attr(prop, "value");
1343 1344 if (buff != NULL)
1344 1345 curlen = strlen(buff);
1345 1346 else
1346 1347 curlen = 0;
1347 1348 if (name != NULL) {
1348 1349 int len;
1349 1350 len = strlen(name) + sep;
1350 1351
1351 1352 /*
1352 1353 * A future RFE would be to replace this with more
1353 1354 * generic code and to possibly handle more types.
1354 1355 */
1355 1356 switch (gettype(name)) {
1356 1357 case OPT_TYPE_BOOLEAN:
1357 1358 /*
1358 1359 * For NFS, boolean value of FALSE means it
1359 1360 * doesn't show up in the option list at all.
1360 1361 */
1361 1362 if (value != NULL && strcasecmp(value, "false") == 0)
1362 1363 goto skip;
1363 1364 if (value != NULL) {
1364 1365 sa_free_attr_string(value);
1365 1366 value = NULL;
1366 1367 }
1367 1368 break;
1368 1369 case OPT_TYPE_ACCLIST:
1369 1370 if (value != NULL && strcmp(value, "*") == 0) {
1370 1371 sa_free_attr_string(value);
1371 1372 value = NULL;
1372 1373 } else {
1373 1374 if (value != NULL)
1374 1375 len += 1 + strlen(value);
1375 1376 }
1376 1377 break;
1377 1378 case OPT_TYPE_LOGTAG:
1378 1379 if (value != NULL && strlen(value) == 0) {
1379 1380 sa_free_attr_string(value);
1380 1381 value = NULL;
1381 1382 } else {
1382 1383 if (value != NULL)
1383 1384 len += 1 + strlen(value);
1384 1385 }
1385 1386 break;
1386 1387 default:
1387 1388 if (value != NULL)
1388 1389 len += 1 + strlen(value);
1389 1390 break;
1390 1391 }
1391 1392 while (buffsize <= (curlen + len)) {
1392 1393 /* need more room */
1393 1394 buffsize += incr;
1394 1395 buff = realloc(buff, buffsize);
1395 1396 if (buff == NULL) {
1396 1397 /* realloc failed so free everything */
1397 1398 if (*rbuff != NULL)
1398 1399 free(*rbuff);
1399 1400 }
1400 1401 *rbuff = buff;
1401 1402 *rbuffsize = buffsize;
1402 1403 if (buff == NULL)
1403 1404 goto skip;
1404 1405
1405 1406 }
1406 1407
1407 1408 if (buff == NULL)
1408 1409 goto skip;
1409 1410
1410 1411 if (value == NULL) {
1411 1412 (void) snprintf(buff + curlen, buffsize - curlen,
1412 1413 "%s%s", sep ? "," : "", name);
1413 1414 } else {
1414 1415 (void) snprintf(buff + curlen, buffsize - curlen,
1415 1416 "%s%s=%s", sep ? "," : "",
1416 1417 name, value != NULL ? value : "");
1417 1418 }
1418 1419 printed = B_TRUE;
1419 1420 }
1420 1421 skip:
1421 1422 if (name != NULL)
1422 1423 sa_free_attr_string(name);
1423 1424 if (value != NULL)
1424 1425 sa_free_attr_string(value);
1425 1426 return (printed);
1426 1427 }
1427 1428
1428 1429 /*
1429 1430 * nfs_format_options(group, hier)
1430 1431 *
1431 1432 * format all the options on the group into an old-style option
1432 1433 * string. If hier is non-zero, walk up the tree to get inherited
1433 1434 * options.
1434 1435 */
1435 1436
1436 1437 static char *
1437 1438 nfs_format_options(sa_group_t group, int hier)
1438 1439 {
1439 1440 sa_optionset_t options = NULL;
1440 1441 sa_optionset_t secoptions = NULL;
1441 1442 sa_property_t prop, secprop;
1442 1443 sa_security_t security = NULL;
1443 1444 char *buff;
1444 1445 size_t buffsize;
1445 1446 char *sectype = NULL;
1446 1447 int sep = 0;
1447 1448
1448 1449
1449 1450 buff = malloc(OPT_CHUNK);
1450 1451 if (buff == NULL) {
1451 1452 return (NULL);
1452 1453 }
1453 1454
1454 1455 buff[0] = '\0';
1455 1456 buffsize = OPT_CHUNK;
1456 1457
1457 1458 /*
1458 1459 * We may have a an optionset relative to this item. format
1459 1460 * these if we find them and then add any security definitions.
1460 1461 */
1461 1462
1462 1463 options = sa_get_derived_optionset(group, "nfs", hier);
1463 1464
1464 1465 /*
1465 1466 * do the default set first but skip any option that is also
1466 1467 * in the protocol specific optionset.
1467 1468 */
1468 1469 if (options != NULL) {
1469 1470 for (prop = sa_get_property(options, NULL);
1470 1471 prop != NULL; prop = sa_get_next_property(prop)) {
1471 1472 /*
1472 1473 * use this one since we skipped any
1473 1474 * of these that were also in
1474 1475 * optdefault
1475 1476 */
1476 1477 if (nfs_sprint_option(&buff, &buffsize, OPT_CHUNK,
1477 1478 prop, sep))
1478 1479 sep = 1;
1479 1480 if (buff == NULL) {
1480 1481 /*
1481 1482 * buff could become NULL if there
1482 1483 * isn't enough memory for
1483 1484 * nfs_sprint_option to realloc()
1484 1485 * as necessary. We can't really
1485 1486 * do anything about it at this
1486 1487 * point so we return NULL. The
1487 1488 * caller should handle the
1488 1489 * failure.
1489 1490 */
1490 1491 if (options != NULL)
1491 1492 sa_free_derived_optionset(
1492 1493 options);
1493 1494 return (buff);
1494 1495 }
1495 1496 }
1496 1497 }
1497 1498 secoptions = (sa_optionset_t)sa_get_all_security_types(group,
1498 1499 "nfs", hier);
1499 1500 if (secoptions != NULL) {
1500 1501 for (secprop = sa_get_property(secoptions, NULL);
1501 1502 secprop != NULL;
1502 1503 secprop = sa_get_next_property(secprop)) {
1503 1504 sectype = sa_get_property_attr(secprop, "type");
1504 1505 security =
1505 1506 (sa_security_t)sa_get_derived_security(
1506 1507 group, sectype, "nfs", hier);
1507 1508 if (security != NULL) {
1508 1509 if (sectype != NULL) {
1509 1510 prop = sa_create_property(
1510 1511 "sec", sectype);
1511 1512 if (prop == NULL)
1512 1513 goto err;
1513 1514 if (nfs_sprint_option(&buff,
1514 1515 &buffsize, OPT_CHUNK, prop, sep))
1515 1516 sep = 1;
1516 1517 (void) sa_remove_property(prop);
1517 1518 if (buff == NULL)
1518 1519 goto err;
1519 1520 }
1520 1521 for (prop = sa_get_property(security,
1521 1522 NULL); prop != NULL;
1522 1523 prop = sa_get_next_property(prop)) {
1523 1524 if (nfs_sprint_option(&buff,
1524 1525 &buffsize, OPT_CHUNK, prop, sep))
1525 1526 sep = 1;
1526 1527 if (buff == NULL)
1527 1528 goto err;
1528 1529 }
1529 1530 sa_free_derived_optionset(security);
1530 1531 }
1531 1532 if (sectype != NULL)
1532 1533 sa_free_attr_string(sectype);
1533 1534 }
1534 1535 sa_free_derived_optionset(secoptions);
1535 1536 }
1536 1537
1537 1538 if (options != NULL)
1538 1539 sa_free_derived_optionset(options);
1539 1540 return (buff);
1540 1541
1541 1542 err:
1542 1543 /*
1543 1544 * If we couldn't allocate memory for option printing, we need
1544 1545 * to break out of the nested loops, cleanup and return NULL.
1545 1546 */
1546 1547 if (secoptions != NULL)
1547 1548 sa_free_derived_optionset(secoptions);
1548 1549 if (security != NULL)
1549 1550 sa_free_derived_optionset(security);
1550 1551 if (sectype != NULL)
1551 1552 sa_free_attr_string(sectype);
1552 1553 if (options != NULL)
1553 1554 sa_free_derived_optionset(options);
1554 1555 return (buff);
1555 1556 }
1556 1557
1557 1558 /*
1558 1559 * Append an entry to the nfslogtab file
1559 1560 */
1560 1561 static int
1561 1562 nfslogtab_add(char *dir, char *buffer, char *tag)
1562 1563 {
1563 1564 FILE *f;
1564 1565 struct logtab_ent lep;
1565 1566 int error = 0;
1566 1567
1567 1568 /*
1568 1569 * Open the file for update and create it if necessary.
1569 1570 * This may leave the I/O offset at the end of the file,
1570 1571 * so rewind back to the beginning of the file.
1571 1572 */
1572 1573 f = fopen(NFSLOGTAB, "a+");
1573 1574 if (f == NULL) {
1574 1575 error = errno;
1575 1576 goto out;
1576 1577 }
1577 1578 rewind(f);
1578 1579
1579 1580 if (lockf(fileno(f), F_LOCK, 0L) < 0) {
1580 1581 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
1581 1582 "share complete, however failed to lock %s "
1582 1583 "for update: %s\n"), NFSLOGTAB, strerror(errno));
1583 1584 error = -1;
1584 1585 goto out;
1585 1586 }
1586 1587
1587 1588 if (logtab_deactivate_after_boot(f) == -1) {
1588 1589 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
1589 1590 "share complete, however could not deactivate "
1590 1591 "entries in %s\n"), NFSLOGTAB);
1591 1592 error = -1;
1592 1593 goto out;
1593 1594 }
1594 1595
1595 1596 /*
1596 1597 * Remove entries matching buffer and sharepoint since we're
1597 1598 * going to replace it with perhaps an entry with a new tag.
1598 1599 */
1599 1600 if (logtab_rement(f, buffer, dir, NULL, -1)) {
1600 1601 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
1601 1602 "share complete, however could not remove matching "
1602 1603 "entries in %s\n"), NFSLOGTAB);
1603 1604 error = -1;
1604 1605 goto out;
1605 1606 }
1606 1607
1607 1608 /*
1608 1609 * Deactivate all active entries matching this sharepoint
1609 1610 */
1610 1611 if (logtab_deactivate(f, NULL, dir, NULL)) {
1611 1612 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
1612 1613 "share complete, however could not deactivate matching "
1613 1614 "entries in %s\n"), NFSLOGTAB);
1614 1615 error = -1;
1615 1616 goto out;
1616 1617 }
1617 1618
1618 1619 lep.le_buffer = buffer;
1619 1620 lep.le_path = dir;
1620 1621 lep.le_tag = tag;
1621 1622 lep.le_state = LES_ACTIVE;
1622 1623
1623 1624 /*
1624 1625 * Add new sharepoint / buffer location to nfslogtab
1625 1626 */
1626 1627 if (logtab_putent(f, &lep) < 0) {
1627 1628 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
1628 1629 "share complete, however could not add %s to %s\n"),
1629 1630 dir, NFSLOGTAB);
1630 1631 error = -1;
1631 1632 }
1632 1633
1633 1634 out:
1634 1635 if (f != NULL)
1635 1636 (void) fclose(f);
1636 1637 return (error);
1637 1638 }
1638 1639
1639 1640 /*
1640 1641 * Deactivate an entry from the nfslogtab file
1641 1642 */
1642 1643 static int
1643 1644 nfslogtab_deactivate(char *path)
1644 1645 {
1645 1646 FILE *f;
1646 1647 int error = 0;
1647 1648
1648 1649 f = fopen(NFSLOGTAB, "r+");
1649 1650 if (f == NULL) {
1650 1651 error = errno;
1651 1652 goto out;
1652 1653 }
1653 1654 if (lockf(fileno(f), F_LOCK, 0L) < 0) {
1654 1655 error = errno;
1655 1656 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
1656 1657 "share complete, however could not lock %s for "
1657 1658 "update: %s\n"), NFSLOGTAB, strerror(error));
1658 1659 goto out;
1659 1660 }
1660 1661 if (logtab_deactivate(f, NULL, path, NULL) == -1) {
1661 1662 error = -1;
1662 1663 (void) fprintf(stderr,
1663 1664 dgettext(TEXT_DOMAIN,
1664 1665 "share complete, however could not "
1665 1666 "deactivate %s in %s\n"), path, NFSLOGTAB);
1666 1667 goto out;
1667 1668 }
1668 1669
1669 1670 out: if (f != NULL)
1670 1671 (void) fclose(f);
1671 1672
1672 1673 return (error);
1673 1674 }
1674 1675
1675 1676 /*
1676 1677 * check_public(group, skipshare)
1677 1678 *
1678 1679 * Check the group for any shares that have the public property
1679 1680 * enabled. We skip "skipshare" since that is the one we are
1680 1681 * working with. This is a separate function to make handling
1681 1682 * subgroups simpler. Returns true if there is a share with public.
1682 1683 */
1683 1684 static int
1684 1685 check_public(sa_group_t group, sa_share_t skipshare)
1685 1686 {
1686 1687 int exists = B_FALSE;
1687 1688 sa_share_t share;
1688 1689 sa_optionset_t opt;
1689 1690 sa_property_t prop;
1690 1691 char *shared;
1691 1692
1692 1693 for (share = sa_get_share(group, NULL); share != NULL;
1693 1694 share = sa_get_next_share(share)) {
1694 1695 if (share == skipshare)
1695 1696 continue;
1696 1697
1697 1698 opt = sa_get_optionset(share, "nfs");
1698 1699 if (opt == NULL)
1699 1700 continue;
1700 1701 prop = sa_get_property(opt, "public");
1701 1702 if (prop == NULL)
1702 1703 continue;
1703 1704 shared = sa_get_share_attr(share, "shared");
1704 1705 if (shared != NULL) {
1705 1706 exists = strcmp(shared, "true") == 0;
1706 1707 sa_free_attr_string(shared);
1707 1708 if (exists == B_TRUE)
1708 1709 break;
1709 1710 }
1710 1711 }
1711 1712
1712 1713 return (exists);
1713 1714 }
1714 1715
1715 1716 /*
1716 1717 * public_exists(handle, skipshare)
1717 1718 *
1718 1719 * check to see if public option is set on any other share than the
1719 1720 * one specified. Need to check zfs sub-groups as well as the top
1720 1721 * level groups.
1721 1722 */
1722 1723 static int
1723 1724 public_exists(sa_handle_t handle, sa_share_t skipshare)
1724 1725 {
1725 1726 sa_group_t group = NULL;
1726 1727
1727 1728 /*
1728 1729 * If we don't have a handle, we can only do syntax check. We
1729 1730 * can't check against other shares so we assume OK and will
1730 1731 * catch the problem only when we actually try to apply it.
1731 1732 */
1732 1733 if (handle == NULL)
1733 1734 return (SA_OK);
1734 1735
1735 1736 if (skipshare != NULL) {
1736 1737 group = sa_get_parent_group(skipshare);
1737 1738 if (group == NULL)
1738 1739 return (SA_NO_SUCH_GROUP);
1739 1740 }
1740 1741
1741 1742 for (group = sa_get_group(handle, NULL); group != NULL;
1742 1743 group = sa_get_next_group(group)) {
1743 1744 /* Walk any ZFS subgroups as well as all standard groups */
1744 1745 if (sa_group_is_zfs(group)) {
1745 1746 sa_group_t subgroup;
1746 1747 for (subgroup = sa_get_sub_group(group);
1747 1748 subgroup != NULL;
1748 1749 subgroup = sa_get_next_group(subgroup)) {
1749 1750 if (check_public(subgroup, skipshare))
1750 1751 return (B_TRUE);
1751 1752 }
1752 1753 } else {
1753 1754 if (check_public(group, skipshare))
1754 1755 return (B_TRUE);
1755 1756 }
1756 1757 }
1757 1758 return (B_FALSE);
1758 1759 }
1759 1760
1760 1761 /*
1761 1762 * sa_enable_share at the protocol level, enable_share must tell the
1762 1763 * implementation that it is to enable the share. This entails
1763 1764 * converting the path and options into the appropriate ioctl
1764 1765 * calls. It is assumed that all error checking of paths, etc. were
1765 1766 * done earlier.
1766 1767 */
1767 1768 static int
1768 1769 nfs_enable_share(sa_share_t share)
1769 1770 {
1770 1771 struct exportdata export;
1771 1772 sa_optionset_t secoptlist;
1772 1773 struct secinfo *sp;
1773 1774 int num_secinfo;
1774 1775 sa_optionset_t opt;
1775 1776 sa_security_t sec;
1776 1777 sa_property_t prop;
1777 1778 char *path;
1778 1779 int err = SA_OK;
1779 1780 int i;
1780 1781 int iszfs;
1781 1782 sa_handle_t handle;
1782 1783
1783 1784 /* Don't drop core if the NFS module isn't loaded. */
1784 1785 (void) signal(SIGSYS, SIG_IGN);
1785 1786
1786 1787 /* get the path since it is important in several places */
1787 1788 path = sa_get_share_attr(share, "path");
1788 1789 if (path == NULL)
1789 1790 return (SA_NO_SUCH_PATH);
1790 1791
1791 1792 iszfs = sa_path_is_zfs(path);
1792 1793 /*
1793 1794 * find the optionsets and security sets. There may not be
1794 1795 * any or there could be one or two for each of optionset and
1795 1796 * security may have multiple, one per security type per
1796 1797 * protocol type.
1797 1798 */
1798 1799 opt = sa_get_derived_optionset(share, "nfs", 1);
1799 1800 secoptlist = (sa_optionset_t)sa_get_all_security_types(share, "nfs", 1);
1800 1801 if (secoptlist != NULL)
1801 1802 num_secinfo = MAX(1, count_security(secoptlist));
1802 1803 else
1803 1804 num_secinfo = 1;
1804 1805
1805 1806 /*
1806 1807 * walk through the options and fill in the structure
1807 1808 * appropriately.
1808 1809 */
1809 1810
1810 1811 (void) memset(&export, '\0', sizeof (export));
1811 1812
1812 1813 /*
1813 1814 * do non-security options first since there is only one after
1814 1815 * the derived group is constructed.
1815 1816 */
1816 1817 export.ex_version = EX_CURRENT_VERSION;
1817 1818 export.ex_anon = UID_NOBODY; /* this is our default value */
1818 1819 export.ex_index = NULL;
1819 1820 export.ex_path = path;
1820 1821 export.ex_pathlen = strlen(path) + 1;
1821 1822
1822 1823 if (opt != NULL)
1823 1824 err = fill_export_from_optionset(&export, opt);
1824 1825
1825 1826 /*
1826 1827 * check to see if "public" is set. If it is, then make sure
1827 1828 * no other share has it set. If it is already used, fail.
1828 1829 */
1829 1830
1830 1831 handle = sa_find_group_handle((sa_group_t)share);
1831 1832 if (export.ex_flags & EX_PUBLIC && public_exists(handle, share)) {
1832 1833 (void) printf(dgettext(TEXT_DOMAIN,
1833 1834 "NFS: Cannot share more than one file "
1834 1835 "system with 'public' property\n"));
1835 1836 err = SA_NOT_ALLOWED;
1836 1837 goto out;
1837 1838 }
1838 1839
1839 1840 sp = calloc(num_secinfo, sizeof (struct secinfo));
1840 1841 if (sp == NULL) {
1841 1842 err = SA_NO_MEMORY;
1842 1843 (void) printf(dgettext(TEXT_DOMAIN,
1843 1844 "NFS: NFS: no memory for security\n"));
1844 1845 goto out;
1845 1846 }
1846 1847 export.ex_secinfo = sp;
1847 1848 /* get default secinfo */
1848 1849 export.ex_seccnt = num_secinfo;
1849 1850 /*
1850 1851 * since we must have one security option defined, we
1851 1852 * init to the default and then override as we find
1852 1853 * defined security options. This handles the case
1853 1854 * where we have no defined options but we need to set
1854 1855 * up one.
1855 1856 */
1856 1857 sp[0].s_window = DEF_WIN;
1857 1858 sp[0].s_rootnames = NULL;
1858 1859 /* setup a default in case no properties defined */
1859 1860 if (nfs_getseconfig_default(&sp[0].s_secinfo)) {
1860 1861 (void) printf(dgettext(TEXT_DOMAIN,
1861 1862 "NFS: nfs_getseconfig_default: failed to "
1862 1863 "get default security mode\n"));
1863 1864 err = SA_CONFIG_ERR;
1864 1865 }
1865 1866 if (secoptlist != NULL) {
1866 1867 for (i = 0, prop = sa_get_property(secoptlist, NULL);
1867 1868 prop != NULL && i < num_secinfo;
1868 1869 prop = sa_get_next_property(prop), i++) {
1869 1870 char *sectype;
1870 1871 sectype = sa_get_property_attr(prop, "type");
1871 1872 /*
1872 1873 * if sectype is NULL, we probably
1873 1874 * have a memory problem and can't get
1874 1875 * the correct values. Rather than
1875 1876 * exporting with incorrect security,
1876 1877 * don't share it.
1877 1878 */
1878 1879 if (sectype == NULL) {
1879 1880 err = SA_NO_MEMORY;
1880 1881 (void) printf(dgettext(TEXT_DOMAIN,
1881 1882 "NFS: Cannot share %s: "
1882 1883 "no memory\n"), path);
1883 1884 goto out;
1884 1885 }
1885 1886 sec = (sa_security_t)sa_get_derived_security(
1886 1887 share, sectype, "nfs", 1);
1887 1888 sp[i].s_window = DEF_WIN;
1888 1889 sp[i].s_rootcnt = 0;
1889 1890 sp[i].s_rootnames = NULL;
1890 1891 (void) fill_security_from_secopts(&sp[i], sec);
1891 1892 if (sec != NULL)
1892 1893 sa_free_derived_security(sec);
1893 1894 if (sectype != NULL)
1894 1895 sa_free_attr_string(sectype);
1895 1896 }
1896 1897 }
1897 1898 /*
1898 1899 * when we get here, we can do the exportfs system call and
1899 1900 * initiate things. We probably want to enable the
1900 1901 * svc:/network/nfs/server service first if it isn't running.
1901 1902 */
1902 1903 /* check svc:/network/nfs/server status and start if needed */
1903 1904 /* now add the share to the internal tables */
1904 1905 printarg(path, &export);
1905 1906 /*
1906 1907 * call the exportfs system call which is implemented
1907 1908 * via the nfssys() call as the EXPORTFS subfunction.
1908 1909 */
1909 1910 if (iszfs) {
1910 1911 struct exportfs_args ea;
1911 1912 share_t sh;
1912 1913 char *str;
1913 1914 priv_set_t *priv_effective;
1914 1915 int privileged;
1915 1916
1916 1917 /*
1917 1918 * If we aren't a privileged user
1918 1919 * and NFS server service isn't running
1919 1920 * then print out an error message
1920 1921 * and return EPERM
1921 1922 */
1922 1923
1923 1924 priv_effective = priv_allocset();
1924 1925 (void) getppriv(PRIV_EFFECTIVE, priv_effective);
1925 1926
1926 1927 privileged = (priv_isfullset(priv_effective) == B_TRUE);
1927 1928 priv_freeset(priv_effective);
1928 1929
1929 1930 if (!privileged &&
1930 1931 (str = smf_get_state(NFS_SERVER_SVC)) != NULL) {
1931 1932 err = 0;
1932 1933 if (strcmp(str, SCF_STATE_STRING_ONLINE) != 0) {
1933 1934 (void) printf(dgettext(TEXT_DOMAIN,
1934 1935 "NFS: Cannot share remote "
1935 1936 "filesystem: %s\n"), path);
1936 1937 (void) printf(dgettext(TEXT_DOMAIN,
1937 1938 "NFS: Service needs to be enabled "
1938 1939 "by a privileged user\n"));
1939 1940 err = SA_SYSTEM_ERR;
1940 1941 errno = EPERM;
1941 1942 }
1942 1943 free(str);
1943 1944 }
1944 1945
1945 1946 if (err == 0) {
1946 1947 ea.dname = path;
1947 1948 ea.uex = &export;
1948 1949
1949 1950 (void) sa_sharetab_fill_zfs(share, &sh, "nfs");
1950 1951 err = sa_share_zfs(share, NULL, path, &sh,
1951 1952 &ea, ZFS_SHARE_NFS);
1952 1953 if (err != SA_OK) {
1953 1954 errno = err;
1954 1955 err = -1;
1955 1956 }
1956 1957 sa_emptyshare(&sh);
1957 1958 }
1958 1959 } else {
1959 1960 err = exportfs(path, &export);
1960 1961 }
1961 1962
1962 1963 if (err < 0) {
1963 1964 err = SA_SYSTEM_ERR;
1964 1965 switch (errno) {
1965 1966 case EREMOTE:
1966 1967 (void) printf(dgettext(TEXT_DOMAIN,
1967 1968 "NFS: Cannot share filesystems "
1968 1969 "in non-global zones: %s\n"), path);
1969 1970 err = SA_NOT_SUPPORTED;
1970 1971 break;
1971 1972 case EPERM:
1972 1973 if (getzoneid() != GLOBAL_ZONEID) {
1973 1974 (void) printf(dgettext(TEXT_DOMAIN,
1974 1975 "NFS: Cannot share file systems "
1975 1976 "in non-global zones: %s\n"), path);
1976 1977 err = SA_NOT_SUPPORTED;
1977 1978 break;
1978 1979 }
1979 1980 err = SA_NO_PERMISSION;
1980 1981 break;
1981 1982 case EEXIST:
1982 1983 err = SA_SHARE_EXISTS;
1983 1984 break;
1984 1985 default:
1985 1986 break;
1986 1987 }
1987 1988 } else {
1988 1989 /* update sharetab with an add/modify */
1989 1990 if (!iszfs) {
1990 1991 (void) sa_update_sharetab(share, "nfs");
1991 1992 }
1992 1993 }
1993 1994
1994 1995 if (err == SA_OK) {
1995 1996 /*
1996 1997 * enable services as needed. This should probably be
1997 1998 * done elsewhere in order to minimize the calls to
1998 1999 * check services.
1999 2000 */
2000 2001 /*
2001 2002 * check to see if logging and other services need to
2002 2003 * be triggered, but only if there wasn't an
2003 2004 * error. This is probably where sharetab should be
2004 2005 * updated with the NFS specific entry.
2005 2006 */
2006 2007 if (export.ex_flags & EX_LOG) {
2007 2008 /* enable logging */
2008 2009 if (nfslogtab_add(path, export.ex_log_buffer,
2009 2010 export.ex_tag) != 0) {
2010 2011 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
2011 2012 "Could not enable logging for %s\n"),
2012 2013 path);
2013 2014 }
2014 2015 _check_services(service_list_logging);
2015 2016 } else {
2016 2017 /*
2017 2018 * don't have logging so remove it from file. It might
2018 2019 * not be thre, but that doesn't matter.
2019 2020 */
2020 2021 (void) nfslogtab_deactivate(path);
2021 2022 _check_services(service_list_default);
2022 2023 }
2023 2024 }
2024 2025
2025 2026 out:
2026 2027 if (path != NULL)
2027 2028 free(path);
2028 2029
2029 2030 cleanup_export(&export);
2030 2031 if (opt != NULL)
2031 2032 sa_free_derived_optionset(opt);
2032 2033 if (secoptlist != NULL)
2033 2034 (void) sa_destroy_optionset(secoptlist);
2034 2035 return (err);
2035 2036 }
2036 2037
2037 2038 /*
2038 2039 * nfs_disable_share(share, path)
2039 2040 *
2040 2041 * Unshare the specified share. Note that "path" is the same path as
2041 2042 * what is in the "share" object. It is passed in to avoid an
2042 2043 * additional lookup. A missing "path" value makes this a no-op
2043 2044 * function.
2044 2045 */
2045 2046 static int
2046 2047 nfs_disable_share(sa_share_t share, char *path)
2047 2048 {
2048 2049 int err;
2049 2050 int ret = SA_OK;
2050 2051 int iszfs;
2051 2052 sa_group_t parent;
2052 2053 sa_handle_t handle;
2053 2054
2054 2055 if (path == NULL)
2055 2056 return (ret);
2056 2057
2057 2058 /*
2058 2059 * If the share is in a ZFS group we need to handle it
2059 2060 * differently. Just being on a ZFS file system isn't
2060 2061 * enough since we may be in a legacy share case.
2061 2062 */
2062 2063 parent = sa_get_parent_group(share);
2063 2064 iszfs = sa_group_is_zfs(parent);
2064 2065 if (iszfs) {
2065 2066 struct exportfs_args ea;
2066 2067 share_t sh = { 0 };
2067 2068 ea.dname = path;
2068 2069 ea.uex = NULL;
2069 2070 sh.sh_path = path;
2070 2071 sh.sh_fstype = "nfs";
2071 2072
2072 2073 err = sa_share_zfs(share, NULL, path, &sh,
2073 2074 &ea, ZFS_UNSHARE_NFS);
2074 2075 if (err != SA_OK) {
2075 2076 errno = err;
2076 2077 err = -1;
2077 2078 }
2078 2079 } else {
2079 2080 err = exportfs(path, NULL);
2080 2081 }
2081 2082 if (err < 0) {
2082 2083 /*
2083 2084 * TBD: only an error in some
2084 2085 * cases - need better analysis
2085 2086 */
2086 2087 switch (errno) {
2087 2088 case EPERM:
2088 2089 case EACCES:
2089 2090 ret = SA_NO_PERMISSION;
2090 2091 if (getzoneid() != GLOBAL_ZONEID) {
2091 2092 ret = SA_NOT_SUPPORTED;
2092 2093 }
2093 2094 break;
2094 2095 case EINVAL:
2095 2096 case ENOENT:
2096 2097 ret = SA_NO_SUCH_PATH;
2097 2098 break;
2098 2099 default:
2099 2100 ret = SA_SYSTEM_ERR;
2100 2101 break;
2101 2102 }
2102 2103 }
2103 2104 if (ret == SA_OK || ret == SA_NO_SUCH_PATH) {
2104 2105 handle = sa_find_group_handle((sa_group_t)share);
2105 2106 if (!iszfs)
2106 2107 (void) sa_delete_sharetab(handle, path, "nfs");
2107 2108 /* just in case it was logged */
2108 2109 (void) nfslogtab_deactivate(path);
2109 2110 }
2110 2111 return (ret);
2111 2112 }
2112 2113
2113 2114 static int
2114 2115 check_user(char *value)
2115 2116 {
2116 2117 int ret = SA_OK;
2117 2118
2118 2119 if (!is_a_number(value)) {
2119 2120 struct passwd *pw;
2120 2121 /*
2121 2122 * in this case it would have to be a
2122 2123 * user name
2123 2124 */
2124 2125 pw = getpwnam(value);
2125 2126 if (pw == NULL)
2126 2127 ret = SA_BAD_VALUE;
2127 2128 endpwent();
2128 2129 } else {
2129 2130 uint64_t intval;
2130 2131 intval = strtoull(value, NULL, 0);
2131 2132 if (intval > UID_MAX && intval != -1)
2132 2133 ret = SA_BAD_VALUE;
2133 2134 }
2134 2135
2135 2136 return (ret);
2136 2137 }
2137 2138
2138 2139 static int
2139 2140 check_group(char *value)
2140 2141 {
2141 2142 int ret = SA_OK;
2142 2143
2143 2144 if (!is_a_number(value)) {
2144 2145 struct group *gr;
2145 2146 /*
2146 2147 * in this case it would have to be a
2147 2148 * group name
2148 2149 */
2149 2150 gr = getgrnam(value);
2150 2151 if (gr == NULL)
2151 2152 ret = SA_BAD_VALUE;
2152 2153 endgrent();
2153 2154 } else {
2154 2155 uint64_t intval;
2155 2156 intval = strtoull(value, NULL, 0);
2156 2157 if (intval > UID_MAX && intval != -1)
2157 2158 ret = SA_BAD_VALUE;
2158 2159 }
2159 2160
2160 2161 return (ret);
2161 2162 }
2162 2163
2163 2164 /*
2164 2165 * check_rorwnone(v1, v2, v3)
2165 2166 *
2166 2167 * check ro vs rw vs none values. Over time this may get beefed up.
2167 2168 * for now it just does simple checks. v1 is never NULL but v2 or v3
2168 2169 * could be.
2169 2170 */
2170 2171
2171 2172 static int
2172 2173 check_rorwnone(char *v1, char *v2, char *v3)
2173 2174 {
2174 2175 int ret = SA_OK;
2175 2176 if (v2 != NULL && strcmp(v1, v2) == 0)
2176 2177 ret = SA_VALUE_CONFLICT;
2177 2178 else if (v3 != NULL && strcmp(v1, v3) == 0)
2178 2179 ret = SA_VALUE_CONFLICT;
2179 2180
2180 2181 return (ret);
2181 2182 }
2182 2183
2183 2184 /*
2184 2185 * nfs_validate_property(handle, property, parent)
2185 2186 *
2186 2187 * Check that the property has a legitimate value for its type.
2187 2188 */
2188 2189
2189 2190 static int
2190 2191 nfs_validate_property(sa_handle_t handle, sa_property_t property,
2191 2192 sa_optionset_t parent)
2192 2193 {
2193 2194 int ret = SA_OK;
2194 2195 char *propname;
2195 2196 char *other1;
2196 2197 char *other2;
2197 2198 int optindex;
2198 2199 nfsl_config_t *configlist;
2199 2200 sa_group_t parent_group;
2200 2201 char *value;
2201 2202
2202 2203 propname = sa_get_property_attr(property, "type");
2203 2204
2204 2205 if ((optindex = findopt(propname)) < 0)
2205 2206 ret = SA_NO_SUCH_PROP;
2206 2207
2207 2208 /* need to validate value range here as well */
2208 2209
2209 2210 if (ret == SA_OK) {
2210 2211 parent_group = sa_get_parent_group((sa_share_t)parent);
2211 2212 if (optdefs[optindex].share && parent_group != NULL &&
2212 2213 !sa_is_share(parent_group))
2213 2214 ret = SA_PROP_SHARE_ONLY;
2214 2215 }
2215 2216 if (ret == SA_OK) {
2216 2217 if (optdefs[optindex].index == OPT_PUBLIC) {
2217 2218 /*
2218 2219 * Public is special in that only one instance can
2219 2220 * be in the repository at the same time.
2220 2221 */
2221 2222 if (public_exists(handle, parent_group)) {
2222 2223 sa_free_attr_string(propname);
2223 2224 return (SA_VALUE_CONFLICT);
2224 2225 }
2225 2226 }
2226 2227 value = sa_get_property_attr(property, "value");
2227 2228 if (value != NULL) {
2228 2229 /* first basic type checking */
2229 2230 switch (optdefs[optindex].type) {
2230 2231
2231 2232 case OPT_TYPE_NUMBER:
2232 2233 /* check that the value is all digits */
2233 2234 if (!is_a_number(value))
2234 2235 ret = SA_BAD_VALUE;
2235 2236 break;
2236 2237
2237 2238 case OPT_TYPE_BOOLEAN:
2238 2239 if (strlen(value) == 0 ||
2239 2240 strcasecmp(value, "true") == 0 ||
2240 2241 strcmp(value, "1") == 0 ||
2241 2242 strcasecmp(value, "false") == 0 ||
2242 2243 strcmp(value, "0") == 0) {
2243 2244 ret = SA_OK;
2244 2245 } else {
2245 2246 ret = SA_BAD_VALUE;
2246 2247 }
2247 2248 break;
2248 2249
2249 2250 case OPT_TYPE_USER:
2250 2251 ret = check_user(value);
2251 2252 break;
2252 2253
2253 2254 case OPT_TYPE_FILE:
2254 2255 if (strcmp(value, "..") == 0 ||
2255 2256 strchr(value, '/') != NULL) {
2256 2257 ret = SA_BAD_VALUE;
2257 2258 }
2258 2259 break;
2259 2260
2260 2261 case OPT_TYPE_ACCLIST: {
2261 2262 sa_property_t oprop1;
2262 2263 sa_property_t oprop2;
2263 2264 char *ovalue1 = NULL;
2264 2265 char *ovalue2 = NULL;
2265 2266
2266 2267 if (parent == NULL)
2267 2268 break;
2268 2269 /*
2269 2270 * access list handling. Should eventually
2270 2271 * validate that all the values make sense.
2271 2272 * Also, ro and rw may have cross value
2272 2273 * conflicts.
2273 2274 */
2274 2275 if (strcmp(propname, SHOPT_RO) == 0) {
2275 2276 other1 = SHOPT_RW;
2276 2277 other2 = SHOPT_NONE;
2277 2278 } else if (strcmp(propname, SHOPT_RW) == 0) {
2278 2279 other1 = SHOPT_RO;
2279 2280 other2 = SHOPT_NONE;
2280 2281 } else if (strcmp(propname, SHOPT_NONE) == 0) {
2281 2282 other1 = SHOPT_RO;
2282 2283 other2 = SHOPT_RW;
2283 2284 } else {
2284 2285 other1 = NULL;
2285 2286 other2 = NULL;
2286 2287 }
2287 2288 if (other1 == NULL && other2 == NULL)
2288 2289 break;
2289 2290
2290 2291 /* compare rw(ro) with ro(rw) */
2291 2292
2292 2293 oprop1 = sa_get_property(parent, other1);
2293 2294 oprop2 = sa_get_property(parent, other2);
2294 2295 if (oprop1 == NULL && oprop2 == NULL)
2295 2296 break;
2296 2297 /*
2297 2298 * Only potential confusion if other1
2298 2299 * or other2 exists. Check the values
2299 2300 * and run the check if there is a
2300 2301 * value other than the one we are
2301 2302 * explicitly looking at.
2302 2303 */
2303 2304 ovalue1 = sa_get_property_attr(oprop1, "value");
2304 2305 ovalue2 = sa_get_property_attr(oprop2, "value");
2305 2306 if (ovalue1 != NULL || ovalue2 != NULL)
2306 2307 ret = check_rorwnone(value, ovalue1,
2307 2308 ovalue2);
2308 2309
2309 2310 if (ovalue1 != NULL)
2310 2311 sa_free_attr_string(ovalue1);
2311 2312 if (ovalue2 != NULL)
2312 2313 sa_free_attr_string(ovalue2);
2313 2314 break;
2314 2315 }
2315 2316
2316 2317 case OPT_TYPE_LOGTAG:
2317 2318 if (nfsl_getconfig_list(&configlist) == 0) {
2318 2319 int error;
2319 2320 if (value == NULL ||
2320 2321 strlen(value) == 0) {
2321 2322 if (value != NULL)
2322 2323 sa_free_attr_string(
2323 2324 value);
2324 2325 value = strdup("global");
2325 2326 }
2326 2327 if (value != NULL &&
2327 2328 nfsl_findconfig(configlist, value,
2328 2329 &error) == NULL) {
2329 2330 ret = SA_BAD_VALUE;
2330 2331 }
2331 2332 /* Must always free when done */
2332 2333 nfsl_freeconfig_list(&configlist);
2333 2334 } else {
2334 2335 ret = SA_CONFIG_ERR;
2335 2336 }
2336 2337 break;
2337 2338
2338 2339 case OPT_TYPE_STRING:
2339 2340 /* whatever is here should be ok */
2340 2341 break;
2341 2342
2342 2343 case OPT_TYPE_SECURITY:
2343 2344 /*
2344 2345 * The "sec" property isn't used in the
2345 2346 * non-legacy parts of sharemgr. We need to
2346 2347 * reject it here. For legacy, it is pulled
2347 2348 * out well before we get here.
2348 2349 */
2349 2350 ret = SA_NO_SUCH_PROP;
2350 2351 break;
2351 2352
2352 2353 case OPT_TYPE_MAPPING: {
2353 2354 char *p;
2354 2355 char *n;
2355 2356 char *c;
2356 2357 int (*f)(char *);
2357 2358
2358 2359 sa_security_t security;
2359 2360
2360 2361 /*
2361 2362 * mapping is only supported for sec=sys
2362 2363 */
2363 2364 ret = SA_CONFIG_ERR;
2364 2365 if (parent_group == NULL)
2365 2366 break;
2366 2367
2367 2368 for (security = sa_get_security(parent_group,
2368 2369 NULL, NULL); security != NULL;
2369 2370 security = sa_get_next_security(security)) {
2370 2371 char *type;
2371 2372 char *sectype;
2372 2373
2373 2374 type = sa_get_security_attr(security,
2374 2375 "type");
2375 2376 if (type == NULL)
2376 2377 continue;
2377 2378
2378 2379 if (strcmp(type, "nfs") != 0) {
2379 2380 sa_free_attr_string(type);
2380 2381 continue;
2381 2382 }
2382 2383 sa_free_attr_string(type);
2383 2384
2384 2385 sectype = sa_get_security_attr(security,
2385 2386 "sectype");
2386 2387 if (sectype == NULL)
2387 2388 continue;
2388 2389
2389 2390 if (strcmp(sectype, "sys") != 0) {
2390 2391 sa_free_attr_string(sectype);
2391 2392 ret = SA_CONFIG_ERR;
2392 2393 break;
2393 2394 }
2394 2395 sa_free_attr_string(sectype);
2395 2396 ret = SA_OK;
2396 2397 }
2397 2398
2398 2399 if (ret != SA_OK)
2399 2400 break;
2400 2401
2401 2402 assert(optindex == OPT_UIDMAP ||
2402 2403 optindex == OPT_GIDMAP);
2403 2404 f = optindex == OPT_UIDMAP ? check_user :
2404 2405 check_group;
2405 2406
2406 2407
2407 2408 p = strdup(value);
2408 2409 if (p == NULL)
2409 2410 ret = SA_BAD_VALUE;
2410 2411
2411 2412 for (c = p; ret == SA_OK && c != NULL; c = n) {
2412 2413 char *s;
2413 2414 char *t;
2414 2415
2415 2416 n = strchr(c, '~');
2416 2417 if (n != NULL)
2417 2418 *n++ = '\0';
2418 2419
2419 2420 s = strchr(c, ':');
2420 2421 if (s != NULL) {
2421 2422 *s++ = '\0';
2422 2423 t = strchr(s, ':');
2423 2424 if (t != NULL)
2424 2425 *t = '\0';
2425 2426 }
2426 2427
2427 2428 if (s == NULL || t == NULL)
2428 2429 ret = SA_BAD_VALUE;
2429 2430
2430 2431 if (ret == SA_OK && *c != '\0' &&
2431 2432 strcmp(c, "*") != 0)
2432 2433 ret = f(c);
2433 2434
2434 2435 if (ret == SA_OK && *s != '\0' &&
2435 2436 strcmp(s, "-1") != 0)
2436 2437 ret = f(s);
2437 2438 }
2438 2439
2439 2440 free(p);
2440 2441
2441 2442 break;
2442 2443 }
2443 2444
2444 2445 default:
2445 2446 break;
2446 2447 }
2447 2448
2448 2449 if (value != NULL)
2449 2450 sa_free_attr_string(value);
2450 2451
2451 2452 if (ret == SA_OK && optdefs[optindex].check != NULL) {
2452 2453 /* do the property specific check */
2453 2454 ret = optdefs[optindex].check(handle, property);
2454 2455 }
2455 2456 }
2456 2457 }
2457 2458
2458 2459 if (propname != NULL)
2459 2460 sa_free_attr_string(propname);
2460 2461 return (ret);
2461 2462 }
2462 2463
2463 2464 /*
2464 2465 * Protocol management functions
2465 2466 *
2466 2467 * Properties defined in the default files are defined in
2467 2468 * proto_option_defs for parsing and validation. If "other" and
2468 2469 * "compare" are set, then the value for this property should be
2469 2470 * compared against the property specified in "other" using the
2470 2471 * "compare" check (either <= or >=) in order to ensure that the
2471 2472 * values are in the correct range. E.g. setting server_versmin
2472 2473 * higher than server_versmax should not be allowed.
2473 2474 */
2474 2475
2475 2476 struct proto_option_defs {
2476 2477 char *tag;
2477 2478 char *name; /* display name -- remove protocol identifier */
2478 2479 int index;
2479 2480 int type;
2480 2481 union {
2481 2482 int intval;
2482 2483 char *string;
2483 2484 } defvalue;
2484 2485 uint32_t svcs;
2485 2486 int32_t minval;
2486 2487 int32_t maxval;
2487 2488 char *other;
2488 2489 int compare;
2489 2490 #define OPT_CMP_GE 0
2490 2491 #define OPT_CMP_LE 1
2491 2492 int (*check)(char *);
2492 2493 } proto_options[] = {
2493 2494 #define PROTO_OPT_NFSD_SERVERS 0
2494 2495 {"nfsd_servers",
2495 2496 "servers", PROTO_OPT_NFSD_SERVERS, OPT_TYPE_NUMBER, 1024, SVC_NFSD,
2496 2497 1, INT32_MAX},
2497 2498 #define PROTO_OPT_LOCKD_LISTEN_BACKLOG 1
2498 2499 {"lockd_listen_backlog",
2499 2500 "lockd_listen_backlog", PROTO_OPT_LOCKD_LISTEN_BACKLOG,
2500 2501 OPT_TYPE_NUMBER, 32, SVC_LOCKD, 32, INT32_MAX},
2501 2502 #define PROTO_OPT_LOCKD_SERVERS 2
2502 2503 {"lockd_servers",
2503 2504 "lockd_servers", PROTO_OPT_LOCKD_SERVERS, OPT_TYPE_NUMBER, 256,
2504 2505 SVC_LOCKD, 1, INT32_MAX},
2505 2506 #define PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT 3
2506 2507 {"lockd_retransmit_timeout",
2507 2508 "lockd_retransmit_timeout", PROTO_OPT_LOCKD_RETRANSMIT_TIMEOUT,
2508 2509 OPT_TYPE_NUMBER, 5, SVC_LOCKD, 0, INT32_MAX},
2509 2510 #define PROTO_OPT_GRACE_PERIOD 4
2510 2511 {"grace_period",
2511 2512 "grace_period", PROTO_OPT_GRACE_PERIOD, OPT_TYPE_NUMBER, 90,
2512 2513 SVC_LOCKD, 0, INT32_MAX},
2513 2514 #define PROTO_OPT_NFS_SERVER_VERSMIN 5
2514 2515 {"nfs_server_versmin",
2515 2516 "server_versmin", PROTO_OPT_NFS_SERVER_VERSMIN, OPT_TYPE_NUMBER,
2516 2517 (int)NFS_VERSMIN_DEFAULT, SVC_NFSD|SVC_MOUNTD, NFS_VERSMIN,
2517 2518 NFS_VERSMAX, "server_versmax", OPT_CMP_LE},
2518 2519 #define PROTO_OPT_NFS_SERVER_VERSMAX 6
2519 2520 {"nfs_server_versmax",
2520 2521 "server_versmax", PROTO_OPT_NFS_SERVER_VERSMAX, OPT_TYPE_NUMBER,
2521 2522 (int)NFS_VERSMAX_DEFAULT, SVC_NFSD|SVC_MOUNTD, NFS_VERSMIN,
2522 2523 NFS_VERSMAX, "server_versmin", OPT_CMP_GE},
2523 2524 #define PROTO_OPT_NFS_CLIENT_VERSMIN 7
2524 2525 {"nfs_client_versmin",
2525 2526 "client_versmin", PROTO_OPT_NFS_CLIENT_VERSMIN, OPT_TYPE_NUMBER,
2526 2527 (int)NFS_VERSMIN_DEFAULT, SVC_CLIENT, NFS_VERSMIN, NFS_VERSMAX,
2527 2528 "client_versmax", OPT_CMP_LE},
2528 2529 #define PROTO_OPT_NFS_CLIENT_VERSMAX 8
2529 2530 {"nfs_client_versmax",
2530 2531 "client_versmax", PROTO_OPT_NFS_CLIENT_VERSMAX, OPT_TYPE_NUMBER,
2531 2532 (int)NFS_VERSMAX_DEFAULT, SVC_CLIENT, NFS_VERSMIN, NFS_VERSMAX,
2532 2533 "client_versmin", OPT_CMP_GE},
2533 2534 #define PROTO_OPT_NFS_SERVER_DELEGATION 9
2534 2535 {"nfs_server_delegation",
2535 2536 "server_delegation", PROTO_OPT_NFS_SERVER_DELEGATION,
2536 2537 OPT_TYPE_ONOFF, NFS_SERVER_DELEGATION_DEFAULT, SVC_NFSD, 0, 0},
2537 2538 #define PROTO_OPT_NFSMAPID_DOMAIN 10
2538 2539 {"nfsmapid_domain",
2539 2540 "nfsmapid_domain", PROTO_OPT_NFSMAPID_DOMAIN, OPT_TYPE_DOMAIN,
2540 2541 NULL, SVC_NFSMAPID, 0, 0},
2541 2542 #define PROTO_OPT_NFSD_MAX_CONNECTIONS 11
2542 2543 {"nfsd_max_connections",
2543 2544 "max_connections", PROTO_OPT_NFSD_MAX_CONNECTIONS,
2544 2545 OPT_TYPE_NUMBER, -1, SVC_NFSD, -1, INT32_MAX},
2545 2546 #define PROTO_OPT_NFSD_PROTOCOL 12
2546 2547 {"nfsd_protocol",
2547 2548 "protocol", PROTO_OPT_NFSD_PROTOCOL, OPT_TYPE_PROTOCOL, 0,
2548 2549 SVC_NFSD, 0, 0},
2549 2550 #define PROTO_OPT_NFSD_LISTEN_BACKLOG 13
2550 2551 {"nfsd_listen_backlog",
2551 2552 "listen_backlog", PROTO_OPT_NFSD_LISTEN_BACKLOG,
2552 2553 OPT_TYPE_NUMBER, 0, SVC_NFSD, 0, INT32_MAX},
2553 2554 #define PROTO_OPT_NFSD_DEVICE 14
2554 2555 {"nfsd_device",
↓ open down ↓ |
2520 lines elided |
↑ open up ↑ |
2555 2556 "device", PROTO_OPT_NFSD_DEVICE,
2556 2557 OPT_TYPE_STRING, NULL, SVC_NFSD, 0, 0},
2557 2558 #define PROTO_OPT_MOUNTD_LISTEN_BACKLOG 15
2558 2559 {"mountd_listen_backlog",
2559 2560 "mountd_listen_backlog", PROTO_OPT_MOUNTD_LISTEN_BACKLOG,
2560 2561 OPT_TYPE_NUMBER, 64, SVC_NFSD|SVC_MOUNTD, 1, INT32_MAX},
2561 2562 #define PROTO_OPT_MOUNTD_MAX_THREADS 16
2562 2563 {"mountd_max_threads",
2563 2564 "mountd_max_threads", PROTO_OPT_MOUNTD_MAX_THREADS,
2564 2565 OPT_TYPE_NUMBER, 16, SVC_NFSD|SVC_MOUNTD, 1, INT32_MAX},
2566 +#define PROTO_OPT_MOUNTD_PORT 17
2567 + {"mountd_port",
2568 + "mountd_port", PROTO_OPT_MOUNTD_PORT,
2569 + OPT_TYPE_NUMBER, 0, SVC_MOUNTD, 1, UINT16_MAX},
2570 +#define PROTO_OPT_STATD_PORT 18
2571 + {"statd_port",
2572 + "statd_port", PROTO_OPT_STATD_PORT,
2573 + OPT_TYPE_NUMBER, 0, SVC_STATD, 1, UINT16_MAX},
2565 2574 {NULL}
2566 2575 };
2567 2576
2568 2577 /*
2569 2578 * the protoset holds the defined options so we don't have to read
2570 2579 * them multiple times
2571 2580 */
2572 2581 static sa_protocol_properties_t protoset;
2573 2582
2574 2583 static int
2575 2584 findprotoopt(char *name, int whichname)
2576 2585 {
2577 2586 int i;
2578 2587 for (i = 0; proto_options[i].tag != NULL; i++) {
2579 2588 if (whichname == 1) {
2580 2589 if (strcasecmp(proto_options[i].name, name) == 0)
2581 2590 return (i);
2582 2591 } else {
2583 2592 if (strcasecmp(proto_options[i].tag, name) == 0)
2584 2593 return (i);
2585 2594 }
2586 2595 }
2587 2596 return (-1);
2588 2597 }
2589 2598
2590 2599 /*
2591 2600 * fixcaselower(str)
2592 2601 *
2593 2602 * convert a string to lower case (inplace).
2594 2603 */
2595 2604
2596 2605 static void
2597 2606 fixcaselower(char *str)
2598 2607 {
2599 2608 while (*str) {
2600 2609 *str = tolower(*str);
2601 2610 str++;
2602 2611 }
2603 2612 }
2604 2613
2605 2614 /*
2606 2615 * skipwhitespace(str)
2607 2616 *
2608 2617 * Skip leading white space. It is assumed that it is called with a
2609 2618 * valid pointer.
2610 2619 */
2611 2620
2612 2621 static char *
2613 2622 skipwhitespace(char *str)
2614 2623 {
2615 2624 while (*str && isspace(*str))
2616 2625 str++;
2617 2626
2618 2627 return (str);
2619 2628 }
2620 2629
2621 2630 /*
2622 2631 * extractprop()
2623 2632 *
2624 2633 * Extract the property and value out of the line and create the
2625 2634 * property in the optionset.
2626 2635 */
2627 2636 static int
2628 2637 extractprop(char *name, char *value)
2629 2638 {
2630 2639 sa_property_t prop;
2631 2640 int index;
2632 2641 int ret = SA_OK;
2633 2642 /*
2634 2643 * Remove any leading
2635 2644 * white space.
2636 2645 */
2637 2646 name = skipwhitespace(name);
2638 2647
2639 2648 index = findprotoopt(name, 1);
2640 2649 if (index >= 0) {
2641 2650 fixcaselower(name);
2642 2651 prop = sa_create_property(proto_options[index].name, value);
2643 2652 if (prop != NULL)
2644 2653 ret = sa_add_protocol_property(protoset, prop);
2645 2654 else
2646 2655 ret = SA_NO_MEMORY;
2647 2656 }
2648 2657 return (ret);
2649 2658 }
2650 2659
2651 2660 scf_type_t
2652 2661 getscftype(int type)
2653 2662 {
2654 2663 scf_type_t ret;
2655 2664
2656 2665 switch (type) {
2657 2666 case OPT_TYPE_NUMBER:
2658 2667 ret = SCF_TYPE_INTEGER;
2659 2668 break;
2660 2669 case OPT_TYPE_BOOLEAN:
2661 2670 ret = SCF_TYPE_BOOLEAN;
2662 2671 break;
2663 2672 default:
2664 2673 ret = SCF_TYPE_ASTRING;
2665 2674 }
2666 2675 return (ret);
2667 2676 }
2668 2677
2669 2678 char *
2670 2679 getsvcname(uint32_t svcs)
2671 2680 {
2672 2681 char *service;
2673 2682 switch (svcs) {
2674 2683 case SVC_LOCKD:
2675 2684 service = LOCKD;
2676 2685 break;
2677 2686 case SVC_STATD:
2678 2687 service = STATD;
2679 2688 break;
2680 2689 case SVC_NFSD:
2681 2690 service = NFSD;
2682 2691 break;
2683 2692 case SVC_CLIENT:
2684 2693 service = NFS_CLIENT_SVC;
2685 2694 break;
2686 2695 case SVC_NFS4CBD:
2687 2696 service = NFS4CBD;
2688 2697 break;
2689 2698 case SVC_NFSMAPID:
2690 2699 service = NFSMAPID;
2691 2700 break;
2692 2701 case SVC_RQUOTAD:
2693 2702 service = RQUOTAD;
2694 2703 break;
2695 2704 case SVC_NFSLOGD:
2696 2705 service = NFSLOGD;
2697 2706 break;
2698 2707 case SVC_REPARSED:
2699 2708 service = REPARSED;
2700 2709 break;
2701 2710 default:
2702 2711 service = NFSD;
2703 2712 }
2704 2713 return (service);
2705 2714 }
2706 2715
2707 2716 /*
2708 2717 * initprotofromsmf()
2709 2718 *
2710 2719 * Read NFS SMF properties and add the defined values to the
2711 2720 * protoset. Note that default values are known from the built in
2712 2721 * table in case SMF doesn't have a definition. Not having
2713 2722 * SMF properties is OK since we have builtin default
2714 2723 * values.
2715 2724 */
2716 2725 static int
2717 2726 initprotofromsmf()
2718 2727 {
2719 2728 char name[PATH_MAX];
2720 2729 char value[PATH_MAX];
2721 2730 int ret = SA_OK, bufsz = 0, i;
2722 2731
2723 2732 protoset = sa_create_protocol_properties("nfs");
2724 2733 if (protoset != NULL) {
2725 2734 for (i = 0; proto_options[i].tag != NULL; i++) {
2726 2735 scf_type_t ptype;
2727 2736 char *svc_name;
2728 2737
2729 2738 bzero(value, PATH_MAX);
2730 2739 (void) strncpy(name, proto_options[i].name, PATH_MAX);
2731 2740 /* Replace NULL with the correct instance */
2732 2741 ptype = getscftype(proto_options[i].type);
2733 2742 svc_name = getsvcname(proto_options[i].svcs);
2734 2743 bufsz = PATH_MAX;
2735 2744 ret = nfs_smf_get_prop(name, value,
2736 2745 (char *)DEFAULT_INSTANCE, ptype,
2737 2746 svc_name, &bufsz);
2738 2747 if (ret == SA_OK) {
2739 2748 ret = extractprop(name, value);
2740 2749 }
2741 2750 }
2742 2751 } else {
2743 2752 ret = SA_NO_MEMORY;
2744 2753 }
2745 2754
2746 2755 return (ret);
2747 2756 }
2748 2757
2749 2758 /*
2750 2759 * add_defaults()
2751 2760 *
2752 2761 * Add the default values for any property not defined
2753 2762 * in NFS SMF repository.
2754 2763 * Values are set according to their defined types.
2755 2764 */
2756 2765
2757 2766 static void
2758 2767 add_defaults()
2759 2768 {
2760 2769 int i;
2761 2770 char number[MAXDIGITS];
2762 2771
2763 2772 for (i = 0; proto_options[i].tag != NULL; i++) {
2764 2773 sa_property_t prop;
2765 2774 prop = sa_get_protocol_property(protoset,
2766 2775 proto_options[i].name);
2767 2776 if (prop == NULL) {
2768 2777 /* add the default value */
2769 2778 switch (proto_options[i].type) {
2770 2779 case OPT_TYPE_NUMBER:
2771 2780 (void) snprintf(number, sizeof (number), "%d",
2772 2781 proto_options[i].defvalue.intval);
2773 2782 prop = sa_create_property(proto_options[i].name,
2774 2783 number);
2775 2784 break;
2776 2785
2777 2786 case OPT_TYPE_BOOLEAN:
2778 2787 prop = sa_create_property(proto_options[i].name,
2779 2788 proto_options[i].defvalue.intval ?
2780 2789 "true" : "false");
2781 2790 break;
2782 2791
2783 2792 case OPT_TYPE_ONOFF:
2784 2793 prop = sa_create_property(proto_options[i].name,
2785 2794 proto_options[i].defvalue.intval ?
2786 2795 "on" : "off");
2787 2796 break;
2788 2797
2789 2798 default:
2790 2799 /* treat as strings of zero length */
2791 2800 prop = sa_create_property(proto_options[i].name,
2792 2801 "");
2793 2802 break;
2794 2803 }
2795 2804 if (prop != NULL)
2796 2805 (void) sa_add_protocol_property(protoset, prop);
2797 2806 }
2798 2807 }
2799 2808 }
2800 2809
2801 2810 static void
2802 2811 free_protoprops()
2803 2812 {
2804 2813 if (protoset != NULL) {
2805 2814 xmlFreeNode(protoset);
2806 2815 protoset = NULL;
2807 2816 }
2808 2817 }
2809 2818
2810 2819 /*
2811 2820 * nfs_init()
2812 2821 *
2813 2822 * Initialize the NFS plugin.
2814 2823 */
2815 2824
2816 2825 static int
2817 2826 nfs_init()
2818 2827 {
2819 2828 int ret = SA_OK;
2820 2829
2821 2830 if (sa_plugin_ops.sa_init != nfs_init) {
2822 2831 (void) printf(dgettext(TEXT_DOMAIN,
2823 2832 "NFS plugin not properly initialized\n"));
2824 2833 return (SA_CONFIG_ERR);
2825 2834 }
2826 2835
2827 2836 ret = initprotofromsmf();
2828 2837 if (ret != SA_OK) {
2829 2838 (void) printf(dgettext(TEXT_DOMAIN,
2830 2839 "NFS plugin problem with SMF repository: %s\n"),
2831 2840 sa_errorstr(ret));
2832 2841 ret = SA_OK;
2833 2842 }
2834 2843 add_defaults();
2835 2844
2836 2845 return (ret);
2837 2846 }
2838 2847
2839 2848 /*
2840 2849 * nfs_fini()
2841 2850 *
2842 2851 * uninitialize the NFS plugin. Want to avoid memory leaks.
2843 2852 */
2844 2853
2845 2854 static void
2846 2855 nfs_fini()
2847 2856 {
2848 2857 free_protoprops();
2849 2858 }
2850 2859
2851 2860 /*
2852 2861 * nfs_get_proto_set()
2853 2862 *
2854 2863 * Return an optionset with all the protocol specific properties in
2855 2864 * it.
2856 2865 */
2857 2866
2858 2867 static sa_protocol_properties_t
2859 2868 nfs_get_proto_set()
2860 2869 {
2861 2870 return (protoset);
2862 2871 }
2863 2872
2864 2873 /*
2865 2874 * service_in_state(service, chkstate)
2866 2875 *
2867 2876 * Want to know if the specified service is in the desired state
2868 2877 * (chkstate) or not. Return true (1) if it is and false (0) if it
2869 2878 * isn't.
2870 2879 */
2871 2880 static int
2872 2881 service_in_state(char *service, const char *chkstate)
2873 2882 {
2874 2883 char *state;
2875 2884 int ret = B_FALSE;
2876 2885
2877 2886 state = smf_get_state(service);
2878 2887 if (state != NULL) {
2879 2888 /* got the state so get the equality for the return value */
2880 2889 ret = strcmp(state, chkstate) == 0 ? B_TRUE : B_FALSE;
2881 2890 free(state);
2882 2891 }
2883 2892 return (ret);
2884 2893 }
2885 2894
2886 2895 /*
2887 2896 * restart_service(svcs)
2888 2897 *
2889 2898 * Walk through the bit mask of services that need to be restarted in
2890 2899 * order to use the new property values. Some properties affect
2891 2900 * multiple daemons. Should only restart a service if it is currently
2892 2901 * enabled (online).
2893 2902 */
2894 2903
2895 2904 static void
2896 2905 restart_service(uint32_t svcs)
2897 2906 {
2898 2907 uint32_t mask;
2899 2908 int ret;
2900 2909 char *service;
2901 2910
2902 2911 for (mask = 1; svcs != 0; mask <<= 1) {
2903 2912 switch (svcs & mask) {
2904 2913 case SVC_LOCKD:
2905 2914 service = LOCKD;
2906 2915 break;
2907 2916 case SVC_STATD:
2908 2917 service = STATD;
2909 2918 break;
2910 2919 case SVC_NFSD:
2911 2920 service = NFSD;
2912 2921 break;
2913 2922 case SVC_MOUNTD:
2914 2923 service = MOUNTD;
2915 2924 break;
2916 2925 case SVC_NFS4CBD:
2917 2926 service = NFS4CBD;
2918 2927 break;
2919 2928 case SVC_NFSMAPID:
2920 2929 service = NFSMAPID;
2921 2930 break;
2922 2931 case SVC_RQUOTAD:
2923 2932 service = RQUOTAD;
2924 2933 break;
2925 2934 case SVC_NFSLOGD:
2926 2935 service = NFSLOGD;
2927 2936 break;
2928 2937 case SVC_REPARSED:
2929 2938 service = REPARSED;
2930 2939 break;
2931 2940 case SVC_CLIENT:
2932 2941 service = NFS_CLIENT_SVC;
2933 2942 break;
2934 2943 default:
2935 2944 continue;
2936 2945 }
2937 2946
2938 2947 /*
2939 2948 * Only attempt to restart the service if it is
2940 2949 * currently running. In the future, it may be
2941 2950 * desirable to use smf_refresh_instance if the NFS
2942 2951 * services ever implement the refresh method.
2943 2952 */
2944 2953 if (service_in_state(service, SCF_STATE_STRING_ONLINE)) {
2945 2954 ret = smf_restart_instance(service);
2946 2955 /*
2947 2956 * There are only a few SMF errors at this point, but
2948 2957 * it is also possible that a bad value may have put
2949 2958 * the service into maintenance if there wasn't an
2950 2959 * SMF level error.
2951 2960 */
2952 2961 if (ret != 0) {
2953 2962 (void) fprintf(stderr,
2954 2963 dgettext(TEXT_DOMAIN,
2955 2964 "%s failed to restart: %s\n"),
2956 2965 service, scf_strerror(scf_error()));
2957 2966 } else {
2958 2967 /*
2959 2968 * Check whether it has gone to "maintenance"
2960 2969 * mode or not. Maintenance implies something
2961 2970 * went wrong.
2962 2971 */
2963 2972 if (service_in_state(service,
2964 2973 SCF_STATE_STRING_MAINT)) {
2965 2974 (void) fprintf(stderr,
2966 2975 dgettext(TEXT_DOMAIN,
2967 2976 "%s failed to restart\n"),
2968 2977 service);
2969 2978 }
2970 2979 }
2971 2980 }
2972 2981 svcs &= ~mask;
2973 2982 }
2974 2983 }
2975 2984
2976 2985 /*
2977 2986 * nfs_minmax_check(name, value)
2978 2987 *
2979 2988 * Verify that the value for the property specified by index is valid
2980 2989 * relative to the opposite value in the case of a min/max variable.
2981 2990 * Currently, server_minvers/server_maxvers and
2982 2991 * client_minvers/client_maxvers are the only ones to check.
2983 2992 */
2984 2993
2985 2994 static int
2986 2995 nfs_minmax_check(int index, int value)
2987 2996 {
2988 2997 int val;
2989 2998 char *pval;
2990 2999 sa_property_t prop;
2991 3000 sa_optionset_t opts;
2992 3001 int ret = B_TRUE;
2993 3002
2994 3003 if (proto_options[index].other != NULL) {
2995 3004 /* have a property to compare against */
2996 3005 opts = nfs_get_proto_set();
2997 3006 prop = sa_get_property(opts, proto_options[index].other);
2998 3007 /*
2999 3008 * If we don't find the property, assume default
3000 3009 * values which will work since the max will be at the
3001 3010 * max and the min at the min.
3002 3011 */
3003 3012 if (prop != NULL) {
3004 3013 pval = sa_get_property_attr(prop, "value");
3005 3014 if (pval != NULL) {
3006 3015 val = strtoul(pval, NULL, 0);
3007 3016 if (proto_options[index].compare ==
3008 3017 OPT_CMP_LE) {
3009 3018 ret = value <= val ? B_TRUE : B_FALSE;
3010 3019 } else if (proto_options[index].compare ==
3011 3020 OPT_CMP_GE) {
3012 3021 ret = value >= val ? B_TRUE : B_FALSE;
3013 3022 }
3014 3023 sa_free_attr_string(pval);
3015 3024 }
3016 3025 }
3017 3026 }
3018 3027 return (ret);
3019 3028 }
3020 3029
3021 3030 /*
3022 3031 * nfs_validate_proto_prop(index, name, value)
3023 3032 *
3024 3033 * Verify that the property specified by name can take the new
3025 3034 * value. This is a sanity check to prevent bad values getting into
3026 3035 * the default files. All values need to be checked against what is
3027 3036 * allowed by their defined type. If a type isn't explicitly defined
3028 3037 * here, it is treated as a string.
3029 3038 *
3030 3039 * Note that OPT_TYPE_NUMBER will additionally check that the value is
3031 3040 * within the range specified and potentially against another property
3032 3041 * value as well as specified in the proto_options members other and
3033 3042 * compare.
3034 3043 */
3035 3044
3036 3045 static int
3037 3046 nfs_validate_proto_prop(int index, char *name, char *value)
3038 3047 {
3039 3048 int ret = SA_OK;
3040 3049 char *cp;
3041 3050 #ifdef lint
3042 3051 name = name;
3043 3052 #endif
3044 3053 switch (proto_options[index].type) {
3045 3054 case OPT_TYPE_NUMBER:
3046 3055 if (!is_a_number(value))
3047 3056 ret = SA_BAD_VALUE;
3048 3057 else {
3049 3058 int val;
3050 3059 val = strtoul(value, NULL, 0);
3051 3060 if (val < proto_options[index].minval ||
3052 3061 val > proto_options[index].maxval)
3053 3062 ret = SA_BAD_VALUE;
3054 3063 /*
3055 3064 * For server_versmin/server_versmax and
3056 3065 * client_versmin/client_versmax, the value of the
3057 3066 * min(max) should be checked to be correct relative
3058 3067 * to the current max(min).
3059 3068 */
3060 3069 if (!nfs_minmax_check(index, val)) {
3061 3070 ret = SA_BAD_VALUE;
3062 3071 }
3063 3072 }
3064 3073 break;
3065 3074
3066 3075 case OPT_TYPE_DOMAIN:
3067 3076 /*
3068 3077 * needs to be a qualified domain so will have at
3069 3078 * least one period and other characters on either
3070 3079 * side of it. A zero length string is also allowed
3071 3080 * and is the way to turn off the override.
3072 3081 */
3073 3082 if (strlen(value) == 0)
3074 3083 break;
3075 3084 cp = strchr(value, '.');
3076 3085 if (cp == NULL || cp == value || strchr(value, '@') != NULL)
3077 3086 ret = SA_BAD_VALUE;
3078 3087 break;
3079 3088
3080 3089 case OPT_TYPE_BOOLEAN:
3081 3090 if (strlen(value) == 0 ||
3082 3091 strcasecmp(value, "true") == 0 ||
3083 3092 strcmp(value, "1") == 0 ||
3084 3093 strcasecmp(value, "false") == 0 ||
3085 3094 strcmp(value, "0") == 0) {
3086 3095 ret = SA_OK;
3087 3096 } else {
3088 3097 ret = SA_BAD_VALUE;
3089 3098 }
3090 3099 break;
3091 3100
3092 3101 case OPT_TYPE_ONOFF:
3093 3102 if (strcasecmp(value, "on") != 0 &&
3094 3103 strcasecmp(value, "off") != 0) {
3095 3104 ret = SA_BAD_VALUE;
3096 3105 }
3097 3106 break;
3098 3107
3099 3108 case OPT_TYPE_PROTOCOL: {
3100 3109 struct netconfig *nconf;
3101 3110 void *nc;
3102 3111 boolean_t pfound = B_FALSE;
3103 3112
3104 3113 if (strcasecmp(value, "all") == 0)
3105 3114 break;
3106 3115
3107 3116 if ((nc = setnetconfig()) == NULL) {
3108 3117 (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
3109 3118 "setnetconfig failed: %s\n"), strerror(errno));
3110 3119 } else {
3111 3120 while ((nconf = getnetconfig(nc)) != NULL) {
3112 3121 if (strcmp(nconf->nc_proto, value) == 0) {
3113 3122 pfound = B_TRUE;
3114 3123 break;
3115 3124 }
3116 3125 }
3117 3126 (void) endnetconfig(nc);
3118 3127 }
3119 3128
3120 3129 if (!pfound)
3121 3130 ret = SA_BAD_VALUE;
3122 3131 break;
3123 3132 }
3124 3133
3125 3134 default:
3126 3135 /* treat as a string */
3127 3136 break;
3128 3137 }
3129 3138 return (ret);
3130 3139 }
3131 3140
3132 3141 /*
3133 3142 * nfs_set_proto_prop(prop)
3134 3143 *
3135 3144 * check that prop is valid.
3136 3145 */
3137 3146
3138 3147 static int
3139 3148 nfs_set_proto_prop(sa_property_t prop)
3140 3149 {
3141 3150 int ret = SA_OK;
3142 3151 char *name;
3143 3152 char *value;
3144 3153
3145 3154 name = sa_get_property_attr(prop, "type");
3146 3155 value = sa_get_property_attr(prop, "value");
3147 3156 if (name != NULL && value != NULL) {
3148 3157 scf_type_t sctype;
3149 3158 char *svc_name;
3150 3159 char *instance = NULL;
3151 3160 int index = findprotoopt(name, 1);
3152 3161
3153 3162 ret = nfs_validate_proto_prop(index, name, value);
3154 3163 if (ret == SA_OK) {
3155 3164 sctype = getscftype(proto_options[index].type);
3156 3165 svc_name = getsvcname(proto_options[index].svcs);
3157 3166 if (sctype == SCF_TYPE_BOOLEAN) {
3158 3167 if (value != NULL)
3159 3168 sa_free_attr_string(value);
3160 3169 if (string_to_boolean(value) == 0)
3161 3170 value = strdup("0");
3162 3171 else
3163 3172 value = strdup("1");
3164 3173 }
3165 3174 ret = nfs_smf_set_prop(name, value, instance, sctype,
3166 3175 svc_name);
3167 3176 if (ret == SA_OK) {
3168 3177 restart_service(proto_options[index].svcs);
3169 3178 } else {
3170 3179 (void) printf(dgettext(TEXT_DOMAIN,
3171 3180 "Cannot restart NFS services : %s\n"),
3172 3181 sa_errorstr(ret));
3173 3182 }
3174 3183 }
3175 3184 }
3176 3185 if (name != NULL)
3177 3186 sa_free_attr_string(name);
3178 3187 if (value != NULL)
3179 3188 sa_free_attr_string(value);
3180 3189 return (ret);
3181 3190 }
3182 3191
3183 3192 /*
3184 3193 * nfs_get_status()
3185 3194 *
3186 3195 * What is the current status of the nfsd? We use the SMF state here.
3187 3196 * Caller must free the returned value.
3188 3197 */
3189 3198
3190 3199 static char *
3191 3200 nfs_get_status()
3192 3201 {
3193 3202 return (smf_get_state(NFSD));
3194 3203 }
3195 3204
3196 3205 /*
3197 3206 * nfs_space_alias(alias)
3198 3207 *
3199 3208 * Lookup the space (security) name. If it is default, convert to the
3200 3209 * real name.
3201 3210 */
3202 3211
3203 3212 static char *
3204 3213 nfs_space_alias(char *space)
3205 3214 {
3206 3215 char *name = space;
3207 3216 seconfig_t secconf;
3208 3217
3209 3218 /*
3210 3219 * Only the space named "default" is special. If it is used,
3211 3220 * the default needs to be looked up and the real name used.
3212 3221 * This is normally "sys" but could be changed. We always
3213 3222 * change default to the real name.
3214 3223 */
3215 3224 if (strcmp(space, "default") == 0 &&
3216 3225 nfs_getseconfig_default(&secconf) == 0) {
3217 3226 if (nfs_getseconfig_bynumber(secconf.sc_nfsnum, &secconf) == 0)
3218 3227 name = secconf.sc_name;
3219 3228 }
3220 3229 return (strdup(name));
3221 3230 }
3222 3231
3223 3232 /*
3224 3233 * nfs_features()
3225 3234 *
3226 3235 * Return a mask of the features required.
3227 3236 */
3228 3237
3229 3238 static uint64_t
3230 3239 nfs_features()
3231 3240 {
3232 3241 return ((uint64_t)SA_FEATURE_DFSTAB | SA_FEATURE_SERVER);
3233 3242 }
↓ open down ↓ |
659 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX