r4593 - trunk/varnish-cache/bin/varnishadm
phk at projects.linpro.no
phk at projects.linpro.no
Fri Feb 26 13:18:44 CET 2010
Author: phk
Date: 2010-02-26 13:18:44 +0100 (Fri, 26 Feb 2010)
New Revision: 4593
Modified:
trunk/varnish-cache/bin/varnishadm/varnishadm.1
trunk/varnish-cache/bin/varnishadm/varnishadm.c
Log:
Add "-S secret_file" support to varnishadm.
Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.1
===================================================================
--- trunk/varnish-cache/bin/varnishadm/varnishadm.1 2010-02-26 12:17:31 UTC (rev 4592)
+++ trunk/varnish-cache/bin/varnishadm/varnishadm.1 2010-02-26 12:18:44 UTC (rev 4593)
@@ -37,6 +37,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl t Ar timeout
+.Op Fl S Ar secret_file
.Fl T Ar address Ns : Ns Ar port
.Cm command
.Op Ar ...
@@ -51,6 +52,8 @@
.Bl -tag -width Fl
.It Fl t Ar timeout
Wait no longer than this many seconds for an operation to finish.
+.It Fl S Ar secret_file
+Specify the authentication secret file
.It Fl T Ar address Ns : Ns Ar port
Connect to the management interface at the specified address and port.
.El
Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c
===================================================================
--- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-02-26 12:17:31 UTC (rev 4592)
+++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-02-26 12:18:44 UTC (rev 4593)
@@ -32,6 +32,7 @@
#include "svnid.h"
SVNID("$Id$")
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -51,12 +52,13 @@
* returned
*/
static void
-telnet_mgt(const char *T_arg, int argc, char *argv[])
+telnet_mgt(const char *T_arg, const char *S_arg, int argc, char *argv[])
{
- int i;
+ int i, fd;
int sock;
unsigned status;
char *answer = NULL;
+ char buf[CLI_AUTH_RESPONSE_LEN];
sock = VSS_open(T_arg, timeout);
if (sock < 0) {
@@ -66,11 +68,25 @@
cli_readres(sock, &status, &answer, timeout);
if (status == CLIS_AUTH) {
- fprintf(stderr, "Authentication required\n");
- exit(1);
+ if (S_arg == NULL) {
+ fprintf(stderr, "Authentication required\n");
+ exit(1);
+ }
+ fd = open(S_arg, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Cannot open \"%s\": %s\n",
+ S_arg, strerror(errno));
+ exit (1);
+ }
+ CLI_response(fd, answer, buf);
+ AZ(close(fd));
+ write(sock, "auth ", 5);
+ write(sock, buf, strlen(buf));
+ write(sock, "\n", 1);
+ cli_readres(sock, &status, &answer, timeout);
}
if (status != CLIS_OK) {
- fprintf(stderr, "No pong received from server\n");
+ fprintf(stderr, "Rejected %u\n%s\n", status, answer);
exit(1);
}
@@ -106,7 +122,7 @@
usage(void)
{
fprintf(stderr,
- "usage: varnishadm [-t timeout] -T [address]:port command [...]\n");
+ "usage: varnishadm [-t timeout] [-S secretfile] -T [address]:port command [...]\n");
exit(1);
}
@@ -114,10 +130,14 @@
main(int argc, char *argv[])
{
const char *T_arg = NULL;
+ const char *S_arg = NULL;
int opt;
- while ((opt = getopt(argc, argv, "T:t:")) != -1) {
+ while ((opt = getopt(argc, argv, "S:T:t:")) != -1) {
switch (opt) {
+ case 'S':
+ S_arg = optarg;
+ break;
case 'T':
T_arg = optarg;
break;
@@ -135,7 +155,7 @@
if (T_arg == NULL || argc < 1)
usage();
- telnet_mgt(T_arg, argc, argv);
+ telnet_mgt(T_arg, S_arg, argc, argv);
exit(0);
}
More information about the varnish-commit
mailing list