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.
54 /* On some solaris distributions INADDR_NONE is not defined,
59 #define INADDR_NONE ((in_addr_t)-1)
63 ndmagent_from_str (struct ndmagent *agent, char *str)
72 NDMOS_MACRO_ZEROFILL (agent);
74 if ((acct = strchr (str, ',')) != 0)
75 *acct++ = 0; /* stomp */
77 if ((port = strchr (str, ':')) != 0)
78 *port++ = 0; /* stomp */
81 flags = strchr (port, '/');
83 flags = strchr (str, '/');
86 *flags++ = 0; /* stomp */
89 * HOST[:PORT][/FLAGS][,ACCOUNT[,PASSWORD]]
92 * port-----------+ | |
93 * flags-----------------+ |
94 * acct--------------------------+
96 * The delimiters have been stomped (*p=0).
97 * If a portion is missing, the respective pointer is NULL (p==0)
98 * We restore the delimiters (p[-1]=x) as we proceed.
101 strncpy (agent->host, str, NDMAGENT_HOST_MAX-1);
104 agent->port = atoi(port);
105 port[-1] = ':'; /* restore */
107 agent->port = NDMPPORT;
113 for (p = flags; *p; p++) {
115 #ifndef NDMOS_OPTION_NO_NDMP2
117 agent->protocol_version = 2;
120 #endif /* !NDMOS_OPTION_NO_NDMP2 */
122 #ifndef NDMOS_OPTION_NO_NDMP3
124 agent->protocol_version = 3;
127 #endif /* !NDMOS_OPTION_NO_NDMP3 */
129 #ifndef NDMOS_OPTION_NO_NDMP4
131 agent->protocol_version = 4;
134 #endif /* !NDMOS_OPTION_NO_NDMP4 */
136 case 'n': /* NDMP_AUTH_NONE */
137 case 't': /* NDMP_AUTH_TEXT */
138 case 'm': /* NDMP_AUTH_MD5 */
139 case 'v': /* void (don't auth) */
140 agent->auth_type = *p;
149 if (have_auth > 1 || have_vers > 1) {
153 flags[-1] = '/'; /* restore */
159 if ((pass = strchr (acct, ',')) != 0)
162 strncpy (agent->account, acct, NDMAGENT_ACCOUNT_MAX-1);
164 strncpy (agent->password, pass,
165 NDMAGENT_PASSWORD_MAX-1);
168 acct[-1] = ','; /* restore */
171 agent->auth_type = 't'; /* NDMP_AUTH_TEXT */
175 if (strcmp (agent->host, ".") == 0) {
176 agent->conn_type = NDMCONN_TYPE_RESIDENT;
177 strcpy (agent->host, "(resident)");
179 agent->conn_type = NDMCONN_TYPE_REMOTE;
185 if (acct) acct[-1] = ','; /* restore */
186 if (port) port[-1] = ':'; /* restore */
187 if (flags) flags[-1] = '/'; /* restore */
195 ndmhost_lookup (char *hostname, struct sockaddr_in *sin)
200 NDMOS_MACRO_ZEROFILL (sin);
201 #ifdef NDMOS_OPTION_HAVE_SIN_LEN
202 sin->sin_len = sizeof *sin;
204 sin->sin_family = AF_INET;
206 addr = inet_addr (hostname);
207 if (addr != INADDR_NONE) {
208 bcopy (&addr, &sin->sin_addr, 4);
210 he = gethostbyname (hostname);
213 bcopy (he->h_addr, &sin->sin_addr, 4);
220 ndmagent_to_sockaddr_in (struct ndmagent *agent, struct sockaddr_in *sin)
224 rc = ndmhost_lookup (agent->host, sin); /* inits sin */
227 sin->sin_port = htons (agent->port);