浏览代码

[ftp] User and password URI support for the FTP protocol

The default user and password are used for anonymous FTP by default.
This patch adds support for an explicit user name and password in an FTP
URI:

    imgfetch ftp://user:password@server.com/path/to/file

Edited-by: Stefan Hajnoczi <stefanha@gmail.com>.  Bugs are my fault.

Signed-off-by: Marty Connor <mdc@etherboot.org>
tags/v1.0.0-rc1
gL2n30Y06arv2 15 年前
父节点
当前提交
93805d9765
共有 1 个文件被更改,包括 24 次插入2 次删除
  1. 24
    2
      src/net/tcp/ftp.c

+ 24
- 2
src/net/tcp/ftp.c 查看文件

131
 	return ftp->uri->path;
131
 	return ftp->uri->path;
132
 }
132
 }
133
 
133
 
134
+/**
135
+ * Retrieve FTP user
136
+ *
137
+ * @v ftp		FTP request
138
+ * @ret user		FTP user
139
+ */
140
+static const char * ftp_user ( struct ftp_request *ftp ) {
141
+	static char *ftp_default_user = "anonymous";
142
+	return ftp->uri->user ? ftp->uri->user : ftp_default_user;
143
+}
144
+
145
+/**
146
+ * Retrieve FTP password
147
+ *
148
+ * @v ftp		FTP request
149
+ * @ret password	FTP password
150
+ */
151
+static const char * ftp_password ( struct ftp_request *ftp ) {
152
+	static char *ftp_default_password = "etherboot@etherboot.org";
153
+	return ftp->uri->password ? ftp->uri->password : ftp_default_password;
154
+}
155
+
134
 /** FTP control channel strings */
156
 /** FTP control channel strings */
135
 static struct ftp_control_string ftp_strings[] = {
157
 static struct ftp_control_string ftp_strings[] = {
136
 	[FTP_CONNECT]	= { NULL, NULL },
158
 	[FTP_CONNECT]	= { NULL, NULL },
137
-	[FTP_USER]	= { "USER anonymous", NULL },
138
-	[FTP_PASS]	= { "PASS etherboot@etherboot.org", NULL },
159
+	[FTP_USER]	= { "USER ", ftp_user },
160
+	[FTP_PASS]	= { "PASS ", ftp_password },
139
 	[FTP_TYPE]	= { "TYPE I", NULL },
161
 	[FTP_TYPE]	= { "TYPE I", NULL },
140
 	[FTP_PASV]	= { "PASV", NULL },
162
 	[FTP_PASV]	= { "PASV", NULL },
141
 	[FTP_RETR]	= { "RETR ", ftp_uri_path },
163
 	[FTP_RETR]	= { "RETR ", ftp_uri_path },

正在加载...
取消
保存