2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
4 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of U.M. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. U.M. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Authors: the Amanda Development Team. Its members are listed in a
25 * file named AUTHORS, in the root directory of this distribution.
28 * $Id: findpass.c,v 1.13 2006/05/25 01:47:11 johnfranks Exp $
30 * Support routines for Amanda SAMBA support
38 * Find the Samba password and optional domain for a given disk.
39 * Returns pointers into an alloc-ed area. The caller should clear them
40 * as soon as reasonable.
49 static char *buffer = NULL;
50 char *s, *d, *pw = NULL;
54 *domain = NULL; /* just to be sure */
55 if ( (fp = fopen("/etc/amandapass", "r")) ) {
57 for (; (buffer = agets(fp)) != NULL; free(buffer)) {
58 if (buffer[0] == '\0')
62 skip_whitespace(s, ch); /* find start of disk name */
63 if (!ch || ch == '#') {
66 qname = s-1; /* start of disk name */
67 skip_quoted_string(s, ch);
68 if (ch && ch != '#') {
69 s[-1] = '\0'; /* terminate disk name */
70 d = unquote_string(qname);
71 if ((strcmp(d,"*") == 0) || (strcmp(disk, d) == 0)) {
72 skip_whitespace(s, ch); /* find start of password */
73 if (ch && ch != '#') {
74 pw = s - 1; /* start of password */
75 skip_non_whitespace_cs(s, ch);
76 s[-1] = '\0'; /* terminate password */
78 skip_whitespace(s, ch); /* find start of domain */
79 if (ch && ch != '#') {
80 *domain = s - 1; /* start of domain */
81 skip_non_whitespace_cs(s, ch);
82 s[-1] = '\0'; /* terminate domain */
83 *domain = stralloc(*domain);
98 * Convert an amanda disk-name into a Samba sharename,
99 * optionally for a shell execution (\'s are escaped).
100 * Returns a new name alloc-d that the caller is responsible
113 buffer_size = 2 * strlen(disk) + 1; /* worst case */
114 buffer = alloc(buffer_size);
117 while ((ch = *disk++) != '\0') {
118 if (s >= buffer+buffer_size-2) { /* room for escape */
119 amfree(buffer); /* should never happen */
120 return NULL; /* buffer not big enough */
123 ch = '\\'; /* convert '/' to '\\' */
125 if (ch == '\\' && shell) {
126 *s++ = '\\'; /* add escape for shell */
130 *s = '\0'; /* terminate the share name */
135 * find out if the samba sharename specifies both a share
136 * and a target subdirectory or just a share
138 * the caller is expected to release share & subdir
154 *share = stralloc(disk);
157 while (*ch != '\0') {
158 if (*ch == '/') {slashcnt++;}
161 *subdir = stralloc(++ch);