@@ -167,6 +167,8 @@ impl TryFrom<SudoOptions> for SudoResetTimestampOptions {
167
167
168
168
// sudo -v [-ABkNnS] [-g group] [-h host] [-p prompt] [-u user]
169
169
pub struct SudoValidateOptions {
170
+ // -B
171
+ pub bell : bool ,
170
172
// -k
171
173
pub reset_timestamp : bool ,
172
174
// -n
@@ -189,16 +191,22 @@ impl TryFrom<SudoOptions> for SudoValidateOptions {
189
191
let validate = mem:: take ( & mut opts. validate ) ;
190
192
debug_assert ! ( validate) ;
191
193
194
+ let bell = mem:: take ( & mut opts. bell ) ;
192
195
let reset_timestamp = mem:: take ( & mut opts. reset_timestamp ) ;
193
196
let non_interactive = mem:: take ( & mut opts. non_interactive ) ;
194
197
let stdin = mem:: take ( & mut opts. stdin ) ;
195
198
let prompt = mem:: take ( & mut opts. prompt ) ;
196
199
let group = mem:: take ( & mut opts. group ) ;
197
200
let user = mem:: take ( & mut opts. user ) ;
198
201
202
+ if bell && stdin {
203
+ return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
204
+ }
205
+
199
206
reject_all ( "--validate" , opts) ?;
200
207
201
208
Ok ( Self {
209
+ bell,
202
210
reset_timestamp,
203
211
non_interactive,
204
212
stdin,
@@ -212,6 +220,8 @@ impl TryFrom<SudoOptions> for SudoValidateOptions {
212
220
// sudo -e [-ABkNnS] [-r role] [-t type] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...
213
221
#[ allow( dead_code) ]
214
222
pub struct SudoEditOptions {
223
+ // -B
224
+ pub bell : bool ,
215
225
// -k
216
226
pub reset_timestamp : bool ,
217
227
// -n
@@ -237,6 +247,7 @@ impl TryFrom<SudoOptions> for SudoEditOptions {
237
247
let edit = mem:: take ( & mut opts. edit ) ;
238
248
debug_assert ! ( edit) ;
239
249
250
+ let bell = mem:: take ( & mut opts. bell ) ;
240
251
let reset_timestamp = mem:: take ( & mut opts. reset_timestamp ) ;
241
252
let non_interactive = mem:: take ( & mut opts. non_interactive ) ;
242
253
let stdin = mem:: take ( & mut opts. stdin ) ;
@@ -246,13 +257,18 @@ impl TryFrom<SudoOptions> for SudoEditOptions {
246
257
let user = mem:: take ( & mut opts. user ) ;
247
258
let positional_args = mem:: take ( & mut opts. positional_args ) ;
248
259
260
+ if bell && stdin {
261
+ return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
262
+ }
263
+
249
264
reject_all ( "--edit" , opts) ?;
250
265
251
266
if positional_args. is_empty ( ) {
252
267
return Err ( "must specify at least one file path" . into ( ) ) ;
253
268
}
254
269
255
270
Ok ( Self {
271
+ bell,
256
272
reset_timestamp,
257
273
non_interactive,
258
274
stdin,
@@ -267,6 +283,8 @@ impl TryFrom<SudoOptions> for SudoEditOptions {
267
283
268
284
// sudo -l [-ABkNnS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command [arg ...]]
269
285
pub struct SudoListOptions {
286
+ // -B
287
+ pub bell : bool ,
270
288
// -l OR -l -l
271
289
pub list : List ,
272
290
@@ -292,6 +310,7 @@ impl TryFrom<SudoOptions> for SudoListOptions {
292
310
type Error = String ;
293
311
294
312
fn try_from ( mut opts : SudoOptions ) -> Result < Self , Self :: Error > {
313
+ let bell = mem:: take ( & mut opts. bell ) ;
295
314
let list = opts. list . take ( ) . unwrap ( ) ;
296
315
let reset_timestamp = mem:: take ( & mut opts. reset_timestamp ) ;
297
316
let non_interactive = mem:: take ( & mut opts. non_interactive ) ;
@@ -302,6 +321,10 @@ impl TryFrom<SudoOptions> for SudoListOptions {
302
321
let user = mem:: take ( & mut opts. user ) ;
303
322
let positional_args = mem:: take ( & mut opts. positional_args ) ;
304
323
324
+ if bell && stdin {
325
+ return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
326
+ }
327
+
305
328
// when present, `-u` must be accompanied by a command
306
329
let has_command = !positional_args. is_empty ( ) ;
307
330
let valid_user_flag = user. is_none ( ) || has_command;
@@ -313,6 +336,7 @@ impl TryFrom<SudoOptions> for SudoListOptions {
313
336
reject_all ( "--list" , opts) ?;
314
337
315
338
Ok ( Self {
339
+ bell,
316
340
list,
317
341
reset_timestamp,
318
342
non_interactive,
@@ -328,6 +352,8 @@ impl TryFrom<SudoOptions> for SudoListOptions {
328
352
329
353
// sudo [-ABbEHnPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i | -s] [command [arg ...]]
330
354
pub struct SudoRunOptions {
355
+ // -B
356
+ pub bell : bool ,
331
357
// -E
332
358
pub preserve_env : PreserveEnv ,
333
359
// -k
@@ -357,6 +383,7 @@ impl TryFrom<SudoOptions> for SudoRunOptions {
357
383
type Error = String ;
358
384
359
385
fn try_from ( mut opts : SudoOptions ) -> Result < Self , Self :: Error > {
386
+ let bell = mem:: take ( & mut opts. bell ) ;
360
387
let preserve_env = mem:: take ( & mut opts. preserve_env ) ;
361
388
let reset_timestamp = mem:: take ( & mut opts. reset_timestamp ) ;
362
389
let non_interactive = mem:: take ( & mut opts. non_interactive ) ;
@@ -370,6 +397,10 @@ impl TryFrom<SudoOptions> for SudoRunOptions {
370
397
let shell = mem:: take ( & mut opts. shell ) ;
371
398
let positional_args = mem:: take ( & mut opts. positional_args ) ;
372
399
400
+ if bell && stdin {
401
+ return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
402
+ }
403
+
373
404
let context = match ( login, shell, positional_args. is_empty ( ) ) {
374
405
( true , false , _) => "--login" ,
375
406
( false , true , _) => "--shell" ,
@@ -392,6 +423,7 @@ impl TryFrom<SudoOptions> for SudoRunOptions {
392
423
reject_all ( context, opts) ?;
393
424
394
425
Ok ( Self {
426
+ bell,
395
427
preserve_env,
396
428
reset_timestamp,
397
429
non_interactive,
@@ -410,6 +442,8 @@ impl TryFrom<SudoOptions> for SudoRunOptions {
410
442
411
443
#[ derive( Default ) ]
412
444
struct SudoOptions {
445
+ // -B
446
+ bell : bool ,
413
447
// -D
414
448
chdir : Option < SudoPath > ,
415
449
// -g
@@ -628,6 +662,9 @@ impl SudoOptions {
628
662
for arg in arg_iter {
629
663
match arg {
630
664
SudoArg :: Flag ( flag) => match flag. as_str ( ) {
665
+ "-B" | "--bell" => {
666
+ options. bell = true ;
667
+ }
631
668
"-E" | "--preserve-env" => {
632
669
options. preserve_env = PreserveEnv :: Everything ;
633
670
}
@@ -779,6 +816,7 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
779
816
}
780
817
781
818
let SudoOptions {
819
+ bell,
782
820
chdir,
783
821
group,
784
822
login,
@@ -801,6 +839,7 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
801
839
} = opts;
802
840
803
841
let flags = [
842
+ tuple ! ( bell) ,
804
843
tuple ! ( chdir) ,
805
844
tuple ! ( edit) ,
806
845
tuple ! ( group) ,
0 commit comments