char *path = (char *)alloca (strlen (home) + 1
+ strlen (NETRC_FILE_NAME) + 1);
sprintf (path, "%s/%s", home, NETRC_FILE_NAME);
- free (home);
+ xfree (home);
err = stat (path, &buf);
if (err == 0)
netrc_list = parse_netrc (path);
}
if (c == EOF && !i)
{
- free(line);
+ xfree(line);
return NULL;
}
if (a && ! a->acc)
{
/* Free any allocated space. */
- free (a->host);
- free (a->acc);
- free (a->passwd);
+ xfree (a->host);
+ xfree (a->acc);
+ xfree (a->passwd);
}
else
{
return;
}
+/* Helper function for the parser, shifts contents of
+ null-terminated string once character to the left.
+ Used in processing \ and " constructs in the netrc file */
+static void
+shift_left(char *string){
+ char *p;
+
+ for (p=string; *p; ++p)
+ *p = *(p+1);
+}
/* Parse a .netrc file (as described in the ftp(1) manual page). */
static acc_t *
FILE *fp;
char *line, *p, *tok, *premature_token;
acc_t *current, *retval;
- int ln;
+ int ln, quote;
/* The latest token we've seen in the file. */
enum
/* Parse the line. */
p = line;
+ quote = 0;
/* If the line is empty, then end any macro definition. */
if (last_token == tok_macdef && !*p)
if (*p == '#')
break;
+ /* If the token starts with quotation mark, note this fact,
+ and squash the quotation character */
+ if (*p == '"'){
+ quote = 1;
+ shift_left (p);
+ }
+
tok = p;
- /* Find the end of the token. */
- while (*p && !ISSPACE (*p))
+ /* Find the end of the token, handling quotes and escapes. */
+ while (*p && (quote ? *p != '"' : !ISSPACE (*p))){
+ if (*p == '\\')
+ shift_left (p);
p ++;
+ }
+
+ /* if field was quoted, squash the trailing quotation mark */
+ if (quote)
+ shift_left(p);
/* Null-terminate the token, if it isn't already. */
if (*p)
}
}
- free (line);
+ xfree (line);
}
fclose (fp);
/* Finalize the last machine entry we found. */
maybe_add_to_list (¤t, &retval);
- free (current);
+ xfree (current);
/* Reverse the order of the list so that it appears in file order. */
current = retval;
FREE_MAYBE (l->acc);
FREE_MAYBE (l->passwd);
FREE_MAYBE (l->host);
- free(l);
+ xfree (l);
l = t;
}
}