Roxen.git / server / etc / modules / CertDB.pmod

version» Context lines:

Roxen.git/server/etc/modules/CertDB.pmod:495:   //! Registering a certificate or key file twice is a noop.   //!   //! @returns   //! Returns resulting keypair ids for the certificates (if any).   //!   //! @note   //! Return value differs from that of @[register_pem_file()].   //!   //! @seealso   //! @[register_pem_file()] - array(int) register_pem_files(array(string) pem_files, string|void password) + array(string) register_pem_files(array(string) pem_files, string|void password)   {    Sql.Sql db = DBManager.cached_get("roxen");       object privs = Privs("Reading cert file");       array(int) pem_ids = ({});    foreach(map(pem_files, String.trim_all_whites), string pem_file) {    if (pem_file == "") continue;       pem_ids += ({ low_register_pem_file(pem_file, password) });    }       privs = 0;       // FIXME: Move the following code to a separate function to improve API?    // (And instead just return pem_ids)? -  array(int) keypairs = ({}); +  array(string) keypair_names = ({});       foreach(Array.uniq(pem_ids), int pem_id) { -  keypairs += -  db->typed_query("SELECT cert_keypairs.id AS id" +  keypair_names += +  db->typed_query("SELECT cert_keypairs.name AS name"    " FROM cert_keys, cert_keypairs "    " WHERE pem_id = %d "    " AND cert_keypairs.key_id = cert_keys.id", -  pem_id)->id; +  pem_id)->name;    } -  return sort(keypairs); +  return Array.uniq(sort(keypair_names));   }      //! Get the private key and the list of certificates given a keypair id.   array(Crypto.Sign.State|array(string)) get_keypair(int keypair_id)   {    // FIXME: Consider having a keypair lookup cache.       Sql.Sql db = DBManager.cached_get("roxen");       array(sql_row) tmp =
Roxen.git/server/etc/modules/CertDB.pmod:643:    " WHERE id = %d",    tmp[0]->pem_id);    if (sizeof(tmp)) {    res->certs[-1]->pem_path = tmp[0]->path;    }    }    }       return res;   } +  + array(int) get_keypairs_by_name(string name) + { +  Sql.Sql db = DBManager.cached_get("roxen"); +  +  array(int) res = +  db->typed_query("SELECT cert_keypairs.id AS id " +  " FROM cert_keypairs, certs " +  " WHERE name = %s " +  " AND cert_id = certs.id " +  " AND pem_id IS NOT NULL " +  " ORDER BY expires ASC", name)->id; +  if (!sizeof(res)) { +  res = +  db->typed_query("SELECT cert_keypairs.id AS id " +  " FROM cert_keypairs, certs " +  " WHERE name = %s " +  " AND cert_id = certs.id " +  " ORDER BY expires DESC " +  " LIMIT 1", name)->id; +  } +  return res; + }