NECESSARY_BECAUSE_SAMBA_DEPENDENCIES_ARE_SO_BROKEN_OBJ = \
libsmb/domain_client_validate.o smbd/auth_util.o \
- rpc_client/cli_netlogon.o rpc_client/cli_login.o
+ rpc_client/cli_netlogon.o rpc_client/cli_login.o
WINBINDD_OBJ = \
$(WINBINDD_OBJ1) $(NOPROTO_OBJ) $(PASSDB_OBJ) \
Authentication utility functions
Copyright (C) Andrew Tridgell 1992-1998
Copyright (C) Andrew Bartlett 2001
+ Copyright (C) Jeremy Allison 2000-2001
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
extern pstring global_myname;
/*******************************************************************
-Get the next challenge value - no repeats.
+ Get the next challenge value - no repeats.
********************************************************************/
+
void generate_next_challenge(char *challenge)
{
- unsigned char buf[8];
+ unsigned char buf[8];
- generate_random_buffer(buf,8,False);
+ generate_random_buffer(buf,8,False);
memcpy(saved_challenge, buf, 8);
memcpy(challenge,buf,8);
challenge_sent = True;
}
/*******************************************************************
-set the last challenge sent, usually from a password server
+ Set the last challenge sent, usually from a password server.
********************************************************************/
+
BOOL set_challenge(unsigned char *challenge)
{
memcpy(saved_challenge,challenge,8);
}
/*******************************************************************
-get the last challenge sent
+ Get the last challenge sent.
********************************************************************/
+
BOOL last_challenge(unsigned char *challenge)
{
- if (!challenge_sent) return(False);
+ if (!challenge_sent)
+ return(False);
memcpy(challenge,saved_challenge,8);
return(True);
}
-
/****************************************************************************
Create a UNIX user on demand.
****************************************************************************/
int ret;
pstrcpy(add_script, lp_adduser_script());
- if (! *add_script) return -1;
+ if (! *add_script)
+ return -1;
all_string_sub(add_script, "%u", unix_user, sizeof(pstring));
if (homedir)
all_string_sub(add_script, "%H", homedir, sizeof(pstring));
int ret;
pstrcpy(del_script, lp_deluser_script());
- if (! *del_script) return -1;
+ if (! *del_script)
+ return -1;
all_string_sub(del_script, "%u", unix_user, sizeof(pstring));
ret = smbrun(del_script,NULL);
DEBUG(3,("smb_delete_user: Running the command `%s' gave %d\n",del_script,ret));
if (home_dir &&
(sys_stat(home_dir, &st) == -1) && (errno == ENOENT)) {
- smb_create_user(user_info->internal_username.str, home_dir);
+ smb_create_user(user_info->internal_username.str, home_dir);
}
}
}
/***************************************************************************
Clear out a server_info struct that has been allocated
***************************************************************************/
+
void free_server_info(auth_serversupplied_info **server_info)
{
if (*server_info != NULL) {
pdb_free_sam(&(*server_info)->sam_account);
/* call pam_end here, unless we know we are keeping it */
- SAFE_FREE((*server_info)->group_rids);
-
+ delete_nt_token( &(*server_info)->ptok );
ZERO_STRUCT(**server_info);
}
SAFE_FREE(*server_info);
/***************************************************************************
Make a server_info struct for a guest user
***************************************************************************/
+
void make_server_info_guest(auth_serversupplied_info **server_info)
{
struct passwd *pass = sys_getpwnam(lp_guestaccount(-1));
}
}
+/****************************************************************************
+ Delete a SID token.
+****************************************************************************/
+
+void delete_nt_token(NT_USER_TOKEN **pptoken)
+{
+ if (*pptoken) {
+ NT_USER_TOKEN *ptoken = *pptoken;
+ SAFE_FREE( ptoken->user_sids );
+ ZERO_STRUCTP(ptoken);
+ }
+ SAFE_FREE(*pptoken);
+}
+
+/****************************************************************************
+ Duplicate a SID token.
+****************************************************************************/
+
+NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken)
+{
+ NT_USER_TOKEN *token;
+
+ if (!ptoken)
+ return NULL;
+
+ if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
+ return NULL;
+
+ ZERO_STRUCTP(token);
+
+ if ((token->user_sids = (DOM_SID *)memdup( ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids )) == NULL) {
+ SAFE_FREE(token);
+ return NULL;
+ }
+
+ token->num_sids = ptoken->num_sids;
+
+ return token;
+}
int n_groups;
gid_t *groups;
- /* NT group information taken from the info3 structure */
+ /* NT group information taken from the info3 structure */
- int n_rids;
- uint32 *group_rids;
+ NT_USER_TOKEN *ptok;
uchar session_key[16];
* token->user_sids[2-num_sids] = supplementary group SIDS.
*/
+#define PRIMARY_USER_SID_INDEX 0
+#define PRIMARY_GROUP_SID_INDEX 1
+
#ifndef _NT_USER_TOKEN
typedef struct _nt_user_token {
size_t num_sids;
continue;
}
- memcpy(f->buf + f->bufused, total+(char *)p, n);
+ memcpy(f->buf + f->bufused, total+(const char *)p, n);
f->bufused += n;
total += n;
}
if (f->buftype == X_IOLBF && f->bufused) {
int i;
for (i=size-1; i>=0; i--) {
- if (*(i+(char *)p) == '\n') {
+ if (*(i+(const char *)p) == '\n') {
x_fflush(f);
break;
}
{
if (data->has_error) return False;
if (data->length < data->ofs+len) {
- uint8 *p;
- p = Realloc(data->data, data->ofs+len);
- if (!p) {
+ uint8 *newp;
+ newp = Realloc(data->data, data->ofs+len);
+ if (!newp) {
SAFE_FREE(data->data);
data->has_error = True;
return False;
}
- data->data = p;
+ data->data = newp;
data->length = data->ofs+len;
}
memcpy(data->data + data->ofs, p, len);
BOOL asn1_write_OID(ASN1_DATA *data, const char *OID)
{
unsigned v, v2;
- char *p = (char *)OID;
+ const char *p = (const char *)OID;
+ char *newp;
- if (!asn1_push_tag(data, ASN1_OID)) return False;
- v = strtol(p, &p, 10);
- v2 = strtol(p, &p, 10);
- if (!asn1_write_uint8(data, 40*v + v2)) return False;
+ if (!asn1_push_tag(data, ASN1_OID))
+ return False;
+ v = strtol(p, &newp, 10);
+ p = newp;
+ v2 = strtol(p, &newp, 10);
+ p = newp;
+ if (!asn1_write_uint8(data, 40*v + v2))
+ return False;
while (*p) {
- v = strtol(p, &p, 10);
+ v = strtol(p, &newp, 10);
+ p = newp;
if (v >= (1<<28)) asn1_write_uint8(data, 0x80 | ((v>>28)&0xff));
if (v >= (1<<21)) asn1_write_uint8(data, 0x80 | ((v>>21)&0xff));
if (v >= (1<<14)) asn1_write_uint8(data, 0x80 | ((v>>14)&0xff));
if (v >= (1<<7)) asn1_write_uint8(data, 0x80 | ((v>>7)&0xff));
- if (!asn1_write_uint8(data, v&0x7f)) return False;
+ if (!asn1_write_uint8(data, v&0x7f))
+ return False;
}
return asn1_pop_tag(data);
}
Used in smbtorture.
****************************************************************************/
-int cli_nt_create_full(struct cli_state *cli, char *fname, uint32 DesiredAccess,
+int cli_nt_create_full(struct cli_state *cli, const char *fname, uint32 DesiredAccess,
uint32 FileAttributes, uint32 ShareAccess,
uint32 CreateDisposition, uint32 CreateOptions)
{
open a file
****************************************************************************/
-int cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess)
+int cli_nt_create(struct cli_state *cli, const char *fname, uint32 DesiredAccess)
{
return cli_nt_create_full(cli, fname, DesiredAccess, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_EXISTS_OPEN, 0x0);
open a file
WARNING: if you open with O_WRONLY then getattrE won't work!
****************************************************************************/
-int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode)
+int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode)
{
char *p;
unsigned openfn=0;
}
}
- /* Store the user group information in the server_info returned to
- the caller. */
+ /* Store the user group information in the server_info returned to the caller. */
- if (NT_STATUS_IS_OK(status)) {
- if (((*server_info)->group_rids = malloc(info3.num_groups2 *
- sizeof(uint32))) == NULL) {
- DEBUG(1, ("out of memory allocating rid group membership\n"));
+ if (NT_STATUS_IS_OK(status) && (info3.num_groups2 != 0)) {
+ DOM_SID domain_sid;
+ int i;
+ NT_USER_TOKEN *ptok;
+ auth_serversupplied_info *pserver_info = *server_info;
+
+ if ((pserver_info->ptok = malloc( sizeof(NT_USER_TOKEN) ) ) == NULL) {
+ DEBUG(0, ("domain_client_validate: out of memory allocating rid group membership\n"));
status = NT_STATUS_NO_MEMORY;
free_server_info(server_info);
- } else {
- int i;
-
- (*server_info)->n_rids = info3.num_groups2;
-
- for (i = 0; i < (*server_info)->n_rids; i++) {
- (*server_info)->group_rids[i] = info3.gids[i].g_rid;
- DEBUG(5, ("** adding group rid 0x%x\n",
- info3.gids[i].g_rid));
- }
+ goto done;
+ }
+
+ ptok = pserver_info->ptok;
+ ptok->num_sids = (size_t)info3.num_groups2;
+
+ if ((ptok->user_sids = (DOM_SID *)malloc( sizeof(DOM_SID) * ptok->num_sids )) == NULL) {
+ DEBUG(0, ("domain_client_validate: Out of memory allocating group SIDS\n"));
+ status = NT_STATUS_NO_MEMORY;
+ free_server_info(server_info);
+ goto done;
+ }
+
+ if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) {
+ DEBUG(0, ("domain_client_validate: unable to fetch domain sid.\n"));
+ status = NT_STATUS_NO_MEMORY;
+ free_server_info(server_info);
+ goto done;
+ }
+
+ for (i = 0; i < ptok->num_sids; i++) {
+ sid_copy(&ptok->user_sids[i], &domain_sid);
+ sid_append_rid(&ptok->user_sids[i], info3.gids[i].g_rid);
}
}
}
#endif /* 0 */
+ done:
+
/* Note - once the cli stream is shutdown the mem_ctx used
to allocate the other_sids and gids structures has been deleted - so
these pointers are no longer valid..... */
/****************************************************************************
compares two passwords. hmm, not as trivial as expected. hmm.
****************************************************************************/
-BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2)
+BOOL pwd_compare(const struct pwd_info *pwd1, const struct pwd_info *pwd2)
{
- if (pwd1->cleartext && pwd2->cleartext)
- {
+ if (pwd1->cleartext && pwd2->cleartext) {
if (strequal(pwd1->password, pwd2->password))
- {
return True;
- }
}
if (pwd1->null_pwd && pwd2->null_pwd)
- {
return True;
- }
if (!pwd1->null_pwd && !pwd2->null_pwd &&
- !pwd1->cleartext && !pwd2->cleartext)
- {
+ !pwd1->cleartext && !pwd2->cleartext) {
#ifdef DEBUG_PASSWORD
DEBUG(100,("pwd compare: nt#\n"));
dump_data(100, pwd1->smb_nt_pwd, 16);
dump_data(100, pwd2->smb_nt_pwd, 16);
#endif
if (memcmp(pwd1->smb_nt_pwd, pwd2->smb_nt_pwd, 16) == 0)
- {
return True;
- }
#ifdef DEBUG_PASSWORD
DEBUG(100,("pwd compare: lm#\n"));
dump_data(100, pwd1->smb_lm_pwd, 16);
dump_data(100, pwd2->smb_lm_pwd, 16);
#endif
if (memcmp(pwd1->smb_lm_pwd, pwd2->smb_lm_pwd, 16) == 0)
- {
return True;
- }
}
return False;
}
uchar trust_passwd[16];
struct in_addr *ip_list = NULL;
int count;
- uint16 validation_level;
fstring controller, trust_account;
int num_retries = 0;
global_myname);
#if 0 /* XXX */
+ {
+ uint16 validation_level;
status = cli_nt_setup_creds(controller, lp_workgroup(), global_myname,
trust_account, trust_passwd,
SEC_CHAN_WKSTA, &validation_level);
+ }
#endif
/* There is a race condition between fetching the trust account
Set the handle state.
****************************************************************************/
-static BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, char *pipe_name, uint16 device_state)
+static BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, const char *pipe_name, uint16 device_state)
{
BOOL state_set = False;
char param[2];
check the rpc bind acknowledge response
****************************************************************************/
-static BOOL valid_pipe_name(char *pipe_name, RPC_IFACE *abstract, RPC_IFACE *transfer)
+static BOOL valid_pipe_name(const char *pipe_name, RPC_IFACE *abstract, RPC_IFACE *transfer)
{
int pipe_idx = 0;
check the rpc bind acknowledge response
****************************************************************************/
-static BOOL check_bind_response(RPC_HDR_BA *hdr_ba, char *pipe_name, RPC_IFACE *transfer)
+static BOOL check_bind_response(RPC_HDR_BA *hdr_ba, const char *pipe_name, RPC_IFACE *transfer)
{
int i = 0;
Do an rpc bind.
****************************************************************************/
-BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, char *my_name)
+BOOL rpc_pipe_bind(struct cli_state *cli, const char *pipe_name, char *my_name)
{
RPC_IFACE abstract;
RPC_IFACE transfer;
Open a session.
****************************************************************************/
-BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name)
+BOOL cli_nt_session_open(struct cli_state *cli, const char *pipe_name)
{
int fnum;
SMB_ASSERT(cli->nt_pipe_fnum == 0);
if (cli->capabilities & CAP_NT_SMBS) {
- if ((fnum = cli_nt_create(cli, &(pipe_name[5]), DESIRED_ACCESS_PIPE)) == -1) {
+ if ((fnum = cli_nt_create(cli, &pipe_name[5], DESIRED_ACCESS_PIPE)) == -1) {
DEBUG(0,("cli_nt_session_open: cli_nt_create failed on pipe %s to machine %s. Error was %s\n",
- &(pipe_name[5]), cli->desthost, cli_errstr(cli)));
+ &pipe_name[5], cli->desthost, cli_errstr(cli)));
return False;
}
{
continue;
}
- if (!reuse && !pwd_compare((struct pwd_info *)&usr_creds->pwd, &c->cli->pwd))
+ if (!reuse && !pwd_compare(&usr_creds->pwd, &c->cli->pwd))
{
DEBUG(100, ("password doesn't match\n"));
continue;
return False;
}
/* if (!cli_nt_session_open(cli->smb, pipe_name, &cli->fnum)) by JERRY */
- if (!cli_nt_session_open(cli->smb, (char *)pipe_name))
+ if (!cli_nt_session_open(cli->smb, pipe_name))
{
cli_net_use_del(srv_name, ntc, False, NULL);
return False;
continue;
}
if (!reuse
- && !pwd_compare((struct pwd_info *)&usr_creds->pwd, &c->cli->smb->pwd))
+ && !pwd_compare(&usr_creds->pwd, &c->cli->smb->pwd))
{
DEBUG(100, ("password doesn't match\n"));
continue;
}
if (usr_creds->domain[0] == 0)
- {
return c;
- }
+
if (strequal(usr_creds->domain, c->cli->smb->domain))
- {
return c;
- }
}
return NULL;
/* Create an NT_USER_TOKEN struct for this user. */
p->pipe_user.nt_user_token = create_nt_token(p->pipe_user.uid,p->pipe_user.gid,
p->pipe_user.ngroups, p->pipe_user.groups,
- guest_user);
+ guest_user, NULL);
p->ntlmssp_auth_validated = True;
Authentication utility functions
Copyright (C) Andrew Tridgell 1992-1998
Copyright (C) Andrew Bartlett 2001
+ Copyright (C) Jeremy Allison 2000-2001
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
extern pstring global_myname;
/*******************************************************************
-Get the next challenge value - no repeats.
+ Get the next challenge value - no repeats.
********************************************************************/
+
void generate_next_challenge(char *challenge)
{
- unsigned char buf[8];
+ unsigned char buf[8];
- generate_random_buffer(buf,8,False);
+ generate_random_buffer(buf,8,False);
memcpy(saved_challenge, buf, 8);
memcpy(challenge,buf,8);
challenge_sent = True;
}
/*******************************************************************
-set the last challenge sent, usually from a password server
+ Set the last challenge sent, usually from a password server.
********************************************************************/
+
BOOL set_challenge(unsigned char *challenge)
{
memcpy(saved_challenge,challenge,8);
}
/*******************************************************************
-get the last challenge sent
+ Get the last challenge sent.
********************************************************************/
+
BOOL last_challenge(unsigned char *challenge)
{
- if (!challenge_sent) return(False);
+ if (!challenge_sent)
+ return(False);
memcpy(challenge,saved_challenge,8);
return(True);
}
-
/****************************************************************************
Create a UNIX user on demand.
****************************************************************************/
int ret;
pstrcpy(add_script, lp_adduser_script());
- if (! *add_script) return -1;
+ if (! *add_script)
+ return -1;
all_string_sub(add_script, "%u", unix_user, sizeof(pstring));
if (homedir)
all_string_sub(add_script, "%H", homedir, sizeof(pstring));
int ret;
pstrcpy(del_script, lp_deluser_script());
- if (! *del_script) return -1;
+ if (! *del_script)
+ return -1;
all_string_sub(del_script, "%u", unix_user, sizeof(pstring));
ret = smbrun(del_script,NULL);
DEBUG(3,("smb_delete_user: Running the command `%s' gave %d\n",del_script,ret));
if (home_dir &&
(sys_stat(home_dir, &st) == -1) && (errno == ENOENT)) {
- smb_create_user(user_info->internal_username.str, home_dir);
+ smb_create_user(user_info->internal_username.str, home_dir);
}
}
}
/***************************************************************************
Clear out a server_info struct that has been allocated
***************************************************************************/
+
void free_server_info(auth_serversupplied_info **server_info)
{
if (*server_info != NULL) {
pdb_free_sam(&(*server_info)->sam_account);
/* call pam_end here, unless we know we are keeping it */
- SAFE_FREE((*server_info)->group_rids);
-
+ delete_nt_token( &(*server_info)->ptok );
ZERO_STRUCT(**server_info);
}
SAFE_FREE(*server_info);
/***************************************************************************
Make a server_info struct for a guest user
***************************************************************************/
+
void make_server_info_guest(auth_serversupplied_info **server_info)
{
struct passwd *pass = sys_getpwnam(lp_guestaccount(-1));
}
}
+/****************************************************************************
+ Delete a SID token.
+****************************************************************************/
+
+void delete_nt_token(NT_USER_TOKEN **pptoken)
+{
+ if (*pptoken) {
+ NT_USER_TOKEN *ptoken = *pptoken;
+ SAFE_FREE( ptoken->user_sids );
+ ZERO_STRUCTP(ptoken);
+ }
+ SAFE_FREE(*pptoken);
+}
+
+/****************************************************************************
+ Duplicate a SID token.
+****************************************************************************/
+
+NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken)
+{
+ NT_USER_TOKEN *token;
+
+ if (!ptoken)
+ return NULL;
+
+ if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
+ return NULL;
+
+ ZERO_STRUCTP(token);
+
+ if ((token->user_sids = (DOM_SID *)memdup( ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids )) == NULL) {
+ SAFE_FREE(token);
+ return NULL;
+ }
+
+ token->num_sids = ptoken->num_sids;
+
+ return token;
+}
} else
sys_fsusage(path, dfree, dsize);
- if (disk_quotas((char *)path, &bsize_q, &dfree_q, &dsize_q)) {
+ if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) {
(*bsize) = bsize_q;
(*dfree) = MIN(*dfree,dfree_q);
(*dsize) = MIN(*dsize,dsize_q);
Create the SID list for this user.
****************************************************************************/
-NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups, BOOL is_guest)
+NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups, BOOL is_guest, NT_USER_TOKEN *sup_tok)
{
extern DOM_SID global_sid_World;
extern DOM_SID global_sid_Network;
/* We always have uid/gid plus World and Network and Authenticated Users or Guest SIDs. */
num_sids = 5 + ngroups;
+ if (sup_tok && sup_tok->num_sids)
+ num_sids += sup_tok->num_sids;
+
if ((token->user_sids = (DOM_SID *)malloc( num_sids*sizeof(DOM_SID))) == NULL) {
SAFE_FREE(token);
return NULL;
* se_access_check depends on this.
*/
- uid_to_sid( &psids[psid_ndx++], uid);
+ uid_to_sid( &psids[PRIMARY_USER_SID_INDEX], uid);
+ psid_ndx++;
/*
* Primary group SID is second in token. Convention.
*/
- gid_to_sid( &psids[psid_ndx++], gid);
+ gid_to_sid( &psids[PRIMARY_GROUP_SID_INDEX], gid);
+ psid_ndx++;
/* Now add the group SIDs. */
}
}
+ /* Now add the additional SIDs from the supplimentary token. */
+ for (i = 0; i < sup_tok->num_sids; i++)
+ sid_copy( &psids[psid_ndx++], &sup_tok->user_sids[i] );
+
/*
* Finally add the "standard" SIDs.
* The only difference between guest and "anonymous" (which we
ZERO_STRUCTP(vuser);
- puid = pdb_get_uid(server_info->sam_account);
- pgid = pdb_get_gid(server_info->sam_account);
+ puid = pdb_get_uid(server_info->sam_account);
+ pgid = pdb_get_gid(server_info->sam_account);
if (!puid || !pgid) {
DEBUG(0,("Attempted session setup with invalid user. No uid/gid in SAM_ACCOUNT\n"));
initialise_groups(vuser->user.unix_name, vuser->uid, vuser->gid);
get_current_groups( &vuser->n_groups, &vuser->groups);
+ if (server_info->ptok)
+ add_supplementary_nt_login_groups(&vuser->n_groups, &vuser->groups, &server_info->ptok);
+
/* Create an NT_USER_TOKEN struct for this user. */
- vuser->nt_user_token = create_nt_token(vuser->uid, vuser->gid, vuser->n_groups, vuser->groups, guest);
+ vuser->nt_user_token = create_nt_token(vuser->uid, vuser->gid, vuser->n_groups, vuser->groups, guest, server_info->ptok);
DEBUG(3,("uid %d registered to name %s\n",(int)vuser->uid,vuser->user.unix_name));
try to get the disk space from disk quotas (LINUX version)
****************************************************************************/
-BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
int r;
SMB_STRUCT_STAT S;
try to get the disk space from disk quotas (CRAY VERSION)
****************************************************************************/
-BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
struct mntent *mnt;
FILE *fd;
Quota code by Peter Urbanec (amiga@cse.unsw.edu.au).
****************************************************************************/
-BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
uid_t euser_id;
int ret;
try to get the disk space from disk quotas - OSF1 version
****************************************************************************/
-BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
int r, save_errno;
struct dqblk D;
#include <sys/quota.h>
#include <mntent.h>
-BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
uid_t euser_id;
int r;
try to get the disk space from disk quotas - default version
****************************************************************************/
-BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
int r;
struct dqblk D;
return ngroups;
}
-/****************************************************************************
- Delete a SID token.
-****************************************************************************/
-
-void delete_nt_token(NT_USER_TOKEN **pptoken)
-{
- if (*pptoken) {
- NT_USER_TOKEN *ptoken = *pptoken;
- SAFE_FREE( ptoken->user_sids );
- ZERO_STRUCTP(ptoken);
- }
- SAFE_FREE(*pptoken);
-}
-
-/****************************************************************************
- Duplicate a SID token.
-****************************************************************************/
-
-NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken)
-{
- NT_USER_TOKEN *token;
-
- if (!ptoken)
- return NULL;
-
- if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
- return NULL;
-
- ZERO_STRUCTP(token);
-
- if ((token->user_sids = (DOM_SID *)memdup( ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids )) == NULL) {
- SAFE_FREE(token);
- return NULL;
- }
-
- token->num_sids = ptoken->num_sids;
-
- return token;
-}
-
/****************************************************************************
Initialize the groups a user belongs to.
****************************************************************************/
conn->nt_user_token = create_nt_token(conn->uid, conn->gid,
conn->ngroups, conn->groups,
- guest);
+ guest, NULL);
/*
* New code to check if there's a share security descripter
if (vuser && vuser->guest)
is_guest = True;
- token = create_nt_token(uid, gid, current_user.ngroups, current_user.groups, is_guest);
+ token = create_nt_token(uid, gid, current_user.ngroups, current_user.groups, is_guest, NULL);
must_free_token = True;
}
return True;
}
+/*****************************************************************
+ Convert the suplimentary SIDs returned in a netlogon into UNIX
+ group gid_t's. Add to the total group array.
+*****************************************************************/
+
+void add_supplementary_nt_login_groups(int *n_groups, gid_t **pp_groups, NT_USER_TOKEN **pptok)
+{
+ int total_groups;
+ int current_n_groups = *n_groups;
+ gid_t *final_groups = NULL;
+ size_t i;
+ NT_USER_TOKEN *ptok = *pptok;
+ NT_USER_TOKEN *new_tok = NULL;
+
+ if (!ptok || (ptok->num_sids == 0))
+ return;
+
+ new_tok = dup_nt_token(ptok);
+ if (!new_tok) {
+ DEBUG(0,("add_supplementary_nt_login_groups: Failed to malloc new token\n"));
+ return;
+ }
+ /* Leave the allocated space but empty the number of SIDs. */
+ new_tok->num_sids = 0;
+
+ total_groups = current_n_groups + ptok->num_sids;
+
+ final_groups = (gid_t *)malloc(total_groups * sizeof(gid_t));
+ if (!final_groups) {
+ DEBUG(0,("add_supplementary_nt_login_groups: Failed to malloc new groups.\n"));
+ delete_nt_token(&new_tok);
+ return;
+ }
+
+ memcpy(final_groups, *pp_groups, current_n_groups * sizeof(gid_t));
+ for (i = 0; i < ptok->num_sids; i++) {
+ enum SID_NAME_USE sid_type;
+ gid_t new_grp;
+
+ if (sid_to_gid(&ptok->user_sids[i], &new_grp, &sid_type)) {
+ /*
+ * Don't add the gid_t if it is already in the current group
+ * list. Some UNIXen don't like the same group more than once.
+ */
+ int j;
+
+ for (j = 0; j < current_n_groups; j++)
+ if (final_groups[j] == new_grp)
+ break;
+
+ if ( j == current_n_groups) {
+ /* Group not already present. */
+ final_groups[current_n_groups++] = new_grp;
+ }
+ } else {
+ /* SID didn't map. Copy to the new token to be saved. */
+ sid_copy(&new_tok->user_sids[new_tok->num_sids++], &ptok->user_sids[i]);
+ }
+ }
+
+ SAFE_FREE(*pp_groups);
+ *pp_groups = final_groups;
+ *n_groups = current_n_groups;
+
+ /* Replace the old token with the truncated one. */
+ delete_nt_token(&ptok);
+ *pptok = new_tok;
+}
+
/*****************************************************************
*THE CANONICAL* convert name to SID function.
Tries winbind first - then uses local lookup.
if (verbosity) {
printf ("username: %s\n", sam_pwent->username);
- printf ("user ID/Group: %d/%d\n", sam_pwent->uid,
- sam_pwent->gid);
- printf ("user RID/GRID: %d/%d\n", sam_pwent->user_rid,
- sam_pwent->group_rid);
+ printf ("user ID/Group: %u/%u\n", (unsigned int)sam_pwent->uid,
+ (unsigned int)sam_pwent->gid);
+ printf ("user RID/GRID: %u/%u\n", (unsigned int)sam_pwent->user_rid,
+ (unsigned int)sam_pwent->group_rid);
printf ("Full Name: %s\n", sam_pwent->full_name);
printf ("Home Directory: %s\n", sam_pwent->home_dir);
printf ("HomeDir Drive: %s\n", sam_pwent->dir_drive);