-/* $Id: zebraapi.c,v 1.185 2005-09-13 11:51:06 adam Exp $
+/* $Id: zebraapi.c,v 1.194 2005-11-09 11:51:29 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
zh->res = 0;
zh->session_res = res_open(zs->global_res, res);
zh->user_perm = 0;
+ zh->dbaccesslist = 0;
zh->reg_name = xstrdup ("");
zh->path_reg = 0;
{
const char *passwd_plain = 0;
const char *passwd_encrypt = 0;
+ const char *dbaccess = 0;
ZebraService zh = xmalloc(sizeof(*zh));
if (configName)
zebra_mutex_cond_init (&zh->session_lock);
passwd_plain = res_get (zh->global_res, "passwd");
passwd_encrypt = res_get (zh->global_res, "passwd.c");
+ dbaccess = res_get (zh->global_res, "dbaccess");
if (!passwd_plain && !passwd_encrypt)
zh->passwd_db = NULL;
- else
+ else
{
zh->passwd_db = passwd_db_open();
if (!zh->passwd_db)
passwd_db_file_crypt(zh->passwd_db, passwd_encrypt);
}
}
+
+ if (!dbaccess)
+ zh->dbaccess = NULL;
+ else {
+ zh->dbaccess = res_open(NULL, NULL);
+ if (res_read_file(zh->dbaccess, dbaccess) != ZEBRA_OK) {
+ yaz_log(YLOG_FATAL, "Failed to read %s", dbaccess);
+ return NULL;
+ }
+ }
+
zh->path_root = res_get (zh->global_res, "root");
zh->nmem = nmem_create();
zh->record_classes = recTypeClass_create (zh->global_res, zh->nmem);
reg->key_buf = 0;
- reg->keys.buf_max = 0;
- reg->keys.buf = 0;
- reg->keys.codec_handle = iscz1_start();
+ reg->keys = zebra_rec_keys_open();
+#if NATTR
+ reg->sortKeys = zebra_rec_keys_open();
+#else
reg->sortKeys.buf = 0;
reg->sortKeys.buf_max = 0;
-#if NATTR
- reg->sortKeys.codec_handle = iscz1_start();
#endif
reg->records = 0;
bfs_destroy (reg->bfs);
data1_destroy (reg->dh);
- xfree(reg->sortKeys.buf);
- xfree(reg->keys.buf);
- if (reg->keys.codec_handle)
- iscz1_stop(reg->keys.codec_handle);
+ zebra_rec_keys_close(reg->keys);
#if NATTR
- if (reg->sortKeys.codec_handle)
- iscz1_stop(reg->sortKeys.codec_handle);
+ zebra_rec_keys_close(reg->sortKeys);
+#else
+ xfree(reg->sortKeys.buf);
#endif
+
xfree(reg->key_buf);
xfree(reg->name);
xfree(reg);
xfree(zh->record_encoding);
+ xfree(zh->dbaccesslist);
+
for (i = 0; i < zh->num_basenames; i++)
xfree(zh->basenames[i]);
xfree(zh->basenames);
zh->errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
return ZEBRA_FAIL;
}
+
+ /* Check if the user has access to all databases (Seb) */
+ /* You could argue that this should happen later, after we have
+ * determined that the database(s) exist. */
+ if (zh->dbaccesslist) {
+ for (i = 0; i < num_bases; i++) {
+ const char *db = basenames[i];
+ char *p, *pp;
+ for (p = zh->dbaccesslist; p && *p; p = pp) {
+ int len;
+ if ((pp = strchr(p, '+'))) {
+ len = pp - p;
+ pp++;
+ }
+ else
+ len = strlen(p);
+ if (len == strlen(db) && !strncmp(db, p, len))
+ break;
+ }
+ if (!p) {
+ zh->errCode = YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED;
+ return ZEBRA_FAIL;
+ }
+ }
+ }
+
for (i = 0; i < zh->num_basenames; i++)
xfree(zh->basenames[i]);
xfree(zh->basenames);
ZEBRA_RES zebra_auth (ZebraHandle zh, const char *user, const char *pass)
{
const char *p;
+ const char *astring;
char u[40];
ZebraService zs;
xfree(zh->user_perm);
zh->user_perm = xstrdup(p ? p : "r");
+ /* Determine database access list */
+ astring = res_get(zs->dbaccess, user ? user : "anonymous");
+ if (astring)
+ zh->dbaccesslist = xstrdup(astring);
+ else
+ zh->dbaccesslist = 0;
+
/* users that don't require a password .. */
if (zh->user_perm && strchr(zh->user_perm, 'a'))
return ZEBRA_OK;
{
ASSERTZH;
assert(encoding);
- yaz_log(log_level, "zebra_octet_term_encoding");
+ yaz_log(log_level, "zebra_octet_term_encoding %s", encoding);
zebra_clearError(zh);
if (zh->iconv_to_utf8 != 0)