1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

reduced the number of magic types we need in mkproto.pl

In general I prefer "struct foo" to just "foo" for most
structures. There are exceptions.
This commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent db6d7daaef
commit 04eb12b56c
11 changed files with 66 additions and 282 deletions

View File

@ -618,7 +618,7 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro
Create the SID list for this user. 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) struct nt_user_token *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups, BOOL is_guest)
{ {
DOM_SID user_sid; DOM_SID user_sid;
DOM_SID group_sid; DOM_SID group_sid;
@ -1169,7 +1169,7 @@ void delete_nt_token(NT_USER_TOKEN **pptoken)
Duplicate a SID token. Duplicate a SID token.
****************************************************************************/ ****************************************************************************/
NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken) struct nt_user_token *dup_nt_token(NT_USER_TOKEN *ptoken)
{ {
NT_USER_TOKEN *token; NT_USER_TOKEN *token;

View File

@ -631,9 +631,9 @@ typedef int socklen_t;
#ifndef SMB_STRUCT_DIRENT #ifndef SMB_STRUCT_DIRENT
# if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64) # if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
# define SMB_STRUCT_DIRENT struct dirent64 # define smb_dirent dirent64
# else # else
# define SMB_STRUCT_DIRENT struct dirent # define smb_dirent dirent
# endif # endif
#endif #endif

View File

@ -346,7 +346,7 @@ typedef struct sid_info
#define PRIMARY_USER_SID_INDEX 0 #define PRIMARY_USER_SID_INDEX 0
#define PRIMARY_GROUP_SID_INDEX 1 #define PRIMARY_GROUP_SID_INDEX 1
typedef struct _nt_user_token { typedef struct nt_user_token {
size_t num_sids; size_t num_sids;
DOM_SID *user_sids; DOM_SID *user_sids;
} NT_USER_TOKEN; } NT_USER_TOKEN;

View File

@ -324,7 +324,7 @@ FILE *sys_fopen(const char *path, const char *type)
A readdir wrapper that will deal with 64 bit filesizes. A readdir wrapper that will deal with 64 bit filesizes.
********************************************************************/ ********************************************************************/
SMB_STRUCT_DIRENT *sys_readdir(DIR *dirp) struct smb_dirent *sys_readdir(DIR *dirp)
{ {
#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64) #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
return readdir64(dirp); return readdir64(dirp);

View File

@ -794,43 +794,4 @@ int unistrcpy(uint16 *dst, uint16 *src)
return num_wchars; return num_wchars;
} }
/**
* Samba ucs2 type to UNISTR2 conversion
*
* @param ctx Talloc context to create the dst strcture (if null) and the
* contents of the unicode string.
* @param dst UNISTR2 destination. If equals null, then it's allocated.
* @param src smb_ucs2_t source.
* @param max_len maximum number of unicode characters to copy. If equals
* null, then null-termination of src is taken
*
* @return copied UNISTR2 destination
**/
UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src)
{
size_t len;
if (!src) return NULL;
len = strlen_w(src);
/* allocate UNISTR2 destination if not given */
if (!dst) {
dst = (UNISTR2*) talloc(ctx, sizeof(UNISTR2));
if (!dst) return NULL;
}
if (!dst->buffer) {
dst->buffer = (uint16*) talloc(ctx, sizeof(uint16) * (len + 1));
if (!dst->buffer) return NULL;
}
/* set UNISTR2 parameters */
dst->uni_max_len = len + 1;
dst->undoc = 0;
dst->uni_str_len = len;
/* copy the actual unicode string */
strncpy_w(dst->buffer, src, dst->uni_max_len);
return dst;
};

View File

@ -76,13 +76,13 @@ BOOL yesno(char *p)
const char *readdirname(DIR *p) const char *readdirname(DIR *p)
{ {
SMB_STRUCT_DIRENT *ptr; struct smb_dirent *ptr;
char *dname; char *dname;
if (!p) if (!p)
return(NULL); return(NULL);
ptr = (SMB_STRUCT_DIRENT *)sys_readdir(p); ptr = (struct smb_dirent *)sys_readdir(p);
if (!ptr) if (!ptr)
return(NULL); return(NULL);

View File

@ -810,189 +810,6 @@ BOOL local_lookup_name(const char *c_user, DOM_SID *psid, enum SID_NAME_USE *psi
return True; return True;
} }
/****************************************************************************
Convert a uid to SID - locally.
****************************************************************************/
DOM_SID *local_uid_to_sid(DOM_SID *psid, uid_t uid)
{
struct passwd *pass;
SAM_ACCOUNT *sam_user = NULL;
fstring str; /* sid string buffer */
sid_copy(psid, get_global_sam_sid());
if((pass = getpwuid_alloc(uid))) {
if (NT_STATUS_IS_ERR(pdb_init_sam(&sam_user))) {
passwd_free(&pass);
return NULL;
}
if (pdb_getsampwnam(sam_user, pass->pw_name)) {
sid_copy(psid, pdb_get_user_sid(sam_user));
} else {
sid_append_rid(psid, fallback_pdb_uid_to_user_rid(uid));
}
DEBUG(10,("local_uid_to_sid: uid %u -> SID (%s) (%s).\n",
(unsigned)uid, sid_to_string( str, psid),
pass->pw_name ));
passwd_free(&pass);
pdb_free_sam(&sam_user);
} else {
sid_append_rid(psid, fallback_pdb_uid_to_user_rid(uid));
DEBUG(10,("local_uid_to_sid: uid %u -> SID (%s) (unknown user).\n",
(unsigned)uid, sid_to_string( str, psid)));
}
return psid;
}
/****************************************************************************
Convert a SID to uid - locally.
****************************************************************************/
BOOL local_sid_to_uid(uid_t *puid, const DOM_SID *psid, enum SID_NAME_USE *name_type)
{
fstring str;
SAM_ACCOUNT *sam_user = NULL;
*name_type = SID_NAME_UNKNOWN;
if (NT_STATUS_IS_ERR(pdb_init_sam(&sam_user)))
return False;
if (pdb_getsampwsid(sam_user, psid)) {
if (!IS_SAM_SET(sam_user,PDB_UID)&&!IS_SAM_CHANGED(sam_user,PDB_UID)) {
pdb_free_sam(&sam_user);
return False;
}
*puid = pdb_get_uid(sam_user);
DEBUG(10,("local_sid_to_uid: SID %s -> uid (%u) (%s).\n", sid_to_string( str, psid),
(unsigned int)*puid, pdb_get_username(sam_user)));
pdb_free_sam(&sam_user);
} else {
DOM_SID dom_sid;
uint32 rid;
GROUP_MAP map;
pdb_free_sam(&sam_user);
if (pdb_getgrsid(&map, *psid, MAPPING_WITHOUT_PRIV)) {
DEBUG(3, ("local_sid_to_uid: SID '%s' is a group, not a user... \n", sid_to_string(str, psid)));
/* It's a group, not a user... */
return False;
}
sid_copy(&dom_sid, psid);
if (!sid_peek_check_rid(get_global_sam_sid(), psid, &rid)) {
DEBUG(3, ("sid_peek_rid failed - sid '%s' is not in our domain\n", sid_to_string(str, psid)));
return False;
}
if (!pdb_rid_is_user(rid)) {
DEBUG(3, ("local_sid_to_uid: sid '%s' cannot be mapped to a uid algorithmicly becouse it is a group\n", sid_to_string(str, psid)));
return False;
}
*puid = fallback_pdb_user_rid_to_uid(rid);
DEBUG(5,("local_sid_to_uid: SID %s algorithmicly mapped to %ld mapped becouse SID was not found in passdb.\n",
sid_to_string(str, psid), (signed long int)(*puid)));
}
*name_type = SID_NAME_USER;
return True;
}
/****************************************************************************
Convert a gid to SID - locally.
****************************************************************************/
DOM_SID *local_gid_to_sid(DOM_SID *psid, gid_t gid)
{
GROUP_MAP map;
sid_copy(psid, get_global_sam_sid());
if (pdb_getgrgid(&map, gid, MAPPING_WITHOUT_PRIV)) {
sid_copy(psid, &map.sid);
}
else {
sid_append_rid(psid, pdb_gid_to_group_rid(gid));
}
return psid;
}
/****************************************************************************
Convert a SID to gid - locally.
****************************************************************************/
BOOL local_sid_to_gid(gid_t *pgid, const DOM_SID *psid, enum SID_NAME_USE *name_type)
{
fstring str;
GROUP_MAP map;
*name_type = SID_NAME_UNKNOWN;
/*
* We can only convert to a gid if this is our local
* Domain SID (ie. we are the controling authority).
*
* Or in the Builtin SID too. JFM, 11/30/2001
*/
if (pdb_getgrsid(&map, *psid, MAPPING_WITHOUT_PRIV)) {
/* the SID is in the mapping table but not mapped */
if (map.gid==(gid_t)-1)
return False;
*pgid = map.gid;
*name_type = map.sid_name_use;
DEBUG(10,("local_sid_to_gid: mapped SID %s (%s) -> gid (%u).\n",
sid_to_string( str, psid),
map.nt_name, (unsigned int)*pgid));
} else {
uint32 rid;
SAM_ACCOUNT *sam_user = NULL;
if (NT_STATUS_IS_ERR(pdb_init_sam(&sam_user)))
return False;
if (pdb_getsampwsid(sam_user, psid)) {
return False;
pdb_free_sam(&sam_user);
}
pdb_free_sam(&sam_user);
if (!sid_peek_check_rid(get_global_sam_sid(), psid, &rid)) {
DEBUG(3, ("sid_peek_rid failed - sid '%s' is not in our domain\n", sid_to_string(str, psid)));
return False;
}
if (pdb_rid_is_user(rid))
return False;
*pgid = pdb_group_rid_to_gid(rid);
*name_type = SID_NAME_ALIAS;
DEBUG(10,("local_sid_to_gid: SID %s -> gid (%u).\n", sid_to_string( str, psid),
(unsigned int)*pgid));
}
return True;
}
/************************************************************* /*************************************************************
Change a password entry in the local smbpasswd file. Change a password entry in the local smbpasswd file.

View File

@ -21,6 +21,55 @@ sub print_footer {
printf "\n#endif /* %s */\n", $header_name; printf "\n#endif /* %s */\n", $header_name;
} }
sub handle_loadparm {
my $line = shift;
if ($line =~ /^FN_GLOBAL_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "char *$fnName(void);\n";
} elsif ($line =~ /^FN_LOCAL_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "char *$fnName(int );\n";
} elsif ($line =~ /^FN_GLOBAL_BOOL/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "BOOL $fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_BOOL/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "BOOL $fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_INTEGER/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "int $fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_INTEGER/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "int $fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_LIST/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char **$fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_LIST/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char **$fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_CONST_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char *$fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_CONST_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char *$fnName(int );\n";
}
elsif ($line =~ /^FN_LOCAL_CHAR/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "char $fnName(int );\n";
}
}
sub process_files { sub process_files {
my $line; my $line;
my $inheader; my $inheader;
@ -57,60 +106,19 @@ sub process_files {
} }
if ($line =~ /^FN_GLOBAL_STRING/o) { if ($line =~ /^FN_/) {
my $fnName = (split(/[\(,]/, $line))[1]; handle_loadparm($line);
print "char *$fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "char *$fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_BOOL/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "BOOL $fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_BOOL/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "BOOL $fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_INTEGER/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "int $fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_INTEGER/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "int $fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_LIST/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char **$fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_LIST/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char **$fnName(int );\n";
}
elsif ($line =~ /^FN_GLOBAL_CONST_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char *$fnName(void);\n";
}
elsif ($line =~ /^FN_LOCAL_CONST_STRING/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "const char *$fnName(int );\n";
}
elsif ($line =~ /^FN_LOCAL_CHAR/o) {
my $fnName = (split(/[\(,]/, $line))[1];
print "char $fnName(int );\n";
} }
# I'm going to leave these as is for now - perl can probably handle larger regex, though -- vance # I'm going to leave these as is for now - perl can probably handle larger regex, though -- vance
# I've also sort of put these in approximate order of most commonly called # I've also sort of put these in approximate order of most commonly called
elsif ( $line =~ /^NTSTATUS|^void|^BOOL|^int|^struct|^char|^const|^PyObject|^ssize_t|^size_t|^uint|^ADS_STATUS|^ADS_STRUCT|^enum.*\(|^SMB_ACL_T|^time|^smb_ucs2_t|^DATA_BLOB|^WERROR/o ) { elsif ( $line =~ /^NTSTATUS|^void|^BOOL|^int|^struct|^char|^const|^\w+_[tT]\s|^uint|^ADS_STATUS|^enum\s.*\(|^DATA_BLOB|^WERROR/o ) {
$gotstart = 1; $gotstart = 1;
} elsif ( $line =~ /^smb_iconv_t|^long|^CLI_POLICY_HND|^FILE|^XFILE|^SMB_OFF_T|^pipes_struct|^smb_np_struct|^file_fd_struct|^files_struct|^connection_struct|^uid_t|^gid_t|^unsigned|^DIR|^user/o) { } elsif ( $line =~ /^long|^XFILE|^FILE|^unsigned|^DIR/o) {
$gotstart = 1; $gotstart = 1;
} elsif ( $line =~ /^pid_t|^ino_t|^off_t|^double|^TDB_CONTEXT|^TDB_DATA|^TALLOC_CTX|^NT_DEVICEMODE|^NT_USER_TOKEN|^ADS_MODLIST|^SORTED_TREE|^REGISTRY_HOOK|^REGISTRY_VALUE|^NTTIME|^UNISTR2|^SMB_STRUCT_DIRENT|^SEC_DESC|^DOM_SID/o ) { } elsif ( $line =~ /^double|^TDB_CONTEXT|^TDB_DATA|^TALLOC_CTX|^NTTIME/o ) {
$gotstart = 1; $gotstart = 1;
} }

View File

@ -26,7 +26,7 @@ check if a uid has been validated, and return an pointer to the user_struct
if it has. NULL if not. vuid is biased by an offset. This allows us to if it has. NULL if not. vuid is biased by an offset. This allows us to
tell random client vuid's (normally zero) from valid vuids. tell random client vuid's (normally zero) from valid vuids.
****************************************************************************/ ****************************************************************************/
user_struct *get_valid_user_struct(struct server_context *smb, uint16 vuid) struct user_struct *get_valid_user_struct(struct server_context *smb, uint16 vuid)
{ {
user_struct *usp; user_struct *usp;
int count=0; int count=0;

View File

@ -64,15 +64,13 @@ BOOL init_names(void)
BOOL uid_to_sid(DOM_SID *sid, uid_t uid) BOOL uid_to_sid(DOM_SID *sid, uid_t uid)
{ {
*sid = *get_global_sam_sid(); ZERO_STRUCTP(sid);
sid_append_rid(sid, uid*2);
return True; return True;
} }
BOOL gid_to_sid(DOM_SID *sid, gid_t gid) BOOL gid_to_sid(DOM_SID *sid, gid_t gid)
{ {
*sid = *get_global_sam_sid(); ZERO_STRUCTP(sid);
sid_append_rid(sid, gid*2 + 1);
return True; return True;
} }

View File

@ -173,7 +173,7 @@ static BOOL test_EnumKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
keyname.unknown = 0x0000020a; keyname.unknown = 0x0000020a;
init_winreg_String(&keyname.key_name, NULL); init_winreg_String(&keyname.key_name, NULL);
init_winreg_String(&classname, NULL); init_winreg_String(&classname, NULL);
r.in.name = &keyname; r.in.in_name = &keyname;
r.in.class = &classname; r.in.class = &classname;
tm.low = tm.high = 0x7fffffff; tm.low = tm.high = 0x7fffffff;
r.in.last_changed_time = &tm; r.in.last_changed_time = &tm;