1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  * Includes specific to the Director User Agent Server
21  *
22  *     Kern Sibbald, August MMI
23  *
24  */
25 
26 #ifndef __UA_H_
27 #define __UA_H_ 1
28 
29 class UAContext {
30 public:
31    BSOCK *UA_sock;
32    BSOCK *sd;
33    JCR *jcr;
34    BDB *db;                          /* Pointing to shared or private db */
35    BDB *shared_db;                   /* Main Bacula DB access */
36    BDB *private_db;                  /* Private DB access */
37    CAT *catalog;
38    CONRES *cons;                      /* console resource */
39    POOLMEM *cmd;                      /* return command/name buffer */
40    POOLMEM *args;                     /* command line arguments */
41    POOLMEM *errmsg;                   /* store error message */
42    char name[MAX_NAME_LENGTH];        /* Name of the console bashed */
43    char *argk[MAX_CMD_ARGS];          /* argument keywords */
44    char *argv[MAX_CMD_ARGS];          /* argument values */
45    int argc;                          /* number of arguments */
46    char **prompt;                     /* list of prompts */
47    char **unique;                     /* extra unique field */
48    int max_prompts;                   /* max size of list */
49    int num_prompts;                   /* current number in list */
50    char api_opts[MAX_NAME_LENGTH];    /* Api options */
51    int api;                           /* For programs want an API */
52    int cmd_index;                     /* Index in command table */
53    bool force_mult_db_connections;    /* overwrite cat.mult_db_connections */
54    bool auto_display_messages;        /* if set, display messages */
55    bool user_notified_msg_pending;    /* set when user notified */
56    bool automount;                    /* if set, mount after label */
57    bool quit;                         /* if set, quit */
58    bool verbose;                      /* set for normal UA verbosity */
59    bool batch;                        /* set for non-interactive mode */
60    bool gui;                          /* set if talking to GUI program */
61    bool runscript;                    /* set if we are in runscript */
62    uint32_t pint32_val;               /* positive integer */
63    int32_t  int32_val;                /* positive/negative */
64    int64_t  int64_val;                /* big int */
65 
66    /* Can be used to restrict the view, not used by bvfs itself */
67    uid_t uid;                         /* used by the .setuid command */
68    gid_t gid;                         /* used by the .setuid command */
69    void *bvfs;                        /* used in some bvfs queries */
70 
signal(int sig)71    void signal(int sig) { UA_sock->signal(sig); };
72 
73    /* The below are in ua_output.c */
74    void send_msg(const char *fmt, ...);
75    void error_msg(const char *fmt, ...);
76    void warning_msg(const char *fmt, ...);
77    void info_msg(const char *fmt, ...);
78    void send_events(const char *code, const char *type, const char *fmt, ...);
79 };
80 
81 /* Context for insert_tree_handler() */
82 struct TREE_CTX {
83    TREE_ROOT *root;                   /* root */
84    TREE_NODE *node;                   /* current node */
85    TREE_NODE *avail_node;             /* unused node last insert */
86    int cnt;                           /* count for user feedback */
87    bool all;                          /* if set mark all as default */
88    bool hardlinks_in_mem;             /* Set to optimize for speed */
89    bool no_auto_parent;               /* Set to not select parent directories */
90    UAContext *ua;
91    uint32_t FileEstimate;             /* estimate of number of files */
92    uint32_t FileCount;                /* current count of files */
93    uint32_t LastCount;                /* last count of files */
94    uint32_t DeltaCount;               /* trigger for printing */
95    alist *uid_acl;                    /* UID allowed in the tree */
96    alist *gid_acl;                    /* GID allowed in the tree */
97    alist *dir_acl;                    /* Directories that can be displayed */
98    char  *last_dir_acl;               /* Last directory from the DirectoryACL list */
99 };
100 
101 struct NAME_LIST {
102    char **name;                       /* list of names */
103    int num_ids;                       /* ids stored */
104    int max_ids;                       /* size of array */
105    int num_del;                       /* number deleted */
106    int tot_ids;                       /* total to process */
107 };
108 
109 
110 /* Main structure for obtaining JobIds or Files to be restored */
111 struct RESTORE_CTX {
112    utime_t JobTDate;
113    uint32_t TotalFiles;
114    JobId_t JobId;
115    char ClientName[MAX_NAME_LENGTH];  /* backup client */
116    char RestoreClientName[MAX_NAME_LENGTH];  /* restore client */
117    char RestoreMediaType[MAX_NAME_LENGTH];   /* restore Media type when storage override */
118    char last_jobid[20];
119    POOLMEM *JobIds;                   /* User entered string of JobIds */
120    POOLMEM *BaseJobIds;               /* Base jobids */
121    STORE  *store;
122    JOB *restore_job;
123    POOL *pool;
124    int restore_jobs;
125    uint32_t selected_files;
126    char *comment;
127    char *where;
128    char *RegexWhere;
129    char *replace;
130    char *fileregex;
131 
132    char *job_user;                    /* used in the restore menu */
133    char *job_group;                   /* used in the restore menu */
134 
135    char *when;
136    rblist *bsr_list;
137    POOLMEM *fname;                    /* filename only */
138    POOLMEM *path;                     /* path only */
139    POOLMEM *query;
140    int fnl;                           /* filename length */
141    int pnl;                           /* path length */
142    bool found;
143    bool all;                          /* mark all as default */
144    bool hardlinks_in_mem;             /* keep hard links in memory */
145    bool fdcalled;                     /* True if we should reuse the FD socket */
146    bool no_auto_parent;               /* Select or not parent directories */
147    NAME_LIST name_list;
148    POOLMEM *component_fname;
149    FILE *component_fd;
150 };
151 
152 #define MAX_ID_LIST_LEN 2000000
153 
154 #endif
155