Skip to content

Commit

Permalink
bvfs: remove set_username()
Browse files Browse the repository at this point in the history
... as this have been bweb specific, which we do not support.
  • Loading branch information
joergsteffens authored and Marco van Wieringen committed Oct 23, 2015
1 parent f077894 commit d299fd4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 59 deletions.
33 changes: 0 additions & 33 deletions src/cats/bvfs.c
Expand Up @@ -64,57 +64,24 @@ 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();
}

/*
Expand Down
9 changes: 0 additions & 9 deletions src/cats/bvfs.h
Expand Up @@ -111,14 +111,6 @@ class Bvfs {
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;
Expand Down Expand Up @@ -164,7 +156,6 @@ class Bvfs {
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 */
Expand Down
26 changes: 9 additions & 17 deletions src/dird/ua_dotcmds.c
Expand Up @@ -206,14 +206,13 @@ static bool bvfs_parse_arg_version(UAContext *ua, char **client, DBId_t *fnid, b
return (*client && *fnid > 0);
}

static bool bvfs_parse_arg(UAContext *ua, DBId_t *pathid, char **path, char **jobid, char **username, int *limit, int *offset)
static bool bvfs_parse_arg(UAContext *ua, DBId_t *pathid, char **path, char **jobid, int *limit, int *offset)
{
*pathid = 0;
*limit = 2000;
*offset = 0;
*path = NULL;
*jobid = NULL;
*username = NULL;

for (int i = 1; i < ua->argc; i++) {
if (bstrcasecmp(ua->argk[i], NT_("pathid"))) {
Expand All @@ -226,10 +225,6 @@ static bool bvfs_parse_arg(UAContext *ua, DBId_t *pathid, char **path, char **jo
*path = ua->argv[i];
}

if (bstrcasecmp(ua->argk[i], NT_("username"))) {
*username = ua->argv[i];
}

if (bstrcasecmp(ua->argk[i], NT_("jobid"))) {
if (is_a_number_list(ua->argv[i])) {
*jobid = ua->argv[i];
Expand Down Expand Up @@ -284,18 +279,17 @@ bool dot_bvfs_restore_cmd(UAContext *ua, const char *cmd)
{
DBId_t pathid = 0;
int limit = 2000, offset = 0, i;
char *path = NULL, *jobid = NULL, *username = NULL;
char *path = NULL, *jobid = NULL;
char *empty = (char *)"";
char *fileid, *dirid, *hardlink;
fileid = dirid = hardlink = empty;

if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &username, &limit, &offset)) {
if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &limit, &offset)) {
ua->error_msg("Can't find jobid, pathid or path argument\n");
return false; /* not enough param */
}

Bvfs fs(ua->jcr, ua->db);
fs.set_username(username);
fs.set_jobids(jobid);

if ((i = find_arg_with_value(ua, "fileid")) >= 0) {
Expand Down Expand Up @@ -324,11 +318,11 @@ bool dot_bvfs_lsfiles_cmd(UAContext *ua, const char *cmd)
{
DBId_t pathid = 0;
int limit = 2000, offset = 0;
char *path = NULL, *jobid = NULL, *username = NULL;
char *path = NULL, *jobid = NULL;
char *pattern = NULL;
int i;

if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &username, &limit, &offset)) {
if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &limit, &offset)) {
ua->error_msg("Can't find jobid, pathid or path argument\n");
return false; /* not enough param */
}
Expand All @@ -342,7 +336,6 @@ bool dot_bvfs_lsfiles_cmd(UAContext *ua, const char *cmd)
}

Bvfs fs(ua->jcr, ua->db);
fs.set_username(username);
fs.set_jobids(jobid);
fs.set_handler(bvfs_result_handler, ua);
fs.set_limit(limit);
Expand Down Expand Up @@ -373,9 +366,9 @@ bool dot_bvfs_lsdirs_cmd(UAContext *ua, const char *cmd)
{
DBId_t pathid = 0;
int limit = 2000, offset = 0;
char *path = NULL, *jobid = NULL, *username = NULL;
char *path = NULL, *jobid = NULL;

if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &username, &limit, &offset)) {
if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &limit, &offset)) {
ua->error_msg("Can't find jobid, pathid or path argument\n");
return true; /* not enough param */
}
Expand All @@ -385,7 +378,6 @@ bool dot_bvfs_lsdirs_cmd(UAContext *ua, const char *cmd)
}

Bvfs fs(ua->jcr, ua->db);
fs.set_username(username);
fs.set_jobids(jobid);
fs.set_limit(limit);
fs.set_handler(bvfs_result_handler, ua);
Expand Down Expand Up @@ -413,10 +405,10 @@ bool dot_bvfs_versions_cmd(UAContext *ua, const char *cmd)
{
DBId_t pathid = 0, fnid = 0;
int limit = 2000, offset = 0;
char *path = NULL, *jobid = NULL, *client = NULL, *username = NULL;
char *path = NULL, *jobid = NULL, *client = NULL;
bool copies = false, versions = false;

if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &username, &limit, &offset)) {
if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, &limit, &offset)) {
ua->error_msg("Can't find jobid, pathid or path argument\n");
return false; /* not enough param */
}
Expand Down

0 comments on commit d299fd4

Please sign in to comment.