/[imapfilter]/imapfilter/passwd.c
ViewVC logotype

Diff of /imapfilter/passwd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by lefcha, Sat Jul 13 22:31:37 2002 UTC revision 1.8.2.2 by lefcha, Mon May 26 08:14:17 2003 UTC
# Line 64  int encrypt_passwords(FILE * fd, account Line 64  int encrypt_passwords(FILE * fd, account
64    
65      /* Initialization vector. */      /* Initialization vector. */
66      c = ultostr(1 + random() % 100000000, 10);      c = ultostr(1 + random() % 100000000, 10);
67      memset(iv, '0', EVP_MAX_IV_LENGTH);      snprintf(iv, EVP_MAX_IV_LENGTH, "%08s", c);
68      memcpy(iv + 8 - strlen(c), c, min(8, strlen(c)));      fprintf(fd, "%s\n", iv);
     fprintf(fd, "%.8s\n", iv);  
69    
70      EVP_CIPHER_CTX_init(&ctx);      EVP_CIPHER_CTX_init(&ctx);
71    
# Line 94  int encrypt_passwords(FILE * fd, account Line 93  int encrypt_passwords(FILE * fd, account
93    
94      /* MD5 checksum of data. */      /* MD5 checksum of data. */
95      for (i = 0; i < mdl; i++)      for (i = 0; i < mdl; i++)
96          snprintf(2 + buf + i * 2, ENCRYPTION_BUF - i * 2, "%02x", mdv[i]);          snprintf(2 + buf + i * 2, ENCRYPTION_BUF - 3 - i * 2, "%02x", mdv[i]);
97    
98      EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf));      EVP_EncryptUpdate(&ctx, ebuf, &ebufl, buf, strlen(buf));
99      EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl);      EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl);
100      fwrite(bbuf, sizeof(char), bbufl, fd);      fwrite(bbuf, sizeof(char), bbufl, fd);
101    
102      EVP_EncryptFinal(&ctx, ebuf, &ebufl);      EVP_EncryptFinal(&ctx, ebuf, &ebufl);
103    
104      EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl);      EVP_EncodeUpdate(&bctx, bbuf, &bbufl, ebuf, ebufl);
105      EVP_EncodeFinal(&bctx, bbuf, &bbufl);      fwrite(bbuf, sizeof(char), bbufl, fd);
106    
107        EVP_EncodeFinal(&bctx, bbuf, &bbufl);
108      fwrite(bbuf, sizeof(char), bbufl, fd);      fwrite(bbuf, sizeof(char), bbufl, fd);
109    
110      EVP_CIPHER_CTX_cleanup(&ctx);      EVP_CIPHER_CTX_cleanup(&ctx);
# Line 212  void password_editor(void) Line 213  void password_editor(void)
213      char buf[LINE_MAX];      char buf[LINE_MAX];
214      char *c;      char *c;
215      char *p[2];      char *p[2];
216      account_t *a, *accts[EDITOR_PASSWORDS_MAX];      account_t *a, *accts[EDITOR_PASSWORDS_MAX + 1];
217    
218      if (!(flags & FLAG_BLANK_PASSWORD)) {      if (!(flags & FLAG_BLANK_PASSWORD)) {
219          error("imapfilter: no candidate passwords for encryption found\n");          error("imapfilter: no candidate passwords for encryption found\n");
# Line 220  void password_editor(void) Line 221  void password_editor(void)
221      }      }
222      q = 0;      q = 0;
223    
224      memset(accts, 0, EDITOR_PASSWORDS_MAX);      memset(accts, 0, (EDITOR_PASSWORDS_MAX + 1) * sizeof(account_t *));
225    
226      for (i = 0, a = accounts; i < EDITOR_PASSWORDS_MAX - 1 && a; a = a->next) {      for (i = 0, a = accounts; i < EDITOR_PASSWORDS_MAX && a; a = a->next) {
227          if (a->passwdattr == PASSWORD_NONE ||          if (a->passwdattr == PASSWORD_NONE ||
228              a->passwdattr == PASSWORD_ENCRYPTED)              a->passwdattr == PASSWORD_ENCRYPTED)
229              accts[i++] = a;              accts[i++] = a;
# Line 252  void password_editor(void) Line 253  void password_editor(void)
253                             accts[i]->username, accts[i]->password);                             accts[i]->username, accts[i]->password);
254              else if (*c == 'e') {              else if (*c == 'e') {
255                  n = atoi(++c);                  n = atoi(++c);
256                  if (!n || n < 1 || n > 128 || !accts[n - 1])                  if (!n || n < 1 || n > EDITOR_PASSWORDS_MAX || !accts[n - 1])
257                      break;                      break;
258                  accts[n - 1]->password[0] = 0;                  accts[n - 1]->password[0] = 0;
259                  printf("Enter new password: ");                  printf("Enter new password: ");
# Line 261  void password_editor(void) Line 262  void password_editor(void)
262                          *c = 0;                          *c = 0;
263              } else if (*c == 'c') {              } else if (*c == 'c') {
264                  n = atoi(++c);                  n = atoi(++c);
265                  if (!n || n < 1 || n > 128 || !accts[n - 1])                  if (!n || n < 1 || n > EDITOR_PASSWORDS_MAX || !accts[n - 1])
266                      break;                      break;
267                  accts[n - 1]->password[0] = 0;                  accts[n - 1]->password[0] = 0;
268              } else if (*c == 'p') {              } else if (*c == 'p') {

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.8.2.2

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26