]>
git.ipfire.org Git - thirdparty/squid.git/blob - tools/cachemgr.cc
2 * DEBUG: section -- CGI Cache Manager
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 #include "compat/tempnam.h"
56 #include <gnumalloc.h>
76 #include <sys/param.h>
79 #include <sys/socket.h>
82 #include <netinet/in.h>
85 #include <arpa/inet.h>
118 #include "ip/Address.h"
119 #include "getfullhostname.h"
121 #ifndef DEFAULT_CACHEMGR_CONFIG
122 #define DEFAULT_CACHEMGR_CONFIG "/etc/squid/cachemgr.conf"
136 * Static variables and constants
138 static const time_t passwd_ttl
= 60 * 60 * 3; /* in sec */
139 static const char *script_name
= "/cgi-bin/cachemgr.cgi";
140 static const char *progname
= NULL
;
144 * Function prototypes
146 #define safe_free(str) { if (str) { xfree(str); (str) = NULL; } }
147 static const char *safe_str(const char *str
);
148 static const char *xstrtok(char **str
, char del
);
149 static void print_trailer(void);
150 static void auth_html(const char *host
, int port
, const char *user_name
);
151 static void error_html(const char *msg
);
152 static char *menu_url(cachemgr_request
* req
, const char *action
);
153 static int parse_status_line(const char *sline
, const char **statusStr
);
154 static cachemgr_request
*read_request(void);
155 static char *read_get_request(void);
156 static char *read_post_request(void);
158 static void make_pub_auth(cachemgr_request
* req
);
159 static void decode_pub_auth(cachemgr_request
* req
);
160 static void reset_auth(cachemgr_request
* req
);
161 static const char *make_auth_header(const cachemgr_request
* req
);
163 static int check_target_acl(const char *hostname
, int port
);
166 static int s_iInitCount
= 0;
168 int Win32SockInit(void)
170 int iVersionRequested
;
174 if (s_iInitCount
> 0) {
177 } else if (s_iInitCount
< 0)
178 return (s_iInitCount
);
180 /* s_iInitCount == 0. Do the initailization */
181 iVersionRequested
= MAKEWORD(2, 0);
183 err
= WSAStartup((WORD
) iVersionRequested
, &wsaData
);
187 return (s_iInitCount
);
190 if (LOBYTE(wsaData
.wVersion
) != 2 ||
191 HIBYTE(wsaData
.wVersion
) != 0) {
194 return (s_iInitCount
);
198 return (s_iInitCount
);
201 void Win32SockCleanup(void)
203 if (--s_iInitCount
== 0)
209 #endif /* ifdef _SQUID_MSWIN_ */
212 safe_str(const char *str
)
214 return str
? str
: "";
217 /* relaxed number format */
219 is_number(const char *str
)
221 return strspn(str
, "\t -+01234567890./\n") == strlen(str
);
225 xstrtok(char **str
, char del
)
228 char *p
= strchr(*str
, del
);
241 while (len
&& xisspace(tok
[len
- 1]))
244 while (xisspace(*tok
))
255 printf("<HR noshade size=\"1px\">\n");
256 printf("<ADDRESS>\n");
257 printf("Generated %s, by %s/%s@%s\n",
258 mkrfc1123(now
), progname
, VERSION
, getfullhostname());
259 printf("</ADDRESS></BODY></HTML>\n");
263 auth_html(const char *host
, int port
, const char *user_name
)
271 if (!host
|| !strlen(host
))
274 printf("Content-Type: text/html\r\n\r\n");
276 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
278 printf("<HTML><HEAD><TITLE>Cache Manager Interface</TITLE>\n");
280 printf("<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE></HEAD>\n");
282 printf("<BODY><H1>Cache Manager Interface</H1>\n");
284 printf("<P>This is a WWW interface to the instrumentation interface\n");
286 printf("for the Squid object cache.</P>\n");
288 printf("<HR noshade size=\"1px\">\n");
290 printf("<FORM METHOD=\"POST\" ACTION=\"%s\">\n", script_name
);
292 printf("<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"1\">\n");
295 fp
= fopen("cachemgr.conf", "r");
298 fp
= fopen(DEFAULT_CACHEMGR_CONFIG
, "r");
302 char config_line
[BUFSIZ
];
304 while (fgets(config_line
, BUFSIZ
, fp
)) {
305 char *server
, *comment
;
306 strtok(config_line
, "\r\n");
308 if (config_line
[0] == '#')
311 if (config_line
[0] == '\0')
314 if ((server
= strtok(config_line
, " \t")) == NULL
)
317 if (strchr(server
, '*') || strchr(server
, '[') || strchr(server
, '?')) {
322 comment
= strtok(NULL
, "");
325 while (*comment
== ' ' || *comment
== '\t')
328 if (!comment
|| !*comment
)
332 printf("<TR><TH ALIGN=\"left\">Cache Server:</TH><TD><SELECT NAME=\"server\">\n");
335 printf("<OPTION VALUE=\"%s\"%s>%s</OPTION>\n", server
, (servers
|| *host
) ? "" : " SELECTED", comment
);
340 if (need_host
== 1 && !*host
)
344 printf("<OPTION VALUE=\"\"%s>Other</OPTION>\n", (*host
) ? " SELECTED" : "");
346 printf("</SELECT></TR>\n");
353 if (need_host
== 1 && !*host
)
356 printf("<TR><TH ALIGN=\"left\">Cache Host:</TH><TD><INPUT NAME=\"host\" ");
358 printf("size=\"30\" VALUE=\"%s\"></TD></TR>\n", host
);
360 printf("<TR><TH ALIGN=\"left\">Cache Port:</TH><TD><INPUT NAME=\"port\" ");
362 printf("size=\"30\" VALUE=\"%d\"></TD></TR>\n", port
);
365 printf("<TR><TH ALIGN=\"left\">Manager name:</TH><TD><INPUT NAME=\"user_name\" ");
367 printf("size=\"30\" VALUE=\"%s\"></TD></TR>\n", user_name
);
369 printf("<TR><TH ALIGN=\"left\">Password:</TH><TD><INPUT TYPE=\"password\" NAME=\"passwd\" ");
371 printf("size=\"30\" VALUE=\"\"></TD></TR>\n");
373 printf("</TABLE><BR CLEAR=\"all\">\n");
375 printf("<INPUT TYPE=\"submit\" VALUE=\"Continue...\">\n");
383 error_html(const char *msg
)
385 printf("Content-Type: text/html\r\n\r\n");
386 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
387 printf("<HTML><HEAD><TITLE>Cache Manager Error</TITLE>\n");
388 printf("<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE></HEAD>\n");
389 printf("<BODY><H1>Cache Manager Error</H1>\n");
390 printf("<P>\n%s</P>\n", html_quote(msg
));
394 /* returns http status extracted from status line or -1 on parsing failure */
396 parse_status_line(const char *sline
, const char **statusStr
)
398 const char *sp
= strchr(sline
, ' ');
403 if (strncasecmp(sline
, "HTTP/", 5) || !sp
)
406 while (xisspace(*++sp
));
417 menu_url(cachemgr_request
* req
, const char *action
)
419 static char url
[1024];
420 snprintf(url
, sizeof(url
), "%s?host=%s&port=%d&user_name=%s&operation=%s&auth=%s",
424 safe_str(req
->user_name
),
426 safe_str(req
->pub_auth
));
431 munge_menu_line(const char *buf
, cachemgr_request
* req
)
439 static char html
[2 * 1024];
447 buf_copy
= x
= xstrdup(buf
);
449 a
= xstrtok(&x
, '\t');
451 d
= xstrtok(&x
, '\t');
453 p
= xstrtok(&x
, '\t');
455 a_url
= xstrdup(menu_url(req
, a
));
457 /* no reason to give a url for a disabled action */
458 if (!strcmp(p
, "disabled"))
459 snprintf(html
, sizeof(html
), "<LI type=\"circle\">%s (disabled)<A HREF=\"%s\">.</A>\n", d
, a_url
);
461 /* disable a hidden action (requires a password, but password is not in squid.conf) */
462 if (!strcmp(p
, "hidden"))
463 snprintf(html
, sizeof(html
), "<LI type=\"circle\">%s (hidden)<A HREF=\"%s\">.</A>\n", d
, a_url
);
465 /* disable link if authentication is required and we have no password */
466 if (!strcmp(p
, "protected") && !req
->passwd
)
467 snprintf(html
, sizeof(html
), "<LI type=\"circle\">%s (requires <a href=\"%s\">authentication</a>)<A HREF=\"%s\">.</A>\n",
468 d
, menu_url(req
, "authenticate"), a_url
);
470 /* highlight protected but probably available entries */
471 if (!strcmp(p
, "protected"))
472 snprintf(html
, sizeof(html
), "<LI type=\"square\"><A HREF=\"%s\"><font color=\"#FF0000\">%s</font></A>\n",
475 /* public entry or unknown type of protection */
477 snprintf(html
, sizeof(html
), "<LI type=\"disk\"><A HREF=\"%s\">%s</A>\n", a_url
, d
);
487 munge_other_line(const char *buf
, cachemgr_request
* req
)
489 static const char *ttags
[] = {"td", "th"};
491 static char html
[4096];
492 static int table_line_num
= 0;
493 static int next_is_header
= 0;
499 /* does it look like a table? */
501 if (!strchr(buf
, '\t') || *buf
== '\t') {
502 /* nope, just text */
503 snprintf(html
, sizeof(html
), "%s%s",
504 table_line_num
? "</table>\n<pre>" : "", html_quote(buf
));
509 /* start html table */
510 if (!table_line_num
) {
511 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "</pre><table cellpadding=\"2\" cellspacing=\"1\">\n");
516 is_header
= (!table_line_num
|| next_is_header
) && !strchr(buf
, ':') && !is_number(buf
);
518 ttag
= ttags
[is_header
];
521 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "<tr>");
523 /* substitute '\t' */
524 buf_copy
= x
= xstrdup(buf
);
526 if ((p
= strchr(x
, '\n')))
529 while (x
&& strlen(x
)) {
531 const char *cell
= xstrtok(&x
, '\t');
533 while (x
&& *x
== '\t') {
538 l
+= snprintf(html
+ l
, sizeof(html
) - l
, "<%s colspan=\"%d\" align=\"%s\">%s</%s>",
540 is_header
? "center" : is_number(cell
) ? "right" : "left",
541 html_quote(cell
), ttag
);
546 snprintf(html
+ l
, sizeof(html
) - l
, "</tr>\n");
547 next_is_header
= is_header
&& strstr(buf
, "\t\t");
553 munge_action_line(const char *_buf
, cachemgr_request
* req
)
555 static char html
[2 * 1024];
556 char *buf
= xstrdup(_buf
);
558 const char *action
, *description
;
561 if ((p
= strchr(x
, '\n')))
563 action
= xstrtok(&x
, '\t');
564 description
= xstrtok(&x
, '\t');
566 description
= action
;
569 snprintf(html
, sizeof(html
), " <a href=\"%s\">%s</a>", menu_url(req
, action
), description
);
574 read_reply(int s
, cachemgr_request
* req
)
580 char *tmpfile
= tempnam(NULL
, "tmp0000");
581 FILE *fp
= fopen(tmpfile
, "w+");
584 FILE *fp
= fdopen(s
, "r");
586 /* interpretation states */
588 isStatusLine
, isHeaders
, isActions
, isBodyStart
, isBody
, isForward
, isEof
, isForwardEof
, isSuccess
, isError
589 } istate
= isStatusLine
;
591 const char *action
= req
->action
;
592 const char *statusStr
= NULL
;
595 if (0 == strlen(req
->action
))
597 else if (0 == strcasecmp(req
->action
, "menu"))
615 while ((reply
=recv(s
, buf
, sizeof(buf
), 0)) > 0)
616 fwrite(buf
, 1, reply
, fp
);
625 /* read reply interpreting one line at a time depending on state */
626 while (istate
< isEof
) {
627 if (!fgets(buf
, sizeof(buf
), fp
))
628 istate
= istate
== isForward
? isForwardEof
: isEof
;
633 /* get HTTP status */
634 /* uncomment the following if you want to debug headers */
635 /* fputs("\r\n\r\n", stdout); */
636 status
= parse_status_line(buf
, &statusStr
);
637 istate
= status
== 200 ? isHeaders
: isForward
;
638 /* if cache asks for authentication, we have to reset our info */
640 if (status
== 401 || status
== 407) {
642 status
= 403; /* Forbiden, see comments in case isForward: */
645 /* this is a way to pass HTTP status to the Web server */
647 printf("Status: %d %s", status
, statusStr
); /* statusStr has '\n' */
652 /* forward header field */
653 if (!strcmp(buf
, "\r\n")) { /* end of headers */
654 fputs("Content-Type: text/html\r\n", stdout
); /* add our type */
655 istate
= isBodyStart
;
658 if (strncasecmp(buf
, "Content-Type:", 13)) /* filter out their type */
664 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
666 printf("<HTML><HEAD><TITLE>CacheMgr@%s: %s</TITLE>\n",
667 req
->hostname
, action
);
669 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");
671 printf("</HEAD><BODY>\n");
674 printf("<H2><a href=\"%s\">Cache Manager</a> menu for %s:</H2>",
675 menu_url(req
, "authenticate"), req
->hostname
);
678 printf("<P><A HREF=\"%s\">%s</A>\n<HR noshade size=\"1px\">\n",
679 menu_url(req
, "menu"), "Cache Manager menu");
684 /* yes, fall through, we do not want to loose the first line */
687 if (strncmp(buf
, "action:", 7) == 0) {
689 fputs(munge_action_line(buf
+ 7, req
), stdout
);
695 printf("<HR noshade size=\"1px\">\n");
700 /* yes, fall through, we do not want to loose the first line */
703 /* interpret [and reformat] cache response */
706 fputs(munge_menu_line(buf
, req
), stdout
);
708 fputs(munge_other_line(buf
, req
), stdout
);
713 /* forward: no modifications allowed */
715 * Note: we currently do not know any way to get browser.reply to
716 * 401 to .cgi because web server filters out all auth info. Thus we
717 * disable authentication headers for now.
719 if (!strncasecmp(buf
, "WWW-Authenticate:", 17) || !strncasecmp(buf
, "Proxy-Authenticate:", 19)); /* skip */
730 printf("</table></PRE>\n");
739 /* indicate that we finished processing an "error" sequence */
745 printf("%s: internal bug: invalid state reached: %d", script_name
, istate
);
764 process_request(cachemgr_request
* req
)
767 char ipbuf
[MAX_IPSTRLEN
];
768 struct addrinfo
*AI
= NULL
;
773 static char buf
[2 * 1024];
776 auth_html(CACHEMGR_HOSTNAME
, CACHE_HTTP_PORT
, "");
780 if (req
->hostname
== NULL
) {
781 req
->hostname
= xstrdup(CACHEMGR_HOSTNAME
);
784 if (req
->port
== 0) {
785 req
->port
= CACHE_HTTP_PORT
;
788 if (req
->action
== NULL
) {
789 req
->action
= xstrdup("");
792 if (strcmp(req
->action
, "authenticate") == 0) {
793 auth_html(req
->hostname
, req
->port
, req
->user_name
);
797 if (!check_target_acl(req
->hostname
, req
->port
)) {
798 snprintf(buf
, 1024, "target %s:%d not allowed in cachemgr.conf\n", req
->hostname
, req
->port
);
803 S
= *gethostbyname(req
->hostname
);
805 if ( !S
.IsAnyAddr() ) {
807 } else if ((S
= req
->hostname
))
810 snprintf(buf
, 1024, "Unknown host: %s\n", req
->hostname
);
815 S
.SetPort(req
->port
);
820 if ((s
= socket( AI
->ai_family
, SOCK_STREAM
, 0)) < 0) {
822 if ((s
= socket(PF_INET
, SOCK_STREAM
, 0)) < 0) {
824 snprintf(buf
, 1024, "socket: %s\n", xstrerror());
829 if (connect(s
, AI
->ai_addr
, AI
->ai_addrlen
) < 0) {
830 snprintf(buf
, 1024, "connect %s: %s\n",
831 S
.ToURL(ipbuf
,MAX_IPSTRLEN
),
840 l
= snprintf(buf
, sizeof(buf
),
841 "GET cache_object://%s/%s HTTP/1.0\r\n"
843 "%s" /* Authentication info or nothing */
847 make_auth_header(req
));
848 if (write(s
, buf
, l
) < 0) {
849 fprintf(stderr
,"ERROR: (%d) writing request: '%s'\n", errno
, buf
);
851 debug("wrote request: '%s'\n", buf
);
853 return read_reply(s
, req
);
857 main(int argc
, char *argv
[])
860 cachemgr_request
*req
;
866 atexit(Win32SockCleanup
);
867 _setmode( _fileno( stdin
), _O_BINARY
);
868 _setmode( _fileno( stdout
), _O_BINARY
);
871 if ((s
= strrchr(argv
[0], '\\')))
874 if ((s
= strrchr(argv
[0], '/')))
877 progname
= xstrdup(s
+ 1);
879 progname
= xstrdup(argv
[0]);
881 if ((s
= getenv("SCRIPT_NAME")) != NULL
)
882 script_name
= xstrdup(s
);
885 while (argc
> 1 && args
[1][0] == '-') {
886 // const char *value = "";
887 char option
= args
[1][1];
893 #if 0 // unused for now.
894 if (strlen(args
[1]) > 2) {
896 } else if (argc
> 2) {
909 req
= read_request();
911 return process_request(req
);
915 read_post_request(void)
921 if ((s
= getenv("REQUEST_METHOD")) == NULL
)
924 if (0 != strcasecmp(s
, "POST"))
927 if ((s
= getenv("CONTENT_LENGTH")) == NULL
)
930 if ((len
= atoi(s
)) <= 0)
933 buf
= (char *)xmalloc(len
+ 1);
935 if (fread(buf
, len
, 1, stdin
) == 0)
944 read_get_request(void)
948 if ((s
= getenv("QUERY_STRING")) == NULL
)
954 static cachemgr_request
*
959 cachemgr_request
*req
;
964 if ((buf
= read_post_request()) != NULL
)
966 else if ((buf
= read_get_request()) != NULL
)
973 if (strlen(buf
) == 0 || strlen(buf
) == 4000)
976 if (strlen(buf
) == 0)
983 req
= (cachemgr_request
*)xcalloc(1, sizeof(cachemgr_request
));
985 for (s
= strtok(buf
, "&"); s
!= NULL
; s
= strtok(NULL
, "&")) {
988 if ((q
= strchr(t
, '=')) == NULL
)
997 if (0 == strcasecmp(t
, "server") && strlen(q
))
998 req
->server
= xstrdup(q
);
999 else if (0 == strcasecmp(t
, "host") && strlen(q
))
1000 req
->hostname
= xstrdup(q
);
1001 else if (0 == strcasecmp(t
, "port") && strlen(q
))
1002 req
->port
= atoi(q
);
1003 else if (0 == strcasecmp(t
, "user_name") && strlen(q
))
1004 req
->user_name
= xstrdup(q
);
1005 else if (0 == strcasecmp(t
, "passwd") && strlen(q
))
1006 req
->passwd
= xstrdup(q
);
1007 else if (0 == strcasecmp(t
, "auth") && strlen(q
))
1008 req
->pub_auth
= xstrdup(q
), decode_pub_auth(req
);
1009 else if (0 == strcasecmp(t
, "operation"))
1010 req
->action
= xstrdup(q
);
1013 if (req
->server
&& !req
->hostname
) {
1015 req
->hostname
= strtok(req
->server
, ":");
1017 if ((p
= strtok(NULL
, ":")))
1018 req
->port
= atoi(p
);
1022 debug("cmgr: got req: host: '%s' port: %d uname: '%s' passwd: '%s' auth: '%s' oper: '%s'\n",
1023 safe_str(req
->hostname
), req
->port
, safe_str(req
->user_name
), safe_str(req
->passwd
), safe_str(req
->pub_auth
), safe_str(req
->action
));
1028 /* Routines to support authentication */
1031 * Encodes auth info into a "public" form.
1032 * Currently no powerful encryption is used.
1035 make_pub_auth(cachemgr_request
* req
)
1037 static char buf
[1024];
1038 safe_free(req
->pub_auth
);
1039 debug("cmgr: encoding for pub...\n");
1041 if (!req
->passwd
|| !strlen(req
->passwd
))
1044 /* host | time | user | passwd */
1045 snprintf(buf
, sizeof(buf
), "%s|%d|%s|%s",
1048 req
->user_name
? req
->user_name
: "",
1051 debug("cmgr: pre-encoded for pub: %s\n", buf
);
1052 debug("cmgr: encoded: '%s'\n", base64_encode(buf
));
1054 req
->pub_auth
= xstrdup(base64_encode(buf
));
1058 decode_pub_auth(cachemgr_request
* req
)
1061 const char *host_name
;
1062 const char *time_str
;
1063 const char *user_name
;
1066 debug("cmgr: decoding pub: '%s'\n", safe_str(req
->pub_auth
));
1067 safe_free(req
->passwd
);
1069 if (!req
->pub_auth
|| strlen(req
->pub_auth
) < 4 + strlen(safe_str(req
->hostname
)))
1072 buf
= xstrdup(base64_decode(req
->pub_auth
));
1074 debug("cmgr: length ok\n");
1076 /* parse ( a lot of memory leaks, but that is cachemgr style :) */
1077 if ((host_name
= strtok(buf
, "|")) == NULL
)
1080 debug("cmgr: decoded host: '%s'\n", host_name
);
1082 if ((time_str
= strtok(NULL
, "|")) == NULL
)
1085 debug("cmgr: decoded time: '%s' (now: %d)\n", time_str
, (int) now
);
1087 if ((user_name
= strtok(NULL
, "|")) == NULL
)
1090 debug("cmgr: decoded uname: '%s'\n", user_name
);
1092 if ((passwd
= strtok(NULL
, "|")) == NULL
)
1095 debug("cmgr: decoded passwd: '%s'\n", passwd
);
1097 /* verify freshness and validity */
1098 if (atoi(time_str
) + passwd_ttl
< now
)
1101 if (strcasecmp(host_name
, req
->hostname
))
1104 debug("cmgr: verified auth. info.\n");
1107 xfree(req
->user_name
);
1109 req
->user_name
= xstrdup(user_name
);
1111 req
->passwd
= xstrdup(passwd
);
1117 reset_auth(cachemgr_request
* req
)
1119 safe_free(req
->passwd
);
1120 safe_free(req
->pub_auth
);
1124 make_auth_header(const cachemgr_request
* req
)
1126 static char buf
[1024];
1127 size_t stringLength
= 0;
1133 snprintf(buf
, sizeof(buf
), "%s:%s",
1134 req
->user_name
? req
->user_name
: "",
1137 str64
= base64_encode(buf
);
1139 stringLength
+= snprintf(buf
, sizeof(buf
), "Authorization: Basic %s\r\n", str64
);
1141 assert(stringLength
< sizeof(buf
));
1143 snprintf(&buf
[stringLength
], sizeof(buf
) - stringLength
, "Proxy-Authorization: Basic %s\r\n", str64
);
1149 check_target_acl(const char *hostname
, int port
)
1151 char config_line
[BUFSIZ
];
1154 fp
= fopen("cachemgr.conf", "r");
1157 fp
= fopen(DEFAULT_CACHEMGR_CONFIG
, "r");
1160 #ifdef CACHEMGR_HOSTNAME_DEFINED
1162 if (strcmp(hostname
, CACHEMGR_HOSTNAME
) == 0 && port
== CACHE_HTTP_PORT
)
1167 if (strcmp(hostname
, "localhost") == 0)
1170 if (strcmp(hostname
, getfullhostname()) == 0)
1178 while (fgets(config_line
, BUFSIZ
, fp
)) {
1180 strtok(config_line
, " \r\n\t");
1182 if (config_line
[0] == '#')
1185 if (config_line
[0] == '\0')
1188 if ((token
= strtok(config_line
, ":")) == NULL
)
1193 if (fnmatch(token
, hostname
, 0) != 0)
1198 if (strcmp(token
, hostname
) != 0)
1203 if ((token
= strtok(NULL
, ":")) != NULL
) {
1206 if (strcmp(token
, "*") == 0)
1208 ; /* Wildcard port specification */
1209 else if (strcasecmp(token
, "any") == 0)
1211 ; /* Wildcard port specification */
1212 else if (sscanf(token
, "%d", &i
) != 1)
1217 } else if (port
!= CACHE_HTTP_PORT
)