Permalink
Browse files

James Cone's efforts to add another netrc parsing "mode"

  • Loading branch information...
1 parent c759d84 commit 105ec79b2b754f31ea75606f8246533e2d47a74e @bagder bagder committed May 21, 2002
Showing with 218 additions and 139 deletions.
  1. +3 −1 lib/memdebug.c
  2. +46 −6 lib/netrc.c
  3. +5 −0 lib/netrc.h
  4. +162 −131 lib/url.c
  5. +2 −1 lib/urldata.h
View
@@ -49,7 +49,9 @@
struct memdebug {
int size;
- char mem[1];
+ double mem[1];
+ /* I'm hoping this is the thing with the strictest alignment
+ * requirements. That also means we waste some space :-( */
};
/*
View
@@ -78,12 +78,15 @@ int Curl_parsenetrc(char *host,
FILE *file;
char netrcbuffer[256];
int retcode=1;
+
+ int specific_login = (login[0] != 0);
char *home = NULL;
int state=NOTHING;
- char state_login=0;
- char state_password=0;
+ char state_login=0; /* Found a login keyword */
+ char state_password=0; /* Found a password keyword */
+ char state_our_login=0; /* With specific_login, found *our* login name */
#define NETRC DOT_CHAR "netrc"
@@ -116,13 +119,41 @@ int Curl_parsenetrc(char *host,
sprintf(netrcbuffer, "%s%s%s", home, DIR_CHAR, NETRC);
+#ifdef MALLOCDEBUG
+ {
+ /* This is a hack to allow testing.
+ * If compiled with --enable-debug and CURL_DEBUG_NETRC is defined,
+ * then it's the path to a substitute .netrc for testing purposes *only* */
+
+ char *override = curl_getenv("CURL_DEBUG_NETRC");
+
+ if (override != NULL) {
+ printf("NETRC: overridden .netrc file: %s\n", home);
+
+ if (strlen(override)+1 > sizeof(netrcbuffer)) {
+ free(override);
+ if(NULL==pw)
+ free(home);
+
+ return -1;
+ }
+ strcpy(netrcbuffer, override);
+ free(override);
+ }
+ }
+#endif /* MALLOCDEBUG */
+
file = fopen(netrcbuffer, "r");
if(file) {
char *tok;
char *tok_buf;
while(fgets(netrcbuffer, sizeof(netrcbuffer), file)) {
tok=strtok_r(netrcbuffer, " \t\n", &tok_buf);
while(tok) {
+
+ if (login[0] && password[0])
+ goto done;
+
switch(state) {
case NOTHING:
if(strequal("machine", tok)) {
@@ -149,17 +180,23 @@ int Curl_parsenetrc(char *host,
case HOSTVALID:
/* we are now parsing sub-keywords concerning "our" host */
if(state_login) {
- strncpy(login, tok, LOGINSIZE-1);
+ if (specific_login) {
+ state_our_login = strequal(login, tok);
+ }else{
+ strncpy(login, tok, LOGINSIZE-1);
#ifdef _NETRC_DEBUG
- printf("LOGIN: %s\n", login);
+ printf("LOGIN: %s\n", login);
#endif
+ }
state_login=0;
}
else if(state_password) {
- strncpy(password, tok, PASSWORDSIZE-1);
+ if (state_our_login || !specific_login) {
+ strncpy(password, tok, PASSWORDSIZE-1);
#ifdef _NETRC_DEBUG
- printf("PASSWORD: %s\n", password);
+ printf("PASSWORD: %s\n", password);
#endif
+ }
state_password=0;
}
else if(strequal("login", tok))
@@ -169,13 +206,16 @@ int Curl_parsenetrc(char *host,
else if(strequal("machine", tok)) {
/* ok, there's machine here go => */
state = HOSTFOUND;
+ state_our_login = 0;
}
break;
} /* switch (state) */
+
tok = strtok_r(NULL, " \t\n", &tok_buf);
} /* while (tok) */
} /* while fgets() */
+done:
fclose(file);
}
View
@@ -25,4 +25,9 @@
int Curl_parsenetrc(char *host,
char *login,
char *password);
+ /* Assume: password[0]=0, host[0] != 0.
+ * If login[0] = 0, search for login and password within a machine section
+ * in the netrc.
+ * If login[0] != 0, search for password within machine and login.
+ */
#endif
Oops, something went wrong.

0 comments on commit 105ec79

Please sign in to comment.