]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/binpatch.cc
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sys/types.h>
37 static void imbue(char *pname
, const char *search
, const string
&replace
);
38 static string
stringerror();
39 static off_t
filesize(int fd
);
41 int main(int argc
, char **argv
)
44 cerr
<<"Syntax: binpatch binary configuration-directory"<<endl
;
48 imbue(argv
[1],"!@@SYSCONFDIR@@:",argv
[2]);
51 static void imbue(char *pname
, const char *search
, const string
&replace
)
53 int fd
=open(pname
, O_RDWR
);
55 cerr
<<"Unable to open executable read/write for imbuing: "<<stringerror()<<endl
;
59 void *ptr
=mmap(0,fs
,PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
60 if(ptr
==(caddr_t
)-1) {
61 cerr
<<"Unable to mmap executable read/write for imbuing: "<<stringerror()<<endl
;
68 if(*p
==*search
&& *(p
+1)==*(search
+1) && !memcmp(p
,search
,strlen(search
)))
72 cerr
<<"Cannot find marker in binary, not imbueing"<<endl
;
75 strcpy(p
+strlen(search
),replace
.c_str());
76 munmap(ptr
,filesize(fd
));
78 cerr
<<"Imbued configuration location '"<<replace
<<"'"<<endl
;
82 static off_t
filesize(int fd
)
88 static string
stringerror()
90 return strerror(errno
);