1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

r3458: more solaris portability fixes, the main one being that we can't use a

structure element called "open" as its a macro on solaris.
(This used to be commit 4e92e15c4e)
This commit is contained in:
Andrew Tridgell 2004-11-02 04:17:30 +00:00 committed by Gerald (Jerry) Carter
parent 5011f901aa
commit 8692564e35
10 changed files with 86 additions and 207 deletions

View File

@ -189,16 +189,6 @@ extern char *sys_errlist[];
extern int errno;
#endif
#ifdef HAVE_BROKEN_GETGROUPS
#define GID_T int
#else
#define GID_T gid_t
#endif
#ifndef NGROUPS_MAX
#define NGROUPS_MAX 32 /* Guess... */
#endif
/* Our own pstrings and fstrings */
#include "pstring.h"

View File

@ -1128,7 +1128,7 @@ union smb_open {
uint32_t size;
uint16_t rmode;
} out;
} open;
} openold;
/* SMBopenX interface */
struct {

View File

@ -64,3 +64,7 @@ int initgroups(char *name,gid_t id);
#define crypt ufc_crypt
#endif
#ifndef NGROUPS_MAX
#define NGROUPS_MAX 32 /* Guess... */
#endif

View File

@ -19,6 +19,7 @@
*/
#include "includes.h"
#include "system/wait.h"
static void (*cont_fn)(void *);

View File

@ -335,122 +335,6 @@ void sys_srandom(uint_t seed)
#endif
}
/**************************************************************************
Returns equivalent to NGROUPS_MAX - using sysconf if needed.
****************************************************************************/
int groups_max(void)
{
#if defined(SYSCONF_SC_NGROUPS_MAX)
int ret = sysconf(_SC_NGROUPS_MAX);
return (ret == -1) ? NGROUPS_MAX : ret;
#else
return NGROUPS_MAX;
#endif
}
/**************************************************************************
Wrapper for getgroups. Deals with broken (int) case.
****************************************************************************/
int sys_getgroups(int setlen, gid_t *gidset)
{
#if !defined(HAVE_BROKEN_GETGROUPS)
return getgroups(setlen, gidset);
#else
GID_T gid;
GID_T *group_list;
int i, ngroups;
if(setlen == 0) {
return getgroups(setlen, &gid);
}
/*
* Broken case. We need to allocate a
* GID_T array of size setlen.
*/
if(setlen < 0) {
errno = EINVAL;
return -1;
}
if (setlen == 0)
setlen = groups_max();
if((group_list = (GID_T *)malloc(setlen * sizeof(GID_T))) == NULL) {
DEBUG(0,("sys_getgroups: Malloc fail.\n"));
return -1;
}
if((ngroups = getgroups(setlen, group_list)) < 0) {
int saved_errno = errno;
SAFE_FREE(group_list);
errno = saved_errno;
return -1;
}
for(i = 0; i < ngroups; i++)
gidset[i] = (gid_t)group_list[i];
SAFE_FREE(group_list);
return ngroups;
#endif /* HAVE_BROKEN_GETGROUPS */
}
#ifdef HAVE_SETGROUPS
/**************************************************************************
Wrapper for setgroups. Deals with broken (int) case. Automatically used
if we have broken getgroups.
****************************************************************************/
int sys_setgroups(int setlen, gid_t *gidset)
{
#if !defined(HAVE_BROKEN_GETGROUPS)
return setgroups(setlen, gidset);
#else
GID_T *group_list;
int i ;
if (setlen == 0)
return 0 ;
if (setlen < 0 || setlen > groups_max()) {
errno = EINVAL;
return -1;
}
/*
* Broken case. We need to allocate a
* GID_T array of size setlen.
*/
if((group_list = (GID_T *)malloc(setlen * sizeof(GID_T))) == NULL) {
DEBUG(0,("sys_setgroups: Malloc fail.\n"));
return -1;
}
for(i = 0; i < setlen; i++)
group_list[i] = (GID_T) gidset[i];
if(setgroups(setlen, group_list) != 0) {
int saved_errno = errno;
SAFE_FREE(group_list);
errno = saved_errno;
return -1;
}
SAFE_FREE(group_list);
return 0 ;
#endif /* HAVE_BROKEN_GETGROUPS */
}
#endif /* HAVE_SETGROUPS */
struct passwd *sys_getpwent(void)
{
return getpwent();

View File

@ -300,15 +300,15 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope
int len;
struct smbcli_request *req = NULL;
switch (parms->open.level) {
switch (parms->generic.level) {
case RAW_OPEN_T2OPEN:
return smb_raw_t2open_send(tree, parms);
case RAW_OPEN_OPEN:
SETUP_REQUEST(SMBopen, 2, 0);
SSVAL(req->out.vwv, VWV(0), parms->open.in.flags);
SSVAL(req->out.vwv, VWV(1), parms->open.in.search_attrs);
smbcli_req_append_ascii4(req, parms->open.in.fname, STR_TERMINATE);
SSVAL(req->out.vwv, VWV(0), parms->openold.in.flags);
SSVAL(req->out.vwv, VWV(1), parms->openold.in.search_attrs);
smbcli_req_append_ascii4(req, parms->openold.in.fname, STR_TERMINATE);
break;
case RAW_OPEN_OPENX:
@ -397,18 +397,18 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio
goto failed;
}
switch (parms->open.level) {
switch (parms->openold.level) {
case RAW_OPEN_T2OPEN:
return smb_raw_t2open_recv(req, mem_ctx, parms);
case RAW_OPEN_OPEN:
SMBCLI_CHECK_WCT(req, 7);
parms->open.out.fnum = SVAL(req->in.vwv, VWV(0));
parms->open.out.attrib = SVAL(req->in.vwv, VWV(1));
parms->open.out.write_time = raw_pull_dos_date3(req->transport,
parms->openold.out.fnum = SVAL(req->in.vwv, VWV(0));
parms->openold.out.attrib = SVAL(req->in.vwv, VWV(1));
parms->openold.out.write_time = raw_pull_dos_date3(req->transport,
req->in.vwv + VWV(2));
parms->open.out.size = IVAL(req->in.vwv, VWV(4));
parms->open.out.rmode = SVAL(req->in.vwv, VWV(6));
parms->openold.out.size = IVAL(req->in.vwv, VWV(4));
parms->openold.out.rmode = SVAL(req->in.vwv, VWV(6));
break;
case RAW_OPEN_OPENX:

View File

@ -221,39 +221,39 @@ NTSTATUS ntvfs_map_open(struct smbsrv_request *req, union smb_open *io,
case RAW_OPEN_OPEN:
ZERO_STRUCT(io2->generic.in);
io2->generic.level = RAW_OPEN_GENERIC;
io2->generic.in.file_attr = io->open.in.search_attrs;
io2->generic.in.fname = io->open.in.fname;
io2->generic.in.file_attr = io->openold.in.search_attrs;
io2->generic.in.fname = io->openold.in.fname;
io2->generic.in.open_disposition = NTCREATEX_DISP_OPEN;
DEBUG(9,("ntvfs_map_open(OPEN): mapping flags=0x%x\n",
io->open.in.flags));
switch (io->open.in.flags & OPEN_FLAGS_MODE_MASK) {
io->openold.in.flags));
switch (io->openold.in.flags & OPEN_FLAGS_MODE_MASK) {
case OPEN_FLAGS_OPEN_READ:
io2->generic.in.access_mask = GENERIC_RIGHTS_FILE_READ;
io->open.out.rmode = DOS_OPEN_RDONLY;
io->openold.out.rmode = DOS_OPEN_RDONLY;
break;
case OPEN_FLAGS_OPEN_WRITE:
io2->generic.in.access_mask = GENERIC_RIGHTS_FILE_WRITE;
io->open.out.rmode = DOS_OPEN_WRONLY;
io->openold.out.rmode = DOS_OPEN_WRONLY;
break;
case OPEN_FLAGS_OPEN_RDWR:
case 0xf: /* FCB mode */
io2->generic.in.access_mask = GENERIC_RIGHTS_FILE_READ |
GENERIC_RIGHTS_FILE_WRITE;
io->open.out.rmode = DOS_OPEN_RDWR; /* assume we got r/w */
io->openold.out.rmode = DOS_OPEN_RDWR; /* assume we got r/w */
break;
default:
DEBUG(2,("ntvfs_map_open(OPEN): invalid mode 0x%x\n",
io->open.in.flags & OPEN_FLAGS_MODE_MASK));
io->openold.in.flags & OPEN_FLAGS_MODE_MASK));
return NT_STATUS_INVALID_PARAMETER;
}
switch(io->open.in.flags & OPEN_FLAGS_DENY_MASK) {
switch(io->openold.in.flags & OPEN_FLAGS_DENY_MASK) {
case OPEN_FLAGS_DENY_DOS:
/* DENY_DOS is quite strange - it depends on the filename! */
if (is_exe_file(io->open.in.fname)) {
if (is_exe_file(io->openold.in.fname)) {
io2->generic.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
} else {
if ((io->open.in.flags & OPEN_FLAGS_MODE_MASK) ==
if ((io->openold.in.flags & OPEN_FLAGS_MODE_MASK) ==
OPEN_FLAGS_OPEN_READ) {
io2->generic.in.share_access = NTCREATEX_SHARE_ACCESS_READ;
} else {
@ -279,11 +279,11 @@ NTSTATUS ntvfs_map_open(struct smbsrv_request *req, union smb_open *io,
break;
default:
DEBUG(2,("ntvfs_map_open(OPEN): invalid DENY 0x%x\n",
io->open.in.flags & OPEN_FLAGS_DENY_MASK));
io->openold.in.flags & OPEN_FLAGS_DENY_MASK));
return NT_STATUS_INVALID_PARAMETER;
}
DEBUG(9,("ntvfs_map_open(OPEN): mapped flags=0x%x to access_mask=0x%x and share_access=0x%x\n",
io->open.in.flags, io2->generic.in.access_mask, io2->generic.in.share_access));
io->openold.in.flags, io2->generic.in.access_mask, io2->generic.in.share_access));
status = ntvfs->ops->open(ntvfs, req, io2);
if (!NT_STATUS_IS_OK(status)) {
@ -291,11 +291,11 @@ NTSTATUS ntvfs_map_open(struct smbsrv_request *req, union smb_open *io,
}
ZERO_STRUCT(io->openx.out);
io->open.out.fnum = io2->generic.out.fnum;
io->open.out.attrib = io2->generic.out.attrib;
io->open.out.write_time = nt_time_to_unix(io2->generic.out.write_time);
io->open.out.size = io2->generic.out.size;
io->open.out.rmode = DOS_OPEN_RDWR;
io->openold.out.fnum = io2->generic.out.fnum;
io->openold.out.attrib = io2->generic.out.attrib;
io->openold.out.write_time = nt_time_to_unix(io2->generic.out.write_time);
io->openold.out.size = io2->generic.out.size;
io->openold.out.rmode = DOS_OPEN_RDWR;
return NT_STATUS_OK;
}

View File

@ -407,11 +407,11 @@ static void reply_open_send(struct smbsrv_request *req)
/* construct reply */
req_setup_reply(req, 7, 0);
SSVAL(req->out.vwv, VWV(0), oi->open.out.fnum);
SSVAL(req->out.vwv, VWV(1), oi->open.out.attrib);
srv_push_dos_date3(req->smb_conn, req->out.vwv, VWV(2), oi->open.out.write_time);
SIVAL(req->out.vwv, VWV(4), oi->open.out.size);
SSVAL(req->out.vwv, VWV(6), oi->open.out.rmode);
SSVAL(req->out.vwv, VWV(0), oi->openold.out.fnum);
SSVAL(req->out.vwv, VWV(1), oi->openold.out.attrib);
srv_push_dos_date3(req->smb_conn, req->out.vwv, VWV(2), oi->openold.out.write_time);
SIVAL(req->out.vwv, VWV(4), oi->openold.out.size);
SSVAL(req->out.vwv, VWV(6), oi->openold.out.rmode);
req_send_reply(req);
}
@ -427,13 +427,13 @@ void reply_open(struct smbsrv_request *req)
REQ_CHECK_WCT(req, 2);
REQ_TALLOC(oi, sizeof(*oi));
oi->open.level = RAW_OPEN_OPEN;
oi->open.in.flags = SVAL(req->in.vwv, VWV(0));
oi->open.in.search_attrs = SVAL(req->in.vwv, VWV(1));
oi->openold.level = RAW_OPEN_OPEN;
oi->openold.in.flags = SVAL(req->in.vwv, VWV(0));
oi->openold.in.search_attrs = SVAL(req->in.vwv, VWV(1));
req_pull_ascii4(req, &oi->open.in.fname, req->in.data, STR_TERMINATE);
req_pull_ascii4(req, &oi->openold.in.fname, req->in.data, STR_TERMINATE);
if (!oi->open.in.fname) {
if (!oi->openold.in.fname) {
req_reply_error(req, NT_STATUS_OBJECT_NAME_NOT_FOUND);
return;
}
@ -1396,7 +1396,7 @@ static void reply_printopen_send(struct smbsrv_request *req)
/* construct reply */
req_setup_reply(req, 1, 0);
SSVAL(req->out.vwv, VWV(0), oi->open.out.fnum);
SSVAL(req->out.vwv, VWV(0), oi->openold.out.fnum);
req_send_reply(req);
}

View File

@ -1085,27 +1085,27 @@ static BOOL handler_open(int instance)
union smb_open parm[NSERVERS];
NTSTATUS status[NSERVERS];
parm[0].open.level = RAW_OPEN_OPEN;
parm[0].open.in.flags = gen_bits_mask2(0xF, 0xFFFF);
parm[0].open.in.search_attrs = gen_attrib();
parm[0].open.in.fname = gen_fname_open(instance);
parm[0].openold.level = RAW_OPEN_OPEN;
parm[0].openold.in.flags = gen_bits_mask2(0xF, 0xFFFF);
parm[0].openold.in.search_attrs = gen_attrib();
parm[0].openold.in.fname = gen_fname_open(instance);
if (!options.use_oplocks) {
/* mask out oplocks */
parm[0].open.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
parm[0].openold.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
}
GEN_COPY_PARM;
GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
CHECK_EQUAL(open.out.attrib);
CHECK_TIMES_EQUAL(open.out.write_time);
CHECK_EQUAL(open.out.size);
CHECK_EQUAL(open.out.rmode);
CHECK_EQUAL(openold.out.attrib);
CHECK_TIMES_EQUAL(openold.out.write_time);
CHECK_EQUAL(openold.out.size);
CHECK_EQUAL(openold.out.rmode);
/* open creates a new file handle */
ADD_HANDLE(parm[0].open.in.fname, open.out.fnum);
ADD_HANDLE(parm[0].openold.in.fname, openold.out.fnum);
return True;
}

View File

@ -157,13 +157,13 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("Checking RAW_OPEN_OPEN\n");
io.open.level = RAW_OPEN_OPEN;
io.open.in.fname = fname;
io.open.in.flags = OPEN_FLAGS_FCB;
io.open.in.search_attrs = 0;
io.openold.level = RAW_OPEN_OPEN;
io.openold.in.fname = fname;
io.openold.in.flags = OPEN_FLAGS_FCB;
io.openold.in.search_attrs = 0;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
smbcli_unlink(cli->tree, fname);
CREATE_FILE;
@ -171,80 +171,80 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
CHECK_RDWR(fnum, RDWR_RDWR);
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum2 = io.open.out.fnum;
fnum2 = io.openold.out.fnum;
CHECK_RDWR(fnum2, RDWR_RDWR);
smbcli_close(cli->tree, fnum2);
smbcli_close(cli->tree, fnum);
/* check the read/write modes */
io.open.level = RAW_OPEN_OPEN;
io.open.in.fname = fname;
io.open.in.search_attrs = 0;
io.openold.level = RAW_OPEN_OPEN;
io.openold.in.fname = fname;
io.openold.in.search_attrs = 0;
io.open.in.flags = OPEN_FLAGS_OPEN_READ;
io.openold.in.flags = OPEN_FLAGS_OPEN_READ;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
CHECK_RDWR(fnum, RDWR_RDONLY);
smbcli_close(cli->tree, fnum);
io.open.in.flags = OPEN_FLAGS_OPEN_WRITE;
io.openold.in.flags = OPEN_FLAGS_OPEN_WRITE;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
CHECK_RDWR(fnum, RDWR_WRONLY);
smbcli_close(cli->tree, fnum);
io.open.in.flags = OPEN_FLAGS_OPEN_RDWR;
io.openold.in.flags = OPEN_FLAGS_OPEN_RDWR;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
CHECK_RDWR(fnum, RDWR_RDWR);
smbcli_close(cli->tree, fnum);
/* check the share modes roughly - not a complete matrix */
io.open.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
io.openold.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
CHECK_RDWR(fnum, RDWR_RDWR);
if (io.open.in.flags != io.open.out.rmode) {
if (io.openold.in.flags != io.openold.out.rmode) {
printf("(%s) rmode should equal flags - 0x%x 0x%x\n",
__location__, io.open.out.rmode, io.open.in.flags);
__location__, io.openold.out.rmode, io.openold.in.flags);
}
io.open.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
io.openold.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
io.open.in.flags = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
io.openold.in.flags = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum2 = io.open.out.fnum;
fnum2 = io.openold.out.fnum;
CHECK_RDWR(fnum2, RDWR_RDONLY);
smbcli_close(cli->tree, fnum);
smbcli_close(cli->tree, fnum2);
/* check the returned write time */
io.open.level = RAW_OPEN_OPEN;
io.open.in.fname = fname;
io.open.in.search_attrs = 0;
io.open.in.flags = OPEN_FLAGS_OPEN_READ;
io.openold.level = RAW_OPEN_OPEN;
io.openold.in.fname = fname;
io.openold.in.search_attrs = 0;
io.openold.in.flags = OPEN_FLAGS_OPEN_READ;
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
fnum = io.open.out.fnum;
fnum = io.openold.out.fnum;
/* check other reply fields */
CHECK_TIME(io.open.out.write_time, write_time);
CHECK_ALL_INFO(io.open.out.size, size);
CHECK_ALL_INFO(io.open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
CHECK_TIME(io.openold.out.write_time, write_time);
CHECK_ALL_INFO(io.openold.out.size, size);
CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
done:
smbcli_close(cli->tree, fnum);