Factor bounds checking annotations into source code.
[platform/upstream/rpm.git] / lib / poptI.c
1 /*@-boundsread@*/
2 /** \ingroup rpmcli
3  * \file lib/poptI.c
4  *  Popt tables for install modes.
5  */
6
7 #include "system.h"
8
9 #include <rpmcli.h>
10
11 #include "debug.h"
12
13 /*@-redecl@*/
14 extern time_t get_date(const char * p, void * now);     /* XXX expedient lies */
15 /*@=redecl@*/
16
17 /*@unchecked@*/
18 struct rpmInstallArguments_s rpmIArgs;
19
20 #define POPT_RELOCATE           -1016
21 #define POPT_EXCLUDEPATH        -1019
22 #define POPT_ROLLBACK           -1024
23
24 /*@exits@*/ static void argerror(const char * desc)
25         /*@*/
26 {
27     /*@-modfilesys -globs @*/
28     fprintf(stderr, _("%s: %s\n"), __progname, desc);
29     /*@=modfilesys =globs @*/
30     exit(EXIT_FAILURE);
31 }
32
33 /**
34  */
35 /*@-bounds@*/
36 static void installArgCallback( /*@unused@*/ poptContext con,
37                 /*@unused@*/ enum poptCallbackReason reason,
38                 const struct poptOption * opt, const char * arg,
39                 /*@unused@*/ const void * data)
40         /*@globals rpmIArgs */
41         /*@modifies rpmIArgs */
42 {
43     struct rpmInstallArguments_s * ia = &rpmIArgs;
44
45     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
46     /*@-branchstate@*/
47     if (opt->arg == NULL)
48     switch (opt->val) {
49     case POPT_EXCLUDEPATH:
50         if (arg == NULL || *arg != '/') 
51             argerror(_("exclude paths must begin with a /"));
52         ia->relocations = xrealloc(ia->relocations, 
53                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
54         /*@-temptrans@*/
55         ia->relocations[ia->numRelocations].oldPath = arg;
56         /*@=temptrans@*/
57         ia->relocations[ia->numRelocations].newPath = NULL;
58         ia->numRelocations++;
59         break;
60     case POPT_RELOCATE:
61       { char * newPath = NULL;
62         if (arg == NULL || *arg != '/') 
63             argerror(_("relocations must begin with a /"));
64         if (!(newPath = strchr(arg, '=')))
65             argerror(_("relocations must contain a ="));
66         *newPath++ = '\0';
67         if (*newPath != '/') 
68             argerror(_("relocations must have a / following the ="));
69         ia->relocations = xrealloc(ia->relocations, 
70                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
71         /*@-temptrans@*/
72         ia->relocations[ia->numRelocations].oldPath = arg;
73         /*@=temptrans@*/
74         /*@-kepttrans@*/
75         ia->relocations[ia->numRelocations].newPath = newPath;
76         /*@=kepttrans@*/
77         ia->numRelocations++;
78       } break;
79     case POPT_ROLLBACK:
80       { time_t tid;
81         if (arg == NULL)
82             argerror(_("rollback takes a time/date stamp argument"));
83
84         /*@-moduncon@*/
85         tid = get_date(arg, NULL);
86         /*@=moduncon@*/
87
88         if (tid == (time_t)-1 || tid == (time_t)0)
89             argerror(_("malformed rollback time/date stamp argument"));
90         ia->rbtid = tid;
91       } break;
92     }
93     /*@=branchstate@*/
94 }
95 /*@=bounds@*/
96
97 /**
98  */
99 /*@-bitwisesigned -compmempass @*/
100 /*@unchecked@*/
101 struct poptOption rpmInstallPoptTable[] = {
102 /*@-type@*/ /* FIX: cast? */
103  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
104         installArgCallback, 0, NULL, NULL },
105 /*@=type@*/
106
107  { "allfiles", '\0', POPT_BIT_SET,
108         &rpmIArgs.transFlags, RPMTRANS_FLAG_ALLFILES,
109   N_("install all files, even configurations which might otherwise be skipped"),
110         NULL},
111  { "allmatches", '\0', POPT_BIT_SET,
112         &rpmIArgs.eraseInterfaceFlags, UNINSTALL_ALLMATCHES,
113         N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
114         NULL},
115
116  { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
117         (_noTransScripts|_noTransTriggers|
118                 RPMTRANS_FLAG_APPLYONLY|RPMTRANS_FLAG_PKGCOMMIT),
119         N_("do not execute package scriptlet(s)"), NULL },
120
121  { "badreloc", '\0', POPT_BIT_SET,
122         &rpmIArgs.probFilter, RPMPROB_FILTER_FORCERELOCATE,
123         N_("relocate files in non-relocateable package"), NULL},
124  { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
125         &rpmIArgs.transFlags, RPMTRANS_FLAG_DIRSTASH,
126         N_("save erased package files by renaming into sub-directory"), NULL},
127  { "erase", 'e', POPT_BIT_SET,
128         &rpmIArgs.installInterfaceFlags, INSTALL_ERASE,
129         N_("erase (uninstall) package"), N_("<package>+") },
130  { "excludedocs", '\0', POPT_BIT_SET,
131         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
132         N_("do not install documentation"), NULL},
133  { "excludepath", '\0', POPT_ARG_STRING, 0, POPT_EXCLUDEPATH,
134         N_("skip files with leading component <path> "),
135         N_("<path>") },
136  { "force", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
137         (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE),
138         N_("short hand for --replacepkgs --replacefiles"), NULL},
139  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
140         (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL),
141         N_("upgrade package(s) if already installed"),
142         N_("<packagefile>+") },
143  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
144         N_("print hash marks as package installs (good with -v)"), NULL},
145  { "ignorearch", '\0', POPT_BIT_SET,
146         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
147         N_("don't verify package architecture"), NULL},
148  { "ignoreos", '\0', POPT_BIT_SET,
149         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREOS,
150         N_("don't verify package operating system"), NULL},
151  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
152         (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
153         N_("don't check disk space before installing"), NULL},
154  { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
155         N_("install documentation"), NULL},
156  { "install", '\0', POPT_BIT_SET,
157         &rpmIArgs.installInterfaceFlags, INSTALL_INSTALL,
158         N_("install package(s)"), N_("<packagefile>+") },
159  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
160         N_("update the database, but do not modify the filesystem"), NULL},
161  { "nodeps", '\0', 0, &rpmIArgs.noDeps, 0,
162         N_("do not verify package dependencies"), NULL },
163  { "noorder", '\0', POPT_BIT_SET,
164         &rpmIArgs.installInterfaceFlags, INSTALL_NOORDER,
165         N_("do not reorder package installation to satisfy dependencies"),
166         NULL},
167
168  { "nosuggest", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
169         RPMTRANS_FLAG_NOSUGGEST,
170         N_("do not suggest missing dependency resolution(s)"), NULL},
171
172  { "noscripts", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
173         (_noTransScripts|_noTransTriggers),
174         N_("do not execute package scriptlet(s)"), NULL },
175  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
176         RPMTRANS_FLAG_NOPRE,
177         N_("do not execute %%pre scriptlet (if any)"), NULL },
178  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
179         RPMTRANS_FLAG_NOPOST,
180         N_("do not execute %%post scriptlet (if any)"), NULL },
181  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
182         RPMTRANS_FLAG_NOPREUN,
183         N_("do not execute %%preun scriptlet (if any)"), NULL },
184  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
185         RPMTRANS_FLAG_NOPOSTUN,
186         N_("do not execute %%postun scriptlet (if any)"), NULL },
187
188  { "nodigest", '\0', POPT_BIT_SET, &rpmIArgs.qva_flags, VERIFY_DIGEST,
189         N_("don't verify package digest(s)"), NULL },
190  { "nosignature", '\0', POPT_BIT_SET, &rpmIArgs.qva_flags, VERIFY_SIGNATURE,
191         N_("don't verify package signature(s)"), NULL },
192
193  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
194         _noTransTriggers,
195         N_("do not execute any scriptlet(s) triggered by this package"), NULL},
196  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
197         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPREIN,
198         N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
199  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
200         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERIN,
201         N_("do not execute any %%triggerin scriptlet(s)"), NULL},
202  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
203         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERUN,
204         N_("do not execute any %%triggerun scriptlet(s)"), NULL},
205  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
206         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPOSTUN,
207         N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
208
209  { "oldpackage", '\0', POPT_BIT_SET,
210         &rpmIArgs.probFilter, RPMPROB_FILTER_OLDPACKAGE,
211         N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
212         NULL},
213  { "percent", '\0', POPT_BIT_SET,
214         &rpmIArgs.installInterfaceFlags, INSTALL_PERCENT,
215         N_("print percentages as package installs"), NULL},
216  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.prefix, 0,
217         N_("relocate the package to <dir>, if relocatable"),
218         N_("<dir>") },
219  { "relocate", '\0', POPT_ARG_STRING, 0, POPT_RELOCATE,
220         N_("relocate files from path <old> to <new>"),
221         N_("<old>=<new>") },
222  { "repackage", '\0', POPT_BIT_SET,
223         &rpmIArgs.transFlags, RPMTRANS_FLAG_REPACKAGE,
224         N_("save erased package files by repackaging"), NULL},
225  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
226         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
227         N_("install even if the package replaces installed files"), NULL},
228  { "replacepkgs", '\0', POPT_BIT_SET,
229         &rpmIArgs.probFilter, RPMPROB_FILTER_REPLACEPKG,
230         N_("reinstall if the package is already present"), NULL},
231  { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_ROLLBACK,
232         N_("deinstall new, reinstall old, package(s), back to <date>"),
233         N_("<date>") },
234  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
235         N_("don't install, but tell if it would work or not"), NULL},
236  { "upgrade", 'U', POPT_BIT_SET,
237         &rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
238         N_("upgrade package(s)"),
239         N_("<packagefile>+") },
240
241    POPT_TABLEEND
242 };
243 /*@=bitwisesigned =compmempass @*/
244 /*@=boundsread@*/