urr...
lib/set_uid.o smbd/dfree.o smbd/dir.o smbd/password.o \
smbd/conn.o smbd/fileio.o \
smbd/ipc.o smbd/lanman.o smbd/mangle.o smbd/negprot.o \
- smbd/message.o smbd/nttrans.o smbd/pipes.o smbd/predict.o \
+ smbd/message.o smbd/nttrans.o smbd/pipes.o \
smbd/$(QUOTAOBJS) smbd/reply.o smbd/ssl.o smbd/trans2.o \
smbd/uid.o smbd/dosmode.o smbd/filename.o smbd/open.o \
smbd/close.o smbd/blocking.o smbd/process.o smbd/oplock.o \
void set_socket_options(int fd, char *options);
void close_sockets(void);
ssize_t write_socket(int fd, char *buf, size_t len);
+int write_data_outstanding(int fd, unsigned int time_out);
+int read_data_outstanding(int fd, unsigned int time_out);
ssize_t read_udp_socket(int fd, char *buf, size_t len);
ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt,
unsigned int time_out);
SMB_DEV_T dev, SMB_INO_T inode);
BOOL unlock_share_entry(connection_struct *conn,
SMB_DEV_T dev, SMB_INO_T inode);
+BOOL lock_share_entry_fsp(files_struct *fsp);
+BOOL unlock_share_entry_fsp(files_struct *fsp);
int get_share_modes(connection_struct *conn,
SMB_DEV_T dev, SMB_INO_T inode,
share_mode_entry **shares);
uint32 status_printqueue(connection_struct *conn,const vuser_key *key,
int snum,int status);
void load_printers(void);
+void print_open_file(files_struct *fsp,connection_struct *conn,char *fname);
/*The following definitions come from profile/profile.c */
BOOL readwrite_pipe(pipes_struct * p, char *data, int len,
char **rdata, int *rlen, BOOL *pipe_outstanding);
ssize_t write_pipe(pipes_struct * p, char *data, size_t n);
-int read_pipe(pipes_struct * p, char *data, int n);
+int read_pipe(pipes_struct * p, char *data, int min_len, int max_len);
/*The following definitions come from rpc_server/srv_pipe_hnd.c */
BOOL pass_oem_change(const char *user,
const uchar * lmdata, const uchar * lmhash,
const uchar * ntdata, const uchar * nthash);
-BOOL change_oem_password(struct smb_passwd *smbpw, UNISTR2 * new_passwd,
- BOOL unicode, BOOL override);
BOOL update_smbpassword_file(const char *user, const char *password);
/*The following definitions come from smbd/close.c */
/*The following definitions come from smbd/files.c */
files_struct *file_new(void );
-file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf);
-file_fd_struct *fd_get_new(void);
void file_close_conn(connection_struct *conn);
void file_init(void);
void file_close_user(int vuid);
files_struct *file_find_di_next(files_struct *start_fsp);
files_struct *file_find_print(void);
void file_sync_all(connection_struct *conn);
-void fd_ptr_free(file_fd_struct *fd_ptr);
void file_free(files_struct *fsp);
files_struct *file_fsp(char *buf, int where);
void file_chain_reset(void);
/*The following definitions come from smbd/open.c */
-void fd_add_to_uid_cache(file_fd_struct *fd_ptr, uid_t u);
-uint16 fd_attempt_close(files_struct *fsp, int *err_ret);
+void fd_close(files_struct *fsp, int *err_ret);
void open_file_shared(files_struct *fsp,connection_struct *conn,char *fname,int share_mode,int ofun,
mode_t mode,int oplock_request, int *Access,int *action);
int open_file_stat(files_struct *fsp,connection_struct *conn,
int reply_pipe_read_and_X(char *inbuf, char *outbuf, int length, int bufsize);
int reply_pipe_close(connection_struct * conn, char *inbuf, char *outbuf);
-/*The following definitions come from smbd/predict.c */
-
-ssize_t read_predict(files_struct *fsp, int fd,SMB_OFF_T offset,char *buf,char **ptr,size_t num);
-void do_read_prediction(connection_struct *conn);
-void invalidate_read_prediction(int fd);
-
/*The following definitions come from smbd/process.c */
BOOL push_oplock_pending_smb_message(char *buf, int msg_len);
char *data;
} write_cache;
-/*
- * Structure used to indirect fd's from the files_struct.
- * Needed as POSIX locking is based on file and process, not
- * file descriptor and process.
- */
-
-typedef struct file_fd_struct
-{
- struct file_fd_struct *next, *prev;
- uint16 ref_count;
- uint16 uid_cache_count;
- uid_t uid_users_cache[10];
- SMB_DEV_T dev;
- SMB_INO_T inode;
- int fd;
- int fd_readonly;
- int fd_writeonly;
- int real_open_flags;
- BOOL delete_on_close;
-} file_fd_struct;
-
typedef struct files_struct
{
struct files_struct *next, *prev;
int fnum;
struct connection_struct *conn;
- file_fd_struct *fd_ptr;
+ int fd;
+ SMB_DEV_T dev;
+ SMB_INO_T inode;
+ BOOL delete_on_close;
SMB_OFF_T pos;
SMB_OFF_T size;
mode_t mode;
} connection_struct;
+typedef struct
+{
+ uint32 pid;
+ uint16 vuid;
+
+}
+vuser_key;
+
+struct current_user
+{
+ connection_struct *conn;
+ vuser_key key;
+ uid_t uid;
+ gid_t gid;
+ int ngroups;
+ gid_t *groups;
+};
+
+/*
+ * Reasons for cache flush.
+ */
+
+#define NUM_FLUSH_REASONS 8 /* Keep this in sync with the enum below. */
+enum flush_reason_enum
+{ SEEK_FLUSH, READ_FLUSH, WRITE_FLUSH, READRAW_FLUSH,
+ OPLOCK_RELEASE_FLUSH, CLOSE_FLUSH, SYNC_FLUSH, SIZECHANGE_FLUSH
+};
+
+/* Defines for the sent_oplock_break field above. */
+#define NO_BREAK_SENT 0
+#define EXCLUSIVE_BREAK_SENT 1
+#define LEVEL_II_BREAK_SENT 2
+
/* Domain controller authentication protocol info */
struct dcinfo
{
uchar md4pw[16]; /* md4(machine password) */
};
-
enum
{ LPQ_QUEUED, LPQ_PAUSED, LPQ_SPOOLING, LPQ_PRINTING };
#include "nt_printing.h"
-typedef struct
-{
- uint32 pid;
- uint16 vuid;
-
-}
-vuser_key;
-
struct use_info
{
BOOL connected;
char *domain;
};
-#include "ntdomain.h"
-
-typedef struct
-{
- uid_t uid; /* uid of a validated user */
- gid_t gid; /* gid of a validated user */
-
- fstring requested_name; /* user name from the client */
- fstring name; /* unix user name of a validated user */
- fstring real_name; /* to store real name from password file - simeon */
- BOOL guest;
-
- /* following groups stuff added by ih */
- /* This groups info is needed for when we become_user() for this uid */
- int n_groups;
- gid_t *groups;
-
- NET_USER_INFO_3 usr;
-
-} user_struct;
-
-struct current_user
-{
- connection_struct *conn;
- vuser_key key;
- uid_t uid;
- gid_t gid;
- int ngroups;
- gid_t *groups;
-};
-
-/*
- * Reasons for cache flush.
- */
-
-#define NUM_FLUSH_REASONS 8 /* Keep this in sync with the enum below. */
-enum flush_reason_enum
-{ SEEK_FLUSH, READ_FLUSH, WRITE_FLUSH, READRAW_FLUSH,
- OPLOCK_RELEASE_FLUSH, CLOSE_FLUSH, SYNC_FLUSH, SIZECHANGE_FLUSH
-};
-
-/* Defines for the sent_oplock_break field above. */
-#define NO_BREAK_SENT 0
-#define EXCLUSIVE_BREAK_SENT 1
-#define LEVEL_II_BREAK_SENT 2
-
/* A netbios name structure. */
struct nmb_name
{
};
-#include "dfs.h"
-
-/*
- * Size of new password account encoding string. DO NOT CHANGE.
- */
-
-#define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
-
-/*
- Do you want session setups at user level security with a invalid
- password to be rejected or allowed in as guest? WinNT rejects them
- but it can be a pain as it means "net view" needs to use a password
-
- You have 3 choices in the setting of map_to_guest:
-
- "NEVER_MAP_TO_GUEST" means session setups with an invalid password
- are rejected. This is the default.
-
- "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
- are rejected, unless the username does not exist, in which case it
- is treated as a guest login
-
- "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
- are treated as a guest login
-
- Note that map_to_guest only has an effect in user or server
- level security.
-*/
-
-#define NEVER_MAP_TO_GUEST 0
-#define MAP_TO_GUEST_ON_BAD_USER 1
-#define MAP_TO_GUEST_ON_BAD_PASSWORD 2
-
/* associate bit field or enumeration field with a string */
struct field_info
{
} CREDS_SUBST;
-#include "rpc_creds.h"
-
struct ntdom_info
{
unsigned char usr_sess_key[16]; /* Current user session key. */
}
policy_cache;
-#include "client.h"
+#include "ntdomain.h"
+
+typedef struct
+{
+ uid_t uid; /* uid of a validated user */
+ gid_t gid; /* gid of a validated user */
+
+ fstring requested_name; /* user name from the client */
+ fstring name; /* unix user name of a validated user */
+ fstring real_name; /* to store real name from password file - simeon */
+ BOOL guest;
+
+ /* following groups stuff added by ih */
+ /* This groups info is needed for when we become_user() for this uid */
+ int n_groups;
+ gid_t *groups;
+
+ NET_USER_INFO_3 usr;
+
+} user_struct;
+
#include "rpcclient.h"
+#include "rpc_creds.h"
+
+#include "client.h"
+
+
+/*
+ * Size of new password account encoding string. DO NOT CHANGE.
+ */
+
+#define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
+
+/*
+ Do you want session setups at user level security with a invalid
+ password to be rejected or allowed in as guest? WinNT rejects them
+ but it can be a pain as it means "net view" needs to use a password
+
+ You have 3 choices in the setting of map_to_guest:
+
+ "NEVER_MAP_TO_GUEST" means session setups with an invalid password
+ are rejected. This is the default.
+
+ "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
+ are rejected, unless the username does not exist, in which case it
+ is treated as a guest login
+
+ "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
+ are treated as a guest login
+
+ Note that map_to_guest only has an effect in user or server
+ level security.
+*/
+
+#define NEVER_MAP_TO_GUEST 0
+#define MAP_TO_GUEST_ON_BAD_USER 1
+#define MAP_TO_GUEST_ON_BAD_PASSWORD 2
#endif /* _SMB_H */
{
if (!lp_locking(SNUM(fsp->conn))) return;
- brl_close(fsp->fd_ptr->dev, fsp->fd_ptr->inode,
+ brl_close(fsp->dev, fsp->inode,
getpid(), fsp->conn->cnum, fsp->fnum);
}
if (!lp_locking(snum) || !lp_strict_locking(snum))
return(False);
- return !brl_locktest(fsp->fd_ptr->dev, fsp->fd_ptr->inode,
+ return !brl_locktest(fsp->dev, fsp->inode,
global_smbpid, getpid(), conn->cnum,
offset, count, lock_type);
}
lock_type, (double)offset, (double)count, fsp->fsp_name ));
if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
- ok = brl_lock(fsp->fd_ptr->dev, fsp->fd_ptr->inode, fsp->fnum,
+ ok = brl_lock(fsp->dev, fsp->inode, fsp->fnum,
global_smbpid, getpid(), conn->cnum,
offset, count,
lock_type);
(double)offset, (double)count, fsp->fsp_name ));
if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
- ok = brl_unlock(fsp->fd_ptr->dev, fsp->fd_ptr->inode, fsp->fnum,
+ ok = brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
global_smbpid, getpid(), conn->cnum,
offset, count);
}
}
static TDB_DATA locking_key_fsp(files_struct *fsp)
{
- return locking_key(fsp->fd_ptr->dev, fsp->fd_ptr->inode);
+ return locking_key(fsp->dev, fsp->inode);
}
/*******************************************************************
return tdb_unlockchain(tdb, locking_key(dev, inode)) == 0;
}
+
+/*******************************************************************
+ Lock a hash bucket entry. use a fsp for convenience
+******************************************************************/
+BOOL lock_share_entry_fsp(files_struct *fsp)
+{
+ return tdb_lockchain(tdb, locking_key(fsp->dev, fsp->inode)) == 0;
+}
+
+/*******************************************************************
+ Unlock a hash bucket entry.
+******************************************************************/
+BOOL unlock_share_entry_fsp(files_struct *fsp)
+{
+ return tdb_unlockchain(tdb, locking_key(fsp->dev, fsp->inode)) == 0;
+}
+
/*******************************************************************
Get all share mode entries for a dev/inode pair.
********************************************************************/
shares[i].share_mode == fsp->share_mode &&
memcmp(&shares[i].time,
&fsp->open_time,sizeof(struct timeval)) == 0) {
- mod_fn(&shares[i], fsp->fd_ptr->dev, fsp->fd_ptr->inode, param);
+ mod_fn(&shares[i], fsp->dev, fsp->inode, param);
need_store=1;
}
}
lpq_reset(snum);
}
-static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
-
-
-/*******************************************************************
-process time fields
-********************************************************************/
-static time_t EntryTime(fstring tok[], int ptr, int count, int minimum)
-{
- time_t jobtime,jobtime1;
-
- jobtime = time(NULL); /* default case: take current time */
- if (count >= minimum) {
- struct tm *t;
- int i, day, hour, min, sec;
- char *c;
-
- for (i=0; i<13; i++) if (!strncmp(tok[ptr], Months[i],3)) break; /* Find month */
- if (i<12) {
- t = localtime(&jobtime);
- day = atoi(tok[ptr+1]);
- c=(char *)(tok[ptr+2]);
- *(c+2)=0;
- hour = atoi(c);
- *(c+5)=0;
- min = atoi(c+3);
- if(*(c+6) != 0)sec = atoi(c+6);
- else sec=0;
-
- if ((t->tm_mon < i)||
- ((t->tm_mon == i)&&
- ((t->tm_mday < day)||
- ((t->tm_mday == day)&&
- (t->tm_hour*60+t->tm_min < hour*60+min)))))
- t->tm_year--; /* last year's print job */
-
- t->tm_mon = i;
- t->tm_mday = day;
- t->tm_hour = hour;
- t->tm_min = min;
- t->tm_sec = sec;
- jobtime1 = mktime(t);
- if (jobtime1 != (time_t)-1)
- jobtime = jobtime1;
- }
- }
- return jobtime;
-}
-
-
-/****************************************************************************
-parse a lpq line
-
-here is an example of lpq output under bsd
-
-Warning: no daemon present
-Rank Owner Job Files Total Size
-1st tridge 148 README 8096 bytes
-
-here is an example of lpq output under osf/1
-
-Warning: no daemon present
-Rank Pri Owner Job Files Total Size
-1st 0 tridge 148 README 8096 bytes
-
-
-<allan@umich.edu> June 30, 1998.
-Modified to handle file names with spaces, like the parse_lpq_lprng code
-further below.
-****************************************************************************/
-static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
-{
-#ifdef OSF1
-#define RANKTOK 0
-#define PRIOTOK 1
-#define USERTOK 2
-#define JOBTOK 3
-#define FILETOK 4
-#define TOTALTOK (count - 2)
-#define NTOK 6
-#define MAXTOK 128
-#else /* OSF1 */
-#define RANKTOK 0
-#define USERTOK 1
-#define JOBTOK 2
-#define FILETOK 3
-#define TOTALTOK (count - 2)
-#define NTOK 5
-#define MAXTOK 128
-#endif /* OSF1 */
-
- char *tok[MAXTOK];
- int count = 0;
- pstring line2;
-
- pstrcpy(line2,line);
-
-#ifdef OSF1
- {
- size_t length;
- length = strlen(line2);
- if (line2[length-3] == ':')
- return(False);
- }
-#endif /* OSF1 */
-
- tok[0] = strtok(line2," \t");
- count++;
-
- while (((tok[count] = strtok(NULL," \t")) != NULL) && (count < MAXTOK)) {
- count++;
- }
-
- /* we must get at least NTOK tokens */
- if (count < NTOK)
- return(False);
-
- /* the Job and Total columns must be integer */
- if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False);
-
- buf->job = atoi(tok[JOBTOK]);
- buf->size = atoi(tok[TOTALTOK]);
- buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
- buf->time = time(NULL);
- StrnCpy(buf->user,tok[USERTOK],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[FILETOK],sizeof(buf->file)-1);
-
- if ((FILETOK + 1) != TOTALTOK) {
- int bufsize;
- int i;
-
- bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
-
- for (i = (FILETOK + 1); i < TOTALTOK; i++) {
- safe_strcat(buf->file," ",bufsize);
- safe_strcat(buf->file,tok[i],bufsize - 1);
- bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
- if (bufsize <= 0) {
- break;
- }
- }
- /* Ensure null termination. */
- buf->file[sizeof(buf->file)-1] = '\0';
- }
-
-#ifdef PRIOTOK
- buf->priority = atoi(tok[PRIOTOK]);
-#else
- buf->priority = 1;
-#endif
- return(True);
-}
-
-/*
-<magnus@hum.auc.dk>
-LPRng_time modifies the current date by inserting the hour and minute from
-the lpq output. The lpq time looks like "23:15:07"
-
-<allan@umich.edu> June 30, 1998.
-Modified to work with the re-written parse_lpq_lprng routine.
-*/
-static time_t LPRng_time(char *time_string)
-{
- time_t jobtime;
- struct tm *t;
-
- jobtime = time(NULL); /* default case: take current time */
- t = localtime(&jobtime);
- t->tm_hour = atoi(time_string);
- t->tm_min = atoi(time_string+3);
- t->tm_sec = atoi(time_string+6);
- jobtime = mktime(t);
-
- return jobtime;
-}
-
-
-/****************************************************************************
- parse a lprng lpq line
- <allan@umich.edu> June 30, 1998.
- Re-wrote this to handle file names with spaces, multiple file names on one
- lpq line, etc;
-****************************************************************************/
-static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
-{
-#define LPRNG_RANKTOK 0
-#define LPRNG_USERTOK 1
-#define LPRNG_PRIOTOK 2
-#define LPRNG_JOBTOK 3
-#define LPRNG_FILETOK 4
-#define LPRNG_TOTALTOK (num_tok - 2)
-#define LPRNG_TIMETOK (num_tok - 1)
-#define LPRNG_NTOK 7
-#define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
-
- char *tokarr[LPRNG_MAXTOK];
- char *cptr;
- int num_tok = 0;
- pstring line2;
-
- pstrcpy(line2,line);
- tokarr[0] = strtok(line2," \t");
- num_tok++;
- while (((tokarr[num_tok] = strtok(NULL," \t")) != NULL)
- && (num_tok < LPRNG_MAXTOK)) {
- num_tok++;
- }
-
- /* We must get at least LPRNG_NTOK tokens. */
- if (num_tok < LPRNG_NTOK) {
- return(False);
- }
-
- if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
- return(False);
- }
-
- buf->job = atoi(tokarr[LPRNG_JOBTOK]);
- buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
-
- if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
- buf->status = LPQ_PRINTING;
- } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
- buf->status = LPQ_QUEUED;
- } else {
- buf->status = LPQ_PAUSED;
- }
-
- buf->priority = *tokarr[LPRNG_PRIOTOK] -'A';
-
- buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
-
- StrnCpy(buf->user,tokarr[LPRNG_USERTOK],sizeof(buf->user)-1);
-
- /* The '@hostname' prevents windows from displaying the printing icon
- * for the current user on the taskbar. Plop in a null.
- */
-
- if ((cptr = strchr(buf->user,'@')) != NULL) {
- *cptr = '\0';
- }
-
- StrnCpy(buf->file,tokarr[LPRNG_FILETOK],sizeof(buf->file)-1);
-
- if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
- int bufsize;
- int i;
-
- bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
-
- for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) {
- safe_strcat(buf->file," ",bufsize);
- safe_strcat(buf->file,tokarr[i],bufsize - 1);
- bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
- if (bufsize <= 0) {
- break;
- }
- }
- /* Ensure null termination. */
- buf->file[sizeof(buf->file)-1] = '\0';
- }
-
- return(True);
-}
-
-
-
-/*******************************************************************
-parse lpq on an aix system
-
-Queue Dev Status Job Files User PP % Blks Cp Rnk
-------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
-lazer lazer READY
-lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
- QUEUED 538 C.ps root@IEDVB 124 1 2
- QUEUED 539 E.ps root@IEDVB 28 1 3
- QUEUED 540 L.ps root@IEDVB 172 1 4
- QUEUED 541 P.ps root@IEDVB 22 1 5
-********************************************************************/
-static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
-{
- fstring tok[11];
- int count=0;
-
- /* handle the case of "(standard input)" as a filename */
- pstring_sub(line,"standard input","STDIN");
- all_string_sub(line,"(","\"",0);
- all_string_sub(line,")","\"",0);
-
- for (count=0;
- count<10 &&
- next_token(&line,tok[count],NULL, sizeof(tok[count]));
- count++) ;
-
- /* we must get 6 tokens */
- if (count < 10)
- {
- if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0)))
- {
- /* the 2nd and 5th columns must be integer */
- if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) return(False);
- buf->size = atoi(tok[4]) * 1024;
- /* if the fname contains a space then use STDIN */
- if (strchr(tok[2],' '))
- fstrcpy(tok[2],"STDIN");
-
- /* only take the last part of the filename */
- {
- fstring tmp;
- char *p = strrchr(tok[2],'/');
- if (p)
- {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[2],tmp);
- }
- }
-
-
- buf->job = atoi(tok[1]);
- buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
- buf->priority = 0;
- buf->time = time(NULL);
- StrnCpy(buf->user,tok[3],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[2],sizeof(buf->file)-1);
- }
- else
- {
- DEBUG(6,("parse_lpq_aix count=%d\n", count));
- return(False);
- }
- }
- else
- {
- /* the 4th and 9th columns must be integer */
- if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) return(False);
- buf->size = atoi(tok[8]) * 1024;
- /* if the fname contains a space then use STDIN */
- if (strchr(tok[4],' '))
- fstrcpy(tok[4],"STDIN");
-
- /* only take the last part of the filename */
- {
- fstring tmp;
- char *p = strrchr(tok[4],'/');
- if (p)
- {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[4],tmp);
- }
- }
-
-
- buf->job = atoi(tok[3]);
- buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
- buf->priority = 0;
- buf->time = time(NULL);
- StrnCpy(buf->user,tok[5],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[4],sizeof(buf->file)-1);
- }
-
-
- return(True);
-}
-
-
-/****************************************************************************
-parse a lpq line
-here is an example of lpq output under hpux; note there's no space after -o !
-$> lpstat -oljplus
-ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
- util.c 125697 bytes
- server.c 110712 bytes
-ljplus-2154 user priority 0 Jan 19 08:14 from client
- (standard input) 7551 bytes
-****************************************************************************/
-static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first)
-{
- /* must read two lines to process, therefore keep some values static */
- static BOOL header_line_ok=False, base_prio_reset=False;
- static fstring jobuser;
- static int jobid;
- static int jobprio;
- static time_t jobtime;
- static int jobstat=LPQ_QUEUED;
- /* to store minimum priority to print, lpstat command should be invoked
- with -p option first, to work */
- static int base_prio;
-
- int count;
- char htab = '\011';
- fstring tok[12];
-
- /* If a line begins with a horizontal TAB, it is a subline type */
-
- if (line[0] == htab) { /* subline */
- /* check if it contains the base priority */
- if (!strncmp(line,"\tfence priority : ",18)) {
- base_prio=atoi(&line[18]);
- DEBUG(4, ("fence priority set at %d\n", base_prio));
- }
- if (!header_line_ok) return (False); /* incorrect header line */
- /* handle the case of "(standard input)" as a filename */
- pstring_sub(line,"standard input","STDIN");
- all_string_sub(line,"(","\"",0);
- all_string_sub(line,")","\"",0);
-
- for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
- /* we must get 2 tokens */
- if (count < 2) return(False);
-
- /* the 2nd column must be integer */
- if (!isdigit((int)*tok[1])) return(False);
-
- /* if the fname contains a space then use STDIN */
- if (strchr(tok[0],' '))
- fstrcpy(tok[0],"STDIN");
-
- buf->size = atoi(tok[1]);
- StrnCpy(buf->file,tok[0],sizeof(buf->file)-1);
-
- /* fill things from header line */
- buf->time = jobtime;
- buf->job = jobid;
- buf->status = jobstat;
- buf->priority = jobprio;
- StrnCpy(buf->user,jobuser,sizeof(buf->user)-1);
-
- return(True);
- }
- else { /* header line */
- header_line_ok=False; /* reset it */
- if (first) {
- if (!base_prio_reset) {
- base_prio=0; /* reset it */
- base_prio_reset=True;
- }
- }
- else if (base_prio) base_prio_reset=False;
-
- /* handle the dash in the job id */
- pstring_sub(line,"-"," ");
-
- for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
-
- /* we must get 8 tokens */
- if (count < 8) return(False);
-
- /* first token must be printer name (cannot check ?) */
- /* the 2nd, 5th & 7th column must be integer */
- if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False);
- jobid = atoi(tok[1]);
- StrnCpy(jobuser,tok[2],sizeof(buf->user)-1);
- jobprio = atoi(tok[4]);
-
- /* process time */
- jobtime=EntryTime(tok, 5, count, 8);
- if (jobprio < base_prio) {
- jobstat = LPQ_PAUSED;
- DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n", jobid, jobprio, base_prio, jobstat));
- }
- else {
- jobstat = LPQ_QUEUED;
- if ((count >8) && (((strequal(tok[8],"on")) ||
- ((strequal(tok[8],"from")) &&
- ((count > 10)&&(strequal(tok[10],"on")))))))
- jobstat = LPQ_PRINTING;
- }
-
- header_line_ok=True; /* information is correct */
- return(False); /* need subline info to include into queuelist */
- }
-}
-
-
-/****************************************************************************
-parse a lpstat line
-
-here is an example of "lpstat -o dcslw" output under sysv
-
-dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
-dcslw-897 tridge 4712 Dec 20 10:30:30 being held
-
-****************************************************************************/
-static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first)
-{
- fstring tok[9];
- int count=0;
- char *p;
-
- /*
- * Handle the dash in the job id, but make sure that we skip over
- * the printer name in case we have a dash in that.
- * Patch from Dom.Mitchell@palmerharvey.co.uk.
- */
-
- /*
- * Move to the first space.
- */
- for (p = line ; !isspace(*p) && *p; p++)
- ;
-
- /*
- * Back up until the last '-' character or
- * start of line.
- */
- for (; (p >= line) && (*p != '-'); p--)
- ;
-
- if((p >= line) && (*p == '-'))
- *p = ' ';
-
- for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++)
- ;
-
- /* we must get 7 tokens */
- if (count < 7)
- return(False);
-
- /* the 2nd and 4th, 6th columns must be integer */
- if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3]))
- return(False);
- if (!isdigit((int)*tok[5]))
- return(False);
-
- /* if the user contains a ! then trim the first part of it */
- if ((p=strchr(tok[2],'!'))) {
- fstring tmp;
- fstrcpy(tmp,p+1);
- fstrcpy(tok[2],tmp);
- }
-
- buf->job = atoi(tok[1]);
- buf->size = atoi(tok[3]);
- if (count > 7 && strequal(tok[7],"on"))
- buf->status = LPQ_PRINTING;
- else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held"))
- buf->status = LPQ_PAUSED;
- else
- buf->status = LPQ_QUEUED;
- buf->priority = 0;
- buf->time = EntryTime(tok, 4, count, 7);
- StrnCpy(buf->user,tok[2],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[2],sizeof(buf->file)-1);
- return(True);
-}
-
-/****************************************************************************
-parse a lpq line
-
-here is an example of lpq output under qnx
-Spooler: /qnx/spooler, on node 1
-Printer: txt (ready)
-0000: root [job #1 ] active 1146 bytes /etc/profile
-0001: root [job #2 ] ready 2378 bytes /etc/install
-0002: root [job #3 ] ready 1146 bytes -- standard input --
-****************************************************************************/
-static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
-{
- fstring tok[7];
- int count=0;
-
- DEBUG(4,("antes [%s]\n", line));
-
- /* handle the case of "-- standard input --" as a filename */
- pstring_sub(line,"standard input","STDIN");
- DEBUG(4,("despues [%s]\n", line));
- all_string_sub(line,"-- ","\"",0);
- all_string_sub(line," --","\"",0);
- DEBUG(4,("despues 1 [%s]\n", line));
-
- pstring_sub(line,"[job #","");
- pstring_sub(line,"]","");
- DEBUG(4,("despues 2 [%s]\n", line));
-
-
-
- for (count=0; count<7 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
-
- /* we must get 7 tokens */
- if (count < 7)
- return(False);
-
- /* the 3rd and 5th columns must be integer */
- if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) return(False);
-
- /* only take the last part of the filename */
- {
- fstring tmp;
- char *p = strrchr(tok[6],'/');
- if (p)
- {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[6],tmp);
- }
- }
-
-
- buf->job = atoi(tok[2]);
- buf->size = atoi(tok[4]);
- buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
- buf->priority = 0;
- buf->time = time(NULL);
- StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
- return(True);
-}
-
-
-/****************************************************************************
- parse a lpq line for the plp printing system
- Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
-
-redone by tridge. Here is a sample queue:
-
-Local Printer 'lp2' (fjall):
- Printing (started at Jun 15 13:33:58, attempt 1).
- Rank Owner Pr Opt Job Host Files Size Date
- active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
- 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
-
-****************************************************************************/
-static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
-{
- fstring tok[11];
- int count=0;
-
- /* handle the case of "(standard input)" as a filename */
- pstring_sub(line,"stdin","STDIN");
- all_string_sub(line,"(","\"",0);
- all_string_sub(line,")","\"",0);
-
- for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
-
- /* we must get 11 tokens */
- if (count < 11)
- return(False);
-
- /* the first must be "active" or begin with an integer */
- if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0]))
- return(False);
-
- /* the 5th and 8th must be integer */
- if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7]))
- return(False);
-
- /* if the fname contains a space then use STDIN */
- if (strchr(tok[6],' '))
- fstrcpy(tok[6],"STDIN");
-
- /* only take the last part of the filename */
- {
- fstring tmp;
- char *p = strrchr(tok[6],'/');
- if (p)
- {
- fstrcpy(tmp,p+1);
- fstrcpy(tok[6],tmp);
- }
- }
-
-
- buf->job = atoi(tok[4]);
-
- buf->size = atoi(tok[7]);
- if (strchr(tok[7],'K'))
- buf->size *= 1024;
- if (strchr(tok[7],'M'))
- buf->size *= 1024*1024;
-
- buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
- buf->priority = 0;
- buf->time = time(NULL);
- StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
- return(True);
-}
-
-/****************************************************************************
-parse a qstat line
-
-here is an example of "qstat -l -d qms" output under softq
-
-Queue qms: 2 jobs; daemon active (313); enabled; accepting;
- job-ID submission-time pri size owner title
-205980: H 98/03/09 13:04:05 0 15733 stephenf chap1.ps
-206086:> 98/03/12 17:24:40 0 659 chris -
-206087: 98/03/12 17:24:45 0 4876 chris -
-Total: 21268 bytes in queue
-
-
-****************************************************************************/
-static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
-{
- fstring tok[10];
- int count=0;
-
- /* mung all the ":"s to spaces*/
- pstring_sub(line,":"," ");
-
- for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
-
- /* we must get 9 tokens */
- if (count < 9)
- return(False);
-
- /* the 1st and 7th columns must be integer */
- if (!isdigit((int)*tok[0]) || !isdigit((int)*tok[6])) return(False);
- /* if the 2nd column is either '>' or 'H' then the 7th and 8th must be
- * integer, else it's the 6th and 7th that must be
- */
- if (*tok[1] == 'H' || *tok[1] == '>')
- {
- if (!isdigit((int)*tok[7]))
- return(False);
- buf->status = *tok[1] == '>' ? LPQ_PRINTING : LPQ_PAUSED;
- count = 1;
- }
- else
- {
- if (!isdigit((int)*tok[5]))
- return(False);
- buf->status = LPQ_QUEUED;
- count = 0;
- }
-
-
- buf->job = atoi(tok[0]);
- buf->size = atoi(tok[count+6]);
- buf->priority = atoi(tok[count+5]);
- StrnCpy(buf->user,tok[count+7],sizeof(buf->user)-1);
- StrnCpy(buf->file,tok[count+8],sizeof(buf->file)-1);
- buf->time = time(NULL); /* default case: take current time */
- {
- time_t jobtime;
- struct tm *t;
-
- t = localtime(&buf->time);
- t->tm_mday = atoi(tok[count+2]+6);
- t->tm_mon = atoi(tok[count+2]+3);
- switch (*tok[count+2])
- {
- case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break;
- default: t->tm_year = atoi(tok[count+2]); break;
- }
-
- t->tm_hour = atoi(tok[count+3]);
- t->tm_min = atoi(tok[count+4]);
- t->tm_sec = atoi(tok[count+5]);
- jobtime = mktime(t);
- if (jobtime != (time_t)-1)
- buf->time = jobtime;
- }
-
- return(True);
-}
-
-
-char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };
-char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
-char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
-
-/****************************************************************************
-parse a lpq line. Choose printing style
-****************************************************************************/
-static BOOL parse_lpq_entry(int snum,char *line,
- print_queue_struct *buf,
- print_status_struct *status,BOOL first)
-{
- BOOL ret;
-
- switch (lp_printing(snum))
- {
- case PRINT_SYSV:
- ret = parse_lpq_sysv(line,buf,first);
- break;
- case PRINT_AIX:
- ret = parse_lpq_aix(line,buf,first);
- break;
- case PRINT_HPUX:
- ret = parse_lpq_hpux(line,buf,first);
- break;
- case PRINT_QNX:
- ret = parse_lpq_qnx(line,buf,first);
- break;
- case PRINT_LPRNG:
- ret = parse_lpq_lprng(line,buf,first);
- break;
- case PRINT_PLP:
- ret = parse_lpq_plp(line,buf,first);
- break;
- case PRINT_SOFTQ:
- ret = parse_lpq_softq(line,buf,first);
- break;
- default:
- ret = parse_lpq_bsd(line,buf,first);
- break;
- }
-
-#ifdef LPQ_GUEST_TO_USER
- if (ret) {
- extern pstring sesssetup_user;
- /* change guest entries to the current logged in user to make
- them appear deletable to windows */
- if (sesssetup_user[0] && strequal(buf->user,lp_guestaccount(snum)))
- pstrcpy(buf->user,sesssetup_user);
- }
-#endif
-
- /* We don't want the newline in the status message. */
- {
- char *p = strchr(line,'\n');
- if (p) *p = 0;
- }
-
- /* in the LPRNG case, we skip lines starting by a space.*/
- if (line && !ret && (lp_printing(snum)==PRINT_LPRNG) )
- {
- if (line[0]==' ')
- return ret;
- }
-
-
- if (status && !ret)
- {
- /* a few simple checks to see if the line might be a
- printer status line:
- handle them so that most severe condition is shown */
- int i;
- strlower(line);
-
- switch (status->status) {
- case LPSTAT_OK:
- for (i=0; stat0_strings[i]; i++)
- if (strstr(line,stat0_strings[i])) {
- StrnCpy(status->message,line,sizeof(status->message)-1);
- status->status=LPSTAT_OK;
- return ret;
- }
- case LPSTAT_STOPPED:
- for (i=0; stat1_strings[i]; i++)
- if (strstr(line,stat1_strings[i])) {
- StrnCpy(status->message,line,sizeof(status->message)-1);
- status->status=LPSTAT_STOPPED;
- return ret;
- }
- case LPSTAT_ERROR:
- for (i=0; stat2_strings[i]; i++)
- if (strstr(line,stat2_strings[i])) {
- StrnCpy(status->message,line,sizeof(status->message)-1);
- status->status=LPSTAT_ERROR;
- return ret;
- }
- break;
- }
- }
-
- return(ret);
-}
/****************************************************************************
get a printer queue
if (lp_load_printers())
add_all_printers();
}
+
+
+void print_open_file(files_struct *fsp,connection_struct *conn,char *fname)
+{
+ pstring template;
+ char *p;
+ SMB_STRUCT_STAT sbuf;
+ extern struct current_user current_user;
+
+ /* see if we have sufficient disk space */
+ if (lp_minprintspace(SNUM(conn))) {
+ SMB_BIG_UINT dum1,dum2,dum3;
+ if (conn->vfs_ops.disk_free(conn->connectpath,False,&dum1,&dum2,&dum3) <
+ (SMB_BIG_UINT)lp_minprintspace(SNUM(conn))) {
+ errno = ENOSPC;
+ return;
+ }
+ }
+
+ slprintf(template, sizeof(template), "%s/smb.XXXXXX", conn->connectpath);
+ p = smbd_mktemp(template);
+ if (!p) {
+ DEBUG(2,("Error creating temporary filename in %s\n",
+ conn->connectpath));
+ errno = ENOSPC;
+ return;
+ }
+
+ fsp->fd = conn->vfs_ops.open(p,O_RDWR|O_CREAT|O_EXCL,0600);
+
+ if (fsp->fd == -1) {
+ DEBUG(3,("Error opening file %s\n",p));
+ return;
+ }
+
+ /*
+ * If the printer is marked as postscript output a leading
+ * file identifier to ensure the file is treated as a raw
+ * postscript file.
+ * This has a similar effect as CtrlD=0 in WIN.INI file.
+ * tim@fsg.com 09/06/94
+ */
+ if (lp_postscript(SNUM(conn))) {
+ DEBUG(3,("Writing postscript line\n"));
+ conn->vfs_ops.write(fsp->fd,"%!\n",3);
+ }
+
+ /* setup a full fsp */
+ conn->vfs_ops.fstat(fsp->fd, &sbuf);
+ conn->num_files_open++;
+ fsp->mode = sbuf.st_mode;
+ fsp->inode = sbuf.st_ino;
+ fsp->dev = sbuf.st_dev;
+ GetTimeOfDay(&fsp->open_time);
+ fsp->vuid = current_user.vuid;
+ fsp->size = 0;
+ fsp->pos = -1;
+ fsp->open = True;
+ fsp->can_lock = True;
+ fsp->can_read = False;
+ fsp->can_write = True;
+ fsp->share_mode = 0;
+ fsp->print_file = True;
+ fsp->modified = False;
+ fsp->oplock_type = NO_OPLOCK;
+ fsp->sent_oplock_break = NO_BREAK_SENT;
+ fsp->is_directory = False;
+ fsp->stat_open = False;
+ fsp->directory_delete_on_close = False;
+ fsp->conn = conn;
+ string_set(&fsp->fsp_name,p);
+ fsp->wbmpx_ptr = NULL;
+ fsp->wcp = NULL;
+}
static int close_normal_file(files_struct *fsp, BOOL normal_close)
{
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
- BOOL last_reference = False;
- BOOL delete_on_close = fsp->fd_ptr->delete_on_close;
+ BOOL delete_on_close = fsp->delete_on_close;
connection_struct *conn = fsp->conn;
int err = 0;
close_filestruct(fsp);
-#if USE_READ_PREDICTION
- invalidate_read_prediction(fsp->fd_ptr->fd);
-#endif
-
if (lp_share_modes(SNUM(conn))) {
- lock_share_entry(conn, dev, inode);
+ lock_share_entry_fsp(fsp);
del_share_mode(fsp);
}
locking_close_file(fsp);
- if(fd_attempt_close(fsp, &err) == 0)
- last_reference = True;
-
- fsp->fd_ptr = NULL;
-
if (lp_share_modes(SNUM(conn)))
- unlock_share_entry(conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
+
+ fd_close(fsp, &err);
/* NT uses smbclose to start a print - weird */
if (normal_close && fsp->print_file)
* reference to a file.
*/
- if (normal_close && last_reference && delete_on_close) {
+ if (normal_close && delete_on_close) {
DEBUG(5,("close_file: file %s. Delete on close was set - deleting file.\n",
fsp->fsp_name));
if(fsp->conn->vfs_ops.unlink(dos_to_unix(fsp->fsp_name, False)) != 0) {
if (fsp->print_file && lp_postscript(fsp->conn->service))
offset = 3;
- seek_ret = fsp->conn->vfs_ops.lseek(fsp->fd_ptr->fd,pos+offset,SEEK_SET);
+ seek_ret = fsp->conn->vfs_ops.lseek(fsp->fd,pos+offset,SEEK_SET);
/*
* We want to maintain the fiction that we can seek
{
ssize_t ret=0,readret;
-#if USE_READ_PREDICTION
- if (!fsp->can_write) {
- ret = read_predict(fsp->fd_ptr->fd,pos,data,NULL,n);
-
- data += ret;
- n -= ret;
- pos += ret;
- }
-#endif
-
/*
* Serve from write cache if we can.
*/
}
if (n > 0) {
- readret = fsp->conn->vfs_ops.read(fsp->fd_ptr->fd,data,n);
+ readret = fsp->conn->vfs_ops.read(fsp->fd,data,n);
if (readret > 0) ret += readret;
}
if ((pos != -1) && (seek_file(fsp,pos) == -1))
return -1;
- return write_data(fsp->fd_ptr->fd,data,n);
+ return write_data(fsp->fd,data,n);
}
/****************************************************************************
SMB_STRUCT_STAT st;
fsp->modified = True;
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&st) == 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&st) == 0) {
int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st);
if (MAP_ARCHIVE(fsp->conn) && !IS_DOS_ARCHIVE(dosmode)) {
file_chmod(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st);
*/
if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
share_mode_entry *share_list = NULL;
pid_t pid = getpid();
int token = -1;
int num_share_modes = 0;
int i;
- if (lock_share_entry(fsp->conn, dev, inode) == False) {
+ if (lock_share_entry_fsp(fsp) == False) {
DEBUG(0,("write_file: failed to lock share mode entry for file %s.\n", fsp->fsp_name ));
}
- num_share_modes = get_share_modes(fsp->conn, dev, inode, &share_list);
+ num_share_modes = get_share_modes(fsp->conn, fsp->dev, fsp->inode, &share_list);
for(i = 0; i < num_share_modes; i++) {
share_mode_entry *share_entry = &share_list[i];
*/
if (pid == share_entry->pid) {
- files_struct *new_fsp = file_find_dit(dev, inode, &share_entry->time);
+ files_struct *new_fsp = file_find_dit(fsp->dev, fsp->inode, &share_entry->time);
/* Paranoia check... */
if(new_fsp == NULL) {
* message.
*/
- request_oplock_break(share_entry, dev, inode);
+ request_oplock_break(share_entry, fsp->dev, fsp->inode);
}
}
free((char *)share_list);
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
}
/* Paranoia check... */
}
DEBUG(9,("write_file(fd=%d pos=%d size=%d) wofs=%d wsize=%d\n",
- fsp->fd_ptr->fd, (int)pos, (int)n, (int)wcp->offset, (int)wcp->data_size));
+ fsp->fd, (int)pos, (int)n, (int)wcp->offset, (int)wcp->data_size));
/*
* If we have active cache and it isn't contiguous then we flush.
wcp->file_size = wcp->offset + wcp->data_size;
#if 0
- if (set_filelen(fsp->fd_ptr->fd, wcp->file_size) == -1) {
+ if (set_filelen(fsp->fd, wcp->file_size) == -1) {
DEBUG(0,("write_file: error %s in setting file to length %.0f\n",
strerror(errno), (double)wcp->file_size ));
return -1;
*/
DEBUG(9,("write_file: non cacheable write : fd = %d, pos = %.0f, len = %u, current cache pos = %.0f \
-len = %u\n",fsp->fd_ptr->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
+len = %u\n",fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
/*
* Update the file size if needed.
DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
- write_path, fsp->fd_ptr->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
+ write_path, fsp->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
(double)wcp->offset, (unsigned int)wcp->data_size ));
flush_write_cache(fsp, WRITE_FLUSH);
flush_reasons[(int)reason]++;
DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
- fsp->fd_ptr->fd, (double)wcp->offset, (unsigned int)data_size));
+ fsp->fd, (double)wcp->offset, (unsigned int)data_size));
if(data_size == wcp->alloc_size)
num_perfect_writes++;
void sys_fsync_file(connection_struct *conn, files_struct *fsp)
{
- if(lp_strict_sync(SNUM(conn)) && fsp->fd_ptr != NULL) {
+ if(lp_strict_sync(SNUM(conn)) && fsp->fd != -1) {
flush_write_cache(fsp, SYNC_FLUSH);
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
}
}
extern char magic_char;
#endif
+ if (conn->printer) {
+ /* we don't ever use the filenames on a printer share as a
+ filename - so don't convert them */
+ return True;
+ }
+
DEBUG(5, ("unix_convert called on file \"%s\"\n", name));
*dirpath = 0;
/* a fsp to use to save when breaking an oplock. */
static files_struct *oplock_save_chain_fsp = NULL;
-/*
- * Indirection for file fd's. Needed as POSIX locking
- * is based on file/process, not fd/process.
- */
-static file_fd_struct *FileFd;
-
-static int files_used, fd_ptr_used;
+static int files_used;
/****************************************************************************
find first available file slot
if (!fsp) return NULL;
ZERO_STRUCTP(fsp);
+ fsp->fd = -1;
first_file = (i+1) % real_max_open_files;
}
-
-/****************************************************************************
-fd support routines - attempt to find an already open file by dev
-and inode - increments the ref_count of the returned file_fd_struct *.
-****************************************************************************/
-file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf)
-{
- file_fd_struct *fd_ptr;
-
- if(!sbuf) return NULL;
-
- for (fd_ptr=FileFd;fd_ptr;fd_ptr=fd_ptr->next) {
- if ((fd_ptr->ref_count > 0) &&
- (sbuf->st_dev == fd_ptr->dev) &&
- (sbuf->st_ino == fd_ptr->inode)) {
- fd_ptr->ref_count++;
-
- DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %.0f, ref_count = %d\n",
- (unsigned int)fd_ptr->dev, (double)fd_ptr->inode,
- fd_ptr->ref_count));
-
- return fd_ptr;
- }
- }
-
- return NULL;
-}
-
-
-
-/****************************************************************************
-fd support routines - attempt to find a empty slot in the FileFd array.
-Increments the ref_count of the returned entry.
-****************************************************************************/
-file_fd_struct *fd_get_new(void)
-{
- extern struct current_user current_user;
- file_fd_struct *fd_ptr;
-
- fd_ptr = (file_fd_struct *)malloc(sizeof(*fd_ptr));
- if (!fd_ptr) {
- DEBUG(0,("ERROR! malloc fail for file_fd struct.\n"));
- return NULL;
- }
-
- ZERO_STRUCTP(fd_ptr);
-
- fd_ptr->dev = (SMB_DEV_T)-1;
- fd_ptr->inode = (SMB_INO_T)-1;
- fd_ptr->fd = -1;
- fd_ptr->fd_readonly = -1;
- fd_ptr->fd_writeonly = -1;
- fd_ptr->real_open_flags = -1;
- fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid);
- fd_ptr->ref_count++;
-
- fd_ptr_used++;
-
- DLIST_ADD(FileFd, fd_ptr);
-
- DEBUG(5,("allocated fd_ptr structure (%d used)\n", fd_ptr_used));
-
- return fd_ptr;
-}
-
-
/****************************************************************************
close all open files for a connection
****************************************************************************/
for (fsp=Files;fsp;fsp=fsp->next,count++) {
if (fsp->open &&
- fsp->fd_ptr != NULL &&
- fsp->fd_ptr->dev == dev &&
- fsp->fd_ptr->inode == inode &&
+ fsp->fd != -1 &&
+ fsp->dev == dev &&
+ fsp->inode == inode &&
(tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) &&
(tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True )) {
if (count > 10) {
for (fsp=Files;fsp;fsp=fsp->next) {
if (fsp->open &&
- fsp->fd_ptr != NULL &&
- fsp->fd_ptr->dev == dev &&
- fsp->fd_ptr->inode == inode )
+ fsp->fd != -1 &&
+ fsp->dev == dev &&
+ fsp->inode == inode )
return fsp;
}
for (fsp = start_fsp->next;fsp;fsp=fsp->next) {
if (fsp->open &&
- fsp->fd_ptr != NULL &&
- fsp->fd_ptr->dev == start_fsp->fd_ptr->dev &&
- fsp->fd_ptr->inode == start_fsp->fd_ptr->inode )
+ fsp->fd != -1 &&
+ fsp->dev == start_fsp->dev &&
+ fsp->inode == start_fsp->inode )
return fsp;
}
for (fsp=Files;fsp;fsp=next) {
next=fsp->next;
- if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) {
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ if (fsp->open && (conn == fsp->conn) && (fsp->fd != -1)) {
+ conn->vfs_ops.fsync(fsp->fd);
}
}
}
-/****************************************************************************
-free up a fd_ptr
-****************************************************************************/
-void fd_ptr_free(file_fd_struct *fd_ptr)
-{
- DLIST_REMOVE(FileFd, fd_ptr);
-
- fd_ptr_used--;
-
- DEBUG(5,("freed fd_ptr structure (%d used)\n", fd_ptr_used));
-
- /* paranoia */
- ZERO_STRUCTP(fd_ptr);
-
- free(fd_ptr);
-}
-
-
/****************************************************************************
free up a fsp
****************************************************************************/
string_free(&fsp->fsp_name);
- if ((fsp->fd_ptr != NULL) && fsp->fd_ptr->ref_count == 0) {
- fd_ptr_free(fsp->fd_ptr);
- }
-
bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET);
files_used--;
return(ERROR(ERRSRV,ERRnofids));
}
- if (!check_name(fname,conn)) {
- if((errno == ENOENT) && bad_path) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
-
- restore_case_semantics(file_attributes);
-
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
unixmode = unix_mode(conn,smb_attr | aARCH, fname);
/*
return(ERROR(ERRDOS,ERRnoaccess));
}
} else {
- if (conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
restore_case_semantics(file_attributes);
return(ERROR(ERRDOS,ERRnoaccess));
return(ERROR(ERRSRV,ERRnofids));
}
- if (!check_name(fname,conn)) {
- if((errno == ENOENT) && bad_path) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
-
- restore_case_semantics(file_attributes);
-
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
unixmode = unix_mode(conn,smb_attr | aARCH, fname);
/*
return(ERROR(ERRDOS,ERRnoaccess));
}
} else {
- if (!fsp->stat_open && conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (!fsp->stat_open && conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
restore_case_semantics(file_attributes);
return(ERROR(ERRDOS,ERRnoaccess));
sid_copy( &group_sid, global_sid_everyone);
} else {
- if(fsp->is_directory || fsp->fd_ptr == NULL) {
- if(dos_stat(fsp->fsp_name, &sbuf) != 0)
- {
+ if(fsp->is_directory || fsp->fd == -1) {
+ if(dos_stat(fsp->fsp_name, &sbuf) != 0) {
return 0;
}
} else {
- if(fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if(fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
return 0;
}
}
int ret;
- if(fsp->fd_ptr == NULL)
+ if(fsp->fd == -1)
ret = conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name,False), &sbuf);
else
- ret = conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf);
+ ret = conn->vfs_ops.fstat(fsp->fd,&sbuf);
if(ret != 0) {
free_sec_desc(&psd);
int ret;
- if(fsp->fd_ptr == NULL)
+ if(fsp->fd == -1)
ret = conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name,False), &sbuf);
else
- ret = conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf);
+ ret = conn->vfs_ops.fstat(fsp->fd,&sbuf);
if(ret != 0)
return(UNIXERROR(ERRDOS,ERRnoaccess));
/****************************************************************************
fd support routines - attempt to do a dos_open
****************************************************************************/
-static int fd_attempt_open(struct connection_struct *conn, char *fname,
+static int fd_open(struct connection_struct *conn, char *fname,
int flags, mode_t mode)
{
int fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
/* Fix for files ending in '.' */
if((fd == -1) && (errno == ENOENT) &&
- (strchr(fname,'.')==NULL))
- {
+ (strchr(fname,'.')==NULL)) {
pstrcat(fname,".");
fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
}
-#if (defined(ENAMETOOLONG) && defined(HAVE_PATHCONF))
- if ((fd == -1) && (errno == ENAMETOOLONG))
- {
- int max_len;
- char *p = strrchr(fname, '/');
-
- if (p == fname) /* name is "/xxx" */
- {
- max_len = pathconf("/", _PC_NAME_MAX);
- p++;
- }
- else if ((p == NULL) || (p == fname))
- {
- p = fname;
- max_len = pathconf(".", _PC_NAME_MAX);
- }
- else
- {
- *p = '\0';
- max_len = pathconf(fname, _PC_NAME_MAX);
- *p = '/';
- p++;
- }
- if (strlen(p) > max_len)
- {
- char tmp = p[max_len];
-
- p[max_len] = '\0';
- if ((fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode)) == -1)
- p[max_len] = tmp;
- }
- }
-#endif
return fd;
}
/****************************************************************************
-Cache a uid_t currently with this file open. This is an optimization only
-used when multiple sessionsetup's have been done to one smbd.
-****************************************************************************/
-
-void fd_add_to_uid_cache(file_fd_struct *fd_ptr, uid_t u)
-{
- if(fd_ptr->uid_cache_count >= sizeof(fd_ptr->uid_users_cache)/sizeof(uid_t))
- return;
- fd_ptr->uid_users_cache[fd_ptr->uid_cache_count++] = u;
-}
-
-/****************************************************************************
-Remove a uid_t that currently has this file open. This is an optimization only
-used when multiple sessionsetup's have been done to one smbd.
-****************************************************************************/
-
-static void fd_remove_from_uid_cache(file_fd_struct *fd_ptr, uid_t u)
-{
- int i;
- for(i = 0; i < fd_ptr->uid_cache_count; i++)
- if(fd_ptr->uid_users_cache[i] == u) {
- if(i < (fd_ptr->uid_cache_count-1))
- memmove((char *)&fd_ptr->uid_users_cache[i], (char *)&fd_ptr->uid_users_cache[i+1],
- sizeof(uid_t)*(fd_ptr->uid_cache_count-1-i) );
- fd_ptr->uid_cache_count--;
- }
- return;
-}
-
-/****************************************************************************
-Check if a uid_t that currently has this file open is present. This is an
-optimization only used when multiple sessionsetup's have been done to one smbd.
+close the file associated with a fsp
****************************************************************************/
-
-static BOOL fd_is_in_uid_cache(file_fd_struct *fd_ptr, uid_t u)
+void fd_close(files_struct *fsp, int *err_ret)
{
- int i;
- for(i = 0; i < fd_ptr->uid_cache_count; i++)
- if(fd_ptr->uid_users_cache[i] == u)
- return True;
- return False;
-}
-
-/****************************************************************************
-fd support routines - attempt to re-open an already open fd as O_RDWR.
-Save the already open fd (we cannot close due to POSIX file locking braindamage.
-****************************************************************************/
-
-static void fd_attempt_reopen(char *fname, mode_t mode, files_struct *fsp)
-{
- int fd = fsp->conn->vfs_ops.open(dos_to_unix(fname, False), O_RDWR, mode);
- file_fd_struct *fd_ptr = fsp->fd_ptr;
-
- if(fd == -1)
- return;
-
- if(fd_ptr->real_open_flags == O_RDONLY)
- fd_ptr->fd_readonly = fd_ptr->fd;
- if(fd_ptr->real_open_flags == O_WRONLY)
- fd_ptr->fd_writeonly = fd_ptr->fd;
-
- fd_ptr->fd = fd;
- fd_ptr->real_open_flags = O_RDWR;
-}
-
-/****************************************************************************
-fd support routines - attempt to close the file referenced by this fd.
-Decrements the ref_count and returns it.
-****************************************************************************/
-uint16 fd_attempt_close(files_struct *fsp, int *err_ret)
-{
- extern struct current_user current_user;
- file_fd_struct *fd_ptr;
- uint16 ret_ref;
-
- *err_ret = 0;
-
- if ((fsp == NULL) || (fsp->fd_ptr == NULL)) {
- return 0;
+ fsp->conn->vfs_ops.close(fsp->fd);
+ fsp->fd = -1;
}
- fd_ptr = fsp->fd_ptr;
- ret_ref = fd_ptr->ref_count;
-
- DEBUG(3,("fd_attempt_close fd = %d, dev = %x, inode = %.0f, open_flags = %d, ref_count = %d.\n",
- fd_ptr->fd, (unsigned int)fd_ptr->dev, (double)fd_ptr->inode,
- fd_ptr->real_open_flags,
- fd_ptr->ref_count));
-
- SMB_ASSERT(fd_ptr->ref_count != 0);
-
- fd_ptr->ref_count--;
- ret_ref = fd_ptr->ref_count;
-
- if(fd_ptr->ref_count == 0) {
-
- if(fd_ptr->fd != -1) {
- if(fsp->conn->vfs_ops.close(fd_ptr->fd) < 0)
- *err_ret = errno;
- }
-
- if(fd_ptr->fd_readonly != -1) {
- if(fsp->conn->vfs_ops.close(fd_ptr->fd_readonly) < 0) {
- if(*err_ret == 0)
- *err_ret = errno;
- }
- }
-
- if(fd_ptr->fd_writeonly != -1) {
- if(fsp->conn->vfs_ops.close(fd_ptr->fd_writeonly) < 0) {
- if(*err_ret == 0)
- *err_ret = errno;
- }
- }
-
- /*
- * Delete this fd_ptr.
- */
- fd_ptr_free(fd_ptr);
- } else {
- fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
- }
-
- return ret_ref;
-}
-
-/****************************************************************************
-fd support routines - check that current user has permissions
-to open this file. Used when uid not found in optimization cache.
-This is really ugly code, as due to POSIX locking braindamage we must
-fork and then attempt to open the file, and return success or failure
-via an exit code.
-****************************************************************************/
-static BOOL check_access_allowed_for_current_user(struct connection_struct
- *conn, char *fname,
- int accmode )
-{
- pid_t child_pid;
-
- /*
- * We need to temporarily stop CatchChild from eating
- * SIGCLD signals as it also eats the exit status code. JRA.
- */
-
- CatchChildLeaveStatus();
-
- if((child_pid = fork()) < 0) {
- DEBUG(0,("check_access_allowed_for_current_user: fork failed.\n"));
- CatchChild();
- return False;
- }
-
- if(child_pid) {
- /*
- * Parent.
- */
- pid_t wpid;
- int status_code;
-
- while ((wpid = sys_waitpid(child_pid, &status_code, 0)) < 0) {
- if(errno == EINTR) {
- errno = 0;
- continue;
- }
- DEBUG(0,("check_access_allowed_for_current_user: The process \
-is no longer waiting ! Error = %s\n", strerror(errno) ));
- CatchChild();
- return(False);
- }
-
- /*
- * Go back to ignoring children.
- */
- CatchChild();
-
- if (child_pid != wpid) {
- DEBUG(0,("check_access_allowed_for_current_user: We were waiting for the wrong process ID\n"));
- return(False);
- }
-#if defined(WIFEXITED) && defined(WEXITSTATUS)
- if (WIFEXITED(status_code) == 0) {
- DEBUG(0,("check_access_allowed_for_current_user: The process exited while we were waiting\n"));
- return(False);
- }
- if (WEXITSTATUS(status_code) != 0) {
- DEBUG(9,("check_access_allowed_for_current_user: The status of the process exiting was %d. Returning access denied.\n", status_code));
- return(False);
- }
-#else /* defined(WIFEXITED) && defined(WEXITSTATUS) */
- if(status_code != 0) {
- DEBUG(9,("check_access_allowed_for_current_user: The status of the process exiting was %d. Returning access denied.\n", status_code));
- return(False);
- }
-#endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */
-
- /*
- * Success - the child could open the file.
- */
- DEBUG(9,("check_access_allowed_for_current_user: The status of the process exiting was %d. Returning access allowed.\n", status_code));
- return True;
- } else {
- /*
- * Child.
- */
- int fd;
- DEBUG(9,("check_access_allowed_for_current_user: Child - attempting to open %s with mode %d.\n", fname, accmode ));
- if((fd = fd_attempt_open(conn, fname, accmode, 0)) < 0) {
- /* Access denied. */
- _exit(EACCES);
- }
- conn->vfs_ops.close(fd);
- DEBUG(9,("check_access_allowed_for_current_user: Child - returning ok.\n"));
- _exit(0);
- }
-
- return False;
-}
/****************************************************************************
check a filename for the pipe string
****************************************************************************/
static void open_file(files_struct *fsp,connection_struct *conn,
- char *fname1,int flags,mode_t mode, SMB_STRUCT_STAT *sbuf)
+ char *fname1,int flags,mode_t mode)
{
extern struct current_user current_user;
pstring fname;
- SMB_STRUCT_STAT statbuf;
- file_fd_struct *fd_ptr;
int accmode = (flags & O_ACCMODE);
+ SMB_STRUCT_STAT sbuf;
fsp->open = False;
- fsp->fd_ptr = 0;
+ fsp->fd = 0;
fsp->oplock_type = NO_OPLOCK;
errno = EPERM;
* JRA.
*/
- if (!CAN_WRITE(conn) && !conn->printer) {
+ if (!CAN_WRITE(conn)) {
/* It's a read-only share - fail if we wanted to write. */
if(accmode != O_RDONLY) {
DEBUG(3,("Permission denied opening %s\n",fname));
}
}
- /* this handles a bug in Win95 - it doesn't say to create the file when it
- should */
- if (conn->printer) {
- flags |= (O_CREAT|O_EXCL);
- }
-
-/*
- if (flags == O_WRONLY)
- DEBUG(3,("Bug in client? Set O_WRONLY without O_CREAT\n"));
-*/
-
- /*
- * Ensure we have a valid struct stat so we can search the
- * open fd table.
- */
- if(sbuf == 0) {
- if(conn->vfs_ops.stat(dos_to_unix(fname,False), &statbuf) < 0) {
- if(errno != ENOENT) {
- DEBUG(3,("Error doing stat on file %s (%s)\n",
- fname,strerror(errno)));
-
- check_for_pipe(fname);
- return;
- }
- sbuf = 0;
- } else {
- sbuf = &statbuf;
- }
- }
-
- /*
- * Check to see if we have this file already
- * open. If we do, just use the already open fd and increment the
- * reference count (fd_get_already_open increments the ref_count).
- */
- if((fd_ptr = fd_get_already_open(sbuf))!= 0) {
- /*
- * File was already open.
- */
-
- /*
- * Check it wasn't open for exclusive use.
- */
- if((flags & O_CREAT) && (flags & O_EXCL)) {
- fd_ptr->ref_count--;
- errno = EEXIST;
- return;
- }
-
- /*
- * Ensure that the user attempting to open
- * this file has permissions to do so, if
- * the user who originally opened the file wasn't
- * the same as the current user.
- */
-
- if(!fd_is_in_uid_cache(fd_ptr, (uid_t)current_user.uid)) {
- if(!check_access_allowed_for_current_user(conn, fname, accmode )) {
- /* Error - permission denied. */
- DEBUG(3,("Permission denied opening file %s (flags=%d, accmode = %d)\n",
- fname, flags, accmode));
- /* Ensure the ref_count is decremented. */
- fd_ptr->ref_count--;
- fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
- errno = EACCES;
- return;
- }
- }
-
- fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid);
-
- /*
- * If not opened O_RDWR try
- * and do that here - a chmod may have been done
- * between the last open and now.
- */
- if(fd_ptr->real_open_flags != O_RDWR)
- fd_attempt_reopen(fname, mode, fsp);
-
- /*
- * Ensure that if we wanted write access
- * it has been opened for write, and if we wanted read it
- * was open for read.
- */
- if(((accmode == O_WRONLY) && (fd_ptr->real_open_flags == O_RDONLY)) ||
- ((accmode == O_RDONLY) && (fd_ptr->real_open_flags == O_WRONLY)) ||
- ((accmode == O_RDWR) && (fd_ptr->real_open_flags != O_RDWR))) {
- DEBUG(3,("Error opening (already open for flags=%d) file %s (%s) (flags=%d)\n",
- fd_ptr->real_open_flags, fname,strerror(EACCES),flags));
- check_for_pipe(fname);
- fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
- fd_ptr->ref_count--;
- return;
- }
-
- } else {
- int open_flags;
- /* We need to allocate a new file_fd_struct (this increments the
- ref_count). */
- if((fd_ptr = fd_get_new()) == 0)
- return;
- /*
- * Whatever the requested flags, attempt read/write access,
- * as we don't know what flags future file opens may require.
- * If this fails, try again with the required flags.
- * Even if we open read/write when only read access was
- * requested the setting of the can_write flag in
- * the file_struct will protect us from errant
- * write requests. We never need to worry about O_APPEND
- * as this is not set anywhere in Samba.
- */
- fd_ptr->real_open_flags = O_RDWR;
- /* Set the flags as needed without the read/write modes. */
- open_flags = flags & ~(O_RDWR|O_WRONLY|O_RDONLY);
- fd_ptr->fd = fd_attempt_open(conn, fname, open_flags|O_RDWR, mode);
- /*
- * On some systems opening a file for R/W access on a read only
- * filesystems sets errno to EROFS.
- */
-#ifdef EROFS
- if((fd_ptr->fd == -1) && ((errno == EACCES) || (errno == EROFS))) {
-#else /* No EROFS */
- if((fd_ptr->fd == -1) && (errno == EACCES)) {
-#endif /* EROFS */
- if(accmode != O_RDWR) {
- fd_ptr->fd = fd_attempt_open(conn, fname, open_flags|accmode, mode);
- fd_ptr->real_open_flags = accmode;
- }
- }
- }
-
- if ((fd_ptr->fd >=0) &&
- conn->printer && lp_minprintspace(SNUM(conn))) {
- pstring dname;
- SMB_BIG_UINT dum1,dum2,dum3;
- char *p;
- pstrcpy(dname,fname);
- p = strrchr(dname,'/');
- if (p) *p = 0;
- if (conn->vfs_ops.disk_free(dos_to_unix(dname,False),False,&dum1,&dum2,&dum3) <
- (SMB_BIG_UINT)lp_minprintspace(SNUM(conn))) {
- int err;
- if(fd_attempt_close(fsp, &err) == 0)
- conn->vfs_ops.unlink(dos_to_unix(fname, False));
- fsp->fd_ptr = 0;
- errno = ENOSPC;
- return;
- }
- }
+ /* actually do the open */
+ fsp->fd = fd_open(conn, fname, flags, mode);
- if (fd_ptr->fd < 0)
- {
- int err;
+ if (fsp->fd == -1) {
DEBUG(3,("Error opening file %s (%s) (flags=%d)\n",
fname,strerror(errno),flags));
- /* Ensure the ref_count is decremented. */
- fd_attempt_close(fsp,&err);
check_for_pipe(fname);
return;
}
- if (fd_ptr->fd >= 0)
- {
- if(sbuf == 0) {
- /* Do the fstat */
- if(conn->vfs_ops.fstat(fd_ptr->fd, &statbuf) == -1) {
- int err;
- /* Error - backout !! */
- DEBUG(3,("Error doing fstat on fd %d, file %s (%s)\n",
- fd_ptr->fd, fname,strerror(errno)));
- /* Ensure the ref_count is decremented. */
- fd_attempt_close(fsp,&err);
- return;
- }
- sbuf = &statbuf;
- }
-
- /* Set the correct entries in fd_ptr. */
- fd_ptr->dev = sbuf->st_dev;
- fd_ptr->inode = sbuf->st_ino;
+ conn->vfs_ops.fstat(fsp->fd, &sbuf);
- fsp->fd_ptr = fd_ptr;
conn->num_files_open++;
- fsp->mode = sbuf->st_mode;
+ fsp->mode = sbuf.st_mode;
+ fsp->inode = sbuf.st_ino;
+ fsp->dev = sbuf.st_dev;
GetTimeOfDay(&fsp->open_time);
fsp->vuid = current_user.key.vuid;
fsp->size = 0;
fsp->can_read = ((flags & O_WRONLY)==0);
fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
fsp->share_mode = 0;
- fsp->print_file = conn->printer;
+ fsp->print_file = False;
fsp->modified = False;
fsp->oplock_type = NO_OPLOCK;
fsp->sent_oplock_break = NO_BREAK_SENT;
fsp->wbmpx_ptr = NULL;
fsp->wcp = NULL; /* Write cache pointer. */
- /*
- * If the printer is marked as postscript output a leading
- * file identifier to ensure the file is treated as a raw
- * postscript file.
- * This has a similar effect as CtrlD=0 in WIN.INI file.
- * tim@fsg.com 09/06/94
- */
- if (fsp->print_file && lp_postscript(SNUM(conn)) && fsp->can_write) {
- DEBUG(3,("Writing postscript line\n"));
- conn->vfs_ops.write(fsp->fd_ptr->fd,"%!\n",3);
- }
-
DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
*sesssetup_user ? sesssetup_user : conn->user,fsp->fsp_name,
BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
conn->num_files_open));
-
- }
}
/****************************************************************************
/* If share modes are in force for this connection we
have the share entry locked. Unlock it before closing. */
if (*share_locked && lp_share_modes(SNUM(conn)))
- unlock_share_entry( conn, fsp->fd_ptr->dev,
- fsp->fd_ptr->inode);
+ unlock_share_entry_fsp(fsp);
close_file(fsp,False);
/* Share mode no longer locked. */
*share_locked = False;
unix_ERR_class = ERRDOS;
unix_ERR_code = ERRlock;
} else {
- sys_ftruncate(fsp->fd_ptr->fd,0);
+ sys_ftruncate(fsp->fd,0);
}
}
}
int oplock_contention_count = 0;
BOOL all_current_opens_are_level_II = False;
fsp->open = False;
- fsp->fd_ptr = 0;
+ fsp->fd = -1;
+
+ if (conn->printer) {
+ /* printers are handled completely differently. Most of the passed parameters are
+ ignored */
+ *Access = DOS_OPEN_WRONLY;
+ *action = FILE_WAS_CREATED;
+ print_open_file(fsp, conn, fname);
+ return;
+ }
DEBUG(10,("open_file_shared: fname = %s, share_mode = %x, ofun = %x, mode = %o, oplock request = %d\n",
fname, share_mode, ofun, (int)mode, oplock_request ));
+ if (!check_name(fname,conn)) {
+ return;
+ }
/* ignore any oplock requests if oplocks are disabled */
if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break) {
DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o\n",
flags,flags2,(int)mode));
- open_file(fsp,conn,fname,flags|(flags2&~(O_TRUNC)),mode,file_existed ? &sbuf : 0);
- if (!fsp->open && flags==O_RDWR && errno!=ENOENT && fcbopen)
- {
+ open_file(fsp,conn,fname,flags|(flags2&~(O_TRUNC)),mode);
+ if (!fsp->open && flags==O_RDWR && errno != ENOENT && fcbopen) {
flags = O_RDONLY;
- open_file(fsp,conn,fname,flags,mode,file_existed ? &sbuf : 0 );
+ open_file(fsp,conn,fname,flags,mode);
}
if (fsp->open)
if((share_locked == False) && lp_share_modes(SNUM(conn)))
{
/* We created the file - thus we must now lock the share entry before creating it. */
- dev = fsp->fd_ptr->dev;
- inode = fsp->fd_ptr->inode;
- lock_share_entry(conn, dev, inode);
+ lock_share_entry_fsp(fsp);
share_locked = True;
}
}
if (share_locked && lp_share_modes(SNUM(conn)))
- unlock_share_entry( conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
}
/****************************************************************************
Open a file for permissions read only. Return a pseudo file entry
- with the 'stat_open' flag set and a fd_ptr of NULL.
+ with the 'stat_open' flag set
****************************************************************************/
int open_file_stat(files_struct *fsp,connection_struct *conn,
* Setup the files_struct for it.
*/
- fsp->fd_ptr = NULL;
+ fsp->fd = -1;
conn->num_files_open++;
fsp->mode = 0;
GetTimeOfDay(&fsp->open_time);
* Setup the files_struct for it.
*/
- fsp->fd_ptr = NULL;
+ fsp->fd = -1;
conn->num_files_open++;
fsp->mode = 0;
GetTimeOfDay(&fsp->open_time);
#if defined(HAVE_KERNEL_OPLOCKS)
if(lp_kernel_oplocks()) {
- if(fcntl(fsp->fd_ptr->fd, F_OPLKREG, oplock_pipe_write) < 0 ) {
+ if(fcntl(fsp->fd, F_OPLKREG, oplock_pipe_write) < 0 ) {
if(errno != EAGAIN) {
DEBUG(0,("set_file_oplock: Unable to get kernel oplock on file %s, dev = %x, \
inode = %.0f. Error was %s\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode,
+ fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode,
strerror(errno) ));
} else {
DEBUG(5,("set_file_oplock: Refused oplock on file %s, fd = %d, dev = %x, \
inode = %.0f. Another process had the file open.\n",
- fsp->fsp_name, fsp->fd_ptr->fd, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode ));
+ fsp->fsp_name, fsp->fd, (unsigned int)fsp->dev, (double)fsp->inode ));
}
return False;
}
DEBUG(10,("set_file_oplock: got kernel oplock on file %s, dev = %x, inode = %.0f\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode));
+ fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode));
}
#endif /* HAVE_KERNEL_OPLOCKS */
exclusive_oplocks_open++;
DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, tv_sec = %x, tv_usec = %x\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode,
+ fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode,
(int)fsp->open_time.tv_sec, (int)fsp->open_time.tv_usec ));
return True;
* Check and print out the current kernel
* oplock state of this file.
*/
- int state = fcntl(fsp->fd_ptr->fd, F_OPLKACK, -1);
+ int state = fcntl(fsp->fd, F_OPLKACK, -1);
dbgtext("release_kernel_oplock: file %s, dev = %x, inode = %.0f has kernel \
-oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev,
- (double)fsp->fd_ptr->inode, state );
+oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev,
+ (double)fsp->inode, state );
}
/*
* Remove the kernel oplock on this file.
*/
- if(fcntl(fsp->fd_ptr->fd, F_OPLKACK, OP_REVOKE) < 0)
+ if(fcntl(fsp->fd, F_OPLKACK, OP_REVOKE) < 0)
{
if( DEBUGLVL( 0 ))
{
dbgtext("release_kernel_oplock: Error when removing kernel oplock on file " );
dbgtext("%s, dev = %x, inode = %.0f. Error was %s\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev,
- (double)fsp->fd_ptr->inode, strerror(errno) );
+ fsp->fsp_name, (unsigned int)fsp->dev,
+ (double)fsp->inode, strerror(errno) );
}
}
}
BOOL remove_oplock(files_struct *fsp)
{
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
+ SMB_DEV_T dev = fsp->dev;
+ SMB_INO_T inode = fsp->inode;
BOOL ret = True;
/* Remove the oplock flag from the sharemode. */
- if (lock_share_entry(fsp->conn, dev, inode) == False) {
+ if (lock_share_entry_fsp(fsp) == False) {
DEBUG(0,("remove_oplock: failed to lock share entry for file %s\n",
fsp->fsp_name ));
ret = False;
downgrade_file_oplock(fsp);
}
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
return ret;
}
extern uint32 global_client_caps;
char outbuf[128];
BOOL got_lock = False;
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
+ SMB_DEV_T dev = fsp->dev;
+ SMB_INO_T inode = fsp->inode;
/*
* We can have a level II oplock even if the client is not
* the existing lock on the shared memory area.
*/
- if(!local_request && lock_share_entry(fsp->conn, dev, inode) == False) {
+ if(!local_request && lock_share_entry_fsp(fsp) == False) {
DEBUG(0,("oplock_break_level2: unable to lock share entry for file %s\n", fsp->fsp_name ));
} else {
got_lock = True;
}
if (!local_request && got_lock)
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
fsp->oplock_type = NO_OPLOCK;
level_II_oplocks_open--;
DEBUG(5,("attempt_close_oplocked_file: checking file %s.\n", fsp->fsp_name));
- if (fsp->open && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd_ptr != NULL)) {
-
+ if (fsp->open && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd != -1)) {
/* Try and break the oplock. */
- file_fd_struct *fd_ptr = fsp->fd_ptr;
- if(oplock_break( fd_ptr->dev, fd_ptr->inode, &fsp->open_time, True)) {
+ if (oplock_break(fsp->dev, fsp->inode, &fsp->open_time, True)) {
if(!fsp->open) /* Did the oplock break close the file ? */
return True;
}
+++ /dev/null
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- file read prediction routines
- Copyright (C) Andrew Tridgell 1992-1998
-
- 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 "includes.h"
-
-extern int DEBUGLEVEL;
-
-#if USE_READ_PREDICTION
-
-/* variables used by the read prediction module */
-static int rp_fd = -1;
-static SMB_OFF_T rp_offset = 0;
-static ssize_t rp_length = 0;
-static ssize_t rp_alloced = 0;
-static int rp_predict_fd = -1;
-static SMB_OFF_T rp_predict_offset = 0;
-static size_t rp_predict_length = 0;
-static int rp_timeout = 5;
-static time_t rp_time = 0;
-static char *rp_buffer = NULL;
-static BOOL predict_skip=False;
-extern struct timeval smb_last_time;
-
-/****************************************************************************
-handle read prediction on a file
-****************************************************************************/
-ssize_t read_predict(files_struct *fsp, int fd,SMB_OFF_T offset,char *buf,char **ptr,size_t num)
-{
- ssize_t ret = 0;
- ssize_t possible = rp_length - (offset - rp_offset);
-
- possible = MIN(possible,num);
-
- /* give data if possible */
- if (fd == rp_fd &&
- offset >= rp_offset &&
- possible>0 &&
- smb_last_time.tv_secs - rp_time < rp_timeout)
- {
- ret = possible;
- if (buf)
- memcpy(buf,rp_buffer + (offset-rp_offset),possible);
- else
- *ptr = rp_buffer + (offset-rp_offset);
- DEBUG(5,("read-prediction gave %d bytes of %d\n",ret,num));
- }
-
- if (ret == num) {
- predict_skip = True;
- } else {
- SMB_STRUCT_STAT rp_stat;
-
- /* Find the end of the file - ensure we don't
- read predict beyond it. */
- if(fsp->conn->vfs_ops.fstat(fd,&rp_stat) < 0)
- {
- DEBUG(0,("read-prediction failed on fstat. Error was %s\n", strerror(errno)));
- predict_skip = True;
- }
- else
- {
- predict_skip = False;
-
- /* prepare the next prediction */
- rp_predict_fd = fd;
- /* Make sure we don't seek beyond the end of the file. */
- rp_predict_offset = MIN((offset + num),rp_stat.st_size);
- rp_predict_length = num;
- }
- }
-
- if (ret < 0) ret = 0;
-
- return(ret);
-}
-
-/****************************************************************************
-pre-read some data
-****************************************************************************/
-void do_read_prediction(connection_struct *conn)
-{
- static size_t readsize = 0;
-
- if (predict_skip) return;
-
- if (rp_predict_fd == -1)
- return;
-
- rp_fd = rp_predict_fd;
- rp_offset = rp_predict_offset;
- rp_length = 0;
-
- rp_predict_fd = -1;
-
- if (readsize == 0) {
- readsize = lp_readsize();
- readsize = MAX(readsize,1024);
- }
-
- rp_predict_length = MIN(rp_predict_length,2*readsize);
- rp_predict_length = MAX(rp_predict_length,1024);
- rp_offset = (rp_offset/1024)*1024;
- rp_predict_length = (rp_predict_length/1024)*1024;
-
- if (rp_predict_length > rp_alloced)
- {
- rp_buffer = Realloc(rp_buffer,rp_predict_length);
- rp_alloced = rp_predict_length;
- if (!rp_buffer)
- {
- DEBUG(0,("can't allocate read-prediction buffer\n"));
- rp_predict_fd = -1;
- rp_fd = -1;
- rp_alloced = 0;
- return;
- }
- }
-
- if (conn->vfs_ops.lseek(rp_fd,rp_offset,SEEK_SET) != rp_offset) {
- rp_fd = -1;
- rp_predict_fd = -1;
- return;
- }
-
- rp_length = conn->vfs_ops.read(rp_fd,rp_buffer,rp_predict_length);
- rp_time = time(NULL);
- if (rp_length < 0)
- rp_length = 0;
-}
-
-/****************************************************************************
-invalidate read-prediction on a fd
-****************************************************************************/
-void invalidate_read_prediction(int fd)
-{
- if (rp_fd == fd)
- rp_fd = -1;
- if (rp_predict_fd == fd)
- rp_predict_fd = -1;
-}
-
-#else
- void read_prediction_dummy(void) ;
-#endif
#endif
}
- /* If softlimit is zero, set it equal to hardlimit.
- */
-
- if (D.dqb_bsoftlimit==0)
- D.dqb_bsoftlimit = D.dqb_bhardlimit;
/* Use softlimit to determine disk space. A user exceeding the quota is told
* that there's no space left. Writes might actually work for a bit if the
return (False);
}
- /* If softlimit is zero, set it equal to hardlimit.
- */
-
- if (D.dqb_bsoftlimit==0)
- D.dqb_bsoftlimit = D.dqb_bhardlimit;
-
/* Use softlimit to determine disk space, except when it has been exceeded */
if (D.dqb_bsoftlimit==0)
}
else return(False);
}
-
- /* If softlimit is zero, set it equal to hardlimit.
- */
-
- if (D.dqb_bsoftlimit==0)
- D.dqb_bsoftlimit = D.dqb_bhardlimit;
-
if (D.dqb_bsoftlimit==0)
return(False);
/* Use softlimit to determine disk space, except when it has been exceeded */
return(False);
}
- /* If softlimit is zero, set it equal to hardlimit.
- */
-
- if (D.dqb_bsoftlimit==0)
- D.dqb_bsoftlimit = D.dqb_bhardlimit;
-
/* Use softlimit to determine disk space. A user exceeding the quota is told
* that there's no space left. Writes might actually work for a bit if the
* hardlimit is set higher than softlimit. Effectively the disk becomes
dev);
/*
- * map from DOS codepage format to Unix
+ * Ensure the user and password names are in UNIX codepage format.
*/
dos_to_unix(user, True);
/****************************************************************************
- reply to a tcon and X
+ Reply to a tcon and X.
****************************************************************************/
int reply_tcon_and_X(connection_struct * conn, char *inbuf, char *outbuf,
int length, int bufsize)
pstring user;
pstring password;
pstring devicename;
+ BOOL doencrypt = SMBENCRYPT();
int ecode = -1;
uint16 vuid = SVAL(inbuf, smb_uid);
int passlen = SVAL(inbuf, smb_vwv3);
char *path;
char *p;
- BOOL doencrypt = SMBENCRYPT();
*service = *user = *password = *devicename = 0;
DEBUG(4, ("Got device type %s\n", devicename));
/*
- * map from DOS codepage format to Unix
+ * Ensure the user and password names are in UNIX codepage format.
*/
dos_to_unix(user, True);
if (!fsp)
return (ERROR(ERRSRV, ERRnofids));
- if (!check_name(fname, conn))
- {
- if ((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return (UNIXERROR(ERRDOS, ERRnoaccess));
- }
-
unixmode = unix_mode(conn, aARCH, fname);
open_file_shared(fsp, conn, fname, share_mode,
return (UNIXERROR(ERRDOS, ERRnoaccess));
}
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd, &sbuf) != 0)
+ if (fsp->conn->vfs_ops.fstat(fsp->fd, &sbuf) != 0)
{
close_file(fsp, False);
return (ERROR(ERRDOS, ERRnoaccess));
if (!fsp)
return (ERROR(ERRSRV, ERRnofids));
- if (!check_name(fname, conn))
- {
- if ((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return (UNIXERROR(ERRDOS, ERRnoaccess));
- }
-
unixmode = unix_mode(conn, smb_attr | aARCH, fname);
open_file_shared(fsp, conn, fname, smb_mode, smb_ofun, unixmode,
return (UNIXERROR(ERRDOS, ERRnoaccess));
}
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd, &sbuf) != 0)
+ if (fsp->conn->vfs_ops.fstat(fsp->fd, &sbuf) != 0)
{
close_file(fsp, False);
return (ERROR(ERRDOS, ERRnoaccess));
if (!fsp)
return (ERROR(ERRSRV, ERRnofids));
- if (!check_name(fname, conn))
- {
- if ((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return (UNIXERROR(ERRDOS, ERRnoaccess));
- }
-
if (com == SMBmknew)
{
/* We should fail if file exists. */
DEBUG(2, ("new file %s\n", fname));
DEBUG(3, ("mknew %s fd=%d dmode=%d umode=%o\n",
- fname, fsp->fd_ptr->fd, createmode, (int)unixmode));
+ fname, fsp->fd, createmode, (int)unixmode));
return (outsize);
}
if (fsp)
return (ERROR(ERRSRV, ERRnofids));
- if (!check_name(fname, conn))
- {
- if ((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return (UNIXERROR(ERRDOS, ERRnoaccess));
- }
-
pstrcpy(fname2, (char *)smbd_mktemp(fname));
/* Open file in dos compatibility share mode. */
DEBUG(2, ("created temp file %s\n", fname2));
DEBUG(3, ("ctemp %s fd=%d dmode=%d umode=%o\n",
- fname2, fsp->fd_ptr->fd, createmode, (int)unixmode));
+ fname2, fsp->fd, createmode, (int)unixmode));
return (outsize);
}
directory, dname);
if (!can_delete(fname, conn, dirtype))
continue;
- if (!conn->
- vfs_ops.unlink(dos_to_unix(fname, False)))
+ if (!conn->vfs_ops.
+ unlink(dos_to_unix(fname, False)))
count++;
DEBUG(3,
("reply_unlink : doing unlink on %s\n",
if (size < sizeneeded)
{
SMB_STRUCT_STAT st;
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd, &st) ==
- 0)
+ if (fsp->conn->vfs_ops.fstat(fsp->fd, &st) == 0)
size = st.st_size;
if (!fsp->can_write)
fsp->size = size;
#if USE_READ_PREDICTION
if (!fsp->can_write)
predict =
- read_predict(fsp, fsp->fd_ptr->fd, startpos,
+ read_predict(fsp, fsp->fd, startpos,
header + 4, NULL, nread);
#endif /* USE_READ_PREDICTION */
if (!seek_fail)
ret =
- (ssize_t) vfs_transfer_file(-1,
- fsp->fd_ptr->fd,
+ (ssize_t) vfs_transfer_file(-1, fsp->fd,
Client, NULL,
(SMB_OFF_T) (nread
-
if ((lp_syncalways(SNUM(conn)) || write_through) &&
lp_strict_sync(SNUM(conn)))
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
DEBUG(3, ("writebraw2 fnum=%d start=%.0f num=%d wrote=%d\n",
fsp->fnum, (double)startpos, (int)numtowrite,
nwritten = write_file(fsp, data, startpos, numtowrite);
if (lp_syncalways(SNUM(conn)))
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if (((nwritten == 0) && (numtowrite != 0)) || (nwritten < 0))
return (UNIXERROR(ERRDOS, ERRnoaccess));
truncated to the size given in smb_vwv[2-3] */
if (numtowrite == 0)
{
- if (
- (nwritten =
- set_filelen(fsp->fd_ptr->fd, (SMB_OFF_T) startpos)) >= 0) /* tpot vfs */
+ if ((nwritten = set_filelen(fsp->fd, (SMB_OFF_T) startpos)) >= 0) /* tpot vfs */
set_filelen_write_cache(fsp, startpos);
}
else
nwritten = write_file(fsp, data, startpos, numtowrite);
if (lp_syncalways(SNUM(conn)))
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if (((nwritten == 0) && (numtowrite != 0)) || (nwritten < 0))
return (UNIXERROR(ERRDOS, ERRnoaccess));
fsp->fnum, (int)numtowrite, (int)nwritten));
if (lp_syncalways(SNUM(conn)) || write_through)
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
return chain_reply(inbuf, outbuf, length, bufsize);
}
break;
}
- if ((res = conn->vfs_ops.lseek(fsp->fd_ptr->fd, startpos, umode)) ==
- -1)
+ if ((res = conn->vfs_ops.lseek(fsp->fd, startpos, umode)) == -1)
{
/*
* Check for the special case where a seek before the start
if (
(current_pos =
- conn->vfs_ops.lseek(fsp->fd_ptr->fd, 0,
+ conn->vfs_ops.lseek(fsp->fd, 0,
SEEK_CUR)) == -1)
return (UNIXERROR
(ERRDOS, ERRnoaccess));
SMB_STRUCT_STAT sbuf;
- if (conn->
- vfs_ops.fstat(fsp->fd_ptr->fd,
- &sbuf) == -1)
+ if (conn->vfs_ops.fstat(fsp->fd, &sbuf) == -1)
return (UNIXERROR
(ERRDOS, ERRnoaccess));
if (current_pos < 0)
res =
- conn->vfs_ops.lseek(fsp->fd_ptr->fd,
- 0, SEEK_SET);
+ conn->vfs_ops.lseek(fsp->fd, 0,
+ SEEK_SET);
}
if (res == -1)
}
else
{
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
}
DEBUG(3, ("flush\n"));
set_filetime(conn, fsp->fsp_name, mtime);
DEBUG(3, ("close fd=%d fnum=%d (numopen=%d)\n",
- fsp->fd_ptr ? fsp->fd_ptr->fd : -1, fsp->fnum,
- conn->num_files_open));
+ fsp->fd, fsp->fnum, conn->num_files_open));
/*
* close_file() returns the unix errno if an error
offset = IVAL(inbuf, smb_vwv3);
DEBUG(3, ("lock fd=%d fnum=%d offset=%.0f count=%.0f\n",
- fsp->fd_ptr->fd, fsp->fnum, (double)offset, (double)count));
+ fsp->fd, fsp->fnum, (double)offset, (double)count));
if (!do_lock(fsp, conn, count, offset, WRITE_LOCK, &eclass, &ecode))
{
return (ERROR(eclass, ecode));
DEBUG(3, ("unlock fd=%d fnum=%d offset=%.0f count=%.0f\n",
- fsp->fd_ptr->fd, fsp->fnum, (double)offset, (double)count));
+ fsp->fd, fsp->fnum, (double)offset, (double)count));
return (outsize);
}
int reply_printopen(connection_struct * conn,
char *inbuf, char *outbuf, int dum_size, int dum_buffsize)
{
- pstring fname;
- pstring fname2;
int outsize = 0;
files_struct *fsp;
- *fname = *fname2 = 0;
-
if (!CAN_PRINT(conn))
return (ERROR(ERRDOS, ERRnoaccess));
- {
- pstring s;
- char *p;
- pstrcpy(s, smb_buf(inbuf) + 1);
- p = s;
- while (*p)
- {
- if (!(isalnum((int)*p) || strchr("._-", *p)))
- *p = 'X';
- p++;
- }
-
- if (strlen(s) > 10)
- s[10] = 0;
-
- slprintf(fname, sizeof(fname) - 1, "%s.XXXXXX", s);
- }
-
fsp = file_new();
if (!fsp)
return (ERROR(ERRSRV, ERRnofids));
- pstrcpy(fname2, (char *)smbd_mktemp(fname));
-
- if (!check_name(fname2, conn))
- {
- file_free(fsp);
- return (ERROR(ERRDOS, ERRnoaccess));
- }
-
/* Open for exclusive use, write only. */
- open_file_shared(fsp, conn, fname2,
- SET_DENY_MODE(DENY_ALL) |
- SET_OPEN_MODE(DOS_OPEN_WRONLY),
- (FILE_CREATE_IF_NOT_EXIST | FILE_EXISTS_FAIL),
- unix_mode(conn, 0, fname2), 0, NULL, NULL);
+ print_open_file(fsp, conn, "dos.prn");
if (!fsp->open)
{
return (UNIXERROR(ERRDOS, ERRnoaccess));
}
- /* force it to be a print file */
- fsp->print_file = True;
-
outsize = set_message(outbuf, 1, 0, True);
SSVAL(outbuf, smb_vwv0, fsp->fnum);
- DEBUG(3, ("openprint %s fd=%d fnum=%d\n",
- fname2, fsp->fd_ptr->fd, fsp->fnum));
+ DEBUG(3, ("openprint fd=%d fnum=%d\n", fsp->fd, fsp->fnum));
return (outsize);
}
if (!CAN_PRINT(conn))
return (ERROR(ERRDOS, ERRnoaccess));
- DEBUG(3, ("printclose fd=%d fnum=%d\n", fsp->fd_ptr->fd, fsp->fnum));
+ DEBUG(3, ("printclose fd=%d fnum=%d\n", fsp->fd, fsp->fnum));
close_err = close_file(fsp, True);
ret = True;
break;
}
- if (conn->
- vfs_ops.rmdir(dos_to_unix(fullname, False)) != 0)
+ if (conn->vfs_ops.
+ rmdir(dos_to_unix(fullname, False)) != 0)
{
ret = True;
break;
pstrcat(fullname, "/");
pstrcat(fullname, dname);
- if (conn->vfs_ops.lstat(dos_to_unix
- (fullname,
- False),
+ if (conn->vfs_ops.
+ lstat(dos_to_unix
+ (fullname, False),
&st) != 0)
break;
if (st.st_mode & S_IFDIR)
fullname) != 0)
break;
}
- if (conn->
- vfs_ops.rmdir(dos_to_unix
+ if (conn->vfs_ops.
+ rmdir(dos_to_unix
(fullname,
- False)) !=
- 0)
+ False)) != 0)
break;
}
- else if (conn->
- vfs_ops.unlink(dos_to_unix
+ else if (conn->vfs_ops.
+ unlink(dos_to_unix
(fullname,
False)) != 0)
break;
CloseDir(dirptr);
/* Retry the rmdir */
ok =
- (conn->
- vfs_ops.rmdir(dos_to_unix
- (directory, False)) == 0);
+ (conn->vfs_ops.
+ rmdir(dos_to_unix(directory, False)) ==
+ 0);
}
else
CloseDir(dirptr);
continue;
}
- if (!conn->
- vfs_ops.rename(dos_to_unix(fname, False),
- dos_to_unix(destname,
- False)))
+ if (!conn->vfs_ops.
+ rename(dos_to_unix(fname, False),
+ dos_to_unix(destname, False)))
count++;
DEBUG(3,
("rename_internals: doing rename on %s -> %s\n",
if ((ofun & 3) == 1)
{
- if (conn->vfs_ops.lseek(fsp2->fd_ptr->fd, 0, SEEK_END) == -1)
+ if (conn->vfs_ops.lseek(fsp2->fd, 0, SEEK_END) == -1)
{
DEBUG(0,
("copy_file: error - sys_lseek returned error %s\n",
nwritten = write_file(fsp, data, startpos, numtowrite);
if (lp_syncalways(SNUM(conn)) || write_through)
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if (nwritten < (ssize_t) numtowrite)
return (UNIXERROR(ERRHRD, ERRdiskfull));
nwritten = write_file(fsp, data, startpos, numtowrite);
if (lp_syncalways(SNUM(conn)) || write_through)
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if (nwritten < (ssize_t) numtowrite)
{
CHECK_ERROR(fsp);
/* Do an fstat on this file */
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd, &sbuf))
+ if (fsp->conn->vfs_ops.fstat(fsp->fd, &sbuf))
return (UNIXERROR(ERRDOS, ERRnoaccess));
mode = dos_mode(conn, fsp->fsp_name, &sbuf);
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
CHECK_ERROR(fsp);
fname = fsp->fsp_name;
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
DEBUG(3,("fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
return(UNIXERROR(ERRDOS,ERRbadfid));
}
- if((pos = fsp->conn->vfs_ops.lseek(fsp->fd_ptr->fd,0,SEEK_CUR)) == -1)
+ if((pos = fsp->conn->vfs_ops.lseek(fsp->fd,0,SEEK_CUR)) == -1)
return(UNIXERROR(ERRDOS,ERRnoaccess));
- delete_pending = fsp->fd_ptr->delete_on_close;
+ delete_pending = fsp->delete_on_close;
}
} else {
/* qpathinfo */
CHECK_ERROR(fsp);
fname = fsp->fsp_name;
- fd = fsp->fd_ptr->fd;
+ fd = fsp->fd;
if (fsp->conn->vfs_ops.fstat(fd,&st) != 0) {
DEBUG(3,("fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
{
int i;
files_struct *iterate_fsp;
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
+ SMB_DEV_T dev = fsp->dev;
+ SMB_INO_T inode = fsp->inode;
int num_share_modes;
share_mode_entry *current_shares = NULL;
- if(lock_share_entry(fsp->conn, dev, inode) == False)
+ if (lock_share_entry_fsp(fsp) == False)
return(ERROR(ERRDOS,ERRnoaccess));
/*
* Release the lock.
*/
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
/*
* current_shares was malloced by get_share_modes - free it here.
* counted struct. Delete when the last reference
* goes away.
*/
- fsp->fd_ptr->delete_on_close = delete_on_close;
+ fsp->delete_on_close = delete_on_close;
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
DEBUG(10, ("call_trans2setfilepathinfo: %s delete on close flag for fnum = %d, file %s\n",
delete_on_close ? "Added" : "Removed", fsp->fnum, fsp->fsp_name ));
{
size_t total=0;
ssize_t ret;
- int fd = fsp->fd_ptr->fd;
while (total < N)
{
- ret = fsp->conn->vfs_ops.write(fd,buffer + total,N - total);
+ ret = fsp->conn->vfs_ops.write(fsp->fd,buffer + total,N - total);
if (ret == -1) return -1;
if (ret == 0) return total;
if (s > ret) {
ret += in_fsp ?
- in_fsp->conn->vfs_ops.read(in_fsp->fd_ptr->fd,buf1+ret,s-ret) : read(in_fd,buf1+ret,s-ret);
+ in_fsp->conn->vfs_ops.read(in_fsp->fd,buf1+ret,s-ret) : read(in_fd,buf1+ret,s-ret);
}
if (ret > 0)
{
if (out_fsp) {
- ret2 = out_fsp->conn->vfs_ops.write(out_fsp->fd_ptr->fd,buf1,ret);
+ ret2 = out_fsp->conn->vfs_ops.write(out_fsp->fd,buf1,ret);
} else {
ret2= (out_fd != -1) ? write_data(out_fd,buf1,ret) : ret;
}
if ((p=smbw_getshared("PREFIX"))) {
slprintf(smbw_prefix,sizeof(fstring)-1, "/%s/", p);
- string_sub(smbw_prefix,"//", "/");
+ string_sub(smbw_prefix,"//", "/", 0);
DEBUG(2,("SMBW_PREFIX is %s\n", smbw_prefix));
}