Changeset 3171 in MondoRescue


Ignore:
Timestamp:
Jul 28, 2013, 7:37:35 PM (11 years ago)
Author:
Bruno Cornec
Message:
  • Fix #673 by improving single quote management in mr_stresc, and using single call for getfacl/getfattr and adding tests to test suite.
Location:
branches/3.0/mondo
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-devices.c

    r3169 r3171  
    28202820                mr_asprintf(&g_getfacl,"getfacl");
    28212821            }
     2822            log_it("Backup of extended attributes");
    28222823        }
    28232824// Interactive mode:
  • branches/3.0/mondo/src/common/libmondo-filelist.c

    r3141 r3171  
    470470        }
    471471        log_msg(8, "Analyzing %s", file_to_analyze);
    472         tmp = mr_stresc(file_to_analyze, " `$\\\"(){}[]'*?&|!#~", '\\');
    473         mr_asprintf(&strtmp, syscall_sprintf, tmp);
     472        tmp = mr_stresc(file_to_analyze, "'", '\\', '\'');
     473        mr_asprintf(&syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp);   // " MONDO_LOGFILE);
    474474        paranoid_free(tmp);
    475         mr_asprintf(&syscall, "%s 2>> /dev/null", strtmp);  // " MONDO_LOGFILE);
    476         paranoid_free(strtmp);
    477475        log_msg(20,"calling %s\n",syscall);
    478476        call_exe_and_pipe_output_to_fd(syscall, pout);
     
    496494        mr_free(command);
    497495
    498         retval =
    499             gen_aux_list(filelist, "getfacl --all-effective -P \"%s\"",
    500                          facl_fname);
     496        retval = gen_aux_list(filelist, "getfacl --all-effective -P ", facl_fname);
    501497    }
    502498    return (retval);
     
    513509        run_program_and_log_output(command, 8);
    514510        mr_free(command);
    515         retval =
    516             gen_aux_list(filelist, "getfattr --en=hex -m - -h -d \"%s\"",
    517                          fattr_fname);
     511        retval = gen_aux_list(filelist, "getfattr --en=hex -m - -h -d ", fattr_fname);
    518512    }
    519513    return (retval);
     
    13501344
    13511345    /* dir is needed when we pass it to the shell */
    1352     dir = mr_stresc(dir1, "`$\\\"(){}'[]&*?|!#~", '\\');
     1346    dir = mr_stresc(dir1, "'", '\\', '\'');
    13531347    p = strrchr(dir1, '/');
    13541348    if (p) {
  • branches/3.0/mondo/src/include/mr_str.h

    r2208 r3171  
    1616
    1717extern char *mr_strtok(char *instr, const char *delims, int *lastpos);
    18 extern char *mr_stresc(char *instr, char *toesc, const char escchr);
     18extern char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr);
    1919extern inline char *mr_date(void);
    2020extern void mr_strip_spaces(char *in_out);
  • branches/3.0/mondo/src/lib/mr_str.c

    r2972 r3171  
    1212
    1313#include "mr_mem.h"
     14
     15// to get bool type
     16#define _MY_STUFF_H_
     17#include "my-stuff.h"
    1418 
    1519/**
     
    6670 * @note this function allocates memory that needs to be freed by caller
    6771 **/
    68 char *mr_stresc(char *instr, char *toesc, const char escchr) {
     72char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr) {
    6973    char *inptr = NULL;
    7074    char *retstr = NULL;
     
    7276    char *escptr = NULL;
    7377    int cnt = 0;
     78    bool found = FALSE;
    7479
    7580    inptr = instr;
    76 
    7781    // Count how many characters need escaping.
    7882    while (*inptr != '\0') {
     
    8286                // Found it, skip the rest.
    8387                cnt++;
     88                // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars
     89                if (*inptr == specialchr) {
     90                    cnt += 2;
     91                }
    8492                break;
    8593            }
     
    8896        inptr++;
    8997    }
     98
    9099    inptr = instr;
    91 
    92100    retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1);
    93101    retptr = retstr;
     
    99107            if (*inptr == *escptr) {
    100108                // Found it, skip the rest.
    101                 *retptr = escchr;
    102                 retptr++;
     109                // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars
     110                if (*inptr == specialchr) {
     111                    *retptr = specialchr;
     112                    retptr++;
     113                    *retptr = escchr;
     114                    retptr++;
     115                    found = TRUE;
     116                } else {
     117                    *retptr = escchr;
     118                    retptr++;
     119                }
    103120                break;
    104121            }
     
    108125        retptr++;
    109126        inptr++;
     127        if (found) {
     128            // finish to put the remaining specialchr
     129            *retptr = specialchr;
     130            retptr++;
     131            found = FALSE;
     132        }
    110133    }
    111134    *retptr = '\0';
  • branches/3.0/mondo/test/test-mr_stresc.c

    r3170 r3171  
    88#include <stdlib.h>
    99#include "mr_str.h"
     10#include "mr_mem.h"
    1011#include "my-stuff.h"
    1112
     
    3940        for (i = 1; strl[i] != NULL ; i++) {
    4041                printf("Test %2d Original chain is %s\n",i,strl[i]);
    41                 p = mr_stresc(strl[i], "`$\\\"(){}'[]&*?|!#~", '\\');
    42                 printf("Test %2d Transformed chain is %s\n",i,p);
     42                p = mr_stresc(strl[i], "`$\\\"(){}'[]&*?|!#~", '\\', '"');
     43                printf("Test %2d Transformed chain (with \") is %s\n",i,p);
     44                mr_free(p);
     45                p = mr_stresc(strl[i], "`$\\\"(){}'[]&*?|!#~", '\\', '\'');
     46                printf("Test %2d Transformed chain (with ') is %s\n",i,p);
     47                mr_free(p);
    4348        }
    4449exit(0);
Note: See TracChangeset for help on using the changeset viewer.