From: Eric Bollengier Date: Mon, 15 Nov 2010 22:03:39 +0000 (+0100) Subject: bvfs: support for bweb user acl X-Git-Tag: Release-5.2.1~938 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5ed764f3615f5af0cc524239deb922bf622d4e70;p=bacula%2Fbacula bvfs: support for bweb user acl --- diff --git a/bacula/src/cats/bvfs.c b/bacula/src/cats/bvfs.c index 4a551fce1d..caeee64fa0 100644 --- a/bacula/src/cats/bvfs.c +++ b/bacula/src/cats/bvfs.c @@ -68,16 +68,59 @@ Bvfs::Bvfs(JCR *j, B_DB *mdb) { attr = new_attr(jcr); list_entries = result_handler; user_data = this; + username = NULL; } Bvfs::~Bvfs() { free_pool_memory(jobids); free_pool_memory(pattern); free_pool_memory(prev_dir); + if (username) { + free(username); + } free_attr(attr); jcr->dec_use_count(); } +void Bvfs::filter_jobid() +{ + if (!username) { + return; + } + + /* Query used by Bweb to filter clients, activated when using + * set_username() + */ + POOL_MEM query; + Mmsg(query, + "SELECT DISTINCT JobId FROM Job JOIN Client USING (ClientId) " + "JOIN (SELECT ClientId FROM client_group_member " + "JOIN client_group USING (client_group_id) " + "JOIN bweb_client_group_acl USING (client_group_id) " + "JOIN bweb_user USING (userid) " + "WHERE bweb_user.username = '%s' " + ") AS filter USING (ClientId) " + " WHERE JobId IN (%s)", + username, jobids); + + db_list_ctx ctx; + Dmsg1(dbglevel_sql, "q=%s\n", query.c_str()); + db_sql_query(db, query.c_str(), db_list_handler, &ctx); + pm_strcpy(jobids, ctx.list); +} + +void Bvfs::set_jobid(JobId_t id) +{ + Mmsg(jobids, "%lld", (uint64_t)id); + filter_jobid(); +} + +void Bvfs::set_jobids(char *ids) +{ + pm_strcpy(jobids, ids); + filter_jobid(); +} + /* * TODO: Find a way to let the user choose how he wants to display * files and directories diff --git a/bacula/src/cats/bvfs.h b/bacula/src/cats/bvfs.h index 5ed5ea58c5..7156874f6a 100644 --- a/bacula/src/cats/bvfs.h +++ b/bacula/src/cats/bvfs.h @@ -72,13 +72,8 @@ public: Bvfs(JCR *j, B_DB *mdb); virtual ~Bvfs(); - void set_jobid(JobId_t id) { - Mmsg(jobids, "%lld", (uint64_t)id); - } - - void set_jobids(char *ids) { - pm_strcpy(jobids, ids); - } + void set_jobid(JobId_t id); + void set_jobids(char *ids); void set_limit(uint32_t max) { limit = max; @@ -125,6 +120,14 @@ public: see_copies = val; } + void filter_jobid(); /* Call after set_username */ + + void set_username(char *user) { + if (user) { + username = bstrdup(user); + } + } + void set_handler(DB_RESULT_HANDLER *h, void *ctx) { list_entries = h; user_data = ctx; @@ -167,6 +170,7 @@ private: JCR *jcr; B_DB *db; POOLMEM *jobids; + char *username; /* Used with Bweb */ uint32_t limit; uint32_t offset; uint32_t nb_record; /* number of records of the last query */