8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / smbsrv / fksmbd / fksmbd_shr.c
blobdea6e3fa001525f308a2d4005525d785274c714e
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
17 * Replace the smb_shr_load() function in libmlsvc, because
18 * fksmbd doesn't want the real shares known by libshare,
19 * instead preferring its own (fake) list of shares.
22 #include <sys/types.h>
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <strings.h>
29 #include <syslog.h>
30 #include <libshare.h>
31 #include <unistd.h>
32 #include <note.h>
34 #include <smbsrv/libsmb.h>
35 #include <smbsrv/libsmbns.h>
36 #include <smbsrv/libmlsvc.h>
37 #include <smbsrv/smb_share.h>
38 #include <smbsrv/smb.h>
40 static void
41 new_share(char *name, char *path, char *comment, int flags)
43 smb_share_t si;
45 bzero(&si, sizeof (si));
46 (void) strlcpy(si.shr_name, name, MAXNAMELEN);
47 (void) strlcpy(si.shr_path, path, MAXPATHLEN);
48 (void) strlcpy(si.shr_cmnt, comment, SMB_SHARE_CMNT_MAX);
49 si.shr_flags = flags;
50 if (smb_shr_add(&si) != 0) {
51 syslog(LOG_ERR, "failed to add test share: %s",
52 si.shr_name);
57 * This function loads a list of shares from a text file, where
58 * each line of the file contains:
59 * name path comment
61 * This is only for fksmbd, for testing.
63 void
64 shr_load_file(char *shr_file)
66 char linebuf[1024];
67 FILE *fp;
68 char *p;
69 char *name, *path, *comment;
71 fp = fopen(shr_file, "r");
72 if (fp == NULL) {
73 perror(shr_file);
74 return;
77 while ((p = fgets(linebuf, sizeof (linebuf), fp)) != NULL) {
79 name = p;
80 p = strpbrk(p, " \t\n");
81 if (p == NULL)
82 continue;
83 *p++ = '\0';
85 path = p;
86 p = strpbrk(p, " \t\n");
87 if (p == NULL)
88 comment = "";
89 else {
90 *p++ = '\0';
92 comment = p;
93 p = strchr(p, '\n');
94 if (p != NULL)
95 *p++ = '\0';
97 new_share(name, path, comment, 0);
99 (void) fclose(fp);
102 /*ARGSUSED*/
103 void *
104 smb_shr_load(void *args)
106 char *shr_file;
107 _NOTE(ARGUNUSED(args))
110 * Not loading the real shares in fksmbd because that
111 * tries to enable the network/smb/server service.
112 * Also, we won't generally have access to everything
113 * in the real shares, because fksmbd runs (only) with
114 * the credentials of the user who runs it.
116 new_share("test", "/var/smb/test", "fksmbd test share",
117 SMB_SHRF_GUEST_OK);
119 /* Allow creating lots of shares for testing. */
120 shr_file = getenv("FKSMBD_SHARE_FILE");
121 if (shr_file != NULL)
122 shr_load_file(shr_file);
124 return (NULL);