Current time: 12-27-2024, 12:10 AM Hello There, Guest! (LoginRegister)


Post Reply 
ispcp integration behavior
Author Message
sawoy Offline
Junior Member
*

Posts: 13
Joined: May 2007
Reputation: 1
Post: #1
ispcp integration behavior
Hi all,

have i a question:

why ispcp integrates into work server with rewriting some files ?
For example, /etc/hosts and /etc/resolv.conf.
Why it doesn't create any backup copies of these files ?


is it a incorrect behavior ? ot that should be by some ideology ?
05-27-2007 06:37 AM
Find all posts by this user Quote this message in a reply
joximu Offline
helper
*****
Moderators

Posts: 7,024
Joined: Jan 2007
Reputation: 92
Post: #2
RE: ispcp integration behavior
I agree...
05-27-2007 07:21 AM
Visit this user's website Find all posts by this user Quote this message in a reply
sawoy Offline
Junior Member
*

Posts: 13
Joined: May 2007
Reputation: 1
Post: #3
RE: ispcp integration behavior
here is a patch that solve this in simplest way.
i don't yet test it - it is just for example as possible solution...

Code:
# diff -updr /root/development/trunk/engine /work/
diff -updr /root/development/trunk/engine/ispcp_common_code.pl /work/ispcp_common_code.pl
--- /root/development/trunk/engine/ispcp_common_code.pl 2007-05-27 13:00:16.000000000 +0700
+++ /work/ispcp_common_code.pl  2007-05-27 12:50:27.000000000 +0700
@@ -87,6 +87,7 @@ BEGIN {
     }
}

+$main::backup_ext = '.ispcp_backup';

#$main::engine_debug = '_on_';

@@ -459,7 +460,7 @@ sub get_file {

sub store_file {

-    my ($fname, $fdata, $fuid, $fgid, $fperms) = @_;
+    my ($fname, $fdata, $fuid, $fgid, $fperms, $to_backup) = @_;

     push_el(\@main::el, 'store_file()', 'Starting...');

@@ -479,6 +480,23 @@ sub store_file {
         return -1;
     }

+    if ( ( -e $fname ) && $to_backup )
+    {
+        my $backup_extension = $main::backup_ext;
+       my $cmd = "$main::cfg{'CMD_CP'} -f $fname $fname$backup_extension";
+       my $rs = sys_command_rs($cmd);
+       if ($rs != 0)
+       {
+           push_el(
+                   \@main::el,
+                   ((caller(0))[3]) . '()',
+                   "ERROR: Can not create backup copy '$fname$backup_extension' of '$fname' - copying failed with '$rs'"
+            );
+
+           return -1;
+       }
+    }
+
     my $res = open(F, '>', $fname);

     if (!defined($res)) {
diff -updr /root/development/trunk/engine/setup/ispcp-setup /work/setup/ispcp-setup
--- /root/development/trunk/engine/setup/ispcp-setup    2007-05-27 13:00:17.000000000 +0700
+++ /work/setup/ispcp-setup     2007-05-27 12:31:16.000000000 +0700
@@ -1414,8 +1414,8 @@ sub setup_resolver {
        if ($main::cfg{'SECONDARY_DNS'} ne '') {
                $data .= "nameserver $main::cfg{'SECONDARY_DNS'}\n";
        }
-
-       $rs = store_file("/etc/resolv.conf", $data, 'root', 'root', 0644);
+       my $to_backup = 1;
+       $rs = store_file("/etc/resolv.conf", $data, 'root', 'root', 0644, $to_backup);

        return $rs if ($rs != 0);

@@ -1437,8 +1437,8 @@ sub setup_hosts {
        my $hostname_local = "$hostname.local";

        my $ip = $main::ua{'eth_ip'};
-
-       $rs = store_file("/etc/hosts", "\n# 'hosts' file configuration.\n\n127.0.0.1\t$hostname_local\tlocalhost\n$ip\t$hostname\t$host\n​::ffff:$ip\t$hostname\t$host\n::1\tip6-localhost ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\nff02::3\tip6-allhosts", 'root', 'root', 0644);
+        my $to_backup = 1;
+       $rs = store_file("/etc/hosts", "\n# 'hosts' file configuration.\n\n127.0.0.1\t$hostname_local\tlocalhost\n$ip\t$hostname\t$host\n​::ffff:$ip\t$hostname\t$host\n::1\tip6-localhost ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\nff02::3\tip6-allhosts", 'root', 'root', 0644, $to_backup);

        return $rs if ($rs != 0);
05-27-2007 04:10 PM
Find all posts by this user Quote this message in a reply
raphael Offline
Member
***

Posts: 474
Joined: Apr 2007
Reputation: 8
Post: #4
RE: ispcp integration behavior
@sawoy: that modification would generate many useless files.
05-28-2007 10:10 AM
Visit this user's website Find all posts by this user Quote this message in a reply
sawoy Offline
Junior Member
*

Posts: 13
Joined: May 2007
Reputation: 1
Post: #5
RE: ispcp integration behavior
raphael Wrote:@sawoy: that modification would generate many useless files.

Hm.
1. Now "many useless files" is 2.
2. Which solution can you offer ?

I think about 3 ways/solutions:
- backup all required for backup files
- analyze (parse) all required files and add only required by ISPCP lines [that requires understanding which lines are required at all]
- do not touch these files [supposed that administrator of server already set up hosts and resolv.conf ]
05-28-2007 02:13 PM
Find all posts by this user Quote this message in a reply
raphael Offline
Member
***

Posts: 474
Joined: Apr 2007
Reputation: 8
Post: #6
RE: ispcp integration behavior
I already developed a fix, but I haven't commited it because it seems like, at least, openbsd's sed doesn't support the -r argument, which I need.
What my solution does is: make backup of resolv.conf, strip from it all the nameserver lines, add new nameserver lines, save file.
05-29-2007 08:26 AM
Visit this user's website Find all posts by this user Quote this message in a reply
sawoy Offline
Junior Member
*

Posts: 13
Joined: May 2007
Reputation: 1
Post: #7
RE: ispcp integration behavior
ok. it is good.

have questions:
- why do not you use perl for platform-independent code ? why sed ?
- with this patch after installation my old preferences will work and my server will be able resolve domains properly ?
- do you fix it for hosts file ?
05-29-2007 08:41 AM
Find all posts by this user Quote this message in a reply
raphael Offline
Member
***

Posts: 474
Joined: Apr 2007
Reputation: 8
Post: #8
RE: ispcp integration behavior
sawoy Wrote:- why do not you use perl for platform-independent code ? why sed ?
Because I don't know perl, so I do what I can. The only problem with sed is that it seems (at least GNU's sed) doesn't support my regex if the -r param isn't passed (extended regex).
sawoy Wrote:- with this patch after installation my old preferences will work and my server will be able resolve domains properly ?
sure
sawoy Wrote:- do you fix it for hosts file ?
haven't done that yet, because I first want to find a real solution that applies to both cases.
05-29-2007 09:18 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)