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.10.4.1.4.1 2001/08/01 22:36:24 jrjackson Exp $
29 * Support routines for Amanda SAMBA support
35 * Find the Samba password and optional domain for a given disk.
36 * Returns pointers into an alloc-ed area. The caller should clear them
37 * as soon as reasonable.
40 char *findpass(disk, domain)
44 static char *buffer = NULL;
45 char *s, *d, *pw = NULL;
48 *domain = NULL; /* just to be sure */
49 if ( (fp = fopen("/etc/amandapass", "r")) ) {
51 for (; (buffer = agets(fp)) != NULL; free(buffer)) {
54 skip_whitespace(s, ch); /* find start of disk name */
55 if (!ch || ch == '#') {
58 d = s-1; /* start of disk name */
59 skip_non_whitespace_cs(s, ch);
60 if (ch && ch != '#') {
61 s[-1] = '\0'; /* terminate disk name */
62 if ((strcmp(d,"*") == 0) || (strcmp(disk, d) == 0)) {
63 skip_whitespace(s, ch); /* find start of password */
64 if (ch && ch != '#') {
65 pw = s - 1; /* start of password */
66 skip_non_whitespace_cs(s, ch);
67 s[-1] = '\0'; /* terminate password */
69 skip_whitespace(s, ch); /* find start of domain */
70 if (ch && ch != '#') {
71 *domain = s - 1; /* start of domain */
72 skip_non_whitespace_cs(s, ch);
73 s[-1] = '\0'; /* terminate domain */
74 *domain = stralloc(*domain);
87 * Convert an amanda disk-name into a Samba sharename,
88 * optionally for a shell execution (\'s are escaped).
89 * Returns a new name alloc-d that the caller is responsible
92 char *makesharename(disk, shell)
101 buffer_size = 2 * strlen(disk) + 1; /* worst case */
102 buffer = alloc(buffer_size);
105 while ((ch = *disk++) != '\0') {
106 if (s >= buffer+buffer_size-2) { /* room for escape */
107 amfree(buffer); /* should never happen */
108 return NULL; /* buffer not big enough */
111 ch = '\\'; /* convert '/' to '\\' */
113 if (ch == '\\' && shell) {
114 *s++ = '\\'; /* add escape for shell */
118 *s = '\0'; /* terminate the share name */
123 * find out if the samba sharename specifies both a share
124 * and a target subdirectory or just a share
126 * the caller is expected to release share & subdir
128 void parsesharename (disk, share, subdir)
141 *share = stralloc(disk);
144 while (*ch != '\0') {
145 if (*ch == '/') {slashcnt++;}
148 *subdir = stralloc(++ch);