Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. static void
  2. lock_dbg_cb(int mode, int type, const char *file, int line)
  3. {
  4.     static int modes[CRYPTO_NUM_LOCKS]; /* = {0, 0, ... } */
  5.     const char *errstr = NULL;
  6.     int rw;
  7.  
  8.     rw = mode & (CRYPTO_READ | CRYPTO_WRITE);
  9.     if (!((rw == CRYPTO_READ) || (rw == CRYPTO_WRITE))) {
  10.         errstr = "invalid mode";
  11.         goto err;
  12.     }
  13.     if (type < 0 || type >= CRYPTO_NUM_LOCKS) {
  14.         errstr = "type out of bounds";
  15.         goto err;
  16.     }
  17.     if (mode & CRYPTO_LOCK) {
  18.         if (modes[type]) {
  19.             errstr = "already locked";
  20.             /*
  21.              * must not happen in a single-threaded program
  22.              * (would deadlock)
  23.              */
  24.             goto err;
  25.         }
  26.         modes[type] = rw;
  27.     } else if (mode & CRYPTO_UNLOCK) {
  28.         if (!modes[type]) {
  29.             errstr = "not locked";
  30.             goto err;
  31.         }
  32.         if (modes[type] != rw) {
  33.             errstr = (rw == CRYPTO_READ) ?
  34.                 "CRYPTO_r_unlock on write lock" :
  35.                 "CRYPTO_w_unlock on read lock";
  36.         }
  37.         modes[type] = 0;
  38.     } else {
  39.         errstr = "invalid mode";
  40.         goto err;
  41.     }
  42.  
  43. err:
  44.     if (errstr) {
  45.         /* we cannot use bio_err here */
  46.         fprintf(stderr, "openssl (lock_dbg_cb): %s (mode=%d, type=%d) at %s:%d\n",
  47.             errstr, mode, type, file, line);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement