summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c162
-rw-r--r--source3/lib/data_blob.c1
-rw-r--r--source3/lib/domain_namemap.c1317
-rw-r--r--source3/lib/gencache.c10
-rw-r--r--source3/lib/genparser.c775
-rw-r--r--source3/lib/genparser_samba.c200
-rw-r--r--source3/lib/iconv.c194
-rw-r--r--source3/lib/system_smbd.c15
-rw-r--r--source3/lib/username.c57
-rw-r--r--source3/lib/util.c27
-rw-r--r--source3/lib/util_file.c5
-rw-r--r--source3/lib/util_str.c251
12 files changed, 360 insertions, 2654 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index bffa2a378c..54e17bea68 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -26,18 +26,10 @@ static pstring cvtbuf;
static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
-/**
- * @file
- *
- * Character set conversion routines.
- *
- * @sa lib/iconv.c
- **/
+/****************************************************************************
+ Return the name of a charset to give to iconv().
+****************************************************************************/
-
-/**
- * Return the name of a charset to give to iconv().
- **/
static const char *charset_name(charset_t ch)
{
const char *ret = NULL;
@@ -64,9 +56,9 @@ static void lazy_initialize_conv(void)
}
}
-/**
+/****************************************************************************
Initialize iconv conversion descriptors.
-**/
+****************************************************************************/
void init_iconv(void)
{
@@ -112,12 +104,14 @@ void init_iconv(void)
/**
* Convert string from one encoding to another, making error checking etc
*
+ * @param descriptor conversion descriptor, created in init_iconv()
* @param src pointer to source string (multibyte or singlebyte)
* @param srclen length of the source string in bytes
* @param dest pointer to destination string (multibyte or singlebyte)
* @param destlen maximal length allowed for string
- * @returns the number of bytes occupied in the destination
+ * @retval the number of bytes occupied in the destination
**/
+
size_t convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
void *dest, size_t destlen)
@@ -176,7 +170,7 @@ size_t convert_string(charset_t from, charset_t to,
* @param dest always set at least to NULL
* @note -1 is not accepted for srclen.
*
- * @returns Size in bytes of the converted string; or -1 in case of error.
+ * @retval Size in bytes of the converted string; or -1 in case of error.
**/
size_t convert_string_allocate(charset_t from, charset_t to,
@@ -248,7 +242,6 @@ convert:
return destlen;
}
-
/**
* Convert between character sets, allocating a new buffer using talloc for the result.
*
@@ -256,8 +249,9 @@ convert:
* @param dest always set at least to NULL
* @note -1 is not accepted for srclen.
*
- * @returns Size in bytes of the converted string; or -1 in case of error.
+ * @retval Size in bytes of the converted string; or -1 in case of error.
**/
+
size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
void const *src, size_t srclen, void **dest)
{
@@ -304,20 +298,16 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags)
}
-/**
- * Copy a string from a char* unix src to a dos codepage string destination.
- *
- * @return the number of bytes occupied by the string in the destination.
- *
- * @param flags can include
- * <dl>
- * <dt>STR_TERMINATE</dt> <dd>means include the null termination</dd>
- * <dt>STR_UPPER</dt> <dd>means uppercase in the destination</dd>
- * </dl>
- *
- * @param dest_len the maximum length in bytes allowed in the
- * destination. If @p dest_len is -1 then no maximum is used.
- **/
+/****************************************************************************
+copy a string from a char* unix src to a dos codepage string destination
+return the number of bytes occupied by the string in the destination
+flags can have:
+ STR_TERMINATE means include the null termination
+ STR_UPPER means uppercase in the destination
+dest_len is the maximum length in bytes allowed in the destination. If dest_len
+is -1 then no maxiumum is used
+****************************************************************************/
+
size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
{
size_t src_len = strlen(src);
@@ -354,21 +344,16 @@ size_t push_pstring(void *dest, const char *src)
return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE);
}
-/**
- * Copy a string from a dos codepage source to a unix char* destination.
- *
- * The resulting string in "dest" is always null terminated.
- *
- * @param flags can have:
- * <dl>
- * <dt>STR_TERMINATE</dt>
- * <dd>STR_TERMINATE means the string in @p src
- * is null terminated, and src_len is ignored.</dd>
- * </dl>
- *
- * @param src_len is the length of the source area in bytes.
- * @returns the number of bytes occupied by the string in @p src.
- **/
+/****************************************************************************
+ Copy a string from a dos codepage source to a unix char* destination.
+ Flags can have:
+ STR_TERMINATE means the string in src is null terminated.
+ if STR_TERMINATE is set then src_len is ignored.
+ src_len is the length of the source area in bytes.
+ Return the number of bytes occupied by the string in src.
+ The resulting string in "dest" is always null terminated.
+****************************************************************************/
+
size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
size_t ret;
@@ -405,22 +390,17 @@ size_t pull_ascii_fstring(char *dest, const void *src)
return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE);
}
-/**
- * Copy a string from a char* src to a unicode destination.
- *
- * @returns the number of bytes occupied by the string in the destination.
- *
- * @param flags can have:
- *
- * <dl>
- * <dt>STR_TERMINATE <dd>means include the null termination.
- * <dt>STR_UPPER <dd>means uppercase in the destination.
- * <dt>STR_NOALIGN <dd>means don't do alignment.
- * </dl>
- *
- * @param dest_len is the maximum length allowed in the
- * destination. If dest_len is -1 then no maxiumum is used.
- **/
+/****************************************************************************
+ Copy a string from a char* src to a unicode destination.
+ Return the number of bytes occupied by the string in the destination.
+ Flags can have:
+ STR_TERMINATE means include the null termination.
+ STR_UPPER means uppercase in the destination.
+ STR_NOALIGN means don't do alignment.
+ dest_len is the maximum length allowed in the destination. If dest_len
+ is -1 then no maxiumum is used.
+****************************************************************************/
+
size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
{
size_t len=0;
@@ -454,16 +434,15 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
return len;
}
-
/**
- * Copy a string from a unix char* src to a UCS2 destination,
- * allocating a buffer using talloc().
+ * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer using talloc
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
* or -1 in case of error.
**/
+
size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
{
size_t src_len = strlen(src)+1;
@@ -472,13 +451,12 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest);
}
-
/**
* Copy a string from a unix char* src to a UCS2 destination, allocating a buffer
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
* or -1 in case of error.
**/
@@ -490,7 +468,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, (void **)dest);
}
-/**
+/****************************************************************************
Copy a string from a char* src to a UTF-8 destination.
Return the number of bytes occupied by the string in the destination
Flags can have:
@@ -498,7 +476,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
STR_UPPER means uppercase in the destination
dest_len is the maximum length allowed in the destination. If dest_len
is -1 then no maxiumum is used.
-**/
+****************************************************************************/
size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags)
{
@@ -536,7 +514,7 @@ size_t push_utf8_pstring(void *dest, const char *src)
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
**/
size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
@@ -552,7 +530,7 @@ size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
**/
size_t push_utf8_allocate(char **dest, const char *src)
@@ -563,7 +541,7 @@ size_t push_utf8_allocate(char **dest, const char *src)
return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest);
}
-/**
+/****************************************************************************
Copy a string from a ucs2 source to a unix char* destination.
Flags can have:
STR_TERMINATE means the string in src is null terminated.
@@ -572,7 +550,7 @@ size_t push_utf8_allocate(char **dest, const char *src)
src_len is the length of the source area in bytes
Return the number of bytes occupied by the string in src.
The resulting string in "dest" is always null terminated.
-**/
+****************************************************************************/
size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
@@ -624,7 +602,7 @@ size_t pull_ucs2_fstring(char *dest, const void *src)
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
**/
size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src)
@@ -639,7 +617,7 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src)
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
**/
size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src)
@@ -649,7 +627,7 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src)
return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest);
}
-/**
+/****************************************************************************
Copy a string from a utf-8 source to a unix char* destination.
Flags can have:
STR_TERMINATE means the string in src is null terminated.
@@ -657,7 +635,7 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src)
src_len is the length of the source area in bytes
Return the number of bytes occupied by the string in src.
The resulting string in "dest" is always null terminated.
-**/
+****************************************************************************/
size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
@@ -699,7 +677,7 @@ size_t pull_utf8_fstring(char *dest, const void *src)
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
**/
size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
@@ -714,7 +692,7 @@ size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
*
* @param dest always set at least to NULL
*
- * @returns The number of bytes occupied by the string in the destination
+ * @retval The number of bytes occupied by the string in the destination
**/
size_t pull_utf8_allocate(void **dest, const char *src)
@@ -724,7 +702,7 @@ size_t pull_utf8_allocate(void **dest, const char *src)
return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len, dest);
}
-/**
+/****************************************************************************
Copy a string from a char* src to a unicode or ascii
dos codepage destination choosing unicode or ascii based on the
flags in the SMB buffer starting at base_ptr.
@@ -736,7 +714,7 @@ size_t pull_utf8_allocate(void **dest, const char *src)
STR_NOALIGN means don't do alignment.
dest_len is the maximum length allowed in the destination. If dest_len
is -1 then no maxiumum is used.
-**/
+****************************************************************************/
size_t push_string(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
{
@@ -749,7 +727,7 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des
}
-/**
+/****************************************************************************
Copy a string from a unicode or ascii source (depending on
the packet flags) to a char* destination.
Flags can have:
@@ -761,7 +739,7 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des
src_len is the length of the source area in bytes.
Return the number of bytes occupied by the string in src.
The resulting string in "dest" is always null terminated.
-**/
+****************************************************************************/
size_t pull_string(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
@@ -783,12 +761,12 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
return 0;
}
-/**
+/****************************************************************************
Convert from ucs2 to unix charset and return the
allocated and converted string or NULL if an error occurred.
You must provide a zero terminated string.
The returning string will be zero terminated.
-**/
+****************************************************************************/
char *acnv_u2ux(const smb_ucs2_t *src)
{
@@ -804,12 +782,12 @@ char *acnv_u2ux(const smb_ucs2_t *src)
return dest;
}
-/**
+/****************************************************************************
Convert from unix to ucs2 charset and return the
allocated and converted string or NULL if an error occurred.
You must provide a zero terminated string.
The returning string will be zero terminated.
-**/
+****************************************************************************/
smb_ucs2_t *acnv_uxu2(const char *src)
{
@@ -825,12 +803,12 @@ smb_ucs2_t *acnv_uxu2(const char *src)
return dest;
}
-/**
+/****************************************************************************
Convert from ucs2 to dos charset and return the
allocated and converted string or NULL if an error occurred.
You must provide a zero terminated string.
The returning string will be zero terminated.
-**/
+****************************************************************************/
char *acnv_u2dos(const smb_ucs2_t *src)
{
@@ -846,12 +824,12 @@ char *acnv_u2dos(const smb_ucs2_t *src)
return dest;
}
-/**
+/****************************************************************************
Convert from dos to ucs2 charset and return the
allocated and converted string or NULL if an error occurred.
You must provide a zero terminated string.
The returning string will be zero terminated.
-**/
+****************************************************************************/
smb_ucs2_t *acnv_dosu2(const char *src)
{
diff --git a/source3/lib/data_blob.c b/source3/lib/data_blob.c
index 4056212fc5..250c3ade88 100644
--- a/source3/lib/data_blob.c
+++ b/source3/lib/data_blob.c
@@ -84,7 +84,6 @@ void data_blob_free(DATA_BLOB *d)
if (d->free) {
(d->free)(d);
}
- d->length = 0;
}
}
diff --git a/source3/lib/domain_namemap.c b/source3/lib/domain_namemap.c
deleted file mode 100644
index 988f5e5d65..0000000000
--- a/source3/lib/domain_namemap.c
+++ /dev/null
@@ -1,1317 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- Groupname handling
- Copyright (C) Jeremy Allison 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.
-*/
-
-/*
- * UNIX gid and Local or Domain SID resolution. This module resolves
- * only those entries in the map files, it is *NOT* responsible for
- * resolving UNIX groups not listed: that is an entirely different
- * matter, altogether...
- */
-
-/*
- *
- *
-
- format of the file is:
-
- unixname NT Group name
- unixname Domain Admins (well-known Domain Group)
- unixname DOMAIN_NAME\NT Group name
- unixname OTHER_DOMAIN_NAME\NT Group name
- unixname DOMAIN_NAME\Domain Admins (well-known Domain Group)
- ....
-
- if the DOMAIN_NAME\ component is left off, then your own domain is assumed.
-
- *
- *
- */
-
-
-#include "includes.h"
-extern int DEBUGLEVEL;
-
-extern fstring global_myworkgroup;
-extern DOM_SID global_member_sid;
-extern fstring global_sam_name;
-extern DOM_SID global_sam_sid;
-extern DOM_SID global_sid_S_1_5_20;
-
-/*******************************************************************
- converts UNIX uid to an NT User RID. NOTE: IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uid_t pwdb_user_rid_to_uid(uint32 user_rid)
-{
- return ((user_rid & (~RID_TYPE_USER))- 1000)/RID_MULTIPLIER;
-}
-
-/*******************************************************************
- converts NT Group RID to a UNIX uid. NOTE: IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uint32 pwdb_group_rid_to_gid(uint32 group_rid)
-{
- return ((group_rid & (~RID_TYPE_GROUP))- 1000)/RID_MULTIPLIER;
-}
-
-/*******************************************************************
- converts NT Alias RID to a UNIX uid. NOTE: IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uint32 pwdb_alias_rid_to_gid(uint32 alias_rid)
-{
- return ((alias_rid & (~RID_TYPE_ALIAS))- 1000)/RID_MULTIPLIER;
-}
-
-/*******************************************************************
- converts NT Group RID to a UNIX uid. NOTE: IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uint32 pwdb_gid_to_group_rid(uint32 gid)
-{
- uint32 grp_rid = ((((gid)*RID_MULTIPLIER) + 1000) | RID_TYPE_GROUP);
- return grp_rid;
-}
-
-/******************************************************************
- converts UNIX gid to an NT Alias RID. NOTE: IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uint32 pwdb_gid_to_alias_rid(uint32 gid)
-{
- uint32 alias_rid = ((((gid)*RID_MULTIPLIER) + 1000) | RID_TYPE_ALIAS);
- return alias_rid;
-}
-
-/*******************************************************************
- converts UNIX uid to an NT User RID. NOTE: IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uint32 pwdb_uid_to_user_rid(uint32 uid)
-{
- uint32 user_rid = ((((uid)*RID_MULTIPLIER) + 1000) | RID_TYPE_USER);
- return user_rid;
-}
-
-/******************************************************************
- converts SID + SID_NAME_USE type to a UNIX id. the Domain SID is,
- and can only be, our own SID.
- ********************************************************************/
-static BOOL pwdb_sam_sid_to_unixid(DOM_SID *sid, uint8 type, uint32 *id)
-{
- DOM_SID tmp_sid;
- uint32 rid;
-
- sid_copy(&tmp_sid, sid);
- sid_split_rid(&tmp_sid, &rid);
- if (!sid_equal(&global_sam_sid, &tmp_sid))
- {
- return False;
- }
-
- switch (type)
- {
- case SID_NAME_USER:
- {
- *id = pwdb_user_rid_to_uid(rid);
- return True;
- }
- case SID_NAME_ALIAS:
- {
- *id = pwdb_alias_rid_to_gid(rid);
- return True;
- }
- case SID_NAME_DOM_GRP:
- case SID_NAME_WKN_GRP:
- {
- *id = pwdb_group_rid_to_gid(rid);
- return True;
- }
- }
- return False;
-}
-
-/******************************************************************
- converts UNIX gid + SID_NAME_USE type to a SID. the Domain SID is,
- and can only be, our own SID.
- ********************************************************************/
-static BOOL pwdb_unixid_to_sam_sid(uint32 id, uint8 type, DOM_SID *sid)
-{
- sid_copy(sid, &global_sam_sid);
- switch (type)
- {
- case SID_NAME_USER:
- {
- sid_append_rid(sid, pwdb_uid_to_user_rid(id));
- return True;
- }
- case SID_NAME_ALIAS:
- {
- sid_append_rid(sid, pwdb_gid_to_alias_rid(id));
- return True;
- }
- case SID_NAME_DOM_GRP:
- case SID_NAME_WKN_GRP:
- {
- sid_append_rid(sid, pwdb_gid_to_group_rid(id));
- return True;
- }
- }
- return False;
-}
-
-/*******************************************************************
- Decides if a RID is a well known RID.
- ********************************************************************/
-static BOOL pwdb_rid_is_well_known(uint32 rid)
-{
- return (rid < 1000);
-}
-
-/*******************************************************************
- determines a rid's type. NOTE: THIS IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-static uint32 pwdb_rid_type(uint32 rid)
-{
- /* lkcl i understand that NT attaches an enumeration to a RID
- * such that it can be identified as either a user, group etc
- * type: SID_ENUM_TYPE.
- */
- if (pwdb_rid_is_well_known(rid))
- {
- /*
- * The only well known user RIDs are DOMAIN_USER_RID_ADMIN
- * and DOMAIN_USER_RID_GUEST.
- */
- if (rid == DOMAIN_USER_RID_ADMIN || rid == DOMAIN_USER_RID_GUEST)
- {
- return RID_TYPE_USER;
- }
- if (DOMAIN_GROUP_RID_ADMINS <= rid && rid <= DOMAIN_GROUP_RID_GUESTS)
- {
- return RID_TYPE_GROUP;
- }
- if (BUILTIN_ALIAS_RID_ADMINS <= rid && rid <= BUILTIN_ALIAS_RID_REPLICATOR)
- {
- return RID_TYPE_ALIAS;
- }
- }
- return (rid & RID_TYPE_MASK);
-}
-
-/*******************************************************************
- checks whether rid is a user rid. NOTE: THIS IS SOMETHING SPECIFIC TO SAMBA
- ********************************************************************/
-BOOL pwdb_rid_is_user(uint32 rid)
-{
- return pwdb_rid_type(rid) == RID_TYPE_USER;
-}
-
-/**************************************************************************
- Groupname map functionality. The code loads a groupname map file and
- (currently) loads it into a linked list. This is slow and memory
- hungry, but can be changed into a more efficient storage format
- if the demands on it become excessive.
-***************************************************************************/
-
-typedef struct name_map
-{
- ubi_slNode next;
- DOM_NAME_MAP grp;
-
-} name_map_entry;
-
-static ubi_slList groupname_map_list;
-static ubi_slList aliasname_map_list;
-static ubi_slList ntusrname_map_list;
-
-static void delete_name_entry(name_map_entry *gmep)
-{
- if (gmep->grp.nt_name)
- {
- free(gmep->grp.nt_name);
- }
- if (gmep->grp.nt_domain)
- {
- free(gmep->grp.nt_domain);
- }
- if (gmep->grp.unix_name)
- {
- free(gmep->grp.unix_name);
- }
- free((char*)gmep);
-}
-
-/**************************************************************************
- Delete all the entries in the name map list.
-***************************************************************************/
-
-static void delete_map_list(ubi_slList *map_list)
-{
- name_map_entry *gmep;
-
- while ((gmep = (name_map_entry *)ubi_slRemHead(map_list )) != NULL)
- {
- delete_name_entry(gmep);
- }
-}
-
-
-/**************************************************************************
- makes a group sid out of a domain sid and a _unix_ gid.
-***************************************************************************/
-static BOOL make_mydomain_sid(DOM_NAME_MAP *grp, DOM_MAP_TYPE type)
-{
- int ret = False;
- fstring sid_str;
-
- if (!map_domain_name_to_sid(&grp->sid, &(grp->nt_domain)))
- {
- DEBUG(0,("make_mydomain_sid: unknown domain %s\n",
- grp->nt_domain));
- return False;
- }
-
- if (sid_equal(&grp->sid, &global_sid_S_1_5_20))
- {
- /*
- * only builtin aliases are recognised in S-1-5-20
- */
- DEBUG(10,("make_mydomain_sid: group %s in builtin domain\n",
- grp->nt_name));
-
- if (lookup_builtin_alias_name(grp->nt_name, "BUILTIN", &grp->sid, &grp->type) != 0x0)
- {
- DEBUG(0,("unix group %s mapped to an unrecognised BUILTIN domain name %s\n",
- grp->unix_name, grp->nt_name));
- return False;
- }
- ret = True;
- }
- else if (lookup_wk_user_name(grp->nt_name, grp->nt_domain, &grp->sid, &grp->type) == 0x0)
- {
- if (type != DOM_MAP_USER)
- {
- DEBUG(0,("well-known NT user %s\\%s listed in wrong map file\n",
- grp->nt_domain, grp->nt_name));
- return False;
- }
- ret = True;
- }
- else if (lookup_wk_group_name(grp->nt_name, grp->nt_domain, &grp->sid, &grp->type) == 0x0)
- {
- if (type != DOM_MAP_DOMAIN)
- {
- DEBUG(0,("well-known NT group %s\\%s listed in wrong map file\n",
- grp->nt_domain, grp->nt_name));
- return False;
- }
- ret = True;
- }
- else
- {
- switch (type)
- {
- case DOM_MAP_USER:
- {
- grp->type = SID_NAME_USER;
- break;
- }
- case DOM_MAP_DOMAIN:
- {
- grp->type = SID_NAME_DOM_GRP;
- break;
- }
- case DOM_MAP_LOCAL:
- {
- grp->type = SID_NAME_ALIAS;
- break;
- }
- }
-
- ret = pwdb_unixid_to_sam_sid(grp->unix_id, grp->type, &grp->sid);
- }
-
- sid_to_string(sid_str, &grp->sid);
- DEBUG(10,("nt name %s\\%s gid %d mapped to %s\n",
- grp->nt_domain, grp->nt_name, grp->unix_id, sid_str));
- return ret;
-}
-
-/**************************************************************************
- makes a group sid out of an nt domain, nt group name or a unix group name.
-***************************************************************************/
-static BOOL unix_name_to_nt_name_info(DOM_NAME_MAP *map, DOM_MAP_TYPE type)
-{
- /*
- * Attempt to get the unix gid_t for this name.
- */
-
- DEBUG(5,("unix_name_to_nt_name_info: unix_name:%s\n", map->unix_name));
-
- if (type == DOM_MAP_USER)
- {
- const struct passwd *pwptr = Get_Pwnam(map->unix_name, False);
- if (pwptr == NULL)
- {
- DEBUG(0,("unix_name_to_nt_name_info: Get_Pwnam for user %s\
-failed. Error was %s.\n", map->unix_name, strerror(errno) ));
- return False;
- }
-
- map->unix_id = (uint32)pwptr->pw_uid;
- }
- else
- {
- struct group *gptr = getgrnam(map->unix_name);
- if (gptr == NULL)
- {
- DEBUG(0,("unix_name_to_nt_name_info: getgrnam for group %s\
-failed. Error was %s.\n", map->unix_name, strerror(errno) ));
- return False;
- }
-
- map->unix_id = (uint32)gptr->gr_gid;
- }
-
- DEBUG(5,("unix_name_to_nt_name_info: unix gid:%d\n", map->unix_id));
-
- /*
- * Now map the name to an NT SID+RID.
- */
-
- if (map->nt_domain != NULL && !strequal(map->nt_domain, global_sam_name))
- {
- /* Must add client-call lookup code here, to
- * resolve remote domain's sid and the group's rid,
- * in that domain.
- *
- * NOTE: it is _incorrect_ to put code here that assumes
- * we are responsible for lookups for foriegn domains' RIDs.
- *
- * for foriegn domains for which we are *NOT* the PDC, all
- * we can be responsible for is the unix gid_t to which
- * the foriegn SID+rid maps to, on this _local_ machine.
- * we *CANNOT* make any short-cuts or assumptions about
- * RIDs in a foriegn domain.
- */
-
- if (!map_domain_name_to_sid(&map->sid, &(map->nt_domain)))
- {
- DEBUG(0,("unix_name_to_nt_name_info: no known sid for %s\n",
- map->nt_domain));
- return False;
- }
- }
-
- return make_mydomain_sid(map, type);
-}
-
-static BOOL make_name_entry(name_map_entry **new_ep,
- char *nt_domain, char *nt_group, char *unix_group,
- DOM_MAP_TYPE type)
-{
- /*
- * Create the list entry and add it onto the list.
- */
-
- DEBUG(5,("make_name_entry:%s,%s,%s\n", nt_domain, nt_group, unix_group));
-
- (*new_ep) = (name_map_entry *)malloc(sizeof(name_map_entry));
- if ((*new_ep) == NULL)
- {
- DEBUG(0,("make_name_entry: malloc fail for name_map_entry.\n"));
- return False;
- }
-
- ZERO_STRUCTP(*new_ep);
-
- (*new_ep)->grp.nt_name = strdup(nt_group );
- (*new_ep)->grp.nt_domain = strdup(nt_domain );
- (*new_ep)->grp.unix_name = strdup(unix_group);
-
- if ((*new_ep)->grp.nt_name == NULL ||
- (*new_ep)->grp.unix_name == NULL)
- {
- DEBUG(0,("make_name_entry: malloc fail for names in name_map_entry.\n"));
- delete_name_entry((*new_ep));
- return False;
- }
-
- /*
- * look up the group names, make the Group-SID and unix gid
- */
-
- if (!unix_name_to_nt_name_info(&(*new_ep)->grp, type))
- {
- delete_name_entry((*new_ep));
- return False;
- }
-
- return True;
-}
-
-/**************************************************************************
- Load a name map file. Sets last accessed timestamp.
-***************************************************************************/
-static ubi_slList *load_name_map(DOM_MAP_TYPE type)
-{
- static time_t groupmap_file_last_modified = (time_t)0;
- static time_t aliasmap_file_last_modified = (time_t)0;
- static time_t ntusrmap_file_last_modified = (time_t)0;
- static BOOL initialised_group = False;
- static BOOL initialised_alias = False;
- static BOOL initialised_ntusr = False;
- char *groupname_map_file = lp_groupname_map();
- char *aliasname_map_file = lp_aliasname_map();
- char *ntusrname_map_file = lp_ntusrname_map();
-
- FILE *fp;
- char *s;
- pstring buf;
- name_map_entry *new_ep;
-
- time_t *file_last_modified = NULL;
- int *initialised = NULL;
- char *map_file = NULL;
- ubi_slList *map_list = NULL;
-
- switch (type)
- {
- case DOM_MAP_DOMAIN:
- {
- file_last_modified = &groupmap_file_last_modified;
- initialised = &initialised_group;
- map_file = groupname_map_file;
- map_list = &groupname_map_list;
-
- break;
- }
- case DOM_MAP_LOCAL:
- {
- file_last_modified = &aliasmap_file_last_modified;
- initialised = &initialised_alias;
- map_file = aliasname_map_file;
- map_list = &aliasname_map_list;
-
- break;
- }
- case DOM_MAP_USER:
- {
- file_last_modified = &ntusrmap_file_last_modified;
- initialised = &initialised_ntusr;
- map_file = ntusrname_map_file;
- map_list = &ntusrname_map_list;
-
- break;
- }
- }
-
- if (!(*initialised))
- {
- DEBUG(10,("initialising map %s\n", map_file));
- ubi_slInitList(map_list);
- (*initialised) = True;
- }
-
- if (!*map_file)
- {
- return map_list;
- }
-
- /*
- * Load the file.
- */
-
- fp = open_file_if_modified(map_file, "r", file_last_modified);
- if (!fp)
- {
- return map_list;
- }
-
- /*
- * Throw away any previous list.
- */
- delete_map_list(map_list);
-
- DEBUG(4,("load_name_map: Scanning name map %s\n",map_file));
-
- while ((s = fgets_slash(buf, sizeof(buf), fp)) != NULL)
- {
- pstring unixname;
- pstring nt_name;
- fstring nt_domain;
- fstring ntname;
- char *p;
-
- DEBUG(10,("Read line |%s|\n", s));
-
- memset(nt_name, 0, sizeof(nt_name));
-
- if (!*s || strchr("#;",*s))
- continue;
-
- if (!next_token(&s,unixname, "\t\n\r=", sizeof(unixname)))
- continue;
-
- if (!next_token(&s,nt_name, "\t\n\r=", sizeof(nt_name)))
- continue;
-
- trim_string(unixname, " ", " ");
- trim_string(nt_name, " ", " ");
-
- if (!*nt_name)
- continue;
-
- if (!*unixname)
- continue;
-
- p = strchr(nt_name, '\\');
-
- if (p == NULL)
- {
- memset(nt_domain, 0, sizeof(nt_domain));
- fstrcpy(ntname, nt_name);
- }
- else
- {
- *p = 0;
- p++;
- fstrcpy(nt_domain, nt_name);
- fstrcpy(ntname , p);
- }
-
- if (make_name_entry(&new_ep, nt_domain, ntname, unixname, type))
- {
- ubi_slAddTail(map_list, (ubi_slNode *)new_ep);
- DEBUG(5,("unixname = %s, ntname = %s\\%s type = %d\n",
- new_ep->grp.unix_name,
- new_ep->grp.nt_domain,
- new_ep->grp.nt_name,
- new_ep->grp.type));
- }
- }
-
- DEBUG(10,("load_name_map: Added %ld entries to name map.\n",
- ubi_slCount(map_list)));
-
- fclose(fp);
-
- return map_list;
-}
-
-static void copy_grp_map_entry(DOM_NAME_MAP *grp, const DOM_NAME_MAP *from)
-{
- sid_copy(&grp->sid, &from->sid);
- grp->unix_id = from->unix_id;
- grp->nt_name = from->nt_name;
- grp->nt_domain = from->nt_domain;
- grp->unix_name = from->unix_name;
- grp->type = from->type;
-}
-
-#if 0
-/***********************************************************
- Lookup unix name.
-************************************************************/
-static BOOL map_unixname(DOM_MAP_TYPE type,
- char *unixname, DOM_NAME_MAP *grp_info)
-{
- name_map_entry *gmep;
- ubi_slList *map_list;
-
- /*
- * Initialise and load if not already loaded.
- */
- map_list = load_name_map(type);
-
- for (gmep = (name_map_entry *)ubi_slFirst(map_list);
- gmep != NULL;
- gmep = (name_map_entry *)ubi_slNext(gmep ))
- {
- if (strequal(gmep->grp.unix_name, unixname))
- {
- copy_grp_map_entry(grp_info, &gmep->grp);
- DEBUG(7,("map_unixname: Mapping unix name %s to nt group %s.\n",
- gmep->grp.unix_name, gmep->grp.nt_name ));
- return True;
- }
- }
-
- return False;
-}
-
-#endif
-
-/***********************************************************
- Lookup nt name.
-************************************************************/
-static BOOL map_ntname(DOM_MAP_TYPE type, char *ntname, char *ntdomain,
- DOM_NAME_MAP *grp_info)
-{
- name_map_entry *gmep;
- ubi_slList *map_list;
-
- /*
- * Initialise and load if not already loaded.
- */
- map_list = load_name_map(type);
-
- for (gmep = (name_map_entry *)ubi_slFirst(map_list);
- gmep != NULL;
- gmep = (name_map_entry *)ubi_slNext(gmep ))
- {
- if (strequal(gmep->grp.nt_name , ntname) &&
- strequal(gmep->grp.nt_domain, ntdomain))
- {
- copy_grp_map_entry(grp_info, &gmep->grp);
- DEBUG(7,("map_ntname: Mapping unix name %s to nt name %s.\n",
- gmep->grp.unix_name, gmep->grp.nt_name ));
- return True;
- }
- }
-
- return False;
-}
-
-
-/***********************************************************
- Lookup by SID
-************************************************************/
-static BOOL map_sid(DOM_MAP_TYPE type,
- DOM_SID *psid, DOM_NAME_MAP *grp_info)
-{
- name_map_entry *gmep;
- ubi_slList *map_list;
-
- /*
- * Initialise and load if not already loaded.
- */
- map_list = load_name_map(type);
-
- for (gmep = (name_map_entry *)ubi_slFirst(map_list);
- gmep != NULL;
- gmep = (name_map_entry *)ubi_slNext(gmep ))
- {
- if (sid_equal(&gmep->grp.sid, psid))
- {
- copy_grp_map_entry(grp_info, &gmep->grp);
- DEBUG(7,("map_sid: Mapping unix name %s to nt name %s.\n",
- gmep->grp.unix_name, gmep->grp.nt_name ));
- return True;
- }
- }
-
- return False;
-}
-
-/***********************************************************
- Lookup by gid_t.
-************************************************************/
-static BOOL map_unixid(DOM_MAP_TYPE type, uint32 unix_id, DOM_NAME_MAP *grp_info)
-{
- name_map_entry *gmep;
- ubi_slList *map_list;
-
- /*
- * Initialise and load if not already loaded.
- */
- map_list = load_name_map(type);
-
- for (gmep = (name_map_entry *)ubi_slFirst(map_list);
- gmep != NULL;
- gmep = (name_map_entry *)ubi_slNext(gmep ))
- {
- fstring sid_str;
- sid_to_string(sid_str, &gmep->grp.sid);
- DEBUG(10,("map_unixid: enum entry unix group %s %d nt %s %s\n",
- gmep->grp.unix_name, gmep->grp.unix_id, gmep->grp.nt_name, sid_str));
- if (gmep->grp.unix_id == unix_id)
- {
- copy_grp_map_entry(grp_info, &gmep->grp);
- DEBUG(7,("map_unixid: Mapping unix name %s to nt name %s type %d\n",
- gmep->grp.unix_name, gmep->grp.nt_name, gmep->grp.type));
- return True;
- }
- }
-
- return False;
-}
-
-/***********************************************************
- *
- * Call four functions to resolve unix group ids and either
- * local group SIDs or domain group SIDs listed in the local group
- * or domain group map files.
- *
- * Note that it is *NOT* the responsibility of these functions to
- * resolve entries that are not in the map files.
- *
- * Any SID can be in the map files (i.e from any Domain).
- *
- ***********************************************************/
-
-#if 0
-
-/***********************************************************
- Lookup a UNIX Group entry by name.
-************************************************************/
-BOOL map_unix_group_name(char *group_name, DOM_NAME_MAP *grp_info)
-{
- return map_unixname(DOM_MAP_DOMAIN, group_name, grp_info);
-}
-
-/***********************************************************
- Lookup a UNIX Alias entry by name.
-************************************************************/
-BOOL map_unix_alias_name(char *alias_name, DOM_NAME_MAP *grp_info)
-{
- return map_unixname(DOM_MAP_LOCAL, alias_name, grp_info);
-}
-
-/***********************************************************
- Lookup an Alias name entry
-************************************************************/
-BOOL map_nt_alias_name(char *ntalias_name, char *nt_domain, DOM_NAME_MAP *grp_info)
-{
- return map_ntname(DOM_MAP_LOCAL, ntalias_name, nt_domain, grp_info);
-}
-
-/***********************************************************
- Lookup a Group entry
-************************************************************/
-BOOL map_nt_group_name(char *ntgroup_name, char *nt_domain, DOM_NAME_MAP *grp_info)
-{
- return map_ntname(DOM_MAP_DOMAIN, ntgroup_name, nt_domain, grp_info);
-}
-
-#endif
-
-/***********************************************************
- Lookup a Username entry by name.
-************************************************************/
-static BOOL map_nt_username(char *nt_name, char *nt_domain, DOM_NAME_MAP *grp_info)
-{
- return map_ntname(DOM_MAP_USER, nt_name, nt_domain, grp_info);
-}
-
-/***********************************************************
- Lookup a Username entry by SID.
-************************************************************/
-static BOOL map_username_sid(DOM_SID *sid, DOM_NAME_MAP *grp_info)
-{
- return map_sid(DOM_MAP_USER, sid, grp_info);
-}
-
-/***********************************************************
- Lookup a Username SID entry by uid.
-************************************************************/
-static BOOL map_username_uid(uid_t gid, DOM_NAME_MAP *grp_info)
-{
- return map_unixid(DOM_MAP_USER, (uint32)gid, grp_info);
-}
-
-/***********************************************************
- Lookup an Alias SID entry by name.
-************************************************************/
-BOOL map_alias_sid(DOM_SID *psid, DOM_NAME_MAP *grp_info)
-{
- return map_sid(DOM_MAP_LOCAL, psid, grp_info);
-}
-
-/***********************************************************
- Lookup a Group entry by sid.
-************************************************************/
-BOOL map_group_sid(DOM_SID *psid, DOM_NAME_MAP *grp_info)
-{
- return map_sid(DOM_MAP_DOMAIN, psid, grp_info);
-}
-
-/***********************************************************
- Lookup an Alias SID entry by gid_t.
-************************************************************/
-static BOOL map_alias_gid(gid_t gid, DOM_NAME_MAP *grp_info)
-{
- return map_unixid(DOM_MAP_LOCAL, (uint32)gid, grp_info);
-}
-
-/***********************************************************
- Lookup a Group SID entry by gid_t.
-************************************************************/
-static BOOL map_group_gid( gid_t gid, DOM_NAME_MAP *grp_info)
-{
- return map_unixid(DOM_MAP_DOMAIN, (uint32)gid, grp_info);
-}
-
-
-/************************************************************************
- Routine to look up User details by UNIX name
-*************************************************************************/
-BOOL lookupsmbpwnam(const char *unix_usr_name, DOM_NAME_MAP *grp)
-{
- uid_t uid;
- DEBUG(10,("lookupsmbpwnam: unix user name %s\n", unix_usr_name));
- if (nametouid(unix_usr_name, &uid))
- {
- return lookupsmbpwuid(uid, grp);
- }
- else
- {
- return False;
- }
-}
-
-/************************************************************************
- Routine to look up a remote nt name
-*************************************************************************/
-static BOOL lookup_remote_ntname(const char *ntname, DOM_SID *sid, uint8 *type)
-{
- struct cli_state cli;
- POLICY_HND lsa_pol;
- fstring srv_name;
- extern struct ntuser_creds *usr_creds;
- struct ntuser_creds usr;
-
- BOOL res3 = True;
- BOOL res4 = True;
- uint32 num_sids;
- DOM_SID *sids;
- uint8 *types;
- char *names[1];
-
- usr_creds = &usr;
-
- ZERO_STRUCT(usr);
- pwd_set_nullpwd(&usr.pwd);
-
- DEBUG(5,("lookup_remote_ntname: %s\n", ntname));
-
- if (!cli_connect_serverlist(&cli, lp_passwordserver()))
- {
- return False;
- }
-
- names[0] = ntname;
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, cli.desthost);
- strupper(srv_name);
-
- /* lookup domain controller; receive a policy handle */
- res3 = res3 ? lsa_open_policy( srv_name,
- &lsa_pol, True) : False;
-
- /* send lsa lookup sids call */
- res4 = res3 ? lsa_lookup_names( &lsa_pol,
- 1, names,
- &sids, &types, &num_sids) : False;
-
- res3 = res3 ? lsa_close(&lsa_pol) : False;
-
- if (res4 && res3 && sids != NULL && types != NULL)
- {
- sid_copy(sid, &sids[0]);
- *type = types[0];
- }
- else
- {
- res3 = False;
- }
- if (types != NULL)
- {
- free(types);
- }
-
- if (sids != NULL)
- {
- free(sids);
- }
-
- return res3 && res4;
-}
-
-/************************************************************************
- Routine to look up a remote nt name
-*************************************************************************/
-static BOOL get_sid_and_type(const char *fullntname, uint8 expected_type,
- DOM_NAME_MAP *gmep)
-{
- /*
- * check with the PDC to see if it owns the name. if so,
- * the SID is resolved with the PDC database.
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
- if (lookup_remote_ntname(fullntname, &gmep->sid, &gmep->type))
- {
- if (sid_front_equal(&gmep->sid, &global_member_sid) &&
- strequal(gmep->nt_domain, global_myworkgroup) &&
- gmep->type == expected_type)
- {
- return True;
- }
- return False;
- }
- }
-
- /*
- * ... otherwise, it's one of ours. map the sid ourselves,
- * which can only happen in our own SAM database.
- */
-
- if (!strequal(gmep->nt_domain, global_sam_name))
- {
- return False;
- }
- if (!pwdb_unixid_to_sam_sid(gmep->unix_id, gmep->type, &gmep->sid))
- {
- return False;
- }
-
- return True;
-}
-
-/*
- * used by lookup functions below
- */
-
-static fstring nt_name;
-static fstring unix_name;
-static fstring nt_domain;
-
-/*************************************************************************
- looks up a uid, returns User Information.
-*************************************************************************/
-BOOL lookupsmbpwuid(uid_t uid, DOM_NAME_MAP *gmep)
-{
- DEBUG(10,("lookupsmbpwuid: unix uid %d\n", uid));
- if (map_username_uid(uid, gmep))
- {
- return True;
- }
-#if 0
- if (lp_server_role() != ROLE_DOMAIN_NONE)
-#endif
- {
- gmep->nt_name = nt_name;
- gmep->unix_name = unix_name;
- gmep->nt_domain = nt_domain;
-
- gmep->unix_id = (uint32)uid;
-
- /*
- * ok, assume it's one of ours. then double-check it
- * if we are a member of a domain
- */
-
- gmep->type = SID_NAME_USER;
- fstrcpy(gmep->nt_name, uidtoname(uid));
- fstrcpy(gmep->unix_name, gmep->nt_name);
-
- /*
- * here we should do a LsaLookupNames() call
- * to check the status of the name with the PDC.
- * if the PDC know nothing of the name, it's ours.
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
-#if 0
- lsa_lookup_names(global_myworkgroup, gmep->nt_name, &gmep->sid...);
-#endif
- }
-
- /*
- * ok, it's one of ours.
- */
-
- gmep->nt_domain = global_sam_name;
- pwdb_unixid_to_sam_sid(gmep->unix_id, gmep->type, &gmep->sid);
-
- return True;
- }
-
- /* oops. */
-
- return False;
-}
-
-/*************************************************************************
- looks up by NT name, returns User Information.
-*************************************************************************/
-BOOL lookupsmbpwntnam(const char *fullntname, DOM_NAME_MAP *gmep)
-{
- DEBUG(10,("lookupsmbpwntnam: nt user name %s\n", fullntname));
-
- if (!split_domain_name(fullntname, nt_domain, nt_name))
- {
- return False;
- }
-
- if (map_nt_username(nt_name, nt_domain, gmep))
- {
- return True;
- }
- if (lp_server_role() != ROLE_DOMAIN_NONE)
- {
- uid_t uid;
- gmep->nt_name = nt_name;
- gmep->unix_name = unix_name;
- gmep->nt_domain = nt_domain;
-
- /*
- * ok, it's one of ours. we therefore "create" an nt user named
- * after the unix user. this is the point where "appliance mode"
- * should get its teeth in, as unix users won't really exist,
- * they will only be numbers...
- */
-
- gmep->type = SID_NAME_USER;
- fstrcpy(gmep->unix_name, gmep->nt_name);
- if (!nametouid(gmep->unix_name, &uid))
- {
- return False;
- }
- gmep->unix_id = (uint32)uid;
-
- return get_sid_and_type(fullntname, gmep->type, gmep);
- }
-
- /* oops. */
-
- return False;
-}
-
-/*************************************************************************
- looks up by RID, returns User Information.
-*************************************************************************/
-BOOL lookupsmbpwsid(DOM_SID *sid, DOM_NAME_MAP *gmep)
-{
- fstring sid_str;
- sid_to_string(sid_str, sid);
- DEBUG(10,("lookupsmbpwsid: nt sid %s\n", sid_str));
-
- if (map_username_sid(sid, gmep))
- {
- return True;
- }
- if (lp_server_role() != ROLE_DOMAIN_NONE)
- {
- gmep->nt_name = nt_name;
- gmep->unix_name = unix_name;
- gmep->nt_domain = nt_domain;
-
- /*
- * here we should do a LsaLookupNames() call
- * to check the status of the name with the PDC.
- * if the PDC know nothing of the name, it's ours.
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
-#if 0
- if (lookup_remote_sid(global_myworkgroup, gmep->sid, gmep->nt_name, gmep->nt_domain...);
-#endif
- }
-
- /*
- * ok, it's one of ours. we therefore "create" an nt user named
- * after the unix user. this is the point where "appliance mode"
- * should get its teeth in, as unix users won't really exist,
- * they will only be numbers...
- */
-
- gmep->type = SID_NAME_USER;
- sid_copy(&gmep->sid, sid);
- if (!pwdb_sam_sid_to_unixid(&gmep->sid, gmep->type, &gmep->unix_id))
- {
- return False;
- }
- fstrcpy(gmep->nt_name, uidtoname((uid_t)gmep->unix_id));
- fstrcpy(gmep->unix_name, gmep->nt_name);
- gmep->nt_domain = global_sam_name;
-
- return True;
- }
-
- /* oops. */
-
- return False;
-}
-
-/************************************************************************
- Routine to look up group / alias / well-known group RID by UNIX name
-*************************************************************************/
-BOOL lookupsmbgrpnam(const char *unix_grp_name, DOM_NAME_MAP *grp)
-{
- gid_t gid;
- DEBUG(10,("lookupsmbgrpnam: unix user group %s\n", unix_grp_name));
- if (nametogid(unix_grp_name, &gid))
- {
- return lookupsmbgrpgid(gid, grp);
- }
- else
- {
- return False;
- }
-}
-
-/*************************************************************************
- looks up a SID, returns name map entry
-*************************************************************************/
-BOOL lookupsmbgrpsid(DOM_SID *sid, DOM_NAME_MAP *gmep)
-{
- fstring sid_str;
- sid_to_string(sid_str, sid);
- DEBUG(10,("lookupsmbgrpsid: nt sid %s\n", sid_str));
-
- if (map_alias_sid(sid, gmep))
- {
- return True;
- }
- if (map_group_sid(sid, gmep))
- {
- return True;
- }
- if (lp_server_role() != ROLE_DOMAIN_NONE)
- {
- gmep->nt_name = nt_name;
- gmep->unix_name = unix_name;
- gmep->nt_domain = nt_domain;
-
- /*
- * here we should do a LsaLookupNames() call
- * to check the status of the name with the PDC.
- * if the PDC know nothing of the name, it's ours.
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
-#if 0
- lsa_lookup_sids(global_myworkgroup, gmep->sid, gmep->nt_name, gmep->nt_domain...);
-#endif
- }
-
- /*
- * ok, it's one of ours. we therefore "create" an nt group or
- * alias name named after the unix group. this is the point
- * where "appliance mode" should get its teeth in, as unix
- * groups won't really exist, they will only be numbers...
- */
-
- /* name is not explicitly mapped
- * with map files or the PDC
- * so we are responsible for it...
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
- /* ... as a LOCAL group. */
- gmep->type = SID_NAME_ALIAS;
- }
- else
- {
- /* ... as a DOMAIN group. */
- gmep->type = SID_NAME_DOM_GRP;
- }
-
- sid_copy(&gmep->sid, sid);
- if (!pwdb_sam_sid_to_unixid(&gmep->sid, gmep->type, &gmep->unix_id))
- {
- return False;
- }
- fstrcpy(gmep->nt_name, gidtoname((gid_t)gmep->unix_id));
- fstrcpy(gmep->unix_name, gmep->nt_name);
- gmep->nt_domain = global_sam_name;
-
- return True;
- }
-
- /* oops */
- return False;
-}
-
-/*************************************************************************
- looks up a gid, returns RID and type local, domain or well-known domain group
-*************************************************************************/
-BOOL lookupsmbgrpgid(gid_t gid, DOM_NAME_MAP *gmep)
-{
- DEBUG(10,("lookupsmbgrpgid: unix gid %d\n", (int)gid));
- if (map_alias_gid(gid, gmep))
- {
- return True;
- }
- if (map_group_gid(gid, gmep))
- {
- return True;
- }
- if (lp_server_role() != ROLE_DOMAIN_NONE)
- {
- gmep->nt_name = nt_name;
- gmep->unix_name = unix_name;
- gmep->nt_domain = nt_domain;
-
- gmep->unix_id = (uint32)gid;
-
- /*
- * here we should do a LsaLookupNames() call
- * to check the status of the name with the PDC.
- * if the PDC know nothing of the name, it's ours.
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
-#if 0
- if (lsa_lookup_names(global_myworkgroup, gmep->nt_name, &gmep->sid...);
- {
- return True;
- }
-#endif
- }
-
- /*
- * ok, it's one of ours. we therefore "create" an nt group or
- * alias name named after the unix group. this is the point
- * where "appliance mode" should get its teeth in, as unix
- * groups won't really exist, they will only be numbers...
- */
-
- /* name is not explicitly mapped
- * with map files or the PDC
- * so we are responsible for it...
- */
-
- if (lp_server_role() == ROLE_DOMAIN_MEMBER)
- {
- /* ... as a LOCAL group. */
- gmep->type = SID_NAME_ALIAS;
- }
- else
- {
- /* ... as a DOMAIN group. */
- gmep->type = SID_NAME_DOM_GRP;
- }
- fstrcpy(gmep->nt_name, gidtoname(gid));
- fstrcpy(gmep->unix_name, gmep->nt_name);
-
- return get_sid_and_type(gmep->nt_name, gmep->type, gmep);
- }
-
- /* oops */
- return False;
-}
-
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 7260e477b8..2c356d24e8 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -83,10 +83,10 @@ BOOL gencache_init(void)
BOOL gencache_shutdown(void)
{
- /* tdb_close routine returns -1 on error */
+ /* tdb_close routine returns 0 on successful close */
if (!cache) return False;
DEBUG(5, ("Closing cache file\n"));
- return tdb_close(cache) != -1;
+ return tdb_close(cache) ? False : True;
}
@@ -127,7 +127,7 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
SAFE_FREE(keybuf.dptr);
SAFE_FREE(databuf.dptr);
- return ret == 0;
+ return ret == 0 ? True : False;
}
@@ -182,7 +182,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout)
SAFE_FREE(keybuf.dptr);
SAFE_FREE(databuf.dptr);
- return ret == 0;
+ return ret == 0 ? True : False;
}
@@ -211,7 +211,7 @@ BOOL gencache_del(const char *keystr)
ret = tdb_delete(cache, keybuf);
SAFE_FREE(keybuf.dptr);
- return ret == 0;
+ return ret == 0 ? True : False;
}
diff --git a/source3/lib/genparser.c b/source3/lib/genparser.c
deleted file mode 100644
index 9fa9dbd33b..0000000000
--- a/source3/lib/genparser.c
+++ /dev/null
@@ -1,775 +0,0 @@
-/*
- Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
-
- 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.
-*/
-
-/*
- automatic marshalling/unmarshalling system for C structures
-*/
-
-#include "includes.h"
-
-/* see if a range of memory is all zero. Used to prevent dumping of zero elements */
-static int all_zero(const char *ptr, unsigned size)
-{
- int i;
- if (!ptr) return 1;
- for (i=0;i<size;i++) {
- if (ptr[i]) return 0;
- }
- return 1;
-}
-
-/* encode a buffer of bytes into a escaped string */
-static char *encode_bytes(const char *ptr, unsigned len)
-{
- const char *hexdig = "0123456789abcdef";
- char *ret, *p;
- unsigned i;
- ret = malloc(len*3 + 1); /* worst case size */
- if (!ret) return NULL;
- for (p=ret,i=0;i<len;i++) {
- if (isalnum(ptr[i]) || isspace(ptr[i]) ||
- (ispunct(ptr[i]) && !strchr("\\{}", ptr[i]))) {
- *p++ = ptr[i];
- } else {
- unsigned char c = *(unsigned char *)(ptr+i);
- if (c == 0 && all_zero(ptr+i, len-i)) break;
- p[0] = '\\';
- p[1] = hexdig[c>>4];
- p[2] = hexdig[c&0xF];
- p += 3;
- }
- }
-
- *p = 0;
-
- return ret;
-}
-
-/* decode an escaped string from encode_bytes() into a buffer */
-static char *decode_bytes(const char *s, unsigned *len)
-{
- char *ret, *p;
- unsigned i;
- ret = calloc(1, strlen(s)+1); /* worst case length */
-
- if (*s == '{') s++;
-
- for (p=ret,i=0;s[i];i++) {
- if (s[i] == '}') {
- break;
- } else if (s[i] == '\\') {
- unsigned v;
- if (sscanf(&s[i+1], "%02x", &v) != 1 || v > 255) {
- free(ret);
- return NULL;
- }
- *(unsigned char *)p = v;
- p++;
- i += 2;
- } else {
- *p++ = s[i];
- }
- }
- *p = 0;
-
- (*len) = (unsigned)(p - ret);
-
- return ret;
-}
-
-/* the add*() functions deal with adding things to a struct
- parse_string */
-
-/* allocate more space if needed */
-static int addgen_alloc(struct parse_string *p, int n)
-{
- if (p->length + n <= p->allocated) return 0;
- p->allocated = p->length + n + 200;
- p->s = realloc(p->s, p->allocated);
- if (!p->s) {
- errno = ENOMEM;
- return -1;
- }
- return 0;
-}
-
-/* add a character to the buffer */
-static int addchar(struct parse_string *p, char c)
-{
- if (addgen_alloc(p, 2) != 0) {
- return -1;
- }
- p->s[p->length++] = c;
- p->s[p->length] = 0;
- return 0;
-}
-
-/* add a string to the buffer */
-int addstr(struct parse_string *p, const char *s)
-{
- int len = strlen(s);
- if (addgen_alloc(p, len+1) != 0) {
- return -1;
- }
- memcpy(p->s + p->length, s, len+1);
- p->length += len;
- return 0;
-}
-
-/* add a string to the buffer with a tab prefix */
-static int addtabbed(struct parse_string *p, const char *s, unsigned indent)
-{
- int len = strlen(s);
- if (addgen_alloc(p, indent+len+1) != 0) {
- return -1;
- }
- while (indent--) {
- p->s[p->length++] = '\t';
- }
- memcpy(p->s + p->length, s, len+1);
- p->length += len;
- return 0;
-}
-
-/* note! this can only be used for results up to 60 chars wide! */
-int addshort(struct parse_string *p, const char *fmt, ...)
-{
- char buf[60];
- int n;
- va_list ap;
- va_start(ap, fmt);
- n = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- if (addgen_alloc(p, n + 1) != 0) {
- return -1;
- }
- if (n != 0) {
- memcpy(p->s + p->length, buf, n);
- }
- p->length += n;
- p->s[p->length] = 0;
- return 0;
-}
-
-/*
- this is here to make it easier for people to write dump functions
- for their own types
- */
-int gen_addgen(struct parse_string *p, const char *fmt, ...)
-{
- char *buf = NULL;
- int n;
- va_list ap;
- va_start(ap, fmt);
- n = vasprintf(&buf, fmt, ap);
- va_end(ap);
- if (addgen_alloc(p, n + 1) != 0) {
- if (buf) free(buf);
- return -1;
- }
- if (n != 0) {
- memcpy(p->s + p->length, buf, n);
- }
- p->length += n;
- p->s[p->length] = 0;
- if (buf) free(buf);
- return 0;
-}
-
-/* dump a enumerated type */
-int gen_dump_enum(const struct enum_struct *einfo,
- struct parse_string *p,
- const char *ptr,
- unsigned indent)
-{
- unsigned v = *(unsigned *)ptr;
- int i;
- for (i=0;einfo[i].name;i++) {
- if (v == einfo[i].value) {
- addstr(p, einfo[i].name);
- return 0;
- }
- }
- /* hmm, maybe we should just fail? */
- return gen_dump_unsigned(p, ptr, indent);
-}
-
-/* dump a single non-array element, hanlding struct and enum */
-static int gen_dump_one(struct parse_string *p,
- const struct parse_struct *pinfo,
- const char *ptr,
- unsigned indent)
-{
- if (pinfo->dump_fn == gen_dump_char && pinfo->ptr_count == 1) {
- char *s = encode_bytes(ptr, strlen(ptr));
- if (addchar(p,'{') ||
- addstr(p, s) ||
- addstr(p, "}")) {
- free(s);
- return -1;
- }
- return 0;
- }
-
- return pinfo->dump_fn(p, ptr, indent);
-}
-
-/* handle dumping of an array of arbitrary type */
-static int gen_dump_array(struct parse_string *p,
- const struct parse_struct *pinfo,
- const char *ptr,
- int array_len,
- int indent)
-{
- int i, count=0;
-
- /* special handling of fixed length strings */
- if (array_len != 0 &&
- pinfo->ptr_count == 0 &&
- pinfo->dump_fn == gen_dump_char) {
- char *s = encode_bytes(ptr, array_len);
- if (!s) return -1;
- if (addtabbed(p, pinfo->name, indent) ||
- addstr(p, " = {") ||
- addstr(p, s) ||
- addstr(p, "}\n")) {
- free(s);
- return -1;
- }
- free(s);
- return 0;
- }
-
- for (i=0;i<array_len;i++) {
- const char *p2 = ptr;
- unsigned size = pinfo->size;
-
- /* generic pointer dereference */
- if (pinfo->ptr_count) {
- p2 = *(const char **)ptr;
- size = sizeof(void *);
- }
-
- if ((count || pinfo->ptr_count) &&
- !(pinfo->flags & FLAG_ALWAYS) &&
- all_zero(ptr, size)) {
- ptr += size;
- continue;
- }
- if (count == 0) {
- if (addtabbed(p, pinfo->name, indent) ||
- addshort(p, " = %u:", i)) {
- return -1;
- }
- } else {
- if (addshort(p, ", %u:", i) != 0) {
- return -1;
- }
- }
- if (gen_dump_one(p, pinfo, p2, indent) != 0) {
- return -1;
- }
- ptr += size;
- count++;
- }
- if (count) {
- return addstr(p, "\n");
- }
- return 0;
-}
-
-/* find a variable by name in a loaded structure and return its value
- as an integer. Used to support dynamic arrays */
-static int find_var(const struct parse_struct *pinfo,
- const char *data,
- const char *var)
-{
- int i;
- const char *ptr;
-
- /* this allows for constant lengths */
- if (isdigit(*var)) {
- return atoi(var);
- }
-
- for (i=0;pinfo[i].name;i++) {
- if (strcmp(pinfo[i].name, var) == 0) break;
- }
- if (!pinfo[i].name) return -1;
-
- ptr = data + pinfo[i].offset;
-
- switch (pinfo[i].size) {
- case sizeof(int):
- return *(int *)ptr;
- case sizeof(char):
- return *(char *)ptr;
- }
-
- return -1;
-}
-
-
-int gen_dump_struct(const struct parse_struct *pinfo,
- struct parse_string *p,
- const char *ptr,
- unsigned indent)
-{
- char *s = gen_dump(pinfo, ptr, indent+1);
- if (!s) return -1;
- if (addstr(p, "{\n") ||
- addstr(p,s) ||
- addtabbed(p,"}", indent)) {
- free(s);
- return -1;
- }
- free(s);
- return 0;
-}
-
-static int gen_dump_string(struct parse_string *p,
- const struct parse_struct *pinfo,
- const char *data,
- unsigned indent)
-{
- const char *ptr = *(char **)data;
- char *s = encode_bytes(ptr, strlen(ptr));
- if (addtabbed(p, pinfo->name, indent) ||
- addstr(p, " = ") ||
- addchar(p,'{') ||
- addstr(p, s) ||
- addstr(p, "}\n")) {
- free(s);
- return -1;
- }
- return 0;
-}
-
-/*
- find the length of a nullterm array
-*/
-static int len_nullterm(const char *ptr, int size, int array_len)
-{
- int len;
-
- if (size == 1) {
- len = strnlen(ptr, array_len);
- } else {
- for (len=0;len<array_len;len++) {
- if (all_zero(ptr+len*size, size)) break;
- }
- }
-
- if (len == 0) len = 1;
-
- return len;
-}
-
-
-/* the generic dump routine. Scans the parse information for this structure
- and processes it recursively */
-char *gen_dump(const struct parse_struct *pinfo,
- const char *data,
- unsigned indent)
-{
- struct parse_string p;
- int i;
-
- p.length = 0;
- p.allocated = 0;
- p.s = NULL;
-
- if (addstr(&p, "") != 0) {
- return NULL;
- }
-
- for (i=0;pinfo[i].name;i++) {
- const char *ptr = data + pinfo[i].offset;
- unsigned size = pinfo[i].size;
-
- if (pinfo[i].ptr_count) {
- size = sizeof(void *);
- }
-
- /* special handling for array types */
- if (pinfo[i].array_len) {
- unsigned len = pinfo[i].array_len;
- if (pinfo[i].flags & FLAG_NULLTERM) {
- len = len_nullterm(ptr, size, len);
- }
- if (gen_dump_array(&p, &pinfo[i], ptr,
- len, indent)) {
- goto failed;
- }
- continue;
- }
-
- /* and dynamically sized arrays */
- if (pinfo[i].dynamic_len) {
- int len = find_var(pinfo, data, pinfo[i].dynamic_len);
- struct parse_struct p2 = pinfo[i];
- if (len < 0) {
- goto failed;
- }
- if (len > 0) {
- if (pinfo[i].flags & FLAG_NULLTERM) {
- len = len_nullterm(*(char **)ptr,
- pinfo[i].size, len);
- }
- p2.ptr_count--;
- p2.dynamic_len = NULL;
- if (gen_dump_array(&p, &p2, *(char **)ptr,
- len, indent) != 0) {
- goto failed;
- }
- }
- continue;
- }
-
- /* don't dump zero elements */
- if (!(pinfo[i].flags & FLAG_ALWAYS) && all_zero(ptr, size)) continue;
-
- /* assume char* is a null terminated string */
- if (pinfo[i].size == 1 && pinfo[i].ptr_count == 1 &&
- pinfo[i].dump_fn == gen_dump_char) {
- if (gen_dump_string(&p, &pinfo[i], ptr, indent) != 0) {
- goto failed;
- }
- continue;
- }
-
- /* generic pointer dereference */
- if (pinfo[i].ptr_count) {
- ptr = *(const char **)ptr;
- }
-
- if (addtabbed(&p, pinfo[i].name, indent) ||
- addstr(&p, " = ") ||
- gen_dump_one(&p, &pinfo[i], ptr, indent) ||
- addstr(&p, "\n")) {
- goto failed;
- }
- }
- return p.s;
-
-failed:
- free(p.s);
- return NULL;
-}
-
-/* search for a character in a string, skipping over sections within
- matching braces */
-static char *match_braces(char *s, char c)
-{
- int depth = 0;
- while (*s) {
- switch (*s) {
- case '}':
- depth--;
- break;
- case '{':
- depth++;
- break;
- }
- if (depth == 0 && *s == c) {
- return s;
- }
- s++;
- }
- return s;
-}
-
-/* parse routine for enumerated types */
-int gen_parse_enum(const struct enum_struct *einfo,
- char *ptr,
- const char *str)
-{
- unsigned v;
- int i;
-
- if (isdigit(*str)) {
- if (sscanf(str, "%u", &v) != 1) {
- errno = EINVAL;
- return -1;
- }
- *(unsigned *)ptr = v;
- return 0;
- }
-
- for (i=0;einfo[i].name;i++) {
- if (strcmp(einfo[i].name, str) == 0) {
- *(unsigned *)ptr = einfo[i].value;
- return 0;
- }
- }
-
- /* unknown enum value?? */
- return -1;
-}
-
-
-/* parse all base types */
-static int gen_parse_base(const struct parse_struct *pinfo,
- char *ptr,
- const char *str)
-{
- if (pinfo->parse_fn == gen_parse_char && pinfo->ptr_count==1) {
- unsigned len;
- char *s = decode_bytes(str, &len);
- if (!s) return -1;
- *(char **)ptr = s;
- return 0;
- }
-
- if (pinfo->ptr_count) {
- struct parse_struct p2 = *pinfo;
- *(void **)ptr = calloc(1, pinfo->ptr_count>1?sizeof(void *):pinfo->size);
- if (! *(void **)ptr) {
- return -1;
- }
- ptr = *(char **)ptr;
- p2.ptr_count--;
- return gen_parse_base(&p2, ptr, str);
- }
-
- return pinfo->parse_fn(ptr, str);
-}
-
-/* parse a generic array */
-static int gen_parse_array(const struct parse_struct *pinfo,
- char *ptr,
- const char *str,
- int array_len)
-{
- char *p, *p2;
- unsigned size = pinfo->size;
-
- /* special handling of fixed length strings */
- if (array_len != 0 &&
- pinfo->ptr_count == 0 &&
- pinfo->dump_fn == gen_dump_char) {
- unsigned len = 0;
- char *s = decode_bytes(str, &len);
- if (!s) return -1;
- memset(ptr, 0, array_len);
- memcpy(ptr, s, len);
- free(s);
- return 0;
- }
-
- if (pinfo->ptr_count) {
- size = sizeof(void *);
- }
-
- while (*str) {
- unsigned idx;
- int done;
-
- idx = atoi(str);
- p = strchr(str,':');
- if (!p) break;
- p++;
- p2 = match_braces(p, ',');
- done = (*p2 != ',');
- *p2 = 0;
-
- if (*p == '{') {
- p++;
- p[strlen(p)-1] = 0;
- }
-
- if (gen_parse_base(pinfo, ptr + idx*size, p) != 0) {
- return -1;
- }
-
- if (done) break;
- str = p2+1;
- }
-
- return 0;
-}
-
-/* parse one element, hanlding dynamic and static arrays */
-static int gen_parse_one(const struct parse_struct *pinfo,
- const char *name,
- char *data,
- const char *str)
-{
- int i;
- for (i=0;pinfo[i].name;i++) {
- if (strcmp(pinfo[i].name, name) == 0) {
- break;
- }
- }
- if (pinfo[i].name == NULL) {
- return 0;
- }
-
- if (pinfo[i].array_len) {
- return gen_parse_array(&pinfo[i], data+pinfo[i].offset,
- str, pinfo[i].array_len);
- }
-
- if (pinfo[i].dynamic_len) {
- int len = find_var(pinfo, data, pinfo[i].dynamic_len);
- if (len < 0) {
- errno = EINVAL;
- return -1;
- }
- if (len > 0) {
- unsigned size;
- struct parse_struct p2 = pinfo[i];
- char *ptr;
- size = pinfo[i].ptr_count>1?sizeof(void*):pinfo[i].size;
- ptr = calloc(len, size);
- if (!ptr) {
- errno = ENOMEM;
- return -1;
- }
- *((char **)(data + pinfo[i].offset)) = ptr;
- p2.ptr_count--;
- p2.dynamic_len = NULL;
- return gen_parse_array(&p2, ptr, str, len);
- }
- return 0;
- }
-
- return gen_parse_base(&pinfo[i], data + pinfo[i].offset, str);
-}
-
-int gen_parse_struct(const struct parse_struct *pinfo, char *ptr, const char *str)
-{
- return gen_parse(pinfo, ptr, str);
-}
-
-/* the main parse routine */
-int gen_parse(const struct parse_struct *pinfo, char *data, const char *s)
-{
- char *str, *s0;
-
- s0 = strdup(s);
- str = s0;
-
- while (*str) {
- char *p;
- char *name;
- char *value;
-
- /* skip leading whitespace */
- while (isspace(*str)) str++;
-
- p = strchr(str, '=');
- if (!p) break;
- value = p+1;
- while (p > str && isspace(*(p-1))) {
- p--;
- }
-
- *p = 0;
- name = str;
-
- while (isspace(*value)) value++;
-
- if (*value == '{') {
- str = match_braces(value, '}');
- value++;
- } else {
- str = match_braces(value, '\n');
- }
-
- *str++ = 0;
-
- if (gen_parse_one(pinfo, name, data, value) != 0) {
- free(s0);
- return -1;
- }
- }
-
- free(s0);
- return 0;
-}
-
-
-
-/* for convenience supply some standard dumpers and parsers here */
-
-int gen_parse_char(char *ptr, const char *str)
-{
- *(unsigned char *)ptr = atoi(str);
- return 0;
-}
-
-int gen_parse_int(char *ptr, const char *str)
-{
- *(int *)ptr = atoi(str);
- return 0;
-}
-
-int gen_parse_unsigned(char *ptr, const char *str)
-{
- *(unsigned *)ptr = strtoul(str, NULL, 10);
- return 0;
-}
-
-int gen_parse_time_t(char *ptr, const char *str)
-{
- *(time_t *)ptr = strtoul(str, NULL, 10);
- return 0;
-}
-
-int gen_parse_double(char *ptr, const char *str)
-{
- *(double *)ptr = atof(str);
- return 0;
-}
-
-int gen_parse_float(char *ptr, const char *str)
-{
- *(float *)ptr = atof(str);
- return 0;
-}
-
-int gen_dump_char(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", *(unsigned char *)(ptr));
-}
-
-int gen_dump_int(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%d", *(int *)(ptr));
-}
-
-int gen_dump_unsigned(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", *(unsigned *)(ptr));
-}
-
-int gen_dump_time_t(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", *(time_t *)(ptr));
-}
-
-int gen_dump_double(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%lg", *(double *)(ptr));
-}
-
-int gen_dump_float(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%g", *(float *)(ptr));
-}
diff --git a/source3/lib/genparser_samba.c b/source3/lib/genparser_samba.c
deleted file mode 100644
index 6c700d1094..0000000000
--- a/source3/lib/genparser_samba.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
- Copyright (C) Simo Sorce <idra@samba.org> 2002
-
- 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"
-#include "genparser_samba.h"
-
-/* PARSE functions */
-
-int gen_parse_uint8(char *ptr, const char *str)
-{
- *(uint8 *)ptr = atoi(str);
- return 0;
-}
-
-int gen_parse_uint16(char *ptr, const char *str)
-{
- *(uint16 *)ptr = atoi(str);
- return 0;
-}
-
-int gen_parse_uint32(char *ptr, const char *str)
-{
- *(uint32 *)ptr = strtoul(str, NULL, 10);
- return 0;
-}
-
-int gen_parse_NTTIME(char *ptr, const char *str)
-{
- if(sscanf(str, "%u,%u", &(((NTTIME *)(ptr))->high), &(((NTTIME *)(ptr))->low)) != 2) {
- errno = EINVAL;
- return -1;
- }
- return 0;
-}
-
-int gen_parse_DOM_SID(char *ptr, const char *str)
-{
- if(!string_to_sid((DOM_SID *)ptr, str)) return -1;
- return 0;
-}
-
-int gen_parse_SEC_ACCESS(char *ptr, const char *str)
-{
- ((SEC_ACCESS *)ptr)->mask = strtoul(str, NULL, 10);
- return 0;
-}
-
-int gen_parse_GUID(char *ptr, const char *str)
-{
- int info[GUID_SIZE];
- int i;
- char *sc;
- char *p;
- char *m;
-
- m = strdup(str);
- if (!m) return -1;
- sc = m;
-
- memset(info, 0, sizeof(info));
- for (i = 0; i < GUID_SIZE; i++) {
- p = strchr(sc, ',');
- if (p != NULL) p = '\0';
- info[i] = atoi(sc);
- if (p != NULL) sc = p + 1;
- }
- free(m);
-
- for (i = 0; i < GUID_SIZE; i++) {
- ((GUID *)ptr)->info[i] = info[i];
- }
-
- return 0;
-}
-
-int gen_parse_SEC_ACE(char *ptr, const char *str)
-{
- return gen_parse_struct(pinfo_security_ace_info, ptr, str);
-}
-
-int gen_parse_SEC_ACL(char *ptr, const char *str)
-{
- return gen_parse_struct(pinfo_security_acl_info, ptr, str);
-}
-
-int gen_parse_SEC_DESC(char *ptr, const char *str)
-{
- return gen_parse_struct(pinfo_security_descriptor_info, ptr, str);
-}
-
-int gen_parse_LUID_ATTR(char *ptr, const char *str)
-{
- return gen_parse_struct(pinfo_luid_attr_info, ptr, str);
-}
-
-int gen_parse_LUID(char *ptr, const char *str)
-{
- if(sscanf(str, "%u,%u", &(((LUID *)(ptr))->high), &(((LUID *)(ptr))->low)) != 2) {
- errno = EINVAL;
- return -1;
- }
- return 0;
-}
-
-
-
-/* DUMP functions */
-
-int gen_dump_uint8(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", *(uint8 *)(ptr));
-}
-
-int gen_dump_uint16(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", *(uint16 *)(ptr));
-}
-
-int gen_dump_uint32(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", *(uint32 *)(ptr));
-}
-
-int gen_dump_NTTIME(struct parse_string *p, const char *ptr, unsigned indent)
-{
- uint32 low, high;
-
- high = ((NTTIME *)(ptr))->high;
- low = ((NTTIME *)(ptr))->low;
- return addshort(p, "%u,%u", high, low);
-}
-
-int gen_dump_DOM_SID(struct parse_string *p, const char *ptr, unsigned indent)
-{
- fstring sidstr;
-
- sid_to_string(sidstr, (DOM_SID *)ptr);
- return addstr(p, sidstr);
-}
-
-int gen_dump_SEC_ACCESS(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return addshort(p, "%u", ((SEC_ACCESS *)ptr)->mask);
-}
-
-int gen_dump_GUID(struct parse_string *p, const char *ptr, unsigned indent)
-{
- int i, r;
-
- for (i = 0; i < (GUID_SIZE - 1); i++) {
- if (!(r = addshort(p, "%d,", ((GUID *)ptr)->info[i]))) return r;
- }
- return addshort(p, "%d", ((GUID *)ptr)->info[i]);
-}
-
-int gen_dump_SEC_ACE(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return gen_dump_struct(pinfo_security_ace_info, p, ptr, indent);
-}
-
-int gen_dump_SEC_ACL(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return gen_dump_struct(pinfo_security_acl_info, p, ptr, indent);
-}
-
-int gen_dump_SEC_DESC(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return gen_dump_struct(pinfo_security_descriptor_info, p, ptr, indent);
-}
-
-int gen_dump_LUID_ATTR(struct parse_string *p, const char *ptr, unsigned indent)
-{
- return gen_dump_struct(pinfo_luid_attr_info, p, ptr, indent);
-}
-
-int gen_dump_LUID(struct parse_string *p, const char *ptr, unsigned indent)
-{
- uint32 low, high;
-
- high = ((LUID *)(ptr))->high;
- low = ((LUID *)(ptr))->low;
- return addshort(p, "%u,%u", high, low);
-}
-
diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c
index 5292e9cf0a..43350d9349 100644
--- a/source3/lib/iconv.c
+++ b/source3/lib/iconv.c
@@ -2,7 +2,6 @@
Unix SMB/CIFS implementation.
minimal iconv implementation
Copyright (C) Andrew Tridgell 2001
- Copyright (C) Jelmer Vernooij 2002
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
@@ -25,51 +24,31 @@ static size_t ascii_pull(void *,char **, size_t *, char **, size_t *);
static size_t ascii_push(void *,char **, size_t *, char **, size_t *);
static size_t utf8_pull(void *,char **, size_t *, char **, size_t *);
static size_t utf8_push(void *,char **, size_t *, char **, size_t *);
+static size_t weird_pull(void *,char **, size_t *, char **, size_t *);
+static size_t weird_push(void *,char **, size_t *, char **, size_t *);
static size_t ucs2hex_pull(void *,char **, size_t *, char **, size_t *);
static size_t ucs2hex_push(void *,char **, size_t *, char **, size_t *);
static size_t iconv_copy(void *,char **, size_t *, char **, size_t *);
-static struct charset_functions builtin_functions[] = {
+/*
+ for each charset we have a function that pulls from that charset to
+ a ucs2 buffer, and a function that pushes to a ucs2 buffer
+*/
+static struct {
+ char *name;
+ size_t (*pull)(void *, char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft);
+ size_t (*push)(void *, char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft);
+} charsets[] = {
{"UCS-2LE", iconv_copy, iconv_copy},
{"UTF8", utf8_pull, utf8_push},
{"ASCII", ascii_pull, ascii_push},
+ {"WEIRD", weird_pull, weird_push},
{"UCS2-HEX", ucs2hex_pull, ucs2hex_push},
{NULL, NULL, NULL}
};
-static struct charset_functions *charsets = NULL;
-
-BOOL smb_register_charset(struct charset_functions *funcs)
-{
- struct charset_functions *c = charsets;
-
- DEBUG(5, ("Attempting to register new charset %s\n", funcs->name));
- /* Check whether we already have this charset... */
- while(c) {
- if(!strcasecmp(c->name, funcs->name)){
- DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name));
- return False;
- }
- c = c->next;
- }
-
- funcs->next = funcs->prev = NULL;
- DEBUG(5, ("Registered charset %s\n", funcs->name));
- DLIST_ADD(charsets, funcs);
- return True;
-}
-
-void lazy_initialize_iconv(void)
-{
- static BOOL initialized = False;
- int i;
-
- if (!initialized) {
- initialized = True;
- for(i = 0; builtin_functions[i].name; i++)
- smb_register_charset(&builtin_functions[i]);
- }
-}
/* if there was an error then reset the internal state,
this ensures that we don't have a shift state remaining for
@@ -136,11 +115,7 @@ size_t smb_iconv(smb_iconv_t cd,
smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
{
smb_iconv_t ret;
- struct charset_functions *from, *to;
-
- lazy_initialize_iconv();
- from = charsets;
- to = charsets;
+ int from, to;
ret = (smb_iconv_t)malloc(sizeof(*ret));
if (!ret) {
@@ -158,52 +133,48 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
return ret;
}
- while (from) {
- if (strcasecmp(from->name, fromcode) == 0) break;
- from = from->next;
+ for (from=0; charsets[from].name; from++) {
+ if (strcasecmp(charsets[from].name, fromcode) == 0) break;
}
-
- while (to) {
- if (strcasecmp(to->name, tocode) == 0) break;
- to = to->next;
+ for (to=0; charsets[to].name; to++) {
+ if (strcasecmp(charsets[to].name, tocode) == 0) break;
}
#ifdef HAVE_NATIVE_ICONV
- if (!from) {
+ if (!charsets[from].name) {
ret->pull = sys_iconv;
ret->cd_pull = iconv_open("UCS-2LE", fromcode);
if (ret->cd_pull == (iconv_t)-1) goto failed;
}
-
- if (!to) {
+ if (!charsets[to].name) {
ret->push = sys_iconv;
ret->cd_push = iconv_open(tocode, "UCS-2LE");
if (ret->cd_push == (iconv_t)-1) goto failed;
}
#else
- if (!from || !to) {
+ if (!charsets[from].name || !charsets[to].name) {
goto failed;
}
#endif
/* check for conversion to/from ucs2 */
- if (strcasecmp(fromcode, "UCS-2LE") == 0 && to) {
- ret->direct = to->push;
+ if (from == 0 && charsets[to].name) {
+ ret->direct = charsets[to].push;
return ret;
}
- if (strcasecmp(tocode, "UCS-2LE") == 0 && from) {
- ret->direct = from->pull;
+ if (to == 0 && charsets[from].name) {
+ ret->direct = charsets[from].pull;
return ret;
}
#ifdef HAVE_NATIVE_ICONV
- if (strcasecmp(fromcode, "UCS-2LE") == 0) {
+ if (from == 0) {
ret->direct = sys_iconv;
ret->cd_direct = ret->cd_push;
ret->cd_push = NULL;
return ret;
}
- if (strcasecmp(tocode, "UCS-2LE") == 0) {
+ if (to == 0) {
ret->direct = sys_iconv;
ret->cd_direct = ret->cd_pull;
ret->cd_pull = NULL;
@@ -212,8 +183,8 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
#endif
/* the general case has to go via a buffer */
- if (!ret->pull) ret->pull = from->pull;
- if (!ret->push) ret->push = to->push;
+ if (!ret->pull) ret->pull = charsets[from].pull;
+ if (!ret->push) ret->push = charsets[to].push;
return ret;
failed:
@@ -381,6 +352,111 @@ static size_t ucs2hex_push(void *cd, char **inbuf, size_t *inbytesleft,
}
+/* the "weird" character set is very useful for testing multi-byte
+ support and finding bugs. Don't use on a production system!
+*/
+static struct {
+ char from;
+ char *to;
+ int len;
+} weird_table[] = {
+ {'q', "^q^", 3},
+ {'Q', "^Q^", 3},
+ {0, NULL}
+};
+
+static size_t weird_pull(void *cd, char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+ while (*inbytesleft >= 1 && *outbytesleft >= 2) {
+ int i;
+ int done = 0;
+ for (i=0;weird_table[i].from;i++) {
+ if (strncmp((*inbuf),
+ weird_table[i].to,
+ weird_table[i].len) == 0) {
+ if (*inbytesleft < weird_table[i].len) {
+ DEBUG(0,("ERROR: truncated weird string\n"));
+ /* smb_panic("weird_pull"); */
+
+ } else {
+ (*outbuf)[0] = weird_table[i].from;
+ (*outbuf)[1] = 0;
+ (*inbytesleft) -= weird_table[i].len;
+ (*outbytesleft) -= 2;
+ (*inbuf) += weird_table[i].len;
+ (*outbuf) += 2;
+ done = 1;
+ break;
+ }
+ }
+ }
+ if (done) continue;
+ (*outbuf)[0] = (*inbuf)[0];
+ (*outbuf)[1] = 0;
+ (*inbytesleft) -= 1;
+ (*outbytesleft) -= 2;
+ (*inbuf) += 1;
+ (*outbuf) += 2;
+ }
+
+ if (*inbytesleft > 0) {
+ errno = E2BIG;
+ return -1;
+ }
+
+ return 0;
+}
+
+static size_t weird_push(void *cd, char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+ int ir_count=0;
+
+ while (*inbytesleft >= 2 && *outbytesleft >= 1) {
+ int i;
+ int done=0;
+ for (i=0;weird_table[i].from;i++) {
+ if ((*inbuf)[0] == weird_table[i].from &&
+ (*inbuf)[1] == 0) {
+ if (*outbytesleft < weird_table[i].len) {
+ DEBUG(0,("No room for weird character\n"));
+ /* smb_panic("weird_push"); */
+ } else {
+ memcpy(*outbuf, weird_table[i].to,
+ weird_table[i].len);
+ (*inbytesleft) -= 2;
+ (*outbytesleft) -= weird_table[i].len;
+ (*inbuf) += 2;
+ (*outbuf) += weird_table[i].len;
+ done = 1;
+ break;
+ }
+ }
+ }
+ if (done) continue;
+
+ (*outbuf)[0] = (*inbuf)[0];
+ if ((*inbuf)[1]) ir_count++;
+ (*inbytesleft) -= 2;
+ (*outbytesleft) -= 1;
+ (*inbuf) += 2;
+ (*outbuf) += 1;
+ }
+
+ if (*inbytesleft == 1) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (*inbytesleft > 1) {
+ errno = E2BIG;
+ return -1;
+ }
+
+ return ir_count;
+}
+
static size_t iconv_copy(void *cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)
{
diff --git a/source3/lib/system_smbd.c b/source3/lib/system_smbd.c
index 3ae0a6395e..0cd3086945 100644
--- a/source3/lib/system_smbd.c
+++ b/source3/lib/system_smbd.c
@@ -39,7 +39,7 @@
static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, int *grpcnt)
{
gid_t *gids_saved;
- int ret, ngrp_saved, num_gids;
+ int ret, ngrp_saved;
if (non_root_mode()) {
*grpcnt = 0;
@@ -78,16 +78,9 @@ static int getgrouplist_internals(const char *user, gid_t gid, gid_t *groups, in
set_effective_gid(gid);
setgid(gid);
- num_gids = getgroups(0, NULL);
- if (num_gids + 1 > *grpcnt) {
- *grpcnt = num_gids + 1;
- ret = -1;
- } else {
- ret = getgroups(*grpcnt - 1, &groups[1]);
- if (ret >= 0) {
- groups[0] = gid;
- *grpcnt = ret + 1;
- }
+ ret = getgroups(*grpcnt, groups);
+ if (ret >= 0) {
+ *grpcnt = ret;
}
restore_re_gid();
diff --git a/source3/lib/username.c b/source3/lib/username.c
index b8f33494ee..b1c9ca0f08 100644
--- a/source3/lib/username.c
+++ b/source3/lib/username.c
@@ -169,7 +169,7 @@ BOOL map_username(char *user)
return False;
}
- if (strchr_m(dosname,'*') || user_in_list(user, (const char **)dosuserlist, NULL, 0)) {
+ if (strchr_m(dosname,'*') || user_in_list(user, (const char **)dosuserlist)) {
DEBUG(3,("Mapped user %s to %s\n",user,unixname));
mapped_user = True;
fstrcpy(last_from,user);
@@ -328,27 +328,11 @@ static BOOL user_in_winbind_group_list(const char *user, const char *gname, BOOL
int num_groups;
int i;
gid_t *groups = NULL;
- gid_t gid, gid_low, gid_high;
+ gid_t gid;
BOOL ret = False;
*winbind_answered = False;
- if ((gid = nametogid(gname)) == (gid_t)-1) {
- DEBUG(0,("user_in_winbind_group_list: nametogid for group %s failed.\n",
- gname ));
- goto err;
- }
-
- if (!lp_winbind_gid(&gid_low, &gid_high)) {
- DEBUG(4, ("winbind gid range not configured, therefore %s cannot be a winbind group\n", gname));
- goto err;
- }
-
- if (gid < gid_low || gid > gid_high) {
- DEBUG(4, ("group %s is not a winbind group\n", gname));
- goto err;
- }
-
/*
* Get the gid's that this user belongs to.
*/
@@ -377,6 +361,12 @@ failed with error %s\n", strerror(errno) ));
* to a gid_t via either winbind or the local UNIX lookup and do the comparison.
*/
+ if ((gid = nametogid(gname)) == (gid_t)-1) {
+ DEBUG(0,("user_in_winbind_group_list: winbind_lookup_name for group %s failed.\n",
+ gname ));
+ goto err;
+ }
+
for (i = 0; i < num_groups; i++) {
if (gid == groups[i]) {
ret = True;
@@ -399,7 +389,7 @@ failed with error %s\n", strerror(errno) ));
Check if a user is in a UNIX group.
****************************************************************************/
-BOOL user_in_unix_group_list(const char *user,const char *gname)
+static BOOL user_in_unix_group_list(const char *user,const char *gname)
{
struct passwd *pass = Get_Pwnam(user);
struct sys_userlist *user_list;
@@ -442,27 +432,10 @@ BOOL user_in_unix_group_list(const char *user,const char *gname)
Check if a user is in a group list. Ask winbind first, then use UNIX.
****************************************************************************/
-BOOL user_in_group_list(const char *user, const char *gname, gid_t *groups, size_t n_groups)
+BOOL user_in_group_list(const char *user, const char *gname)
{
BOOL winbind_answered = False;
BOOL ret;
- gid_t gid;
- unsigned i;
-
- gid = nametogid(gname);
- if (gid == (gid_t)-1)
- return False;
-
- if (groups && n_groups > 0) {
- for (i=0; i < n_groups; i++) {
- if (groups[i] == gid) {
- return True;
- }
- }
- return False;
- }
-
- /* fallback if we don't yet have the group list */
ret = user_in_winbind_group_list(user, gname, &winbind_answered);
if (!winbind_answered)
@@ -478,7 +451,7 @@ BOOL user_in_group_list(const char *user, const char *gname, gid_t *groups, size
and netgroup lists.
****************************************************************************/
-BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_groups)
+BOOL user_in_list(const char *user,const char **list)
{
if (!list || !*list)
return False;
@@ -507,7 +480,7 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr
*/
if(user_in_netgroup_list(user, *list +1))
return True;
- if(user_in_group_list(user, *list +1, groups, n_groups))
+ if(user_in_group_list(user, *list +1))
return True;
} else if (**list == '+') {
@@ -515,7 +488,7 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr
/*
* Search UNIX list followed by netgroup.
*/
- if(user_in_group_list(user, *list +2, groups, n_groups))
+ if(user_in_group_list(user, *list +2))
return True;
if(user_in_netgroup_list(user, *list +2))
return True;
@@ -526,7 +499,7 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr
* Just search UNIX list.
*/
- if(user_in_group_list(user, *list +1, groups, n_groups))
+ if(user_in_group_list(user, *list +1))
return True;
}
@@ -538,7 +511,7 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr
*/
if(user_in_netgroup_list(user, *list +2))
return True;
- if(user_in_group_list(user, *list +2, groups, n_groups))
+ if(user_in_group_list(user, *list +2))
return True;
} else {
/*
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 13f5b17781..b4d9e9f16f 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -249,7 +249,13 @@ BOOL init_names(void)
int n;
if (global_myname() == NULL || *global_myname() == '\0') {
- if (!set_global_myname(myhostname())) {
+ fstring name;
+
+ fstrcpy( name, myhostname() );
+ p = strchr( name, '.' );
+ if (p)
+ *p = 0;
+ if (!set_global_myname(name)) {
DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
return False;
}
@@ -1008,7 +1014,7 @@ BOOL get_myfullname(char *my_name)
Get my own domain name.
****************************************************************************/
-BOOL get_mydomname(fstring my_domname)
+BOOL get_mydomname(char *my_domname)
{
pstring hostname;
char *p;
@@ -1724,23 +1730,6 @@ BOOL is_myname_or_ipaddr(const char *s)
}
/*******************************************************************
- Is the name specified our workgroup/domain.
- Returns true if it is equal, false otherwise.
-********************************************************************/
-
-BOOL is_myworkgroup(const char *s)
-{
- BOOL ret = False;
-
- if (strequal(s, lp_workgroup())) {
- ret=True;
- }
-
- DEBUG(8, ("is_myworkgroup(\"%s\") returns %d\n", s, ret));
- return(ret);
-}
-
-/*******************************************************************
Set the horrid remote_arch string based on an enum.
********************************************************************/
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 4babab8931..611e0e40be 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -362,7 +362,7 @@ char *file_pload(char *syscmd, size_t *size)
while ((n = read(fd, buf, sizeof(buf))) > 0) {
tp = Realloc(p, total + n + 1);
if (!tp) {
- DEBUG(0,("file_pload: failed to expand buffer!\n"));
+ DEBUG(0,("file_pload: failed to exand buffer!\n"));
close(fd);
SAFE_FREE(p);
return NULL;
@@ -372,9 +372,6 @@ char *file_pload(char *syscmd, size_t *size)
}
if (p) p[total] = 0;
- /* FIXME: Perhaps ought to check that the command completed
- * successfully (returned 0); if not the data may be
- * truncated. */
sys_pclose(fd);
if (size) *size = total;
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 8fe04f0f58..60e0e3837f 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -21,13 +21,13 @@
#include "includes.h"
-/**
- * Get the next token from a string, return False if none found.
- * Handles double-quotes.
- *
- * Based on a routine by GJC@VILLAGE.COM.
- * Extensively modified by Andrew.Tridgell@anu.edu.au
- **/
+/****************************************************************************
+ Get the next token from a string, return False if none found.
+ Handles double-quotes.
+ Based on a routine by GJC@VILLAGE.COM.
+ Extensively modified by Andrew.Tridgell@anu.edu.au
+****************************************************************************/
+
BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
{
const char *s;
@@ -67,11 +67,11 @@ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
return(True);
}
-/**
+/****************************************************************************
This is like next_token but is not re-entrant and "remembers" the first
parameter so you can pass NULL. This is useful for user interface code
but beware the fact that it is not re-entrant!
-**/
+****************************************************************************/
static char *last_ptr=NULL;
@@ -93,10 +93,10 @@ void set_first_token(char *ptr)
last_ptr = ptr;
}
-/**
+/****************************************************************************
Convert list of tokens to array; dependent on above routine.
Uses last_ptr from above - bit of a hack.
-**/
+****************************************************************************/
char **toktocliplist(int *ctok, const char *sep)
{
@@ -139,9 +139,9 @@ char **toktocliplist(int *ctok, const char *sep)
return ret;
}
-/**
+/*******************************************************************
Case insensitive string compararison.
-**/
+********************************************************************/
int StrCaseCmp(const char *s, const char *t)
{
@@ -151,9 +151,9 @@ int StrCaseCmp(const char *s, const char *t)
return strcmp(buf1,buf2);
}
-/**
+/*******************************************************************
Case insensitive string compararison, length limited.
-**/
+********************************************************************/
int StrnCaseCmp(const char *s, const char *t, size_t n)
{
@@ -163,9 +163,9 @@ int StrnCaseCmp(const char *s, const char *t, size_t n)
return strncmp(buf1,buf2,n);
}
-/**
+/*******************************************************************
Compare 2 strings.
-**/
+********************************************************************/
BOOL strequal(const char *s1, const char *s2)
{
@@ -177,9 +177,9 @@ BOOL strequal(const char *s1, const char *s2)
return(StrCaseCmp(s1,s2)==0);
}
-/**
+/*******************************************************************
Compare 2 strings up to and including the nth char.
-**/
+******************************************************************/
BOOL strnequal(const char *s1,const char *s2,size_t n)
{
@@ -191,9 +191,9 @@ BOOL strnequal(const char *s1,const char *s2,size_t n)
return(StrnCaseCmp(s1,s2,n)==0);
}
-/**
+/*******************************************************************
Compare 2 strings (case sensitive).
-**/
+********************************************************************/
BOOL strcsequal(const char *s1,const char *s2)
{
@@ -205,9 +205,9 @@ BOOL strcsequal(const char *s1,const char *s2)
return(strcmp(s1,s2)==0);
}
-/**
+/***************************************************************************
Do a case-insensitive, whitespace-ignoring string compare.
-**/
+***************************************************************************/
int strwicmp(const char *psz1, const char *psz2)
{
@@ -236,9 +236,9 @@ int strwicmp(const char *psz1, const char *psz2)
}
-/**
+/*******************************************************************
Convert a string to upper case, but don't modify it.
-**/
+********************************************************************/
char *strupper_static(const char *s)
{
@@ -250,9 +250,9 @@ char *strupper_static(const char *s)
return str;
}
-/**
+/*******************************************************************
Convert a string to "normal" form.
-**/
+********************************************************************/
void strnorm(char *s)
{
@@ -263,9 +263,9 @@ void strnorm(char *s)
strlower(s);
}
-/**
+/*******************************************************************
Check if a string is in "normal" case.
-**/
+********************************************************************/
BOOL strisnormal(const char *s)
{
@@ -277,10 +277,10 @@ BOOL strisnormal(const char *s)
}
-/**
+/****************************************************************************
String replace.
NOTE: oldc and newc must be 7 bit characters
-**/
+****************************************************************************/
void string_replace(char *s,char oldc,char newc)
{
@@ -289,9 +289,9 @@ void string_replace(char *s,char oldc,char newc)
pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
}
-/**
+/*******************************************************************
Skip past some strings in a buffer.
-**/
+********************************************************************/
char *skip_string(char *buf,size_t n)
{
@@ -300,11 +300,11 @@ char *skip_string(char *buf,size_t n)
return(buf);
}
-/**
+/*******************************************************************
Count the number of characters in a string. Normally this will
be the same as the number of bytes in a string for single byte strings,
but will be different for multibyte.
-**/
+********************************************************************/
size_t str_charnum(const char *s)
{
@@ -313,11 +313,11 @@ size_t str_charnum(const char *s)
return strlen_w(tmpbuf2);
}
-/**
+/*******************************************************************
Count the number of characters in a string. Normally this will
be the same as the number of bytes in a string for single byte strings,
but will be different for multibyte.
-**/
+********************************************************************/
size_t str_ascii_charnum(const char *s)
{
@@ -326,9 +326,9 @@ size_t str_ascii_charnum(const char *s)
return strlen(tmpbuf2);
}
-/**
+/*******************************************************************
Trim the specified elements off the front and back of a string.
-**/
+********************************************************************/
BOOL trim_string(char *s,const char *front,const char *back)
{
@@ -364,9 +364,9 @@ BOOL trim_string(char *s,const char *front,const char *back)
return ret;
}
-/**
+/****************************************************************************
Does a string have any uppercase chars in it?
-**/
+****************************************************************************/
BOOL strhasupper(const char *s)
{
@@ -378,9 +378,9 @@ BOOL strhasupper(const char *s)
return(False);
}
-/**
+/****************************************************************************
Does a string have any lowercase chars in it?
-**/
+****************************************************************************/
BOOL strhaslower(const char *s)
{
@@ -392,9 +392,9 @@ BOOL strhaslower(const char *s)
return(False);
}
-/**
+/****************************************************************************
Find the number of 'c' chars in a string
-**/
+****************************************************************************/
size_t count_chars(const char *s,char c)
{
@@ -407,9 +407,9 @@ size_t count_chars(const char *s,char c)
return(count);
}
-/**
+/*******************************************************************
Return True if a string consists only of one particular character.
-**/
+********************************************************************/
BOOL str_is_all(const char *s,char c)
{
@@ -428,10 +428,10 @@ BOOL str_is_all(const char *s,char c)
return True;
}
-/**
+/*******************************************************************
Safe string copy into a known length string. maxlength does not
include the terminating zero.
-**/
+********************************************************************/
char *safe_strcpy(char *dest,const char *src, size_t maxlength)
{
@@ -442,14 +442,6 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength)
return NULL;
}
-#ifdef DEVELOPER
- /* We intentionally write out at the extremity of the destination
- * string. If the destination is too short (e.g. pstrcpy into mallocd
- * or fstring) then this should cause an error under a memory
- * checker. */
- dest[maxlength] = '\0';
-#endif
-
if (!src) {
*dest = 0;
return dest;
@@ -458,8 +450,8 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength)
len = strlen(src);
if (len > maxlength) {
- DEBUG(0,("ERROR: string overflow by %u (%u - %u) in safe_strcpy [%.50s]\n",
- (unsigned int)(len-maxlength), len, maxlength, src));
+ DEBUG(0,("ERROR: string overflow by %d in safe_strcpy [%.50s]\n",
+ (int)(len-maxlength), src));
len = maxlength;
}
@@ -468,10 +460,10 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength)
return dest;
}
-/**
+/*******************************************************************
Safe string cat into a string. maxlength does not
include the terminating zero.
-**/
+********************************************************************/
char *safe_strcat(char *dest, const char *src, size_t maxlength)
{
@@ -503,12 +495,12 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength)
return dest;
}
-/**
+/*******************************************************************
Paranoid strcpy into a buffer of given length (includes terminating
zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
and replaces with '_'. Deliberately does *NOT* check for multibyte
characters. Don't change it !
-**/
+********************************************************************/
char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
{
@@ -544,10 +536,10 @@ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, si
return dest;
}
-/**
+/****************************************************************************
Like strncpy but always null terminates. Make sure there is room!
The variable n should always be one less than the available size.
-**/
+****************************************************************************/
char *StrnCpy(char *dest,const char *src,size_t n)
{
@@ -564,10 +556,10 @@ char *StrnCpy(char *dest,const char *src,size_t n)
return(dest);
}
-/**
+/****************************************************************************
Like strncpy but copies up to the character marker. always null terminates.
returns a pointer to the character marker in the source string (src).
-**/
+****************************************************************************/
char *strncpyn(char *dest, const char *src, size_t n, char c)
{
@@ -587,7 +579,7 @@ char *strncpyn(char *dest, const char *src, size_t n, char c)
return p;
}
-/**
+/*************************************************************
Routine to get hex characters and turn them into a 16 byte array.
the array can be variable length, and any non-hex-numeric
characters are skipped. "0xnn" or "0Xnn" is specially catered
@@ -595,7 +587,7 @@ char *strncpyn(char *dest, const char *src, size_t n, char c)
valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"
-**/
+**************************************************************/
size_t strhex_to_str(char *p, size_t len, const char *strhex)
{
@@ -632,9 +624,9 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex)
return num_chars;
}
-/**
+/****************************************************************************
Check if a string is part of a list.
-**/
+****************************************************************************/
BOOL in_list(char *s,char *list,BOOL casesensitive)
{
@@ -659,9 +651,9 @@ BOOL in_list(char *s,char *list,BOOL casesensitive)
/* this is used to prevent lots of mallocs of size 1 */
static char *null_string = NULL;
-/**
+/****************************************************************************
Set a string value, allocing the space for the string
-**/
+****************************************************************************/
static BOOL string_init(char **dest,const char *src)
{
@@ -690,9 +682,9 @@ static BOOL string_init(char **dest,const char *src)
return(True);
}
-/**
+/****************************************************************************
Free a string value.
-**/
+****************************************************************************/
void string_free(char **s)
{
@@ -703,10 +695,10 @@ void string_free(char **s)
SAFE_FREE(*s);
}
-/**
+/****************************************************************************
Set a string value, deallocating any existing space, and allocing the space
for the string
-**/
+****************************************************************************/
BOOL string_set(char **dest,const char *src)
{
@@ -714,7 +706,7 @@ BOOL string_set(char **dest,const char *src)
return(string_init(dest,src));
}
-/**
+/****************************************************************************
Substitute a string for a pattern in another string. Make sure there is
enough room!
@@ -724,7 +716,7 @@ BOOL string_set(char **dest,const char *src)
Any of " ; ' $ or ` in the insert string are replaced with _
if len==0 then the string cannot be extended. This is different from the old
use of len==0 which was for no length checks to be done.
-**/
+****************************************************************************/
void string_sub(char *s,const char *pattern, const char *insert, size_t len)
{
@@ -782,12 +774,12 @@ void pstring_sub(char *s,const char *pattern,const char *insert)
string_sub(s, pattern, insert, sizeof(pstring));
}
-/**
+/****************************************************************************
Similar to string_sub, but it will accept only allocated strings
and may realloc them so pay attention at what you pass on no
pointers inside strings, no pstrings or const may be passed
as string.
-**/
+****************************************************************************/
char *realloc_string_sub(char *string, const char *pattern, const char *insert)
{
@@ -848,12 +840,12 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert)
return string;
}
-/**
+/****************************************************************************
Similar to string_sub() but allows for any character to be substituted.
Use with caution!
if len==0 then the string cannot be extended. This is different from the old
use of len==0 which was for no length checks to be done.
-**/
+****************************************************************************/
void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
{
@@ -889,12 +881,12 @@ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
}
}
-/**
+/****************************************************************************
Similar to all_string_sub but for unicode strings.
Return a new allocated unicode string.
similar to string_sub() but allows for any character to be substituted.
Use with caution!
-**/
+****************************************************************************/
smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *pattern,
const smb_ucs2_t *insert)
@@ -954,9 +946,9 @@ smb_ucs2_t *all_string_sub_wa(smb_ucs2_t *s, const char *pattern,
return all_string_sub_w(s, p, i);
}
-/**
+/****************************************************************************
Splits out the front and back at a separator.
-**/
+****************************************************************************/
void split_at_last_component(char *path, char *front, char sep, char *back)
{
@@ -978,9 +970,9 @@ void split_at_last_component(char *path, char *front, char sep, char *back)
}
}
-/**
+/****************************************************************************
Write an octal as a string.
-**/
+****************************************************************************/
const char *octal_string(int i)
{
@@ -992,9 +984,9 @@ const char *octal_string(int i)
}
-/**
+/****************************************************************************
Truncate a string at a specified length.
-**/
+****************************************************************************/
char *string_truncate(char *s, int length)
{
@@ -1003,10 +995,10 @@ char *string_truncate(char *s, int length)
return s;
}
-/**
+/****************************************************************************
Strchr and strrchr_m are very hard to do on general multi-byte strings.
We convert via ucs2 for now.
-**/
+****************************************************************************/
char *strchr_m(const char *s, char c)
{
@@ -1038,9 +1030,9 @@ char *strrchr_m(const char *s, char c)
return (char *)(s+strlen(s2));
}
-/**
+/*******************************************************************
Convert a string to lower case.
-**/
+********************************************************************/
void strlower_m(char *s)
{
@@ -1062,9 +1054,9 @@ void strlower_m(char *s)
unix_strlower(s,strlen(s)+1,s,strlen(s)+1);
}
-/**
+/*******************************************************************
Duplicate convert a string to lower case.
-**/
+********************************************************************/
char *strdup_lower(const char *s)
{
@@ -1077,9 +1069,9 @@ char *strdup_lower(const char *s)
return t;
}
-/**
+/*******************************************************************
Convert a string to upper case.
-**/
+********************************************************************/
void strupper_m(char *s)
{
@@ -1101,9 +1093,9 @@ void strupper_m(char *s)
unix_strupper(s,strlen(s)+1,s,strlen(s)+1);
}
-/**
+/*******************************************************************
Convert a string to upper case.
-**/
+********************************************************************/
char *strdup_upper(const char *s)
{
@@ -1116,11 +1108,11 @@ char *strdup_upper(const char *s)
return t;
}
-/**
+/*******************************************************************
Return a RFC2254 binary string representation of a buffer.
Used in LDAP filters.
Caller must free.
-**/
+********************************************************************/
char *binary_string(char *buf, int len)
{
@@ -1140,9 +1132,9 @@ char *binary_string(char *buf, int len)
return s;
}
-/**
+/*******************************************************************
Just a typesafety wrapper for snprintf into a pstring.
-**/
+********************************************************************/
int pstr_sprintf(pstring s, const char *fmt, ...)
{
@@ -1155,9 +1147,9 @@ char *binary_string(char *buf, int len)
return ret;
}
-/**
+/*******************************************************************
Just a typesafety wrapper for snprintf into a fstring.
-**/
+********************************************************************/
int fstr_sprintf(fstring s, const char *fmt, ...)
{
@@ -1171,9 +1163,9 @@ char *binary_string(char *buf, int len)
}
#ifndef HAVE_STRNDUP
-/**
+/*******************************************************************
Some platforms don't have strndup.
-**/
+********************************************************************/
char *strndup(const char *s, size_t n)
{
@@ -1191,9 +1183,9 @@ char *binary_string(char *buf, int len)
#endif
#ifndef HAVE_STRNLEN
-/**
+/*******************************************************************
Some platforms don't have strnlen
-**/
+********************************************************************/
size_t strnlen(const char *s, size_t n)
{
@@ -1204,9 +1196,9 @@ char *binary_string(char *buf, int len)
}
#endif
-/**
+/***********************************************************
List of Strings manipulation functions
-**/
+***********************************************************/
#define S_LIST_ABS 16 /* List Allocation Block Size */
@@ -1299,9 +1291,10 @@ BOOL str_list_copy(char ***dest, const char **src)
return True;
}
-/**
- * Return true if all the elements of the list match exactly.
- **/
+/***********************************************************
+ Return true if all the elements of the list match exactly.
+***********************************************************/
+
BOOL str_list_compare(char **list1, char **list2)
{
int num;
@@ -1506,9 +1499,9 @@ void ipstr_list_free(char* ipstr_list)
}
-/**
+/***********************************************************
Unescape a URL encoded string, in place.
-**/
+***********************************************************/
void rfc1738_unescape(char *buf)
{
@@ -1548,9 +1541,9 @@ void rfc1738_unescape(char *buf)
static const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-/**
- * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
- **/
+/***************************************************************************
+decode a base64 string into a DATA_BLOB - simple and slow algorithm
+ ***************************************************************************/
DATA_BLOB base64_decode_data_blob(const char *s)
{
int bit_offset, byte_offset, idx, i, n;
@@ -1582,9 +1575,9 @@ DATA_BLOB base64_decode_data_blob(const char *s)
return decoded;
}
-/**
- * Decode a base64 string in-place - wrapper for the above
- **/
+/***************************************************************************
+decode a base64 string in-place - wrapper for the above
+***************************************************************************/
void base64_decode(char *s)
{
DATA_BLOB decoded = base64_decode_data_blob(s);
@@ -1595,11 +1588,11 @@ void base64_decode(char *s)
s[decoded.length] = '\0';
}
-/**
- * Encode a base64 string into a malloc()ed string caller to free.
- *
- *From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c with adjustments
- **/
+/***************************************************************************
+encode a base64 string into a malloc()ed string caller to free.
+
+From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c with adjustments
+***************************************************************************/
char * base64_encode_data_blob(DATA_BLOB data)
{
int bits = 0;