From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 13 Feb 2007 19:38:35 -0000 Subject: [Cluster-devel] cluster/fence/agents ipmilan/ipmilan.c manual/ ... Message-ID: <20070213193835.20013.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Branch: RHEL4 Changes by: rmccabe at sourceware.org 2007-02-13 19:38:33 Modified files: fence/agents/ipmilan: ipmilan.c fence/agents/manual: ack.c manual.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&only_with_tag=RHEL4&r1=1.1.2.7&r2=1.1.2.8 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/manual/ack.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.3&r2=1.3.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/manual/manual.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.3.2.1&r2=1.3.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/rackswitch/do_rack.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.1&r2=1.1.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/rackswitch/do_rack.h.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.1&r2=1.1.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/rps10/rps10.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.2&r2=1.2.2.1 --- cluster/fence/agents/ipmilan/ipmilan.c 2007/01/29 20:31:13 1.1.2.7 +++ cluster/fence/agents/ipmilan/ipmilan.c 2007/02/13 19:38:33 1.1.2.8 @@ -8,7 +8,7 @@ * * http://ipmitool.sourceforge.net * - * Copyright 2005 Red Hat, Inc. + * Copyright 2005-2007 Red Hat, Inc. * author: Lon Hohberger * * This library is free software; you can redistribute it and/or @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -758,7 +759,7 @@ cleanup(char *line, size_t linelen) { char *p; - int x; + size_t x; /* Remove leading whitespace. */ p = line; @@ -805,6 +806,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 *verbose) @@ -854,7 +856,12 @@ strncpy(passwd, val, pwlen); else passwd[0] = 0; - + } 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 */ @@ -901,6 +908,7 @@ printf(" -i IPMI Lan IP to talk to (deprecated, use -i)\n"); printf(" -p Password (if required) to control power on\n" " IPMI device\n"); +printf(" -S Script to retrieve password (if required)\n"); printf(" -l Username/Login (if required) to control power\n" " on IPMI device\n"); printf(" -o Operation to perform.\n"); @@ -909,14 +917,15 @@ 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= Same as -A\n"); -printf(" ipaddr=<#> Same as -a\n"); -printf(" passwd= Same as -p\n"); -printf(" login= Same as -u\n"); -printf(" option= Same as -o\n"); -printf(" operation= Same as -o\n"); -printf(" action= Same as -o\n"); -printf(" verbose Same as -v\n\n"); +printf(" auth= Same as -A\n"); +printf(" ipaddr=<#> Same as -a\n"); +printf(" passwd= Same as -p\n"); +printf(" passwd_script= Same as -S\n"); +printf(" login= Same as -u\n"); +printf(" option= Same as -o\n"); +printf(" operation= Same as -o\n"); +printf(" action= Same as -o\n"); +printf(" verbose Same as -v\n\n"); exit(1); } @@ -931,6 +940,7 @@ char passwd[64]; char user[64]; char op[64]; + char pwd_script[PATH_MAX]; int verbose=0; char *pname = basename(argv[0]); struct ipmi *i; @@ -938,6 +948,7 @@ memset(ip, 0, sizeof(ip)); memset(authtype, 0, sizeof(authtype)); memset(passwd, 0, sizeof(passwd)); + memset(pwd_script, 0, sizeof(pwd_script)); memset(user, 0, sizeof(user)); memset(op, 0, sizeof(op)); @@ -945,7 +956,7 @@ /* Parse command line options if any were specified */ - while ((opt = getopt(argc, argv, "A:a:i:l:p:o:vV?hH")) != EOF) { + while ((opt = getopt(argc, argv, "A:a:i:l:p:S:o:vV?hH")) != EOF) { switch(opt) { case 'A': /* Auth type */ @@ -964,6 +975,11 @@ /* password */ strncpy(passwd, optarg, sizeof(passwd)); break; + case 'S': + /* password script */ + strncpy(pwd_script, optarg, sizeof(pwd_script)); + pwd_script[sizeof(pwd_script) - 1] = '\0'; + break; case 'o': /* Operation */ strncpy(op, optarg, sizeof(op)); @@ -989,11 +1005,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), &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/manual/Attic/ack.c 2004/11/24 03:46:32 1.3 +++ cluster/fence/agents/manual/Attic/ack.c 2007/02/13 19:38:33 1.3.2.1 @@ -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 --- cluster/fence/agents/manual/Attic/manual.c 2005/01/10 03:28:47 1.3.2.1 +++ cluster/fence/agents/manual/Attic/manual.c 2007/02/13 19:38:33 1.3.2.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 --- 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:38:33 1.1.2.1 @@ -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 Physical plug number on RackSwitch\n" " -l Username\n" " -p Password\n" + " -S 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:38:33 1.1.2.1 @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include --- cluster/fence/agents/rps10/rps10.c 2004/11/16 19:39:35 1.2 +++ cluster/fence/agents/rps10/rps10.c 2007/02/13 19:38:33 1.2.2.1 @@ -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