[Cluster-devel] cluster/fence/agents ipmilan/ipmilan.c rackswi ...
rmccabe at sourceware.org
rmccabe at sourceware.org
Tue Feb 13 19:23:41 UTC 2007
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: rmccabe at sourceware.org 2007-02-13 19:23:40
Modified files:
fence/agents/ipmilan: ipmilan.c
fence/agents/rackswitch: do_rack.c do_rack.h
fence/agents/rps10: rps10.c
Log message:
Support the "passwd_script" parameter in the C fence agents.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/ipmilan/ipmilan.c.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/rackswitch/do_rack.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/rackswitch/do_rack.h.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/rps10/rps10.c.diff?cvsroot=cluster&r1=1.2&r2=1.3
--- cluster/fence/agents/ipmilan/ipmilan.c 2007/01/29 20:34:38 1.10
+++ cluster/fence/agents/ipmilan/ipmilan.c 2007/02/13 19:23:40 1.11
@@ -8,7 +8,7 @@
*
* http://ipmitool.sourceforge.net
*
- * Copyright 2005 Red Hat, Inc.
+ * Copyright 2005-2007 Red Hat, Inc.
* author: Lon Hohberger <lhh at redhat.com>
*
* This library is free software; you can redistribute it and/or
@@ -32,6 +32,7 @@
#include <signal.h>
#include <string.h>
#include <errno.h>
+#include <limits.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <libintl.h>
@@ -765,7 +766,7 @@
cleanup(char *line, size_t linelen)
{
char *p;
- int x;
+ size_t x;
/* Remove leading whitespace. */
p = line;
@@ -812,6 +813,7 @@
get_options_stdin(char *ip, size_t iplen,
char *authtype, size_t atlen,
char *passwd, size_t pwlen,
+ char *pwd_script, size_t pwd_script_len,
char *user, size_t userlen,
char *op, size_t oplen,
int *lanplus, int *verbose)
@@ -862,14 +864,18 @@
else
passwd[0] = 0;
- } else if (!strcasecmp(name, "user") ||
- !strcasecmp(name, "login")) {
+ } else if (!strcasecmp(name, "passwd_script")) {
+ if (val) {
+ strncpy(pwd_script, val, pwd_script_len);
+ pwd_script[pwd_script_len - 1] = '\0';
+ } else
+ pwd_script[0] = '\0';
+ } else if (!strcasecmp(name, "user") || !strcasecmp(name, "login")) {
/* username */
if (val)
strncpy(user, val, userlen);
else
user[0] = 0;
-
} else if (!strcasecmp(name, "lanplus")) {
(*lanplus) = 1;
} else if (!strcasecmp(name, "option") ||
@@ -905,6 +911,8 @@
printf(" -i <ipaddr> IPMI Lan IP to talk to (deprecated, use -i)\n");
printf(" -p <password> Password (if required) to control power on\n"
" IPMI device\n");
+printf(" -P Use Lanplus\n");
+printf(" -S <path> Script to retrieve password (if required)\n");
printf(" -l <login> Username/Login (if required) to control power\n"
" on IPMI device\n");
printf(" -o <op> Operation to perform.\n");
@@ -913,14 +921,16 @@
printf(" -v Verbose mode\n\n");
printf("If no options are specified, the following options will be read\n");
printf("from standard input (one per line):\n\n");
-printf(" auth=<auth> Same as -A\n");
-printf(" ipaddr=<#> Same as -a\n");
-printf(" passwd=<pass> Same as -p\n");
-printf(" login=<login> Same as -u\n");
-printf(" option=<op> Same as -o\n");
-printf(" operation=<op> Same as -o\n");
-printf(" action=<op> Same as -o\n");
-printf(" verbose Same as -v\n\n");
+printf(" auth=<auth> Same as -A\n");
+printf(" ipaddr=<#> Same as -a\n");
+printf(" passwd=<pass> Same as -p\n");
+printf(" passwd_script=<path> Same as -S\n");
+printf(" lanplus Same as -P\n");
+printf(" login=<login> Same as -u\n");
+printf(" option=<op> Same as -o\n");
+printf(" operation=<op> Same as -o\n");
+printf(" action=<op> Same as -o\n");
+printf(" verbose Same as -v\n\n");
exit(1);
}
@@ -935,6 +945,7 @@
char passwd[64];
char user[64];
char op[64];
+ char pwd_script[PATH_MAX] = { 0, };
int lanplus=0;
int verbose=0;
char *pname = basename(argv[0]);
@@ -950,7 +961,7 @@
/*
Parse command line options if any were specified
*/
- while ((opt = getopt(argc, argv, "A:a:i:l:p:Po:vV?hH")) != EOF) {
+ while ((opt = getopt(argc, argv, "A:a:i:l:p:S:Po:vV?hH")) != EOF) {
switch(opt) {
case 'A':
/* Auth type */
@@ -972,6 +983,10 @@
case 'P':
lanplus = 1;
break;
+ case 'S':
+ strncpy(pwd_script, optarg, sizeof(pwd_script));
+ pwd_script[sizeof(pwd_script) - 1] = '\0';
+ break;
case 'o':
/* Operation */
strncpy(op, optarg, sizeof(op));
@@ -997,11 +1012,33 @@
if (get_options_stdin(ip, sizeof(ip),
authtype, sizeof(authtype),
passwd, sizeof(passwd),
+ pwd_script, sizeof(pwd_script),
user, sizeof(user),
op, sizeof(op), &lanplus, &verbose) != 0)
return 1;
}
+ if (pwd_script[0] != '\0') {
+ char pwd_buf[1024];
+ FILE *fp;
+ fp = popen(pwd_script, "r");
+ if (fp != NULL) {
+ ssize_t len = fread(pwd_buf, 1, sizeof(pwd_buf), fp);
+ if (len > 0) {
+ char *p;
+ p = strchr(pwd_buf, '\n');
+ if (p != NULL)
+ *p = '\0';
+ p = strchr(pwd_buf, '\r');
+ if (p != NULL)
+ *p = '\0';
+ strncpy(passwd, pwd_buf, sizeof(passwd));
+ passwd[sizeof(passwd) - 1] = '\0';
+ }
+ pclose(fp);
+ }
+ }
+
/*
Validate the operating parameters
*/
--- cluster/fence/agents/rackswitch/do_rack.c 2004/06/24 08:53:14 1.1
+++ cluster/fence/agents/rackswitch/do_rack.c 2007/02/13 19:23:40 1.2
@@ -2,7 +2,7 @@
*******************************************************************************
**
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
-** Copyright (C) 2004 Red Hat, Inc. All rights reserved.
+** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
@@ -24,6 +24,7 @@
char password[256];
char arg[256];
char name[256];
+char pwd_script[PATH_MAX] = { 0, };
char readbuf[MAXBUF];
char writebuf[MAXBUF];
@@ -159,6 +160,7 @@
" -n <dec num> Physical plug number on RackSwitch\n"
" -l <string> Username\n"
" -p <string> Password\n"
+ " -S <path> Script to retrieve password\n"
" -v Verbose\n"
" -q Quiet\n"
" -V Version information\n", pname);
@@ -175,7 +177,7 @@
/*
* Command line input
*/
- while ((c = getopt(argc, argv, "ha:n:l:p:vqVd")) != -1)
+ while ((c = getopt(argc, argv, "ha:n:l:p:S:vqVd")) != -1)
{
switch(c)
{
@@ -199,6 +201,11 @@
strncpy(password,optarg,254);
break;
+ case 'S':
+ strncpy(pwd_script, optarg, sizeof(pwd_script));
+ pwd_script[sizeof(pwd_script) - 1] = '\0';
+ break;
+
case 'v':
verbose_flag = 1;
break;
@@ -265,10 +272,37 @@
if (!strcmp(arg, "password"))
strcpy(password, value);
+
+ if (!strcasecmp(arg, "passwd_script")) {
+ strncpy(pwd_script, optarg, sizeof(pwd_script));
+ pwd_script[sizeof(pwd_script) - 1] = '\0';
+ }
}
errno = 0;
}
+
+ if (pwd_script[0] != '\0') {
+ FILE *fp;
+ char pwd_buf[1024];
+
+ fp = popen(pwd_script, "r");
+ if (fp != NULL) {
+ ssize_t len = fread(pwd_buf, 1, sizeof(pwd_buf), fp);
+ if (len > 0) {
+ char *p;
+ p = strchr(pwd_buf, '\n');
+ if (p != NULL)
+ *p = '\0';
+ p = strchr(pwd_buf, '\r');
+ if (p != NULL)
+ *p = '\0';
+ strncpy(password, pwd_buf, sizeof(password));
+ password[sizeof(password) - 1] = '\0';
+ }
+ pclose(fp);
+ }
+ }
}
static void sig_alarm(int sig)
--- cluster/fence/agents/rackswitch/do_rack.h 2004/06/24 08:53:14 1.1
+++ cluster/fence/agents/rackswitch/do_rack.h 2007/02/13 19:23:40 1.2
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
--- cluster/fence/agents/rps10/rps10.c 2004/11/16 19:39:35 1.2
+++ cluster/fence/agents/rps10/rps10.c 2007/02/13 19:23:40 1.3
@@ -1,5 +1,5 @@
/*
- Copyright Red Hat, Inc. 2002-2004
+ Copyright Red Hat, Inc. 2002-2007
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
More information about the Cluster-devel
mailing list