| PLEX86 | ||
|
Escaping backslash programming questionYou'll need to create a new file anyway. If all you want to do is delete that line... mvtmp-tempfileetc-syslog.conf Will do it. :-) You might want to save the original syslog.conf file too. It requires that "*.*" be at the start of the line, followed by any amount of white space made up of tabs or spaces, then your IP address, which can only be followed by any amount of white space. All lines meeting that specification will be deleted from the output. You could comment out those lines usingsed-, like this: If you are going to read youretc-syslog.conf file into a C program, there is little point in usinggrepto find the byte offset. Just read in the file line by line using fopen() and fgets(), parse each line for what you want to change, and write each line to a temporary file as you go (of course changing the one you want to be different). Then unlink your original and rename the temp file. I would highly recommend that you just code your own parsing function to look at the line one byte at a time, rather than try something like sscanf() or strtok(). Something like this (which for demonstration purposes outputs to stdout, and unlike the above examples allows the line to begin with white space): #define skipwsp(x) {while (*x == ' ' *x == '-t') {++x;}} int main(void) { char *s, ibufBUFSIZ; char *ipaddr = "173.23.62.12"; FILE *fp = fopen("-etc-syslog.conf", "r"); if (!fp) exit(EXITFAILURE); while (fgets(ibuf, sizeof ibuf, fp)) { if (NULL != (s = strchr(ibuf, '-n'))) { *s = '-0'; * remove newlines * } s = ibuf; skipwsp(s); * skip over white space * * test first token * if (*s != '*' strncmp(s, "*.*", 3)) { printf("%s-n", ibuf); continue; * next line * } Linux Security 7166 If you run redhat-fedora there is a program system-config-securitylevel you can use to configure a firewall rather easily. In the Gnome menus it's called... s += 3; skipwsp(s); * skip over white space * * test second token * printf("%s-n", ibuf); continue; * next line * } s += 1 + strlen(ipaddr);* skip compared token * skipwsp(s); * skip over white space too * if (*s != 0) { * test for end of the line * printf("%s-n", ibuf); continue; * next line * } #if 1 * insert appropriate line in place of target line * #endif } fclose(fp); return EXITSUCCESS; } --
|
||||
Linux groups from Newsgroups The #1 Usenet Provider on the Internet
C program for getting IP address of standlone box with no sockets 7164 |
||||