2011-11-13 00:38:56 +01:00
|
|
|
|
/* connect.c 20-Mar-96 */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
/* (C)opyright (C) 1993,1996 Martin Stover, Marburg, Germany
|
2011-11-13 00:38:55 +01:00
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
extern int errno;
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* #define TEST_FNAME "PRINT.000"
|
|
|
|
|
*/
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#ifdef TEST_FNAME
|
|
|
|
|
static int test_handle=-1;
|
|
|
|
|
#endif
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
#define DONT_KNOW_IF_OK 1
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static int default_uid=-1;
|
|
|
|
|
static int default_gid=-1;
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#include "nwvolume.h"
|
2011-11-13 00:38:56 +01:00
|
|
|
|
#include "nwfile.h"
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#include "connect.h"
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_DIR dirs[MAX_NW_DIRS];
|
|
|
|
|
int used_dirs=0;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static int connect_is_init = 0;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
#define MAX_DIRHANDLES 80
|
|
|
|
|
|
|
|
|
|
static DIR_HANDLE dir_handles[MAX_DIRHANDLES];
|
|
|
|
|
|
|
|
|
|
static int anz_dirhandles=0;
|
|
|
|
|
|
|
|
|
|
static char *build_unix_name(NW_PATH *nwpath, int modus)
|
|
|
|
|
/*
|
|
|
|
|
* returns complete UNIX path
|
|
|
|
|
* modus & 1 : ignore fn, (only path)
|
|
|
|
|
* modus & 2 : no '/' at end
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
static char unixname[300]; /* must be big enouugh */
|
|
|
|
|
int volume = nwpath->volume;
|
|
|
|
|
char *p, *pp;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (volume < 0 || volume >= used_nw_volumes) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
fprintf(stderr, "build_unix_name volume=%d not ok\n", volume);
|
|
|
|
|
strcpy(unixname, "ZZZZZZZZZZZZ"); /* vorsichthalber */
|
|
|
|
|
return(unixname);
|
|
|
|
|
}
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy(unixname, (char*)nw_volumes[volume].unixname); /* first UNIXNAME VOLUME */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
p = pp = unixname+strlen(unixname);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy(p, (char*)nwpath->path); /* now the path */
|
|
|
|
|
p += strlen((char*)nwpath->path);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if ( (!(modus & 1)) && nwpath->fn[0])
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy(p, (char*)nwpath->fn); /* and now fn */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
else if ((modus & 2) && (*(p-1) == '/')) *(p-1) = '\0';
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (nw_volumes[volume].options & 1) downstr((uint8*)pp);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(unixname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int new_dir_handle(ino_t inode, NW_PATH *nwpath)
|
|
|
|
|
/*
|
|
|
|
|
* RETURN=errorcode (<0) or dir_handle
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
int rethandle;
|
|
|
|
|
DIR_HANDLE *fh = NULL;
|
|
|
|
|
time_t akttime = time(NULL);
|
|
|
|
|
time_t last_time = akttime;
|
|
|
|
|
int thandle = 0;
|
|
|
|
|
int nhandle = 0;
|
|
|
|
|
for (rethandle=0; rethandle < anz_dirhandles; rethandle++){
|
|
|
|
|
fh=&(dir_handles[rethandle]);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (!fh->inode) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!nhandle) nhandle = rethandle+1;
|
|
|
|
|
} else if (fh->inode == inode && fh->volume == nwpath->volume){
|
|
|
|
|
/* Dieser hat Vorrang */
|
|
|
|
|
if (fh->f) closedir(fh->f);
|
|
|
|
|
fh->f = NULL;
|
|
|
|
|
fh->timestamp = akttime;
|
|
|
|
|
nhandle = rethandle+1;
|
|
|
|
|
break;
|
|
|
|
|
} else if (fh->timestamp < last_time){
|
|
|
|
|
thandle = rethandle+1;
|
|
|
|
|
last_time = fh->timestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!nhandle){
|
|
|
|
|
if (anz_dirhandles < MAX_DIRHANDLES) {
|
|
|
|
|
fh=&(dir_handles[anz_dirhandles]);
|
|
|
|
|
rethandle = ++anz_dirhandles;
|
|
|
|
|
} else {
|
|
|
|
|
fh=&(dir_handles[thandle-1]);
|
|
|
|
|
if (fh->f) closedir(fh->f);
|
|
|
|
|
fh->f = NULL;
|
|
|
|
|
rethandle = thandle;
|
|
|
|
|
}
|
|
|
|
|
} else rethandle=nhandle;
|
|
|
|
|
|
|
|
|
|
/* init dir_handle */
|
|
|
|
|
fh=&(dir_handles[rethandle-1]);
|
|
|
|
|
strcpy(fh->unixname, build_unix_name(nwpath, 0));
|
|
|
|
|
if ((fh->f = opendir(fh->unixname)) != (DIR*) NULL){
|
|
|
|
|
fh->kpath = fh->unixname + strlen(fh->unixname);
|
|
|
|
|
fh->volume = nwpath->volume;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
fh->vol_options = nw_volumes[fh->volume].options;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
fh->inode = inode;
|
|
|
|
|
fh->timestamp = akttime;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (fh->vol_options & VOL_OPTION_REMOUNT) {
|
|
|
|
|
closedir(fh->f);
|
|
|
|
|
fh->f = NULL;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else {
|
|
|
|
|
fh->f = (DIR*)NULL;
|
|
|
|
|
fh->unixname[0] = '\0';
|
|
|
|
|
fh->vol_options = 0;
|
|
|
|
|
fh->kpath = (char*)NULL;
|
|
|
|
|
rethandle = -0x9c;
|
|
|
|
|
}
|
|
|
|
|
return(rethandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int free_dir_handle(int dhandle)
|
|
|
|
|
{
|
|
|
|
|
if (dhandle > 0 && --dhandle < anz_dirhandles) {
|
|
|
|
|
DIR_HANDLE *fh=&(dir_handles[dhandle]);
|
|
|
|
|
if (fh->f != (DIR*) NULL) {
|
|
|
|
|
closedir(fh->f);
|
|
|
|
|
fh->f = (DIR*)NULL;
|
|
|
|
|
}
|
2011-11-13 00:38:56 +01:00
|
|
|
|
fh->inode = 0;
|
|
|
|
|
while (anz_dirhandles && !dir_handles[anz_dirhandles-1].inode)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
anz_dirhandles--;
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
return(-0x88); /* wrong dir_handle */
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
void set_default_guid(void)
|
|
|
|
|
{
|
|
|
|
|
seteuid(0);
|
|
|
|
|
if (setegid(default_gid) < 0 || seteuid(default_uid) < 0) {
|
2011-11-13 00:38:56 +01:00
|
|
|
|
errorp(1, "set_default_guid, !! Abort !!",
|
|
|
|
|
"Cannot set default gid=%d and uid=%d" , default_gid, default_uid);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_guid(int gid, int uid)
|
|
|
|
|
{
|
|
|
|
|
if ( gid < 0 || uid < 0
|
|
|
|
|
|| seteuid(0)
|
|
|
|
|
|| setegid(gid) == -1
|
|
|
|
|
|| seteuid(uid) == -1 ) {
|
|
|
|
|
DPRINTF(("SET GID=%d, UID=%d failed\n", gid, uid));
|
|
|
|
|
set_default_guid();
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else XDPRINTF((5,0,"SET GID=%d, UID=%d OK", gid, uid));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static char *conn_get_nwpath_name(NW_PATH *p)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* for debugging */
|
|
|
|
|
{
|
|
|
|
|
static char nwpathname[300];
|
|
|
|
|
char volname[100];
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (p->volume < 0 || p->volume >= used_nw_volumes) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
sprintf(volname, "<%d=NOT-OK>", (int)p->volume);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
} else strcpy(volname, (char*)nw_volumes[p->volume].sysname);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
sprintf(nwpathname, "%s:%s%s", volname, p->path, p->fn);
|
|
|
|
|
return(nwpathname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int x_str_match(uint8 *s, uint8 *p)
|
|
|
|
|
{
|
|
|
|
|
uint8 pc, sc;
|
|
|
|
|
uint state = 0;
|
|
|
|
|
uint8 anf, ende;
|
|
|
|
|
int not = 0;
|
|
|
|
|
uint found = 0;
|
|
|
|
|
while ( (pc = *p++) != 0) {
|
|
|
|
|
switch (state){
|
|
|
|
|
case 0 :
|
|
|
|
|
switch (pc) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
case 255: if (*p == '*' || *p == '?') continue;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\\': /* beliebiges Folgezeichen */
|
|
|
|
|
if (*p++ != *s++) return(0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '?' : if ((sc = *s++) == '.') {
|
|
|
|
|
uint8 *pp=p;
|
|
|
|
|
while (*pp) {
|
|
|
|
|
if (*pp++ == '.') p=pp;
|
|
|
|
|
}
|
|
|
|
|
} else if (!sc) return(1); /* one character */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '.' :
|
|
|
|
|
if (!*s && (!*p || *p == '*' || *p == '?')) return(1);
|
|
|
|
|
if (pc != *s++) return(0);
|
|
|
|
|
if (*p == '*') return(1);
|
|
|
|
|
break;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
case '*' :
|
|
|
|
|
if (!*p) return(1);
|
|
|
|
|
while (*s){
|
|
|
|
|
if (x_str_match(s, p) == 1) return(1);
|
|
|
|
|
++s;
|
|
|
|
|
}
|
|
|
|
|
return((*p == '.' && *(p+1) == '*') ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
case '[' : if ( (*p == '!') || (*p == '^') ){
|
|
|
|
|
++p;
|
|
|
|
|
not = 1;
|
|
|
|
|
}
|
|
|
|
|
state = 1;
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
default : if (pc != *s++) return(0); /* normal char */
|
|
|
|
|
break;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
} /* switch */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1 : /* Bereich von Zeichen */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
sc = *s++;
|
|
|
|
|
found = not;
|
|
|
|
|
if (!sc) return(0);
|
|
|
|
|
do {
|
|
|
|
|
if (pc == '\\') pc = *(p++);
|
|
|
|
|
if (!pc) return(0);
|
|
|
|
|
anf = pc;
|
|
|
|
|
if (*p == '-' && *(p+1) != ']'){
|
|
|
|
|
ende = *(++p);
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
else ende = anf;
|
|
|
|
|
if (found == not) { /* only if not found */
|
|
|
|
|
if (anf == sc || (anf <= sc && sc <= ende))
|
|
|
|
|
found = !not;
|
|
|
|
|
}
|
|
|
|
|
} while ((pc = *(p++)) != ']');
|
|
|
|
|
if (! found ) return(0);
|
|
|
|
|
not = 0;
|
|
|
|
|
found = 0;
|
|
|
|
|
state = 0;
|
|
|
|
|
break;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
default : break;
|
|
|
|
|
} /* switch */
|
|
|
|
|
} /* while */
|
|
|
|
|
return ( (*s) ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int fn_match(uint8 *s, uint8 *p, uint8 options)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
uint8 *ss=s;
|
|
|
|
|
int len=0;
|
|
|
|
|
int pf=0;
|
|
|
|
|
for (; *ss; ss++){
|
|
|
|
|
if (*ss == '.') {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (pf++) return(0); /* no 2. pouint */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
len=0;
|
|
|
|
|
} else {
|
|
|
|
|
if ((pf && len > 3) || len > 8) return(0);
|
|
|
|
|
if (options & 1){ /* only downshift chars */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (*ss >= 'A' && *ss <= 'Z') return(0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else { /* only upshift chars */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (*ss >= 'a' && *ss <= 'z') return(0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(x_str_match(s, p));
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
int attrib;
|
|
|
|
|
struct stat statb;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
uint8 *ubuf; /* userbuff */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} FUNC_SEARCH;
|
|
|
|
|
|
|
|
|
|
static int func_search_entry(NW_PATH *nwpath, int attrib,
|
|
|
|
|
int (*fs_func)(NW_PATH *nwpath, FUNC_SEARCH *fs), FUNC_SEARCH *fs)
|
|
|
|
|
|
|
|
|
|
/* returns > 0 if OK < 1 if not ok or not found */
|
|
|
|
|
{
|
|
|
|
|
struct dirent* dirbuff;
|
|
|
|
|
DIR *f;
|
|
|
|
|
int result=0;
|
|
|
|
|
int okflag=0;
|
|
|
|
|
char xkpath[256];
|
|
|
|
|
uint8 entry[256];
|
|
|
|
|
int volume = nwpath->volume;
|
|
|
|
|
uint8 soptions;
|
|
|
|
|
FUNC_SEARCH fs_local;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (!fs) {
|
|
|
|
|
fs = &fs_local;
|
|
|
|
|
fs->ubuf = NULL;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
fs->attrib = attrib;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (volume < 0 || volume >= used_nw_volumes) return(-1); /* something wrong */
|
|
|
|
|
else soptions = nw_volumes[volume].options;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)entry, (char*)nwpath->fn);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (soptions & 1) downstr(entry); /* now downshift chars */
|
|
|
|
|
nwpath->fn[0] = '\0';
|
|
|
|
|
strcpy(xkpath, build_unix_name(nwpath, 1|2));
|
|
|
|
|
|
|
|
|
|
XDPRINTF((5,0,"func_search_entry attrib=0x%x path:%s:, xkpath:%s:, entry:%s:",
|
|
|
|
|
attrib, nwpath->path, xkpath, entry));
|
|
|
|
|
if ((f=opendir(xkpath)) != (DIR*)NULL) {
|
|
|
|
|
char *kpath=xkpath+strlen(xkpath);
|
|
|
|
|
*kpath++ = '/';
|
|
|
|
|
while ((dirbuff = readdir(f)) != (struct dirent*)NULL){
|
|
|
|
|
okflag = 0;
|
|
|
|
|
if (dirbuff->d_ino) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *name=(uint8*)(dirbuff->d_name);
|
|
|
|
|
okflag = (name[0] != '.' &&
|
|
|
|
|
( (entry[0] == '*' && entry[1] == '\0')
|
2011-11-13 00:38:56 +01:00
|
|
|
|
|| (!strcmp((char*)name, (char*)entry))
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|| fn_match(name, entry, soptions)));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (okflag) {
|
|
|
|
|
*kpath = '\0';
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy(kpath, (char*)name);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!stat(xkpath, &(fs->statb))) {
|
|
|
|
|
okflag = ( ( ( (fs->statb.st_mode & S_IFMT) == S_IFDIR) && (attrib & 0x10))
|
|
|
|
|
|| ( ( (fs->statb.st_mode & S_IFMT) != S_IFDIR) && !(attrib & 0x10)));
|
|
|
|
|
if (okflag){
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)nwpath->fn, (char*)name);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (soptions & 1) upstr(nwpath->fn);
|
|
|
|
|
XDPRINTF((5,0,"FOUND=:%s: attrib=0x%x", nwpath->fn, fs->statb.st_mode));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
result = (*fs_func)(nwpath, fs);
|
|
|
|
|
if (result < 0) break;
|
|
|
|
|
else result=1;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
} else okflag = 0;
|
|
|
|
|
}
|
|
|
|
|
XDPRINTF((6,0, "NAME=:%s: OKFLAG %d", name, okflag));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} /* if */
|
|
|
|
|
} /* while */
|
|
|
|
|
closedir(f);
|
|
|
|
|
} /* if */
|
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static int get_dir_entry(NW_PATH *nwpath,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int *sequence,
|
|
|
|
|
int attrib,
|
|
|
|
|
struct stat *statb)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
/* returns 1 if OK and 0 if not OK */
|
|
|
|
|
{
|
|
|
|
|
struct dirent* dirbuff;
|
|
|
|
|
DIR *f;
|
|
|
|
|
int okflag=0;
|
|
|
|
|
char xkpath[256];
|
|
|
|
|
uint8 entry[256];
|
|
|
|
|
int volume = nwpath->volume;
|
|
|
|
|
uint8 soptions;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (volume < 0 || volume >= used_nw_volumes) return(0); /* something wrong */
|
|
|
|
|
else soptions = nw_volumes[volume].options;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)entry, (char*)nwpath->fn);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (soptions & 1) downstr(entry); /* now downshift chars */
|
|
|
|
|
|
|
|
|
|
nwpath->fn[0] = '\0';
|
|
|
|
|
strcpy(xkpath, build_unix_name(nwpath, 1|2));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"get_dir_entry attrib=0x%x path:%s:, xkpath:%s:, entry:%s:",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
attrib, nwpath->path, xkpath, entry));
|
|
|
|
|
|
|
|
|
|
if ((f=opendir(xkpath)) != (DIR*)NULL) {
|
|
|
|
|
char *kpath=xkpath+strlen(xkpath);
|
|
|
|
|
*kpath++ = '/';
|
|
|
|
|
if (*sequence == MAX_U16) *sequence = 0;
|
|
|
|
|
else seekdir(f, (long)*sequence);
|
|
|
|
|
|
|
|
|
|
while ((dirbuff = readdir(f)) != (struct dirent*)NULL){
|
|
|
|
|
okflag = 0;
|
|
|
|
|
if (dirbuff->d_ino) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *name=(uint8*)(dirbuff->d_name);
|
|
|
|
|
okflag = (name[0] != '.' &&
|
|
|
|
|
( (entry[0] == '*' && entry[1] == '\0')
|
2011-11-13 00:38:56 +01:00
|
|
|
|
|| (!strcmp((char*)name, (char*)entry))
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|| fn_match(name, entry, soptions)));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (okflag) {
|
|
|
|
|
*kpath = '\0';
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy(kpath, (char*)name);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!stat(xkpath, statb)) {
|
|
|
|
|
okflag = ( ( ( (statb->st_mode & S_IFMT) == S_IFDIR) && (attrib & 0x10))
|
|
|
|
|
|| ( ( (statb->st_mode & S_IFMT) != S_IFDIR) && !(attrib & 0x10)));
|
|
|
|
|
if (okflag){
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)nwpath->fn, (char*)name);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (soptions & 1) upstr(nwpath->fn);
|
|
|
|
|
XDPRINTF((5,0,"FOUND=:%s: attrib=0x%x", nwpath->fn, statb->st_mode));
|
|
|
|
|
break; /* ready */
|
|
|
|
|
}
|
|
|
|
|
} else okflag = 0;
|
|
|
|
|
}
|
|
|
|
|
XDPRINTF((6,0, "NAME=:%s: OKFLAG %d", name, okflag));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} /* if */
|
|
|
|
|
} /* while */
|
|
|
|
|
*sequence = (int) telldir(f);
|
|
|
|
|
closedir(f);
|
|
|
|
|
} /* if */
|
|
|
|
|
return(okflag);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
static DIR *give_dh_f(DIR_HANDLE *dh)
|
|
|
|
|
{
|
|
|
|
|
if (!dh->f) {
|
|
|
|
|
*(dh->kpath) = '\0';
|
|
|
|
|
dh->f = opendir(dh->unixname);
|
|
|
|
|
}
|
|
|
|
|
return(dh->f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void release_dh_f(DIR_HANDLE *dh)
|
|
|
|
|
{
|
|
|
|
|
if (dh->f && (dh->vol_options & VOL_OPTION_REMOUNT) ) {
|
|
|
|
|
closedir(dh->f);
|
|
|
|
|
dh->f = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static int get_dh_entry(DIR_HANDLE *dh,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *search,
|
|
|
|
|
int *sequence,
|
|
|
|
|
int attrib,
|
|
|
|
|
struct stat *statb)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
/* returns 1 if OK and 0 if not OK */
|
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
DIR *f = give_dh_f(dh);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int okflag = 0;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (f != (DIR*)NULL) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
struct dirent *dirbuff;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 entry[256];
|
|
|
|
|
strmaxcpy(entry, search, 255);
|
|
|
|
|
|
|
|
|
|
if (dh->vol_options & 1) downstr(entry);
|
|
|
|
|
if ( (uint16)*sequence == MAX_U16) *sequence = 0;
|
|
|
|
|
seekdir(f, (long) *sequence);
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"get_dh_entry attrib=0x%x path:%s:, entry:%s:",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
attrib, dh->unixname, entry));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
while ((dirbuff = readdir(f)) != (struct dirent*)NULL){
|
|
|
|
|
okflag = 0;
|
|
|
|
|
if (dirbuff->d_ino) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *name=(uint8*)(dirbuff->d_name);
|
|
|
|
|
okflag = (name[0] != '.' && (
|
2011-11-13 00:38:56 +01:00
|
|
|
|
(!strcmp((char*)name, (char*)entry)) ||
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(entry[0] == '*' && entry[1] == '\0')
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|| fn_match(name, entry, dh->vol_options)));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
if (okflag) {
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy(dh->kpath, (char*)name);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"get_dh_entry Name=%s unixname=%s",
|
|
|
|
|
name, dh->unixname));
|
|
|
|
|
|
|
|
|
|
if (!stat(dh->unixname, statb)) {
|
|
|
|
|
okflag = ( (( (statb->st_mode & S_IFMT) == S_IFDIR) && (attrib & 0x10))
|
|
|
|
|
|| (((statb->st_mode & S_IFMT) != S_IFDIR) && !(attrib & 0x10)));
|
|
|
|
|
if (okflag){
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)search, (char*)name);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (dh->vol_options & 1) upstr(search);
|
|
|
|
|
break; /* ready */
|
|
|
|
|
}
|
|
|
|
|
} else okflag = 0;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} /* if */
|
|
|
|
|
} /* while */
|
|
|
|
|
dh->kpath[0] = '\0';
|
|
|
|
|
*sequence = (int) telldir(f);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
release_dh_f(dh);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} /* if */
|
|
|
|
|
return(okflag);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
void conn_build_path_fn( uint8 *vol,
|
2011-11-13 00:38:56 +01:00
|
|
|
|
uint8 *path,
|
|
|
|
|
uint8 *fn,
|
|
|
|
|
int *has_wild,
|
|
|
|
|
uint8 *data,
|
|
|
|
|
int len)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
/* is called from build_path */
|
|
|
|
|
{
|
|
|
|
|
uint8 *p = NULL;
|
|
|
|
|
uint8 *p1 = path;
|
|
|
|
|
*vol = '\0';
|
|
|
|
|
*has_wild = 0; /* no wild char */
|
|
|
|
|
while (len-- && *data){
|
|
|
|
|
if (*data == 0xae) *p1++ = '.';
|
|
|
|
|
else if (*data > 0x60 && *data < 0x7b) {
|
|
|
|
|
*p1++ = *data - 0x20; /* all is upshift */
|
|
|
|
|
} else if (*data == 0xaa|| *data == '*' ) {
|
|
|
|
|
*p1++ = '*';
|
|
|
|
|
(*has_wild)++;
|
|
|
|
|
} else if (*data == 0xbf|| *data == '?' ) {
|
|
|
|
|
*p1++ = '?';
|
|
|
|
|
(*has_wild)++;
|
|
|
|
|
} else if (*data == '/' || *data == '\\') {
|
|
|
|
|
*p1++ = '/';
|
|
|
|
|
p = p1;
|
|
|
|
|
} else if (*data == ':') { /* extract volume */
|
|
|
|
|
int len = (int) (p1 - path);
|
|
|
|
|
memcpy(vol, path, len);
|
|
|
|
|
vol[len] = '\0';
|
|
|
|
|
p1 = path;
|
|
|
|
|
} else *p1++ = *data;
|
|
|
|
|
data++;
|
|
|
|
|
}
|
|
|
|
|
*p1 = '\0';
|
|
|
|
|
if (fn != NULL) { /* if with filename */
|
|
|
|
|
if (p != NULL){ /* exist directory-path */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)fn, (char*)p);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
*p = '\0';
|
|
|
|
|
} else { /* only filename */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)fn, (char*)path);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
*path= '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int build_path( NW_PATH *path,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *data,
|
|
|
|
|
int len,
|
|
|
|
|
int only_dir)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/*
|
2011-11-13 00:38:56 +01:00
|
|
|
|
* fills path structure with the right values
|
2011-11-13 00:38:55 +01:00
|
|
|
|
* if only_dir > 0, then the full path will be interpreted
|
|
|
|
|
* as directory, in the other way, the last segment of path
|
|
|
|
|
* will be interpreted as fn.
|
|
|
|
|
* returns -0x98, if volume is wrong
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
uint8 vol[20];
|
2011-11-13 00:38:55 +01:00
|
|
|
|
conn_build_path_fn(vol, path->path,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(only_dir) ? (uint8)NULL
|
|
|
|
|
: path->fn,
|
|
|
|
|
&(path->has_wild),
|
|
|
|
|
data, len);
|
|
|
|
|
|
|
|
|
|
path->volume = -1;
|
|
|
|
|
if (only_dir) path->fn[0] = '\0';
|
|
|
|
|
|
|
|
|
|
if (vol[0]) { /* there is a volume in path */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int j = used_nw_volumes;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
while (j--) {
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (!strcmp((char*)nw_volumes[j].sysname, (char*)vol)) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
path->volume = j;
|
|
|
|
|
break;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (path->volume < 0) return(-0x98);
|
|
|
|
|
}
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int nw_path_ok(NW_PATH *nwpath)
|
|
|
|
|
/* returns UNIX inode of path */
|
|
|
|
|
{
|
|
|
|
|
int j = 0;
|
|
|
|
|
NW_DIR *d=&(dirs[0]);
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
int result = -0x9c; /* wrong path */
|
|
|
|
|
|
|
|
|
|
while (j++ < (int)used_dirs){
|
|
|
|
|
if (d->inode && d->volume == nwpath->volume
|
2011-11-13 00:38:56 +01:00
|
|
|
|
&& !strcmp((char*)nwpath->path, (char*)d->path)){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(d->inode);
|
|
|
|
|
}
|
|
|
|
|
d++;
|
|
|
|
|
} /* while */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!stat(build_unix_name(nwpath, 1 | 2 ), &stbuff)
|
|
|
|
|
&& (stbuff.st_mode & S_IFMT) == S_IFDIR) result=stbuff.st_ino;
|
|
|
|
|
else {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((4,0, "NW_PATH_OK failed:`%s`", conn_get_nwpath_name(nwpath)));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int build_verz_name(NW_PATH *nwpath, /* gets complete path */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int dir_handle) /* search with dirhandle */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
/* return -completition code or inode */
|
|
|
|
|
{
|
|
|
|
|
uint8 searchpath[256];
|
|
|
|
|
uint8 *p=searchpath;
|
|
|
|
|
int completition=0;
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)searchpath, (char*)nwpath->path); /* save path */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
if (nwpath->volume > -1) { /* absolute path */
|
|
|
|
|
nwpath->path[0] = '\0';
|
|
|
|
|
} else { /* volume not kwown yet, I must get it about dir_handle */
|
|
|
|
|
if (dir_handle > 0 &&
|
|
|
|
|
--dir_handle < (int)used_dirs && dirs[dir_handle].inode){
|
|
|
|
|
nwpath->volume = dirs[dir_handle].volume;
|
|
|
|
|
if (searchpath[0] == '/') { /* absolute path */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
p++;
|
|
|
|
|
nwpath->path[0] = '\0';
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else /* get path from dir_handle */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)nwpath->path, (char*)dirs[dir_handle].path);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else return(-0x9b); /* wrong dir handle */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*p) {
|
|
|
|
|
uint8 *panf = nwpath->path;
|
|
|
|
|
uint8 *p1 = panf+strlen((char*)panf);
|
|
|
|
|
uint8 *a = p;
|
|
|
|
|
uint8 w;
|
|
|
|
|
int state = 0;
|
|
|
|
|
while ((!completition) && (w = *p++) > 0){
|
|
|
|
|
if (!state){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"in build_verz_name path=:%s:", nwpath->path));
|
|
|
|
|
if (w == '.') state = 20;
|
|
|
|
|
else if (w == '/') state = 30;
|
|
|
|
|
else state++;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else if (state < 9){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (w == '.') state = 10;
|
|
|
|
|
else if (w == '/') state = 30;
|
|
|
|
|
else state++;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else if (state == 9) completition= -0x9c; /* something wrong */
|
|
|
|
|
else if (state < 14){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (w == '.') return(-0x9c);
|
|
|
|
|
else if (w == '/') state = 30;
|
|
|
|
|
else state++;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else if (state == 14) completition= -0x9c; /* something wrong */
|
|
|
|
|
else if (state == 20){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (w == '/') state = 30;
|
|
|
|
|
else if (w != '.') completition= -0x9c; /* something wrong */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
if (state == 30 || !*p) { /* now action */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *xpath=a;
|
|
|
|
|
int len = (int)(p-a);
|
|
|
|
|
if (len && state == 30) --len; /* '/' stoert hier */
|
|
|
|
|
a = p;
|
|
|
|
|
if (len) {
|
|
|
|
|
if (*xpath == '.') {
|
|
|
|
|
uint8 *xp=xpath+1;
|
|
|
|
|
if (*xp == '.') {
|
|
|
|
|
while (*xp++ == '.' && completition > -1) {
|
|
|
|
|
p1--; /* steht nun auf letztem Zeichen '/' od. ':' */
|
|
|
|
|
if (p1 < panf) completition = -0x9c ;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* wrong path, don't can go back any more */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
else {
|
|
|
|
|
while (p1 > panf && *(--p1) != '/');;
|
|
|
|
|
if (p1 == panf) *p1='\0';
|
|
|
|
|
else *(++p1) = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
memcpy(p1, xpath, len);
|
|
|
|
|
p1 += len;
|
|
|
|
|
*p1++ = '/';
|
|
|
|
|
*p1 = '\0';
|
|
|
|
|
}
|
|
|
|
|
} /* if len */
|
|
|
|
|
state = 0;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!completition) completition = nw_path_ok(nwpath);
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
static int lastdirhandle=0;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int conn_get_kpl_path(NW_PATH *nwpath, int dirhandle,
|
|
|
|
|
uint8 *data, int len, int only_dir)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/*
|
|
|
|
|
* if ok then the inode of dir will be returned
|
|
|
|
|
* else a negativ errcode will be returned
|
|
|
|
|
*/
|
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
int completition;
|
|
|
|
|
#if DONT_KNOW_IF_OK
|
|
|
|
|
if (!dirhandle && len > 1 && *data== ':' && *(data+1) == '/') {
|
|
|
|
|
--len;
|
|
|
|
|
data++;
|
|
|
|
|
dirhandle = lastdirhandle;
|
|
|
|
|
} else if (dirhandle) lastdirhandle = dirhandle;
|
|
|
|
|
#endif
|
|
|
|
|
completition = build_path(nwpath, data, len, only_dir);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
XDPRINTF((5, 0, "conn_get_kpl_path %s", conn_get_nwpath_name(nwpath)));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!completition) completition = build_verz_name(nwpath, dirhandle);
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint16 un_date_2_nw(time_t time, uint8 *d)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
struct tm *s_tm=localtime(&time);
|
|
|
|
|
uint16 xdate=s_tm->tm_year - 80;
|
|
|
|
|
xdate <<= 4;
|
|
|
|
|
xdate |= s_tm->tm_mon+1;
|
|
|
|
|
xdate <<= 5;
|
|
|
|
|
xdate |= s_tm->tm_mday;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (d) U16_TO_BE16(xdate, d);
|
|
|
|
|
return(xdate);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
time_t nw_2_un_time(uint8 *d, uint8 *t)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
uint16 xdate = GET_BE16(d);
|
|
|
|
|
uint16 xtime = (t != (uint8*) NULL) ? GET_BE16(t) : 0;
|
|
|
|
|
|
|
|
|
|
int year = (xdate >> 9) + 80;
|
|
|
|
|
int month = (xdate >> 5) & 0x0F;
|
|
|
|
|
int day = xdate & 0x1f;
|
|
|
|
|
int hour = xtime >> 11;
|
|
|
|
|
int minu = (xtime >> 5) & 0x3f;
|
|
|
|
|
int sec = xtime & 0x1f;
|
|
|
|
|
struct tm s_tm;
|
|
|
|
|
s_tm.tm_year = year;
|
|
|
|
|
s_tm.tm_mon = month-1;
|
|
|
|
|
s_tm.tm_mday = day;
|
|
|
|
|
s_tm.tm_hour = hour;
|
|
|
|
|
s_tm.tm_min = minu;
|
|
|
|
|
s_tm.tm_sec = sec;
|
|
|
|
|
return(mktime(&s_tm));
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint16 un_time_2_nw(time_t time, uint8 *d)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
struct tm *s_tm=localtime(&time);
|
|
|
|
|
uint16 xdate=s_tm->tm_hour;
|
|
|
|
|
xdate <<= 6;
|
|
|
|
|
xdate |= s_tm->tm_min;
|
|
|
|
|
xdate <<= 5;
|
|
|
|
|
xdate |= (s_tm->tm_sec / 2);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (d) U16_TO_BE16(xdate, d);
|
|
|
|
|
return(xdate);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int get_file_attrib(NW_FILE_INFO *f, struct stat *stb,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_PATH *nwpath)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0, "get_file_attrib of %s", conn_get_nwpath_name(nwpath) ));
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strncpy((char*)f->name, (char*)nwpath->fn, sizeof(f->name));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* Attribute */
|
|
|
|
|
/* 0x20 Archive Flag */
|
|
|
|
|
/* 0x80 Sharable */ /* TLINK (TCC 2.0) don't like it ???? */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#if 1
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (!strcmp((char*)nwpath->fn, "TURBOC.$LN")) f->attrib = 0x20;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
else f->attrib = 0x80;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#else
|
|
|
|
|
f->attrib = 0x20;
|
|
|
|
|
#endif
|
2011-11-13 00:38:55 +01:00
|
|
|
|
f->ext_attrib = 0;
|
|
|
|
|
un_date_2_nw(stb->st_mtime, f->create_date);
|
|
|
|
|
un_date_2_nw(stb->st_atime, f->acces_date );
|
|
|
|
|
un_date_2_nw(stb->st_mtime, f->modify_date);
|
|
|
|
|
un_time_2_nw(stb->st_mtime, f->modify_time);
|
|
|
|
|
U32_TO_BE32(stb->st_size, f->size);
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int get_dir_attrib(NW_DIR_INFO *d, struct stat *stb,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_PATH *nwpath)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0, "get_dir_attrib of %s", conn_get_nwpath_name(nwpath)));
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strncpy((char*)d->name, (char*)nwpath->fn, sizeof(d->name));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
d->attrib = 0x10; /* Verzeichnis */
|
|
|
|
|
d->ext_attrib = 0xff; /* effektive rights ?? */
|
|
|
|
|
|
|
|
|
|
un_date_2_nw(stb->st_mtime, d->create_date);
|
|
|
|
|
un_time_2_nw(stb->st_mtime, d->create_time);
|
|
|
|
|
|
|
|
|
|
U32_TO_BE32(1L, d->owner_id);
|
|
|
|
|
d->access_right_mask = 0;
|
|
|
|
|
d->reserved = 0;
|
|
|
|
|
U16_TO_BE16(0, d->next_search);
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static int do_delete_file(NW_PATH *nwpath, FUNC_SEARCH *fs)
|
|
|
|
|
{
|
|
|
|
|
char unname[256];
|
|
|
|
|
strcpy(unname, build_unix_name(nwpath, 0));
|
|
|
|
|
XDPRINTF((5,0,"DELETE FILE unname:%s:", unname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (get_volume_options(nwpath->volume, 1) & VOL_OPTION_IS_PIPE)
|
|
|
|
|
return(0); /* don't delete 'pipe commands' */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!unlink(unname)) return(0);
|
|
|
|
|
return(-0x8a); /* NO Delete Privileges */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_delete_datei(int dir_handle, uint8 *data, int len)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dir_handle, data, len, 0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (completition > -1) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
completition = func_search_entry(&nwpath, 0x6, do_delete_file, NULL);
|
|
|
|
|
if (completition < 0) return(completition);
|
|
|
|
|
else if (!completition) return(-0xff);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
static int do_set_file_info(NW_PATH *nwpath, FUNC_SEARCH *fs)
|
|
|
|
|
{
|
|
|
|
|
char unname[256];
|
|
|
|
|
NW_FILE_INFO *f=(NW_FILE_INFO*)fs->ubuf;
|
|
|
|
|
strcpy(unname, build_unix_name(nwpath, 0));
|
|
|
|
|
XDPRINTF((5,0,"set_file_info unname:%s:", unname));
|
|
|
|
|
if (get_volume_options(nwpath->volume, 1) & VOL_OPTION_IS_PIPE)
|
|
|
|
|
return(0); /* don't change 'pipe commands' */
|
|
|
|
|
else {
|
|
|
|
|
struct utimbuf ut;
|
|
|
|
|
ut.actime = ut.modtime = nw_2_un_time(f->modify_date, f->modify_time);
|
|
|
|
|
if (!utime(unname, &ut)) return(0);
|
|
|
|
|
}
|
|
|
|
|
return(-0x85); /* NO Privileges */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_set_file_information(int dir_handle, uint8 *data, int len,
|
|
|
|
|
int searchattrib, NW_FILE_INFO *f)
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dir_handle, data, len, 0);
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
FUNC_SEARCH fs;
|
|
|
|
|
fs.ubuf = (uint8*)f;
|
|
|
|
|
completition = func_search_entry(&nwpath, searchattrib,
|
|
|
|
|
do_set_file_info, &fs);
|
|
|
|
|
if (completition < 0) return(completition);
|
|
|
|
|
else if (!completition) return(-0xff);
|
|
|
|
|
}
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int nw_chmod_datei(int dir_handle, uint8 *data, int len, int modus)
|
|
|
|
|
{
|
|
|
|
|
char unname[256];
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
int completition=-0x9c;
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
#if DONT_KNOW_IF_OK
|
|
|
|
|
if (!dir_handle && len > 1 && *data== ':' && *(data+1) == '/') {
|
|
|
|
|
--len;
|
|
|
|
|
data++;
|
|
|
|
|
dir_handle = lastdirhandle;
|
|
|
|
|
} else if (dir_handle) lastdirhandle = dir_handle;
|
|
|
|
|
#endif
|
2011-11-13 00:38:55 +01:00
|
|
|
|
build_path(&nwpath, data, len, 0);
|
|
|
|
|
if (nwpath.fn[0] != '.') { /* Files with . at the beginning are not ok */
|
|
|
|
|
completition = build_verz_name(&nwpath, dir_handle);
|
|
|
|
|
}
|
|
|
|
|
if (completition < 0) return(completition);
|
|
|
|
|
strcpy(unname, build_unix_name(&nwpath, 2));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"CHMOD DATEI unname:%s:", unname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!stat(unname, &stbuff)){
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
return(-0x9c); /* wrong path */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int nw_mk_rd_dir(int dir_handle, uint8 *data, int len, int mode)
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dir_handle, data, len, !mode);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
char unname[256];
|
|
|
|
|
strcpy(unname, build_unix_name(&nwpath, 2));
|
|
|
|
|
#if 0
|
|
|
|
|
if (unname[0] && unname[1]) {
|
|
|
|
|
char *p=unname+strlen(unname)-1;
|
|
|
|
|
if (*p=='/') *p = '\0';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (mode) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"MKDIR dirname:%s:", unname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!mkdir(unname, 0777)) return(0);
|
|
|
|
|
completition = -0x84; /* No Create Priv.*/ /* -0x9f Direktory Aktive */
|
|
|
|
|
} else { /* rmdir */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"RMDIR dirname:%s:", unname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!rmdir(unname)) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_DIR *d=&(dirs[0]);
|
|
|
|
|
int j = 0;
|
|
|
|
|
while (j++ < (int)used_dirs){
|
|
|
|
|
if (d->inode == completition) d->inode = 0;
|
|
|
|
|
d++;
|
|
|
|
|
}
|
|
|
|
|
completition = 0;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else if (errno & EEXIST)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
completition = -0xa0; /* dir not empty */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
else completition = -0x8a; /* No privilegs */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int mv_file(int qdirhandle, uint8 *q, int qlen,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int zdirhandle, uint8 *z, int zlen)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
NW_PATH quellpath;
|
|
|
|
|
NW_PATH zielpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition=conn_get_kpl_path(&quellpath, qdirhandle, q, qlen, 0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!completition > -1){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
completition=conn_get_kpl_path(&zielpath, zdirhandle, z, zlen, 0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (completition > -1) {
|
|
|
|
|
if (get_volume_options(quellpath.volume, 1) &
|
|
|
|
|
VOL_OPTION_IS_PIPE ||
|
|
|
|
|
get_volume_options(zielpath.volume, 1) &
|
|
|
|
|
VOL_OPTION_IS_PIPE)
|
|
|
|
|
completition = -0x9c;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (completition > -1){
|
|
|
|
|
char unquelle[256];
|
|
|
|
|
char unziel[256];
|
|
|
|
|
strcpy(unquelle, build_unix_name(&quellpath,0));
|
|
|
|
|
strcpy(unziel, build_unix_name(&zielpath,0));
|
|
|
|
|
if (!link(unquelle, unziel)){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (unlink(unquelle)) {
|
|
|
|
|
completition=-0x9c;
|
|
|
|
|
/* TODO: here completition must be no pernmissions */
|
|
|
|
|
unlink(unziel);
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (errno & EEXIST)
|
|
|
|
|
completition=-0x91; /* allready exist */
|
|
|
|
|
else if (errno & EXDEV)
|
|
|
|
|
completition=-0x9a; /* cross devices */
|
|
|
|
|
else completition=-0x9c; /* wrong path */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int change_dir_entry( NW_DIR *dir, int volume,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *path, ino_t inode,
|
|
|
|
|
int driveletter, int is_temp,
|
|
|
|
|
int new_entry, int task)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
if (new_entry || (dir->inode && dir->is_temp != 2)) {
|
|
|
|
|
new_str(dir->path, path);
|
|
|
|
|
dir->inode = inode;
|
|
|
|
|
dir->volume = (uint8) volume;
|
|
|
|
|
dir->timestamp = time(NULL);
|
|
|
|
|
if (driveletter > -1) {
|
|
|
|
|
dir->drive = (uint8) driveletter;
|
|
|
|
|
dir->task = (uint8)task;
|
|
|
|
|
} else {
|
|
|
|
|
if (task < (int)dir->task) dir->task = (uint8) task;
|
|
|
|
|
}
|
|
|
|
|
if (is_temp > -1) dir->is_temp = (uint8) is_temp;
|
|
|
|
|
return(0);
|
|
|
|
|
} else {
|
|
|
|
|
if (!dir->inode) return(-0x9b); /* wrong handle */
|
|
|
|
|
else return(-0xfa); /* temp remap Error */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
void nw_exit_connect(void)
|
|
|
|
|
{
|
|
|
|
|
if (connect_is_init) {
|
|
|
|
|
init_file_module();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int nw_init_connect(void)
|
|
|
|
|
/* Cann be called when ever you want */
|
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *login = (uint8*) "LOGIN/";
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_PATH nwlogin;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
FILE *f= open_nw_ini();
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (f != (FILE*) NULL){
|
|
|
|
|
uint8 buff[256];
|
|
|
|
|
struct stat stbuff;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int what;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int k = MAX_NW_DIRS;
|
|
|
|
|
NW_DIR *d = &(dirs[0]);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)nwlogin.path, (char*)login);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
nwlogin.fn[0] = '\0';
|
|
|
|
|
nwlogin.volume = 0;
|
|
|
|
|
|
|
|
|
|
while (k--) {
|
|
|
|
|
if (connect_is_init) xfree(d->path);
|
|
|
|
|
else d->path = NULL;
|
|
|
|
|
d->volume = 0;
|
|
|
|
|
d->inode = 0;
|
|
|
|
|
d->is_temp = 0;
|
|
|
|
|
d->drive = 0;
|
|
|
|
|
d++;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
init_file_module();
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (connect_is_init) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
k = 0;
|
|
|
|
|
while (k++ < anz_dirhandles) free_dir_handle(k);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else connect_is_init++;
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
while (0 != (what = get_ini_entry(f, 0, buff, sizeof(buff)))) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (what == 10) { /* GID */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
default_gid = atoi((char*)buff);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else if (what == 11) { /* UID */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
default_uid = atoi((char*)buff);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else if (what == 103) { /* Debug */
|
2011-11-13 00:38:56 +01:00
|
|
|
|
nw_debug = atoi((char*)buff);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} /* while */
|
|
|
|
|
nw_init_volumes(f);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
fclose(f);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (used_nw_volumes < 1) {
|
2011-11-13 00:38:56 +01:00
|
|
|
|
errorp(1, "No Volumes defined. Look at ini file entry 1, Abort !!", NULL);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (stat(build_unix_name(&nwlogin, 0), &stbuff)) {
|
2011-11-13 00:38:56 +01:00
|
|
|
|
errorp(1, "Stat error LOGIN Directory, Abort !!",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
"UnixPath=`%s`", build_unix_name(&nwlogin, 0));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(-1);
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(void)change_dir_entry(&(dirs[0]), 0, nwlogin.path, stbuff.st_ino,
|
|
|
|
|
0, 0, 1, 0);
|
|
|
|
|
/* first Handle must be known und must not be temp */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* and has no Drive-Character */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
used_dirs = 1;
|
|
|
|
|
anz_dirhandles = 0;
|
|
|
|
|
return(0);
|
|
|
|
|
} else return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_free_handles(int task)
|
|
|
|
|
/*
|
|
|
|
|
* if task==0 then all is initialized
|
|
|
|
|
* else the temp handles of the actuell task and greater
|
|
|
|
|
* are deleted. I hope it is right. !??
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
if (!task) return(nw_init_connect());
|
|
|
|
|
else {
|
|
|
|
|
NW_DIR *d = &(dirs[0]);
|
|
|
|
|
int k = used_dirs;
|
|
|
|
|
while (k--) {
|
|
|
|
|
if (d->is_temp && d->task >= task) {
|
|
|
|
|
xfree(d->path);
|
|
|
|
|
d->volume = 0;
|
|
|
|
|
d->inode = 0;
|
|
|
|
|
d->is_temp = 0;
|
|
|
|
|
d->drive = 0;
|
|
|
|
|
}
|
|
|
|
|
d++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int insert_new_dir(NW_PATH *nwpath, int inode, int drive, int is_temp, int task)
|
|
|
|
|
{
|
|
|
|
|
int j = 0;
|
|
|
|
|
time_t lowtime = time(NULL);
|
|
|
|
|
int freehandle = 0;
|
|
|
|
|
int timedhandle = 0;
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
/* first look, whether drive is allready in use */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
for (j = 0; j < (int)used_dirs; j++) {
|
|
|
|
|
NW_DIR *d = &(dirs[j]);
|
|
|
|
|
if (d->inode && !is_temp && !d->is_temp && (int)d->drive == drive) {
|
|
|
|
|
(void)change_dir_entry(d, nwpath->volume, nwpath->path, inode, drive, is_temp, 1, task);
|
|
|
|
|
return(++j);
|
|
|
|
|
} else if (!d->inode) freehandle = j+1;
|
|
|
|
|
else if (d->is_temp && d->timestamp < lowtime) {
|
|
|
|
|
timedhandle = j+1;
|
|
|
|
|
lowtime = d->timestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!freehandle && used_dirs < MAX_NW_DIRS) freehandle = ++used_dirs;
|
|
|
|
|
if (!freehandle) freehandle = timedhandle;
|
|
|
|
|
if (freehandle){
|
|
|
|
|
(void)change_dir_entry(&(dirs[freehandle-1]),
|
|
|
|
|
nwpath->volume, nwpath->path, inode,
|
|
|
|
|
drive, is_temp, 1, task);
|
|
|
|
|
while (used_dirs > freehandle && !dirs[used_dirs-1].inode) used_dirs--;
|
|
|
|
|
return(freehandle);
|
|
|
|
|
} else return(-0x9d); /* no dir Handles */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_search(uint8 *info,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int dirhandle, int searchsequence,
|
|
|
|
|
int search_attrib, uint8 *data, int len)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
int completition= conn_get_kpl_path(&nwpath, dirhandle, data, len, 0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_search path:%s:, fn:%s:, completition:0x%x",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
nwpath.path, nwpath.fn, completition));
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
if (get_dir_entry(&nwpath,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
&searchsequence,
|
|
|
|
|
search_attrib,
|
|
|
|
|
&stbuff)){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#if 1
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if ( (stbuff.st_mode & S_IFMT) == S_IFDIR) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#else
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (search_attrib & 0x10) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#endif
|
2011-11-13 00:38:55 +01:00
|
|
|
|
get_dir_attrib((NW_DIR_INFO*)info, &stbuff,
|
|
|
|
|
&nwpath);
|
|
|
|
|
} else {
|
|
|
|
|
get_file_attrib((NW_FILE_INFO*)info, &stbuff,
|
|
|
|
|
&nwpath);
|
|
|
|
|
}
|
|
|
|
|
return(searchsequence);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else return(-0xff); /* not found */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else return(completition); /* wrong path */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_dir_search(uint8 *info,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int dirhandle, int searchsequence,
|
|
|
|
|
int search_attrib, uint8 *data, int len)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
|
|
|
|
int completition=-0x9c;
|
|
|
|
|
build_path(&nwpath, data, len, 0);
|
|
|
|
|
if (dirhandle > 0 && --dirhandle < anz_dirhandles){
|
|
|
|
|
DIR_HANDLE *dh = &(dir_handles[dirhandle]);
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
if (get_dh_entry(dh,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
nwpath.fn,
|
|
|
|
|
&searchsequence,
|
|
|
|
|
search_attrib,
|
|
|
|
|
&stbuff)){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#if 1
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if ( (stbuff.st_mode & S_IFMT) == S_IFDIR) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#else
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (search_attrib & 0x10) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#endif
|
2011-11-13 00:38:55 +01:00
|
|
|
|
get_dir_attrib((NW_DIR_INFO*)info, &stbuff,
|
|
|
|
|
&nwpath);
|
|
|
|
|
} else {
|
|
|
|
|
get_file_attrib((NW_FILE_INFO*)info, &stbuff,
|
|
|
|
|
&nwpath);
|
|
|
|
|
}
|
|
|
|
|
return(searchsequence);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else return(-0xff); /* not found */
|
|
|
|
|
} else return(completition); /* wrong path */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_alloc_dir_handle( int dir_handle, /* Suche ab Pfad dirhandle */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *data, /* zusaetzl. Pfad */
|
|
|
|
|
int len, /* L<>nge DATA */
|
|
|
|
|
int driveletter, /* A .. Z normal */
|
|
|
|
|
int is_temphandle, /* temporaeres Handle 1 */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* spez. temp Handle 2 */
|
|
|
|
|
int task) /* Prozess Task */
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int inode=conn_get_kpl_path(&nwpath, dir_handle, data, len, 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (inode > -1)
|
|
|
|
|
inode = insert_new_dir(&nwpath, inode, driveletter, is_temphandle, task);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"Allocate %shandle:%s, Handle=%d, drive=%d, result=0x%x",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(is_temphandle) ? "Temp" : "Perm", conn_get_nwpath_name(&nwpath),
|
|
|
|
|
dir_handle, driveletter, inode));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(inode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_open_dir_handle( int dir_handle,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *data, /* extra path */
|
|
|
|
|
int len, /* len of DATA */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
int *volume, /* Volume */
|
|
|
|
|
int *dir_id,
|
|
|
|
|
int *searchsequence)
|
|
|
|
|
|
|
|
|
|
/*
|
2011-11-13 00:38:55 +01:00
|
|
|
|
* Routine returns handle to use in searchroutines.
|
|
|
|
|
* RETURN=errcode ( <0 ) or ACCES Rights
|
2011-11-13 00:38:55 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dir_handle, data, len, 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (completition > -1) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"NW_OPEN_DIR: completition = 0x%x; nwpath= %s",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(int)completition, conn_get_nwpath_name(&nwpath) ));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
completition = new_dir_handle((ino_t)completition, &nwpath);
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
DIR_HANDLE *fh = &(dir_handles[completition-1]);
|
|
|
|
|
*volume = fh->volume;
|
|
|
|
|
*dir_id = completition;
|
|
|
|
|
*searchsequence = MAX_U16;
|
|
|
|
|
completition = 0xff; /* Alle Rechte */
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"NW_OPEN_DIR_2: completition = 0x%x",
|
2011-11-13 00:38:56 +01:00
|
|
|
|
completition));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else {
|
2011-11-13 00:38:56 +01:00
|
|
|
|
XDPRINTF((4,0,"NW_OPEN_DIR failed: completition = -0x%x", -completition));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_free_dir_handle(int dir_handle)
|
|
|
|
|
{
|
|
|
|
|
if (dir_handle && --dir_handle < (int)used_dirs) {
|
|
|
|
|
NW_DIR *d=&(dirs[dir_handle]);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (!d->inode) return(-0x9b); /* wrong handle */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
else {
|
|
|
|
|
d->inode = 0;
|
|
|
|
|
xfree(d->path);
|
|
|
|
|
}
|
|
|
|
|
return(0);
|
|
|
|
|
} else return(-0x9b); /* wrong handle */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_set_dir_handle(int targetdir, int dir_handle,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *data, int len, int task)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* targetdirs gets path of dirhandle + data */
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int inode = conn_get_kpl_path(&nwpath, dir_handle, data, len, 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (inode > -1){
|
|
|
|
|
if (targetdir > 0 && --targetdir < used_dirs
|
|
|
|
|
&& dirs[targetdir].is_temp != 2) { /* not a spez. temphandle */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"Change dhandle:%d -> `%s`", targetdir+1, conn_get_nwpath_name(&nwpath)));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(change_dir_entry(&dirs[targetdir], nwpath.volume, nwpath.path, inode, -1, -1, 0, task));
|
|
|
|
|
/* here the existing handle is only modified */
|
|
|
|
|
} else return(-0x9b); /* BAD DIR Handle */
|
|
|
|
|
}
|
|
|
|
|
return(inode); /* invalid PATH */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_get_directory_path(int dir_handle, uint8 *name)
|
|
|
|
|
{
|
|
|
|
|
int result = -0x9b;
|
|
|
|
|
name[0] = '\0';
|
|
|
|
|
if (dir_handle > 0 && --dir_handle < (int)used_dirs) {
|
|
|
|
|
int volume = dirs[dir_handle].volume;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (volume > -1 && volume < used_nw_volumes){
|
|
|
|
|
result=sprintf((char*)name, "%s:%s", nw_volumes[volume].sysname, dirs[dir_handle].path);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (name[result-1] == '/') name[--result] = '\0';
|
|
|
|
|
} else result = -0x98;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_get_directory_path:%s: Handle=%d, result=0x%x", name, dir_handle+1, result));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_get_vol_number(int dir_handle)
|
|
|
|
|
/* Get Volume Nummmer with Handle */
|
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int result = -0x9b; /* wrong handle */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (dir_handle > 0 && --dir_handle < (int)used_dirs) {
|
|
|
|
|
result = dirs[dir_handle].volume;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (result < 0 || result >= used_nw_volumes) result = -0x98; /* wrong volume */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_get_vol_number:0x%x: von Handle=%d", result, dir_handle+1));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int nw_get_eff_dir_rights(int dir_handle, uint8 *data, int len, int modus)
|
|
|
|
|
/* modus 0=only_dir, 1=dirs and files */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
char unname[256];
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dir_handle, data, len,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(modus) ? 0 : 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (completition < 0) return(completition);
|
|
|
|
|
strcpy(unname, build_unix_name(&nwpath, 0));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (stat(unname, &stbuff) ||
|
|
|
|
|
(!modus && (stbuff.st_mode & S_IFMT) != S_IFDIR) ) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
completition = -0x9c;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else completition=0xff; /* all rights */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(completition);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
int nw_creat_open_file(int dir_handle, uint8 *data, int len,
|
|
|
|
|
NW_FILE_INFO *info, int attrib, int access,
|
|
|
|
|
int creatmode)
|
|
|
|
|
/*
|
|
|
|
|
* creatmode: 0 = open | 1 = creat | 2 = creatnew & 4 == save handle
|
|
|
|
|
* attrib ??
|
|
|
|
|
* access: 0x1=read, 0x2=write
|
|
|
|
|
*/
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
NW_PATH nwpath;
|
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dir_handle, data, len, 0);
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
struct stat stbuff;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
completition=file_creat_open(nwpath.volume, (uint8*)build_unix_name(&nwpath, 0),
|
2011-11-13 00:38:56 +01:00
|
|
|
|
&stbuff, attrib, access, creatmode);
|
|
|
|
|
|
|
|
|
|
if (completition > -1)
|
|
|
|
|
get_file_attrib(info, &stbuff, &nwpath);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:56 +01:00
|
|
|
|
return(completition);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int s_nw_scan_dir_info(int dir_handle,
|
|
|
|
|
uint8 *data, int len, uint8 *subnr,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *subname, uint8 *subdatetime,
|
|
|
|
|
uint8 *owner, uint8 *wild)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
int volume;
|
|
|
|
|
int searchsequence;
|
|
|
|
|
int dir_id;
|
|
|
|
|
int rights = nw_open_dir_handle(dir_handle, data, len,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
&volume, &dir_id, &searchsequence);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
if (rights > -1) {
|
|
|
|
|
DIR_HANDLE *dh = &(dir_handles[dir_id-1]);
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
int searchsequence = MAX_U16;
|
|
|
|
|
uint16 dirsequenz = GET_BE16(subnr);
|
|
|
|
|
uint16 aktsequenz = 0;
|
|
|
|
|
uint8 dirname[256];
|
|
|
|
|
if (!dirsequenz) dirsequenz++;
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)dirname, (char*)wild);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"SCAN_DIR: rights = 0x%x, subnr = %d",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
(int)rights, (int)GET_BE16(subnr)));
|
|
|
|
|
|
|
|
|
|
if (*dirname) {
|
|
|
|
|
while ( get_dh_entry( dh,
|
|
|
|
|
dirname,
|
|
|
|
|
&searchsequence,
|
|
|
|
|
0x10,
|
|
|
|
|
&stbuff) ) {
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"SCAN_DIR: von %s, found %s:", dh->unixname, dirname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (++aktsequenz == dirsequenz) { /* actual found */
|
|
|
|
|
U16_TO_BE16(aktsequenz, subnr);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strncpy((char*)subname, (char*)dirname, 16);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
U32_TO_BE32(1L, owner); /* erstmal */
|
|
|
|
|
un_date_2_nw(stbuff.st_mtime, subdatetime);
|
|
|
|
|
un_time_2_nw(stbuff.st_mtime, subdatetime+2);
|
|
|
|
|
return(0xff);
|
|
|
|
|
}
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strcpy((char*)dirname, (char*)wild);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} /* while */
|
|
|
|
|
} else {
|
|
|
|
|
strcpy(dh->kpath, ".");
|
|
|
|
|
if (!stat(dh->unixname, &stbuff)) {
|
|
|
|
|
U16_TO_BE16(1, subnr);
|
|
|
|
|
memset(subname, 0, 16);
|
|
|
|
|
U32_TO_BE32(1L, owner);
|
|
|
|
|
un_date_2_nw(stbuff.st_mtime, subdatetime);
|
|
|
|
|
un_time_2_nw(stbuff.st_mtime, subdatetime+2);
|
|
|
|
|
return(0xff);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* return(-0x9c); NO MORE INFO */
|
|
|
|
|
return(-0xff);
|
|
|
|
|
}
|
|
|
|
|
return(rights);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nw_scan_dir_info(int dir_handle, uint8 *data, int len, uint8 *subnr,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *subname, uint8 *subdatetime, uint8 *owner)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
int k = len;
|
|
|
|
|
uint8 *p = data+len;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 dirname[256];
|
2011-11-13 00:38:56 +01:00
|
|
|
|
while (k) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 c = *--p;
|
|
|
|
|
if (c == '/' || c == '\\' || c == ':') {
|
|
|
|
|
p++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-11-13 00:38:56 +01:00
|
|
|
|
--k;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (len && k < len) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
strmaxcpy(dirname, p, len-k);
|
|
|
|
|
len = k;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else dirname[0] = '\0';
|
2011-11-13 00:38:56 +01:00
|
|
|
|
XDPRINTF((7, 0, "nw_scan_dir_info, dirname=`%s`, len=%d, k=%d",
|
|
|
|
|
dirname, len , k));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(s_nw_scan_dir_info(dir_handle, data, len, subnr,
|
|
|
|
|
subname, subdatetime, owner, dirname));
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
uint8 time[2];
|
|
|
|
|
uint8 date[2];
|
|
|
|
|
uint8 id[4];
|
|
|
|
|
} NW_FILE_DATES_INFO;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
uint8 subdir[4];
|
|
|
|
|
uint8 attributes[4]; /* 0x20,0,0,0 File */
|
|
|
|
|
uint8 uniqueid; /* 0 */
|
|
|
|
|
uint8 flags; /* 0x18 */
|
|
|
|
|
uint8 namespace; /* 0 */
|
|
|
|
|
uint8 namlen;
|
|
|
|
|
uint8 name[12];
|
|
|
|
|
NW_FILE_DATES_INFO created;
|
|
|
|
|
NW_FILE_DATES_INFO archived;
|
|
|
|
|
NW_FILE_DATES_INFO updated;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 size[4];
|
|
|
|
|
uint8 reserved_1[44];
|
|
|
|
|
uint8 inherited_rights_mask[2];
|
|
|
|
|
uint8 last_access_date[2];
|
|
|
|
|
uint8 reserved_2[28];
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} NW_DOS_FILE_INFO;
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
void xun_date_2_nw(time_t time, uint8 *d)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint16 i = un_date_2_nw(time, NULL);
|
|
|
|
|
memcpy(d, &i, 2);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
void xun_time_2_nw(time_t time, uint8 *d)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
uint16 i = un_time_2_nw(time, NULL);
|
|
|
|
|
memcpy(d, &i, 2);
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static void get_dos_file_attrib(NW_DOS_FILE_INFO *f,
|
|
|
|
|
struct stat *stb,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_PATH *nwpath)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
f->namlen=min(strlen((char*)nwpath->fn), 12);
|
|
|
|
|
strncpy((char*)f->name, (char*)nwpath->fn, f->namlen);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* Attribute */
|
|
|
|
|
/* 0x20 Archive Flag */
|
|
|
|
|
/* 0x80 Sharable */
|
|
|
|
|
f->attributes[0] = 0x20;
|
|
|
|
|
xun_date_2_nw(stb->st_mtime, f->created.date);
|
|
|
|
|
xun_time_2_nw(stb->st_mtime, f->created.time);
|
|
|
|
|
U32_TO_BE32(1, f->created.id);
|
|
|
|
|
memcpy(&(f->updated), &(f->created), sizeof(NW_DOS_FILE_INFO));
|
|
|
|
|
xun_date_2_nw(stb->st_atime, f->last_access_date);
|
|
|
|
|
memcpy(f->size, &(stb->st_size), 4);
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
uint8 subdir[4];
|
|
|
|
|
uint8 attributes[4]; /* 0x10,0,0,0 DIR */
|
|
|
|
|
uint8 uniqueid; /* 0 */
|
|
|
|
|
uint8 flags; /* 0x14 or 0x1c */
|
|
|
|
|
uint8 namespace; /* 0 */
|
|
|
|
|
uint8 namlen;
|
|
|
|
|
uint8 name[12];
|
|
|
|
|
NW_FILE_DATES_INFO created;
|
|
|
|
|
NW_FILE_DATES_INFO archived;
|
|
|
|
|
uint8 modify_time[2];
|
|
|
|
|
uint8 modify_date[2];
|
|
|
|
|
uint8 next_trustee[4];
|
|
|
|
|
uint8 reserved_1[48];
|
|
|
|
|
uint8 max_space[4];
|
|
|
|
|
uint8 inherited_rights_mask[2];
|
|
|
|
|
uint8 reserved_2[26];
|
|
|
|
|
} NW_DOS_DIR_INFO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void get_dos_dir_attrib(NW_DOS_DIR_INFO *f,
|
|
|
|
|
struct stat *stb,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_PATH *nwpath)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:56 +01:00
|
|
|
|
f->namlen=min(strlen((char*)nwpath->fn), 12);
|
|
|
|
|
strncpy((char*)f->name, (char*)nwpath->fn, f->namlen);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
f->attributes[0] = 0x10; /* Dir */
|
|
|
|
|
xun_date_2_nw(stb->st_mtime, f->created.date);
|
|
|
|
|
xun_time_2_nw(stb->st_mtime, f->created.time);
|
|
|
|
|
U32_TO_BE32(1, f->created.id);
|
|
|
|
|
xun_date_2_nw(stb->st_mtime, f->modify_date);
|
|
|
|
|
xun_time_2_nw(stb->st_mtime, f->modify_time);
|
|
|
|
|
U32_TO_BE32(MAX_U32, f->max_space);
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
uint8 searchsequence[4];
|
|
|
|
|
union {
|
|
|
|
|
NW_DOS_DIR_INFO d;
|
|
|
|
|
NW_DOS_FILE_INFO f;
|
|
|
|
|
} u;
|
|
|
|
|
} NW_SCAN_DIR_INFO;
|
|
|
|
|
|
|
|
|
|
int nw_scan_a_directory(uint8 *rdata,
|
|
|
|
|
int dirhandle,
|
|
|
|
|
uint8 *data,
|
|
|
|
|
int len,
|
|
|
|
|
int searchattrib,
|
|
|
|
|
uint32 searchbeg) /* 32 bit */
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dirhandle, data, len, 0);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_scan_a_directory path:%s:, fn:%s:, completition:0x%x",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
nwpath.path, nwpath.fn, completition));
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
int searchsequence = (searchbeg == MAX_U32) ? MAX_U16 : searchbeg;
|
|
|
|
|
if (get_dir_entry(&nwpath,
|
|
|
|
|
&searchsequence,
|
|
|
|
|
searchattrib,
|
|
|
|
|
&stbuff)){
|
|
|
|
|
|
|
|
|
|
NW_SCAN_DIR_INFO *scif = (NW_SCAN_DIR_INFO*)rdata;
|
|
|
|
|
memset(rdata, 0, sizeof(NW_SCAN_DIR_INFO));
|
|
|
|
|
U32_TO_BE32((uint32)searchsequence, scif->searchsequence);
|
|
|
|
|
|
|
|
|
|
if ( (stbuff.st_mode & S_IFMT) == S_IFDIR) {
|
|
|
|
|
get_dos_dir_attrib(&(scif->u.d), &stbuff,
|
|
|
|
|
&nwpath);
|
|
|
|
|
} else {
|
|
|
|
|
get_dos_file_attrib(&(scif->u.f), &stbuff,
|
|
|
|
|
&nwpath);
|
|
|
|
|
}
|
|
|
|
|
return(sizeof(NW_SCAN_DIR_INFO));
|
|
|
|
|
} else return(-0xff); /* not found */
|
|
|
|
|
} else return(completition); /* wrong path */
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int nw_scan_a_root_dir(uint8 *rdata,
|
|
|
|
|
int dirhandle)
|
|
|
|
|
{
|
|
|
|
|
NW_PATH nwpath;
|
|
|
|
|
uint8 data[2];
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int completition = conn_get_kpl_path(&nwpath, dirhandle, data, 0, 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_scan_a_directory_2 path:%s:, fn:%s:, completition:0x%x",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
nwpath.path, nwpath.fn, completition));
|
|
|
|
|
if (completition > -1) {
|
|
|
|
|
struct stat stbuff;
|
|
|
|
|
if (!stat(build_unix_name(&nwpath, 2), &stbuff)) {
|
|
|
|
|
NW_DOS_DIR_INFO *d=(NW_DOS_DIR_INFO*)rdata;
|
|
|
|
|
memset(rdata, 0, sizeof(NW_DOS_DIR_INFO));
|
|
|
|
|
get_dos_dir_attrib(d, &stbuff, &nwpath);
|
|
|
|
|
return(sizeof(NW_DOS_DIR_INFO));
|
|
|
|
|
} else return(-0xff); /* not found */
|
|
|
|
|
} else return(completition); /* wrong path */
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* <======================================================================> */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
/* minimal queue handling to enable very simple printing */
|
|
|
|
|
/* qick and dirty !!!!!!!!!!!!!!! */
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
#define MAX_JOBS 5 /* max. open queue jobs for one connection */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static int anz_jobs=0;
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
uint32 fhandle;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int old_job; /* is old structure */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
union {
|
|
|
|
|
QUEUE_JOB n;
|
|
|
|
|
QUEUE_JOB_OLD o;
|
|
|
|
|
} q;
|
|
|
|
|
} INT_QUEUE_JOB;
|
|
|
|
|
|
|
|
|
|
INT_QUEUE_JOB *queue_jobs[MAX_JOBS];
|
|
|
|
|
|
|
|
|
|
static INT_QUEUE_JOB *give_new_queue_job(int old_job)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
|
|
|
|
int k=-1;
|
|
|
|
|
while (++k < anz_jobs) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
INT_QUEUE_JOB *p=queue_jobs[k];
|
|
|
|
|
if (!p->fhandle) { /* free slot */
|
|
|
|
|
memset(p, 0, sizeof(INT_QUEUE_JOB));
|
|
|
|
|
p->old_job = old_job;
|
|
|
|
|
if (old_job)
|
|
|
|
|
p->q.o.job_id[0] = k+1;
|
|
|
|
|
else
|
|
|
|
|
p->q.n.job_id[0] = k+1;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(p);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
if (anz_jobs < MAX_JOBS) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
INT_QUEUE_JOB **pp=&(queue_jobs[anz_jobs++]);
|
|
|
|
|
*pp = (INT_QUEUE_JOB *) xmalloc(sizeof(INT_QUEUE_JOB));
|
|
|
|
|
memset(*pp, 0, sizeof(INT_QUEUE_JOB));
|
|
|
|
|
(*pp)->old_job = old_job;
|
|
|
|
|
if (old_job)
|
|
|
|
|
(*pp)->q.o.job_id[0] = anz_jobs;
|
|
|
|
|
else
|
|
|
|
|
(*pp)->q.n.job_id[0] = anz_jobs;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
return(*pp);
|
|
|
|
|
}
|
|
|
|
|
return(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void free_queue_job(int q_id)
|
|
|
|
|
{
|
|
|
|
|
if (q_id > 0 && q_id <= anz_jobs) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
INT_QUEUE_JOB **pp=&(queue_jobs[q_id-1]);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint32 fhandle = (*pp)->fhandle;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (fhandle > 0) nw_close_datei(fhandle, 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (q_id == anz_jobs) {
|
|
|
|
|
xfree(*pp);
|
|
|
|
|
--anz_jobs;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else (*pp)->fhandle=0L;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
static void set_entry_time(uint8 *entry_time)
|
2011-11-13 00:38:55 +01:00
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
struct tm *s_tm;
|
|
|
|
|
time_t timer;
|
|
|
|
|
time(&timer);
|
|
|
|
|
s_tm = localtime(&timer);
|
|
|
|
|
entry_time[0] = (uint8) s_tm->tm_year;
|
|
|
|
|
entry_time[1] = (uint8) s_tm->tm_mon+1;
|
|
|
|
|
entry_time[2] = (uint8) s_tm->tm_mday;
|
|
|
|
|
entry_time[3] = (uint8) s_tm->tm_hour;
|
|
|
|
|
entry_time[4] = (uint8) s_tm->tm_min;
|
|
|
|
|
entry_time[5] = (uint8) s_tm->tm_sec;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:56 +01:00
|
|
|
|
static int create_queue_file(uint8 *job_file_name,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint32 q_id,
|
|
|
|
|
int jo_id,
|
|
|
|
|
int connection,
|
|
|
|
|
uint8 *dirname,
|
|
|
|
|
int dir_nam_len,
|
|
|
|
|
uint8 *job_bez)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int result;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
NW_FILE_INFO fnfo;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
*job_file_name
|
2011-11-13 00:38:56 +01:00
|
|
|
|
= sprintf((char*)job_file_name+1, "%07lX%d.%03d", q_id, jo_id, connection);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
|
|
|
|
result=nw_alloc_dir_handle(0, dirname, dir_nam_len, 99, 2, 1);
|
|
|
|
|
if (result > -1)
|
|
|
|
|
result = nw_creat_open_file(result, job_file_name+1,
|
|
|
|
|
(int) *job_file_name,
|
2011-11-13 00:38:56 +01:00
|
|
|
|
&fnfo, 0x6, 0x6, 1 | 4);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"creat queue file bez=`%s` handle=%d",
|
2011-11-13 00:38:55 +01:00
|
|
|
|
job_bez, result));
|
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int nw_creat_queue(int connection, uint8 *queue_id, uint8 *queue_job,
|
|
|
|
|
uint8 *dirname, int dir_nam_len, int old_call)
|
|
|
|
|
{
|
|
|
|
|
INT_QUEUE_JOB *jo = give_new_queue_job(old_call);
|
|
|
|
|
uint32 q_id = GET_BE32(queue_id);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int result = -0xff;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"NW_CREAT_Q:dlen=%d, dirname=%s", dir_nam_len, dirname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (NULL != jo) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int jo_id = 0;
|
|
|
|
|
if (jo->old_job) {
|
|
|
|
|
jo_id = (int) jo->q.o.job_id[0];
|
|
|
|
|
memcpy(&(jo->q.o), queue_job, sizeof(QUEUE_JOB_OLD));
|
|
|
|
|
jo->q.o.job_id[0] = (uint8) jo_id;
|
|
|
|
|
jo->q.o.client_connection = (uint8)connection;
|
|
|
|
|
jo->q.o.client_task = (uint8)0xfe; /* ?? */
|
|
|
|
|
U32_TO_BE32(1, jo->q.o.client_id); /* SU */
|
|
|
|
|
set_entry_time(jo->q.o.job_entry_time);
|
|
|
|
|
jo->q.o.job_typ[0] = 0x0; /* 0xd0;*/
|
|
|
|
|
jo->q.o.job_typ[1] = 0x0;
|
|
|
|
|
jo->q.o.job_position = 0x1;
|
|
|
|
|
jo->q.o.job_control_flags |= 0x20;
|
|
|
|
|
|
|
|
|
|
result = create_queue_file(jo->q.o.job_file_name,
|
|
|
|
|
q_id, jo_id, connection,
|
|
|
|
|
dirname, dir_nam_len,
|
|
|
|
|
jo->q.o.job_bez);
|
|
|
|
|
|
|
|
|
|
if (result > -1) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
jo->fhandle = (uint32) result;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
U16_TO_BE16(0, jo->q.o.job_file_handle);
|
|
|
|
|
U32_TO_BE32(jo->fhandle, jo->q.o.job_file_handle+2);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
result = 0;
|
|
|
|
|
}
|
|
|
|
|
jo->q.o.server_station = 0;
|
|
|
|
|
jo->q.o.server_task = 0;
|
|
|
|
|
U32_TO_BE32(0, jo->q.o.server_id);
|
|
|
|
|
if (!result) memcpy(queue_job, &(jo->q.o), sizeof(QUEUE_JOB_OLD));
|
|
|
|
|
} else {
|
|
|
|
|
jo_id = (int) jo->q.n.job_id[0];
|
|
|
|
|
memcpy(&(jo->q.n), queue_job, sizeof(QUEUE_JOB));
|
|
|
|
|
jo->q.n.job_id[0] = (uint8) jo_id;
|
|
|
|
|
|
|
|
|
|
U16_TO_BE16(0xffff, jo->q.n.record_in_use);
|
|
|
|
|
U32_TO_BE32(0x0, jo->q.n.record_previous);
|
|
|
|
|
U32_TO_BE32(0x0, jo->q.n.record_next);
|
|
|
|
|
memset(jo->q.n.client_connection, 0, 4);
|
|
|
|
|
jo->q.n.client_connection[0] = (uint8)connection;
|
|
|
|
|
memset(jo->q.n.client_task, 0, 4);
|
|
|
|
|
jo->q.n.client_task[0] = (uint8)0xfe; /* ?? */
|
|
|
|
|
U32_TO_BE32(1, jo->q.n.client_id); /* SU */
|
|
|
|
|
set_entry_time(jo->q.n.job_entry_time);
|
|
|
|
|
|
|
|
|
|
jo->q.n.job_typ[0] = 0x0; /* 0xd0;*/
|
|
|
|
|
jo->q.n.job_typ[1] = 0x0;
|
|
|
|
|
jo->q.n.job_position[0] = 0x1;
|
|
|
|
|
jo->q.n.job_position[1] = 0x0;
|
|
|
|
|
jo->q.n.job_control_flags[0] |= 0x20;
|
|
|
|
|
jo->q.n.job_control_flags[1] = 0x0;
|
|
|
|
|
|
|
|
|
|
result = create_queue_file(jo->q.n.job_file_name,
|
|
|
|
|
q_id, jo_id, connection,
|
|
|
|
|
dirname, dir_nam_len,
|
|
|
|
|
jo->q.n.job_bez);
|
|
|
|
|
|
|
|
|
|
if (result > -1) {
|
|
|
|
|
jo->fhandle = (uint32) result;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
U32_TO_BE32(jo->fhandle, jo->q.n.job_file_handle);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
result = 0;
|
|
|
|
|
}
|
|
|
|
|
U32_TO_BE32(0, jo->q.n.server_station);
|
|
|
|
|
U32_TO_BE32(0, jo->q.n.server_task);
|
|
|
|
|
U32_TO_BE32(0, jo->q.n.server_id);
|
|
|
|
|
if (!result) memcpy(queue_job, &(jo->q.n), sizeof(QUEUE_JOB));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (result) free_queue_job(jo_id);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int nw_close_file_queue(uint8 *queue_id,
|
|
|
|
|
uint8 *job_id,
|
2011-11-13 00:38:55 +01:00
|
|
|
|
uint8 *prc, int prc_len)
|
|
|
|
|
{
|
2011-11-13 00:38:55 +01:00
|
|
|
|
int result = -0xff;
|
|
|
|
|
int jo_id = (int) *job_id; /* ever only the first byte */
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_close_file_queue JOB=%d", jo_id));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (jo_id > 0 && jo_id <= anz_jobs){
|
2011-11-13 00:38:55 +01:00
|
|
|
|
INT_QUEUE_JOB *jo=queue_jobs[jo_id-1];
|
|
|
|
|
int fhandle = (int)jo->fhandle;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
char unixname[300];
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strmaxcpy((uint8*)unixname, (uint8*)file_get_unix_name(fhandle), sizeof(unixname)-1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((5,0,"nw_close_file_queue fhandle=%d", fhandle));
|
2011-11-13 00:38:56 +01:00
|
|
|
|
if (*unixname) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
char printcommand[256];
|
|
|
|
|
FILE *f=NULL;
|
2011-11-13 00:38:56 +01:00
|
|
|
|
strmaxcpy((uint8*)printcommand, prc, prc_len);
|
2011-11-13 00:38:56 +01:00
|
|
|
|
nw_close_datei(fhandle, 1);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
jo->fhandle = 0L;
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (NULL != (f = fopen(unixname, "r"))) {
|
|
|
|
|
int is_ok = 0;
|
|
|
|
|
FILE *fout = popen(printcommand, "w");
|
|
|
|
|
if (fout) {
|
|
|
|
|
char buff[1024];
|
|
|
|
|
int k;
|
|
|
|
|
is_ok++;
|
|
|
|
|
while ((k = fread(buff, 1, sizeof(buff), f)) > 0) {
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (1 != fwrite(buff, k, 1, fout)) {
|
|
|
|
|
XDPRINTF((1,0,"Cannot write to pipe `%s`", printcommand));
|
|
|
|
|
is_ok=0;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
}
|
|
|
|
|
pclose(fout);
|
|
|
|
|
} else
|
2011-11-13 00:38:55 +01:00
|
|
|
|
XDPRINTF((1,0,"Cannot open pipe `%s`", printcommand));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
fclose(f);
|
2011-11-13 00:38:55 +01:00
|
|
|
|
if (is_ok) {
|
|
|
|
|
unlink(unixname);
|
|
|
|
|
result=0;
|
|
|
|
|
}
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else XDPRINTF((1,0,"Cannot open queue-file `%s`", unixname));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
} else
|
2011-11-13 00:38:56 +01:00
|
|
|
|
XDPRINTF((2,0,"fhandle=%d NOT OK !", fhandle));
|
2011-11-13 00:38:55 +01:00
|
|
|
|
free_queue_job(jo_id);
|
|
|
|
|
}
|
|
|
|
|
return(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|