[151] | 1 | /*
|
---|
| 2 | Netdrive Samba client plugin
|
---|
| 3 | samba library wrappers
|
---|
| 4 | Copyright (C) netlabs.org 2003-2008
|
---|
| 5 |
|
---|
| 6 | This program is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | This program is distributed in the hope that it will be useful,
|
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | You should have received a copy of the GNU General Public License
|
---|
| 17 | along with this program; if not, write to the Free Software
|
---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[5] | 21 | #ifndef _SMBWRP_H
|
---|
| 22 | #define _SMBWRP_H
|
---|
| 23 |
|
---|
| 24 | #if !defined (O_RDONLY)
|
---|
| 25 | #define O_ACCMODE 0x03 /* mask */
|
---|
| 26 | #define O_RDONLY 0x00
|
---|
| 27 | #define O_WRONLY 0x01
|
---|
| 28 | #define O_RDWR 0x02
|
---|
| 29 | #define O_NONBLOCK 0x04
|
---|
| 30 | #define O_APPEND 0x08
|
---|
| 31 | #define O_TEXT 0x10
|
---|
| 32 |
|
---|
| 33 | #define O_BINARY 0x0100
|
---|
| 34 | #define O_CREAT 0x0200
|
---|
| 35 | #define O_TRUNC 0x0400
|
---|
| 36 | #define O_EXCL 0x0800
|
---|
| 37 | #define O_SYNC 0x2000
|
---|
| 38 | #define O_NOCTTY 0x4000
|
---|
| 39 | #define O_SIZE 0x8000
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | #if !defined (DENY_NONE)
|
---|
| 43 | /* deny modes */
|
---|
| 44 | #define DENY_DOS 0
|
---|
| 45 | #define DENY_ALL 1
|
---|
| 46 | #define DENY_WRITE 2
|
---|
| 47 | #define DENY_READ 3
|
---|
| 48 | #define DENY_NONE 4
|
---|
| 49 | #define DENY_FCB 7
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | /* these define the attribute byte as seen by DOS */
|
---|
| 54 | #ifndef aRONLY
|
---|
| 55 | #define aRONLY (1L<<0) /* 0x01 */
|
---|
| 56 | #define aHIDDEN (1L<<1) /* 0x02 */
|
---|
| 57 | #define aSYSTEM (1L<<2) /* 0x04 */
|
---|
| 58 | #define aVOLID (1L<<3) /* 0x08 */
|
---|
| 59 | #define aDIR (1L<<4) /* 0x10 */
|
---|
| 60 | #define aARCH (1L<<5) /* 0x20 */
|
---|
| 61 | #endif
|
---|
| 62 |
|
---|
| 63 | #pragma pack(1)
|
---|
| 64 |
|
---|
| 65 | #ifdef CLI_BUFFER_SIZE
|
---|
| 66 | typedef struct cli_state cli_state;
|
---|
| 67 | #else
|
---|
| 68 | typedef unsigned long cli_state;
|
---|
| 69 | #endif
|
---|
| 70 |
|
---|
| 71 | #define CAP_NOPATHINFO2 0x01000000
|
---|
| 72 |
|
---|
| 73 | typedef struct smbwrp_server
|
---|
| 74 | {
|
---|
| 75 | char server_name[256];
|
---|
| 76 | char share_name[256];
|
---|
| 77 | char workgroup[256];
|
---|
| 78 | char username[256];
|
---|
| 79 | char password[256];
|
---|
| 80 | char master[256];
|
---|
| 81 | int ifmastergroup;
|
---|
| 82 | int no_pathinfo2;
|
---|
| 83 | } smbwrp_server;
|
---|
| 84 |
|
---|
| 85 | typedef struct smbwrp_file
|
---|
| 86 | {
|
---|
| 87 | int fd;
|
---|
| 88 | unsigned long long offset;
|
---|
| 89 | int openmode;
|
---|
| 90 | int openattr;
|
---|
| 91 | int denymode;
|
---|
| 92 | unsigned long mtime;
|
---|
[818] | 93 | unsigned long ctime;
|
---|
| 94 | int updatetime;
|
---|
| 95 | // 0 = time is not updated upon file close
|
---|
| 96 | // 1 = modified time is updated to current time
|
---|
| 97 | // 2 = create and modified time are updated according local file
|
---|
[5] | 98 | char fullname[261];
|
---|
| 99 | char fname[261];
|
---|
| 100 | } smbwrp_file;
|
---|
| 101 |
|
---|
| 102 | typedef struct smbwrp_fileinfo
|
---|
| 103 | {
|
---|
| 104 | unsigned long long size;
|
---|
| 105 | unsigned long attr;
|
---|
| 106 | unsigned long ctime;
|
---|
| 107 | unsigned long mtime;
|
---|
| 108 | unsigned long atime;
|
---|
| 109 | int easize;
|
---|
[472] | 110 | char fname[261];
|
---|
[5] | 111 | } smbwrp_fileinfo;
|
---|
| 112 |
|
---|
| 113 | typedef struct smbwrp_fileseek
|
---|
| 114 | {
|
---|
| 115 | int whence;
|
---|
| 116 | long offset;
|
---|
| 117 | unsigned long result;
|
---|
| 118 | } smbwrp_fileseek;
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | #ifndef INCL_DOS
|
---|
| 122 | typedef struct _FSALLOCATE /* fsalloc */
|
---|
| 123 | {
|
---|
| 124 | unsigned long idFileSystem;
|
---|
| 125 | unsigned long cSectorUnit;
|
---|
| 126 | unsigned long cUnit;
|
---|
| 127 | unsigned long cUnitAvail;
|
---|
| 128 | unsigned short cbSector;
|
---|
| 129 | } FSALLOCATE;
|
---|
| 130 | #endif
|
---|
| 131 |
|
---|
[499] | 132 | struct DirectoryCache;
|
---|
| 133 |
|
---|
[145] | 134 | typedef struct _Resource
|
---|
| 135 | {
|
---|
| 136 | int rootlevel;
|
---|
| 137 | smbwrp_server srv;
|
---|
| 138 | char logfile[_MAX_PATH + 1];
|
---|
| 139 | char loglevel;
|
---|
| 140 | int easupport;
|
---|
| 141 | int krb5support;
|
---|
[931] | 142 | int ntlmv1support;
|
---|
[1006] | 143 | int encryptionsupport;
|
---|
[519] | 144 | int cachetimeout;
|
---|
| 145 | int cachedepth;
|
---|
[499] | 146 | struct DirectoryCache *pdc;
|
---|
[145] | 147 | } Resource;
|
---|
[5] | 148 |
|
---|
[145] | 149 | typedef struct _Connection
|
---|
| 150 | {
|
---|
| 151 | Resource *pRes;
|
---|
| 152 | cli_state* cli;
|
---|
| 153 | smbwrp_file file;
|
---|
| 154 | } Connection;
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | typedef struct filelist_state
|
---|
| 158 | {
|
---|
| 159 | unsigned long pipe;
|
---|
| 160 | char * data;
|
---|
| 161 | int datalen;
|
---|
| 162 | int bufferlen;
|
---|
| 163 | void ( * _System add_dir_entry)(void * st);
|
---|
| 164 | char mask[ _MAX_PATH];
|
---|
| 165 | char dir[ _MAX_PATH];
|
---|
| 166 | char dir_mask[ _MAX_PATH];
|
---|
| 167 | smbwrp_fileinfo finfo;
|
---|
| 168 | Connection* pConn;
|
---|
| 169 | void *plist;
|
---|
| 170 | unsigned long ulAttribute;
|
---|
[499] | 171 | const char *fullpath;
|
---|
[145] | 172 | } filelist_state;
|
---|
| 173 |
|
---|
[5] | 174 | #pragma pack()
|
---|
| 175 |
|
---|
| 176 | int _System smbwrp_getclisize(void);
|
---|
| 177 | int _System smbwrp_init(void);
|
---|
[145] | 178 | int _System smbwrp_connect(Resource * pRes, cli_state **);
|
---|
| 179 | void _System smbwrp_disconnect(Resource * pRes, cli_state *);
|
---|
[5] | 180 | int _System smbwrp_open(cli_state * cli, smbwrp_file * file);
|
---|
| 181 | int _System smbwrp_read(cli_state * cli, smbwrp_file * file, void *buf, unsigned long count, unsigned long * result);
|
---|
| 182 | int _System smbwrp_write(cli_state * cli, smbwrp_file * file, void *buf, unsigned long count, unsigned long * result);
|
---|
| 183 | int _System smbwrp_lseek(cli_state * cli, smbwrp_file * file, int whence, long long offset);
|
---|
| 184 | int _System smbwrp_close(cli_state * cli, smbwrp_file * file);
|
---|
| 185 | int _System smbwrp_setattr(cli_state * cli, smbwrp_fileinfo *finfo);
|
---|
[75] | 186 | int _System smbwrp_getattr(smbwrp_server *srv, cli_state * cli, smbwrp_fileinfo *finfo);
|
---|
[5] | 187 | int _System smbwrp_fgetattr(cli_state * cli, smbwrp_file *file, smbwrp_fileinfo *finfo);
|
---|
| 188 | int _System smbwrp_filelist(smbwrp_server *srv, cli_state * cli, filelist_state * state);
|
---|
| 189 | int _System smbwrp_rename(cli_state * cli, char *oldname, char *newname);
|
---|
[75] | 190 | int _System smbwrp_chdir(smbwrp_server *srv, cli_state * cli, char *fname);
|
---|
[5] | 191 | int _System smbwrp_mkdir(cli_state * cli, char *fname);
|
---|
| 192 | int _System smbwrp_rmdir(cli_state * cli, char *fname);
|
---|
| 193 | int _System smbwrp_unlink(cli_state * cli, const char *fname);
|
---|
| 194 | int _System smbwrp_setfilesize(cli_state * cli, smbwrp_file * file, long long newsize);
|
---|
| 195 | int _System smbwrp_setea(cli_state * cli, char *fname, char * name, unsigned char * value, int size);
|
---|
| 196 | int _System smbwrp_fsetea(cli_state * cli, smbwrp_file *file, char * name, unsigned char * value, int size);
|
---|
| 197 | int _System smbwrp_listea(cli_state * cli, char *fname, void * buffer, unsigned long size);
|
---|
| 198 | int _System smbwrp_flistea(cli_state * cli, smbwrp_file *file, void * buffer, unsigned long size);
|
---|
| 199 | int _System smbwrp_dskattr(cli_state * cli, FSALLOCATE *pfsa);
|
---|
[933] | 200 | int _System smbwrp_echo(cli_state * cli);
|
---|
[5] | 201 |
|
---|
[499] | 202 | /* Directory cache helpers. */
|
---|
| 203 | int dircache_create(struct DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries);
|
---|
| 204 | void dircache_delete(struct DirectoryCache *pdc);
|
---|
| 205 |
|
---|
| 206 | typedef void FNADDDIRENTRY(const char*, smbwrp_fileinfo *, const char *, void *);
|
---|
| 207 | typedef FNADDDIRENTRY *PFNADDDIRENTRY;
|
---|
| 208 |
|
---|
| 209 | /* Note: dircache_list_files or dircache_write_begin construct the directory path
|
---|
| 210 | * using information in the filelist_state structure.
|
---|
| 211 | */
|
---|
| 212 | int dircache_list_files(PFNADDDIRENTRY fn,
|
---|
| 213 | filelist_state *state,
|
---|
| 214 | int *ptotal_received);
|
---|
| 215 |
|
---|
| 216 | void *dircache_write_begin(filelist_state *state,
|
---|
| 217 | int cFiles);
|
---|
| 218 | void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo);
|
---|
| 219 | void dircache_write_end(void *dircachectx);
|
---|
| 220 |
|
---|
| 221 | void dircache_invalidate(const char *path,
|
---|
| 222 | struct DirectoryCache *pdc,
|
---|
| 223 | int fParent);
|
---|
| 224 |
|
---|
| 225 | int dircache_find_path(struct DirectoryCache *pdc,
|
---|
| 226 | const char *path,
|
---|
| 227 | smbwrp_fileinfo *finfo,
|
---|
| 228 | unsigned long *pulAge);
|
---|
| 229 |
|
---|
| 230 | /* Prototype the debug log helper. */
|
---|
| 231 | void debuglocal(int level, const char * fmt, ...);
|
---|
| 232 |
|
---|
[521] | 233 | void smbwrp_initthread(void);
|
---|
| 234 |
|
---|
[5] | 235 | #endif /* _SMBWRP_H */
|
---|