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