Drop current code and make it fail by default ENGINE-451
authorClaudio Luck <claudio.luck@pep.foundation>
Sat, 11 Aug 2018 22:58:23 +0200
branchENGINE-451
changeset 280945ebfd77285d
parent 2798 e0abb44b8098
child 2810 9ae82b72ca33
Drop current code and make it fail by default
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Wed Aug 01 16:34:38 2018 +0200
     1.2 +++ b/src/pgp_gpg.c	Sat Aug 11 22:58:23 2018 +0200
     1.3 @@ -25,92 +25,10 @@
     1.4      return (int)((((str_ptr_and_bit*)(a))->key) - (((str_ptr_and_bit*)(b))->key));
     1.5  }
     1.6  
     1.7 -static bool write_old_conf_file(const char* old_fname) {
     1.8 -    if (!old_fname)
     1.9 -        return NULL;
    1.10 -        
    1.11 -    const unsigned int MAX_OPEN_TRIES = 20;
    1.12 -    const unsigned int MAX_DIGITS = 2; // cheaper than using math to sort out the MAX TRIES for a hotfix.
    1.13 -    unsigned int curr_attempt = 0;
    1.14 -    const char* old_ext = ".pep.old";    
    1.15 -    // name + . + num + old_ext + \0 - this is unoptimised for clarity.
    1.16 -    size_t buf_size = strlen(old_fname) + 1 + MAX_DIGITS + strlen(old_ext) + 1;
    1.17 -    char* buf = (char*)calloc(buf_size, 1);
    1.18 -    
    1.19 -    while (curr_attempt < MAX_OPEN_TRIES) {
    1.20 -        strlcpy(buf, old_fname, buf_size);
    1.21 -        strlcat(buf, ".", buf_size);
    1.22 -        unsigned int num_index = strlen(buf);
    1.23 -        sprintf(buf + num_index, "%d", curr_attempt);
    1.24 -        strlcat(buf, old_ext, buf_size);
    1.25 -    
    1.26 -        // Attn Claudio: Fopen vs. open is a portability choice here, consistent
    1.27 -        // with usage throughout the rest of the engine.
    1.28 -        FILE* test = Fopen(buf, "r");
    1.29 -        if (!test) 
    1.30 -            break;
    1.31 -        
    1.32 -        Fclose(test);
    1.33 -        curr_attempt++;
    1.34 -    }                
    1.35 -    
    1.36 -    if (curr_attempt >= MAX_OPEN_TRIES)
    1.37 -        return false;
    1.38 -    
    1.39 -    FILE* input = Fopen(old_fname, "r");    
    1.40 -    if (!input)
    1.41 -        return false;
    1.42 -        
    1.43 -    FILE* output = Fopen(buf, "w");
    1.44 -    if (!output) {
    1.45 -        Fclose(input);
    1.46 -        return false;
    1.47 -    }
    1.48 -    
    1.49 -    static char read_buf[MAX_LINELENGTH];
    1.50 -
    1.51 -//     const char* line_end;
    1.52 -// #ifdef WIN32
    1.53 -//     line_end = "\r\n";
    1.54 -// #else
    1.55 -//     line_end = "\n";
    1.56 -// #endif    
    1.57 -
    1.58 -    int success = 0;
    1.59 -    char* s = NULL;
    1.60 -    
    1.61 -    while ((s = Fgets(read_buf, MAX_LINELENGTH, input))) {
    1.62 -        success = Fprintf(output, "%s", s);        
    1.63 -        assert(success >= 0);
    1.64 -        if (success < 0)
    1.65 -            return false;
    1.66 -    }
    1.67 -
    1.68 -    Fclose(output);
    1.69 -    Fclose(input);
    1.70 -    return true;
    1.71 -}
    1.72 -
    1.73  // This is in response to ENGINE-427. We should NOT be aiming to keep this here.
    1.74  bool quickfix_config(stringlist_t* keys, const char* config_file_path) {
    1.75 -    static char buf[MAX_LINELENGTH];
    1.76 -    size_t num_keys = stringlist_length(keys);
    1.77 -
    1.78 -    if (!write_old_conf_file(config_file_path))
    1.79 -        return false;
    1.80 -        
    1.81 -    // Open old conf file
    1.82 -    FILE *f = Fopen(config_file_path, "r");    
    1.83 -       
    1.84 -    if (f == NULL)
    1.85 -        return false;
    1.86 -
    1.87 -    int i;
    1.88 -    stringlist_t* _k;
    1.89 -    stringlist_t* lines = new_stringlist(NULL);
    1.90 -    int found = 0;
    1.91 -
    1.92 -    char* s = NULL;
    1.93 +    return false;
    1.94 +#if 0
    1.95  
    1.96      // Go through every line in the file
    1.97      while ((s = Fgets(buf, MAX_LINELENGTH, f))) {
    1.98 @@ -265,56 +183,7 @@
    1.99          free(found_keys);
   1.100          found_keys = NULL;
   1.101      } // End of file
   1.102 -    
   1.103 -    int ret = Fclose(f);
   1.104 -    assert(ret == 0);
   1.105 -    if (ret != 0)
   1.106 -        return false;
   1.107 -
   1.108 -    // then write all lines to file.
   1.109 -    const char* line_end;
   1.110 -#ifdef WIN32
   1.111 -    line_end = "\r\n";
   1.112 -#else
   1.113 -    line_end = "\n";
   1.114 -#endif    
   1.115 -
   1.116 -    size_t cf_path_len = strlen(config_file_path);
   1.117 -    size_t new_buf_size = cf_path_len + 8; // + pep.new\0
   1.118 -    char* temp_config_path_fname = (char*)calloc(new_buf_size, 1);
   1.119 -    if (!temp_config_path_fname)
   1.120 -        return false;
   1.121 -    strlcpy(temp_config_path_fname, config_file_path, new_buf_size);
   1.122 -    strlcat(temp_config_path_fname, ".pep.new", new_buf_size);
   1.123 -        
   1.124 -    // Ok, now open the thing for writing.
   1.125 -    f = Fopen(temp_config_path_fname, "w");
   1.126 -    
   1.127 -    assert(f);
   1.128 -    if (f == NULL)
   1.129 -        return false;
   1.130 -  
   1.131 -    stringlist_t* cur_string;
   1.132 -    
   1.133 -    for (cur_string = lines; cur_string; cur_string = cur_string->next) {
   1.134 -        ret = Fprintf(f, "%s%s", cur_string->value, line_end);
   1.135 -        assert(ret >= 0);
   1.136 -        if (ret < 0)
   1.137 -            return false;
   1.138 -    }
   1.139 -    free_stringlist(lines); // FIXME: memory
   1.140 -    
   1.141 -    ret = Fclose(f);
   1.142 -    assert(ret == 0);
   1.143 -    if (ret != 0)
   1.144 -        return false;
   1.145 -
   1.146 -    ret = rename(temp_config_path_fname, config_file_path);
   1.147 -    assert(ret == 0);
   1.148 -    if (ret != 0)
   1.149 -        return false;
   1.150 -
   1.151 -    return true;
   1.152 +#endif
   1.153  }
   1.154  
   1.155  static bool ensure_config_values(stringlist_t *keys, stringlist_t *values, const char* config_file_path)