]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/netrc.cc
merge from lp:~donkult/apt/sid
[apt.git] / apt-pkg / contrib / netrc.cc
index 950d21dadb651d4e0a23c8742e4eb186e283888b..0a902f12699e0713327171475f0e5c40001cac76 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/strutl.h>
+#include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 
 #include <iostream>
@@ -39,8 +40,8 @@ enum {
 };
 
 /* make sure we have room for at least this size: */
-#define LOGINSIZE 64
-#define PASSWORDSIZE 64
+#define LOGINSIZE 256
+#define PASSWORDSIZE 256
 #define NETRC DOT_CHAR "netrc"
 
 /* returns -1 on failure, 0 if the host is found, 1 is the host isn't found */
@@ -79,13 +80,14 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
     char *tok;
     char *tok_buf;
     bool done = false;
-    char netrcbuffer[256];
+    char *netrcbuffer = NULL;
+    size_t netrcbuffer_size = 0;
 
     int state = NOTHING;
     char state_login = 0;        /* Found a login keyword */
     char state_password = 0;     /* Found a password keyword */
 
-    while (!done && fgets(netrcbuffer, sizeof (netrcbuffer), file)) {
+    while (!done && getline(&netrcbuffer, &netrcbuffer_size, file) != -1) {
       tok = strtok_r (netrcbuffer, " \t\n", &tok_buf);
       while (!done && tok) {
         if(login.empty() == false && password.empty() == false) {
@@ -142,8 +144,9 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
 
         tok = strtok_r (NULL, " \t\n", &tok_buf);
       } /* while(tok) */
-    } /* while fgets() */
+    } /* while getline() */
 
+    free(netrcbuffer);
     fclose(file);
   }