已开启
feat: 组件开源适配 #8
rosa776创建于 8月20日
feat: 组件开源适配 #8
已开启
共 32 个文件变更+6102-6030
| @@ -0,0 +1,142 @@ | |||
| 1 | +--- | ||
| 2 | +Language: Cpp | ||
| 3 | +# 基于 LLVM 风格的自定义配置 | ||
| 4 | +BasedOnStyle: LLVM | ||
| 5 | + | ||
| 6 | +# 缩进设置 | ||
| 7 | +IndentWidth: 4 | ||
| 8 | +TabWidth: 4 | ||
| 9 | +UseTab: Never | ||
| 10 | +AccessModifierOffset: -4 | ||
| 11 | +IndentCaseLabels: true | ||
| 12 | +NamespaceIndentation: None | ||
| 13 | + | ||
| 14 | +# 行长度设置 | ||
| 15 | +ColumnLimit: 120 | ||
| 16 | + | ||
| 17 | +# 括号设置 | ||
| 18 | +BreakBeforeBraces: Custom | ||
| 19 | +BraceWrapping: | ||
| 20 | + AfterClass: false | ||
| 21 | + AfterControlStatement: false | ||
| 22 | + AfterEnum: false | ||
| 23 | + AfterFunction: true | ||
| 24 | + AfterNamespace: false | ||
| 25 | + AfterStruct: false | ||
| 26 | + AfterUnion: false | ||
| 27 | + BeforeCatch: false | ||
| 28 | + BeforeElse: false | ||
| 29 | + IndentBraces: false | ||
| 30 | + SplitEmptyFunction: false | ||
| 31 | + SplitEmptyRecord: false | ||
| 32 | + SplitEmptyNamespace: false | ||
| 33 | + | ||
| 34 | +# 控制语句括号设置 | ||
| 35 | +# 强制所有控制语句使用花括号,包括单行语句 | ||
| 36 | +InsertBraces: true | ||
| 37 | + | ||
| 38 | +# 空格设置 | ||
| 39 | +SpaceBeforeParens: ControlStatements | ||
| 40 | +SpaceInEmptyParentheses: false | ||
| 41 | +SpacesInAngles: false | ||
| 42 | +SpacesInCStyleCastParentheses: false | ||
| 43 | +SpacesInContainerLiterals: false | ||
| 44 | +SpacesInParentheses: false | ||
| 45 | +SpacesInSquareBrackets: false | ||
| 46 | +SpaceAfterCStyleCast: false | ||
| 47 | +SpaceAfterTemplateKeyword: true | ||
| 48 | +SpaceBeforeAssignmentOperators: true | ||
| 49 | +SpaceBeforeInheritanceColon: true | ||
| 50 | +SpaceBeforeRangeBasedForLoopColon: true | ||
| 51 | + | ||
| 52 | +# 对齐设置 | ||
| 53 | +AlignAfterOpenBracket: Align | ||
| 54 | +AlignConsecutiveAssignments: Consecutive | ||
| 55 | +AlignConsecutiveDeclarations: Consecutive | ||
| 56 | +AlignEscapedNewlines: Right | ||
| 57 | +AlignOperands: Align | ||
| 58 | +AlignTrailingComments: true | ||
| 59 | +AlignConsecutiveMacros: Consecutive | ||
| 60 | +AlignConsecutiveBitFields: Consecutive | ||
| 61 | + | ||
| 62 | +# 换行设置 | ||
| 63 | +AllowAllParametersOfDeclarationOnNextLine: true | ||
| 64 | +AllowShortBlocksOnASingleLine: false | ||
| 65 | +AllowShortCaseLabelsOnASingleLine: false | ||
| 66 | +AllowShortFunctionsOnASingleLine: None | ||
| 67 | +AllowShortLambdasOnASingleLine: None | ||
| 68 | +AllowShortIfStatementsOnASingleLine: false | ||
| 69 | +AllowShortLoopsOnASingleLine: false | ||
| 70 | +AlwaysBreakAfterReturnType: None | ||
| 71 | +AlwaysBreakBeforeMultilineStrings: false | ||
| 72 | +AlwaysBreakTemplateDeclarations: Yes | ||
| 73 | +BinPackArguments: true | ||
| 74 | +BinPackParameters: true | ||
| 75 | +BreakBeforeBinaryOperators: None | ||
| 76 | +BreakBeforeTernaryOperators: true | ||
| 77 | +BreakConstructorInitializers: BeforeColon | ||
| 78 | +BreakInheritanceList: BeforeColon | ||
| 79 | +BreakStringLiterals: true | ||
| 80 | +PackConstructorInitializers: BinPack | ||
| 81 | +ConstructorInitializerIndentWidth: 4 | ||
| 82 | +ContinuationIndentWidth: 4 | ||
| 83 | +Cpp11BracedListStyle: true | ||
| 84 | + | ||
| 85 | +# 派生类设置 | ||
| 86 | +DerivePointerAlignment: false | ||
| 87 | +PointerAlignment: Left | ||
| 88 | + | ||
| 89 | +# 注释设置 | ||
| 90 | +ReflowComments: true | ||
| 91 | +CommentPragmas: '^ IWYU pragma:' | ||
| 92 | + | ||
| 93 | +# 包含文件排序 | ||
| 94 | +IncludeBlocks: Regroup | ||
| 95 | +IncludeCategories: | ||
| 96 | + # 系统库: sys/, linux/, net/, arpa/, netinet/, security/, unistd.h | ||
| 97 | + - Regex: '^<unistd\.h>' | ||
| 98 | + Priority: 3 | ||
| 99 | + - Regex: '^<(sys|linux|net|arpa|netinet|security)/' | ||
| 100 | + Priority: 3 | ||
| 101 | + # 第三方库: securec, glib, openssl, dbus, lua, sasl, ldap 等 | ||
| 102 | + - Regex: '^<(securec|glib|lua|lauxlib|ldap|sasl)\.h>' | ||
| 103 | + Priority: 4 | ||
| 104 | + - Regex: '^<(sasl)/' | ||
| 105 | + Priority: 4 | ||
| 106 | + - Regex: '^(<|")(openssl|dbus|glib|glib-2\.0)/' | ||
| 107 | + Priority: 4 | ||
| 108 | + # C/C++标准库: 单名头文件 | ||
| 109 | + - Regex: '^<[a-z_]+\.h>' | ||
| 110 | + Priority: 2 | ||
| 111 | + # 项目内头文件 | ||
| 112 | + - Regex: '^".*' | ||
| 113 | + Priority: 5 | ||
| 114 | +IncludeIsMainRegex: '(Test)?$' | ||
| 115 | + | ||
| 116 | +# 其他设置 | ||
| 117 | +IndentPPDirectives: None | ||
| 118 | +KeepEmptyLinesAtTheStartOfBlocks: false | ||
| 119 | +MaxEmptyLinesToKeep: 1 | ||
| 120 | +PenaltyBreakAssignment: 2 | ||
| 121 | +PenaltyBreakBeforeFirstCallParameter: 19 | ||
| 122 | +PenaltyBreakComment: 300 | ||
| 123 | +PenaltyBreakFirstLessLess: 120 | ||
| 124 | +PenaltyBreakString: 1000 | ||
| 125 | +PenaltyExcessCharacter: 1000000 | ||
| 126 | +PenaltyReturnTypeOnItsOwnLine: 60 | ||
| 127 | +SortIncludes: true | ||
| 128 | +SortUsingDeclarations: true | ||
| 129 | + | ||
| 130 | +# C++特定设置 | ||
| 131 | +Standard: Cpp11 | ||
| 132 | + | ||
| 133 | +# 嵌套深度限制 | ||
| 134 | +# 注意:clang-format本身不直接支持限制嵌套深度 | ||
| 135 | +# 但可以通过以下设置间接影响代码结构 | ||
| 136 | +IndentCaseBlocks: false | ||
| 137 | +IndentGotoLabels: false | ||
| 138 | +IndentWrappedFunctionNames: false | ||
| 139 | + | ||
| 140 | +# 链式调用配置 | ||
| 141 | +# 关键:lambda体不额外缩进 | ||
| 142 | +LambdaBodyIndentation: OuterScope | ||
| @@ -18,7 +18,6 @@ luacov.stats.out | |||
| 18 | 18 | ||
| 19 | crates | 19 | crates |
| 20 | temp | 20 | temp |
| 21 | -.clang-format | ||
| 22 | .lua-format | 21 | .lua-format |
| 23 | .predefine | 22 | .predefine |
| 24 | conanbase.py | 23 | conanbase.py |
| @@ -0,0 +1,8 @@ | |||
| 1 | +# Changelog | ||
| 2 | +All notable changes to this project will be documented in this file. | ||
| 3 | + | ||
| 4 | +## [1.140.7] - 2026-8-20 | ||
| 5 | + | ||
| 6 | +### Fixed | ||
| 7 | + | ||
| 8 | +- 更正版本号 | ||
| @@ -0,0 +1,41 @@ | |||
| 1 | +## pre-commit 使用说明 | ||
| 2 | + | ||
| 3 | +本项目已配置 [pre-commit](https://pre-commit.com/) 钩子,用于在提交代码时自动进行代码规范检查和格式化。 | ||
| 4 | + | ||
| 5 | +### 安装与初始化 | ||
| 6 | + | ||
| 7 | +```bash | ||
| 8 | +pip install pre-commit | ||
| 9 | +pre-commit install --hook-type commit-msg | ||
| 10 | +pre-commit install | ||
| 11 | +``` | ||
| 12 | + | ||
| 13 | +### 手动运行检查 | ||
| 14 | + | ||
| 15 | +```bash | ||
| 16 | +pre-commit run --all-files | ||
| 17 | +pre-commit run --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +### 配置详情 | ||
| 21 | + | ||
| 22 | +本项目使用以下两组钩子: | ||
| 23 | + | ||
| 24 | +**[openUBMC pre-commit-hooks](https://gitcode.com/openUBMC/pre-commit-hooks/blob/main/README.md)**: | ||
| 25 | +- **conventional-commit**: 检查提交消息是否符合 Conventional Commits 规范 | ||
| 26 | +- **add-signoff-and-change-id**: 自动添加 Sign-off-by 和 Change-Id | ||
| 27 | +- **check-sr**: 检查 .sr 文件 | ||
| 28 | +- **check-json**: 检查 JSON 文件 | ||
| 29 | +- **check-yaml**: 检查 YAML 文件 | ||
| 30 | + | ||
| 31 | +**[pre-commit-hooks (mirrored)](https://gitcode.com/gh_mirrors/pr/pre-commit-hooks)**: | ||
| 32 | +- **trailing-whitespace**: 修复行尾多余空白(排除 .vscode/、test_data/) | ||
| 33 | +- **end-of-file-fixer**: 修复文件末尾缺少换行(排除 .vscode/、test_data/) | ||
| 34 | +- **check-merge-conflict**: 检查合并冲突标记 | ||
| 35 | +- **check-added-large-files**: 防止提交大文件(限制 1024KB) | ||
| 36 | +- **check-case-conflict**: 检查文件名大小写冲突 | ||
| 37 | +- **detect-private-key**: 检测私钥泄露(排除测试 fixture key.pem:test/integration/test_suit/file_transfer/data/key.pem) | ||
| 38 | + | ||
| 39 | +## 许可证 | ||
| 40 | + | ||
| 41 | +Mulan PSL v2 许可证,详见 [LICENSE](LICENSE) 文件 | ||
| @@ -12,185 +12,179 @@ See the Mulan PSL v2 for more details. | |||
| 12 | 12 | ||
| 13 | # cli | 13 | # cli |
| 14 | 14 | ||
| 15 | -openUBMC 命令行(CLI)组件,提供受限 Shell 登录能力,以及 `ipmcget`(查询)/ `ipmcset`(配置)两套命令。 | 15 | +openUBMC 命令行(CLI)组件,提供受限 Shell 命令,以及 `ipmcget`(查询)/ `ipmcset`(配置)两套命令。 |
| 16 | 16 | ||
| 17 | ---- | 17 | +| 项目 | 内容 | |
| 18 | +| -------- | ------------------ | | ||
| 19 | +| 组件名称 | cli | | ||
| 20 | +| 许可证 | Mulan PSL v2 | | ||
| 21 | +| 最后更新 | 2026 年 8 月 25 日 | | ||
| 22 | + | ||
| 23 | +------ | ||
| 18 | 24 | ||
| 19 | ## 1. 组件概述 | 25 | ## 1. 组件概述 |
| 20 | 26 | ||
| 21 | -`cli` 组件是 openUBMC 对外的人机交互入口,向上提供命令行界面,向下屏蔽资源协作接口与后端服务差异。由两部分组成: | 27 | +### 1.1 组件简介 |
| 22 | 28 | ||
| 23 | -| 部分 | 语言 | 说明 | | 29 | + `cli` 组件是 openUBMC 对外的人机交互入口,向上提供命令行界面,向下屏蔽资源协作接口与后端服务差异。由两部分组成: |
| 24 | -| --- | --- | --- | | 30 | + |
| 25 | -| 受限 Shell(CLP) | C(`src/clp/`) | 登录后进入的命令行环境,仅放行固定命令集 | | 31 | +| 部分 | 语言 | 说明 | |
| 32 | +| --------------------- | ------------------------------------ | ---------------------------------------------------------- | | ||
| 33 | +| 受限 Shell(CLP) | C(`src/clp/`) | 登录后进入的命令行环境,仅放行固定命令集 | | ||
| 26 | | `ipmcget` / `ipmcset` | Lua(`src/lualib/`、`src/service/`) | 将命令解析为 URI,经路由映射器转成后端资源协作接口对象调用 | | 34 | | `ipmcget` / `ipmcset` | Lua(`src/lualib/`、`src/service/`) | 将命令解析为 URI,经路由映射器转成后端资源协作接口对象调用 | |
| 27 | 35 | ||
| 28 | -- **受限 Shell**:登录提示符、命令历史、会话超时(默认 900 秒,`notimeout` 可取消)、敏感信息遮蔽;命令集含 `help`、`ipmcget`、`ipmcset`、`mdbctl`、`ping`、`reboot`、`rollback`、`passwd`、`ssh` 等。 | 36 | +### 1.2 解决什么问题 |
| 29 | -- **`ipmcget` / `ipmcset`**:参数化命令 `[-l <location>] [-t <target>] -d <dataitem> [-s <systemid>] [-v <value>]`,支持普通/分页/任务三类执行模式、敏感命令二次确认与鉴权、SOL 会话管理、一键日志收集入口(`ipmcget -d diaginfo`)。 | ||
| 30 | -- **交互边界**:本组件不持有数据,所有查询/配置最终通过 D-Bus 用户会话总线(`sd_bus`)访问资源协作接口对象(`path` + `interface`)与后端服务(账号、重启、SOL、任务服务等)。`mdbctl` 在线调试命令由独立的 mdbctl 组件实现,不属于本组件。 | ||
| 31 | 37 | ||
| 32 | ---- | 38 | +**1、解决服务器底层管理的标准化、自动化与可追溯性问题**。 |
| 33 | 39 | ||
| 34 | -## 2. API 使用说明和示例 | 40 | +服务器内部硬件组件众多,配置项复杂。如果缺乏统一的接口,运维将面临配置不一致、批量操作困难、接口随意变更导致自动化脚本失效等问题。 |
| 35 | 41 | ||
| 36 | -### 2.1 `ipmcget` / `ipmcset` 命令 | 42 | +**2、CLI 的解决方案:** |
| 37 | 43 | ||
| 38 | -**作用**:`ipmcget` 查询 BMC 状态、配置、日志等信息;`ipmcset` 下发配置与控制命令。 | 44 | +统一配置与接口,屏蔽硬件差异,允许用户通过简单的命令完成所有管理操作。 |
| 39 | 45 | ||
| 40 | -**语法**: | 46 | +支持基于 Shell / Python 的自动化运维,使得大规模服务器集群的批量配置、状态监控成为可能。 |
| 41 | 47 | ||
| 42 | -``` | 48 | +接口基线与生命周期管控,解决接口变更导致上下游系统兼容性问题,确保自动化流程的稳定性和可维护性。 |
| 43 | -ipmcget/ipmcset [-l <location>] [-t <target>] -d <dataitem> [-s <systemid>] [-v <value>] | 49 | + |
| 50 | +### 1.3 核心功能 | ||
| 51 | + | ||
| 52 | +**1. 受限 Shell**:登录提示符、命令历史、会话超时(默认 900 秒,`notimeout` 可取消)、敏感信息遮蔽;命令集含 `help`、`ipmcget`、`ipmcset`、`mdbctl`、`ping`、`reboot`、`rollback`、`passwd`、`ssh` 等。 | ||
| 53 | + | ||
| 54 | +**2. `ipmcget` / `ipmcset`**:参数化命令 `[-l <location>] [-t <target>] -d <dataitem> [-s <systemid>] [-v <value>]`,支持普通/分页/任务三类执行模式、敏感命令二次确认与鉴权、SOL 会话管理、一键日志收集入口(`ipmcget -d diaginfo`)。 | ||
| 55 | + | ||
| 56 | +### 1.4 外部交互边界图 | ||
| 57 | + | ||
| 58 | +> 只有Release包才会默认使用clp_commands。本组件不持有数据,所有查询/配置最终通过 D-Bus 用户会话总线(`sd_bus`)访问资源协作接口对象(`path` + `interface`)与后端服务(账号、重启、SOL、任务服务等)。 | ||
| 59 | + | ||
| 60 | +```mermaid | ||
| 61 | + flowchart LR | ||
| 62 | + A1((SSH登录)) -->|release包| B(/usr/bin/clp_commands) | ||
| 63 | + A1 -->|debug包| C(/bin/bash) | ||
| 64 | + A2((Telnet登录)) --> C | ||
| 44 | ``` | 65 | ``` |
| 45 | 66 | ||
| 46 | -| 参数 | 必选 | 说明 | | 67 | +------ |
| 47 | -| --- | --- | --- | | ||
| 48 | -| `-l <location>` | 否 | 机框/位置(仅当构建开启 `cli_l_supported` 时可用,默认关闭) | | ||
| 49 | -| `-t <target>` | 否 | 目标资源类型,缺省为 `_`(通配) | | ||
| 50 | -| `-d <dataitem>` | 是 | 数据项,如 `version`、`sensor`、`sel` | | ||
| 51 | -| `-s <systemid>` | 否 | 多机形态下的系统 ID | | ||
| 52 | -| `-v <value>` | 否 | 附加参数/配置值 | | ||
| 53 | 68 | ||
| 54 | -**可能抛出的异常及触发条件**(通过 `pcall` 捕获,打印到标准输出而非抛堆栈): | 69 | + ## 2. 使用说明和示例 |
| 55 | 70 | ||
| 56 | -| 输出 | 触发条件 | | 71 | + > 运行help指令可以查看clp_commands下所有可用指令 |
| 57 | -| --- | --- | | ||
| 58 | -| `Invalid Command` | 路由映射器响应异常,或命令执行类型未注册 | | ||
| 59 | -| `Request failed.` | 后端服务返回错误(`errs` 非空) | | ||
| 60 | -| `Request failed, the echo profile does not exist.` | 回显模板文件缺失 | | ||
| 61 | -| `Invalid input` | 鉴权提示后,密码输入失败 | | ||
| 62 | -| 内部错误消息 | Lua 执行抛出未预期异常 | | ||
| 63 | 72 | ||
| 64 | -参数不完整/非法时打印对应层级的帮助信息(Usage/参数列表/Example),不算异常。 | 73 | + ### 2.1 `ipmcget` / `ipmcset` 命令 |
| 65 | 74 | ||
| 66 | -**应用场景 / 限制条件**: | 75 | + **作用**:`ipmcget` 查询 BMC 状态、配置、日志等信息;`ipmcset` 下发配置与控制命令。 |
| 67 | 76 | ||
| 68 | -- 场景:日常巡检(版本、传感器、SEL、日志查询)、配置下发、SOL 会话管理、用户口令管理。 | 77 | + **语法**: |
| 69 | -- 限制:`ipmcget` 只读;写操作需对应权限,部分命令需二次确认或密码鉴权;`passwd` 命令仅在 `bmc.kepler.Cli.Command` 的 `Enabled` 为真时可用。 | 78 | + |
| 79 | + ``` | ||
| 80 | + ipmcget/ipmcset [-l <location>] [-t <target>] -d <dataitem> [-s <systemid>] [-v <value>] | ||
| 81 | + ``` | ||
| 82 | + | ||
| 83 | +| 参数 | 必选 | 说明 | | ||
| 84 | +| --------------- | ---- | ------------------------------------------------------------ | | ||
| 85 | +| `-l <location>` | 否 | 机框/位置(仅当构建开启 `cli_l_supported` 时可用,默认关闭) | | ||
| 86 | +| `-t <target>` | 否 | 目标资源类型,缺省为 `_`(通配) | | ||
| 87 | +| `-d <dataitem>` | 是 | 数据项,如 `version`、`sensor`、`sel` | | ||
| 88 | +| `-s <systemid>` | 否 | 多机形态下的系统 ID | | ||
| 89 | +| `-v <value>` | 否 | 附加参数/配置值 | | ||
| 90 | + | ||
| 91 | + **可能抛出的异常及触发条件**(通过 `pcall` 捕获,打印到标准输出而非抛堆栈): | ||
| 92 | + | ||
| 93 | +| 输出 | 触发条件 | | ||
| 94 | +| -------------------------------------------------- | ---------------------------------------- | | ||
| 95 | +| `Invalid Command` | 路由映射器响应异常,或命令执行类型未注册 | | ||
| 96 | +| `Request failed.` | 后端服务返回错误(`errs` 非空) | | ||
| 97 | +| `Request failed, the echo profile does not exist.` | 回显模板文件缺失 | | ||
| 98 | +| `Invalid input` | 鉴权提示后,密码输入失败 | | ||
| 99 | +| 内部错误消息 | Lua 执行抛出未预期异常 | | ||
| 100 | + | ||
| 101 | + 参数不完整/非法时打印对应层级的帮助信息(Usage/参数列表/Example),不算异常。 | ||
| 102 | + | ||
| 103 | + **应用场景 / 限制条件**: | ||
| 104 | + | ||
| 105 | + - 场景:日常巡检(版本、传感器、SEL、日志查询)、配置下发、SOL 会话管理、用户口令管理。 | ||
| 106 | +- 限制:`ipmcget` 只读;写操作需对应权限,部分命令需二次确认或密码鉴权;`passwd` 命令仅在 `bmc.kepler.Cli.Command` 的 `Enabled` 属性为`True`(默认)时可用。mdb_interface 仓中定义了资源协作接口路径: `/bmc/kepler/:Customer/Cli/Command/:Id`。 | ||
| 70 | 107 | ||
| 71 | **调试示例**(命令底层直调,等价于在受限 Shell 内执行): | 108 | **调试示例**(命令底层直调,等价于在受限 Shell 内执行): |
| 72 | 109 | ||
| 73 | -```bash | 110 | + ```bash |
| 74 | # 查询版本 | 111 | # 查询版本 |
| 75 | -/opt/bmc/skynet/lua /opt/bmc/apps/cli/service/ipmcget.lua -d version | 112 | +ipmcset /opt/bmc/skynet/lua /opt/bmc/apps/cli/service/ipmcget.lua -d version |
| 76 | 113 | ||
| 77 | # 设置 SOL 超时时间 | 114 | # 设置 SOL 超时时间 |
| 78 | -/opt/bmc/skynet/lua /opt/bmc/apps/cli/service/ipmcset.lua -t sol -d timeout -v 15 | 115 | +ipmcset /opt/bmc/skynet/lua /opt/bmc/apps/cli/service/ipmcset.lua -t sol -d timeout -v 15 |
| 79 | # 期望输出:Set SOL timeout period successfully. | 116 | # 期望输出:Set SOL timeout period successfully. |
| 80 | -``` | 117 | + ``` |
| 81 | 118 | ||
| 82 | -非 Release 构建支持 `--verbose=<level>` 调整运行日志级别(`error/warning/notice/info/debug/mass`)。 | 119 | + 对于非 Release 构建,ipmcget/ipmcset 命令支持 `--verbose=<level>` 调整运行日志级别。 |
| 83 | 120 | ||
| 84 | -### 2.2 受限 Shell 调试命令 | 121 | +**调试示例** |
| 85 | - | ||
| 86 | -| 命令 | 作用 | | ||
| 87 | -| --- | --- | | ||
| 88 | -| `help` | 打印命令帮助 | | ||
| 89 | -| `notimeout` | 取消会话超时 | | ||
| 90 | -| `reboot [-f] [-r] [-R]` | 重启 BMC(`-f` 强制、`-r` 进入恢复模式、`-R` 重启并回滚) | | ||
| 91 | -| `rollback` | 强制重启并回滚 | | ||
| 92 | -| `passwd [options] [LOGIN]` | 修改/锁定/解锁账号口令 | | ||
| 93 | -| `mdbctl` | 在线调试命令(实现位于 mdbctl 组件) | | ||
| 94 | - | ||
| 95 | -### 2.3 通过 busctl / mdbctl 调试后端对象 | ||
| 96 | - | ||
| 97 | -命令本质是转成对资源树对象的 D-Bus 调用,可绕过 CLI 直接访问后端对象定位问题。 | ||
| 98 | 122 | ||
| 99 | ```bash | 123 | ```bash |
| 100 | -# 通用流程 | 124 | +# 设置日志级别为debug,查看详细调试信息 |
| 101 | -busctl --user --no-pager list # 列出服务 | 125 | +ipmcget --verbose=debug -d version |
| 102 | -busctl --user --no-pager tree <service> # 对象树 | 126 | +ipmcset --verbose=debug -d sel |
| 103 | -busctl --user --no-pager introspect <service> <path> # 接口/属性/方法 | 127 | + |
| 104 | -busctl --user --no-pager get-property <service> <path> <interface> <property> | 128 | +# 设置日志级别为info,查看一般信息 |
| 105 | -busctl --user --no-pager call <service> <path> <interface> <method> <signature> <args...> | 129 | +ipmcget --verbose=info -d sensorlist |
| 106 | -busctl --user --no-pager monitor # 监听属性变化 | 130 | +ipmcset --verbose=info -t syslog -d state -v enabled |
| 107 | ``` | 131 | ``` |
| 108 | 132 | ||
| 109 | -结合本组件代码中实际引用的对象: | 133 | +| `<level>` | 说明 | |
| 134 | +| --------- | -------------------- | | ||
| 135 | +| error | 仅错误信息 | | ||
| 136 | +| warning | 警告及以上 | | ||
| 137 | +| notice | 重要通知及以上 | | ||
| 138 | +| info | 一般信息(默认) | | ||
| 139 | +| debug | 详细调试信息 | | ||
| 140 | +| mass | 大量日志(最高级别) | | ||
| 110 | 141 | ||
| 111 | -```bash | 142 | + ### 2.2 受限 Shell 调试命令 |
| 112 | -# 查询单机/多机形态 | ||
| 113 | -busctl --user --no-pager get-property bmc.kepler.fructrl \ | ||
| 114 | - /bmc/kepler/Managers/1/Multihost \ | ||
| 115 | - bmc.kepler.Managers.Multihost HostType | ||
| 116 | 143 | ||
| 117 | -# 查询 SOL 模式/超时 | 144 | +| 命令 | 作用 | |
| 118 | -busctl --user --no-pager get-property bmc.kepler.rmcpd /bmc/kepler/Managers/1/SOL \ | 145 | +| -------------------------- | --------------------------------------------------------- | |
| 119 | - bmc.kepler.Managers.SOL Mode | 146 | +| `help` | 打印命令帮助 | |
| 120 | -``` | 147 | +| `exit` | 中止CLP会话 | |
| 148 | +| `ping` | 测试IPv4网络状态 | | ||
| 149 | +| `ping6` | 测试IPv6网络状态 | | ||
| 150 | +| `ifconfig` | 查看网络设备信息 | | ||
| 151 | +| `notimeout` | 取消登录会话超时 | | ||
| 152 | +| `free` | 检测内存状态 | | ||
| 153 | +| `top` | 检查系统资源使用情况。不接受参数 | | ||
| 154 | +| `df` | 检查磁盘使用情况 | | ||
| 155 | +| `netstat` | 用于检查端口状态 | | ||
| 156 | +| `route` | 用于检查路由信息。不接受参数 | | ||
| 157 | +| `reboot [-f] [-r] [-R]` | 重启 BMC(`-f` 强制、`-r` 进入恢复模式、`-R` 重启并回滚) | | ||
| 158 | +| `rollback` | 强制重启并回滚 | | ||
| 159 | +| `passwd [options] [LOGIN]` | 修改/锁定/解锁账号口令 | | ||
| 160 | +| `mdbctl` | 在线调试命令(实现位于 mdbctl 组件) | | ||
| 121 | 161 | ||
| 122 | -> `<service>` 用 `busctl --user list` 查询;具体签名以目标环境 `introspect` 为准。debug shell 中若 `busctl --user` 失败,先导出: | 162 | +------ |
| 123 | -> | ||
| 124 | -> ```bash | ||
| 125 | -> export XDG_RUNTIME_DIR=/run/user/0 | ||
| 126 | -> export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus | ||
| 127 | -> ``` | ||
| 128 | - | ||
| 129 | -mdbctl 常用子命令(实现见 mdbctl 组件):`attach` / `lsobj` / `lsprop` / `call` / `setprop modify`,完整语法与响应样例以 mdbctl 组件文档为准。 | ||
| 130 | - | ||
| 131 | ---- | ||
| 132 | 163 | ||
| 133 | ## 3. 组件扩展案例 | 164 | ## 3. 组件扩展案例 |
| 134 | 165 | ||
| 135 | -本组件支持**声明式配置 + 模板**扩展命令(主要在rackmount仓的interface_config/目录下),无需改动核心代码: | 166 | +### 3.1 扩展能力概述 |
Z | |||
| 136 | 167 | ||
| 137 | -| 扩展点 | 位置 | 作用 | | 168 | +本组件支持**声明式配置 + 模板**扩展命令(主要在rackmount仓的interface_config/目录下),无需改动核心代码。 |
| 138 | -| --- | --- | --- | | ||
| 139 | -| 接口配置 JSON(rackmount仓) | `interface_config/{ipmcget,ipmcset}/*.json` | URI → 后端调用映射、参数校验、回显引用 | | ||
| 140 | -| 回显模板(rackmount仓) | `interface_config/echoes/**` | 自定义输出格式(Lua 模板引擎) | | ||
| 141 | -| 客户/产品定制(rackmount仓) | `interface_config/customer/**`<br />`interface_config/<platform_board>/` | 按客户/产品替换配置与模板 | | ||
| 142 | -| 自定义路由脚本(cli组件仓) | `src/lualib/route/**` | 复杂命令定制逻辑(如 SOL activate) | | ||
| 143 | 169 | ||
| 144 | -**案例:新增一条配置命令(以 `sol/timeout` 为例,取自单元测试数据)** | 170 | +### 3.2 扩展点说明 |
| 145 | 171 | ||
| 146 | -Step 1:接口配置 `interface_config/cli/ipmcset/sol.json`,`Uri` 对应 `/cli/v1/<target>/<dataitem>`: | 172 | +| 扩展点 | 位置 | 作用 | |
| 173 | +| ---------------------------- | ------------------------------------------------------------ | -------------------------------------- | | ||
| 174 | +| 接口配置 JSON(rackmount仓) | `interface_config/{ipmcget,ipmcset}/*.json` | URI → 后端调用映射、参数校验、回显引用 | | ||
| 175 | +| 回显模板(rackmount仓) | `interface_config/echoes/**` | 自定义输出格式(Lua 模板引擎) | | ||
| 176 | +| 客户/产品定制(rackmount仓) | `interface_config/customer/**`<br />`interface_config/<platform_board>/` | 按客户/产品替换配置与模板 | | ||
| 177 | +| 自定义路由脚本(cli组件仓) | `src/lualib/route/**` | 复杂命令定制逻辑(如 SOL activate) | | ||
| 147 | 178 | ||
| 148 | -```json | 179 | + ### 3.3 二次开发指导 |
| 149 | -{ | ||
| 150 | - "Resources": [{ | ||
| 151 | - "Uri": "/cli/v1/sol/timeout", | ||
| 152 | - "Interfaces": [{ | ||
| 153 | - "Type": "Patch", | ||
| 154 | - "Usage": "ipmcset -t sol -d timeout -v <value>", | ||
| 155 | - "ReqBody": { | ||
| 156 | - "Type": "object", | ||
| 157 | - "Required": true, | ||
| 158 | - "Properties": { | ||
| 159 | - "Value": { "Required": true, "Type": "integer", "Validator": [{ "Type": "Range", "Formula": [0, 480] }] } | ||
| 160 | - } | ||
| 161 | - }, | ||
| 162 | - "ProcessingFlow": [{ | ||
| 163 | - "Type": "Method", | ||
| 164 | - "Path": "sol/SetTimeout", | ||
| 165 | - "Interface": "interface", | ||
| 166 | - "Name": "SetTimeout", | ||
| 167 | - "Params": ["${ReqBody/Value}"], | ||
| 168 | - "Destination": { "Result": "Result" } | ||
| 169 | - }], | ||
| 170 | - "Echoes": ["ipmcset/sol_timeout", ""] | ||
| 171 | - }] | ||
| 172 | - }] | ||
| 173 | -} | ||
| 174 | -``` | ||
| 175 | 180 | ||
| 176 | -Step 2:回显模板 `interface_config/cli/echoes/ipmcset/sol_timeout`: | 181 | +openUBMC社区的CLI接口采用接口映射配置方案实现,需要将命令配置到json文件中。CLI命令的接口映射配置文件位于 rackmount 代码仓的 interface_config/cli 路径下。参考社区文档: |
| 177 | 182 | ||
| 178 | -```text | 183 | +- [CLI接口映射配置指南](https://www.openubmc.cn/docs/zh/development/develop_guide/feature_development/CLI_mapping_guide.html) |
| 179 | -Set SOL timeout period {* Result == 0 and 'successfully' or 'failed' *}. | 184 | +- [北向接口映射器适配指导](https://www.openubmc.cn/docs/zh/development/develop_guide/feature_development/north_interface_mapper_adaptation_guideline.html) |
| 180 | -``` | 185 | +- [产品多层级接口定制](https://www.openubmc.cn/docs/zh/development/develop_guide/product_development/multi_level_customization.html) |
| 181 | 186 | ||
| 182 | -Step 3:验证 | 187 | +------ |
| 183 | - | ||
| 184 | -```bash | ||
| 185 | -/opt/bmc/skynet/lua /opt/bmc/apps/cli/service/ipmcset.lua -t sol -d timeout -v 15 | ||
| 186 | -# Set SOL timeout period successfully. | ||
| 187 | -``` | ||
| 188 | - | ||
| 189 | -模板标记(`src/lualib/template/parser.lua`):`{* expr *}` 原样输出、`{{ expr }}` 输出expr的结果(一些特殊符号将会被转义)、`{% lua %}` 语句、`{( view, ctx )}` 引入模板、`{# comment #}` 注释。 | ||
| 190 | - | ||
| 191 | -**参考文档**:[产品多层级接口定制](https://www.openubmc.cn/docs/zh/development/develop_guide/product_development/multi_level_customization.html) | ||
| 192 | - | ||
| 193 | ---- | ||
| 194 | 188 | ||
| 195 | ## 4. 问题定界指南 | 189 | ## 4. 问题定界指南 |
| 196 | 190 | ||
| @@ -198,44 +192,42 @@ Step 3:验证 | |||
| 198 | 192 | ||
| 199 | **典型问题**: | 193 | **典型问题**: |
| 200 | 194 | ||
| 201 | -| 现象 | 可能原因 | 定位 | | 195 | +| 现象 | 可能原因 | 定位 | |
| 202 | -| --- | --- | --- | | 196 | +| ----------------------- | -------------------------------------- | --------------------------------- | |
| 203 | -| `Invalid Command` | 接口配置缺 URI 或命令类型未注册 | 运行日志搜 `Invalid command type` | | 197 | +| `Invalid Command` | 接口配置缺 URI 或命令类型未注册 | 运行日志搜 `Invalid command type` | |
| 204 | -| `Request failed.` | 后端服务返回错误 | 查后端服务日志 | | 198 | +| `Request failed.` | 后端服务返回错误 | 查后端服务日志 | |
| 205 | | `COMMAND NOT SUPPORTED` | verb 未注册或功能未使能(如 `passwd`) | 检查 `help` 输出与 `Enabled` 开关 | | 199 | | `COMMAND NOT SUPPORTED` | verb 未注册或功能未使能(如 `passwd`) | 检查 `help` 输出与 `Enabled` 开关 | |
| 206 | -| 任务命令卡在进度 | 任务对象异常 | 运行日志搜 `get task failed` | | 200 | +| 任务命令卡在进度 | 任务对象异常 | 运行日志搜 `get task failed` | |
| 207 | 201 | ||
| 208 | -**关键错误码**(`src/clp/libs/common/inc/clp.h`):`241` FUNCTION_NOT_SUPPORTED、`245` REQUIRED_OPTION_MISSING、`253` COMMAND_NOT_RECOGNIZED、`254` COMMAND_NOT_SUPPORTED、`255` COMMAND_ERROR_UNSPECIFIED;口令相关 `0x83` 用户锁定、`0x96` 初始口令需重置等。 | 202 | + **关键错误码**(`src/clp/libs/common/inc/clp.h`):`241` FUNCTION_NOT_SUPPORTED、`245` REQUIRED_OPTION_MISSING、`253` COMMAND_NOT_RECOGNIZED、`254` COMMAND_NOT_SUPPORTED、`255` COMMAND_ERROR_UNSPECIFIED;口令相关 `0x83` 用户锁定、`0x96` 初始口令需重置等。 |
| 209 | 203 | ||
| 210 | -**复现方法**: | 204 | + **复现方法**: |
| 211 | 205 | ||
| 212 | -① `ipmcget --verbose=debug -d <dataitem>` 开日志; | 206 | + ① `ipmcget --verbose=debug -d <dataitem>` 开日志; |
| 213 | 207 | ||
| 214 | -② 底层直调排除 Shell 干扰(见 2.1); | 208 | + ② 底层直调排除 Shell 干扰(见 2.1); |
| 215 | 209 | ||
| 216 | -③ 核对 `interface_config` 配置; | 210 | + ③ 核对 `interface_config` 配置; |
| 217 | 211 | ||
| 218 | -④ `busctl`/`mdbctl` 直接访问后端对象判断问题在 CLI 层还是后端。 | 212 | + ④ `busctl`/`mdbctl` 直接访问后端对象判断问题在 CLI 层还是后端。 |
| 219 | 213 | ||
| 220 | ---- | 214 | +------ |
| 221 | 215 | ||
| 222 | -## 5. FAQ | 216 | + ## 5. FAQ |
| 223 | 217 | ||
| 224 | -**Q1:`ipmcget`/`ipmcset` 报 `Invalid Command`?** | 218 | + **Q1:`ipmcget`/`ipmcset` 报 `Invalid Command`?** |
| 225 | 命令未命中合法接口配置,或命令执行类型未注册。检查 `interface_config` 下 URI 配置;app日志搜 `Invalid command type`。 | 219 | 命令未命中合法接口配置,或命令执行类型未注册。检查 `interface_config` 下 URI 配置;app日志搜 `Invalid command type`。 |
| 226 | 220 | ||
| 227 | -**Q2:配置命令返回 `Request failed.`?** | 221 | + **Q2:配置命令返回 `Request failed.`?** |
| 228 | -命令已下发但后端返回错误。查app日志,或 `--verbose=debug` 提升日志级别。 | 222 | + 命令已下发但后端返回错误。查app日志,或 `--verbose=debug` 提升日志级别。 |
| 229 | 223 | ||
| 230 | -**Q3:受限 Shell 里 `passwd` 显示 `COMMAND NOT SUPPORTED`?** | 224 | + **Q3:受限 Shell 里 `passwd` 显示 `COMMAND NOT SUPPORTED`?** |
| 231 | -CLI 的 `passwd` 未使能(`bmc.kepler.Cli.Command` 的 `Enabled` 为false)。确认功能开关已打开。 | 225 | + CLI 的 `passwd` 未使能(`bmc.kepler.Cli.Command` 的 `Enabled` 为false)。确认功能开关已打开(见2.1 **应用场景 / 限制条件**)。 |
| 232 | 226 | ||
| 233 | -**Q4:一键日志包在哪?** | 227 | +```bash |
| 234 | -默认 `/tmp/dump_info.tar.gz`,可用 `ipmcget -d diaginfo -v <path>` 指定。 | 228 | +# 查看 passwd 命令状态 |
| 229 | +mdbctl get /bmc/kepler/openubmc/Cli/Command/passwd bmc.kepler.Cli.Command Enabled | ||
| 230 | +``` | ||
| 235 | 231 | ||
| 236 | ---- | 232 | + **Q4:一键日志包在哪?** |
| 237 | - | 233 | + 默认 `/tmp/dump_info.tar.gz`,可用 `ipmcget -d diaginfo -v <path>` 指定。 |
| 238 | -## 参考文档 | ||
| 239 | - | ||
| 240 | -- [CLI接口映射配置指南](https://www.openubmc.cn/docs/zh/development/develop_guide/feature_development/CLI_mapping_guide.html) | ||
| 241 | -- [北向接口映射器适配指导](https://www.openubmc.cn/docs/zh/development/develop_guide/feature_development/north_interface_mapper_adaptation_guideline.html) | ||
| @@ -0,0 +1 @@ | |||
| 1 | +Test Info : {* Info *} | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +{% | ||
| 2 | +if State == 'New' then | ||
| 3 | + echo('running...') | ||
| 4 | +end | ||
| 5 | + | ||
| 6 | +if State == 'Exception' or State == 'Killed' or State == 'Cancelled' then | ||
| 7 | + echo('Excute task demo failed.') | ||
| 8 | +end | ||
| 9 | + | ||
| 10 | +if State == 'Completed' then | ||
| 11 | + echo('Excute task demo successfully.') | ||
| 12 | +end | ||
| 13 | +%} | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "name": "cli", | 2 | "name": "cli", |
| 3 | - "version": "1.130.6", | 3 | + "version": "1.140.7", |
| 4 | "type": "command", | 4 | "type": "command", |
| 5 | "author": "Huawei", | 5 | "author": "Huawei", |
| 6 | "license": "Mulan PSL v2", | 6 | "license": "Mulan PSL v2", |
| @@ -13,16 +13,17 @@ | |||
| 13 | #ifndef CLP_COMMAND_H | 13 | #ifndef CLP_COMMAND_H |
| 14 | #define CLP_COMMAND_H | 14 | #define CLP_COMMAND_H |
| 15 | 15 | ||
| 16 | -#include "v3_adapter.h" | ||
| 17 | #include <clp.h> | 16 | #include <clp.h> |
| 18 | 17 | ||
| 19 | -#define RETREAT 127 | 18 | +#include "v3_adapter.h" |
| 19 | + | ||
| 20 | +#define RETREAT 127 | ||
| 20 | #define LINE_BREAK 3 | 21 | #define LINE_BREAK 3 |
| 21 | /* command handler function */ | 22 | /* command handler function */ |
| 22 | gint32 get_no_timeout_flag(void); | 23 | gint32 get_no_timeout_flag(void); |
| 23 | -void dal_clear_sensitive_info(gchar *buf, guint32 len); | 24 | +void dal_clear_sensitive_info(gchar* buf, guint32 len); |
| 24 | gint32 getch(void); | 25 | gint32 getch(void); |
| 25 | -gchar *safe_getstr(gsize max_len); | 26 | +gchar* safe_getstr(gsize max_len); |
| 26 | #endif | 27 | #endif |
| 27 | 28 | ||
| 28 | /* end of clp_command.h */ | 29 | /* end of clp_command.h */ |
| @@ -16,27 +16,27 @@ | |||
| 16 | #include "clp.h" | 16 | #include "clp.h" |
| 17 | 17 | ||
| 18 | // INPUT命令长度为 命令绝对目录地址+CLP输入字符串长度 | 18 | // INPUT命令长度为 命令绝对目录地址+CLP输入字符串长度 |
| 19 | -#define CLP_MAX_INPUT_LEN (SMASH_MAX_TOKENSIZE + 128) | 19 | +#define CLP_MAX_INPUT_LEN (SMASH_MAX_TOKENSIZE + 128) |
| 20 | -#define CLP_MAX_ARGV_NUM 32 | 20 | +#define CLP_MAX_ARGV_NUM 32 |
| 21 | #define SMASH_COMMAND_IPMCGET_HELP "ipmcget help" | 21 | #define SMASH_COMMAND_IPMCGET_HELP "ipmcget help" |
| 22 | 22 | ||
| 23 | #define IPMCGET_HELP_LEN 12 // IPMCGET_HELP_LEN应该等于strlen("ipmcget help") | 23 | #define IPMCGET_HELP_LEN 12 // IPMCGET_HELP_LEN应该等于strlen("ipmcget help") |
| 24 | 24 | ||
| 25 | typedef struct tag_target_command_s { | 25 | typedef struct tag_target_command_s { |
| 26 | - gchar *target; | 26 | + gchar* target; |
| 27 | - gchar *command; | 27 | + gchar* command; |
| 28 | - gint32 compare_num; | 28 | + gint32 compare_num; |
| 29 | } TARGET_COMMAND_CONF_S; | 29 | } TARGET_COMMAND_CONF_S; |
| 30 | 30 | ||
| 31 | -SMASH_CMD_T *smash_cmd_new(void); | 31 | +SMASH_CMD_T* smash_cmd_new(void); |
| 32 | -SMASH_TARGET_T *smash_target_new(void); | 32 | +SMASH_TARGET_T* smash_target_new(void); |
| 33 | -void smash_propval_delete(SMASH_PROPERTY_VALUE_T *pv); | 33 | +void smash_propval_delete(SMASH_PROPERTY_VALUE_T* pv); |
| 34 | -void smash_optval_delete(SMASH_OPTION_VALUE_T *ov); | 34 | +void smash_optval_delete(SMASH_OPTION_VALUE_T* ov); |
| 35 | -SMASH_UFIT_T *smash_ufit_new(void); | 35 | +SMASH_UFIT_T* smash_ufit_new(void); |
| 36 | 36 | ||
| 37 | -void smash_cmd_delete(SMASH_CMD_T *cmd); | 37 | +void smash_cmd_delete(SMASH_CMD_T* cmd); |
| 38 | -void smash_target_delete(SMASH_TARGET_T *target); | 38 | +void smash_target_delete(SMASH_TARGET_T* target); |
| 39 | 39 | ||
| 40 | -gint32 check_cmd_need_special_processing(gchar *cmd_history, gchar **ppvalue); | 40 | +gint32 check_cmd_need_special_processing(gchar* cmd_history, gchar** ppvalue); |
| 41 | -guint8 dal_str_mul_repeat_div(const gchar *str, guint8 len); | 41 | +guint8 dal_str_mul_repeat_div(const gchar* str, guint8 len); |
| 42 | #endif | 42 | #endif |
| @@ -16,49 +16,47 @@ | |||
| 16 | #include "clp.h" | 16 | #include "clp.h" |
| 17 | #include "v3_adapter.h" | 17 | #include "v3_adapter.h" |
| 18 | typedef struct { | 18 | typedef struct { |
| 19 | - SMASH_VERB_T verb_id; | 19 | + SMASH_VERB_T verb_id; |
| 20 | - const gchar *verb_name; | 20 | + const gchar* verb_name; |
| 21 | } SMASH_VERB_NAME_T; | 21 | } SMASH_VERB_NAME_T; |
| 22 | 22 | ||
| 23 | typedef struct { | 23 | typedef struct { |
| 24 | - SMASH_OPTION_T option_id; | 24 | + SMASH_OPTION_T option_id; |
| 25 | - const gchar *option_name; | 25 | + const gchar* option_name; |
| 26 | - const gchar *abbreviation; | 26 | + const gchar* abbreviation; |
| 27 | } SMASH_OPTION_NAME_T; | 27 | } SMASH_OPTION_NAME_T; |
| 28 | 28 | ||
| 29 | typedef enum { | 29 | typedef enum { |
| 30 | - OUTPUT_FORMAT, | 30 | + OUTPUT_FORMAT, |
| 31 | - OUTPUT_ERROR, | 31 | + OUTPUT_ERROR, |
| 32 | - OUTPUT_TERSE, | 32 | + OUTPUT_TERSE, |
| 33 | - OUTPUT_VERBOSE, | 33 | + OUTPUT_VERBOSE, |
| 34 | - OUTPUT_LANGUAGE, | 34 | + OUTPUT_LANGUAGE, |
| 35 | - OUTPUT_BEGIN, | 35 | + OUTPUT_BEGIN, |
| 36 | - OUTPUT_END, | 36 | + OUTPUT_END, |
| 37 | - OUTPUT_ORDER, | 37 | + OUTPUT_ORDER, |
| 38 | - OUTPUT_COUNT, | 38 | + OUTPUT_COUNT, |
| 39 | - OUTPUT_NUMBER, | 39 | + OUTPUT_NUMBER, |
| 40 | - NUM_OUTPUT_OPTIONS | 40 | + NUM_OUTPUT_OPTIONS |
| 41 | } SMASH_OUTPUT_OPTION_T; | 41 | } SMASH_OUTPUT_OPTION_T; |
| 42 | 42 | ||
| 43 | typedef struct { | 43 | typedef struct { |
| 44 | - SMASH_OUTPUT_OPTION_T option_id; | 44 | + SMASH_OUTPUT_OPTION_T option_id; |
| 45 | - const gchar *option_name; | 45 | + const gchar* option_name; |
| 46 | } clp_output_option_name_t; | 46 | } clp_output_option_name_t; |
| 47 | 47 | ||
| 48 | -gint32 clp_parser_tokenizer(SMASH_SESSION_T *session, const gchar *buf, | 48 | +gint32 clp_parser_tokenizer(SMASH_SESSION_T* session, const gchar* buf, vector_t* tokens); |
| 49 | - vector_t *tokens); | 49 | +SMASH_SESSION_T* pp_clp_open(const gchar* in_prompt); |
| 50 | -SMASH_SESSION_T *pp_clp_open(const gchar *in_prompt); | ||
| 51 | 50 | ||
| 52 | -gint32 pp_clp_verb_supports_option(SMASH_VERB_T verb, SMASH_OPTION_T option); | 51 | +gint32 pp_clp_verb_supports_option(SMASH_VERB_T verb, SMASH_OPTION_T option); |
| 53 | -SMASH_CMD_T *clp_token_check(SMASH_SESSION_T *session, vector_t *tokens); | 52 | +SMASH_CMD_T* clp_token_check(SMASH_SESSION_T* session, vector_t* tokens); |
| 54 | 53 | ||
| 55 | -void sfcc_cleanup(void); | 54 | +void sfcc_cleanup(void); |
| 56 | -gint32 parser_prompt_path(const gchar *prompt, vector_t *vector_path); | 55 | +gint32 parser_prompt_path(const gchar* prompt, vector_t* vector_path); |
| 57 | -gint32 parse_absolute_path(vector_t *vector); | 56 | +gint32 parse_absolute_path(vector_t* vector); |
| 58 | -BOOL_E is_supported_class_level(const gchar *class_name, const gint32 level); | 57 | +BOOL_E is_supported_class_level(const gchar* class_name, const gint32 level); |
| 59 | -gint32 trim_target(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 58 | +gint32 trim_target(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 60 | -void printf_command_exec_status(const STATUS_TAG_E ret, const ERR_TYPE_E err, | 59 | +void printf_command_exec_status(const STATUS_TAG_E ret, const ERR_TYPE_E err, const gint32 cim_err); |
| 61 | - const gint32 cim_err); | ||
| 62 | 60 | ||
| 63 | #endif | 61 | #endif |
| 64 | 62 | ||
| @@ -37,9 +37,9 @@ | |||
| 37 | #pragma pack(1) | 37 | #pragma pack(1) |
| 38 | 38 | ||
| 39 | typedef struct read_property_t { | 39 | typedef struct read_property_t { |
| 40 | - char *name; | 40 | + char* name; |
| 41 | - char *alias; | 41 | + char* alias; |
| 42 | - char value[MAX_PROPERTY_VALUE_LEN]; | 42 | + char value[MAX_PROPERTY_VALUE_LEN]; |
| 43 | } READ_PROPERTY_T, *PREAD_PROPERTY_T; | 43 | } READ_PROPERTY_T, *PREAD_PROPERTY_T; |
| 44 | 44 | ||
| 45 | #pragma pack() | 45 | #pragma pack() |
| @@ -13,117 +13,100 @@ | |||
| 13 | #ifndef V3_ADAPTER_H | 13 | #ifndef V3_ADAPTER_H |
| 14 | #define V3_ADAPTER_H | 14 | #define V3_ADAPTER_H |
| 15 | 15 | ||
| 16 | -#include "clp.h" | ||
| 17 | #include <dbus/dbus.h> | 16 | #include <dbus/dbus.h> |
| 18 | #include <glib-2.0/glib.h> | 17 | #include <glib-2.0/glib.h> |
| 19 | #include <securec.h> | 18 | #include <securec.h> |
| 20 | 19 | ||
| 21 | -#define IAM_SERVICE "bmc.kepler.iam" | 20 | +#include "clp.h" |
| 22 | -#define IAM_SERVICE_PATH "/bmc/kepler/iam" | 21 | + |
| 23 | -#define IAM_SERVICE_INTF "bmc.kepler.iam" | 22 | +#define IAM_SERVICE "bmc.kepler.iam" |
| 24 | -#define ACCOUNT_SERVICE "bmc.kepler.account" | 23 | +#define IAM_SERVICE_PATH "/bmc/kepler/iam" |
| 25 | -#define MDB_SERVICE "bmc.kepler.maca" | 24 | +#define IAM_SERVICE_INTF "bmc.kepler.iam" |
| 26 | -#define MDB_SERVICE_PATH "/bmc/kepler/MdbService" | 25 | +#define ACCOUNT_SERVICE "bmc.kepler.account" |
| 27 | -#define MDB_SERVICE_INTF "bmc.kepler.Mdb" | 26 | +#define MDB_SERVICE "bmc.kepler.maca" |
| 28 | -#define ACCOUNT_SERVICE_PATH "/bmc/kepler/AccountService" | 27 | +#define MDB_SERVICE_PATH "/bmc/kepler/MdbService" |
| 29 | -#define ACCOUNT_SERVICE_INTF "bmc.kepler.AccountService" | 28 | +#define MDB_SERVICE_INTF "bmc.kepler.Mdb" |
| 30 | -#define ACCOUNT_SERVICE_OEM_PATH \ | 29 | +#define ACCOUNT_SERVICE_PATH "/bmc/kepler/AccountService" |
| 31 | - "/bmc/kepler/AccountService/PasswordPolicys/OEM" | 30 | +#define ACCOUNT_SERVICE_INTF "bmc.kepler.AccountService" |
| 31 | +#define ACCOUNT_SERVICE_OEM_PATH "/bmc/kepler/AccountService/PasswordPolicys/OEM" | ||
| 32 | #define ACCOUNT_SERVICE_OEM_INTF "bmc.kepler.AccountService.PasswordPolicy" | 32 | #define ACCOUNT_SERVICE_OEM_INTF "bmc.kepler.AccountService.PasswordPolicy" |
| 33 | -#define ACCOUNTS_PATH "/bmc/kepler/AccountService/Accounts" | 33 | +#define ACCOUNTS_PATH "/bmc/kepler/AccountService/Accounts" |
| 34 | -#define MANAGER_ACCOUNT_INTF "bmc.kepler.AccountService.ManagerAccount" | 34 | +#define MANAGER_ACCOUNT_INTF "bmc.kepler.AccountService.ManagerAccount" |
| 35 | -#define ROLE_PATH "/bmc/kepler/AccountService/Roles" | 35 | +#define ROLE_PATH "/bmc/kepler/AccountService/Roles" |
| 36 | -#define ROLE_INTF "bmc.kepler.AccountService.Role" | 36 | +#define ROLE_INTF "bmc.kepler.AccountService.Role" |
| 37 | -#define AUTHENTICATION_PATH "/bmc/kepler/AccountService/Authentication" | 37 | +#define AUTHENTICATION_PATH "/bmc/kepler/AccountService/Authentication" |
| 38 | -#define AUTHENTICATION_INTF "bmc.kepler.AccountService.Authentication" | 38 | +#define AUTHENTICATION_INTF "bmc.kepler.AccountService.Authentication" |
| 39 | -#define PRODUCT_MGMT_SERVICE "bmc.kepler.product_mgmt" | 39 | +#define PRODUCT_MGMT_SERVICE "bmc.kepler.product_mgmt" |
| 40 | -#define PRODUCT_MGMT_BMC_PATH "/bmc/kepler/Managers/1/BMC" | 40 | +#define PRODUCT_MGMT_BMC_PATH "/bmc/kepler/Managers/1/BMC" |
| 41 | -#define PRODUCT_MGMT_BMC_INTF "bmc.kepler.Managers.BMC" | 41 | +#define PRODUCT_MGMT_BMC_INTF "bmc.kepler.Managers.BMC" |
| 42 | -#define CLI_SESSION_PATH "/bmc/kepler/SessionService/CLI" | 42 | +#define CLI_SESSION_PATH "/bmc/kepler/SessionService/CLI" |
| 43 | -#define CLI_SESSION_INTF "bmc.kepler.SessionService" | 43 | +#define CLI_SESSION_INTF "bmc.kepler.SessionService" |
| 44 | -#define MACA_SERVICE "bmc.kepler.maca" | 44 | +#define MACA_SERVICE "bmc.kepler.maca" |
| 45 | -#define MACA_PATH "/bmc/kepler/MacaService" | 45 | +#define MACA_PATH "/bmc/kepler/MacaService" |
| 46 | -#define SYSTEMCTL_INTERFACE "bmc.kepler.SystemControl" | 46 | +#define SYSTEMCTL_INTERFACE "bmc.kepler.SystemControl" |
| 47 | -#define SSH_LOGIN_FILE_NAME "/usr/sbin/ssh" | 47 | +#define SSH_LOGIN_FILE_NAME "/usr/sbin/ssh" |
| 48 | -#define SSHLOG_SCRIPT_PATH "/opt/bmc/lualib/commands/sshlogin.lua" | 48 | +#define SSHLOG_SCRIPT_PATH "/opt/bmc/lualib/commands/sshlogin.lua" |
| 49 | -#define PATH_MAX_LEN 256 | 49 | +#define PATH_MAX_LEN 256 |
| 50 | -#define PASSWD_MAX_LEN 512 | 50 | +#define PASSWD_MAX_LEN 512 |
| 51 | -#define PRIVS_MAX_NUM 9 | 51 | +#define PRIVS_MAX_NUM 9 |
| 52 | -#define DECIMAL_NUM 10 | 52 | +#define DECIMAL_NUM 10 |
| 53 | -#define USER_ID_MIN 2 | 53 | +#define USER_ID_MIN 2 |
| 54 | -#define USER_ID_MAX 17 | 54 | +#define USER_ID_MAX 17 |
| 55 | -#define CLI_INTERFACE_NAME "bmc.kepler.Cli.Command" | 55 | +#define CLI_INTERFACE_NAME "bmc.kepler.Cli.Command" |
| 56 | -#define NORMAL_REBOOT 0x00 | 56 | +#define NORMAL_REBOOT 0x00 |
| 57 | -#define MAXIMUM 115 | 57 | +#define MAXIMUM 115 |
| 58 | -#define MINIMUM 101 | 58 | +#define MINIMUM 101 |
| 59 | typedef struct { | 59 | typedef struct { |
| 60 | - const char *key; | 60 | + const char* key; |
| 61 | - const char *value; | 61 | + const char* value; |
| 62 | } DBUS_STRINF_MAP; | 62 | } DBUS_STRINF_MAP; |
| 63 | 63 | ||
| 64 | #define LDAP_USER_FILE "/dev/shm/uip_ldap_users" | 64 | #define LDAP_USER_FILE "/dev/shm/uip_ldap_users" |
| 65 | typedef struct LDAP_USER { | 65 | typedef struct LDAP_USER { |
| 66 | - guint8 used; // 0 未使用; 1 已使用 | 66 | + guint8 used; // 0 未使用; 1 已使用 |
| 67 | - gint32 uid; | 67 | + gint32 uid; |
| 68 | - gchar username[LDAP_USER_NAME_LEN]; | 68 | + gchar username[LDAP_USER_NAME_LEN]; |
| 69 | - gchar fromip[LDAP_USER_FROM_IP]; | 69 | + gchar fromip[LDAP_USER_FROM_IP]; |
| 70 | - guint8 serverid; | 70 | + guint8 serverid; |
| 71 | - guint8 groupid; | 71 | + guint8 groupid; |
| 72 | - guint8 privilege; | 72 | + guint8 privilege; |
| 73 | - guint8 roleid[LDAP_USER_ROLE_ID_NUM]; | 73 | + guint8 roleid[LDAP_USER_ROLE_ID_NUM]; |
| 74 | } LDAP_USER; | 74 | } LDAP_USER; |
| 75 | 75 | ||
| 76 | -void clp_method_operation_log(const gchar *username, const gchar *ipaddr, | 76 | +void clp_method_operation_log(const gchar* username, const gchar* ipaddr, const gchar* fmt, ...); |
| 77 | - const gchar *fmt, ...); | ||
| 78 | gint32 init_dbus_connection(void); | 77 | gint32 init_dbus_connection(void); |
| 79 | -void destroy_connection(void); | 78 | +void destroy_connection(void); |
| 80 | 79 | ||
| 81 | -gint32 get_property_value_uint32(const gchar *destination, const gchar *path, | 80 | +gint32 get_property_value_uint32(const gchar* destination, const gchar* path, const gchar* interface, |
| 82 | - const gchar *interface, | 81 | + const gchar* property_name, guint32* out_val); |
| 83 | - const gchar *property_name, guint32 *out_val); | 82 | +gint32 get_property_value_int32(const gchar* destination, const gchar* path, const gchar* interface, |
| 84 | -gint32 get_property_value_int32(const gchar *destination, const gchar *path, | 83 | + const gchar* property_name, gint32* out_val); |
| 85 | - const gchar *interface, | 84 | +gint32 get_property_value_byte(const gchar* destination, const gchar* path, const gchar* interface, |
| 86 | - const gchar *property_name, gint32 *out_val); | 85 | + const gchar* property_name, guchar* out_val); |
| 87 | -gint32 get_property_value_byte(const gchar *destination, const gchar *path, | 86 | +gint32 get_property_value_boolean(const gchar* destination, const gchar* path, const gchar* interface, |
| 88 | - const gchar *interface, | 87 | + const gchar* property_name, gboolean* out_val); |
| 89 | - const gchar *property_name, guchar *out_val); | 88 | +gint32 get_property_value_string(const gchar* destination, const gchar* path, const gchar* interface, |
| 90 | -gint32 get_property_value_boolean(const gchar *destination, const gchar *path, | 89 | + const gchar* property_name, gchar** out_val); |
| 91 | - const gchar *interface, | 90 | +gint32 get_property_value_string_array(const gchar* destination, const gchar* path, const gchar* interface, |
| 92 | - const gchar *property_name, | 91 | + const gchar* property_name, gchar* out_val[], gsize out_len); |
| 93 | - gboolean *out_val); | ||
| 94 | -gint32 get_property_value_string(const gchar *destination, const gchar *path, | ||
| 95 | - const gchar *interface, | ||
| 96 | - const gchar *property_name, gchar **out_val); | ||
| 97 | -gint32 get_property_value_string_array(const gchar *destination, | ||
| 98 | - const gchar *path, | ||
| 99 | - const gchar *interface, | ||
| 100 | - const gchar *property_name, | ||
| 101 | - gchar *out_val[], gsize out_len); | ||
| 102 | 92 | ||
| 103 | -void get_user_id_and_initial_flag(const gchar *username, guint8 *user_id, | 93 | +void get_user_id_and_initial_flag(const gchar* username, guint8* user_id, gboolean* initial_flag); |
| 104 | - gboolean *initial_flag); | 94 | +gint32 clp_get_username_ip(gchar* username, guint32 name_size, gchar* ip, guint32 ip_size); |
| 105 | -gint32 clp_get_username_ip(gchar *username, guint32 name_size, gchar *ip, | 95 | +gint32 clp_auth_user(guint8 user_id, const gchar* user_name, const gchar* passwd); |
| 106 | - guint32 ip_size); | 96 | +gint32 clp_set_user_password(guint8 user_id, const gchar* user_name, const gchar* passwd); |
| 107 | -gint32 clp_auth_user(guint8 user_id, const gchar *user_name, | ||
| 108 | - const gchar *passwd); | ||
| 109 | -gint32 clp_set_user_password(guint8 user_id, const gchar *user_name, | ||
| 110 | - const gchar *passwd); | ||
| 111 | gint32 clp_check_reset_password_privilege(guint8 user_id); | 97 | gint32 clp_check_reset_password_privilege(guint8 user_id); |
| 112 | 98 | ||
| 113 | -guint32 get_cli_session_timeout(void); | 99 | +guint32 get_cli_session_timeout(void); |
| 114 | -guchar get_software_type(void); | 100 | +guchar get_software_type(void); |
| 115 | gboolean get_weak_pwd_dict_enable(void); | 101 | gboolean get_weak_pwd_dict_enable(void); |
| 116 | -gint32 uip_check_login_limit_status(guint8 type, const gchar *user_name, | 102 | +gint32 uip_check_login_limit_status(guint8 type, const gchar* user_name, const gchar* ip_addr); |
| 117 | - const gchar *ip_addr); | 103 | +gint32 clp_check_system_lockdown(void); |
| 118 | -gint32 clp_check_system_lockdown(void); | 104 | +gint32 clp_call_maca_reboot(gchar* type, gchar* mode); |
| 119 | -gint32 clp_call_maca_reboot(gchar *type, gchar *mode); | 105 | +gint32 clp_check_passwd_privilege(gchar* username, guint8 user_id); |
| 120 | -gint32 clp_check_passwd_privilege(gchar *username, guint8 user_id); | 106 | +gint32 clp_check_sshlogin_privilege(gchar* username, guint8 user_id); |
| 121 | -gint32 clp_check_sshlogin_privilege(gchar *username, guint8 user_id); | 107 | +gint32 clp_set_user_lock(guint8 user_id, const gchar* user_name, dbus_bool_t value); |
| 122 | -gint32 clp_set_user_lock(guint8 user_id, const gchar *user_name, | 108 | +gint32 get_passwd_parameter(const gchar* username); |
| 123 | - dbus_bool_t value); | 109 | +gint32 get_passwd_administrators_number(const gchar* username); |
| 124 | -gint32 get_passwd_parameter(const gchar *username); | 110 | +gint32 clp_set_user_lock(guint8 user_id, const gchar* user_name, dbus_bool_t value); |
| 125 | -gint32 get_passwd_administrators_number(const gchar *username); | 111 | +gint32 get_cli_enabled(gboolean* initial_state); |
| 126 | -gint32 clp_set_user_lock(guint8 user_id, const gchar *user_name, | ||
| 127 | - dbus_bool_t value); | ||
| 128 | -gint32 get_cli_enabled(gboolean *initial_state); | ||
| 129 | #endif | 112 | #endif |
| @@ -13,29 +13,29 @@ | |||
| 13 | #ifndef __VECTOR_H__ | 13 | #ifndef __VECTOR_H__ |
| 14 | #define __VECTOR_H__ | 14 | #define __VECTOR_H__ |
| 15 | 15 | ||
| 16 | -#include <glib-2.0/glib.h> | ||
| 17 | #include <stdint.h> | 16 | #include <stdint.h> |
| 18 | 17 | ||
| 19 | -typedef void (*vector_elem_del_func_simple)(void *var); | 18 | +#include <glib-2.0/glib.h> |
| 19 | + | ||
| 20 | +typedef void (*vector_elem_del_func_simple)(void* var); | ||
| 20 | 21 | ||
| 21 | typedef struct __vector_t { | 22 | typedef struct __vector_t { |
| 22 | - gulong pos; // 记录数据在buf的位置 | 23 | + gulong pos; // 记录数据在buf的位置 |
| 23 | - gulong max_count; // 总的buf个数 | 24 | + gulong max_count; // 总的buf个数 |
| 24 | - gulong cur_count; // 当前有效buf个数 | 25 | + gulong cur_count; // 当前有效buf个数 |
| 25 | - gulong *buf; // 地址记录 | 26 | + gulong* buf; // 地址记录 |
| 26 | - vector_elem_del_func_simple free_callback; // 资源释放回调函数 | 27 | + vector_elem_del_func_simple free_callback; // 资源释放回调函数 |
| 27 | } vector_t; | 28 | } vector_t; |
| 28 | 29 | ||
| 29 | -vector_t *vector_new(vector_t *new_vector, gulong number, | 30 | +vector_t* vector_new(vector_t* new_vector, gulong number, vector_elem_del_func_simple func); |
| 30 | - vector_elem_del_func_simple func); | 31 | +void vector_delete(vector_t* new_vector); |
| 31 | -void vector_delete(vector_t *new_vector); | 32 | +gint32 vector_add(vector_t* vector, const void* object); // 与remove对应 |
| 32 | -gint32 vector_add(vector_t *vector, const void *object); // 与remove对应 | 33 | +gint32 vector_remove(vector_t* vector, gint32 pos); // 与add对应 |
| 33 | -gint32 vector_remove(vector_t *vector, gint32 pos); // 与add对应 | 34 | +uintptr_t vector_get(vector_t* new_vector, |
| 34 | -uintptr_t vector_get(vector_t *new_vector, | 35 | + guint32 pos); // 返回对应pos的vector 地址 |
| 35 | - guint32 pos); // 返回对应pos的vector 地址 | 36 | +gulong vector_size(vector_t* new_vector); // 返回vector大小 |
| 36 | -gulong vector_size(vector_t *new_vector); // 返回vector大小 | ||
| 37 | 37 | ||
| 38 | -void vector_replace(vector_t *vector); // 主要用于对层级无要求的场合 | 38 | +void vector_replace(vector_t* vector); // 主要用于对层级无要求的场合 |
| 39 | 39 | ||
| 40 | #endif | 40 | #endif |
| 41 | 41 | ||
| @@ -11,6 +11,7 @@ | |||
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include "common_help.h" | 13 | #include "common_help.h" |
| 14 | + | ||
| 14 | #include "v3_adapter.h" | 15 | #include "v3_adapter.h" |
| 15 | 16 | ||
| 16 | #define SSH_FILE_NAME "/usr/bin/ssh" | 17 | #define SSH_FILE_NAME "/usr/bin/ssh" |
| @@ -18,44 +19,44 @@ | |||
| 18 | /* | 19 | /* |
| 19 | * Description: 如果输入的help格式不对打印的默认帮助信息 | 20 | * Description: 如果输入的help格式不对打印的默认帮助信息 |
| 20 | */ | 21 | */ |
| 21 | -void help_info_general(void) { | 22 | +void help_info_general(void) |
| 22 | - g_printf("Commands:\n"); | 23 | +{ |
| 24 | + g_printf("Commands:\n"); | ||
| 23 | 25 | ||
| 24 | - g_printf("help : Used to get context sensitive help.\n"); | 26 | + g_printf("help : Used to get context sensitive help.\n"); |
| 25 | - g_printf("exit : Used to terminate the CLP session.\n"); | 27 | + g_printf("exit : Used to terminate the CLP session.\n"); |
| 26 | - g_printf("ipmcget : Used to get BMC runtime status.\n"); | 28 | + g_printf("ipmcget : Used to get BMC runtime status.\n"); |
| 27 | - g_printf("ipmcset : Used to set BMC runtime status or send control " | 29 | + g_printf("ipmcset : Used to set BMC runtime status or send control " |
| 28 | - "command.\n"); | 30 | + "command.\n"); |
| 29 | - g_printf("notimeout : Used to set no timeout limit to login shell.\n"); | 31 | + g_printf("notimeout : Used to set no timeout limit to login shell.\n"); |
| 30 | - g_printf("mdbctl : Used to maintain in debug mode.\n"); | 32 | + g_printf("mdbctl : Used to maintain in debug mode.\n"); |
| 31 | - g_printf("ping : Used to test IPv4 network status.\n"); | 33 | + g_printf("ping : Used to test IPv4 network status.\n"); |
| 32 | - g_printf("ping6 : Used to test IPv6 network status.\n"); | 34 | + g_printf("ping6 : Used to test IPv6 network status.\n"); |
| 33 | - g_printf("ifconfig : Used to check network device information.\n"); | 35 | + g_printf("ifconfig : Used to check network device information.\n"); |
| 34 | - g_printf("free : Used to check memory status.\n"); | 36 | + g_printf("free : Used to check memory status.\n"); |
| 35 | - g_printf("top : Used to check system resource used information. " | 37 | + g_printf("top : Used to check system resource used information. " |
| 36 | - "None parameter is allowed\n"); | 38 | + "None parameter is allowed\n"); |
| 37 | - g_printf("df : Used to check disk used information.\n"); | 39 | + g_printf("df : Used to check disk used information.\n"); |
| 38 | - g_printf("route : Used to check route information. None parameter " | 40 | + g_printf("route : Used to check route information. None parameter " |
| 39 | - "is allowed\n"); | 41 | + "is allowed\n"); |
| 40 | - g_printf("netstat : Used to check network port status.\n"); | 42 | + g_printf("netstat : Used to check network port status.\n"); |
| 41 | - g_printf("reboot : Used to reboot BMC system.\n"); | 43 | + g_printf("reboot : Used to reboot BMC system.\n"); |
| 42 | - g_printf("rollback : Used to reboot BMC and rollback.\n"); | 44 | + g_printf("rollback : Used to reboot BMC and rollback.\n"); |
| 43 | - gboolean initial_state = FALSE; | 45 | + gboolean initial_state = FALSE; |
| 44 | - gint32 ret = get_cli_enabled(&initial_state); | 46 | + gint32 ret = get_cli_enabled(&initial_state); |
| 45 | - if (ret == RET_OK) { | 47 | + if (ret == RET_OK) { |
| 46 | - if (initial_state) { | 48 | + if (initial_state) { |
| 47 | - g_printf("passwd : Used to changes passwords for user accounts, " | 49 | + g_printf("passwd : Used to changes passwords for user accounts, " |
| 48 | - "lock or unlock accounts.\n"); | 50 | + "lock or unlock accounts.\n"); |
| 51 | + } | ||
| 52 | + } | ||
| 53 | + if (TRUE == vos_get_file_accessible(SSH_FILE_NAME)) { | ||
| 54 | + g_printf("ssh : Used to connect to another devices.\n"); | ||
| 55 | + } | ||
| 56 | + if (vos_get_file_accessible(SSH_LOGIN_FILE_NAME) == TRUE && vos_get_file_accessible(SSHLOG_SCRIPT_PATH) == TRUE) { | ||
| 57 | + g_printf("sshlogin : Used to log in to the Management Controller " | ||
| 58 | + "CLI at a specific location via SSH.\n"); | ||
| 49 | } | 59 | } |
| 50 | - } | ||
| 51 | - if (TRUE == vos_get_file_accessible(SSH_FILE_NAME)) { | ||
| 52 | - g_printf("ssh : Used to connect to another devices.\n"); | ||
| 53 | - } | ||
| 54 | - if (vos_get_file_accessible(SSH_LOGIN_FILE_NAME) == TRUE && | ||
| 55 | - vos_get_file_accessible(SSHLOG_SCRIPT_PATH) == TRUE) { | ||
| 56 | - g_printf("sshlogin : Used to log in to the Management Controller " | ||
| 57 | - "CLI at a specific location via SSH.\n"); | ||
| 58 | - } | ||
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | /* end of common_help.c */ | 62 | /* end of common_help.c */ |
| @@ -11,185 +11,188 @@ | |||
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include "vector.h" | 13 | #include "vector.h" |
| 14 | + | ||
| 14 | #include "clp.h" | 15 | #include "clp.h" |
| 15 | 16 | ||
| 16 | /* | 17 | /* |
| 17 | * Description: 创建新的vector | 18 | * Description: 创建新的vector |
| 18 | */ | 19 | */ |
| 19 | -vector_t *vector_new(vector_t *new_vector, gulong number, | 20 | +vector_t* vector_new(vector_t* new_vector, gulong number, vector_elem_del_func_simple func) |
| 20 | - vector_elem_del_func_simple func) { | 21 | +{ |
| 21 | - vector_t *vector = NULL; | 22 | + vector_t* vector = NULL; |
| 22 | 23 | ||
| 23 | - if (number == 0) { | 24 | + if (number == 0) { |
| 24 | - return NULL; | 25 | + return NULL; |
| 25 | - } | ||
| 26 | - | ||
| 27 | - /* 多次使用的时候为避免使用的时候忘记释放导致多次malloc造成内存泄露在这里增加NULL检测 | ||
| 28 | - */ | ||
| 29 | - if (new_vector == NULL) { | ||
| 30 | - vector = (vector_t *)calloc(1, sizeof(vector_t)); | ||
| 31 | - if (vector == NULL) { | ||
| 32 | - return NULL; | ||
| 33 | } | 26 | } |
| 34 | - } else { | ||
| 35 | - vector = new_vector; | ||
| 36 | - } | ||
| 37 | 27 | ||
| 38 | - vector->max_count = number; // 总的buf地址个数 | 28 | + /* 多次使用的时候为避免使用的时候忘记释放导致多次malloc造成内存泄露在这里增加NULL检测 |
| 39 | - vector->cur_count = 0; | 29 | + */ |
| 40 | - vector->pos = 0; // buf的初始位置为0 | 30 | + if (new_vector == NULL) { |
| 41 | - vector->free_callback = func; | 31 | + vector = (vector_t*)calloc(1, sizeof(vector_t)); |
| 42 | - vector->buf = | 32 | + if (vector == NULL) { |
| 43 | - (gulong *)calloc(vector->max_count, sizeof(gulong)); // 申请buf地址空间 | 33 | + return NULL; |
| 44 | - | 34 | + } |
| 45 | - if (vector->buf == NULL) { | 35 | + } else { |
| 46 | - if (!new_vector) { | 36 | + vector = new_vector; |
| 47 | - free(vector); | ||
| 48 | - vector = NULL; | ||
| 49 | } | 37 | } |
| 50 | - } | ||
| 51 | 38 | ||
| 52 | - return vector; | 39 | + vector->max_count = number; // 总的buf地址个数 |
| 40 | + vector->cur_count = 0; | ||
| 41 | + vector->pos = 0; // buf的初始位置为0 | ||
| 42 | + vector->free_callback = func; | ||
| 43 | + vector->buf = (gulong*)calloc(vector->max_count, sizeof(gulong)); // 申请buf地址空间 | ||
| 44 | + | ||
| 45 | + if (vector->buf == NULL) { | ||
| 46 | + if (!new_vector) { | ||
| 47 | + free(vector); | ||
| 48 | + vector = NULL; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return vector; | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | /* | 55 | /* |
| 56 | * Description: 删除创建的vector | 56 | * Description: 删除创建的vector |
| 57 | */ | 57 | */ |
| 58 | -void vector_delete(vector_t *vector) { | 58 | +void vector_delete(vector_t* vector) |
| 59 | - guint32 idx = 0; | 59 | +{ |
| 60 | + guint32 idx = 0; | ||
| 60 | 61 | ||
| 61 | - if ((vector == NULL) || (vector->buf == NULL)) { | 62 | + if ((vector == NULL) || (vector->buf == NULL)) { |
| 62 | - return; | 63 | + return; |
| 63 | - } | ||
| 64 | - | ||
| 65 | - for (idx = 0; idx < vector->max_count; idx++) { | ||
| 66 | - if (vector->buf[idx] != 0) { | ||
| 67 | - vector_remove(vector, idx); | ||
| 68 | } | 64 | } |
| 69 | - } | ||
| 70 | 65 | ||
| 71 | - free(vector->buf); | 66 | + for (idx = 0; idx < vector->max_count; idx++) { |
| 72 | - vector->buf = NULL; | 67 | + if (vector->buf[idx] != 0) { |
| 73 | - vector->max_count = 0; | 68 | + vector_remove(vector, idx); |
| 74 | - vector->cur_count = 0; | 69 | + } |
| 75 | - vector->pos = 0; | 70 | + } |
| 76 | - vector->free_callback = NULL; // 回调函数清除 | 71 | + |
| 72 | + free(vector->buf); | ||
| 73 | + vector->buf = NULL; | ||
| 74 | + vector->max_count = 0; | ||
| 75 | + vector->cur_count = 0; | ||
| 76 | + vector->pos = 0; | ||
| 77 | + vector->free_callback = NULL; // 回调函数清除 | ||
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | /* | 80 | /* |
| 80 | * Description: 向vector的buf里添数据 | 81 | * Description: 向vector的buf里添数据 |
| 81 | */ | 82 | */ |
| 82 | -gint32 vector_add(vector_t *vector, const void *object) { | 83 | +gint32 vector_add(vector_t* vector, const void* object) |
| 83 | - guint32 idx = 0; | 84 | +{ |
| 84 | - errno_t safe_fun_ret; | 85 | + guint32 idx = 0; |
| 85 | - gulong buf_loc_val = 0; | 86 | + errno_t safe_fun_ret; |
| 87 | + gulong buf_loc_val = 0; | ||
| 86 | 88 | ||
| 87 | - if (vector == NULL || object == NULL || vector->buf == NULL) { | 89 | + if (vector == NULL || object == NULL || vector->buf == NULL) { |
| 88 | - return PP_ERR_NULL; | 90 | + return PP_ERR_NULL; |
| 89 | - } | ||
| 90 | - | ||
| 91 | - if (vector->cur_count > vector->max_count) { | ||
| 92 | - return PP_ERR_OUTOFRANGE; | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - for (idx = 0; idx < vector->max_count; idx++) { | ||
| 96 | - if (vector->buf[idx] != 0) { | ||
| 97 | - continue; | ||
| 98 | } | 91 | } |
| 99 | - safe_fun_ret = | ||
| 100 | - memcpy_s(&buf_loc_val, sizeof(gulong), &object, sizeof(void *)); | ||
| 101 | - if (safe_fun_ret != EOK) { | ||
| 102 | - debug_log(DLOG_ERROR, "%s: memcpy_s fail, ret = %d", __FUNCTION__, | ||
| 103 | - safe_fun_ret); | ||
| 104 | - return PP_ERR_INTERNAL; | ||
| 105 | - } | ||
| 106 | - vector->buf[idx] = buf_loc_val; // 获取对象地址 | ||
| 107 | - vector->cur_count++; // 添加一个增加一个 | ||
| 108 | - return PP_SUC; | ||
| 109 | - } | ||
| 110 | 92 | ||
| 111 | - return PP_ERR_INTERNAL; | 93 | + if (vector->cur_count > vector->max_count) { |
| 94 | + return PP_ERR_OUTOFRANGE; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + for (idx = 0; idx < vector->max_count; idx++) { | ||
| 98 | + if (vector->buf[idx] != 0) { | ||
| 99 | + continue; | ||
| 100 | + } | ||
| 101 | + safe_fun_ret = memcpy_s(&buf_loc_val, sizeof(gulong), &object, sizeof(void*)); | ||
| 102 | + if (safe_fun_ret != EOK) { | ||
| 103 | + debug_log(DLOG_ERROR, "%s: memcpy_s fail, ret = %d", __FUNCTION__, safe_fun_ret); | ||
| 104 | + return PP_ERR_INTERNAL; | ||
| 105 | + } | ||
| 106 | + vector->buf[idx] = buf_loc_val; // 获取对象地址 | ||
| 107 | + vector->cur_count++; // 添加一个增加一个 | ||
| 108 | + return PP_SUC; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + return PP_ERR_INTERNAL; | ||
| 112 | } | 112 | } |
| 113 | /* | 113 | /* |
| 114 | * Description: 移除vector里指定的buf数据 | 114 | * Description: 移除vector里指定的buf数据 |
| 115 | */ | 115 | */ |
| 116 | -gint32 vector_remove(vector_t *vector, gint32 pos) { | 116 | +gint32 vector_remove(vector_t* vector, gint32 pos) |
| 117 | - if (vector == NULL || vector->buf == NULL) { | 117 | +{ |
| 118 | - return PP_ERR_NULL; | 118 | + if (vector == NULL || vector->buf == NULL) { |
| 119 | - } | 119 | + return PP_ERR_NULL; |
| 120 | - | ||
| 121 | - if (vector->max_count == 0) { // pos非法 | ||
| 122 | - return PP_ERR_OUTOFRANGE; | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - if (vector->buf[pos]) { | ||
| 126 | - gpointer object = (gpointer)vector->buf[pos]; | ||
| 127 | - if (vector->free_callback != NULL) { | ||
| 128 | - vector->free_callback(object); | ||
| 129 | } | 120 | } |
| 130 | - vector->buf[pos] = 0; | ||
| 131 | - vector->cur_count--; | ||
| 132 | - } | ||
| 133 | 121 | ||
| 134 | - return PP_SUC; | 122 | + if (vector->max_count == 0) { // pos非法 |
| 123 | + return PP_ERR_OUTOFRANGE; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + if (vector->buf[pos]) { | ||
| 127 | + gpointer object = (gpointer)vector->buf[pos]; | ||
| 128 | + if (vector->free_callback != NULL) { | ||
| 129 | + vector->free_callback(object); | ||
| 130 | + } | ||
| 131 | + vector->buf[pos] = 0; | ||
| 132 | + vector->cur_count--; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + return PP_SUC; | ||
| 135 | } | 136 | } |
| 136 | 137 | ||
| 137 | /* | 138 | /* |
| 138 | * Description: 获取vector指定位置buf的地址 | 139 | * Description: 获取vector指定位置buf的地址 |
| 139 | */ | 140 | */ |
| 140 | -uintptr_t vector_get(vector_t *vector, guint32 pos) { | 141 | +uintptr_t vector_get(vector_t* vector, guint32 pos) |
| 141 | - if (vector == NULL || vector->buf == NULL) { | 142 | +{ |
| 142 | - return ILLEGAL_ADDR; // 非法地址 | 143 | + if (vector == NULL || vector->buf == NULL) { |
| 143 | - } | 144 | + return ILLEGAL_ADDR; // 非法地址 |
| 145 | + } | ||
| 144 | 146 | ||
| 145 | - if (vector->max_count == 0 || pos > (vector->max_count - 1) || | 147 | + if (vector->max_count == 0 || pos > (vector->max_count - 1) || (vector->cur_count == 0)) { // pos非法 |
| 146 | - (vector->cur_count == 0)) { // pos非法 | 148 | + return ILLEGAL_ADDR; // 非法地址 |
| 147 | - return ILLEGAL_ADDR; // 非法地址 | 149 | + } |
| 148 | - } | ||
| 149 | 150 | ||
| 150 | - return (uintptr_t)vector->buf[pos]; | 151 | + return (uintptr_t)vector->buf[pos]; |
| 151 | } | 152 | } |
| 152 | 153 | ||
| 153 | /* | 154 | /* |
| 154 | * Description: 获取vector的buf大小 | 155 | * Description: 获取vector的buf大小 |
| 155 | */ | 156 | */ |
| 156 | -gulong vector_size(vector_t *vector) { | 157 | +gulong vector_size(vector_t* vector) |
| 157 | - if (vector == NULL || vector->buf == NULL) { | 158 | +{ |
| 158 | - return 0; | 159 | + if (vector == NULL || vector->buf == NULL) { |
| 159 | - } | 160 | + return 0; |
| 161 | + } | ||
| 160 | 162 | ||
| 161 | - return vector->cur_count; | 163 | + return vector->cur_count; |
| 162 | } | 164 | } |
| 163 | 165 | ||
| 164 | /* | 166 | /* |
| 165 | * Description: buf中不允许间隔出现有效地址 该函数功能是将buf从新排序 | 167 | * Description: buf中不允许间隔出现有效地址 该函数功能是将buf从新排序 |
| 166 | * 与remove可配合使用保证非零地址排在前面 | 168 | * 与remove可配合使用保证非零地址排在前面 |
| 167 | */ | 169 | */ |
| 168 | -void vector_replace(vector_t *vector) { | 170 | +void vector_replace(vector_t* vector) |
| 169 | - guint32 i = 0; | 171 | +{ |
| 170 | - guint32 idx = 0; | 172 | + guint32 i = 0; |
| 173 | + guint32 idx = 0; | ||
| 171 | 174 | ||
| 172 | - if ((vector == NULL) || (vector->max_count == 0)) { | 175 | + if ((vector == NULL) || (vector->max_count == 0)) { |
| 173 | - return; | 176 | + return; |
| 174 | - } | ||
| 175 | - gulong *buf_temp = (gulong *)calloc(vector->max_count, sizeof(gulong)); | ||
| 176 | - | ||
| 177 | - if (buf_temp == NULL) { | ||
| 178 | - return; | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - for (i = 0; i < vector->max_count; i++) { | ||
| 182 | - if (vector->buf[i] == 0) { | ||
| 183 | - continue; | ||
| 184 | } | 177 | } |
| 185 | - buf_temp[idx++] = vector->buf[i]; | 178 | + gulong* buf_temp = (gulong*)calloc(vector->max_count, sizeof(gulong)); |
| 186 | - } | ||
| 187 | 179 | ||
| 188 | - for (i = 0; i < vector->max_count; i++) { | 180 | + if (buf_temp == NULL) { |
| 189 | - vector->buf[i] = buf_temp[i]; | 181 | + return; |
| 190 | - } | 182 | + } |
| 191 | 183 | ||
| 192 | - free(buf_temp); | 184 | + for (i = 0; i < vector->max_count; i++) { |
| 185 | + if (vector->buf[i] == 0) { | ||
| 186 | + continue; | ||
| 187 | + } | ||
| 188 | + buf_temp[idx++] = vector->buf[i]; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + for (i = 0; i < vector->max_count; i++) { | ||
| 192 | + vector->buf[i] = buf_temp[i]; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + free(buf_temp); | ||
| 193 | } | 196 | } |
| 194 | 197 | ||
| 195 | /* End of vector.c */ | 198 | /* End of vector.c */ |
| @@ -13,45 +13,46 @@ | |||
| 13 | #ifndef COMMAND_IFCONFIG_H | 13 | #ifndef COMMAND_IFCONFIG_H |
| 14 | #define COMMAND_IFCONFIG_H | 14 | #define COMMAND_IFCONFIG_H |
| 15 | 15 | ||
| 16 | +#include <lualib.h> | ||
| 17 | +#include <termio.h> | ||
| 18 | + | ||
| 19 | +#include <lauxlib.h> | ||
| 20 | +#include <lua.h> | ||
| 21 | + | ||
| 16 | #include "clp.h" | 22 | #include "clp.h" |
| 17 | #include "clp_common.h" | 23 | #include "clp_common.h" |
| 18 | #include "command.h" | 24 | #include "command.h" |
| 19 | #include "v3_adapter.h" | 25 | #include "v3_adapter.h" |
| 20 | -#include <lauxlib.h> | ||
| 21 | -#include <lua.h> | ||
| 22 | -#include <lualib.h> | ||
| 23 | -#include <termio.h> | ||
| 24 | 26 | ||
| 25 | -#define VOS_TICK_PER_SECOND 1000 | 27 | +#define VOS_TICK_PER_SECOND 1000 |
| 26 | -#define CHANGING_PASSWD 1 | 28 | +#define CHANGING_PASSWD 1 |
| 27 | -#define CHANGING_USER_PASSWD 2 | 29 | +#define CHANGING_USER_PASSWD 2 |
| 28 | -#define LOCK_OR_UNLOCK 3 | 30 | +#define LOCK_OR_UNLOCK 3 |
| 29 | -#define SYSTEMLOCK_SERVICE "bmc.kepler.fructrl" | 31 | +#define SYSTEMLOCK_SERVICE "bmc.kepler.fructrl" |
| 30 | #define SYSTEMLOCK_SERVICE_PATH "/bmc/kepler/Systems/1" | 32 | #define SYSTEMLOCK_SERVICE_PATH "/bmc/kepler/Systems/1" |
| 31 | #define SYSTEMLOCK_SERVICE_INTF "bmc.kepler.Systems.SystemLockDown" | 33 | #define SYSTEMLOCK_SERVICE_INTF "bmc.kepler.Systems.SystemLockDown" |
| 32 | 34 | ||
| 33 | -void init_dbus_env_var(void); | 35 | +void init_dbus_env_var(void); |
| 34 | -gint32 clp_verb_handler_ipmcget(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 36 | +gint32 clp_verb_handler_ipmcget(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 35 | -gint32 clp_verb_handler_ipmcset(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 37 | +gint32 clp_verb_handler_ipmcset(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 36 | -gint32 clp_verb_handler_mdbctl(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 38 | +gint32 clp_verb_handler_mdbctl(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 37 | -gint32 clp_verb_handler_ifconfig(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 39 | +gint32 clp_verb_handler_ifconfig(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 38 | -gint32 clp_verb_handler_ping(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 40 | +gint32 clp_verb_handler_ping(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 39 | -gint32 clp_verb_handler_ping6(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 41 | +gint32 clp_verb_handler_ping6(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 40 | -gint32 clp_verb_handler_route(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 42 | +gint32 clp_verb_handler_route(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 41 | -gint32 clp_verb_handler_time_out(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 43 | +gint32 clp_verb_handler_time_out(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 42 | -gint32 clp_verb_handler_free(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 44 | +gint32 clp_verb_handler_free(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 43 | -gint32 clp_verb_handler_top(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 45 | +gint32 clp_verb_handler_top(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 44 | -gint32 clp_verb_handler_df(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 46 | +gint32 clp_verb_handler_df(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 45 | -gint32 clp_verb_handler_netstat(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 47 | +gint32 clp_verb_handler_netstat(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 46 | -gint32 clp_verb_handler_help(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 48 | +gint32 clp_verb_handler_help(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 47 | gint32 get_no_timeout_flag(void); | 49 | gint32 get_no_timeout_flag(void); |
| 48 | -gint32 clp_verb_handler_ssh(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 50 | +gint32 clp_verb_handler_ssh(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 49 | -gint32 clp_verb_handler_reboot(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 51 | +gint32 clp_verb_handler_reboot(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 50 | -gint32 reset_password(guint8 user_id, const gchar *user_name, | 52 | +gint32 reset_password(guint8 user_id, const gchar* user_name, const gchar* new_user_name, const gchar* ip_addr, |
| 51 | - const gchar *new_user_name, const gchar *ip_addr, | ||
| 52 | guint8 new_user_id); | 53 | guint8 new_user_id); |
| 53 | -gint32 clp_verb_handler_passwd(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 54 | +gint32 clp_verb_handler_passwd(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 54 | -gint32 clp_verb_handler_rollback(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 55 | +gint32 clp_verb_handler_rollback(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 55 | -gint32 clp_verb_handler_sshlogin(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 56 | +gint32 clp_verb_handler_sshlogin(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 56 | 57 | ||
| 57 | #endif | 58 | #endif |
| @@ -26,210 +26,208 @@ | |||
| 26 | // clang-format on | 26 | // clang-format on |
| 27 | 27 | ||
| 28 | #define MAX_DBUS_ENV_VAR_NUM 4 | 28 | #define MAX_DBUS_ENV_VAR_NUM 4 |
| 29 | -#define PARAMETER_LEN 64 | 29 | +#define PARAMETER_LEN 64 |
| 30 | -#define LOGNAME_LEN (PARAMETER_LEN + 9) | 30 | +#define LOGNAME_LEN (PARAMETER_LEN + 9) |
| 31 | -#define SSH_CONNECTION_LEN (PARAMETER_LEN + 16) | 31 | +#define SSH_CONNECTION_LEN (PARAMETER_LEN + 16) |
| 32 | -#define REMOTEHOST_LEN (PARAMETER_LEN + 12) | 32 | +#define REMOTEHOST_LEN (PARAMETER_LEN + 12) |
| 33 | -#define ENV_NUM 8 /* 命令参数个数 */ | 33 | +#define ENV_NUM 8 /* 命令参数个数 */ |
| 34 | 34 | ||
| 35 | /* | 35 | /* |
| 36 | * Description: 系统信号处理, 只处理断连信号,忽略其他信号 | 36 | * Description: 系统信号处理, 只处理断连信号,忽略其他信号 |
| 37 | */ | 37 | */ |
| 38 | -static void clp_ouch_deal_default(gint32 sig) { | 38 | +static void clp_ouch_deal_default(gint32 sig) |
| 39 | - if (sig == SIGCHLD) { | 39 | +{ |
| 40 | - return; | 40 | + if (sig == SIGCHLD) { |
| 41 | - } | 41 | + return; |
| 42 | + } | ||
| 42 | 43 | ||
| 43 | - // 直接断连,会产生SIGHUP信号,在这里退出进程 | 44 | + // 直接断连,会产生SIGHUP信号,在这里退出进程 |
| 44 | - if (sig == SIGHUP) { | 45 | + if (sig == SIGHUP) { |
| 45 | - _exit(0); | 46 | + _exit(0); |
| 46 | - } | 47 | + } |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | -LOCAL gint32 system_s(const gchar *path, gchar *cmdstring[], | 50 | +LOCAL gint32 system_s(const gchar* path, gchar* cmdstring[], gchar* envstring[]) |
| 50 | - gchar *envstring[]) { | 51 | +{ |
| 51 | - pid_t pid; | 52 | + pid_t pid; |
| 52 | - sig_t old_handler; | 53 | + sig_t old_handler; |
| 53 | 54 | ||
| 54 | - if ((cmdstring == NULL) || (path == NULL) || (envstring == NULL)) { | 55 | + if ((cmdstring == NULL) || (path == NULL) || (envstring == NULL)) { |
| 55 | - debug_log(DLOG_ERROR, "invalid params"); | 56 | + debug_log(DLOG_ERROR, "invalid params"); |
| 56 | - return VOS_ERR; | 57 | + return VOS_ERR; |
| 57 | - } | 58 | + } |
| 59 | + | ||
| 60 | + old_handler = signal(SIGCHLD, SIG_DFL); | ||
| 61 | + if ((pid = fork()) < 0) { | ||
| 62 | + debug_log(DLOG_ERROR, "%s: failed to fork: %s", __FUNCTION__, g_strerror(errno)); | ||
| 63 | + (void)signal(SIGCHLD, old_handler); | ||
| 64 | + return VOS_ERR; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + if (pid == 0) { | ||
| 68 | + gint32 fds = getdtablesize(); | ||
| 69 | + /* 文件标识符,跳过标准输入、输出与标准错误输出 */ | ||
| 70 | + for (gint32 i = 3; i < fds; i++) { | ||
| 71 | + (void)close(i); | ||
| 72 | + } | ||
| 73 | + exit(execve(path, cmdstring, envstring)); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + gint32 ret; | ||
| 77 | + gint32 status; | ||
| 78 | + do { | ||
| 79 | + ret = waitpid(pid, &status, 0); | ||
| 80 | + } while ((ret == -1) && (errno == EINTR)); | ||
| 81 | + | ||
| 82 | + if (WIFEXITED(status) == 0) { | ||
| 83 | + debug_log(DLOG_ERROR, "%s: failed, Failed to waitpid : %s", __FUNCTION__, cmdstring[0]); | ||
| 84 | + return VOS_ERR; | ||
| 85 | + } | ||
| 58 | 86 | ||
| 59 | - old_handler = signal(SIGCHLD, SIG_DFL); | ||
| 60 | - if ((pid = fork()) < 0) { | ||
| 61 | - debug_log(DLOG_ERROR, "%s: failed to fork: %s", __FUNCTION__, | ||
| 62 | - g_strerror(errno)); | ||
| 63 | (void)signal(SIGCHLD, old_handler); | 87 | (void)signal(SIGCHLD, old_handler); |
| 64 | - return VOS_ERR; | 88 | + return WEXITSTATUS(status); |
| 65 | - } | ||
| 66 | - | ||
| 67 | - if (pid == 0) { | ||
| 68 | - gint32 fds = getdtablesize(); | ||
| 69 | - /* 文件标识符,跳过标准输入、输出与标准错误输出 */ | ||
| 70 | - for (gint32 i = 3; i < fds; i++) { | ||
| 71 | - (void)close(i); | ||
| 72 | - } | ||
| 73 | - exit(execve(path, cmdstring, envstring)); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - gint32 ret; | ||
| 77 | - gint32 status; | ||
| 78 | - do { | ||
| 79 | - ret = waitpid(pid, &status, 0); | ||
| 80 | - } while ((ret == -1) && (errno == EINTR)); | ||
| 81 | - | ||
| 82 | - if (WIFEXITED(status) == 0) { | ||
| 83 | - debug_log(DLOG_ERROR, "%s: failed, Failed to waitpid : %s", __FUNCTION__, | ||
| 84 | - cmdstring[0]); | ||
| 85 | - return VOS_ERR; | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - (void)signal(SIGCHLD, old_handler); | ||
| 89 | - return WEXITSTATUS(status); | ||
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | -LOCAL gint32 init_dbus_env_var(gchar *env[], guint32 *count) { | 91 | +LOCAL gint32 init_dbus_env_var(gchar* env[], guint32* count) |
| 92 | +{ | ||
| 93 | #define MAX_ENV_LINE_SIZE 256 | 93 | #define MAX_ENV_LINE_SIZE 256 |
| 94 | - if (setuid(0) != 0) { // root:0 | 94 | + if (setuid(0) != 0) { // root:0 |
| 95 | - g_printf("Set uid failed.\r\n"); | 95 | + g_printf("Set uid failed.\r\n"); |
| 96 | - return -1; | 96 | + return -1; |
| 97 | - } | 97 | + } |
| 98 | 98 | ||
| 99 | - FILE *fp = fopen_s("/dev/shm/dbus/.dbus", "r", NULL); | 99 | + FILE* fp = fopen_s("/dev/shm/dbus/.dbus", "r", NULL); |
| 100 | - if (fp == NULL) { | 100 | + if (fp == NULL) { |
| 101 | - debug_log(DLOG_ERROR, "%s: Open the file of dbus failed", __FUNCTION__); | 101 | + debug_log(DLOG_ERROR, "%s: Open the file of dbus failed", __FUNCTION__); |
| 102 | - return -1; | 102 | + return -1; |
| 103 | - } | 103 | + } |
| 104 | + | ||
| 105 | + if (setuid(101) != 0) { // comm_user:101 | ||
| 106 | + g_printf("Set uid failed.\r\n"); | ||
| 107 | + (void)fclose(fp); | ||
| 108 | + return -1; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + gchar line[MAX_ENV_LINE_SIZE] = {0}; | ||
| 112 | + while (fgets(line, MAX_ENV_LINE_SIZE, fp) != NULL) { | ||
| 113 | + if (*count >= MAX_DBUS_ENV_VAR_NUM) { | ||
| 114 | + debug_log(DLOG_ERROR, | ||
| 115 | + "%s: The number of dbus environment variables exceeds the " | ||
| 116 | + "upper limit", | ||
| 117 | + __FUNCTION__); | ||
| 118 | + (void)fclose(fp); | ||
| 119 | + return -1; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + if (line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n') { | ||
| 123 | + line[strlen(line) - 1] = '\0'; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + env[(*count)++] = g_strdup(line); | ||
| 127 | + } | ||
| 104 | 128 | ||
| 105 | - if (setuid(101) != 0) { // comm_user:101 | ||
| 106 | - g_printf("Set uid failed.\r\n"); | ||
| 107 | (void)fclose(fp); | 129 | (void)fclose(fp); |
| 108 | - return -1; | ||
| 109 | - } | ||
| 110 | 130 | ||
| 111 | - gchar line[MAX_ENV_LINE_SIZE] = {0}; | 131 | + return 0; |
| 112 | - while (fgets(line, MAX_ENV_LINE_SIZE, fp) != NULL) { | ||
| 113 | - if (*count >= MAX_DBUS_ENV_VAR_NUM) { | ||
| 114 | - debug_log(DLOG_ERROR, | ||
| 115 | - "%s: The number of dbus environment variables exceeds the " | ||
| 116 | - "upper limit", | ||
| 117 | - __FUNCTION__); | ||
| 118 | - (void)fclose(fp); | ||
| 119 | - return -1; | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - if (line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n') { | ||
| 123 | - line[strlen(line) - 1] = '\0'; | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - env[(*count)++] = g_strdup(line); | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - (void)fclose(fp); | ||
| 130 | - | ||
| 131 | - return 0; | ||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | -LOCAL gint32 init_env_var(gchar *env[]) { | 134 | +LOCAL gint32 init_env_var(gchar* env[]) |
| 135 | - guint32 count = 0; | 135 | +{ |
| 136 | - if (init_dbus_env_var(env, &count) != 0) { | 136 | + guint32 count = 0; |
| 137 | - return -1; | 137 | + if (init_dbus_env_var(env, &count) != 0) { |
| 138 | - } | 138 | + return -1; |
| 139 | - | ||
| 140 | - gint32 ret; | ||
| 141 | - | ||
| 142 | - const gchar *temp_log_name = NULL; | ||
| 143 | - if ((temp_log_name = g_getenv("LOGNAME")) != NULL) { | ||
| 144 | - gchar log_name[LOGNAME_LEN] = {}; /* CLP登录的用户 */ | ||
| 145 | - ret = snprintf_s(log_name, LOGNAME_LEN, LOGNAME_LEN - 1, "LOGNAME=%s", | ||
| 146 | - temp_log_name); | ||
| 147 | - if (ret <= 0) { | ||
| 148 | - debug_log(DLOG_ERROR, "%s: snprintf_s failed, ret = %d", __FUNCTION__, | ||
| 149 | - ret); | ||
| 150 | - return -1; | ||
| 151 | } | 139 | } |
| 152 | - env[count++] = g_strdup(log_name); | ||
| 153 | - } | ||
| 154 | 140 | ||
| 155 | - const gchar *temp_ssh_connection = NULL; | 141 | + gint32 ret; |
| 156 | - if ((temp_ssh_connection = g_getenv("SSH_CONNECTION")) != NULL) { | 142 | + |
| 157 | - gchar ssh_connection[SSH_CONNECTION_LEN] = {}; /* CLP登录后记录日志的用户 */ | 143 | + const gchar* temp_log_name = NULL; |
| 158 | - ret = snprintf_s(ssh_connection, SSH_CONNECTION_LEN, SSH_CONNECTION_LEN - 1, | 144 | + if ((temp_log_name = g_getenv("LOGNAME")) != NULL) { |
| 159 | - "SSH_CONNECTION=%s", temp_ssh_connection); | 145 | + gchar log_name[LOGNAME_LEN] = {}; /* CLP登录的用户 */ |
| 160 | - if (ret <= 0) { | 146 | + ret = snprintf_s(log_name, LOGNAME_LEN, LOGNAME_LEN - 1, "LOGNAME=%s", temp_log_name); |
| 161 | - debug_log(DLOG_ERROR, "%s: snprintf_s failed, ret = %d", __FUNCTION__, | 147 | + if (ret <= 0) { |
| 162 | - ret); | 148 | + debug_log(DLOG_ERROR, "%s: snprintf_s failed, ret = %d", __FUNCTION__, ret); |
| 163 | - return -1; | 149 | + return -1; |
| 150 | + } | ||
| 151 | + env[count++] = g_strdup(log_name); | ||
| 164 | } | 152 | } |
| 165 | - env[count++] = g_strdup(ssh_connection); | ||
| 166 | - } | ||
| 167 | 153 | ||
| 168 | - const gchar *temp_remote_host = NULL; | 154 | + const gchar* temp_ssh_connection = NULL; |
| 169 | - if ((temp_remote_host = g_getenv("REMOTEHOST")) != NULL) { | 155 | + if ((temp_ssh_connection = g_getenv("SSH_CONNECTION")) != NULL) { |
| 170 | - gchar remote_host[REMOTEHOST_LEN] = {}; /* CLP登录的IP地址 */ | 156 | + gchar ssh_connection[SSH_CONNECTION_LEN] = {}; /* CLP登录后记录日志的用户 */ |
| 171 | - ret = snprintf_s(remote_host, REMOTEHOST_LEN, REMOTEHOST_LEN - 1, | 157 | + ret = snprintf_s(ssh_connection, SSH_CONNECTION_LEN, SSH_CONNECTION_LEN - 1, "SSH_CONNECTION=%s", |
| 172 | - "REMOTEHOST=%s", temp_remote_host); | 158 | + temp_ssh_connection); |
| 173 | - if (ret <= 0) { | 159 | + if (ret <= 0) { |
| 174 | - debug_log(DLOG_ERROR, "%s: snprintf_s failed, ret = %d", __FUNCTION__, | 160 | + debug_log(DLOG_ERROR, "%s: snprintf_s failed, ret = %d", __FUNCTION__, ret); |
| 175 | - ret); | 161 | + return -1; |
| 176 | - return -1; | 162 | + } |
| 163 | + env[count++] = g_strdup(ssh_connection); | ||
| 177 | } | 164 | } |
| 178 | - env[count] = g_strdup(remote_host); | ||
| 179 | - } | ||
| 180 | 165 | ||
| 181 | - return 0; | 166 | + const gchar* temp_remote_host = NULL; |
| 167 | + if ((temp_remote_host = g_getenv("REMOTEHOST")) != NULL) { | ||
| 168 | + gchar remote_host[REMOTEHOST_LEN] = {}; /* CLP登录的IP地址 */ | ||
| 169 | + ret = snprintf_s(remote_host, REMOTEHOST_LEN, REMOTEHOST_LEN - 1, "REMOTEHOST=%s", temp_remote_host); | ||
| 170 | + if (ret <= 0) { | ||
| 171 | + debug_log(DLOG_ERROR, "%s: snprintf_s failed, ret = %d", __FUNCTION__, ret); | ||
| 172 | + return -1; | ||
| 173 | + } | ||
| 174 | + env[count] = g_strdup(remote_host); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + return 0; | ||
| 182 | } | 178 | } |
| 183 | 179 | ||
| 184 | -void free_env(gchar *env[]) { | 180 | +void free_env(gchar* env[]) |
| 185 | - for (gint32 i = 0; i < ENV_NUM; ++i) { | 181 | +{ |
| 186 | - if (env[i] != NULL) { | 182 | + for (gint32 i = 0; i < ENV_NUM; ++i) { |
| 187 | - g_free(env[i]); | 183 | + if (env[i] != NULL) { |
| 188 | - env[i] = NULL; | 184 | + g_free(env[i]); |
| 185 | + env[i] = NULL; | ||
| 186 | + } | ||
| 189 | } | 187 | } |
| 190 | - } | ||
| 191 | } | 188 | } |
| 192 | 189 | ||
| 193 | /* | 190 | /* |
| 194 | * Description: 主函数 | 191 | * Description: 主函数 |
| 195 | */ | 192 | */ |
| 196 | -gint32 main(gint32 argc, gchar *argv[]) { | 193 | +gint32 main(gint32 argc, gchar* argv[]) |
| 197 | - uid_t old_uid = getuid(); | 194 | +{ |
| 198 | - gchar *user_name = (gchar *)g_getenv("LOGNAME"); | 195 | + uid_t old_uid = getuid(); |
| 199 | - gchar *comm = ""; | 196 | + gchar* user_name = (gchar*)g_getenv("LOGNAME"); |
| 197 | + gchar* comm = ""; | ||
| 200 | 198 | ||
| 201 | - char old_uid_str[32]; // uid最大长度32 - 1 | 199 | + char old_uid_str[32]; // uid最大长度32 - 1 |
| 202 | - (void)sprintf_s(old_uid_str, sizeof(old_uid_str), "%d", old_uid); | 200 | + (void)sprintf_s(old_uid_str, sizeof(old_uid_str), "%d", old_uid); |
| 203 | - if ((argc > 2) && (strcmp(argv[1], "-c") == 0x00)) { | 201 | + if ((argc > 2) && (strcmp(argv[1], "-c") == 0x00)) { |
| 204 | - comm = argv[2]; | 202 | + comm = argv[2]; |
| 205 | - } | 203 | + } |
| 206 | 204 | ||
| 207 | - gchar *argv2[5] = {NULL}; /* 5:命令参数个数 */ | 205 | + gchar* argv2[5] = {NULL}; /* 5:命令参数个数 */ |
| 208 | - argv2[0] = "/usr/bin/clp_comm"; /* 0:命令参数0 */ | 206 | + argv2[0] = "/usr/bin/clp_comm"; /* 0:命令参数0 */ |
| 209 | - argv2[1] = old_uid_str; /* 1:命令参数1 */ | 207 | + argv2[1] = old_uid_str; /* 1:命令参数1 */ |
| 210 | - argv2[2] = user_name; /* 2:命令参数2 */ | 208 | + argv2[2] = user_name; /* 2:命令参数2 */ |
| 211 | - argv2[3] = comm; /* 3:命令参数3 */ | 209 | + argv2[3] = comm; /* 3:命令参数3 */ |
| 212 | - argv2[4] = NULL; /* 4:命令参数4 */ | 210 | + argv2[4] = NULL; /* 4:命令参数4 */ |
| 213 | 211 | ||
| 214 | - /* 注册信号处理函数 */ | 212 | + /* 注册信号处理函数 */ |
| 215 | - for (gint32 i = SIGHUP; i <= SIGSYS; i++) { | 213 | + for (gint32 i = SIGHUP; i <= SIGSYS; i++) { |
| 216 | - (void)signal(i, clp_ouch_deal_default); | 214 | + (void)signal(i, clp_ouch_deal_default); |
| 217 | - } | 215 | + } |
| 218 | 216 | ||
| 219 | - gchar *env[ENV_NUM] = {NULL}; | 217 | + gchar* env[ENV_NUM] = {NULL}; |
| 220 | - gint32 ret = init_env_var(env); | 218 | + gint32 ret = init_env_var(env); |
| 221 | - if (ret != 0) { | 219 | + if (ret != 0) { |
| 222 | - g_printf("start clp_commands failed: %d\r\n", ret); | 220 | + g_printf("start clp_commands failed: %d\r\n", ret); |
| 221 | + free_env(env); | ||
| 222 | + return -1; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + ret = system_s("/usr/bin/clp_comm", argv2, env); | ||
| 226 | + if (ret != 0) { | ||
| 227 | + g_printf("start clp_commands failed: %d\r\n", ret); | ||
| 228 | + free_env(env); | ||
| 229 | + return -1; | ||
| 230 | + } | ||
| 223 | free_env(env); | 231 | free_env(env); |
| 224 | - return -1; | 232 | + return 0; |
| 225 | - } | ||
| 226 | - | ||
| 227 | - ret = system_s("/usr/bin/clp_comm", argv2, env); | ||
| 228 | - if (ret != 0) { | ||
| 229 | - g_printf("start clp_commands failed: %d\r\n", ret); | ||
| 230 | - free_env(env); | ||
| 231 | - return -1; | ||
| 232 | - } | ||
| 233 | - free_env(env); | ||
| 234 | - return 0; | ||
| 235 | } | 233 | } |
| @@ -26,184 +26,192 @@ | |||
| 26 | 26 | ||
| 27 | #define LUA_LIB | 27 | #define LUA_LIB |
| 28 | 28 | ||
| 29 | -static int l_redirect_start_print(lua_State *L) { | 29 | +static int l_redirect_start_print(lua_State* L) |
| 30 | - const char *content = luaL_checkstring(L, 1); | 30 | +{ |
| 31 | + const char* content = luaL_checkstring(L, 1); | ||
| 31 | 32 | ||
| 32 | - printf("\r%s", content); | 33 | + printf("\r%s", content); |
| 33 | - (void)fflush(stdout); | 34 | + (void)fflush(stdout); |
| 34 | 35 | ||
| 35 | - lua_pushinteger(L, 0); | 36 | + lua_pushinteger(L, 0); |
| 36 | - return 1; | 37 | + return 1; |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 39 | -#define MS_PER_SECOND 1000 | 40 | +#define MS_PER_SECOND 1000 |
| 40 | #define US_PER_MILIISECOND 1000 | 41 | #define US_PER_MILIISECOND 1000 |
| 41 | #define MS_PER_HARF_SECOND 500 | 42 | #define MS_PER_HARF_SECOND 500 |
| 42 | -static int l_delay(lua_State *L) { | 43 | +static int l_delay(lua_State* L) |
| 43 | - guint16 millisecond = luaL_checkinteger(L, 1); | 44 | +{ |
| 44 | - if (millisecond < MS_PER_SECOND) { | 45 | + guint16 millisecond = luaL_checkinteger(L, 1); |
| 45 | - (void)usleep(millisecond * US_PER_MILIISECOND); | 46 | + if (millisecond < MS_PER_SECOND) { |
| 46 | - } else { | 47 | + (void)usleep(millisecond * US_PER_MILIISECOND); |
| 47 | - (void)sleep((millisecond + MS_PER_HARF_SECOND) / MS_PER_SECOND); | 48 | + } else { |
| 48 | - } | 49 | + (void)sleep((millisecond + MS_PER_HARF_SECOND) / MS_PER_SECOND); |
| 50 | + } | ||
| 49 | 51 | ||
| 50 | - lua_pushinteger(L, 0); | 52 | + lua_pushinteger(L, 0); |
| 51 | - return 1; | 53 | + return 1; |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | -static gint32 getch(void) { | 56 | +static gint32 getch(void) |
| 55 | - struct termios cu_time; | 57 | +{ |
| 56 | - struct termios tm_old; | 58 | + struct termios cu_time; |
| 57 | - gint32 fd = 0; | 59 | + struct termios tm_old; |
| 60 | + gint32 fd = 0; | ||
| 58 | 61 | ||
| 59 | - if (tcgetattr(fd, &cu_time) < 0) { | 62 | + if (tcgetattr(fd, &cu_time) < 0) { |
| 60 | - return -1; | 63 | + return -1; |
| 61 | - } | 64 | + } |
| 62 | 65 | ||
| 63 | - tm_old = cu_time; | 66 | + tm_old = cu_time; |
| 64 | - cfmakeraw(&cu_time); | 67 | + cfmakeraw(&cu_time); |
| 65 | 68 | ||
| 66 | - if (tcsetattr(fd, TCSANOW, &cu_time) < 0) { | 69 | + if (tcsetattr(fd, TCSANOW, &cu_time) < 0) { |
| 67 | - return -1; | 70 | + return -1; |
| 68 | - } | 71 | + } |
| 69 | 72 | ||
| 70 | - gint32 c = fgetc(stdin); | 73 | + gint32 c = fgetc(stdin); |
| 71 | - if (tcsetattr(fd, TCSANOW, &tm_old) < 0) { | 74 | + if (tcsetattr(fd, TCSANOW, &tm_old) < 0) { |
| 72 | - return -1; | 75 | + return -1; |
| 73 | - } | 76 | + } |
| 74 | 77 | ||
| 75 | - return c; | 78 | + return c; |
| 76 | } | 79 | } |
| 77 | 80 | ||
| 78 | -#define ALARM 0x07 | 81 | +#define ALARM 0x07 |
| 79 | #define BACKSPACE 0x08 | 82 | #define BACKSPACE 0x08 |
| 80 | #define LINE_FEED 0x0a | 83 | #define LINE_FEED 0x0a |
| 81 | -#define ENTER 0x0d | 84 | +#define ENTER 0x0d |
| 82 | -#define SPACE 0x20 | 85 | +#define SPACE 0x20 |
| 83 | -#define DELETE 0x7f | 86 | +#define DELETE 0x7f |
| 84 | 87 | ||
| 85 | #define MAX_LINE_STR_SIZE 1024 | 88 | #define MAX_LINE_STR_SIZE 1024 |
| 86 | -static int l_get_line_without_echo(lua_State *L) { | 89 | +static int l_get_line_without_echo(lua_State* L) |
| 87 | - /* 输出提示信息 */ | 90 | +{ |
| 88 | - const char *prompt = luaL_checkstring(L, 1); | 91 | + /* 输出提示信息 */ |
| 89 | - printf("%s", prompt); | 92 | + const char* prompt = luaL_checkstring(L, 1); |
| 93 | + printf("%s", prompt); | ||
| 90 | 94 | ||
| 91 | - int status = 0; | 95 | + int status = 0; |
| 92 | - char str[MAX_LINE_STR_SIZE + 1] = {0}; | 96 | + char str[MAX_LINE_STR_SIZE + 1] = {0}; |
| 93 | - gint32 c; | 97 | + gint32 c; |
| 94 | - gsize i = 0; | 98 | + gsize i = 0; |
| 95 | 99 | ||
| 96 | - /* 无回显获取输入,直到获取到回车/换行为止 */ | 100 | + /* 无回显获取输入,直到获取到回车/换行为止 */ |
| 97 | - while ((c = getch()) != -1 && c != LINE_FEED && c != ENTER) { | 101 | + while ((c = getch()) != -1 && c != LINE_FEED && c != ENTER) { |
| 98 | - if (c == BACKSPACE || c == DELETE) { | 102 | + if (c == BACKSPACE || c == DELETE) { |
| 99 | - if (i == 0) { | 103 | + if (i == 0) { |
| 100 | - (void)putchar(ALARM); | 104 | + (void)putchar(ALARM); |
| 101 | - } else { | 105 | + } else { |
| 102 | - str[--i] = '\0'; | 106 | + str[--i] = '\0'; |
| 103 | - } | 107 | + } |
| 104 | - continue; | 108 | + continue; |
| 109 | + } | ||
| 110 | + | ||
| 111 | + if (c < SPACE || c > DELETE) { | ||
| 112 | + printf("[Error] Input password contains incorrect characters"); | ||
| 113 | + status = -1; | ||
| 114 | + (void)memset_s(str, sizeof(str), 0, sizeof(str)); | ||
| 115 | + break; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /* 限定输入长度,超过长度作提示 */ | ||
| 119 | + if (i >= MAX_LINE_STR_SIZE) { | ||
| 120 | + printf("[Error] The input length is too long"); | ||
| 121 | + status = -1; | ||
| 122 | + (void)memset_s(str, sizeof(str), 0, sizeof(str)); | ||
| 123 | + break; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + str[i++] = (char)c; | ||
| 105 | } | 127 | } |
| 106 | 128 | ||
| 107 | - if (c < SPACE || c > DELETE) { | 129 | + printf("\n"); |
| 108 | - printf("[Error] Input password contains incorrect characters"); | 130 | + lua_pushinteger(L, status); |
| 109 | - status = -1; | 131 | + lua_pushstring(L, str); |
| 110 | - (void)memset_s(str, sizeof(str), 0, sizeof(str)); | 132 | + return 2; /* 2个返回值 */ |
| 111 | - break; | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - /* 限定输入长度,超过长度作提示 */ | ||
| 115 | - if (i >= MAX_LINE_STR_SIZE) { | ||
| 116 | - printf("[Error] The input length is too long"); | ||
| 117 | - status = -1; | ||
| 118 | - (void)memset_s(str, sizeof(str), 0, sizeof(str)); | ||
| 119 | - break; | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - str[i++] = (char)c; | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - printf("\n"); | ||
| 126 | - lua_pushinteger(L, status); | ||
| 127 | - lua_pushstring(L, str); | ||
| 128 | - return 2; /* 2个返回值 */ | ||
| 129 | } | 133 | } |
| 130 | 134 | ||
| 131 | -static int l_redirect_stdout_to_file(lua_State *L) { | 135 | +static int l_redirect_stdout_to_file(lua_State* L) |
| 132 | - const char *file = luaL_checkstring(L, 1); | 136 | +{ |
| 133 | - if (file == NULL || check_realpath_before_open_s(file, NULL) != RET_OK) { | 137 | + const char* file = luaL_checkstring(L, 1); |
| 134 | - lua_pushinteger(L, -1); | 138 | + if (file == NULL || check_realpath_before_open_s(file, NULL) != RET_OK) { |
| 135 | - return 1; | 139 | + lua_pushinteger(L, -1); |
| 136 | - } | 140 | + return 1; |
| 141 | + } | ||
| 137 | 142 | ||
| 138 | - int fd = dup(1); | 143 | + int fd = dup(1); |
| 139 | - FILE *fp = freopen(file, "w", stdout); | 144 | + FILE* fp = freopen(file, "w", stdout); |
| 140 | - if (fp == NULL) { | 145 | + if (fp == NULL) { |
| 141 | - lua_pushinteger(L, -1); | 146 | + lua_pushinteger(L, -1); |
| 142 | - return 1; | 147 | + return 1; |
| 143 | - } | 148 | + } |
| 144 | - (void)fflush(fp); | 149 | + (void)fflush(fp); |
| 145 | 150 | ||
| 146 | - lua_pushinteger(L, fd); | 151 | + lua_pushinteger(L, fd); |
| 147 | - return 1; | 152 | + return 1; |
| 148 | } | 153 | } |
| 149 | 154 | ||
| 150 | -static int l_stop_redirect(lua_State *L) { | 155 | +static int l_stop_redirect(lua_State* L) |
| 151 | - int fd = luaL_checkinteger(L, 1); | 156 | +{ |
| 152 | - dup2(fd, 1); | 157 | + int fd = luaL_checkinteger(L, 1); |
| 158 | + dup2(fd, 1); | ||
| 153 | 159 | ||
| 154 | - lua_pushinteger(L, 0); | 160 | + lua_pushinteger(L, 0); |
| 155 | - return 0; | 161 | + return 0; |
| 156 | } | 162 | } |
| 157 | 163 | ||
| 158 | // 获取目录下的文件 | 164 | // 获取目录下的文件 |
| 159 | -static int l_get_dir_files(lua_State *L) { | 165 | +static int l_get_dir_files(lua_State* L) |
| 160 | - const char *path = luaL_checkstring(L, 1); // 获取传入的目录路径 | 166 | +{ |
| 167 | + const char* path = luaL_checkstring(L, 1); // 获取传入的目录路径 | ||
| 161 | 168 | ||
| 162 | - DIR *dir = opendir(path); // 打开目录 | 169 | + DIR* dir = opendir(path); // 打开目录 |
| 163 | - if (!dir) { | 170 | + if (!dir) { |
| 164 | - return luaL_error(L, "Failed to open directory: %s", path); | 171 | + return luaL_error(L, "Failed to open directory: %s", path); |
| 165 | - } | ||
| 166 | - | ||
| 167 | - lua_newtable(L); // 创建一个新的 Lua 表格,用于存储文件名 | ||
| 168 | - | ||
| 169 | - struct dirent *entry; | ||
| 170 | - while ((entry = readdir(dir)) != NULL) { // 读取目录中的每个文件 | ||
| 171 | - if (entry->d_type == DT_REG) { // 如果是普通文件 | ||
| 172 | - lua_pushstring(L, entry->d_name); // 将文件名压入 Lua 栈 | ||
| 173 | - lua_rawseti(L, -2, luaL_len(L, -2) + 1); // 将文件名存入 Lua 表格 | ||
| 174 | } | 172 | } |
| 175 | - } | ||
| 176 | 173 | ||
| 177 | - closedir(dir); // 关闭目录 | 174 | + lua_newtable(L); // 创建一个新的 Lua 表格,用于存储文件名 |
| 178 | 175 | ||
| 179 | - return 1; // 返回 Lua 表格 | 176 | + struct dirent* entry; |
| 177 | + while ((entry = readdir(dir)) != NULL) { // 读取目录中的每个文件 | ||
| 178 | + if (entry->d_type == DT_REG) { // 如果是普通文件 | ||
| 179 | + lua_pushstring(L, entry->d_name); // 将文件名压入 Lua 栈 | ||
| 180 | + lua_rawseti(L, -2, luaL_len(L, -2) + 1); // 将文件名存入 Lua 表格 | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + closedir(dir); // 关闭目录 | ||
| 185 | + | ||
| 186 | + return 1; // 返回 Lua 表格 | ||
| 180 | } | 187 | } |
| 181 | 188 | ||
| 182 | -#define BUILD_TYPE_DT (0x0a) | 189 | +#define BUILD_TYPE_DT (0x0a) |
| 183 | -#define BUILD_TYPE_DEBUG (0x0b) | 190 | +#define BUILD_TYPE_DEBUG (0x0b) |
| 184 | #define BUILD_TYPE_RELEASE (0x0c) | 191 | #define BUILD_TYPE_RELEASE (0x0c) |
| 185 | 192 | ||
| 186 | -static int l_build_type_is_release(lua_State *L) { | 193 | +static int l_build_type_is_release(lua_State* L) |
| 187 | -#if defined(BUILD_TYPE) && defined(BUILD_TYPE_RELEASE) && \ | 194 | +{ |
| 188 | - BUILD_TYPE == BUILD_TYPE_RELEASE | 195 | +#if defined(BUILD_TYPE) && defined(BUILD_TYPE_RELEASE) && BUILD_TYPE == BUILD_TYPE_RELEASE |
| 189 | - lua_pushboolean(L, 1); | 196 | + lua_pushboolean(L, 1); |
| 190 | #else | 197 | #else |
| 191 | - lua_pushboolean(L, 0); | 198 | + lua_pushboolean(L, 0); |
| 192 | #endif | 199 | #endif |
| 193 | - return 1; | 200 | + return 1; |
| 194 | } | 201 | } |
| 195 | 202 | ||
| 196 | -LUAMOD_API int luaopen_cli_utils(lua_State *L) { | 203 | +LUAMOD_API int luaopen_cli_utils(lua_State* L) |
| 197 | - luaL_checkversion(L); | 204 | +{ |
| 198 | - luaL_Reg l[] = {{"redirect_start_print", l_redirect_start_print}, | 205 | + luaL_checkversion(L); |
| 199 | - {"delay", l_delay}, | 206 | + luaL_Reg l[] = {{"redirect_start_print", l_redirect_start_print}, |
| 200 | - {"get_line_without_echo", l_get_line_without_echo}, | 207 | + {"delay", l_delay}, |
| 201 | - {"redirect_stdout_to_file", l_redirect_stdout_to_file}, | 208 | + {"get_line_without_echo", l_get_line_without_echo}, |
| 202 | - {"stop_redirect", l_stop_redirect}, | 209 | + {"redirect_stdout_to_file", l_redirect_stdout_to_file}, |
| 203 | - {"get_dir_files", l_get_dir_files}, | 210 | + {"stop_redirect", l_stop_redirect}, |
| 204 | - {"build_type_is_release", l_build_type_is_release}, | 211 | + {"get_dir_files", l_get_dir_files}, |
| 205 | - {NULL, NULL}}; | 212 | + {"build_type_is_release", l_build_type_is_release}, |
| 213 | + {NULL, NULL}}; | ||
| 206 | 214 | ||
| 207 | - luaL_newlib(L, l); | 215 | + luaL_newlib(L, l); |
| 208 | - return 1; | 216 | + return 1; |
| 209 | } | 217 | } |
| @@ -10,190 +10,201 @@ | |||
| 10 | * Mulan PSL v2 for more details. | 10 | * Mulan PSL v2 for more details. |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | -#include <arpa/inet.h> | ||
| 14 | -#include <lauxlib.h> | ||
| 15 | -#include <lua.h> | ||
| 16 | -#include <netinet/in.h> | ||
| 17 | -#include <secure/securec.h> | ||
| 18 | #include <string.h> | 13 | #include <string.h> |
| 19 | #include <termio.h> | 14 | #include <termio.h> |
| 15 | + | ||
| 16 | +#include <arpa/inet.h> | ||
| 17 | +#include <netinet/in.h> | ||
| 20 | #include <unistd.h> | 18 | #include <unistd.h> |
| 21 | 19 | ||
| 20 | +#include <lauxlib.h> | ||
| 21 | +#include <lua.h> | ||
| 22 | + | ||
| 23 | +#include <secure/securec.h> | ||
| 24 | + | ||
| 22 | #define LUA_LIB | 25 | #define LUA_LIB |
| 23 | 26 | ||
| 24 | #define SOL_MODULE_TCP_PORT 8210 | 27 | #define SOL_MODULE_TCP_PORT 8210 |
| 25 | 28 | ||
| 26 | static int32_t sockfd = -1; | 29 | static int32_t sockfd = -1; |
| 27 | 30 | ||
| 28 | -static int l_connect_socket(lua_State *L) { | 31 | +static int l_connect_socket(lua_State* L) |
| 29 | - if (sockfd != -1) { | 32 | +{ |
| 30 | - (void)close(sockfd); | 33 | + if (sockfd != -1) { |
| 31 | - sockfd = -1; | 34 | + (void)close(sockfd); |
| 32 | - } | 35 | + sockfd = -1; |
| 36 | + } | ||
| 33 | 37 | ||
| 34 | - struct sockaddr_in servaddr; | 38 | + struct sockaddr_in servaddr; |
| 35 | - (void)memset_s(&servaddr, sizeof(servaddr), 0, sizeof(servaddr)); | 39 | + (void)memset_s(&servaddr, sizeof(servaddr), 0, sizeof(servaddr)); |
| 36 | - servaddr.sin_family = AF_INET; | 40 | + servaddr.sin_family = AF_INET; |
| 37 | - (void)inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr); | 41 | + (void)inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr); |
| 38 | - servaddr.sin_port = htons(SOL_MODULE_TCP_PORT); | 42 | + servaddr.sin_port = htons(SOL_MODULE_TCP_PORT); |
| 39 | 43 | ||
| 40 | - int ret = 0; | 44 | + int ret = 0; |
| 41 | - sockfd = socket(AF_INET, SOCK_STREAM, 0); | 45 | + sockfd = socket(AF_INET, SOCK_STREAM, 0); |
| 42 | - if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { | 46 | + if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1) { |
| 43 | - ret = -1; | 47 | + ret = -1; |
| 44 | - } | 48 | + } |
| 45 | 49 | ||
| 46 | - lua_pushinteger(L, ret); | 50 | + lua_pushinteger(L, ret); |
| 47 | - return 1; | 51 | + return 1; |
| 48 | } | 52 | } |
| 49 | 53 | ||
| 50 | #define MAX_CLI_DATA_LEN 200 | 54 | #define MAX_CLI_DATA_LEN 200 |
| 51 | #define MAX_SOL_DATA_LEN 1024 | 55 | #define MAX_SOL_DATA_LEN 1024 |
| 52 | 56 | ||
| 53 | -static int l_recv_data(lua_State *L) { | 57 | +static int l_recv_data(lua_State* L) |
| 54 | - ssize_t ret = 0; | 58 | +{ |
| 55 | - int source = 0; | 59 | + ssize_t ret = 0; |
| 56 | - uint8_t buffer[MAX_SOL_DATA_LEN] = {0}; | 60 | + int source = 0; |
| 57 | - if (sockfd == -1) { | 61 | + uint8_t buffer[MAX_SOL_DATA_LEN] = {0}; |
| 58 | - ret = -1; | 62 | + if (sockfd == -1) { |
| 63 | + ret = -1; | ||
| 59 | 64 | ||
| 60 | - goto RETURN1; | 65 | + goto RETURN1; |
| 61 | - } | 66 | + } |
| 62 | 67 | ||
| 63 | - fd_set read_fds; | 68 | + fd_set read_fds; |
| 64 | - FD_ZERO(&read_fds); | 69 | + FD_ZERO(&read_fds); |
| 65 | - FD_SET(0, &read_fds); | 70 | + FD_SET(0, &read_fds); |
| 66 | - FD_SET(sockfd, &read_fds); | 71 | + FD_SET(sockfd, &read_fds); |
| 67 | 72 | ||
| 68 | - struct timeval tv = {1, 0}; | 73 | + struct timeval tv = {1, 0}; |
| 69 | - ret = select(sockfd + 1, &read_fds, NULL, NULL, &tv); | 74 | + ret = select(sockfd + 1, &read_fds, NULL, NULL, &tv); |
| 70 | - if (ret <= 0) { | 75 | + if (ret <= 0) { |
| 71 | - goto RETURN1; | 76 | + goto RETURN1; |
| 72 | - } | 77 | + } |
| 73 | 78 | ||
| 74 | - if (FD_ISSET(0, &read_fds)) { | 79 | + if (FD_ISSET(0, &read_fds)) { |
| 75 | - ret = read(fileno(stdin), buffer, MAX_CLI_DATA_LEN); | 80 | + ret = read(fileno(stdin), buffer, MAX_CLI_DATA_LEN); |
| 76 | - } else if (FD_ISSET(sockfd, &read_fds)) { | 81 | + } else if (FD_ISSET(sockfd, &read_fds)) { |
| 77 | - ret = recv(sockfd, buffer, MAX_SOL_DATA_LEN, 0); | 82 | + ret = recv(sockfd, buffer, MAX_SOL_DATA_LEN, 0); |
| 78 | - source = 1; // 1表示数据来源为服务端 | 83 | + source = 1; // 1表示数据来源为服务端 |
| 79 | - } | 84 | + } |
| 80 | 85 | ||
| 81 | - if (ret <= 0) { | 86 | + if (ret <= 0) { |
| 82 | - ret = -1; | 87 | + ret = -1; |
| 83 | - } | 88 | + } |
| 84 | 89 | ||
| 85 | RETURN1: | 90 | RETURN1: |
| 86 | - lua_pushinteger(L, ret); | 91 | + lua_pushinteger(L, ret); |
| 87 | - lua_pushinteger(L, source); | 92 | + lua_pushinteger(L, source); |
| 88 | - lua_pushlstring(L, (const char *)buffer, (ret >= 0 ? ret : 0)); | 93 | + lua_pushlstring(L, (const char*)buffer, (ret >= 0 ? ret : 0)); |
| 89 | - return 3; // 返回3个参数 | 94 | + return 3; // 返回3个参数 |
| 90 | } | 95 | } |
| 91 | 96 | ||
| 92 | #define MAX_SOL_RETRY 3 | 97 | #define MAX_SOL_RETRY 3 |
| 93 | -static int l_send_msg(lua_State *L) { | 98 | +static int l_send_msg(lua_State* L) |
| 94 | - ssize_t send_len = 0; | 99 | +{ |
| 95 | - if (sockfd < 0) { | 100 | + ssize_t send_len = 0; |
| 96 | - goto RETURN2; | 101 | + if (sockfd < 0) { |
| 97 | - } | ||
| 98 | - | ||
| 99 | - size_t data_len = 0; | ||
| 100 | - const char *msg = luaL_checklstring(L, 1, &data_len); | ||
| 101 | - | ||
| 102 | - int times = 0; | ||
| 103 | - ssize_t ret = 0; | ||
| 104 | - while (!(send_len == (ssize_t)data_len)) { | ||
| 105 | - ret = send(sockfd, msg + send_len, data_len - send_len, 0); | ||
| 106 | - if (ret < ((ssize_t)data_len - send_len)) { | ||
| 107 | - if (times < MAX_SOL_RETRY) { | ||
| 108 | - times++; | ||
| 109 | - continue; | ||
| 110 | - } else { | ||
| 111 | goto RETURN2; | 102 | goto RETURN2; |
| 112 | - } | ||
| 113 | } | 103 | } |
| 114 | - times = 0; | 104 | + |
| 115 | - send_len += ret; | 105 | + size_t data_len = 0; |
| 116 | - } | 106 | + const char* msg = luaL_checklstring(L, 1, &data_len); |
| 107 | + | ||
| 108 | + int times = 0; | ||
| 109 | + ssize_t ret = 0; | ||
| 110 | + while (!(send_len == (ssize_t)data_len)) { | ||
| 111 | + ret = send(sockfd, msg + send_len, data_len - send_len, 0); | ||
| 112 | + if (ret < ((ssize_t)data_len - send_len)) { | ||
| 113 | + if (times < MAX_SOL_RETRY) { | ||
| 114 | + times++; | ||
| 115 | + continue; | ||
| 116 | + } else { | ||
| 117 | + goto RETURN2; | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + times = 0; | ||
| 121 | + send_len += ret; | ||
| 122 | + } | ||
| 117 | 123 | ||
| 118 | RETURN2: | 124 | RETURN2: |
| 119 | - lua_pushinteger(L, send_len); | 125 | + lua_pushinteger(L, send_len); |
| 120 | - return 1; | 126 | + return 1; |
| 121 | } | 127 | } |
| 122 | 128 | ||
| 123 | -static int l_close(lua_State *L) { | 129 | +static int l_close(lua_State* L) |
| 124 | - if (sockfd != -1) { | 130 | +{ |
| 125 | - (void)close(sockfd); | 131 | + if (sockfd != -1) { |
| 126 | - sockfd = -1; | 132 | + (void)close(sockfd); |
| 127 | - } | 133 | + sockfd = -1; |
| 134 | + } | ||
| 128 | 135 | ||
| 129 | - return 0; | 136 | + return 0; |
| 130 | } | 137 | } |
| 131 | 138 | ||
| 132 | static struct termios _saved_tio; | 139 | static struct termios _saved_tio; |
| 133 | -static int _in_raw_mode = 0; | 140 | +static int _in_raw_mode = 0; |
| 141 | + | ||
| 142 | +static int l_leave_raw_mode(lua_State* L) | ||
| 143 | +{ | ||
| 144 | + if (_in_raw_mode == 0) { | ||
| 145 | + return 0; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) != -1) { | ||
| 149 | + _in_raw_mode = 0; | ||
| 150 | + } | ||
| 134 | 151 | ||
| 135 | -static int l_leave_raw_mode(lua_State *L) { | ||
| 136 | - if (_in_raw_mode == 0) { | ||
| 137 | return 0; | 152 | return 0; |
| 138 | - } | ||
| 139 | - | ||
| 140 | - if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) != -1) { | ||
| 141 | - _in_raw_mode = 0; | ||
| 142 | - } | ||
| 143 | - | ||
| 144 | - return 0; | ||
| 145 | } | 153 | } |
| 146 | 154 | ||
| 147 | -static int l_enter_raw_mode(lua_State *L) { | 155 | +static int l_enter_raw_mode(lua_State* L) |
| 148 | - struct termios tio; | 156 | +{ |
| 157 | + struct termios tio; | ||
| 158 | + | ||
| 159 | + if (tcgetattr(fileno(stdin), &tio) == -1) { | ||
| 160 | + return 0; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + _saved_tio = tio; | ||
| 164 | + tio.c_iflag |= IGNPAR; | ||
| 165 | + tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF); | ||
| 166 | + tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL); | ||
| 167 | + tio.c_lflag &= ~IEXTEN; | ||
| 168 | + tio.c_oflag &= ~OPOST; | ||
| 169 | + tio.c_cc[VMIN] = 1; | ||
| 170 | + tio.c_cc[VTIME] = 0; | ||
| 171 | + | ||
| 172 | + if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) != -1) { | ||
| 173 | + _in_raw_mode = 1; | ||
| 174 | + } | ||
| 149 | 175 | ||
| 150 | - if (tcgetattr(fileno(stdin), &tio) == -1) { | ||
| 151 | return 0; | 176 | return 0; |
| 152 | - } | ||
| 153 | - | ||
| 154 | - _saved_tio = tio; | ||
| 155 | - tio.c_iflag |= IGNPAR; | ||
| 156 | - tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF); | ||
| 157 | - tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL); | ||
| 158 | - tio.c_lflag &= ~IEXTEN; | ||
| 159 | - tio.c_oflag &= ~OPOST; | ||
| 160 | - tio.c_cc[VMIN] = 1; | ||
| 161 | - tio.c_cc[VTIME] = 0; | ||
| 162 | - | ||
| 163 | - if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) != -1) { | ||
| 164 | - _in_raw_mode = 1; | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - return 0; | ||
| 168 | } | 177 | } |
| 169 | 178 | ||
| 170 | -static int l_output(lua_State *L) { | 179 | +static int l_output(lua_State* L) |
| 171 | - size_t data_len = 0; | 180 | +{ |
| 172 | - const char *rsp = luaL_checklstring(L, 1, &data_len); | 181 | + size_t data_len = 0; |
| 173 | - if (!rsp) { | 182 | + const char* rsp = luaL_checklstring(L, 1, &data_len); |
| 183 | + if (!rsp) { | ||
| 184 | + return 0; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + size_t i = 0; | ||
| 188 | + for (i = 0; i < data_len; ++i) { | ||
| 189 | + (void)putc(rsp[i], stdout); | ||
| 190 | + } | ||
| 191 | + (void)fflush(stdout); | ||
| 192 | + | ||
| 174 | return 0; | 193 | return 0; |
| 175 | - } | ||
| 176 | - | ||
| 177 | - size_t i = 0; | ||
| 178 | - for (i = 0; i < data_len; ++i) { | ||
| 179 | - (void)putc(rsp[i], stdout); | ||
| 180 | - } | ||
| 181 | - (void)fflush(stdout); | ||
| 182 | - | ||
| 183 | - return 0; | ||
| 184 | } | 194 | } |
| 185 | 195 | ||
| 186 | -LUAMOD_API int luaopen_cli_sol(lua_State *L) { | 196 | +LUAMOD_API int luaopen_cli_sol(lua_State* L) |
| 187 | - luaL_checkversion(L); | 197 | +{ |
| 188 | - luaL_Reg l[] = {{"connect_socket", l_connect_socket}, | 198 | + luaL_checkversion(L); |
| 189 | - {"recv_data", l_recv_data}, | 199 | + luaL_Reg l[] = {{"connect_socket", l_connect_socket}, |
| 190 | - {"send_msg", l_send_msg}, | 200 | + {"recv_data", l_recv_data}, |
| 191 | - {"close", l_close}, | 201 | + {"send_msg", l_send_msg}, |
| 192 | - {"leave_raw_mode", l_leave_raw_mode}, | 202 | + {"close", l_close}, |
| 193 | - {"enter_raw_mode", l_enter_raw_mode}, | 203 | + {"leave_raw_mode", l_leave_raw_mode}, |
| 194 | - {"output", l_output}, | 204 | + {"enter_raw_mode", l_enter_raw_mode}, |
| 195 | - {NULL, NULL}}; | 205 | + {"output", l_output}, |
| 206 | + {NULL, NULL}}; | ||
| 196 | 207 | ||
| 197 | - luaL_newlib(L, l); | 208 | + luaL_newlib(L, l); |
| 198 | - return 1; | 209 | + return 1; |
| 199 | } | 210 | } |
| @@ -14,60 +14,63 @@ | |||
| 14 | #include <lauxlib.h> | 14 | #include <lauxlib.h> |
| 15 | #include <lua.h> | 15 | #include <lua.h> |
| 16 | 16 | ||
| 17 | -#define MAX_LEN 512 | 17 | +#define MAX_LEN 512 |
| 18 | #define LUA_RET_ERR 1 | 18 | #define LUA_RET_ERR 1 |
| 19 | -#define LUA_RET_OK 0 | 19 | +#define LUA_RET_OK 0 |
| 20 | 20 | ||
| 21 | -void dal_clear_sensitive_info(gchar *buf, guint32 len); | 21 | +void dal_clear_sensitive_info(gchar* buf, guint32 len); |
| 22 | -gchar *safe_getstr(gsize max_len); | 22 | +gchar* safe_getstr(gsize max_len); |
| 23 | 23 | ||
| 24 | -static int l_test_safe_getstr(lua_State *L) { | 24 | +static int l_test_safe_getstr(lua_State* L) |
| 25 | - // 1. 检查第一个参数是否为数字 | 25 | +{ |
| 26 | - luaL_checktype(L, 1, LUA_TNUMBER); | 26 | + // 1. 检查第一个参数是否为数字 |
| 27 | + luaL_checktype(L, 1, LUA_TNUMBER); | ||
| 28 | + | ||
| 29 | + // 2. 获取最大长度 | ||
| 30 | + gsize max_len = luaL_checkinteger(L, 1); | ||
| 31 | + if (max_len > MAX_LEN) { | ||
| 32 | + lua_pushinteger(L, LUA_RET_ERR); | ||
| 33 | + return 1; | ||
| 34 | + } | ||
| 35 | + int str = ungetc('\n', stdin); | ||
| 36 | + if (str == EOF) { | ||
| 37 | + return 1; | ||
| 38 | + } | ||
| 39 | + // 3. 调用 safe_getstr 函数 | ||
| 40 | + gchar* result = safe_getstr(max_len); | ||
| 41 | + // 4. 检查结果 | ||
| 42 | + if (result == NULL) { | ||
| 43 | + lua_pushinteger(L, LUA_RET_ERR); | ||
| 44 | + return 1; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + // 5. 将结果推入 Lua 栈 | ||
| 48 | + lua_pushstring(L, result); | ||
| 49 | + free(result); // 释放内存 | ||
| 27 | 50 | ||
| 28 | - // 2. 获取最大长度 | ||
| 29 | - gsize max_len = luaL_checkinteger(L, 1); | ||
| 30 | - if (max_len > MAX_LEN) { | ||
| 31 | - lua_pushinteger(L, LUA_RET_ERR); | ||
| 32 | return 1; | 51 | return 1; |
| 33 | - } | ||
| 34 | - int str = ungetc('\n', stdin); | ||
| 35 | - if (str == EOF) { | ||
| 36 | - return 1; | ||
| 37 | - } | ||
| 38 | - // 3. 调用 safe_getstr 函数 | ||
| 39 | - gchar *result = safe_getstr(max_len); | ||
| 40 | - // 4. 检查结果 | ||
| 41 | - if (result == NULL) { | ||
| 42 | - lua_pushinteger(L, LUA_RET_ERR); | ||
| 43 | - return 1; | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - // 5. 将结果推入 Lua 栈 | ||
| 47 | - lua_pushstring(L, result); | ||
| 48 | - free(result); // 释放内存 | ||
| 49 | - | ||
| 50 | - return 1; | ||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | -static int l_test_dal_clear_sensitive_info(lua_State *L) { | 54 | +static int l_test_dal_clear_sensitive_info(lua_State* L) |
| 54 | - const char *buf = lua_tostring(L, 1); | 55 | +{ |
| 56 | + const char* buf = lua_tostring(L, 1); | ||
| 55 | 57 | ||
| 56 | - size_t len = lua_tointeger(L, 2); | 58 | + size_t len = lua_tointeger(L, 2); |
| 57 | 59 | ||
| 58 | - dal_clear_sensitive_info((gchar *)buf, len); | 60 | + dal_clear_sensitive_info((gchar*)buf, len); |
| 59 | 61 | ||
| 60 | - lua_pushboolean(L, 1); | 62 | + lua_pushboolean(L, 1); |
| 61 | - return 1; | 63 | + return 1; |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | -LUAMOD_API int luaopen_clpcomm(lua_State *L) { | 66 | +LUAMOD_API int luaopen_clpcomm(lua_State* L) |
| 65 | - luaL_checkversion(L); | 67 | +{ |
| 66 | - luaL_Reg l[] = { | 68 | + luaL_checkversion(L); |
| 67 | - {"test_safe_getstr", l_test_safe_getstr}, | 69 | + luaL_Reg l[] = { |
| 68 | - {"test_dal_clear_sensitive_info", l_test_dal_clear_sensitive_info}, | 70 | + {"test_safe_getstr", l_test_safe_getstr}, |
| 69 | - {NULL, NULL}, | 71 | + {"test_dal_clear_sensitive_info", l_test_dal_clear_sensitive_info}, |
| 70 | - }; | 72 | + {NULL, NULL}, |
| 71 | - luaL_newlib(L, l); | 73 | + }; |
| 72 | - return 1; | 74 | + luaL_newlib(L, l); |
| 75 | + return 1; | ||
| 73 | } | 76 | } |
| @@ -10,113 +10,140 @@ | |||
| 10 | * Mulan PSL v2 for more details. | 10 | * Mulan PSL v2 for more details. |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | -#include "vector.h" | ||
| 14 | #include <glib-2.0/glib.h> | 13 | #include <glib-2.0/glib.h> |
| 15 | #include <lauxlib.h> | 14 | #include <lauxlib.h> |
| 16 | #include <lua.h> | 15 | #include <lua.h> |
| 17 | 16 | ||
| 17 | +#include "vector.h" | ||
| 18 | + | ||
| 18 | #define RET_ERR (-1) | 19 | #define RET_ERR (-1) |
| 19 | 20 | ||
| 20 | -gint32 get_passwd_parameter(const gchar *username) { return RET_ERR; } | 21 | +gint32 get_passwd_parameter(const gchar* username) |
| 21 | -void help_info_general(void) {} | 22 | +{ |
| 22 | -gint32 check_cmd_need_special_processing(gchar *cmd_history, gchar **ppvalue) { | 23 | + return RET_ERR; |
| 23 | - return RET_ERR; | ||
| 24 | } | 24 | } |
| 25 | -void get_user_id_and_initial_flag(const gchar *username, guint8 *user_id, | 25 | +void help_info_general(void) |
| 26 | - gboolean *initial_flag) {} | 26 | +{} |
| 27 | -gint32 vos_get_file_accessible(const gchar *filename) { return RET_ERR; } | 27 | +gint32 check_cmd_need_special_processing(gchar* cmd_history, gchar** ppvalue) |
| 28 | -gint32 vector_add(vector_t *vector, const void *object) { return RET_ERR; } | 28 | +{ |
| 29 | -gint32 clp_auth_user(guint8 user_id, const gchar *user_name, | 29 | + return RET_ERR; |
| 30 | - const gchar *passwd) { | ||
| 31 | - return RET_ERR; | ||
| 32 | } | 30 | } |
| 33 | -gint32 get_passwd_administrators_number(const gchar *username) { | 31 | +void get_user_id_and_initial_flag(const gchar* username, guint8* user_id, gboolean* initial_flag) |
| 34 | - return RET_ERR; | 32 | +{} |
| 33 | +gint32 vos_get_file_accessible(const gchar* filename) | ||
| 34 | +{ | ||
| 35 | + return RET_ERR; | ||
| 35 | } | 36 | } |
| 36 | -gint32 clp_get_username_ip(gchar *username, guint32 name_size, gchar *ip, | 37 | +gint32 vector_add(vector_t* vector, const void* object) |
| 37 | - guint32 ip_size) { | 38 | +{ |
| 38 | - return RET_ERR; | 39 | + return RET_ERR; |
| 39 | } | 40 | } |
| 40 | -gulong vector_size(vector_t *new_vector) { return 0; } | 41 | +gint32 clp_auth_user(guint8 user_id, const gchar* user_name, const gchar* passwd) |
| 41 | -gint32 clp_set_user_password(guint8 user_id, const gchar *user_name, | 42 | +{ |
| 42 | - const gchar *passwd) { | 43 | + return RET_ERR; |
| 43 | - return RET_ERR; | ||
| 44 | } | 44 | } |
| 45 | -gchar *safe_getstr(gsize max_len) { return NULL; } | 45 | +gint32 get_passwd_administrators_number(const gchar* username) |
| 46 | -gint32 reset_password(guint8 user_id, const gchar *user_name, | 46 | +{ |
| 47 | - const gchar *new_user_name, const gchar *ip_addr, | 47 | + return RET_ERR; |
| 48 | +} | ||
| 49 | +gint32 clp_get_username_ip(gchar* username, guint32 name_size, gchar* ip, guint32 ip_size) | ||
| 50 | +{ | ||
| 51 | + return RET_ERR; | ||
| 52 | +} | ||
| 53 | +gulong vector_size(vector_t* new_vector) | ||
| 54 | +{ | ||
| 55 | + return 0; | ||
| 56 | +} | ||
| 57 | +gint32 clp_set_user_password(guint8 user_id, const gchar* user_name, const gchar* passwd) | ||
| 58 | +{ | ||
| 59 | + return RET_ERR; | ||
| 60 | +} | ||
| 61 | +gchar* safe_getstr(gsize max_len) | ||
| 62 | +{ | ||
| 63 | + return NULL; | ||
| 64 | +} | ||
| 65 | +gint32 reset_password(guint8 user_id, const gchar* user_name, const gchar* new_user_name, const gchar* ip_addr, | ||
| 48 | guint8 new_user_id); | 66 | guint8 new_user_id); |
| 49 | -typedef enum { | 67 | +typedef enum { SMASH_TOK_NORMAL, SMASH_TOK_TOKEN, SMASH_TOK_QUOTED } SMASH_TOK_STATE_T; |
| 50 | - SMASH_TOK_NORMAL, | 68 | +void dal_clear_sensitive_info(gchar* buf, guint32 len); |
| 51 | - SMASH_TOK_TOKEN, | 69 | +void clp_method_operation_log(const gchar* username, const gchar* ipaddr, const gchar* fmt, ...) |
| 52 | - SMASH_TOK_QUOTED | 70 | +{} |
| 53 | -} SMASH_TOK_STATE_T; | 71 | +gint32 clp_call_maca_reboot(gchar* type, gchar* mode) |
| 54 | -void dal_clear_sensitive_info(gchar *buf, guint32 len); | 72 | +{ |
| 55 | -void clp_method_operation_log(const gchar *username, const gchar *ipaddr, | 73 | + return RET_ERR; |
| 56 | - const gchar *fmt, ...) {} | ||
| 57 | -gint32 clp_call_maca_reboot(gchar *type, gchar *mode) { return RET_ERR; } | ||
| 58 | -gint32 clp_set_user_lock(guint8 user_id, const gchar *user_name, | ||
| 59 | - unsigned int value) { | ||
| 60 | - return RET_ERR; | ||
| 61 | } | 74 | } |
| 62 | -gint32 check_the_input_operation(const gchar *prompt) { return RET_ERR; } | 75 | +gint32 clp_set_user_lock(guint8 user_id, const gchar* user_name, unsigned int value) |
| 63 | -gint32 clp_check_passwd_privilege(gchar *username, guint8 user_id) { | 76 | +{ |
| 64 | - return RET_ERR; | 77 | + return RET_ERR; |
| 78 | +} | ||
| 79 | +gint32 check_the_input_operation(const gchar* prompt) | ||
| 80 | +{ | ||
| 81 | + return RET_ERR; | ||
| 82 | +} | ||
| 83 | +gint32 clp_check_passwd_privilege(gchar* username, guint8 user_id) | ||
| 84 | +{ | ||
| 85 | + return RET_ERR; | ||
| 86 | +} | ||
| 87 | +void dal_clear_sensitive_info(gchar* buf, guint32 len) | ||
| 88 | +{} | ||
| 89 | +uintptr_t vector_get(vector_t* new_vector, guint32 pos) | ||
| 90 | +{ | ||
| 91 | + return 0; | ||
| 65 | } | 92 | } |
| 66 | -void dal_clear_sensitive_info(gchar *buf, guint32 len) {} | ||
| 67 | -uintptr_t vector_get(vector_t *new_vector, guint32 pos) { return 0; } | ||
| 68 | typedef struct { | 93 | typedef struct { |
| 69 | - /* 命令行提示 */ | 94 | + /* 命令行提示 */ |
| 70 | - gchar *prompt; | 95 | + gchar* prompt; |
| 71 | - gint32 level; // 当前目录等级 | 96 | + gint32 level; // 当前目录等级 |
| 72 | - /* 包含字符的容器 */ | 97 | + /* 包含字符的容器 */ |
| 73 | - gint32 tokens; // 数据类型: gchar * | 98 | + gint32 tokens; // 数据类型: gchar * |
| 74 | - /* 是否存在多行输入 */ | 99 | + /* 是否存在多行输入 */ |
| 75 | - gint32 cont; | 100 | + gint32 cont; |
| 76 | - /* 用来存储字符 */ | 101 | + /* 用来存储字符 */ |
| 77 | - /* BEGIN: Added for PN:DTS2015030602719 by l00205093, 2015/3/13 */ | 102 | + /* BEGIN: Added for PN:DTS2015030602719 by l00205093, 2015/3/13 */ |
| 78 | - gchar token[1694]; | 103 | + gchar token[1694]; |
| 79 | - /* END: Added by l00205093, 2015/3/13 */ | 104 | + /* END: Added by l00205093, 2015/3/13 */ |
| 80 | - gint32 tpos; | 105 | + gint32 tpos; |
| 81 | - /* 但前字符属于哪一类型 */ | 106 | + /* 但前字符属于哪一类型 */ |
| 82 | - SMASH_TOK_STATE_T tok_state; | 107 | + SMASH_TOK_STATE_T tok_state; |
| 83 | } SMASH_SESSION_T; | 108 | } SMASH_SESSION_T; |
| 84 | typedef struct { | 109 | typedef struct { |
| 85 | - gchar *verb; | 110 | + gchar* verb; |
| 86 | } SMASH_CMD_T; | 111 | } SMASH_CMD_T; |
| 87 | -gint32 clp_verb_handler_passwd(SMASH_SESSION_T *session, SMASH_CMD_T *cmd); | 112 | +gint32 clp_verb_handler_passwd(SMASH_SESSION_T* session, SMASH_CMD_T* cmd); |
| 88 | -static int l_test_reset_password(lua_State *L) { | 113 | +static int l_test_reset_password(lua_State* L) |
| 89 | - guint8 user_id = (guint8)lua_tointeger(L, 1); | 114 | +{ |
| 90 | - const gchar *user_name = lua_tostring(L, 2); | 115 | + guint8 user_id = (guint8)lua_tointeger(L, 1); |
| 91 | - const gchar *new_user_name = lua_tostring(L, 3); | 116 | + const gchar* user_name = lua_tostring(L, 2); |
| 92 | - const gchar *ip_addr = lua_tostring(L, 4); | 117 | + const gchar* new_user_name = lua_tostring(L, 3); |
| 93 | - guint8 new_user_id = (guint8)lua_tointeger(L, 5); | 118 | + const gchar* ip_addr = lua_tostring(L, 4); |
| 94 | - int str = ungetc('\n', stdin); | 119 | + guint8 new_user_id = (guint8)lua_tointeger(L, 5); |
| 95 | - if (str == EOF) { | 120 | + int str = ungetc('\n', stdin); |
| 121 | + if (str == EOF) { | ||
| 122 | + return 1; | ||
| 123 | + } | ||
| 124 | + gint32 ret = reset_password(user_id, user_name, new_user_name, ip_addr, new_user_id); | ||
| 125 | + | ||
| 126 | + lua_pushinteger(L, ret); | ||
| 96 | return 1; | 127 | return 1; |
| 97 | - } | ||
| 98 | - gint32 ret = | ||
| 99 | - reset_password(user_id, user_name, new_user_name, ip_addr, new_user_id); | ||
| 100 | - | ||
| 101 | - lua_pushinteger(L, ret); | ||
| 102 | - return 1; | ||
| 103 | } | 128 | } |
| 104 | 129 | ||
| 105 | -static int l_test_clp_verb_handler_passwd(lua_State *L) { | 130 | +static int l_test_clp_verb_handler_passwd(lua_State* L) |
| 106 | - SMASH_SESSION_T *session = (SMASH_SESSION_T *)lua_touserdata(L, 1); | 131 | +{ |
| 107 | - SMASH_CMD_T *cmd = (SMASH_CMD_T *)lua_touserdata(L, 2); | 132 | + SMASH_SESSION_T* session = (SMASH_SESSION_T*)lua_touserdata(L, 1); |
| 108 | - gint32 ret = clp_verb_handler_passwd(session, cmd); | 133 | + SMASH_CMD_T* cmd = (SMASH_CMD_T*)lua_touserdata(L, 2); |
| 109 | - lua_pushinteger(L, ret); | 134 | + gint32 ret = clp_verb_handler_passwd(session, cmd); |
| 110 | - return 1; | 135 | + lua_pushinteger(L, ret); |
| 136 | + return 1; | ||
| 111 | } | 137 | } |
| 112 | 138 | ||
| 113 | -LUAMOD_API int luaopen_clpprivatecmd(lua_State *L) { | 139 | +LUAMOD_API int luaopen_clpprivatecmd(lua_State* L) |
| 114 | - luaL_checkversion(L); | 140 | +{ |
| 115 | - luaL_Reg l[] = { | 141 | + luaL_checkversion(L); |
| 116 | - {"test_reset_password", l_test_reset_password}, | 142 | + luaL_Reg l[] = { |
| 117 | - {"test_clp_verb_handler_passwd", l_test_clp_verb_handler_passwd}, | 143 | + {"test_reset_password", l_test_reset_password}, |
| 118 | - {NULL, NULL}, | 144 | + {"test_clp_verb_handler_passwd", l_test_clp_verb_handler_passwd}, |
| 119 | - }; | 145 | + {NULL, NULL}, |
| 120 | - luaL_newlib(L, l); | 146 | + }; |
| 121 | - return 1; | 147 | + luaL_newlib(L, l); |
| 148 | + return 1; | ||
| 122 | } | 149 | } |
| @@ -14,81 +14,86 @@ | |||
| 14 | #include <lauxlib.h> | 14 | #include <lauxlib.h> |
| 15 | #include <lua.h> | 15 | #include <lua.h> |
| 16 | 16 | ||
| 17 | -#define MAX_LEN 512 | 17 | +#define MAX_LEN 512 |
| 18 | #define LUA_RET_ERR 1 | 18 | #define LUA_RET_ERR 1 |
| 19 | -#define LUA_RET_OK 0 | 19 | +#define LUA_RET_OK 0 |
| 20 | + | ||
| 21 | +gint32 clp_check_passwd_privilege(gchar* username, guint8 user_id); | ||
| 22 | +gint32 get_passwd_parameter(const gchar* username); | ||
| 23 | +guint8 get_passwd_userid(const char* reply_array_str); | ||
| 24 | +gint32 clp_set_user_lock(guint8 user_id, const gchar* user_name, unsigned int value); | ||
| 25 | +guint8 dal_str_mul_repeat_div(const gchar* str, guint8 len); | ||
| 26 | +static int l_test_dal_str_mul_repeat_div(lua_State* L) | ||
| 27 | +{ | ||
| 28 | + const gchar* str = luaL_checkstring(L, 1); | ||
| 29 | + guint8 len = luaL_checkinteger(L, 2); | ||
| 30 | + if (len == 0) { | ||
| 31 | + lua_pushinteger(L, LUA_RET_ERR); | ||
| 32 | + return 1; | ||
| 33 | + } | ||
| 34 | + guint8 result = dal_str_mul_repeat_div(str, len); | ||
| 35 | + lua_pushinteger(L, result); | ||
| 20 | 36 | ||
| 21 | -gint32 clp_check_passwd_privilege(gchar *username, guint8 user_id); | ||
| 22 | -gint32 get_passwd_parameter(const gchar *username); | ||
| 23 | -guint8 get_passwd_userid(const char *reply_array_str); | ||
| 24 | -gint32 clp_set_user_lock(guint8 user_id, const gchar *user_name, | ||
| 25 | - unsigned int value); | ||
| 26 | -guint8 dal_str_mul_repeat_div(const gchar *str, guint8 len); | ||
| 27 | -static int l_test_dal_str_mul_repeat_div(lua_State *L) { | ||
| 28 | - const gchar *str = luaL_checkstring(L, 1); | ||
| 29 | - guint8 len = luaL_checkinteger(L, 2); | ||
| 30 | - if (len == 0) { | ||
| 31 | - lua_pushinteger(L, LUA_RET_ERR); | ||
| 32 | return 1; | 37 | return 1; |
| 33 | - } | ||
| 34 | - guint8 result = dal_str_mul_repeat_div(str, len); | ||
| 35 | - lua_pushinteger(L, result); | ||
| 36 | - | ||
| 37 | - return 1; | ||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | -static int l_test_clp_check_passwd_privilege(lua_State *L) { | 40 | +static int l_test_clp_check_passwd_privilege(lua_State* L) |
| 41 | - if (lua_gettop(L) != 2) { | 41 | +{ |
| 42 | - lua_pushstring(L, "Expected two arguments: username and user_id"); | 42 | + if (lua_gettop(L) != 2) { |
| 43 | + lua_pushstring(L, "Expected two arguments: username and user_id"); | ||
| 44 | + return 1; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + const char* username = luaL_checkstring(L, 1); | ||
| 48 | + | ||
| 49 | + guint8 user_id = luaL_checkinteger(L, 2); | ||
| 50 | + | ||
| 51 | + gint32 result = clp_check_passwd_privilege((gchar*)username, user_id); | ||
| 52 | + | ||
| 53 | + lua_pushinteger(L, result); | ||
| 54 | + | ||
| 43 | return 1; | 55 | return 1; |
| 44 | - } | ||
| 45 | - | ||
| 46 | - const char *username = luaL_checkstring(L, 1); | ||
| 47 | - | ||
| 48 | - guint8 user_id = luaL_checkinteger(L, 2); | ||
| 49 | - | ||
| 50 | - gint32 result = clp_check_passwd_privilege((gchar *)username, user_id); | ||
| 51 | - | ||
| 52 | - lua_pushinteger(L, result); | ||
| 53 | - | ||
| 54 | - return 1; | ||
| 55 | } | 56 | } |
| 56 | -static int l_test_get_passwd_parameter(lua_State *L) { | 57 | +static int l_test_get_passwd_parameter(lua_State* L) |
| 57 | - const gchar *username = luaL_checkstring(L, 1); | 58 | +{ |
| 58 | - gint32 result = get_passwd_parameter(username); | 59 | + const gchar* username = luaL_checkstring(L, 1); |
| 60 | + gint32 result = get_passwd_parameter(username); | ||
| 59 | 61 | ||
| 60 | - lua_pushinteger(L, result); | 62 | + lua_pushinteger(L, result); |
| 61 | - return 1; | 63 | + return 1; |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | -static int l_test_get_passwd_userid(lua_State *L) { | 66 | +static int l_test_get_passwd_userid(lua_State* L) |
| 65 | - const char *reply_array_str = luaL_checkstring(L, 1); | 67 | +{ |
| 66 | - guint8 userid = get_passwd_userid(reply_array_str); | 68 | + const char* reply_array_str = luaL_checkstring(L, 1); |
| 69 | + guint8 userid = get_passwd_userid(reply_array_str); | ||
| 67 | 70 | ||
| 68 | - lua_pushinteger(L, userid); | 71 | + lua_pushinteger(L, userid); |
| 69 | - return 1; | 72 | + return 1; |
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | -static int l_test_clp_set_user_lock(lua_State *L) { | 75 | +static int l_test_clp_set_user_lock(lua_State* L) |
| 73 | - guint8 user_id = luaL_checknumber(L, 1); | 76 | +{ |
| 74 | - const gchar *user_name = luaL_checkstring(L, 2); | 77 | + guint8 user_id = luaL_checknumber(L, 1); |
| 75 | - unsigned int value = lua_toboolean(L, 3); | 78 | + const gchar* user_name = luaL_checkstring(L, 2); |
| 79 | + unsigned int value = lua_toboolean(L, 3); | ||
| 76 | 80 | ||
| 77 | - gint32 sult = clp_set_user_lock(user_id, user_name, value); | 81 | + gint32 sult = clp_set_user_lock(user_id, user_name, value); |
| 78 | 82 | ||
| 79 | - lua_pushinteger(L, sult); | 83 | + lua_pushinteger(L, sult); |
| 80 | - return 1; | 84 | + return 1; |
| 81 | } | 85 | } |
| 82 | -LUAMOD_API int luaopen_clpcommon(lua_State *L) { | 86 | +LUAMOD_API int luaopen_clpcommon(lua_State* L) |
| 83 | - luaL_checkversion(L); | 87 | +{ |
| 84 | - luaL_Reg l[] = { | 88 | + luaL_checkversion(L); |
| 85 | - {"test_dal_str_mul_repeat_div", l_test_dal_str_mul_repeat_div}, | 89 | + luaL_Reg l[] = { |
| 86 | - {"test_clp_check_passwd_privilege", l_test_clp_check_passwd_privilege}, | 90 | + {"test_dal_str_mul_repeat_div", l_test_dal_str_mul_repeat_div}, |
| 87 | - {"test_get_passwd_parameter", l_test_get_passwd_parameter}, | 91 | + {"test_clp_check_passwd_privilege", l_test_clp_check_passwd_privilege}, |
| 88 | - {"test_get_passwd_userid", l_test_get_passwd_userid}, | 92 | + {"test_get_passwd_parameter", l_test_get_passwd_parameter}, |
| 89 | - {"test_clp_set_user_lock", l_test_clp_set_user_lock}, | 93 | + {"test_get_passwd_userid", l_test_get_passwd_userid}, |
| 90 | - {NULL, NULL}, | 94 | + {"test_clp_set_user_lock", l_test_clp_set_user_lock}, |
| 91 | - }; | 95 | + {NULL, NULL}, |
| 92 | - luaL_newlib(L, l); | 96 | + }; |
| 93 | - return 1; | 97 | + luaL_newlib(L, l); |
| 98 | + return 1; | ||
| 94 | } | 99 | } |
| @@ -11,92 +11,112 @@ | |||
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include "mock_dbus.h" | 13 | #include "mock_dbus.h" |
| 14 | + | ||
| 14 | #include <stdio.h> | 15 | #include <stdio.h> |
| 15 | 16 | ||
| 16 | -void dbus_init(void) {} | 17 | +void dbus_init(void) |
| 18 | +{} | ||
| 17 | 19 | ||
| 18 | -void dbus_error_init(DBusError *error) {} | 20 | +void dbus_error_init(DBusError* error) |
| 21 | +{} | ||
| 19 | 22 | ||
| 20 | -DBusConnection *dbus_bus_get(DBusBusType type, DBusError *error) { | 23 | +DBusConnection* dbus_bus_get(DBusBusType type, DBusError* error) |
| 21 | - DBusConnection *connection = NULL; | 24 | +{ |
| 22 | - return connection; | 25 | + DBusConnection* connection = NULL; |
| 26 | + return connection; | ||
| 23 | } | 27 | } |
| 24 | 28 | ||
| 25 | -DBusMessage *dbus_message_new_method_call(const char *bus_name, | 29 | +DBusMessage* dbus_message_new_method_call(const char* bus_name, const char* object_path, const char* interface_name, |
| 26 | - const char *object_path, | 30 | + const char* method_name) |
| 27 | - const char *interface_name, | 31 | +{ |
| 28 | - const char *method_name) { | 32 | + DBusMessage* message = NULL; |
| 29 | - DBusMessage *message = NULL; | 33 | + return message; |
| 30 | - return message; | ||
| 31 | } | 34 | } |
| 32 | 35 | ||
| 33 | -void dbus_message_iter_recurse(DBusMessageIter *iter, DBusMessageIter *sub) {} | 36 | +void dbus_message_iter_recurse(DBusMessageIter* iter, DBusMessageIter* sub) |
| 37 | +{} | ||
| 34 | 38 | ||
| 35 | -unsigned int dbus_message_append_args(DBusMessage *message, | 39 | +unsigned int dbus_message_append_args(DBusMessage* message, const char* signature, ...) |
| 36 | - const char *signature, ...) { | 40 | +{ |
| 37 | - return 0; | 41 | + return 0; |
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | -int dbus_message_iter_get_arg_type(const DBusMessageIter *iter) { return 0; } | 44 | +int dbus_message_iter_get_arg_type(const DBusMessageIter* iter) |
| 41 | - | 45 | +{ |
| 42 | -void dbus_message_iter_get_basic(DBusMessageIter *iter, void *value) {} | 46 | + return 0; |
| 43 | - | ||
| 44 | -unsigned int dbus_message_iter_init(DBusMessage *message, | ||
| 45 | - DBusMessageIter *iter) { | ||
| 46 | - return 0; | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -void dbus_message_unref(DBusMessage *message) {} | 49 | +void dbus_message_iter_get_basic(DBusMessageIter* iter, void* value) |
| 50 | +{} | ||
| 50 | 51 | ||
| 51 | -DBusMessage * | 52 | +unsigned int dbus_message_iter_init(DBusMessage* message, DBusMessageIter* iter) |
| 52 | -dbus_connection_send_with_reply_and_block(DBusConnection *connection, | 53 | +{ |
| 53 | - DBusMessage *message, int timeout, | 54 | + return 0; |
| 54 | - DBusError *error) { | ||
| 55 | - DBusMessage *mage = NULL; | ||
| 56 | - return mage; | ||
| 57 | } | 55 | } |
| 58 | 56 | ||
| 59 | -unsigned int dbus_message_iter_open_container(DBusMessageIter *iter, | 57 | +void dbus_message_unref(DBusMessage* message) |
| 60 | - DBusMessageType type, | 58 | +{} |
| 61 | - const char *container_name, | 59 | + |
| 62 | - DBusMessageIter *subiter) { | 60 | +DBusMessage* dbus_connection_send_with_reply_and_block(DBusConnection* connection, DBusMessage* message, int timeout, |
| 63 | - return 0; | 61 | + DBusError* error) |
| 62 | +{ | ||
| 63 | + DBusMessage* mage = NULL; | ||
| 64 | + return mage; | ||
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | -unsigned int dbus_message_iter_close_container(DBusMessageIter *iter, | 67 | +unsigned int dbus_message_iter_open_container(DBusMessageIter* iter, DBusMessageType type, const char* container_name, |
| 67 | - DBusMessageIter *sub) { | 68 | + DBusMessageIter* subiter) |
| 68 | - return 0; | 69 | +{ |
| 70 | + return 0; | ||
| 69 | } | 71 | } |
| 70 | 72 | ||
| 71 | -void dbus_connection_set_exit_on_disconnect(DBusConnection *connection, | 73 | +unsigned int dbus_message_iter_close_container(DBusMessageIter* iter, DBusMessageIter* sub) |
| 72 | - int exit_on_disconnect) {} | 74 | +{ |
| 73 | - | 75 | + return 0; |
| 74 | -DBusConnection *dbus_bus_get_private(DBusBusType bus_type, DBusError *error) { | ||
| 75 | - DBusConnection *connection = NULL; | ||
| 76 | - return connection; | ||
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | -int dbus_message_iter_get_element_count(DBusMessageIter *iter) { return 0; } | 78 | +void dbus_connection_set_exit_on_disconnect(DBusConnection* connection, int exit_on_disconnect) |
| 79 | +{} | ||
| 80 | 80 | ||
| 81 | -unsigned int dbus_message_iter_append_basic(DBusMessageIter *iter, int type, | 81 | +DBusConnection* dbus_bus_get_private(DBusBusType bus_type, DBusError* error) |
| 82 | - const char *value) { | 82 | +{ |
| 83 | - return 0; | 83 | + DBusConnection* connection = NULL; |
| 84 | + return connection; | ||
| 84 | } | 85 | } |
| 85 | 86 | ||
| 86 | -unsigned int dbus_message_get_args(DBusMessage *message, DBusError *error, | 87 | +int dbus_message_iter_get_element_count(DBusMessageIter* iter) |
| 87 | - int first_arg_type, ...) { | 88 | +{ |
| 88 | - return 0; | 89 | + return 0; |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | -void dbus_connection_unref(DBusConnection *connection) {} | 92 | +unsigned int dbus_message_iter_append_basic(DBusMessageIter* iter, int type, const char* value) |
| 93 | +{ | ||
| 94 | + return 0; | ||
| 95 | +} | ||
| 92 | 96 | ||
| 93 | -void dbus_error_free(DBusError *error) {} | 97 | +unsigned int dbus_message_get_args(DBusMessage* message, DBusError* error, int first_arg_type, ...) |
| 98 | +{ | ||
| 99 | + return 0; | ||
| 100 | +} | ||
| 94 | 101 | ||
| 95 | -void dbus_message_iter_init_append(DBusMessage *message, | 102 | +void dbus_connection_unref(DBusConnection* connection) |
| 96 | - DBusMessageIter *iter) {} | 103 | +{} |
| 97 | 104 | ||
| 98 | -void dbus_connection_close(DBusConnection *connection) {} | 105 | +void dbus_error_free(DBusError* error) |
| 106 | +{} | ||
| 99 | 107 | ||
| 100 | -unsigned int dbus_error_is_set(const DBusError *error) { return 0; } | 108 | +void dbus_message_iter_init_append(DBusMessage* message, DBusMessageIter* iter) |
| 109 | +{} | ||
| 101 | 110 | ||
| 102 | -unsigned int dbus_message_iter_next(DBusMessageIter *iter) { return 0; } | 111 | +void dbus_connection_close(DBusConnection* connection) |
| 112 | +{} | ||
| 113 | + | ||
| 114 | +unsigned int dbus_error_is_set(const DBusError* error) | ||
| 115 | +{ | ||
| 116 | + return 0; | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +unsigned int dbus_message_iter_next(DBusMessageIter* iter) | ||
| 120 | +{ | ||
| 121 | + return 0; | ||
| 122 | +} | ||
| @@ -13,8 +13,8 @@ | |||
| 13 | #ifndef __MOCK_DBUS_H__ | 13 | #ifndef __MOCK_DBUS_H__ |
| 14 | #define __MOCK_DBUS_H__ | 14 | #define __MOCK_DBUS_H__ |
| 15 | typedef struct { | 15 | typedef struct { |
| 16 | - char *name; | 16 | + char* name; |
| 17 | - char *message; | 17 | + char* message; |
| 18 | } DBusError; | 18 | } DBusError; |
| 19 | typedef enum { DBUS_BUS_SYSTEM = 1, DBUS_BUS_SESSION = 2 } DBusBusType; | 19 | typedef enum { DBUS_BUS_SYSTEM = 1, DBUS_BUS_SESSION = 2 } DBusBusType; |
| 20 | 20 | ||
| @@ -25,71 +25,59 @@ typedef struct DBusMessage DBusMessage; | |||
| 25 | typedef struct DBusMessageIter DBusMessageIter; | 25 | typedef struct DBusMessageIter DBusMessageIter; |
| 26 | 26 | ||
| 27 | typedef enum { | 27 | typedef enum { |
| 28 | - DBUS_TYPE_INVALID = 0, | 28 | + DBUS_TYPE_INVALID = 0, |
| 29 | - DBUS_TYPE_INT32 = 'i', | 29 | + DBUS_TYPE_INT32 = 'i', |
| 30 | - DBUS_TYPE_INT16 = 's', | 30 | + DBUS_TYPE_INT16 = 's', |
| 31 | - DBUS_TYPE_UINT32 = 'u', | 31 | + DBUS_TYPE_UINT32 = 'u', |
| 32 | - DBUS_TYPE_UINT16 = 'q', | 32 | + DBUS_TYPE_UINT16 = 'q', |
| 33 | - DBUS_TYPE_STRING = 's', | 33 | + DBUS_TYPE_STRING = 's', |
| 34 | - DBUS_TYPE_OBJECT_PATH = 'o', | 34 | + DBUS_TYPE_OBJECT_PATH = 'o', |
| 35 | - DBUS_TYPE_SIGNATURE = 'g', | 35 | + DBUS_TYPE_SIGNATURE = 'g', |
| 36 | - DBUS_TYPE_BOOLEAN = 'b', | 36 | + DBUS_TYPE_BOOLEAN = 'b', |
| 37 | - DBUS_TYPE_INT64 = 'x', | 37 | + DBUS_TYPE_INT64 = 'x', |
| 38 | - DBUS_TYPE_UINT64 = 't', | 38 | + DBUS_TYPE_UINT64 = 't', |
| 39 | - DBUS_TYPE_DOUBLE = 'd', | 39 | + DBUS_TYPE_DOUBLE = 'd', |
| 40 | - DBUS_TYPE_ARRAY = 'a', | 40 | + DBUS_TYPE_ARRAY = 'a', |
| 41 | - DBUS_TYPE_STRUCT = 'r', | 41 | + DBUS_TYPE_STRUCT = 'r', |
| 42 | - DBUS_TYPE_VARIANT = 'v', | 42 | + DBUS_TYPE_VARIANT = 'v', |
| 43 | - DBUS_TYPE_DICT_ENTRY = 'e', | 43 | + DBUS_TYPE_DICT_ENTRY = 'e', |
| 44 | - DBUS_TYPE_UNIX_FD = 'h' | 44 | + DBUS_TYPE_UNIX_FD = 'h' |
| 45 | } DBusType; | 45 | } DBusType; |
| 46 | 46 | ||
| 47 | typedef enum { | 47 | typedef enum { |
| 48 | - DBUS_MESSAGE_TYPE_INVALID = 0, | 48 | + DBUS_MESSAGE_TYPE_INVALID = 0, |
| 49 | - DBUS_MESSAGE_TYPE_METHOD_CALL, | 49 | + DBUS_MESSAGE_TYPE_METHOD_CALL, |
| 50 | - DBUS_MESSAGE_TYPE_METHOD_RETURN, | 50 | + DBUS_MESSAGE_TYPE_METHOD_RETURN, |
| 51 | - DBUS_MESSAGE_TYPE_ERROR, | 51 | + DBUS_MESSAGE_TYPE_ERROR, |
| 52 | - DBUS_MESSAGE_TYPE_SIGNAL | 52 | + DBUS_MESSAGE_TYPE_SIGNAL |
| 53 | } DBusMessageType; | 53 | } DBusMessageType; |
| 54 | 54 | ||
| 55 | -void dbus_init(void); | 55 | +void dbus_init(void); |
| 56 | -void dbus_error_init(DBusError *error); | 56 | +void dbus_error_init(DBusError* error); |
| 57 | -DBusConnection *dbus_bus_get(DBusBusType type, DBusError *error); | 57 | +DBusConnection* dbus_bus_get(DBusBusType type, DBusError* error); |
| 58 | -DBusMessage *dbus_message_new_method_call(const char *bus_name, | 58 | +DBusMessage* dbus_message_new_method_call(const char* bus_name, const char* object_path, const char* interface_name, |
| 59 | - const char *object_path, | 59 | + const char* method_name); |
| 60 | - const char *interface_name, | 60 | +void dbus_message_iter_recurse(DBusMessageIter* iter, DBusMessageIter* sub); |
| 61 | - const char *method_name); | 61 | +unsigned int dbus_message_append_args(DBusMessage* message, const char* signature, ...); |
| 62 | -void dbus_message_iter_recurse(DBusMessageIter *iter, DBusMessageIter *sub); | 62 | +int dbus_message_iter_get_arg_type(const DBusMessageIter* iter); |
| 63 | -unsigned int dbus_message_append_args(DBusMessage *message, | 63 | +void dbus_message_iter_get_basic(DBusMessageIter* iter, void* value); |
| 64 | - const char *signature, ...); | 64 | +unsigned int dbus_message_iter_init(DBusMessage* message, DBusMessageIter* iter); |
| 65 | -int dbus_message_iter_get_arg_type(const DBusMessageIter *iter); | 65 | +void dbus_message_unref(DBusMessage* message); |
| 66 | -void dbus_message_iter_get_basic(DBusMessageIter *iter, void *value); | 66 | +DBusMessage* dbus_connection_send_with_reply_and_block(DBusConnection* connection, DBusMessage* message, int timeout, |
| 67 | -unsigned int dbus_message_iter_init(DBusMessage *message, | 67 | + DBusError* error); |
| 68 | - DBusMessageIter *iter); | 68 | +unsigned int dbus_message_iter_open_container(DBusMessageIter* iter, DBusMessageType type, const char* container_name, |
| 69 | -void dbus_message_unref(DBusMessage *message); | 69 | + DBusMessageIter* subiter); |
| 70 | -DBusMessage * | 70 | +unsigned int dbus_message_iter_close_container(DBusMessageIter* iter, DBusMessageIter* sub); |
| 71 | -dbus_connection_send_with_reply_and_block(DBusConnection *connection, | 71 | +void dbus_connection_set_exit_on_disconnect(DBusConnection* connection, int exit_on_disconnect); |
| 72 | - DBusMessage *message, int timeout, | 72 | +DBusConnection* dbus_bus_get_private(DBusBusType bus_type, DBusError* error); |
| 73 | - DBusError *error); | 73 | +int dbus_message_iter_get_element_count(DBusMessageIter* iter); |
| 74 | -unsigned int dbus_message_iter_open_container(DBusMessageIter *iter, | 74 | +unsigned int dbus_message_iter_append_basic(DBusMessageIter* iter, int type, const char* value); |
| 75 | - DBusMessageType type, | 75 | +unsigned int dbus_message_get_args(DBusMessage* message, DBusError* error, int first_arg_type, ...); |
| 76 | - const char *container_name, | 76 | +void dbus_connection_unref(DBusConnection* connection); |
| 77 | - DBusMessageIter *subiter); | 77 | +void dbus_error_free(DBusError* error); |
| 78 | -unsigned int dbus_message_iter_close_container(DBusMessageIter *iter, | 78 | +void dbus_message_iter_init_append(DBusMessage* message, DBusMessageIter* iter); |
| 79 | - DBusMessageIter *sub); | 79 | +void dbus_connection_close(DBusConnection* connection); |
| 80 | -void dbus_connection_set_exit_on_disconnect(DBusConnection *connection, | 80 | +unsigned int dbus_error_is_set(const DBusError* error); |
| 81 | - int exit_on_disconnect); | 81 | +unsigned int dbus_message_iter_next(DBusMessageIter* iter); |
| 82 | -DBusConnection *dbus_bus_get_private(DBusBusType bus_type, DBusError *error); | ||
| 83 | -int dbus_message_iter_get_element_count(DBusMessageIter *iter); | ||
| 84 | -unsigned int dbus_message_iter_append_basic(DBusMessageIter *iter, int type, | ||
| 85 | - const char *value); | ||
| 86 | -unsigned int dbus_message_get_args(DBusMessage *message, DBusError *error, | ||
| 87 | - int first_arg_type, ...); | ||
| 88 | -void dbus_connection_unref(DBusConnection *connection); | ||
| 89 | -void dbus_error_free(DBusError *error); | ||
| 90 | -void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter); | ||
| 91 | -void dbus_connection_close(DBusConnection *connection); | ||
| 92 | -unsigned int dbus_error_is_set(const DBusError *error); | ||
| 93 | -unsigned int dbus_message_iter_next(DBusMessageIter *iter); | ||
| 94 | 82 | ||
| 95 | #endif | 83 | #endif |


没有必要维护多份文档,看看这个:https://www.openubmc.cn/docs/zh/development/develop_guide/feature_development/CLI_mapping_guide.html 不在这里面的再到readme里加,这个链接记得贴上 我看最后有参考文档,你看看还需不需要补充,不需要的话删了吧