2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Handle representation of an NDMP agent.
36 * This provides for a common text for specifying
37 * an agent host, connection authentication, and
38 * protocol version. The text specification may
39 * originate on the command line, in a config file,
42 * A text string representation has the form:
44 * AGENT ::= HOST[:PORT][/FLAGS][,ACCOUNT[,PASSWORD]]
48 * The internal representation is a struct ndmagent.
56 ndmagent_from_str (struct ndmagent *agent, char *str)
65 NDMOS_MACRO_ZEROFILL (agent);
67 if ((acct = strchr (str, ',')) != 0)
68 *acct++ = 0; /* stomp */
70 if ((port = strchr (str, ':')) != 0)
71 *port++ = 0; /* stomp */
74 flags = strchr (port, '/');
76 flags = strchr (str, '/');
79 *flags++ = 0; /* stomp */
82 * HOST[:PORT][/FLAGS][,ACCOUNT[,PASSWORD]]
85 * port-----------+ | |
86 * flags-----------------+ |
87 * acct--------------------------+
89 * The delimiters have been stomped (*p=0).
90 * If a portion is missing, the respective pointer is NULL (p==0)
91 * We restore the delimiters (p[-1]=x) as we proceed.
94 strncpy (agent->host, str, NDMAGENT_HOST_MAX-1);
97 agent->port = atoi(port);
98 port[-1] = ':'; /* restore */
100 agent->port = NDMPPORT;
106 for (p = flags; *p; p++) {
108 #ifndef NDMOS_OPTION_NO_NDMP2
110 agent->protocol_version = 2;
113 #endif /* !NDMOS_OPTION_NO_NDMP2 */
115 #ifndef NDMOS_OPTION_NO_NDMP3
117 agent->protocol_version = 3;
120 #endif /* !NDMOS_OPTION_NO_NDMP3 */
122 #ifndef NDMOS_OPTION_NO_NDMP4
124 agent->protocol_version = 4;
127 #endif /* !NDMOS_OPTION_NO_NDMP4 */
129 case 'n': /* NDMP_AUTH_NONE */
130 case 't': /* NDMP_AUTH_TEXT */
131 case 'm': /* NDMP_AUTH_MD5 */
132 case 'v': /* void (don't auth) */
133 agent->auth_type = *p;
142 if (have_auth > 1 || have_vers > 1) {
146 flags[-1] = '/'; /* restore */
152 if ((pass = strchr (acct, ',')) != 0)
155 strncpy (agent->account, acct, NDMAGENT_ACCOUNT_MAX-1);
157 strncpy (agent->password, pass,
158 NDMAGENT_PASSWORD_MAX-1);
161 acct[-1] = ','; /* restore */
164 agent->auth_type = 't'; /* NDMP_AUTH_TEXT */
168 if (strcmp (agent->host, ".") == 0) {
169 agent->conn_type = NDMCONN_TYPE_RESIDENT;
170 strcpy (agent->host, "(resident)");
172 agent->conn_type = NDMCONN_TYPE_REMOTE;
178 if (acct) acct[-1] = ','; /* restore */
179 if (port) port[-1] = ':'; /* restore */
180 if (flags) flags[-1] = '/'; /* restore */
188 ndmhost_lookup (char *hostname, struct sockaddr_in *sin)
193 NDMOS_MACRO_ZEROFILL (sin);
194 #ifdef NDMOS_OPTION_HAVE_SIN_LEN
195 sin->sin_len = sizeof *sin;
197 sin->sin_family = AF_INET;
199 addr = inet_addr (hostname);
200 if (addr != INADDR_NONE) {
201 bcopy (&addr, &sin->sin_addr, 4);
203 he = gethostbyname (hostname);
206 bcopy (he->h_addr, &sin->sin_addr, 4);
213 ndmagent_to_sockaddr_in (struct ndmagent *agent, struct sockaddr_in *sin)
217 rc = ndmhost_lookup (agent->host, sin); /* inits sin */
220 sin->sin_port = htons (agent->port);