[PATCH] Parse login/password from URL (#505424)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In RHEL 5.3 (anaconda-11.1.2.168) the installer fails to retrieve a kickstart file hosted on password-protected FTP. Strangely enough, the code to parse the login/password is present in RHEL 4 and in F12. Don't know why it was pulled in RHEL 5, but here's a backport of the relevant parts to anaconda-11.1.2.168.

--
--- anaconda-11.1.2.113/loader2/kickstart.h.url_login
+++ anaconda-11.1.2.113/loader2/kickstart.h
@@ -29,5 +29,6 @@ void getKickstartFile(struct loaderData_
 void runKickstart(struct loaderData_s * loaderData);
 int getKickstartFromBlockDevice(char *device, char *path);
 void getHostandPath(char * ksSource, char **host, char ** file, char * ip);
+void getHostPathandLogin(char * ksSource, char **host, char ** file, char ** login, char ** password, char * ip);
 
 #endif
--- anaconda-11.1.2.113/loader2/kickstart.c.url_login
+++ anaconda-11.1.2.113/loader2/kickstart.c
@@ -301,7 +301,9 @@ int getKickstartFromBlockDevice(char *de
     return getFileFromBlockDevice(device, path, "/tmp/ks.cfg");
 }
 
-void getHostandPath(char * ksSource, char **host, char ** file, char * ip) {
+void getHostPathandLogin(char * ksSource, char **host, char ** file, char ** login, char ** password, char * ip) {
+    char *tmp;
+
     *host = malloc(strlen(ksSource) + 1);
     strcpy(*host, ksSource);
 
@@ -325,6 +327,33 @@ void getHostandPath(char * ksSource, cha
         *file = sdupprintf("%s%s-kickstart", *file, ip);
         logMessage(DEBUGLVL, "getHostandPath file(2): |%s|", *file);
     }
+
+    /* Do we have a password? */
+    tmp = strchr(*host, '@');
+    if (tmp != NULL) {
+        *login = *host;
+        *tmp = '\0';
+        *host = tmp + 1;
+
+        tmp = strchr(*login, ':');
+        if (tmp != NULL) {
+            *password = tmp + 1;
+            *tmp = '\0';
+        } else {
+            *password = malloc(sizeof(char *));
+            **password = '\0';
+        }
+    } else {
+        *login = malloc(sizeof(char *));
+        **login = '\0';
+        *password = malloc(sizeof(char *));
+        **password = '\0';
+    }
+}
+
+void getHostandPath(char * ksSource, char **host, char ** file, char * ip) {
+    char *password, *login;
+    getHostPathandLogin (ksSource, host, file, &login, &password, ip);
 }
 
 static char *newKickstartLocation(const char *origLocation) {
--- anaconda-11.1.2.113/loader2/urlinstall.c.url_login
+++ anaconda-11.1.2.113/loader2/urlinstall.c
@@ -339,7 +339,7 @@ int getFileFromUrl(char * url, char * de
     struct iurlinfo ui;
     enum urlprotocol_t proto = 
         !strncmp(url, "ftp://";, 6) ? URL_METHOD_FTP : URL_METHOD_HTTP;
-    char * host = NULL, * file = NULL, * chptr = NULL;
+    char * host = NULL, * file = NULL, * chptr = NULL, *login = NULL, *password = NULL;
     int fd, rc;
     struct networkDeviceConfig netCfg;
     char * ehdrs = NULL;
@@ -355,8 +355,8 @@ int getFileFromUrl(char * url, char * de
 
     tip = &(netCfg.dev.ip);
     inet_ntop(tip->sa_family, IP_ADDR(tip), ret, IP_STRLEN(tip));
-    getHostandPath((proto == URL_METHOD_FTP ? url + 6 : url + 7), 
-                   &host, &file, ret);
+    getHostPathandLogin((proto == URL_METHOD_FTP ? url + 6 : url + 7),
+                   &host, &file, &login, &password, ret);
 
     logMessage(INFO, "file location: %s://%s/%s", 
                (proto == URL_METHOD_FTP ? "ftp" : "http"), host, file);
@@ -373,6 +373,11 @@ int getFileFromUrl(char * url, char * de
         ui.prefix = strdup(host);
     }
 
+    if (password[0] != '\0')
+        ui.password = strdup (password);
+    if (login[0] != '\0')
+        ui.login = strdup (login);
+
     if (proto == URL_METHOD_HTTP) {
         ehdrs = (char *) malloc(24+strlen(VERSION));
         sprintf(ehdrs, "User-Agent: anaconda/%s\r\n", VERSION);
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux