[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;
|
---|
| 93 | char fullname[261];
|
---|
| 94 | char fname[261];
|
---|
| 95 | } smbwrp_file;
|
---|
| 96 |
|
---|
| 97 | typedef struct smbwrp_fileinfo
|
---|
| 98 | {
|
---|
| 99 | unsigned long long size;
|
---|
| 100 | unsigned long attr;
|
---|
| 101 | unsigned long ctime;
|
---|
| 102 | unsigned long mtime;
|
---|
| 103 | unsigned long atime;
|
---|
| 104 | int easize;
|
---|
| 105 | char fname[261];
|
---|
| 106 | } smbwrp_fileinfo;
|
---|
| 107 |
|
---|
| 108 | typedef struct smbwrp_fileseek
|
---|
| 109 | {
|
---|
| 110 | int whence;
|
---|
| 111 | long offset;
|
---|
| 112 | unsigned long result;
|
---|
| 113 | } smbwrp_fileseek;
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | #ifndef INCL_DOS
|
---|
| 117 | typedef struct _FSALLOCATE /* fsalloc */
|
---|
| 118 | {
|
---|
| 119 | unsigned long idFileSystem;
|
---|
| 120 | unsigned long cSectorUnit;
|
---|
| 121 | unsigned long cUnit;
|
---|
| 122 | unsigned long cUnitAvail;
|
---|
| 123 | unsigned short cbSector;
|
---|
| 124 | } FSALLOCATE;
|
---|
| 125 | #endif
|
---|
| 126 |
|
---|
[497] | 127 | struct DirectoryCache;
|
---|
| 128 |
|
---|
[145] | 129 | typedef struct _Resource
|
---|
| 130 | {
|
---|
| 131 | int rootlevel;
|
---|
| 132 | smbwrp_server srv;
|
---|
| 133 | char logfile[_MAX_PATH + 1];
|
---|
| 134 | char loglevel;
|
---|
| 135 | int easupport;
|
---|
| 136 | int krb5support;
|
---|
[518] | 137 | int cachetimeout;
|
---|
| 138 | int cachedepth;
|
---|
[497] | 139 | struct DirectoryCache *pdc;
|
---|
[145] | 140 | } Resource;
|
---|
[5] | 141 |
|
---|
[145] | 142 | typedef struct _Connection
|
---|
| 143 | {
|
---|
| 144 | Resource *pRes;
|
---|
| 145 | cli_state* cli;
|
---|
| 146 | smbwrp_file file;
|
---|
| 147 | } Connection;
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | typedef struct filelist_state
|
---|
| 151 | {
|
---|
| 152 | unsigned long pipe;
|
---|
| 153 | char * data;
|
---|
| 154 | int datalen;
|
---|
| 155 | int bufferlen;
|
---|
| 156 | void ( * _System add_dir_entry)(void * st);
|
---|
| 157 | char mask[ _MAX_PATH];
|
---|
| 158 | char dir[ _MAX_PATH];
|
---|
| 159 | char dir_mask[ _MAX_PATH];
|
---|
| 160 | smbwrp_fileinfo finfo;
|
---|
| 161 | Connection* pConn;
|
---|
| 162 | void *plist;
|
---|
| 163 | unsigned long ulAttribute;
|
---|
[497] | 164 | const char *fullpath;
|
---|
[145] | 165 | } filelist_state;
|
---|
| 166 |
|
---|
[5] | 167 | #pragma pack()
|
---|
| 168 |
|
---|
| 169 | int _System smbwrp_getclisize(void);
|
---|
| 170 | int _System smbwrp_init(void);
|
---|
[145] | 171 | int _System smbwrp_connect(Resource * pRes, cli_state **);
|
---|
| 172 | void _System smbwrp_disconnect(Resource * pRes, cli_state *);
|
---|
[5] | 173 | int _System smbwrp_open(cli_state * cli, smbwrp_file * file);
|
---|
| 174 | int _System smbwrp_read(cli_state * cli, smbwrp_file * file, void *buf, unsigned long count, unsigned long * result);
|
---|
| 175 | int _System smbwrp_write(cli_state * cli, smbwrp_file * file, void *buf, unsigned long count, unsigned long * result);
|
---|
| 176 | int _System smbwrp_lseek(cli_state * cli, smbwrp_file * file, int whence, long long offset);
|
---|
| 177 | int _System smbwrp_close(cli_state * cli, smbwrp_file * file);
|
---|
| 178 | int _System smbwrp_setattr(cli_state * cli, smbwrp_fileinfo *finfo);
|
---|
[75] | 179 | int _System smbwrp_getattr(smbwrp_server *srv, cli_state * cli, smbwrp_fileinfo *finfo);
|
---|
[5] | 180 | int _System smbwrp_fgetattr(cli_state * cli, smbwrp_file *file, smbwrp_fileinfo *finfo);
|
---|
| 181 | int _System smbwrp_filelist(smbwrp_server *srv, cli_state * cli, filelist_state * state);
|
---|
| 182 | int _System smbwrp_rename(cli_state * cli, char *oldname, char *newname);
|
---|
[75] | 183 | int _System smbwrp_chdir(smbwrp_server *srv, cli_state * cli, char *fname);
|
---|
[5] | 184 | int _System smbwrp_mkdir(cli_state * cli, char *fname);
|
---|
| 185 | int _System smbwrp_rmdir(cli_state * cli, char *fname);
|
---|
| 186 | int _System smbwrp_unlink(cli_state * cli, const char *fname);
|
---|
| 187 | int _System smbwrp_setfilesize(cli_state * cli, smbwrp_file * file, long long newsize);
|
---|
| 188 | int _System smbwrp_setea(cli_state * cli, char *fname, char * name, unsigned char * value, int size);
|
---|
| 189 | int _System smbwrp_fsetea(cli_state * cli, smbwrp_file *file, char * name, unsigned char * value, int size);
|
---|
| 190 | int _System smbwrp_listea(cli_state * cli, char *fname, void * buffer, unsigned long size);
|
---|
| 191 | int _System smbwrp_flistea(cli_state * cli, smbwrp_file *file, void * buffer, unsigned long size);
|
---|
| 192 | int _System smbwrp_dskattr(cli_state * cli, FSALLOCATE *pfsa);
|
---|
| 193 |
|
---|
[497] | 194 | /* Directory cache helpers. */
|
---|
| 195 | int dircache_create(struct DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries);
|
---|
| 196 | void dircache_delete(struct DirectoryCache *pdc);
|
---|
| 197 |
|
---|
| 198 | typedef void FNADDDIRENTRY(const char*, smbwrp_fileinfo *, const char *, void *);
|
---|
| 199 | typedef FNADDDIRENTRY *PFNADDDIRENTRY;
|
---|
| 200 |
|
---|
| 201 | /* Note: dircache_list_files or dircache_write_begin construct the directory path
|
---|
| 202 | * using information in the filelist_state structure.
|
---|
| 203 | */
|
---|
| 204 | int dircache_list_files(PFNADDDIRENTRY fn,
|
---|
| 205 | filelist_state *state,
|
---|
| 206 | int *ptotal_received);
|
---|
| 207 |
|
---|
| 208 | void *dircache_write_begin(filelist_state *state,
|
---|
| 209 | int cFiles);
|
---|
| 210 | void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo);
|
---|
| 211 | void dircache_write_end(void *dircachectx);
|
---|
| 212 |
|
---|
| 213 | void dircache_invalidate(const char *path,
|
---|
| 214 | struct DirectoryCache *pdc,
|
---|
| 215 | int fParent);
|
---|
| 216 |
|
---|
| 217 | int dircache_find_path(struct DirectoryCache *pdc,
|
---|
| 218 | const char *path,
|
---|
| 219 | smbwrp_fileinfo *finfo,
|
---|
| 220 | unsigned long *pulAge);
|
---|
| 221 |
|
---|
| 222 | /* Prototype the debug log helper. */
|
---|
| 223 | void debuglocal(int level, const char * fmt, ...);
|
---|
| 224 |
|
---|
[520] | 225 | void smbwrp_initthread(void);
|
---|
| 226 |
|
---|
[5] | 227 | #endif /* _SMBWRP_H */
|
---|