Skip to content

Commit

Permalink
fixes in REST API to prevent server error and loops (bnc#553244)
Browse files Browse the repository at this point in the history
2.18.3

svn path=/branches/SuSE-Linux-11_2-Branch/registration/; revision=59551
  • Loading branch information
jdsn committed Nov 14, 2009
1 parent ffceb45 commit 3470852
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.18.2
2.18.3
6 changes: 6 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Sat Nov 14 04:42:20 CET 2009 - jdsn@suse.de

- fixes in REST API to prevent server error and loops (bnc#553244)
- 2.18.3

-------------------------------------------------------------------
Thu Nov 5 16:22:53 CET 2009 - jdsn@suse.de

Expand Down
37 changes: 30 additions & 7 deletions src/modules/YSR.pm
Expand Up @@ -189,6 +189,7 @@ sub statelessregister
my $self = shift;
my $ctx = shift;
my $arguments = shift;
my $SRregisterFlagFile = '/var/lib/yastws/registration_successful';

unless ( defined $ctx && ref($ctx) eq "HASH" )
{
Expand Down Expand Up @@ -260,8 +261,9 @@ sub statelessregister

if ( $exitcode == 0 )
{
# successful registration, so we need to save the last ZMD config
$self->saveLastZmdConfig();
$tasklist = $self->getTaskList() || {};

my $ret = $self->changerepos($tasklist);

if ( ref($ret) eq 'HASH' )
Expand All @@ -278,7 +280,23 @@ sub statelessregister
}

${$regret}{'success'} = 'Successfully ran registration';
${$regret}{'tasklist'} = XMLout( {'item' => $tasklist}, rootname => 'tasklist', KeyAttr => { item => "+ALIAS" }, NoAttr => 1);
# prepare the tasklist for XML conversion
foreach my $k (keys %{$tasklist})
{
if ( exists ${${$tasklist}{$k}}{'CATALOGS'} )
{
${${$tasklist}{$k}}{'CATALOGS'} = { 'catalog' => ${${$tasklist}{$k}}{'CATALOGS'} };
}
}
${$regret}{'tasklist'} = XMLout( {'item' => $tasklist}, rootname => 'tasklist', KeyAttr => { item => "+ALIAS", catalog => "+ALIAS" }, NoAttr => 1);

# write flagfile for successful registration
open(FLAGFILE, "> $SRregisterFlagFile");
print FLAGFILE localtime();
close FLAGFILE;

# to be on the safe side for a following registration request, we need to delete the context data
$self->del_ctx();
}
elsif ( $exitcode == 3 )
{
Expand Down Expand Up @@ -312,6 +330,7 @@ sub getregistrationconfig
my $SRconf = '/etc/suseRegister.conf';
my $SRcert = '/etc/ssl/certs/registration-server.pem';
my $SRcredentials = '/etc/zypp/credentials.d/NCCcredentials';
my $SRregisterFlagFile = '/var/lib/yastws/registration_successful';

my $url = undef;
my $cert = undef;
Expand Down Expand Up @@ -347,8 +366,8 @@ sub getregistrationconfig
}

# read the guid
if (-e $SRcredentials)
{
if ( -e $SRcredentials && -e $SRregisterFlagFile )
{
if (open(CRED, "< $SRcredentials") )
{
while(<CRED>)
Expand All @@ -366,6 +385,9 @@ sub getregistrationconfig
$cert = '' unless defined $cert;
$guid = '' unless defined $guid;

# delete a flagfile that might be still there if no guid is found
unlink($SRregisterFlagFile) if $guid eq '';

return { "regserverurl" => $url,
"regserverca" => $cert,
"guid" => $guid };
Expand Down Expand Up @@ -472,6 +494,7 @@ sub checkcatalogs

foreach $catalog (keys %{$todo})
{
$pAny = ${$todo}{$catalog};
if ( not defined $catalog || $catalog eq '' )
{
push @log, "A catalog returned by SuseRegister has no or an invalid name.";
Expand Down Expand Up @@ -499,7 +522,7 @@ sub checkcatalogs
elsif ( ${$pAny}{"TASK"} eq 'a' )
{
push @log, "According to SuseRegister a catalog has to be enabled: $catalog ($pService)";
my @zCMD = ('zypper', '--non-interactive', 'modifyrepo', '--enable', ${$pAny}{'ALIAS'});
my @zCMD = ('zypper', '--non-interactive', 'modifyrepo', '--enable', "${$pAny}{'ALIAS'}");
if ( system(@zCMD) == 0 )
{
push @log, "Enabled catalog: ${$pAny}{'ALIAS'} ($pService)";
Expand Down Expand Up @@ -623,7 +646,7 @@ sub changerepos
push @log, "According to SuseRegister a service should be left enabled: $pService";
push @log, "Now checking the catalogs of the service: $pService";

my @zCMD = ('zypper', '--non-interactive', 'refresh-services', $pService);
my @zCMD = ('zypper', '--non-interactive', 'refresh', '--services');
if ( system(@zCMD) == 0 )
{
push @log, "Successfully refreshed service: $pService";
Expand Down Expand Up @@ -655,7 +678,7 @@ sub changerepos

push @log, "Now checking the catalogs of the service: $pService";

my @zrCMD = ('zypper', '--non-interactive', 'refresh-services', $pService);
my @zrCMD = ('zypper', '--non-interactive', 'refresh', '--services');
if ( system(@zrCMD) == 0 )
{
push @log, "Successfully refreshed service: $pService";
Expand Down

0 comments on commit 3470852

Please sign in to comment.