|
@@ -101,33 +101,26 @@ typedef shellmatta_retCode_t (*shellmatta_cmdFct_t)(const shellmatta_handle_t
|
|
*/
|
|
*/
|
|
typedef shellmatta_retCode_t (*shellmatta_write_t)(const char* data, uint32_t length);
|
|
typedef shellmatta_retCode_t (*shellmatta_write_t)(const char* data, uint32_t length);
|
|
|
|
|
|
-/**
|
|
|
|
- * @brief structure of one shellmatta command
|
|
|
|
- */
|
|
|
|
-typedef struct shellmatta_cmd
|
|
|
|
-{
|
|
|
|
- char *cmd; /**< command name */
|
|
|
|
- char *cmdAlias; /**< command alias */
|
|
|
|
- char *helpText; /**< help text to print in "help" command */
|
|
|
|
- char *usageText; /**< usage text - printed on "help cmd" */
|
|
|
|
-#ifdef SHELLMATTA_AUTHENTICATION
|
|
|
|
- uint32_t minRoleId; /**< minimum user role id for this command */
|
|
|
|
-#endif
|
|
|
|
- shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
|
|
|
|
- struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
|
|
|
-} shellmatta_cmd_t;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
#ifdef SHELLMATTA_AUTHENTICATION
|
|
#ifdef SHELLMATTA_AUTHENTICATION
|
|
/**
|
|
/**
|
|
* @brief user role matrix
|
|
* @brief user role matrix
|
|
*/
|
|
*/
|
|
typedef struct
|
|
typedef struct
|
|
{
|
|
{
|
|
- uint32_t roleId; /**< id of the user role (!= 0) */
|
|
|
|
|
|
+ uint32_t userId; /**< id of the user (!= 0) */
|
|
const char *username; /**< name of the user role */
|
|
const char *username; /**< name of the user role */
|
|
const char *password; /**< password of the user role or NULL (custom auth) */
|
|
const char *password; /**< password of the user role or NULL (custom auth) */
|
|
-} user_role_t;
|
|
|
|
|
|
+} shellmatta_user_t;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @brief typedefinition of one line of the authentication table
|
|
|
|
+ */
|
|
|
|
+typedef struct
|
|
|
|
+{
|
|
|
|
+ const char* cmd; /**< command to grand access to */
|
|
|
|
+ const uint32_t *userIds; /**< list of user ids with access to the cmd */
|
|
|
|
+ const uint32_t userIdslength; /**< length of the user list */
|
|
|
|
+} shellmatta_perm_t;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @brief custom shellmatta authentication method
|
|
* @brief custom shellmatta authentication method
|
|
@@ -135,52 +128,86 @@ typedef struct
|
|
* @param[in] password password for the login
|
|
* @param[in] password password for the login
|
|
* @return #SHELLMATTA_OK if the username and password is correct
|
|
* @return #SHELLMATTA_OK if the username and password is correct
|
|
*/
|
|
*/
|
|
-typedef shellmatta_retCode_t (*shellmatta_auth_check_t)(const char* username, const char* password);
|
|
|
|
|
|
+typedef shellmatta_retCode_t (*shellmatta_check_t)(const char* username, const char* password);
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @brief login states
|
|
|
|
+ */
|
|
|
|
+typedef enum
|
|
|
|
+{
|
|
|
|
+ SHELLMATTA_AUTH_IDLE, /**< authentication system waits */
|
|
|
|
+ SHELLMATTA_AUTH_USERNAME, /**< input of username */
|
|
|
|
+ SHELLMATTA_AUTH_PASSWORD /**< input of password */
|
|
|
|
+} shellmatta_auth_status_t;
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief structure of one shellmatta command
|
|
|
|
+ */
|
|
|
|
+typedef struct shellmatta_cmd
|
|
|
|
+{
|
|
|
|
+ char *cmd; /**< command name */
|
|
|
|
+ char *cmdAlias; /**< command alias */
|
|
|
|
+ char *helpText; /**< help text to print in "help" command */
|
|
|
|
+ char *usageText; /**< usage text - printed on "help cmd" */
|
|
|
|
+ shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
|
|
|
|
+ struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
|
|
|
+#ifdef SHELLMATTA_AUTHENTICATION
|
|
|
|
+ shellmatta_perm_t *authLink; /**< internally used - pointer to perm list */
|
|
|
|
+#endif
|
|
|
|
+} shellmatta_cmd_t;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @brief structure of one shellmatta instance
|
|
* @brief structure of one shellmatta instance
|
|
*/
|
|
*/
|
|
typedef struct
|
|
typedef struct
|
|
{
|
|
{
|
|
- uint32_t magic; /**< magic number to check if initialized */
|
|
|
|
- char *buffer; /**< input buffer */
|
|
|
|
- uint32_t bufferSize; /**< size of the input buffer */
|
|
|
|
- uint32_t inputCount; /**< offset of the current write operation */
|
|
|
|
- uint32_t byteCounter; /**< counter used to loop over input data */
|
|
|
|
- uint32_t lastNewlineIdx; /**< index of the lest newline */
|
|
|
|
- uint32_t cursor; /**< offset where the cursor is at */
|
|
|
|
- uint32_t stdinIdx; /**< start index of stdin in buffer */
|
|
|
|
- uint32_t stdinLength; /**< length of the stdin data */
|
|
|
|
- char *historyBuffer; /**< buffer to store the last commands */
|
|
|
|
- uint32_t historyBufferSize; /**< size of the history buffer */
|
|
|
|
- uint32_t historyStart; /**< index of the oldest stored command */
|
|
|
|
- uint32_t historyEnd; /**< index of the newest stored command */
|
|
|
|
- uint32_t historyRead; /**< index of the current search */
|
|
|
|
- bool historyReadUp; /**< flag to show the last history dir */
|
|
|
|
- uint32_t tabCounter; /**< counts the tabulator key presses */
|
|
|
|
- uint32_t escapeCounter; /**< counts the characters of an escape seq */
|
|
|
|
- char escapeChars[4u]; /**< buffer to save the escape characters */
|
|
|
|
- uint32_t hereStartIdx; /**< heredoc start of "<<" */
|
|
|
|
- uint32_t hereDelimiterIdx; /**< heredoc delimiter index in input */
|
|
|
|
- uint32_t hereLength; /**< length of the heredoc delimiter */
|
|
|
|
- bool echoEnabled; /**< if true the input is printed */
|
|
|
|
- bool dirty; /**< dirty flag to show changes */
|
|
|
|
- const char *prompt; /**< prompt is printed after every command */
|
|
|
|
- char delimiter; /**< delimiter (return) to terminate a cmd */
|
|
|
|
- shellmatta_mode_t mode; /**< mode of the shell */
|
|
|
|
- shellmatta_write_t write; /**< pointer to write function */
|
|
|
|
- shellmatta_cmd_t helpCmd; /**< help command structure */
|
|
|
|
- shellmatta_cmd_t *cmdList; /**< pointer to the first command */
|
|
|
|
- shellmatta_cmd_t *continuousCmd; /**< command to be called continuously */
|
|
|
|
- shellmatta_cmd_t *busyCmd; /**< command to be polled (busy mode) */
|
|
|
|
- bool cmdListIsConst; /**< true if the #cmdList was passed during
|
|
|
|
- initialization */
|
|
|
|
- shellmatta_opt_t optionParser; /**< option parser sructure */
|
|
|
|
|
|
+ uint32_t magic; /**< magic number to check if initialized */
|
|
|
|
+ char *buffer; /**< input buffer */
|
|
|
|
+ uint32_t bufferSize; /**< size of the input buffer */
|
|
|
|
+ uint32_t inputCount; /**< offset of the current write operation */
|
|
|
|
+ uint32_t byteCounter; /**< counter used to loop over input data */
|
|
|
|
+ uint32_t lastNewlineIdx; /**< index of the lest newline */
|
|
|
|
+ uint32_t cursor; /**< offset where the cursor is at */
|
|
|
|
+ uint32_t stdinIdx; /**< start index of stdin in buffer */
|
|
|
|
+ uint32_t stdinLength; /**< length of the stdin data */
|
|
|
|
+ char *historyBuffer; /**< buffer to store the last commands */
|
|
|
|
+ uint32_t historyBufferSize; /**< size of the history buffer */
|
|
|
|
+ uint32_t historyStart; /**< index of the oldest stored command */
|
|
|
|
+ uint32_t historyEnd; /**< index of the newest stored command */
|
|
|
|
+ uint32_t historyRead; /**< index of the current search */
|
|
|
|
+ bool historyReadUp; /**< flag to show the last history dir */
|
|
|
|
+ uint32_t tabCounter; /**< counts the tabulator key presses */
|
|
|
|
+ uint32_t escapeCounter; /**< counts the characters of an escape seq */
|
|
|
|
+ char escapeChars[4u]; /**< buffer to save the escape characters */
|
|
|
|
+ uint32_t hereStartIdx; /**< heredoc start of "<<" */
|
|
|
|
+ uint32_t hereDelimiterIdx; /**< heredoc delimiter index in input */
|
|
|
|
+ uint32_t hereLength; /**< length of the heredoc delimiter */
|
|
|
|
+ bool echoEnabled; /**< if true the input is printed */
|
|
|
|
+ bool dirty; /**< dirty flag to show changes */
|
|
|
|
+ const char *prompt; /**< prompt is printed after every command */
|
|
|
|
+ char delimiter; /**< delimiter (return) to terminate a cmd */
|
|
|
|
+ shellmatta_mode_t mode; /**< mode of the shell */
|
|
|
|
+ shellmatta_write_t write; /**< pointer to write function */
|
|
|
|
+ shellmatta_cmd_t helpCmd; /**< help command structure */
|
|
|
|
+ shellmatta_cmd_t *cmdList; /**< pointer to the first command */
|
|
|
|
+ shellmatta_cmd_t *continuousCmd; /**< command to be called continuously */
|
|
|
|
+ shellmatta_cmd_t *busyCmd; /**< command to be polled (busy mode) */
|
|
|
|
+ bool cmdListIsConst; /**< true if the #cmdList was passed during
|
|
|
|
+ initialization */
|
|
|
|
+ shellmatta_opt_t optionParser; /**< option parser sructure */
|
|
#ifdef SHELLMATTA_AUTHENTICATION
|
|
#ifdef SHELLMATTA_AUTHENTICATION
|
|
- uint32_t roleId; /**< role ID of the current session */
|
|
|
|
- user_role_t *userRoleMatrix /**< user role matrix structure */
|
|
|
|
|
|
+ shellmatta_cmd_t loginCmd; /**< login command structure */
|
|
|
|
+ shellmatta_cmd_t logoutCmd; /**< logout command structure */
|
|
|
|
+ uint32_t userId; /**< user ID of the current session */
|
|
|
|
+ shellmatta_user_t *userPointer; /**< pointer to the user in the user list */
|
|
|
|
+ shellmatta_user_t *userList; /**< user list */
|
|
|
|
+ uint32_t userListLength; /**< length of the user list */
|
|
|
|
+ shellmatta_perm_t *permList; /**< permission list */
|
|
|
|
+ uint32_t permListLength; /**< length of the permission list */
|
|
|
|
+ shellmatta_check_t checkFct; /**< custom credential check function */
|
|
#endif
|
|
#endif
|
|
} shellmatta_instance_t;
|
|
} shellmatta_instance_t;
|
|
|
|
|
|
@@ -241,18 +268,20 @@ shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
|
|
|
|
|
|
#ifdef SHELLMATTA_AUTHENTICATION
|
|
#ifdef SHELLMATTA_AUTHENTICATION
|
|
|
|
|
|
-shellmatta_retCode_t shellmatta_auth_init( shellmatta_handle_t handle,
|
|
|
|
- user_role_t *userRoleMatrix,
|
|
|
|
- uint32_t length,
|
|
|
|
- bool customLogin,
|
|
|
|
- shellmatta_auth_check_t checkFct);
|
|
|
|
-shellmatta_retCode_t shellmatta_auth_login( shellmatta_handle_t handle,
|
|
|
|
- uint32_t roleId);
|
|
|
|
-shellmatta_retCode_t shellmatta_auth_logout( shellmatta_handle_t handle);
|
|
|
|
-uint32_t shellmatta_auth_getLoggedInRole( shellmatta_handle_t handle);
|
|
|
|
-shellmatta_retCode_t shellmatta_auth_getLoggedInUserName( shellmatta_handle_t handle,
|
|
|
|
- char **data,
|
|
|
|
- uint32_t *length);
|
|
|
|
|
|
+shellmatta_retCode_t shellmatta_auth_init( shellmatta_handle_t handle,
|
|
|
|
+ shellmatta_user_t *userList,
|
|
|
|
+ uint32_t userListLength,
|
|
|
|
+ shellmatta_perm_t *permList,
|
|
|
|
+ uint32_t permListLength,
|
|
|
|
+ bool customLogin,
|
|
|
|
+ shellmatta_check_t checkFct);
|
|
|
|
+shellmatta_retCode_t shellmatta_auth_login( shellmatta_handle_t handle,
|
|
|
|
+ uint32_t userId);
|
|
|
|
+shellmatta_retCode_t shellmatta_auth_logout( shellmatta_handle_t handle);
|
|
|
|
+uint32_t shellmatta_auth_getLoggedInUserId( shellmatta_handle_t handle);
|
|
|
|
+shellmatta_retCode_t shellmatta_auth_getLoggedInUserName( shellmatta_handle_t handle,
|
|
|
|
+ char **data,
|
|
|
|
+ uint32_t *length);
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|