/*
- * $Id: errorpage.cc,v 1.23 1996/07/15 23:12:36 wessels Exp $
+ * $Id: errorpage.cc,v 1.24 1996/07/15 23:57:49 wessels Exp $
*
* DEBUG: section 4 Error Generation
* AUTHOR: Duane Wessels
meta_data.misc += MAX_URL * 4;
tbuf = xmalloc(MAX_URL * 3);
meta_data.misc += MAX_URL * 3;
+ auth_msg = xmalloc(MAX_URL * 3);
+ meta_data.misc += MAX_URL * 3;
}
void squid_error_entry(entry, type, msg)
getMyHostname());
return tmp_error_buf;
}
+
+char *authorization_needed_msg(request, realm)
+ request_t *request;
+ char *realm;
+{
+ sprintf(auth_msg, "<TITLE>Authorization needed</TITLE>\n\
+Sorry, you have to authorize yourself to request\n\
+<PRE> ftp://%s@%s%s</PRE>\n\
+from this cache. Please check with the cache administrator if you\n\
+believe this is incorrect.\n\
+<HR>\n\
+<ADDRESS>\n\
+Generated by %s/%s@%s\n\
+</ADDRESS>\n\
+\n",
+ request->login,
+ request->host,
+ request->urlpath,
+ appname,
+ version_string,
+ getMyHostname());
+
+ mk_mime_hdr(tbuf,
+ (time_t) getNegativeTTL(),
+ strlen(auth_msg),
+ 0,
+ "text/html");
+ sprintf(tmp_error_buf, "HTTP/1.0 401 Unauthorized\r\n\
+%s\
+WWW-Authenticate: Basic realm=\"%s\"\r\n\
+\r\n\
+%s",
+ tbuf, realm, auth_msg);
+ return tmp_error_buf;
+}
/*
- * $Id: ftp.cc,v 1.41 1996/07/15 23:13:31 wessels Exp $
+ * $Id: ftp.cc,v 1.42 1996/07/15 23:57:51 wessels Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
* expires */
int got_marker; /* denotes end of successful request */
int reply_hdr_state;
+ int authenticated; /* This ftp request is authenticated */
} FtpData;
/* Local functions */
void ftpConnInProgress _PARAMS((int fd, FtpData * data));
void ftpServerClose _PARAMS((void));
+/* External functions */
+extern char *base64_decode _PARAMS((char *coded));
+
static int ftpStateFree(fd, ftpState)
int fd;
FtpData *ftpState;
sprintf(tbuf, "-H %s ", s);
strcat(buf, tbuf);
}
+ if (data->authenticated) {
+ strcat(buf, "-a ");
+ }
strcat(buf, "-h "); /* httpify */
strcat(buf, "- "); /* stdout */
strcat(buf, data->request->host);
request_t *request;
StoreEntry *entry;
{
+ static char realm[8192];
FtpData *data = NULL;
+ char *req_hdr = entry->mem_obj->mime_hdr;
+ char *auth_hdr;
+ char *response;
+ char *auth;
+
int status;
debug(9, 3, "FtpStart: FD %d <URL:%s>\n", unusedfd, url);
storeLockObject(data->entry = entry, NULL, NULL);
data->request = requestLink(request);
+ auth_hdr = mime_get_header(req_hdr, "Authorization");
+ auth = NULL;
+ if (auth_hdr) {
+ if (strcasecmp(strtok(auth_hdr, " \t"), "Basic") == 0) {
+ auth = base64_decode(strtok(NULL, " \t"));
+ }
+ }
/* Parse login info. */
- ftp_login_parser(request->login, data);
+ if (auth) {
+ ftp_login_parser(auth, data);
+ data->authenticated = 1;
+ } else {
+ ftp_login_parser(request->login, data);
+ if (*data->user && !*data->password) {
+ /* This request is not fully authenticated */
+ if (request->port == 21) {
+ sprintf(realm, "ftp %s", data->user);
+ } else {
+ sprintf(realm, "ftp %s port %d",
+ data->user, request->port);
+ }
+ response = authorization_needed_msg(request, realm);
+ storeAppend(entry, response, strlen(response));
+ httpParseHeaders(response, entry->mem_obj->reply);
+ storeComplete(entry);
+ ftpStateFree(-1, data);
+ return COMM_OK;
+ }
+ }
debug(9, 5, "FtpStart: FD %d, host=%s, path=%s, user=%s, passwd=%s\n",
unusedfd, data->request->host, data->request->urlpath,