X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=0b854ea60dbc82bd1f478d8720201754b8a05f24;hb=433f7360a01640cfdbe09ce7ae19f3319b348bb3;hp=e4ea55574962a5e9a704ce96efef549787b50b09;hpb=2a6f64379961f30bfe6376964ce279ab5242da1f;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index e4ea555..0b854ea 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.116 2004-01-22 11:27:21 adam Exp $ +/* $Id: zebraapi.c,v 1.120 2004-07-28 08:15:45 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -77,8 +77,8 @@ static void zebra_flush_reg (ZebraHandle zh) zh->errCode=0; zebraExplain_flush (zh->reg->zei, zh); - extract_flushWriteKeys (zh); - zebra_index_merge (zh); + extract_flushWriteKeys (zh,1 /* final */); + zebra_index_merge (zh ); } static struct zebra_register *zebra_register_open (ZebraService zs, @@ -108,6 +108,7 @@ ZebraHandle zebra_open (ZebraService zs) zh->errCode = 0; zh->errString = 0; zh->res = 0; + zh->user_perm = 0; zh->reg_name = xstrdup (""); zh->path_reg = 0; @@ -146,7 +147,12 @@ ZebraHandle zebra_open (ZebraService zs) return zh; } -ZebraService zebra_start (const char *configName, Res def_res, Res over_res) +ZebraService zebra_start (const char *configName) +{ + return zebra_start_res(configName, 0, 0); +} + +ZebraService zebra_start_res (const char *configName, Res def_res, Res over_res) { Res res; @@ -258,6 +264,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, reg->zei = 0; reg->matchDict = 0; reg->key_file_no = 0; + reg->ptr_i=0; zebraRankInstall (reg, rank1_class); zebraRankInstall (reg, rankzv_class); @@ -507,6 +514,7 @@ int zebra_close (ZebraHandle zh) } zebra_mutex_cond_unlock (&zs->session_lock); xfree (zh->reg_name); + xfree (zh->user_perm); zh->service=0; /* more likely to trigger an assert */ xfree (zh->path_reg); xfree (zh); @@ -918,10 +926,10 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, return Z_DeleteStatus_systemProblemAtTarget; switch (function) { - case Z_DeleteRequest_list: + case Z_DeleteResultSetRequest_list: resultSetDestroy (zh, num_setnames, setnames, statuses); break; - case Z_DeleteRequest_all: + case Z_DeleteResultSetRequest_all: resultSetDestroy (zh, -1, 0, statuses); break; } @@ -973,18 +981,25 @@ void zebra_clearError(ZebraHandle zh) int zebra_auth (ZebraHandle zh, const char *user, const char *pass) { + const char *p; + char u[40]; ZebraService zs; + ASSERTZH; - yaz_log(LOG_API,"zebra_auth u=%s p=%s",user,pass); zh->errCode=0; zs= zh->service; + + sprintf(u, "perm.%.30s", user ? user : "anonymous"); + p = res_get(zs->global_res, u); + xfree (zh->user_perm); + zh->user_perm = xstrdup(p ? p : "r"); + + /* users that don't require a password .. */ + if (zh->user_perm && strchr(zh->user_perm, 'a')) + return 0; + if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass)) - { - logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS"); return 0; - } - - logf(LOG_APP,"AUTHFAIL:%s", user?user:"ANONYMOUS"); return 1; } @@ -997,7 +1012,8 @@ int zebra_admin_import_begin (ZebraHandle zh, const char *database, zh->errCode=0; if (zebra_select_database(zh, database)) return 1; - zebra_begin_trans (zh, 1); + if (zebra_begin_trans (zh, 1)) + return 1; return 0; } @@ -1068,7 +1084,8 @@ int zebra_admin_exchange_record (ZebraHandle zh, memcpy (recid_z, recid_buf, recid_len); recid_z[recid_len] = 0; - zebra_begin_trans(zh,1); + if (zebra_begin_trans(zh, 1)) + return -1; rinfo = dict_lookup (zh->reg->matchDict, recid_z); if (rinfo) @@ -1307,6 +1324,17 @@ int zebra_begin_trans (ZebraHandle zh, int rw) } ASSERTZHRES; yaz_log(LOG_API,"zebra_begin_trans rw=%d",rw); + + if (zh->user_perm) + { + if (rw && !strchr(zh->user_perm, 'w')) + { + zh->errCode = 223; + zh->errString = 0; + return -1; + } + } + assert (zh->res); if (rw) { @@ -1317,7 +1345,10 @@ int zebra_begin_trans (ZebraHandle zh, int rw) (zh->trans_no++); if (zh->trans_w_no) + { + read_res_for_transaction(zh); return 0; + } if (zh->trans_no != 1) { zh->errCode = 2; @@ -1924,14 +1955,15 @@ int zebra_add_record(ZebraHandle zh, int zebra_insert_record (ZebraHandle zh, const char *recordType, int *sysno, const char *match, const char *fname, - const char *buf, int buf_size) + const char *buf, int buf_size, int force_update) { int res; yaz_log(LOG_API,"zebra_insert_record sysno=%d", *sysno); if (buf_size < 1) buf_size = strlen(buf); - zebra_begin_trans(zh, 1); + if (zebra_begin_trans(zh, 1)) + return 1; res = buffer_extract_record (zh, buf, buf_size, 0, /* delete_flag */ 0, /* test_mode */ @@ -1956,7 +1988,8 @@ int zebra_update_record (ZebraHandle zh, if (buf_size < 1) buf_size = strlen(buf); - zebra_begin_trans(zh, 1); + if (zebra_begin_trans(zh, 1)) + return 1; res = buffer_extract_record (zh, buf, buf_size, 0, /* delete_flag */ 0, /* test_mode */ @@ -1965,6 +1998,7 @@ int zebra_update_record (ZebraHandle zh, match, fname, force_update, 1); /* allow_update */ + yaz_log(LOG_LOG, "zebra_update_record returned res=%d", res); zebra_end_trans(zh); return res; } @@ -1980,7 +2014,8 @@ int zebra_delete_record (ZebraHandle zh, if (buf_size < 1) buf_size = strlen(buf); - zebra_begin_trans(zh, 1); + if (zebra_begin_trans(zh, 1)) + return 1; res = buffer_extract_record (zh, buf, buf_size, 1, /* delete_flag */ 0, /* test_mode */ @@ -2058,3 +2093,4 @@ int zebra_sort_by_specstr (ZebraHandle zh, zebra_end_read(zh); return sort_status; } +