Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shell] Add otcli pass-through commands for direct control over the OpenThread interface. #2371

Merged
merged 2 commits into from
Aug 29, 2020

Conversation

turon
Copy link
Contributor

@turon turon commented Aug 28, 2020

Problem

For testing and development scenarios, a shell app user may want to directly access the OpenThread cli in order to configure the interface.

Summary of Changes

Add an otcli pass-through option -- both for Linux and embedded (direct openthread C API calls).

fixes #1694

otCliConsoleInputLine(buff, buff_ptr - buff);
#else
streamer_printf(streamer_get(), "Exec: %s\n\r", buff);
system(buff);
Copy link
Contributor

@mspang mspang Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is vulnerable to shell escapes. Do we intend to give the CHIP shell control to run arbitrary system shell commands?

Copy link
Contributor Author

@turon turon Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to replicate the socket APIs used by ot-ctl itself. Perhaps those could be made available as a linkable library, but I don't think they are in that form currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mspang @rwalker-apple, updated to use fork()/exec().

examples/shell/cmd_otcli.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@rwalker-apple rwalker-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to move to fork()/exec() (or equivalent) instead of system() to reduce stringops and close the shell escape hole?

@mspang
Copy link
Contributor

mspang commented Aug 28, 2020

possible to move to fork()/exec() (or equivalent) instead of system() to reduce stringops and close the shell escape hole?

Yep, that's what I had in mind too.


int pid, status;
uid_t euid = geteuid();
char ctl_command[] = "/usr/local/sbin/ot-ctl";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably needs more configurability in the future. Could use execvp().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to execvp(), but when running sudo, it still has trouble finding simply ot-cli, even if I add export PATH=$PATH:/usr/local/sbin to /root/.bashrc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a sudo policy biting:

sudo grep secure_path /etc/sudoers
Defaults secure_path=/usr/sbin:/usr/bin:/sbin:/bin

Copy link
Contributor

@mspang mspang Aug 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a TODO for now to add some way to override (could just be a command line argument).

examples/shell/cmd_otcli.cpp Outdated Show resolved Hide resolved
@github-actions
Copy link

Size increase report for "nrfconnect-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-nrf52840-lock-example.elf and ./pull_artifact/chip-nrf52840-lock-example.elf:

sections,vmsize,filesize


@github-actions
Copy link

Size increase report for "esp32-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-wifi-echo.elf and ./pull_artifact/chip-wifi-echo.elf:

sections,vmsize,filesize


@github-actions
Copy link

Size increase report for "gn_nrf-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv


@github-actions
Copy link

Size increase report for "gn_linux-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv


@github-actions
Copy link

Size increase report for "gn_efr32-example-build"

File Section File VM
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-efr32-lock-example.out and ./pull_artifact/chip-efr32-lock-example.out:

sections,vmsize,filesize


@rwalker-apple rwalker-apple merged commit e1e7f66 into project-chip:master Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[shell] add Thread commands as pass-through to otcli
4 participants