Commit c334faff authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add "-S secret_file" support to varnishadm.



git-svn-id: http://www.varnish-cache.org/svn/trunk@4593 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 31d14b18
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl t Ar timeout .Op Fl t Ar timeout
.Op Fl S Ar secret_file
.Fl T Ar address Ns : Ns Ar port .Fl T Ar address Ns : Ns Ar port
.Cm command .Cm command
.Op Ar ... .Op Ar ...
...@@ -51,6 +52,8 @@ The following options are available: ...@@ -51,6 +52,8 @@ The following options are available:
.Bl -tag -width Fl .Bl -tag -width Fl
.It Fl t Ar timeout .It Fl t Ar timeout
Wait no longer than this many seconds for an operation to finish. 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 .It Fl T Ar address Ns : Ns Ar port
Connect to the management interface at the specified address and port. Connect to the management interface at the specified address and port.
.El .El
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "svnid.h" #include "svnid.h"
SVNID("$Id$") SVNID("$Id$")
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -51,12 +52,13 @@ static double timeout = 5; ...@@ -51,12 +52,13 @@ static double timeout = 5;
* returned * returned
*/ */
static void 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; int sock;
unsigned status; unsigned status;
char *answer = NULL; char *answer = NULL;
char buf[CLI_AUTH_RESPONSE_LEN];
sock = VSS_open(T_arg, timeout); sock = VSS_open(T_arg, timeout);
if (sock < 0) { if (sock < 0) {
...@@ -66,11 +68,25 @@ telnet_mgt(const char *T_arg, int argc, char *argv[]) ...@@ -66,11 +68,25 @@ telnet_mgt(const char *T_arg, int argc, char *argv[])
cli_readres(sock, &status, &answer, timeout); cli_readres(sock, &status, &answer, timeout);
if (status == CLIS_AUTH) { if (status == CLIS_AUTH) {
fprintf(stderr, "Authentication required\n"); if (S_arg == NULL) {
exit(1); 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) { if (status != CLIS_OK) {
fprintf(stderr, "No pong received from server\n"); fprintf(stderr, "Rejected %u\n%s\n", status, answer);
exit(1); exit(1);
} }
...@@ -106,7 +122,7 @@ static void ...@@ -106,7 +122,7 @@ static void
usage(void) usage(void)
{ {
fprintf(stderr, fprintf(stderr,
"usage: varnishadm [-t timeout] -T [address]:port command [...]\n"); "usage: varnishadm [-t timeout] [-S secretfile] -T [address]:port command [...]\n");
exit(1); exit(1);
} }
...@@ -114,10 +130,14 @@ int ...@@ -114,10 +130,14 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
const char *T_arg = NULL; const char *T_arg = NULL;
const char *S_arg = NULL;
int opt; int opt;
while ((opt = getopt(argc, argv, "T:t:")) != -1) { while ((opt = getopt(argc, argv, "S:T:t:")) != -1) {
switch (opt) { switch (opt) {
case 'S':
S_arg = optarg;
break;
case 'T': case 'T':
T_arg = optarg; T_arg = optarg;
break; break;
...@@ -135,7 +155,7 @@ main(int argc, char *argv[]) ...@@ -135,7 +155,7 @@ main(int argc, char *argv[])
if (T_arg == NULL || argc < 1) if (T_arg == NULL || argc < 1)
usage(); usage();
telnet_mgt(T_arg, argc, argv); telnet_mgt(T_arg, S_arg, argc, argv);
exit(0); exit(0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment