]>
git.ipfire.org Git - thirdparty/squid.git/blob - tools/cachemgr.cc
2 * $Id: cachemgr.cc,v 1.6 2007/12/14 23:11:53 amosjeffries Exp $
4 * DEBUG: section 0 CGI Cache Manager
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
47 #include <sys/types.h>
62 #include <gnumalloc.h>
69 #if HAVE_NETDB_H && !defined(_SQUID_NETDB_H_) /* protect NEXTSTEP */
70 #define _SQUID_NETDB_H_
83 #include <sys/param.h>
88 #if HAVE_SYS_RESOURCE_H
89 #include <sys/resource.h> /* needs sys/time.h above it */
92 #include <sys/socket.h>
95 #include <netinet/in.h>
98 #include <arpa/inet.h>
101 #include <sys/stat.h>
107 #include <sys/wait.h>
124 #if HAVE_SYS_SELECT_H
125 #include <sys/select.h>
136 #include "IPAddress.h"
137 #include "getfullhostname.h"
139 #ifndef DEFAULT_CACHEMGR_CONFIG
140 #define DEFAULT_CACHEMGR_CONFIG "/etc/squid/cachemgr.conf"
155 * Debugging macros (info goes to error_log on your web server)
156 * Note: do not run cache manager with non zero debugging level
157 * if you do not debug, it may write a lot of [sensitive]
158 * information to your error log.
161 /* debugging level 0 (disabled) - 3 (max) */
162 #define DEBUG_LEVEL 0
163 #define debug(level) if ((level) <= DEBUG_LEVEL && DEBUG_LEVEL > 0)
166 * Static variables and constants
168 static const time_t passwd_ttl
= 60 * 60 * 3; /* in sec */
169 static const char *script_name
= "/cgi-bin/cachemgr.cgi";
170 static const char *progname
= NULL
;
174 * Function prototypes
176 #define safe_free(str) { if (str) { xfree(str); (str) = NULL; } }
177 static const char *safe_str(const char *str
);
178 static const char *xstrtok(char **str
, char del
);
179 static void print_trailer(void);
180 static void auth_html(const char *host
, int port
, const char *user_name
);
181 static void error_html(const char *msg
);
182 static char *menu_url(cachemgr_request
* req
, const char *action
);
183 static int parse_status_line(const char *sline
, const char **statusStr
);
184 static cachemgr_request
*read_request(void);
185 static char *read_get_request(void);
186 static char *read_post_request(void);
188 static void make_pub_auth(cachemgr_request
* req
);
189 static void decode_pub_auth(cachemgr_request
* req
);
190 static void reset_auth(cachemgr_request
* req
);
191 static const char *make_auth_header(const cachemgr_request
* req
);
193 static int check_target_acl(const char *hostname
, int port
);
196 static int s_iInitCount
= 0;
198 int Win32SockInit(void)
200 int iVersionRequested
;
204 if (s_iInitCount
> 0) {
207 } else if (s_iInitCount
< 0)
208 return (s_iInitCount
);
210 /* s_iInitCount == 0. Do the initailization */
211 iVersionRequested
= MAKEWORD(2, 0);
213 err
= WSAStartup((WORD
) iVersionRequested
, &wsaData
);
217 return (s_iInitCount
);
220 if (LOBYTE(wsaData
.wVersion
) != 2 ||
221 HIBYTE(wsaData
.wVersion
) != 0) {
224 return (s_iInitCount
);
228 return (s_iInitCount
);
231 void Win32SockCleanup(void)
233 if (--s_iInitCount
== 0)
239 #endif /* ifdef _SQUID_MSWIN_ */
242 safe_str(const char *str
)
244 return str
? str
: "";
247 /* relaxed number format */
249 is_number(const char *str
)
251 return strspn(str
, "\t -+01234567890./\n") == strlen(str
);
255 xstrtok(char **str
, char del
)
258 char *p
= strchr(*str
, del
);
271 while (len
&& xisspace(tok
[len
- 1]))
274 while (xisspace(*tok
))
285 printf("<HR noshade size=\"1px\">\n");
286 printf("<ADDRESS>\n");
287 printf("Generated %s, by %s/%s@%s\n",
288 mkrfc1123(now
), progname
, VERSION
, getfullhostname());
289 printf("</ADDRESS></BODY></HTML>\n");
293 auth_html(const char *host
, int port
, const char *user_name
)
301 if (!host
|| !strlen(host
))
304 printf("Content-Type: text/html\r\n\r\n");
306 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
308 printf("<HTML><HEAD><TITLE>Cache Manager Interface</TITLE>\n");
310 printf("<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE></HEAD>\n");
312 printf("<BODY><H1>Cache Manager Interface</H1>\n");
314 printf("<P>This is a WWW interface to the instrumentation interface\n");
316 printf("for the Squid object cache.</P>\n");
318 printf("<HR noshade size=\"1px\">\n");
320 printf("<FORM METHOD=\"POST\" ACTION=\"%s\">\n", script_name
);
322 printf("<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"1\">\n");
325 fp
= fopen("cachemgr.conf", "r");
328 fp
= fopen(DEFAULT_CACHEMGR_CONFIG
, "r");
332 char config_line
[BUFSIZ
];
334 while (fgets(config_line
, BUFSIZ
, fp
)) {
335 char *server
, *comment
;
336 strtok(config_line
, "\r\n");
338 if (config_line
[0] == '#')
341 if (config_line
[0] == '\0')
344 if ((server
= strtok(config_line
, " \t")) == NULL
)
347 if (strchr(server
, '*') || strchr(server
, '[') || strchr(server
, '?')) {
352 comment
= strtok(NULL
, "");
355 while (*comment
== ' ' || *comment
== '\t')
358 if (!comment
|| !*comment
)
362 printf("<TR><TH ALIGN=\"left\">Cache Server:</TH><TD><SELECT NAME=\"server\">\n");
365 printf("<OPTION VALUE=\"%s\"%s>%s</OPTION>\n", server
, (servers
|| *host
) ? "" : " SELECTED", comment
);
370 if (need_host
== 1 && !*host
)
374 printf("<OPTION VALUE=\"\"%s>Other</OPTION>\n", (*host
) ? " SELECTED" : "");
376 printf("</SELECT></TR>\n");
383 if (need_host
== 1 && !*host
)
386 printf("<TR><TH ALIGN=\"left\">Cache Host:</TH><TD><INPUT NAME=\"host\" ");
388 printf("size=\"30\" VALUE=\"%s\"></TD></TR>\n", host
);
390 printf("<TR><TH ALIGN=\"left\">Cache Port:</TH><TD><INPUT NAME=\"port\" ");
392 printf("size=\"30\" VALUE=\"%d\"></TD></TR>\n", port
);
395 printf("<TR><TH ALIGN=\"left\">Manager name:</TH><TD><INPUT NAME=\"user_name\" ");
397 printf("size=\"30\" VALUE=\"%s\"></TD></TR>\n", user_name
);
399 printf("<TR><TH ALIGN=\"left\">Password:</TH><TD><INPUT TYPE=\"password\" NAME=\"passwd\" ");
401 printf("size=\"30\" VALUE=\"\"></TD></TR>\n");
403 printf("</TABLE><BR CLEAR=\"all\">\n");
405 printf("<INPUT TYPE=\"submit\" VALUE=\"Continue...\">\n");
413 error_html(const char *msg
)
415 printf("Content-Type: text/html\r\n\r\n");
416 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
417 printf("<HTML><HEAD><TITLE>Cache Manager Error</TITLE>\n");
418 printf("<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE></HEAD>\n");
419 printf("<BODY><H1>Cache Manager Error</H1>\n");
420 printf("<P>\n%s</P>\n", msg
);
424 /* returns http status extracted from status line or -1 on parsing failure */
426 parse_status_line(const char *sline
, const char **statusStr
)
428 const char *sp
= strchr(sline
, ' ');
433 if (strncasecmp(sline
, "HTTP/", 5) || !sp
)
436 while (xisspace(*++sp
));
447 menu_url(cachemgr_request
* req
, const char *action
)
449 static char url
[1024];
450 snprintf(url
, sizeof(url
), "%s?host=%s&port=%d&user_name=%s&operation=%s&auth=%s",
454 safe_str(req
->user_name
),
456 safe_str(req
->pub_auth
));
461 munge_menu_line(const char *buf
, cachemgr_request
* req
)
469 static char html
[2 * 1024];
477 buf_copy
= x
= xstrdup(buf
);
479 a
= xstrtok(&x
, '\t');
481 d
= xstrtok(&x
, '\t');
483 p
= xstrtok(&x
, '\t');
485 a_url
= xstrdup(menu_url(req
, a
));
487 /* no reason to give a url for a disabled action */
488 if (!strcmp(p
, "disabled"))
489 snprintf(html
, sizeof(html
), "<LI type=\"circle\">%s (disabled)<A HREF=\"%s\">.</A>\n", d
, a_url
);
491 /* disable a hidden action (requires a password, but password is not in squid.conf) */
492 if (!strcmp(p
, "hidden"))
493 snprintf(html
, sizeof(html
), "<LI type=\"circle\">%s (hidden)<A HREF=\"%s\">.</A>\n", d
, a_url
);
495 /* disable link if authentication is required and we have no password */
496 if (!strcmp(p
, "protected") && !req
->passwd
)
497 snprintf(html
, sizeof(html
), "<LI type=\"circle\">%s (requires <a href=\"%s\">authentication</a>)<A HREF=\"%s\">.</A>\n",
498 d
, menu_url(req
, "authenticate"), a_url
);
500 /* highlight protected but probably available entries */
501 if (!strcmp(p
, "protected"))
502 snprintf(html
, sizeof(html
), "<LI type=\"square\"><A HREF=\"%s\"><font color=\"#FF0000\">%s</font></A>\n",
505 /* public entry or unknown type of protection */
507 snprintf(html
, sizeof(html
), "<LI type=\"disk\"><A HREF=\"%s\">%s</A>\n", a_url
, d
);
517 munge_other_line(const char *buf
, cachemgr_request
* req
)
519 static const char *ttags
[] = {"td", "th"};
521 static char html
[4096];
522 static int table_line_num
= 0;
523 static int next_is_header
= 0;
529 /* does it look like a table? */
531 if (!strchr(buf
, '\t') || *buf
== '\t') {
532 /* nope, just text */
533 snprintf(html
, sizeof(html
), "%s%s",
534 table_line_num
? "</table>\n<pre>" : "", buf
);
539 /* start html table */
540 if (!table_line_num
) {
541 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "</pre><table cellpadding=\"2\" cellspacing=\"1\">\n");
546 is_header
= (!table_line_num
|| next_is_header
) && !strchr(buf
, ':') && !is_number(buf
);
548 ttag
= ttags
[is_header
];
551 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "<tr>");
553 /* substitute '\t' */
554 buf_copy
= x
= xstrdup(buf
);
556 if ((p
= strchr(x
, '\n')))
559 while (x
&& strlen(x
)) {
561 const char *cell
= xstrtok(&x
, '\t');
563 while (x
&& *x
== '\t') {
568 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "<%s colspan=\"%d\" align=\"%s\">%s</%s>",
570 is_header
? "center" : is_number(cell
) ? "right" : "left",
576 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "</tr>\n");
577 next_is_header
= is_header
&& strstr(buf
, "\t\t");
583 read_reply(int s
, cachemgr_request
* req
)
589 char *tmpfile
= tempnam(NULL
, "tmp0000");
590 FILE *fp
= fopen(tmpfile
, "w+");
593 FILE *fp
= fdopen(s
, "r");
595 /* interpretation states */
597 isStatusLine
, isHeaders
, isBodyStart
, isBody
, isForward
, isEof
, isForwardEof
, isSuccess
, isError
598 } istate
= isStatusLine
;
600 const char *action
= req
->action
;
601 const char *statusStr
= NULL
;
604 if (0 == strlen(req
->action
))
606 else if (0 == strcasecmp(req
->action
, "menu"))
624 while ((reply
=recv(s
, buf
, sizeof(buf
), 0)) > 0)
625 fwrite(buf
, 1, reply
, fp
);
634 /* read reply interpreting one line at a time depending on state */
635 while (istate
< isEof
) {
636 if (!fgets(buf
, sizeof(buf
), fp
))
637 istate
= istate
== isForward
? isForwardEof
: isEof
;
642 /* get HTTP status */
643 /* uncomment the following if you want to debug headers */
644 /* fputs("\r\n\r\n", stdout); */
645 status
= parse_status_line(buf
, &statusStr
);
646 istate
= status
== 200 ? isHeaders
: isForward
;
647 /* if cache asks for authentication, we have to reset our info */
649 if (status
== 401 || status
== 407) {
651 status
= 403; /* Forbiden, see comments in case isForward: */
654 /* this is a way to pass HTTP status to the Web server */
656 printf("Status: %d %s", status
, statusStr
); /* statusStr has '\n' */
661 /* forward header field */
662 if (!strcmp(buf
, "\r\n")) { /* end of headers */
663 fputs("Content-Type: text/html\r\n", stdout
); /* add our type */
664 istate
= isBodyStart
;
667 if (strncasecmp(buf
, "Content-Type:", 13)) /* filter out their type */
673 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
675 printf("<HTML><HEAD><TITLE>CacheMgr@%s: %s</TITLE>\n",
676 req
->hostname
, action
);
678 printf("<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}TABLE{background-color:#333333;border:0pt;padding:0pt}TH,TD{background-color:#ffffff;white-space:nowrap}--></STYLE>\n");
680 printf("</HEAD><BODY>\n");
683 printf("<H2><a href=\"%s\">Cache Manager</a> menu for %s:</H2>",
684 menu_url(req
, "authenticate"), req
->hostname
);
687 printf("<P><A HREF=\"%s\">%s</A>\n<HR noshade size=\"1px\">\n",
688 menu_url(req
, "menu"), "Cache Manager menu");
693 /* yes, fall through, we do not want to loose the first line */
696 /* interpret [and reformat] cache response */
699 fputs(munge_menu_line(buf
, req
), stdout
);
701 fputs(munge_other_line(buf
, req
), stdout
);
706 /* forward: no modifications allowed */
708 * Note: we currently do not know any way to get browser.reply to
709 * 401 to .cgi because web server filters out all auth info. Thus we
710 * disable authentication headers for now.
712 if (!strncasecmp(buf
, "WWW-Authenticate:", 17) || !strncasecmp(buf
, "Proxy-Authenticate:", 19))
725 printf("</table></PRE>\n");
734 /* indicate that we finished processing an "error" sequence */
740 printf("%s: internal bug: invalid state reached: %d", script_name
, istate
);
759 process_request(cachemgr_request
* req
)
762 char ipbuf
[MAX_IPSTRLEN
];
763 struct addrinfo
*AI
= NULL
;
768 static char buf
[2 * 1024];
771 auth_html(CACHEMGR_HOSTNAME
, CACHE_HTTP_PORT
, "");
775 if (req
->hostname
== NULL
) {
776 req
->hostname
= xstrdup(CACHEMGR_HOSTNAME
);
779 if (req
->port
== 0) {
780 req
->port
= CACHE_HTTP_PORT
;
783 if (req
->action
== NULL
) {
784 req
->action
= xstrdup("");
787 if (strcmp(req
->action
, "authenticate") == 0) {
788 auth_html(req
->hostname
, req
->port
, req
->user_name
);
792 if (!check_target_acl(req
->hostname
, req
->port
)) {
793 snprintf(buf
, 1024, "target %s:%d not allowed in cachemgr.conf\n", req
->hostname
, req
->port
);
799 if ((s
= socket(PF_INET6
, SOCK_STREAM
, 0)) < 0) {
801 if ((s
= socket(PF_INET
, SOCK_STREAM
, 0)) < 0) {
803 snprintf(buf
, 1024, "socket: %s\n", xstrerror());
808 S
= *gethostbyname(req
->hostname
);
810 if ( !S
.IsAnyAddr() ) {
812 } else if ( S
= req
->hostname
)
815 snprintf(buf
, 1024, "Unknown host: %s\n", req
->hostname
);
820 S
.SetPort(req
->port
);
824 if (connect(s
, AI
->ai_addr
, AI
->ai_addrlen
) < 0) {
825 snprintf(buf
, 1024, "connect %s: %s\n",
826 S
.ToURL(ipbuf
,MAX_IPSTRLEN
),
835 l
= snprintf(buf
, sizeof(buf
),
836 "GET cache_object://%s/%s HTTP/1.0\r\n"
838 "%s" /* Authentication info or nothing */
842 make_auth_header(req
));
844 debug(1) fprintf(stderr
, "wrote request: '%s'\n", buf
);
845 return read_reply(s
, req
);
849 main(int argc
, char *argv
[])
852 cachemgr_request
*req
;
858 atexit(Win32SockCleanup
);
859 _setmode( _fileno( stdin
), _O_BINARY
);
860 _setmode( _fileno( stdout
), _O_BINARY
);
863 if ((s
= strrchr(argv
[0], '\\')))
866 if ((s
= strrchr(argv
[0], '/')))
869 progname
= xstrdup(s
+ 1);
871 progname
= xstrdup(argv
[0]);
873 if ((s
= getenv("SCRIPT_NAME")) != NULL
)
874 script_name
= xstrdup(s
);
876 req
= read_request();
878 return process_request(req
);
882 read_post_request(void)
888 if ((s
= getenv("REQUEST_METHOD")) == NULL
)
891 if (0 != strcasecmp(s
, "POST"))
894 if ((s
= getenv("CONTENT_LENGTH")) == NULL
)
897 if ((len
= atoi(s
)) <= 0)
900 buf
= (char *)xmalloc(len
+ 1);
902 fread(buf
, len
, 1, stdin
);
910 read_get_request(void)
914 if ((s
= getenv("QUERY_STRING")) == NULL
)
920 static cachemgr_request
*
925 cachemgr_request
*req
;
930 if ((buf
= read_post_request()) != NULL
)
932 else if ((buf
= read_get_request()) != NULL
)
939 if (strlen(buf
) == 0 || strlen(buf
) == 4000)
942 if (strlen(buf
) == 0)
949 req
= (cachemgr_request
*)xcalloc(1, sizeof(cachemgr_request
));
951 for (s
= strtok(buf
, "&"); s
!= NULL
; s
= strtok(NULL
, "&")) {
954 if ((q
= strchr(t
, '=')) == NULL
)
963 if (0 == strcasecmp(t
, "server") && strlen(q
))
964 req
->server
= xstrdup(q
);
965 else if (0 == strcasecmp(t
, "host") && strlen(q
))
966 req
->hostname
= xstrdup(q
);
967 else if (0 == strcasecmp(t
, "port") && strlen(q
))
969 else if (0 == strcasecmp(t
, "user_name") && strlen(q
))
970 req
->user_name
= xstrdup(q
);
971 else if (0 == strcasecmp(t
, "passwd") && strlen(q
))
972 req
->passwd
= xstrdup(q
);
973 else if (0 == strcasecmp(t
, "auth") && strlen(q
))
974 req
->pub_auth
= xstrdup(q
), decode_pub_auth(req
);
975 else if (0 == strcasecmp(t
, "operation"))
976 req
->action
= xstrdup(q
);
979 if (req
->server
&& !req
->hostname
) {
981 req
->hostname
= strtok(req
->server
, ":");
983 if ((p
= strtok(NULL
, ":")))
988 debug(1) fprintf(stderr
, "cmgr: got req: host: '%s' port: %d uname: '%s' passwd: '%s' auth: '%s' oper: '%s'\n",
989 safe_str(req
->hostname
), req
->port
, safe_str(req
->user_name
), safe_str(req
->passwd
), safe_str(req
->pub_auth
), safe_str(req
->action
));
994 /* Routines to support authentication */
997 * Encodes auth info into a "public" form.
998 * Currently no powerful encryption is used.
1001 make_pub_auth(cachemgr_request
* req
)
1003 static char buf
[1024];
1004 safe_free(req
->pub_auth
);
1005 debug(3) fprintf(stderr
, "cmgr: encoding for pub...\n");
1007 if (!req
->passwd
|| !strlen(req
->passwd
))
1010 /* host | time | user | passwd */
1011 snprintf(buf
, sizeof(buf
), "%s|%d|%s|%s",
1014 req
->user_name
? req
->user_name
: "",
1017 debug(3) fprintf(stderr
, "cmgr: pre-encoded for pub: %s\n", buf
);
1019 debug(3) fprintf(stderr
, "cmgr: encoded: '%s'\n", base64_encode(buf
));
1021 req
->pub_auth
= xstrdup(base64_encode(buf
));
1025 decode_pub_auth(cachemgr_request
* req
)
1028 const char *host_name
;
1029 const char *time_str
;
1030 const char *user_name
;
1033 debug(2) fprintf(stderr
, "cmgr: decoding pub: '%s'\n", safe_str(req
->pub_auth
));
1034 safe_free(req
->passwd
);
1036 if (!req
->pub_auth
|| strlen(req
->pub_auth
) < 4 + strlen(safe_str(req
->hostname
)))
1039 buf
= xstrdup(base64_decode(req
->pub_auth
));
1041 debug(3) fprintf(stderr
, "cmgr: length ok\n");
1043 /* parse ( a lot of memory leaks, but that is cachemgr style :) */
1044 if ((host_name
= strtok(buf
, "|")) == NULL
)
1047 debug(3) fprintf(stderr
, "cmgr: decoded host: '%s'\n", host_name
);
1049 if ((time_str
= strtok(NULL
, "|")) == NULL
)
1052 debug(3) fprintf(stderr
, "cmgr: decoded time: '%s' (now: %d)\n", time_str
, (int) now
);
1054 if ((user_name
= strtok(NULL
, "|")) == NULL
)
1057 debug(3) fprintf(stderr
, "cmgr: decoded uname: '%s'\n", user_name
);
1059 if ((passwd
= strtok(NULL
, "|")) == NULL
)
1062 debug(2) fprintf(stderr
, "cmgr: decoded passwd: '%s'\n", passwd
);
1064 /* verify freshness and validity */
1065 if (atoi(time_str
) + passwd_ttl
< now
)
1068 if (strcasecmp(host_name
, req
->hostname
))
1071 debug(1) fprintf(stderr
, "cmgr: verified auth. info.\n");
1074 xfree(req
->user_name
);
1076 req
->user_name
= xstrdup(user_name
);
1078 req
->passwd
= xstrdup(passwd
);
1084 reset_auth(cachemgr_request
* req
)
1086 safe_free(req
->passwd
);
1087 safe_free(req
->pub_auth
);
1091 make_auth_header(const cachemgr_request
* req
)
1093 static char buf
[1024];
1094 size_t stringLength
= 0;
1100 snprintf(buf
, sizeof(buf
), "%s:%s",
1101 req
->user_name
? req
->user_name
: "",
1104 str64
= base64_encode(buf
);
1106 stringLength
+= snprintf(buf
, sizeof(buf
), "Authorization: Basic %s\r\n", str64
);
1108 assert(stringLength
< sizeof(buf
));
1110 stringLength
+= snprintf(&buf
[stringLength
], sizeof(buf
) - stringLength
,
1111 "Proxy-Authorization: Basic %s\r\n", str64
);
1117 check_target_acl(const char *hostname
, int port
)
1119 char config_line
[BUFSIZ
];
1122 fp
= fopen("cachemgr.conf", "r");
1125 fp
= fopen(DEFAULT_CACHEMGR_CONFIG
, "r");
1128 #ifdef CACHEMGR_HOSTNAME_DEFINED
1130 if (strcmp(hostname
, CACHEMGR_HOSTNAME
) == 0 && port
== CACHE_HTTP_PORT
)
1135 if (strcmp(hostname
, "localhost") == 0)
1138 if (strcmp(hostname
, getfullhostname()) == 0)
1146 while (fgets(config_line
, BUFSIZ
, fp
)) {
1148 strtok(config_line
, " \r\n\t");
1150 if (config_line
[0] == '#')
1153 if (config_line
[0] == '\0')
1156 if ((token
= strtok(config_line
, ":")) == NULL
)
1161 if (fnmatch(token
, hostname
, 0) != 0)
1166 if (strcmp(token
, hostname
) != 0)
1171 if ((token
= strtok(NULL
, ":")) != NULL
) {
1174 if (strcmp(token
, "*") == 0)
1176 ; /* Wildcard port specification */
1177 else if (strcasecmp(token
, "any") == 0)
1179 ; /* Wildcard port specification */
1180 else if (sscanf(token
, "%d", &i
) != 1)
1185 } else if (port
!= CACHE_HTTP_PORT
)