Print this page
NEX-14666 Need to provide SMB 2.1 Client
NEX-17187 panic in smbfs_acl_store
NEX-17231 smbfs create xattr files finds wrong file
NEX-17224 smbfs lookup EINVAL should be ENOENT
NEX-17260 SMB1 client fails to list directory after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
and: (cleanup)
NEX-16818 Add fksmbcl development tool
NEX-17264 SMB client test tp_smbutil_013 fails after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (fix ref leaks)
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libsmbfs/smb/rcfile.c
+++ new/usr/src/lib/libsmbfs/smb/rcfile.c
1 1 /*
2 2 * Copyright (c) 2000, Boris Popov
3 3 * All rights reserved.
4 4 *
5 5 * Redistribution and use in source and binary forms, with or without
6 6 * modification, are permitted provided that the following conditions
7 7 * are met:
8 8 * 1. Redistributions of source code must retain the above copyright
9 9 * notice, this list of conditions and the following disclaimer.
10 10 * 2. Redistributions in binary form must reproduce the above copyright
11 11 * notice, this list of conditions and the following disclaimer in the
12 12 * documentation and/or other materials provided with the distribution.
13 13 * 3. All advertising materials mentioning features or use of this software
14 14 * must display the following acknowledgement:
15 15 * This product includes software developed by Boris Popov.
16 16 * 4. Neither the name of the author nor the names of any co-contributors
17 17 * may be used to endorse or promote products derived from this software
18 18 * without specific prior written permission.
19 19 *
20 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
24 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 30 * SUCH DAMAGE.
31 31 *
32 32 * $Id: rcfile.c,v 1.1.1.2 2001/07/06 22:38:43 conrad Exp $
33 33 */
34 +/*
35 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
36 + */
34 37
35 38 #include <fcntl.h>
36 39 #include <sys/types.h>
37 40 #include <sys/queue.h>
38 41 #include <sys/stat.h>
39 42
40 43 #include <ctype.h>
41 44 #include <errno.h>
42 45 #include <stdio.h>
43 46 #include <string.h>
44 47 #include <strings.h>
45 48 #include <stdlib.h>
46 49 #include <synch.h>
47 50 #include <unistd.h>
48 51 #include <pwd.h>
49 52 #include <libintl.h>
|
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
50 53
51 54 #include <cflib.h>
52 55 #include "rcfile_priv.h"
53 56
54 57 #include <assert.h>
55 58
56 59 #if 0 /* before SMF */
57 60 #define SMB_CFG_FILE "/etc/nsmb.conf"
58 61 #define OLD_SMB_CFG_FILE "/usr/local/etc/nsmb.conf"
59 62 #endif
60 -#define SMBFS_SHARECTL_CMD "/usr/sbin/sharectl get smbfs"
61 63
62 64 extern int smb_debug;
63 65
64 66 static struct rcfile *rc_cachelookup(const char *filename);
65 67 static struct rcsection *rc_findsect(struct rcfile *rcp, const char *sectname);
66 68 static struct rcsection *rc_addsect(struct rcfile *rcp, const char *sectname);
67 69 static int rc_freesect(struct rcfile *rcp, struct rcsection *rsp);
68 70 static struct rckey *rc_sect_findkey(struct rcsection *rsp, const char *key);
69 71 static struct rckey *rc_sect_addkey(struct rcsection *rsp, const char *name,
70 72 const char *value);
71 73 static void rc_key_free(struct rckey *p);
72 74 static void rc_parse(struct rcfile *rcp);
73 75
74 76 /* lock for the variables below */
75 77 mutex_t rcfile_mutex = DEFAULTMUTEX;
76 78
77 79 SLIST_HEAD(rcfile_head, rcfile);
78 80 static struct rcfile_head pf_head = {NULL};
79 81 struct rcfile *smb_rc;
80 82 int home_nsmbrc;
81 83 int insecure_nsmbrc;
82 84
83 85 /*
84 86 * open rcfile and load its content, if already open - return previous handle
85 87 */
86 88 static int
87 89 rc_open(const char *filename, const char *mode, struct rcfile **rcfile)
88 90 {
89 91 struct stat statbuf;
90 92 struct rcfile *rcp;
91 93 FILE *f;
92 94
93 95 assert(MUTEX_HELD(&rcfile_mutex));
94 96
95 97 rcp = rc_cachelookup(filename);
96 98 if (rcp) {
97 99 *rcfile = rcp;
98 100 return (0);
99 101 }
100 102 f = fopen(filename, mode);
101 103 if (f == NULL)
102 104 return (errno);
103 105 insecure_nsmbrc = 0;
104 106 if (fstat(fileno(f), &statbuf) >= 0 &&
105 107 (statbuf.st_mode & 077) != 0)
106 108 insecure_nsmbrc = 1;
107 109 rcp = malloc(sizeof (struct rcfile));
108 110 if (rcp == NULL) {
109 111 fclose(f);
110 112 return (ENOMEM);
111 113 }
112 114 bzero(rcp, sizeof (struct rcfile));
113 115 rcp->rf_name = strdup(filename);
114 116 rcp->rf_f = f;
115 117 SLIST_INSERT_HEAD(&pf_head, rcp, rf_next);
116 118 rc_parse(rcp);
117 119 *rcfile = rcp;
118 120 return (0);
119 121 }
120 122
121 123 static int
122 124 rc_merge(const char *filename, struct rcfile **rcfile)
123 125 {
124 126 struct stat statbuf;
125 127 struct rcfile *rcp = *rcfile;
126 128 FILE *f, *t;
127 129
128 130 assert(MUTEX_HELD(&rcfile_mutex));
129 131
130 132 insecure_nsmbrc = 0;
131 133 if (rcp == NULL) {
132 134 return (rc_open(filename, "r", rcfile));
133 135 }
134 136 f = fopen(filename, "r");
135 137 if (f == NULL)
136 138 return (errno);
137 139 insecure_nsmbrc = 0;
138 140 if (fstat(fileno(f), &statbuf) >= 0 &&
139 141 (statbuf.st_mode & 077) != 0)
|
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
140 142 insecure_nsmbrc = 1;
141 143 t = rcp->rf_f;
142 144 rcp->rf_f = f;
143 145 rc_parse(rcp);
144 146 rcp->rf_f = t;
145 147 fclose(f);
146 148 return (0);
147 149 }
148 150
149 151 /*
150 - * Like rc_open, but does popen of command:
151 - * sharectl get smbfs
152 + * Like rc_open, but creates a temporary file and
153 + * reads the sharectl settings into it.
154 + * The file is deleted when we close it.
152 155 */
153 156 static int
154 -rc_popen_cmd(const char *command, struct rcfile **rcfile)
157 +rc_open_sharectl(struct rcfile **rcfile)
155 158 {
156 - struct rcfile *rcp;
157 - FILE *f;
159 + static char template[24] = "/tmp/smbfsXXXXXX";
160 + struct rcfile *rcp = NULL;
161 + FILE *fp = NULL;
162 + int err;
163 + int fd = -1;
158 164
159 165 assert(MUTEX_HELD(&rcfile_mutex));
160 166
161 - f = popen(command, "r");
162 - if (f == NULL)
163 - return (errno);
164 - insecure_nsmbrc = 0;
167 + fd = mkstemp(template);
168 + if (fd < 0) {
169 + err = errno;
170 + goto errout;
171 + }
165 172
173 + fp = fdopen(fd, "w+");
174 + if (fp == NULL) {
175 + err = errno;
176 + close(fd);
177 + goto errout;
178 + }
179 + fd = -1; /* The fp owns this fd now. */
180 +
181 + /*
182 + * Get smbfs sharectl settings into the file.
183 + */
184 + if ((err = rc_scf_get_sharectl(fp)) != 0)
185 + goto errout;
186 +
166 187 rcp = malloc(sizeof (struct rcfile));
167 188 if (rcp == NULL) {
168 - fclose(f);
169 - return (ENOMEM);
189 + err = ENOMEM;
190 + goto errout;
170 191 }
171 192 bzero(rcp, sizeof (struct rcfile));
172 - rcp->rf_name = strdup(command);
173 - rcp->rf_f = f;
193 +
194 + rcp->rf_name = strdup(template);
195 + if (rcp->rf_name == NULL) {
196 + err = ENOMEM;
197 + goto errout;
198 + }
199 + rcp->rf_f = fp;
200 + rcp->rf_flags = RCFILE_DELETE_ON_CLOSE;
201 +
174 202 SLIST_INSERT_HEAD(&pf_head, rcp, rf_next);
203 + insecure_nsmbrc = 0;
175 204 rc_parse(rcp);
176 205 *rcfile = rcp;
177 206 /* fclose(f) in rc_close */
178 207 return (0);
208 +
209 +errout:
210 + if (rcp != NULL)
211 + free(rcp);
212 + if (fp != NULL) {
213 + fclose(fp);
214 + fd = -1;
215 + }
216 + if (fd != -1)
217 + close(fd);
218 +
219 + return (err);
179 220 }
180 221
222 +
181 223 static int
182 224 rc_close(struct rcfile *rcp)
183 225 {
184 226 struct rcsection *p, *n;
185 227
186 228 mutex_lock(&rcfile_mutex);
187 229
188 230 fclose(rcp->rf_f);
231 + if (rcp->rf_flags & RCFILE_DELETE_ON_CLOSE)
232 + (void) unlink(rcp->rf_name);
233 +
189 234 for (p = SLIST_FIRST(&rcp->rf_sect); p; ) {
190 235 n = p;
191 236 p = SLIST_NEXT(p, rs_next);
192 237 rc_freesect(rcp, n);
193 238 }
194 239 free(rcp->rf_name);
195 240 SLIST_REMOVE(&pf_head, rcp, rcfile, rf_next);
196 241 free(rcp);
197 242
198 243 mutex_unlock(&rcfile_mutex);
199 244 return (0);
200 245 }
201 246
202 247 static struct rcfile *
203 248 rc_cachelookup(const char *filename)
204 249 {
205 250 struct rcfile *p;
206 251
207 252 assert(MUTEX_HELD(&rcfile_mutex));
208 253
209 254 SLIST_FOREACH(p, &pf_head, rf_next)
210 255 if (strcmp(filename, p->rf_name) == 0)
211 256 return (p);
212 257 return (0);
213 258 }
214 259
215 260 static struct rcsection *
216 261 rc_findsect(struct rcfile *rcp, const char *sectname)
217 262 {
218 263 struct rcsection *p;
219 264
220 265 assert(MUTEX_HELD(&rcfile_mutex));
221 266
222 267 SLIST_FOREACH(p, &rcp->rf_sect, rs_next)
223 268 if (strcasecmp(p->rs_name, sectname) == 0)
224 269 return (p);
225 270 return (NULL);
226 271 }
227 272
228 273 static struct rcsection *
229 274 rc_addsect(struct rcfile *rcp, const char *sectname)
230 275 {
231 276 struct rcsection *p;
232 277
233 278 assert(MUTEX_HELD(&rcfile_mutex));
234 279
235 280 p = rc_findsect(rcp, sectname);
236 281 if (p)
237 282 return (p);
238 283 p = malloc(sizeof (*p));
239 284 if (!p)
240 285 return (NULL);
241 286 p->rs_name = strdup(sectname);
242 287 SLIST_INIT(&p->rs_keys);
243 288 SLIST_INSERT_HEAD(&rcp->rf_sect, p, rs_next);
244 289 return (p);
245 290 }
246 291
247 292 static int
248 293 rc_freesect(struct rcfile *rcp, struct rcsection *rsp)
249 294 {
250 295 struct rckey *p, *n;
251 296
252 297 assert(MUTEX_HELD(&rcfile_mutex));
253 298
254 299 SLIST_REMOVE(&rcp->rf_sect, rsp, rcsection, rs_next);
255 300 for (p = SLIST_FIRST(&rsp->rs_keys); p; ) {
256 301 n = p;
257 302 p = SLIST_NEXT(p, rk_next);
258 303 rc_key_free(n);
259 304 }
260 305 free(rsp->rs_name);
261 306 free(rsp);
262 307 return (0);
263 308 }
264 309
265 310 static struct rckey *
266 311 rc_sect_findkey(struct rcsection *rsp, const char *keyname)
267 312 {
268 313 struct rckey *p;
269 314
270 315 assert(MUTEX_HELD(&rcfile_mutex));
271 316
272 317 SLIST_FOREACH(p, &rsp->rs_keys, rk_next)
273 318 if (strcmp(p->rk_name, keyname) == 0)
274 319 return (p);
275 320 return (NULL);
276 321 }
277 322
278 323 static struct rckey *
279 324 rc_sect_addkey(struct rcsection *rsp, const char *name, const char *value)
280 325 {
281 326 struct rckey *p;
282 327
283 328 assert(MUTEX_HELD(&rcfile_mutex));
284 329
285 330 p = rc_sect_findkey(rsp, name);
286 331 if (!p) {
287 332 p = malloc(sizeof (*p));
288 333 if (!p)
289 334 return (NULL);
290 335 SLIST_INSERT_HEAD(&rsp->rs_keys, p, rk_next);
291 336 p->rk_name = strdup(name);
292 337 p->rk_value = value ? strdup(value) : strdup("");
293 338 }
294 339 return (p);
295 340 }
296 341
297 342 #if 0
298 343 void
299 344 rc_sect_delkey(struct rcsection *rsp, struct rckey *p)
300 345 {
301 346
302 347 SLIST_REMOVE(&rsp->rs_keys, p, rckey, rk_next);
303 348 rc_key_free(p);
304 349 }
305 350 #endif
306 351
307 352 static void
308 353 rc_key_free(struct rckey *p)
309 354 {
310 355 free(p->rk_value);
311 356 free(p->rk_name);
312 357 free(p);
313 358 }
314 359
315 360
316 361 static char *minauth_values[] = {
317 362 "none",
318 363 "lm",
319 364 "ntlm",
320 365 "ntlmv2",
321 366 "kerberos",
322 367 NULL
323 368 };
324 369
325 370 static int
326 371 eval_minauth(char *auth)
327 372 {
328 373 int i;
329 374
330 375 for (i = 0; minauth_values[i]; i++)
331 376 if (strcmp(auth, minauth_values[i]) == 0)
332 377 return (i);
333 378 return (-1);
334 379 }
335 380
|
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
336 381 /*
337 382 * Ensure that "minauth" is set to the highest level
338 383 */
339 384 /*ARGSUSED*/
340 385 static void
341 386 set_value(struct rcfile *rcp, struct rcsection *rsp, struct rckey *rkp,
342 387 char *ptr)
343 388 {
344 389 int now, new;
345 390 #ifdef DEBUG
346 - char *from;
391 + char *from = "SMF";
347 392
348 - if (smb_debug)
349 - from = (home_nsmbrc) ?
350 - "user file" : "SMF";
393 + if (home_nsmbrc != 0)
394 + from = "user file";
351 395 #endif
352 396
353 397 if (strcmp(rkp->rk_name, "minauth") == 0) {
354 398 now = eval_minauth(rkp->rk_value);
355 399 new = eval_minauth(ptr);
356 400 if (new <= now) {
357 401 #ifdef DEBUG
358 402 if (smb_debug)
359 403 fprintf(stderr,
360 404 "set_value: rejecting %s=%s"
361 405 " in %s from %s\n",
362 406 rkp->rk_name, ptr,
363 407 rsp->rs_name, from);
364 408 #endif
365 409 return;
366 410 }
367 411 }
368 412 #ifdef DEBUG
369 413 if (smb_debug)
370 414 fprintf(stderr,
371 415 "set_value: applying %s=%s in %s from %s\n",
372 416 rkp->rk_name, ptr, rsp->rs_name, from);
373 417 #endif
374 418 rkp->rk_value = strdup(ptr);
375 419 }
376 420
377 421
378 422 /* states in rc_parse */
379 423 enum { stNewLine, stHeader, stSkipToEOL, stGetKey, stGetValue};
380 424
381 425 static void
382 426 rc_parse(struct rcfile *rcp)
383 427 {
384 428 FILE *f = rcp->rf_f;
385 429 int state = stNewLine, c;
386 430 struct rcsection *rsp = NULL;
387 431 struct rckey *rkp = NULL;
388 432 char buf[2048];
389 433 char *next = buf, *last = &buf[sizeof (buf)-1];
390 434
391 435 assert(MUTEX_HELD(&rcfile_mutex));
392 436
393 437 while ((c = getc(f)) != EOF) {
394 438 if (c == '\r')
395 439 continue;
396 440 if (state == stNewLine) {
397 441 next = buf;
398 442 if (isspace(c))
399 443 continue; /* skip leading junk */
400 444 if (c == '[') {
401 445 state = stHeader;
402 446 rsp = NULL;
403 447 continue;
404 448 }
405 449 if (c == '#' || c == ';') {
406 450 state = stSkipToEOL;
407 451 } else { /* something meaningfull */
408 452 state = stGetKey;
409 453 }
410 454 }
411 455 /* ignore long lines */
412 456 if (state == stSkipToEOL || next == last) {
413 457 if (c == '\n') {
414 458 state = stNewLine;
415 459 next = buf;
416 460 }
417 461 continue;
418 462 }
419 463 if (state == stHeader) {
420 464 if (c == ']') {
421 465 *next = 0;
422 466 next = buf;
423 467 rsp = rc_addsect(rcp, buf);
424 468 state = stSkipToEOL;
425 469 } else
426 470 *next++ = c;
427 471 continue;
428 472 }
429 473 if (state == stGetKey) {
430 474 /* side effect: 'key name=' */
431 475 if (c == ' ' || c == '\t')
432 476 continue; /* become 'keyname=' */
433 477 if (c == '\n') { /* silently ignore ... */
434 478 state = stNewLine;
435 479 continue;
436 480 }
437 481 if (c != '=') {
438 482 *next++ = c;
439 483 continue;
440 484 }
441 485 *next = 0;
442 486 if (rsp == NULL) {
443 487 fprintf(stderr, dgettext(TEXT_DOMAIN,
444 488 "Key '%s' defined before section\n"), buf);
445 489 state = stSkipToEOL;
446 490 continue;
447 491 }
448 492 if (home_nsmbrc != 0 && (
449 493 strcmp(buf, "nbns") == 0 ||
450 494 strcmp(buf, "nbns_enable") == 0 ||
451 495 strcmp(buf, "nbns_broadcast") == 0 ||
452 496 strcmp(buf, "signing") == 0)) {
453 497 fprintf(stderr, dgettext(TEXT_DOMAIN,
454 498 "option %s may not be set "
455 499 "in user .nsmbrc file\n"), buf);
456 500 next = buf;
457 501 state = stNewLine;
458 502 continue;
459 503 }
460 504 if (insecure_nsmbrc != 0 &&
461 505 strcmp(buf, "password") == 0) {
462 506 fprintf(stderr, dgettext(TEXT_DOMAIN,
463 507 "Warning: .nsmbrc file not secure, "
464 508 "ignoring passwords\n"));
465 509 next = buf;
466 510 state = stNewLine;
467 511 continue;
468 512 }
469 513 rkp = rc_sect_addkey(rsp, buf, NULL);
470 514 next = buf;
471 515 state = stGetValue;
472 516 continue;
473 517 }
474 518 /* only stGetValue left */
475 519 if (state != stGetValue) {
476 520 fprintf(stderr, dgettext(TEXT_DOMAIN,
477 521 "Well, I can't parse file '%s'\n"), rcp->rf_name);
478 522 state = stSkipToEOL;
479 523 }
480 524 if (c != '\n') {
481 525 *next++ = c;
482 526 continue;
483 527 }
484 528 *next = 0;
485 529 set_value(rcp, rsp, rkp, buf);
486 530 state = stNewLine;
487 531 rkp = NULL;
488 532 } /* while */
489 533 if (c == EOF && state == stGetValue) {
490 534 *next = 0;
491 535 set_value(rcp, rsp, rkp, buf);
492 536 }
493 537 }
494 538
495 539 int
496 540 rc_getstringptr(struct rcfile *rcp, const char *section, const char *key,
497 541 char **dest)
498 542 {
499 543 struct rcsection *rsp;
500 544 struct rckey *rkp;
501 545 int err;
502 546
503 547 mutex_lock(&rcfile_mutex);
504 548
505 549 *dest = NULL;
506 550 rsp = rc_findsect(rcp, section);
507 551 if (!rsp) {
508 552 err = ENOENT;
509 553 goto out;
510 554 }
511 555 rkp = rc_sect_findkey(rsp, key);
512 556 if (!rkp) {
513 557 err = ENOENT;
514 558 goto out;
515 559 }
516 560 *dest = rkp->rk_value;
517 561 err = 0;
518 562
519 563 out:
520 564 mutex_unlock(&rcfile_mutex);
521 565 return (err);
522 566 }
523 567
524 568 int
525 569 rc_getstring(struct rcfile *rcp, const char *section, const char *key,
526 570 size_t maxlen, char *dest)
527 571 {
528 572 char *value;
529 573 int error;
530 574
531 575 error = rc_getstringptr(rcp, section, key, &value);
532 576 if (error)
533 577 return (error);
534 578 if (strlen(value) >= maxlen) {
535 579 fprintf(stderr, dgettext(TEXT_DOMAIN,
536 580 "line too long for key '%s' in section '%s', max = %d\n"),
537 581 key, section, maxlen);
538 582 return (EINVAL);
539 583 }
540 584 strcpy(dest, value);
541 585 return (0);
542 586 }
543 587
544 588 int
545 589 rc_getint(struct rcfile *rcp, const char *section, const char *key, int *value)
546 590 {
547 591 struct rcsection *rsp;
548 592 struct rckey *rkp;
549 593 int err;
550 594
551 595 mutex_lock(&rcfile_mutex);
552 596
553 597 rsp = rc_findsect(rcp, section);
554 598 if (!rsp) {
555 599 err = ENOENT;
556 600 goto out;
557 601 }
558 602 rkp = rc_sect_findkey(rsp, key);
559 603 if (!rkp) {
560 604 err = ENOENT;
561 605 goto out;
562 606 }
563 607 errno = 0;
564 608 *value = strtol(rkp->rk_value, NULL, 0);
565 609 if ((err = errno) != 0) {
566 610 fprintf(stderr, dgettext(TEXT_DOMAIN,
567 611 "invalid int value '%s' for key '%s' in section '%s'\n"),
568 612 rkp->rk_value, key, section);
569 613 }
570 614
571 615 out:
572 616 mutex_unlock(&rcfile_mutex);
573 617 return (err);
574 618 }
575 619
576 620 /*
577 621 * 1,yes,true
578 622 * 0,no,false
579 623 */
580 624 int
581 625 rc_getbool(struct rcfile *rcp, const char *section, const char *key, int *value)
582 626 {
583 627 struct rcsection *rsp;
584 628 struct rckey *rkp;
585 629 char *p;
586 630 int err;
587 631
588 632 mutex_lock(&rcfile_mutex);
589 633
590 634 rsp = rc_findsect(rcp, section);
591 635 if (!rsp) {
592 636 err = ENOENT;
593 637 goto out;
594 638 }
595 639 rkp = rc_sect_findkey(rsp, key);
596 640 if (!rkp) {
597 641 err = ENOENT;
598 642 goto out;
599 643 }
600 644 p = rkp->rk_value;
601 645 while (*p && isspace(*p)) p++;
602 646 if (*p == '0' ||
603 647 strcasecmp(p, "no") == 0 ||
604 648 strcasecmp(p, "false") == 0) {
605 649 *value = 0;
606 650 err = 0;
607 651 goto out;
608 652 }
609 653 if (*p == '1' ||
610 654 strcasecmp(p, "yes") == 0 ||
611 655 strcasecmp(p, "true") == 0) {
612 656 *value = 1;
613 657 err = 0;
614 658 goto out;
615 659 }
616 660 fprintf(stderr, dgettext(TEXT_DOMAIN,
617 661 "invalid boolean value '%s' for key '%s' in section '%s' \n"),
618 662 p, key, section);
619 663 err = EINVAL;
620 664
621 665 out:
622 666 mutex_unlock(&rcfile_mutex);
623 667 return (err);
624 668 }
625 669
626 670 #ifdef DEBUG
627 671 void
628 672 dump_props(char *where)
629 673 {
630 674 struct rcsection *rsp = NULL;
631 675 struct rckey *rkp = NULL;
632 676
633 677 fprintf(stderr, "Settings %s\n", where);
634 678 SLIST_FOREACH(rsp, &smb_rc->rf_sect, rs_next) {
635 679 fprintf(stderr, "section=%s\n", rsp->rs_name);
636 680 fflush(stderr);
637 681
638 682 SLIST_FOREACH(rkp, &rsp->rs_keys, rk_next) {
639 683 fprintf(stderr, " key=%s, value=%s\n",
640 684 rkp->rk_name, rkp->rk_value);
641 685 fflush(stderr);
642 686 }
643 687 }
644 688 }
645 689 #endif
646 690
647 691 /*
648 692 * first parse "sharectl get smbfs, then $HOME/.nsmbrc
649 693 * This is called by library consumers (commands)
650 694 */
651 695 int
652 696 smb_open_rcfile(char *home)
653 697 {
|
↓ open down ↓ |
293 lines elided |
↑ open up ↑ |
654 698 char *fn;
655 699 int len, error = 0;
656 700
657 701 mutex_lock(&rcfile_mutex);
658 702
659 703 smb_rc = NULL;
660 704 #if 0 /* before SMF */
661 705 fn = SMB_CFG_FILE;
662 706 error = rc_open(fn, &smb_rc);
663 707 #else
664 - fn = SMBFS_SHARECTL_CMD;
665 - error = rc_popen_cmd(fn, &smb_rc);
708 + fn = "(sharectl get smbfs)";
709 + error = rc_open_sharectl(&smb_rc);
666 710 #endif
667 711 if (error != 0 && error != ENOENT) {
668 712 /* Error from fopen. strerror is OK. */
669 713 fprintf(stderr, dgettext(TEXT_DOMAIN,
670 714 "Can't open %s: %s\n"), fn, strerror(errno));
671 715 }
672 716 #ifdef DEBUG
673 717 if (smb_debug)
674 718 dump_props(fn);
675 719 #endif
676 720
677 721 if (home) {
678 722 len = strlen(home) + 20;
679 723 fn = malloc(len);
680 724 snprintf(fn, len, "%s/.nsmbrc", home);
681 725 home_nsmbrc = 1;
682 726 error = rc_merge(fn, &smb_rc);
683 727 if (error != 0 && error != ENOENT) {
684 728 fprintf(stderr, dgettext(TEXT_DOMAIN,
685 729 "Can't open %s: %s\n"), fn, strerror(errno));
686 730 }
687 731 home_nsmbrc = 0;
688 732 #ifdef DEBUG
689 733 if (smb_debug)
690 734 dump_props(fn);
691 735 #endif
692 736 free(fn);
693 737 }
694 738
695 739 /* Mostly ignore error returns above. */
696 740 if (smb_rc == NULL)
697 741 error = ENOENT;
698 742 else
699 743 error = 0;
700 744
701 745 mutex_unlock(&rcfile_mutex);
702 746
703 747 return (error);
704 748 }
705 749
706 750 /*
707 751 * This is called by library consumers (commands)
708 752 */
709 753 void
710 754 smb_close_rcfile(void)
711 755 {
712 756 struct rcfile *rcp;
713 757
714 758 if ((rcp = smb_rc) != NULL) {
715 759 smb_rc = NULL;
716 760 rc_close(rcp);
717 761 }
718 762 }
|
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX