rash_core 2.19.1

Declarative shell scripting using Rust native bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/// ANCHOR: module
/// # chroot
///
/// Execute commands within a chroot environment.
///
/// ## Attributes
///
/// ```yaml
/// check_mode:
///   support: none
/// ```
/// ANCHOR_END: module
/// ANCHOR: examples
/// ## Example
///
/// ```yaml
/// - name: Update package lists in chroot
///   chroot:
///     root: /mnt
///     cmd: apt-get update
///
/// - name: Install packages in chroot
///   chroot:
///     root: /mnt
///     cmd: apt-get install -y linux-image-generic zfs-initramfs
///     environment:
///       DEBIAN_FRONTEND: noninteractive
///
/// - name: Run script in chroot
///   chroot:
///     root: /mnt
///     cmd: /usr/local/bin/setup-script.sh
///     creates: /etc/installed-marker
///
/// - name: Run as different user
///   chroot:
///     root: /mnt
///     cmd: whoami
///     become: true
///     become_user: agil
/// ```
/// ANCHOR_END: examples
use crate::context::GlobalParams;
use crate::error::{Error, ErrorKind, Result};
use crate::modules::{Module, ModuleResult, parse_params};

#[cfg(feature = "docs")]
use rash_derive::DocJsonSchema;

use std::collections::HashMap;
use std::fs;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use minijinja::Value;
#[cfg(feature = "docs")]
use schemars::{JsonSchema, Schema};
use serde::Deserialize;
use serde_norway::Value as YamlValue;
use serde_norway::value;
use tempfile::TempDir;

const DEFAULT_TIMEOUT: u64 = 3600;

#[derive(Clone, Debug, PartialEq, Deserialize)]
#[cfg_attr(feature = "docs", derive(JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum CmdSpec {
    /// The command to run as a string.
    Cmd(String),
    /// The command to run as a list of arguments.
    Argv(Vec<String>),
    /// The command executable (use with args).
    Command(String),
}

#[derive(Debug, PartialEq, Deserialize)]
#[cfg_attr(feature = "docs", derive(JsonSchema, DocJsonSchema))]
#[serde(deny_unknown_fields)]
pub struct Params {
    /// Path to the chroot directory.
    pub root: String,
    #[serde(flatten)]
    pub cmd_spec: CmdSpec,
    /// Arguments for the command (if command used instead of cmd).
    pub args: Option<String>,
    /// Working directory inside chroot.
    /// **[default: `"/"`]**
    pub chdir: Option<String>,
    /// Data to pass to command stdin.
    pub stdin: Option<String>,
    /// Shell to use for command execution.
    /// **[default: `"/bin/sh"`]**
    pub executable: Option<String>,
    /// File that if exists skips the command.
    pub creates: Option<String>,
    /// File that if missing skips the command.
    pub removes: Option<String>,
    /// Environment variables to set.
    pub environment: Option<HashMap<String, String>>,
    /// File to source environment from (e.g., /etc/environment).
    pub env_file: Option<String>,
    /// Umask for command execution.
    pub umask: Option<u32>,
    /// Become another user inside chroot.
    #[serde(rename = "become")]
    pub do_become: Option<bool>,
    /// User to become.
    pub become_user: Option<String>,
    /// Command timeout in seconds.
    /// **[default: `3600`]**
    pub timeout: Option<u64>,
}

fn resolve_path_in_chroot(root: &str, path: &str) -> String {
    if path.starts_with('/') {
        format!("{}{}", root, path)
    } else {
        format!("{}/{}", root, path)
    }
}

fn check_creates(root: &str, creates: &str) -> bool {
    let full_path = resolve_path_in_chroot(root, creates);
    Path::new(&full_path).exists()
}

fn check_removes(root: &str, removes: &str) -> bool {
    let full_path = resolve_path_in_chroot(root, removes);
    !Path::new(&full_path).exists()
}

fn build_command(params: &Params) -> (String, Vec<String>) {
    let executable = params.executable.as_deref().unwrap_or("/bin/sh");

    match &params.cmd_spec {
        CmdSpec::Cmd(cmd) => (executable.to_string(), vec!["-c".to_string(), cmd.clone()]),
        CmdSpec::Argv(argv) => {
            if argv.is_empty() {
                (executable.to_string(), vec![])
            } else {
                (argv[0].clone(), argv[1..].to_vec())
            }
        }
        CmdSpec::Command(command) => {
            let mut cmd_args: Vec<String> = vec![command.clone()];
            if let Some(extra_args) = &params.args {
                cmd_args.extend(extra_args.split_whitespace().map(|s| s.to_string()));
            }
            (
                executable.to_string(),
                vec!["-c".to_string(), cmd_args.join(" ")],
            )
        }
    }
}

fn parse_env_file(path: &str) -> Result<HashMap<String, String>> {
    let content = fs::read_to_string(path).map_err(|e| {
        Error::new(
            ErrorKind::InvalidData,
            format!("Failed to read env file '{}': {}", path, e),
        )
    })?;

    let mut env_vars = HashMap::new();
    for line in content.lines() {
        let line = line.trim();
        if line.is_empty() || line.starts_with('#') {
            continue;
        }
        if let Some((key, value)) = line.split_once('=') {
            let key = key.trim().to_string();
            let value = value
                .trim()
                .trim_matches('"')
                .trim_matches('\'')
                .to_string();
            env_vars.insert(key, value);
        }
    }

    Ok(env_vars)
}

fn merge_environment(params: &Params, root: &str) -> Result<HashMap<String, String>> {
    let mut env_vars: HashMap<String, String> = HashMap::new();

    env_vars.insert(
        "PATH".to_string(),
        "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".to_string(),
    );
    env_vars.insert("HOME".to_string(), "/root".to_string());
    env_vars.insert("TERM".to_string(), "dumb".to_string());

    if let Some(env_file) = &params.env_file {
        let full_path = resolve_path_in_chroot(root, env_file);
        let file_env = parse_env_file(&full_path)?;
        env_vars.extend(file_env);
    }

    if let Some(environment) = &params.environment {
        env_vars.extend(environment.clone());
    }

    Ok(env_vars)
}

struct ChrootExecutor {
    root: PathBuf,
    chdir: PathBuf,
    do_become: bool,
    become_user: Option<String>,
    umask: Option<u32>,
    timeout: u64,
}

impl ChrootExecutor {
    fn new(params: &Params) -> Self {
        let workdir = params
            .chdir
            .as_ref()
            .map(PathBuf::from)
            .unwrap_or_else(|| PathBuf::from("/"));

        ChrootExecutor {
            root: PathBuf::from(&params.root),
            chdir: workdir,
            do_become: params.do_become.unwrap_or(false),
            become_user: params.become_user.clone(),
            umask: params.umask,
            timeout: params.timeout.unwrap_or(DEFAULT_TIMEOUT),
        }
    }

    #[allow(dead_code)]
    fn timeout(&self) -> u64 {
        self.timeout
    }

    fn create_wrapper_script(
        &self,
        program: &str,
        args: &[String],
        env_vars: &HashMap<String, String>,
    ) -> Result<TempDir> {
        let temp_dir = TempDir::new().map_err(|e| {
            Error::new(
                ErrorKind::IOError,
                format!("Failed to create temp dir: {}", e),
            )
        })?;

        let wrapper_path = temp_dir.path().join("chroot_wrapper.sh");
        let mut script = String::new();

        script.push_str("#!/bin/sh\n");
        script.push_str("set -e\n");

        for (key, value) in env_vars {
            script.push_str(&format!(
                "export {}='{}'\n",
                key,
                value.replace("'", "'\\''")
            ));
        }

        if let Some(mask) = self.umask {
            script.push_str(&format!("umask {:03o}\n", mask));
        }

        script.push_str("cd \"");
        script.push_str(&self.chdir.to_string_lossy());
        script.push_str("\"\n");

        if self.do_become {
            if let Some(user) = &self.become_user {
                script.push_str(&format!("exec su - '{}' -c ", user));
                let full_cmd = if args.is_empty() {
                    format!("'{}'", program)
                } else {
                    format!("'{} {}'", program, args.join(" "))
                };
                script.push_str(&format!("\"{}\"\n", full_cmd.replace("\"", "\\\"")));
            } else {
                return Err(Error::new(
                    ErrorKind::InvalidData,
                    "become_user is required when become is true",
                ));
            }
        } else {
            script.push_str("exec '");
            script.push_str(program);
            script.push('\'');
            for arg in args {
                script.push_str(" '");
                script.push_str(&arg.replace("'", "'\\''"));
                script.push('\'');
            }
            script.push('\n');
        }

        let mut file = fs::File::create(&wrapper_path).map_err(|e| {
            Error::new(
                ErrorKind::IOError,
                format!("Failed to create wrapper script: {}", e),
            )
        })?;

        file.write_all(script.as_bytes()).map_err(|e| {
            Error::new(
                ErrorKind::IOError,
                format!("Failed to write wrapper script: {}", e),
            )
        })?;

        fs::set_permissions(&wrapper_path, fs::Permissions::from_mode(0o755)).map_err(|e| {
            Error::new(
                ErrorKind::IOError,
                format!("Failed to set permissions on wrapper script: {}", e),
            )
        })?;

        Ok(temp_dir)
    }

    fn execute(
        &self,
        program: &str,
        args: &[String],
        env_vars: &HashMap<String, String>,
        stdin_data: Option<&str>,
    ) -> Result<(String, String, i32)> {
        let temp_dir = self.create_wrapper_script(program, args, env_vars)?;
        let wrapper_path = temp_dir.path().join("chroot_wrapper.sh");
        let wrapper_in_chroot = format!("/tmp/chroot_wrapper_{}.sh", std::process::id());

        let full_wrapper_dest = self.root.join(&wrapper_in_chroot);
        if let Some(parent) = full_wrapper_dest.parent() {
            fs::create_dir_all(parent).map_err(|e| {
                Error::new(
                    ErrorKind::IOError,
                    format!("Failed to create parent dir: {}", e),
                )
            })?;
        }

        fs::copy(&wrapper_path, &full_wrapper_dest).map_err(|e| {
            Error::new(
                ErrorKind::IOError,
                format!("Failed to copy wrapper script: {}", e),
            )
        })?;

        let mut cmd = Command::new("chroot");
        cmd.arg(&self.root);
        cmd.arg(&wrapper_in_chroot);

        cmd.stdout(Stdio::piped());
        cmd.stderr(Stdio::piped());

        if let Some(data) = stdin_data {
            let mut child = cmd.stdin(Stdio::piped()).spawn().map_err(|e| {
                Error::new(
                    ErrorKind::SubprocessFail,
                    format!("Failed to spawn chroot: {}", e),
                )
            })?;

            if let Some(mut stdin) = child.stdin.take() {
                stdin.write_all(data.as_bytes()).map_err(|e| {
                    Error::new(ErrorKind::IOError, format!("Failed to write stdin: {}", e))
                })?;
            }

            let output = child.wait_with_output().map_err(|e| {
                Error::new(
                    ErrorKind::SubprocessFail,
                    format!("Failed to wait for chroot: {}", e),
                )
            })?;

            let stdout = String::from_utf8_lossy(&output.stdout).to_string();
            let stderr = String::from_utf8_lossy(&output.stderr).to_string();
            let rc = output.status.code().unwrap_or(-1);

            let _ = fs::remove_file(self.root.join(&wrapper_in_chroot));

            Ok((stdout, stderr, rc))
        } else {
            let output = cmd.output().map_err(|e| {
                Error::new(
                    ErrorKind::SubprocessFail,
                    format!("Failed to execute chroot: {}", e),
                )
            })?;

            let stdout = String::from_utf8_lossy(&output.stdout).to_string();
            let stderr = String::from_utf8_lossy(&output.stderr).to_string();
            let rc = output.status.code().unwrap_or(-1);

            let _ = fs::remove_file(self.root.join(&wrapper_in_chroot));

            Ok((stdout, stderr, rc))
        }
    }
}

fn chroot_module(params: Params, _check_mode: bool) -> Result<ModuleResult> {
    let root_path = Path::new(&params.root);
    if !root_path.exists() {
        return Err(Error::new(
            ErrorKind::InvalidData,
            format!("Chroot root '{}' does not exist", params.root),
        ));
    }

    if let Some(creates) = &params.creates
        && check_creates(&params.root, creates)
    {
        return Ok(ModuleResult::new(false, None, None));
    }

    if let Some(removes) = &params.removes
        && check_removes(&params.root, removes)
    {
        return Ok(ModuleResult::new(false, None, None));
    }

    let (program, args) = build_command(&params);
    let env_vars = merge_environment(&params, &params.root)?;

    let executor = ChrootExecutor::new(&params);
    let (stdout, stderr, rc) =
        executor.execute(&program, &args, &env_vars, params.stdin.as_deref())?;

    if rc != 0 {
        return Err(Error::new(
            ErrorKind::SubprocessFail,
            format!("Command failed with exit code {}: {}", rc, stderr),
        ));
    }

    let output = if stdout.trim().is_empty() {
        None
    } else {
        Some(stdout.trim().to_string())
    };

    let cmd_str = match &params.cmd_spec {
        CmdSpec::Cmd(cmd) => cmd.clone(),
        CmdSpec::Argv(argv) => argv.join(" "),
        CmdSpec::Command(cmd) => {
            if let Some(cmd_args) = &params.args {
                format!("{} {}", cmd, cmd_args)
            } else {
                cmd.clone()
            }
        }
    };

    let extra = Some(value::to_value(json!({
        "rc": rc,
        "stderr": stderr,
        "cmd": cmd_str,
    }))?);

    Ok(ModuleResult::new(true, extra, output))
}

#[derive(Debug)]
pub struct Chroot;

impl Module for Chroot {
    fn get_name(&self) -> &str {
        "chroot"
    }

    fn exec(
        &self,
        _: &GlobalParams,
        optional_params: YamlValue,
        _vars: &Value,
        _check_mode: bool,
    ) -> Result<(ModuleResult, Option<Value>)> {
        Ok((
            chroot_module(parse_params(optional_params)?, _check_mode)?,
            None,
        ))
    }

    fn force_string_on_params(&self) -> bool {
        false
    }

    #[cfg(feature = "docs")]
    fn get_json_schema(&self) -> Option<Schema> {
        Some(Params::get_json_schema())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_parse_params_cmd() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            cmd: apt-get update
            "#,
        )
        .unwrap();
        let params: Params = parse_params(yaml).unwrap();
        assert_eq!(params.root, "/mnt");
        assert_eq!(params.cmd_spec, CmdSpec::Cmd("apt-get update".to_owned()));
        assert_eq!(params.chdir, None);
    }

    #[test]
    fn test_parse_params_argv() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            argv:
              - echo
              - "hello world"
            "#,
        )
        .unwrap();
        let params: Params = parse_params(yaml).unwrap();
        assert_eq!(params.root, "/mnt");
        assert_eq!(
            params.cmd_spec,
            CmdSpec::Argv(vec!["echo".to_owned(), "hello world".to_owned()])
        );
    }

    #[test]
    fn test_parse_params_with_environment() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            cmd: apt-get install -y vim
            environment:
              DEBIAN_FRONTEND: noninteractive
              FOO: bar
            "#,
        )
        .unwrap();
        let params: Params = parse_params(yaml).unwrap();
        assert_eq!(
            params.environment,
            Some(HashMap::from([
                ("DEBIAN_FRONTEND".to_owned(), "noninteractive".to_owned()),
                ("FOO".to_owned(), "bar".to_owned())
            ]))
        );
    }

    #[test]
    fn test_parse_params_with_become() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            cmd: whoami
            become: true
            become_user: agil
            "#,
        )
        .unwrap();
        let params: Params = parse_params(yaml).unwrap();
        assert_eq!(params.do_become, Some(true));
        assert_eq!(params.become_user, Some("agil".to_owned()));
    }

    #[test]
    fn test_parse_params_with_creates() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            cmd: /setup.sh
            creates: /etc/setup-done
            "#,
        )
        .unwrap();
        let params: Params = parse_params(yaml).unwrap();
        assert_eq!(params.creates, Some("/etc/setup-done".to_owned()));
    }

    #[test]
    fn test_parse_params_with_removes() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            cmd: rm /tmp/file
            removes: /tmp/file
            "#,
        )
        .unwrap();
        let params: Params = parse_params(yaml).unwrap();
        assert_eq!(params.removes, Some("/tmp/file".to_owned()));
    }

    #[test]
    fn test_resolve_path_in_chroot() {
        assert_eq!(
            resolve_path_in_chroot("/mnt", "/etc/passwd"),
            "/mnt/etc/passwd"
        );
        assert_eq!(
            resolve_path_in_chroot("/mnt", "relative/path"),
            "/mnt/relative/path"
        );
    }

    #[test]
    fn test_build_command_cmd() {
        let params = Params {
            root: "/mnt".to_string(),
            cmd_spec: CmdSpec::Cmd("echo hello".to_string()),
            args: None,
            chdir: None,
            stdin: None,
            executable: None,
            creates: None,
            removes: None,
            environment: None,
            env_file: None,
            umask: None,
            do_become: None,
            become_user: None,
            timeout: None,
        };

        let (program, args) = build_command(&params);
        assert_eq!(program, "/bin/sh");
        assert_eq!(args, vec!["-c", "echo hello"]);
    }

    #[test]
    fn test_build_command_argv() {
        let params = Params {
            root: "/mnt".to_string(),
            cmd_spec: CmdSpec::Argv(vec!["/usr/bin/apt-get".to_string(), "update".to_string()]),
            args: None,
            chdir: None,
            stdin: None,
            executable: None,
            creates: None,
            removes: None,
            environment: None,
            env_file: None,
            umask: None,
            do_become: None,
            become_user: None,
            timeout: None,
        };

        let (program, args) = build_command(&params);
        assert_eq!(program, "/usr/bin/apt-get");
        assert_eq!(args, vec!["update"]);
    }

    #[test]
    fn test_parse_env_file() {
        let dir = tempfile::tempdir().unwrap();
        let env_path = dir.path().join("env");
        let mut file = fs::File::create(&env_path).unwrap();
        writeln!(file, "FOO=bar").unwrap();
        writeln!(file, "# comment").unwrap();
        writeln!(file, "BAZ=\"qux quux\"").unwrap();
        writeln!(file, "EMPTY=").unwrap();

        let env_vars = parse_env_file(env_path.to_str().unwrap()).unwrap();
        assert_eq!(env_vars.get("FOO"), Some(&"bar".to_string()));
        assert_eq!(env_vars.get("BAZ"), Some(&"qux quux".to_string()));
        assert_eq!(env_vars.get("EMPTY"), Some(&"".to_string()));
        assert!(!env_vars.contains_key("comment"));
    }

    #[test]
    fn test_merge_environment() {
        let params = Params {
            root: "/mnt".to_string(),
            cmd_spec: CmdSpec::Cmd("echo".to_string()),
            args: None,
            chdir: None,
            stdin: None,
            executable: None,
            creates: None,
            removes: None,
            environment: Some(HashMap::from([("CUSTOM".to_string(), "value".to_string())])),
            env_file: None,
            umask: None,
            do_become: None,
            become_user: None,
            timeout: None,
        };

        let env_vars = merge_environment(&params, "/mnt").unwrap();
        assert!(env_vars.contains_key("PATH"));
        assert!(env_vars.contains_key("HOME"));
        assert_eq!(env_vars.get("CUSTOM"), Some(&"value".to_string()));
    }

    #[test]
    fn test_parse_params_invalid_field() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            cmd: ls
            invalid_field: value
            "#,
        )
        .unwrap();
        let error = parse_params::<Params>(yaml).unwrap_err();
        assert_eq!(error.kind(), ErrorKind::InvalidData);
    }

    #[test]
    fn test_parse_params_missing_root() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            cmd: ls
            "#,
        )
        .unwrap();
        let error = parse_params::<Params>(yaml).unwrap_err();
        assert_eq!(error.kind(), ErrorKind::InvalidData);
    }

    #[test]
    fn test_parse_params_missing_cmd() {
        let yaml: YamlValue = serde_norway::from_str(
            r#"
            root: /mnt
            "#,
        )
        .unwrap();
        let error = parse_params::<Params>(yaml).unwrap_err();
        assert_eq!(error.kind(), ErrorKind::InvalidData);
    }
}