POSIX Shell Server and Login Services - posh
#include <posh_init.h>
The posh server provides a shell for user interaction via telnet or serial file I/O. Typically, when initialized, it allows users to query files, examine the file structure, create new files and look at the content of files. It is a minimal implementation for memory reasons. It does not support scripting of any kind and only supports a minimal set of commands.
The posh server inputs characters and outputs results of command requests. The first command request is a login request. Unlike many implementations, the login support is contained within posh - it does not have a separate thread for this purpose. The .login file is specified at posh creation time in the initialization structure.
The initialization structure also specifies the mount points for two file systems. These mount points are important to avoid attempts to list non-existent files. Setup these mount points at creation time for proper operation.
The final elements of the initalization structure are the input and output streams. These two are specified as files. The structure is shown below.
The login services are provided by the posh server library. These login services allow users to identify users and passwords, update users and passwords and create new password files. These functions are usable when posh is included in the system.
All login functions return 0 on success, -2 on a missing user if the password is being updated and -1 on all other conditions like missing login file or failed user - password.
All errors are handled by the return values.
Posh initialization structure.
struct set_posh
{
char *stdinstring; // set the input stream
char *stdoutstring; // set output stream
char *mountpoint; // set first file mount point
char *mountpoint2; // set second file mount point
char *loginfile;
};This partial example shows the creation and registration of the posh server. After creation, posh may be accessed via the serial port setup for input and output.
THREAD Main(void *arg)
{
int mystatus;
pthread_t poshTid;
pthread_attr_t poshattr;
struct sched_param poshPriority;
struct set_posh *set_posh_tty;
xprintf("Start Main\n");
posix_compat("", "/dev/ttyS0", "/dev/ttyS0");
printf("Start tty, fsys with posix_compat\n");
// insert posh here and see what we get...
// first fill the files so we can play
filetest();
mystatus = pthread_attr_init(&poshattr);
mystatus = pthread_attr_setstacksize(&poshattr, 1400);
poshPriority.sched_priority = 6;
mystatus = pthread_attr_setschedparam(&poshattr, &poshPriority);
if( (set_posh_tty = malloc(sizeof(struct set_posh)))==NULL)
{
xprintf("posh create - no memory\n");
pthread_exit(0);
}
set_posh_tty->stdinstring = "/dev/ttyS0";
set_posh_tty->stdoutstring = "/dev/ttyS0";
set_posh_tty->mountpoint = "/dev/rd/d1";
set_posh_tty->mountpoint2 = NULL;
set_posh_tty->loginfile = "/dev/rd/d1/.login";
mystatus = pthread_create(&poshTid, &poshattr, (void *)(&posh), set_posh_tty);
pthread_exit(0);
}help - help listing
alias [alias_name="value"] - setup an alias for an expression
cat - concatinate output
cd <dir> - change directory
chmod <mode> <dir | file> - change a file's mode
cp <src> <dst> - copy a file
exit - exit the posh shell
logout - logout of posh
ls [option] - list directory contents
-l for long list
-d lists directories, not content
mkdir <dir> - make a directory
mv <src> <dst> - move a file
printenv [env_name] - print all or part of environment - printenv [VARIABLE]...
or printenv OPTION
pwd - present working directory
rm <file> - remove a file
rmdir - remove a directory
setenv [env_name="value"] - set an environment variable
unalias <alias_name> - delete an alias
useradd <username> <password> - add a user with a password
userdel <username> - delete a user
userpasswd <username> <oldpassword> <newpassword> - set (or reset) a user password
There is a demo available for the Unison and DSPnano posh server which is found in installdir/demos and a second demo available with the telnet server which uses posh for command interpretation.