mars_dosutils-0.10

This commit is contained in:
Mario Fetka
2011-11-13 00:40:40 +01:00
parent 5e6805dd31
commit f375f79cce
18 changed files with 768 additions and 529 deletions

215
login.c
View File

@@ -1,4 +1,4 @@
/* login.c 05-Apr-96 */
/* login.c 21-May-96 */
/****************************************************************
* (C)opyright (C) 1993,1996 Martin Stover, Marburg, Germany *
@@ -7,7 +7,6 @@
#include "net.h"
#include "nwcrypt.h"
static int do_change_object_passwd(char *name,
uint16 objtyp,
char *oldpassword,
@@ -115,12 +114,13 @@ static int login_usage(void)
return(-1);
}
int func_login(int argc, char *argv[])
int func_login(int argc, char *argv[], int mode)
{
int result=-1;
int option=0;
uint8 uname[200];
uint8 upasswd[200];
SEARCH_VECTOR save_drives;
if (argc > 1) {
if (argv[1][0] == '-') {
@@ -130,13 +130,15 @@ int func_login(int argc, char *argv[])
argv++;
}
}
get_search_drive_vektor(save_drives);
remove_nwpathes();
if (argc > 1) strmaxcpy(uname, argv[1], sizeof(uname) -1);
else uname[0]='\0';
if (argc > 2) strmaxcpy(upasswd, argv[2], sizeof(upasswd) -1);
else upasswd[0]='\0';
while (result) {
if (!uname[0]) getstr("login", uname, sizeof(uname)-1, 1);
if (!uname[0]) getstr("Login", uname, sizeof(uname)-1, 1);
if (uname[0]) {
upstr(uname);
upstr(upasswd);
@@ -152,16 +154,29 @@ int func_login(int argc, char *argv[])
}
} else break;
}
if (result > -1) {
char profile[200];
remove_nwpathes();
sprintf(profile, "%slogin", prgpath);
read_command_file(profile);
} else {
(void)set_search_drive_vektor(save_drives);
}
return(result);
}
int func_logout(int argc, char *argv[])
int func_logout(int argc, char *argv[], int mode)
{
if (logout()) fprintf(stderr, "logout=%d", neterrno);
remove_nwpathes();
if (logout()) {
fprintf(stderr, "logout=%d\n", neterrno);
return(1);
}
return(0);
}
int func_passwd(int argc, char *argv[])
int func_passwd(int argc, char *argv[], int mode)
{
int result=0;
uint8 uname[100];
@@ -169,7 +184,7 @@ int func_passwd(int argc, char *argv[])
uint32 my_obj_id;
if (ncp_14_46(&my_obj_id) < 0 || my_obj_id == MAX_U32 || !my_obj_id) {
fprintf(stderr, "Cannot get actual User ID\n");
fprintf(stderr, "Cannot get actual user id\n");
result = -1;
}
@@ -179,13 +194,13 @@ int func_passwd(int argc, char *argv[])
upstr(uname);
obj_id = ncp_17_35(uname, 1);
if (!obj_id) {
fprintf(stderr, "Unkwown User: %s\n", uname);
fprintf(stderr, "Unkwown user: %s\n", uname);
return(-1);
}
} else if (!result) {
uint16 obj_typ;
if (ncp_17_36(my_obj_id, uname, &obj_typ) || obj_typ != 1) {
fprintf(stderr, "Cannot get actual Username\n");
fprintf(stderr, "Cannot get actual username\n");
result=-1;
}
}
@@ -194,11 +209,11 @@ int func_passwd(int argc, char *argv[])
uint8 newpasswd2[130];
if (my_obj_id == 1L) *upasswd='\0';
else {
getstr("Old Password", upasswd, sizeof(upasswd)-1, 0);
getstr("Old password", upasswd, sizeof(upasswd)-1, 0);
upstr(upasswd);
}
getstr("New Password", newpasswd, sizeof(newpasswd)-1, 0);
getstr("New Password again", newpasswd2, sizeof(newpasswd2)-1, 0);
getstr("New password", newpasswd, sizeof(newpasswd)-1, 0);
getstr("New password again", newpasswd2, sizeof(newpasswd2)-1, 0);
if (!strcmp(newpasswd, newpasswd2)) {
upstr(uname);
upstr(newpasswd);
@@ -213,3 +228,175 @@ int func_passwd(int argc, char *argv[])
return(result);
}
static int get_line(FILE *f, char *buff, int bufsize, uint8 *str, int strsize)
/* returns command line or -1 if ends */
{
if ((FILE*) NULL != f) {
while (fgets(buff, bufsize, f) != NULL){
char *p = buff;
char *beg = NULL;
char c;
int len=0;
while (0 != (c = *p++) && c != '\n' && c != '\r' && c != '#') {
if (!beg){
if (c != '\t' && c != 32) {
beg = p - 1;
len = 1;
}
} else ++len;
}
if (len) {
strmaxcpy((uint8*)str, (uint8*)beg, min(len, strsize-1));
return(0);
}
}
}
return(-1);
}
static char **build_argv(char *buf, int bufsize, char *command)
/* routine returns **argv for use with execv routines */
/* buf will contain the path component */
{
int len = strlen(command);
int offset = ((len+4) / 4) * 4; /* aligned offset for **argv */
int components = (bufsize - offset) / 4;
if (components > 1) { /* minimal argv[0] + NULL */
char **argv = (char **)(buf+offset);
char **pp = argv;
char *p = buf;
char c;
int i=0;
--components;
memcpy(buf, command, len);
memset(buf+len, 0, bufsize - len);
*pp = p;
while ((0 != (c = *p++)) && i < components) {
if (c == 32 || c == '\t') {
*(p-1) = '\0';
if (*p != 32 && *p != '\t') {
*(++pp)=p;
i++;
}
} else if (!i && c == '/') { /* here i must get argv[0] */
*pp=p;
}
}
return(argv);
}
return(NULL);
}
int read_command_file(char *fstr)
{
FILE *f=fopen(fstr, "r");
int result=-1;
if (f != NULL) {
char *linebuf= xmalloc(512);
char *buf = xmalloc(512);
while (get_line(f, buf, 512, linebuf, 512) > -1) {
char **argv=build_argv(buf, 512, linebuf);
if (argv != NULL) {
int argc=0;
char **pp=argv;
while (*pp) {
argc++;
pp++;
}
upstr(argv[0]);
if (argc > 2 && !strcmp(argv[0], "ECHO")) {
char *p=argv[argc-1];
while (p-- > argv[1]) {
if (*p=='\0') *p=32;
}
argc=2;
}
call_func_entry(argc, argv);
result = 0;
}
}
fclose(f);
xfree(linebuf);
xfree(buf);
} else result=-2;
return(result);
}
int func_profile(int argc, char *argv[], int mode)
{
if (argc < 2) {
fprintf(stderr, "usage:\t%s fn\n", funcname);
return(-1);
}
if (read_command_file(argv[1]) == -2) {
fprintf(stderr, "command file %s not found\n", argv[1]);
}
return(0);
}
int func_cwd(int argc, char *argv[], int mode)
{
char pathname[65];
int len;
if (argc < 2) {
fprintf(stderr, "usage:\t%s path\n", funcname);
return(-1);
}
strmaxcpy(pathname, argv[1], sizeof(pathname) -1);
korrpath(pathname);
if (0 != (len = strlen(pathname))) {
char *p=pathname+len-1;
if (*p == '/' || *p == ':') {
*(++p) = '.';
*(++p) = '\0';
len++;
}
if (!chdir(pathname)) {
if (len > 2 && *(pathname+1) == ':') /* device changed */
setdisk(*pathname - 'a' );
} else {
fprintf(stderr, "cannot chdir to %s\n", pathname);
return(1);
}
return(0);
} else return(-1);
}
int func_echo(int argc, char *argv[], int mode)
{
if (argc > 1)
fprintf(stdout, "%s\n", argv[1]);
return(0);
}
int func_exec(int argc, char *argv[], int mode)
{
if (argc > 1) {
char *buf = xmalloc(512);
char *buff = xmalloc(512);
char *p = buff;
int k = 0;
char **nargv;
while (++k < argc) {
strcpy(p, argv[k]);
p += strlen(argv[k]);
*p++ = 32;
*p = '\0';
}
nargv=build_argv(buf, 512, buff);
xfree(buff);
if (nargv != NULL) {
if (!mode)
spawnvp(P_WAIT, buf, nargv);
else
execvp(buf, nargv);
}
xfree(buf);
}
return(0);
}