client/rhel/rhnsd/rhnsd.c | 57 +++++++++++++++++++++++++++++++++++++++----
client/rhel/rhnsd/rhnsd.init | 5 +++
client/rhel/rhnsd/rhnsd.spec | 5 +++
rel-eng/packages/rhnsd | 2 -
4 files changed, 62 insertions(+), 7 deletions(-)
New commits:
commit e503205a58e4500ca4e03e904eac569a38ceb093
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Fri Sep 25 14:44:16 2009 +0200
Automatic commit of package [rhnsd] release [4.5.14-1].
diff --git a/client/rhel/rhnsd/rhnsd.spec b/client/rhel/rhnsd/rhnsd.spec
index 1e84b89..0b08ba2 100644
--- a/client/rhel/rhnsd/rhnsd.spec
+++ b/client/rhel/rhnsd/rhnsd.spec
@@ -4,7 +4,7 @@ Group: System Environment/Base
Source0:
https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
URL:
https://fedorahosted.org/spacewalk
Name: rhnsd
-Version: 4.5.13
+Version: 4.5.14
Release: 1%{?dist}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@@ -63,6 +63,9 @@ rm -fr $RPM_BUILD_ROOT
%doc LICENSE
%changelog
+* Fri Sep 25 2009 Tomas Lestach <tlestach(a)redhat.com> 4.5.14-1
+- removed hardcoded systemid path (tlestach(a)redhat.com)
+
* Tue Sep 22 2009 Miroslav Suchý <msuchy(a)redhat.com> 4.5.13-1
- use macros
- pass CFLAGS on correct position
diff --git a/rel-eng/packages/rhnsd b/rel-eng/packages/rhnsd
index bb71d42..36cb2bf 100644
--- a/rel-eng/packages/rhnsd
+++ b/rel-eng/packages/rhnsd
@@ -1 +1 @@
-4.5.13-1 client/rhel/rhnsd/
+4.5.14-1 client/rhel/rhnsd/
commit 884632ce73d2bf1743e76a309e79a3b2520950f1
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Fri Sep 25 12:03:46 2009 +0200
removed hardcoded systemid path
diff --git a/client/rhel/rhnsd/rhnsd.c b/client/rhel/rhnsd/rhnsd.c
index ca5c1ae..5a21e70 100644
--- a/client/rhel/rhnsd/rhnsd.c
+++ b/client/rhel/rhnsd/rhnsd.c
@@ -26,9 +26,12 @@
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
+#include <regex.h>
#define RHN_CHECK "/usr/sbin/rhn_check" /* XXX: fix me */
-#define RHN_SYSID "/etc/sysconfig/rhn/systemid" /* XXX: hard coded paths are
evil */
+#define RHN_UP2DATE "/etc/sysconfig/rhn/up2date"
+
+#define MAX_PATH_SIZE 512
/* gettext stuff */
#define N_(msgid) (msgid)
@@ -73,6 +76,7 @@ static struct argp argp = {
static void termination_handler (int);
static int rhn_init(void);
static int rhn_do_action(void);
+static int parse_systemid_path(char* systemid_path, int systemid_path_length);
static void set_signal_handlers (void);
static void unset_signal_handlers (void);
@@ -316,14 +320,30 @@ static int rhn_do_action(void)
int child;
int retval;
int fds[2];
+ char systemid_path[MAX_PATH_SIZE] = {0};
/*
* before we do anything, check if a systemid has been created.
* if not, we aren't gonna even go through with this.
*/
- if (access(RHN_SYSID, R_OK)) {
- syslog(LOG_DEBUG, "%s does not exist or is unreadable", RHN_SYSID);
- return -1;
+
+ if (access(RHN_UP2DATE, R_OK))
+ {
+ syslog(LOG_DEBUG, "%s does not exist or is unreadable", RHN_UP2DATE);
+ return -1;
+ }
+
+ /* parse the systemid location from the up2date file */
+ if (parse_systemid_path(systemid_path, sizeof(systemid_path)))
+ {
+ syslog(LOG_DEBUG, "%s does not contain valid systemIdPath entry",
RHN_UP2DATE);
+ return -1;
+ }
+
+ if (access(systemid_path, R_OK))
+ {
+ syslog(LOG_DEBUG, "%s does not exist or is unreadable",
systemid_path);
+ return -1;
}
/* first, the child will have the stdout redirected */
@@ -452,3 +472,32 @@ static int rhn_do_action(void)
close(fds[1]);
return 0;
}
+
+#define MAX_CONFIG_LINE_SIZE (2*MAX_PATH_SIZE)
+#define SYSTEMID_NMATCH 2
+/* parse systemIdPath from the up2date configuration file */
+static int parse_systemid_path(char* systemid_path, int systemid_path_length)
+{
+ FILE* config_file;
+ regex_t re_systemIdPath;
+ regmatch_t submatch[SYSTEMID_NMATCH];
+
+
regcomp(&re_systemIdPath,"^[[:space:]]*systemIdPath[[:space:]]*=[[:space:]]*([[:print:]]+)",
REG_EXTENDED);
+ if (NULL != (config_file = fopen(RHN_UP2DATE, "r") ))
+ {
+ char line[MAX_CONFIG_LINE_SIZE];
+ while (NULL != fgets(line, MAX_CONFIG_LINE_SIZE, config_file))
+ {
+ int match_length = submatch[1].rm_eo - submatch[1].rm_so;
+ if (systemid_path_length < match_length)
+ match_length = systemid_path_length - 1;
+
+ strncpy(systemid_path, &line[submatch[1].rm_so], match_length);
+ systemid_path[match_length] = '\0';
+ return 0;
+ }
+ fclose(config_file);
+ }
+ return 1; /* file / key not found */
+}
+
diff --git a/client/rhel/rhnsd/rhnsd.init b/client/rhel/rhnsd/rhnsd.init
index 5c9cdbc..19dbc7d 100644
--- a/client/rhel/rhnsd/rhnsd.init
+++ b/client/rhel/rhnsd/rhnsd.init
@@ -35,7 +35,10 @@
# Sanity checks.
[ -x /usr/sbin/rhnsd ] || exit 6
-[ -f /etc/sysconfig/rhn/systemid ] || exit 6
+RHN_UP2DATE_FILE="/etc/sysconfig/rhn/up2date"
+[ -f $RHN_UP2DATE_FILE ] || exit 6
+RHN_SYSTEMID_FILE=`awk -F '=[[:space:]]*'
'/^[[:space:]]*systemIdPath[[:space:]]*=/ {print $2}' $RHN_UP2DATE_FILE`
+[ -f $RHN_SYSTEMID_FILE ] || exit 6
# Source function library.
. /etc/rc.d/init.d/functions