diff options
author | Jeremy Allison <jra@samba.org> | 2006-07-11 18:01:26 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:19:14 -0500 |
commit | fbdcf2663b56007a438ac4f0d8d82436b1bfe688 (patch) | |
tree | 4e42c1f061391cea3d640152fd240682cbf4fd9a /source3/lib | |
parent | 5bf62a0c3cc95abe918f3e772bb10e0a90fdce22 (diff) | |
download | samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.tar.gz samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.tar.bz2 samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.zip |
r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
to do the upper layer directories but this is what
everyone is waiting for....
Jeremy.
(This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/account_pol.c | 16 | ||||
-rw-r--r-- | source3/lib/afs.c | 7 | ||||
-rw-r--r-- | source3/lib/charcnv.c | 18 | ||||
-rw-r--r-- | source3/lib/data_blob.c | 2 | ||||
-rw-r--r-- | source3/lib/debug.c | 2 | ||||
-rw-r--r-- | source3/lib/popt_common.c | 10 | ||||
-rw-r--r-- | source3/lib/socket_wrapper.c | 17 | ||||
-rw-r--r-- | source3/lib/substitute.c | 182 | ||||
-rw-r--r-- | source3/lib/system.c | 78 | ||||
-rw-r--r-- | source3/lib/talloc.c | 7 | ||||
-rw-r--r-- | source3/lib/talloctort.c | 4 | ||||
-rw-r--r-- | source3/lib/time.c | 47 | ||||
-rw-r--r-- | source3/lib/util.c | 6 | ||||
-rw-r--r-- | source3/lib/util_reg.c | 110 | ||||
-rw-r--r-- | source3/lib/util_str.c | 122 |
15 files changed, 475 insertions, 153 deletions
diff --git a/source3/lib/account_pol.c b/source3/lib/account_pol.c index 6bf7346fe7..8d844741f5 100644 --- a/source3/lib/account_pol.c +++ b/source3/lib/account_pol.c @@ -262,10 +262,18 @@ BOOL init_account_policy(void) return True; } - tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); - if (!tdb) { - DEBUG(0,("Failed to open account policy database\n")); - return False; + tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); + if (!tdb) { /* the account policies files does not exist or open failed, try to create a new one */ + tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + if (!tdb) { + DEBUG(0,("Failed to open account policy database\n")); + return False; + } + /* creation was successful */ + /* add AP_MIGRATED_TO_PASSDB speacial key */ + /* so that you do not need to migrate policies */ + /* on brand new servers as it does not make sense */ + account_policy_migrated(True); } /* handle a Samba upgrade */ diff --git a/source3/lib/afs.c b/source3/lib/afs.c index 8a304adcf0..ea83fdebc2 100644 --- a/source3/lib/afs.c +++ b/source3/lib/afs.c @@ -211,6 +211,7 @@ char *afs_createtoken_str(const char *username, const char *cell) BOOL afs_login(connection_struct *conn) { + extern userdom_struct current_user_info; extern struct current_user current_user; DATA_BLOB ticket; pstring afs_username; @@ -222,7 +223,11 @@ BOOL afs_login(connection_struct *conn) struct ClearToken ct; pstrcpy(afs_username, lp_afs_username_map()); - standard_sub_conn(conn, afs_username, sizeof(afs_username)); + standard_sub_advanced(SNUM(conn), conn->user, + conn->connectpath, conn->gid, + get_current_username(), + current_user_info.domain, + afs_username, sizeof(afs_username)); user_sid = ¤t_user.nt_user_token->user_sids[0]; pstring_sub(afs_username, "%s", sid_string_static(user_sid)); diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 097d746a63..fffdf010a0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -516,13 +516,14 @@ size_t convert_string(charset_t from, charset_t to, **/ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest, BOOL allow_bad_conv) + void const *src, size_t srclen, void *dst, BOOL allow_bad_conv) { size_t i_len, o_len, destlen = MAX(srclen, 512); size_t retval; const char *inbuf = (const char *)src; char *outbuf = NULL, *ob = NULL; smb_iconv_t descriptor; + void **dest = (void **)dst; *dest = NULL; @@ -702,9 +703,11 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, * * @returns Size in bytes of the converted string; or -1 in case of error. **/ -static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest, BOOL allow_bad_conv) +size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, + void const *src, size_t srclen, void *dst, + BOOL allow_bad_conv) { + void **dest = (void **)dst; size_t dest_len; *dest = NULL; @@ -944,9 +947,9 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, if (flags & STR_TERMINATE) { if (src_len == (size_t)-1) { - src_len = strlen(src) + 1; + src_len = strlen((const char *)src) + 1; } else { - size_t len = strnlen(src, src_len); + size_t len = strnlen((const char *)src, src_len); if (len < src_len) len++; src_len = len; @@ -1034,7 +1037,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_ len += ret; if (flags & STR_UPPER) { - smb_ucs2_t *dest_ucs2 = dest; + smb_ucs2_t *dest_ucs2 = (smb_ucs2_t *)dest; size_t i; for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) { smb_ucs2_t v = toupper_w(dest_ucs2[i]); @@ -1178,7 +1181,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_ if (flags & STR_TERMINATE) { /* src_len -1 is the default for null terminated strings. */ if (src_len != (size_t)-1) { - size_t len = strnlen_w(src, src_len/2); + size_t len = strnlen_w((const smb_ucs2_t *)src, + src_len/2); if (len < src_len/2) len++; src_len = len*2; diff --git a/source3/lib/data_blob.c b/source3/lib/data_blob.c index ccd0d27f47..860ef5ad10 100644 --- a/source3/lib/data_blob.c +++ b/source3/lib/data_blob.c @@ -102,7 +102,7 @@ void data_blob_free(DATA_BLOB *d) Clear a DATA_BLOB's contents *******************************************************************/ -static void data_blob_clear(DATA_BLOB *d) +void data_blob_clear(DATA_BLOB *d) { if (d->data) { memset(d->data, 0, d->length); diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 2b6c42b8eb..bf75bdf3d3 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -981,7 +981,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line ) /* Print it all out at once to prevent split syslog output. */ (void)Debug1( "[%s, %d%s] %s:%s(%d)\n", - timestring(lp_debug_hires_timestamp()), level, + current_timestring(lp_debug_hires_timestamp()), level, header_str, file, func, line ); } diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index d29e171be0..0c0ed86dd1 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -123,7 +123,7 @@ static void popt_common_callback(poptContext con, } struct poptOption popt_common_connection[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, { "socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use", "SOCKETOPTIONS" }, { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" }, @@ -134,7 +134,7 @@ struct poptOption popt_common_connection[] = { }; struct poptOption popt_common_samba[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_callback }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternate configuration file", "CONFIGFILE" }, { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" }, @@ -143,7 +143,7 @@ struct poptOption popt_common_samba[] = { }; struct poptOption popt_common_version[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, POPT_TABLEEND }; @@ -248,7 +248,7 @@ static void popt_dynconfig_callback(poptContext con, const struct poptOption popt_common_dynconfig[] = { - { NULL, '\0', POPT_ARG_CALLBACK, popt_dynconfig_callback }, + { NULL, '\0', POPT_ARG_CALLBACK, (void *)popt_dynconfig_callback }, { "sbindir", '\0' , POPT_ARG_STRING, NULL, DYN_SBINDIR, "Path to sbin directory", "SBINDIR" }, @@ -515,7 +515,7 @@ static void popt_common_credentials_callback(poptContext con, struct poptOption popt_common_credentials[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_credentials_callback }, + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" }, { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, diff --git a/source3/lib/socket_wrapper.c b/source3/lib/socket_wrapper.c index e9c1404d11..04c337267f 100644 --- a/source3/lib/socket_wrapper.c +++ b/source3/lib/socket_wrapper.c @@ -411,12 +411,16 @@ _PUBLIC_ int swrap_socket(int domain, int type, int protocol) return real_socket(domain, type, protocol); } + si = (struct socket_info *)calloc(1, sizeof(struct socket_info)); + if (si == NULL) { + errno = ENOMEM; + return -1; + } + fd = real_socket(AF_UNIX, type, 0); if (fd == -1) return -1; - si = calloc(1, sizeof(struct socket_info)); - si->domain = domain; si->type = type; si->protocol = protocol; @@ -457,7 +461,12 @@ _PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) parent_si->domain, addr, addrlen); if (ret == -1) return ret; - child_si = malloc(sizeof(struct socket_info)); + child_si = (struct socket_info *)malloc(sizeof(struct socket_info)); + if (child_si == NULL) { + close(fd); + errno = ENOMEM; + return -1; + } memset(child_si, 0, sizeof(*child_si)); child_si->fd = fd; @@ -466,7 +475,7 @@ _PUBLIC_ int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) child_si->protocol = parent_si->protocol; child_si->bound = 1; - ret = real_getsockname(fd, &un_my_addr, &un_my_addrlen); + ret = real_getsockname(fd, (struct sockaddr *)&un_my_addr, &un_my_addrlen); if (ret == -1) return ret; ret = sockaddr_convert_from_un(child_si, &un_my_addr, un_my_addrlen, diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index ff9deb8a5f..430c8029b8 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -415,11 +415,12 @@ static const char *automount_server(const char *user_name) don't allow expansions. ****************************************************************************/ -void standard_sub_basic(const char *smb_name, char *str, size_t len) +void standard_sub_basic(const char *smb_name, const char *domain_name, + char *str, size_t len) { char *s; - if ( (s = alloc_sub_basic( smb_name, str )) != NULL ) { + if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) { strncpy( str, s, len ); } @@ -432,11 +433,12 @@ void standard_sub_basic(const char *smb_name, char *str, size_t len) This function will return an allocated string that have to be freed. ****************************************************************************/ -char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) +char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, + const char *domain_name, const char *str) { char *a, *t; - if ( (a = alloc_sub_basic(smb_name, str)) == NULL ) { + if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) { return NULL; } t = talloc_strdup(mem_ctx, a); @@ -447,7 +449,8 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *st /**************************************************************************** ****************************************************************************/ -char *alloc_sub_basic(const char *smb_name, const char *str) +char *alloc_sub_basic(const char *smb_name, const char *domain_name, + const char *str) { char *b, *p, *s, *r, *a_string; fstring pidstr; @@ -463,7 +466,7 @@ char *alloc_sub_basic(const char *smb_name, const char *str) a_string = SMB_STRDUP(str); if (a_string == NULL) { - DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); + DEBUG(0, ("alloc_sub_basic: Out of memory!\n")); return NULL; } @@ -490,7 +493,7 @@ char *alloc_sub_basic(const char *smb_name, const char *str) } break; case 'D' : - r = strdup_upper(current_user_info.domain); + r = strdup_upper(domain_name); if (r == NULL) { goto error; } @@ -522,7 +525,7 @@ char *alloc_sub_basic(const char *smb_name, const char *str) a_string = realloc_string_sub(a_string, "%R", remote_proto); break; case 'T' : - a_string = realloc_string_sub(a_string, "%T", timestring(False)); + a_string = realloc_string_sub(a_string, "%T", current_timestring(False)); break; case 'a' : a_string = realloc_string_sub(a_string, "%a", remote_arch); @@ -580,32 +583,20 @@ char *talloc_sub_specified(TALLOC_CTX *mem_ctx, uid_t uid, gid_t gid) { - char *a, *t; - a = alloc_sub_specified(input_string, username, domain, uid, gid); - if (!a) { + char *a_string; + char *ret_string = NULL; + char *b, *p, *s; + TALLOC_CTX *tmp_ctx; + + if (!(tmp_ctx = talloc_new(mem_ctx))) { + DEBUG(0, ("talloc_new failed\n")); return NULL; } - t = talloc_strdup(mem_ctx, a); - SAFE_FREE(a); - return t; -} -/**************************************************************************** -****************************************************************************/ - -char *alloc_sub_specified(const char *input_string, - const char *username, - const char *domain, - uid_t uid, - gid_t gid) -{ - char *a_string, *ret_string; - char *b, *p, *s; - - a_string = SMB_STRDUP(input_string); + a_string = talloc_strdup(tmp_ctx, input_string); if (a_string == NULL) { - DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); - return NULL; + DEBUG(0, ("talloc_sub_specified: Out of memory!\n")); + goto done; } for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { @@ -614,30 +605,42 @@ char *alloc_sub_specified(const char *input_string, switch (*(p+1)) { case 'U' : - a_string = realloc_string_sub(a_string, "%U", username); + a_string = talloc_string_sub( + tmp_ctx, a_string, "%U", username); break; case 'u' : - a_string = realloc_string_sub(a_string, "%u", username); + a_string = talloc_string_sub( + tmp_ctx, a_string, "%u", username); break; case 'G' : if (gid != -1) { - a_string = realloc_string_sub(a_string, "%G", gidtoname(gid)); + a_string = talloc_string_sub( + tmp_ctx, a_string, "%G", + gidtoname(gid)); } else { - a_string = realloc_string_sub(a_string, "%G", "NO_GROUP"); + a_string = talloc_string_sub( + tmp_ctx, a_string, + "%G", "NO_GROUP"); } break; case 'g' : if (gid != -1) { - a_string = realloc_string_sub(a_string, "%g", gidtoname(gid)); + a_string = talloc_string_sub( + tmp_ctx, a_string, "%g", + gidtoname(gid)); } else { - a_string = realloc_string_sub(a_string, "%g", "NO_GROUP"); + a_string = talloc_string_sub( + tmp_ctx, a_string, "%g", "NO_GROUP"); } break; case 'D' : - a_string = realloc_string_sub(a_string, "%D", domain); + a_string = talloc_string_sub(tmp_ctx, a_string, + "%D", domain); break; case 'N' : - a_string = realloc_string_sub(a_string, "%N", automount_server(username)); + a_string = talloc_string_sub( + tmp_ctx, a_string, "%N", + automount_server(username)); break; default: break; @@ -645,42 +648,27 @@ char *alloc_sub_specified(const char *input_string, p++; if (a_string == NULL) { - return NULL; + goto done; } } - ret_string = alloc_sub_basic(username, a_string); - SAFE_FREE(a_string); - return ret_string; -} + /* Watch out, using "mem_ctx" here, so all intermediate stuff goes + * away with the TALLOC_FREE(tmp_ctx) further down. */ -/**************************************************************************** -****************************************************************************/ + ret_string = talloc_sub_basic(mem_ctx, username, domain, a_string); -char *talloc_sub_advanced(TALLOC_CTX *mem_ctx, - int snum, - const char *user, - const char *connectpath, - gid_t gid, - const char *smb_name, - const char *str) -{ - char *a, *t; - a = alloc_sub_advanced(snum, user, connectpath, gid, smb_name, str); - if (!a) { - return NULL; - } - t = talloc_strdup(mem_ctx, a); - SAFE_FREE(a); - return t; + done: + TALLOC_FREE(tmp_ctx); + return ret_string; } /**************************************************************************** ****************************************************************************/ -char *alloc_sub_advanced(int snum, const char *user, - const char *connectpath, gid_t gid, - const char *smb_name, const char *str) +char *alloc_sub_advanced(const char *servicename, const char *user, + const char *connectpath, gid_t gid, + const char *smb_name, const char *domain_name, + const char *str) { char *a_string, *ret_string; char *b, *p, *s, *h; @@ -707,7 +695,7 @@ char *alloc_sub_advanced(int snum, const char *user, a_string = realloc_string_sub(a_string, "%P", connectpath); break; case 'S': - a_string = realloc_string_sub(a_string, "%S", lp_servicename(snum)); + a_string = realloc_string_sub(a_string, "%S", servicename); break; case 'g': a_string = realloc_string_sub(a_string, "%g", gidtoname(gid)); @@ -724,7 +712,8 @@ char *alloc_sub_advanced(int snum, const char *user, * "path =" string in [homes] and so needs the * service name, not the username. */ case 'p': - a_string = realloc_string_sub(a_string, "%p", automount_path(lp_servicename(snum))); + a_string = realloc_string_sub(a_string, "%p", + automount_path(servicename)); break; default: @@ -737,67 +726,20 @@ char *alloc_sub_advanced(int snum, const char *user, } } - ret_string = alloc_sub_basic(smb_name, a_string); + ret_string = alloc_sub_basic(smb_name, domain_name, a_string); SAFE_FREE(a_string); return ret_string; } -/**************************************************************************** - Do some standard substitutions in a string. -****************************************************************************/ - -void standard_sub_conn(connection_struct *conn, char *str, size_t len) -{ - char *s; - - s = alloc_sub_advanced(SNUM(conn), conn->user, conn->connectpath, - conn->gid, smb_user_name, str); - - if ( s ) { - strncpy( str, s, len ); - SAFE_FREE( s ); - } -} - -/**************************************************************************** -****************************************************************************/ - -char *talloc_sub_conn(TALLOC_CTX *mem_ctx, connection_struct *conn, const char *str) -{ - return talloc_sub_advanced(mem_ctx, SNUM(conn), conn->user, - conn->connectpath, conn->gid, - smb_user_name, str); -} - -/**************************************************************************** -****************************************************************************/ - -char *alloc_sub_conn(connection_struct *conn, const char *str) -{ - return alloc_sub_advanced(SNUM(conn), conn->user, conn->connectpath, - conn->gid, smb_user_name, str); -} - -/**************************************************************************** - Like standard_sub but by snum. -****************************************************************************/ - -void standard_sub_snum(int snum, char *str, size_t len) +void standard_sub_advanced(const char *servicename, const char *user, + const char *connectpath, gid_t gid, + const char *smb_name, const char *domain_name, + char *str, size_t len) { - static uid_t cached_uid = -1; - static fstring cached_user; char *s; - /* calling uidtoname() on every substitute would be too expensive, so - we cache the result here as nearly every call is for the same uid */ - - if (cached_uid != current_user.ut.uid) { - fstrcpy(cached_user, uidtoname(current_user.ut.uid)); - cached_uid = current_user.ut.uid; - } - - s = alloc_sub_advanced(snum, cached_user, "", current_user.ut.gid, - smb_user_name, str); + s = alloc_sub_advanced(servicename, user, connectpath, + gid, smb_name, domain_name, str); if ( s ) { strncpy( str, s, len ); diff --git a/source3/lib/system.c b/source3/lib/system.c index 2e5f42307b..24c726b8f7 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -922,16 +922,94 @@ void sys_endpwent(void) Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid() ****************************************************************************/ +#ifdef ENABLE_BUILD_FARM_HACKS + +/* + * In the build farm we want to be able to join machines to the domain. As we + * don't have root access, we need to bypass direct access to /etc/passwd + * after a user has been created via samr. Fake those users. + */ + +static struct passwd *fake_pwd; +static int num_fake_pwd; + struct passwd *sys_getpwnam(const char *name) { + int i; + + for (i=0; i<num_fake_pwd; i++) { + if (strcmp(fake_pwd[i].pw_name, name) == 0) { + DEBUG(10, ("Returning fake user %s\n", name)); + return &fake_pwd[i]; + } + } + return getpwnam(name); } struct passwd *sys_getpwuid(uid_t uid) { + int i; + + for (i=0; i<num_fake_pwd; i++) { + if (fake_pwd[i].pw_uid == uid) { + DEBUG(10, ("Returning fake user %s\n", + fake_pwd[i].pw_name)); + return &fake_pwd[i]; + } + } + return getpwuid(uid); } +void faked_create_user(const char *name) +{ + int i; + uid_t uid; + struct passwd new_pwd; + + for (i=0; i<10; i++) { + generate_random_buffer((unsigned char *)&uid, + sizeof(uid)); + if (getpwuid(uid) == NULL) { + break; + } + } + + if (i==10) { + /* Weird. No free uid found... */ + return; + } + + new_pwd.pw_name = SMB_STRDUP(name); + new_pwd.pw_passwd = SMB_STRDUP("x"); + new_pwd.pw_uid = uid; + new_pwd.pw_gid = 100; + new_pwd.pw_gecos = SMB_STRDUP("faked user"); + new_pwd.pw_dir = SMB_STRDUP("/nodir"); + new_pwd.pw_shell = SMB_STRDUP("/bin/false"); + + ADD_TO_ARRAY(NULL, struct passwd, new_pwd, &fake_pwd, + &num_fake_pwd); + + DEBUG(10, ("Added fake user %s, have %d fake users\n", + name, num_fake_pwd)); +} + +#else + +struct passwd *sys_getpwnam(const char *name) +{ + return getpwnam(name); +} + +struct passwd *sys_getpwuid(uid_t uid) +{ + return getpwuid(uid); +} + +#endif + struct group *sys_getgrnam(const char *name) { return getgrnam(name); diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index 51087ef979..9d82441137 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -85,6 +85,7 @@ static const void *null_context; static void *cleanup_context; +static void *talloc_steal(const void *new_ctx, const void *ptr); struct talloc_reference_handle { struct talloc_reference_handle *next, *prev; @@ -665,7 +666,7 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n ptr on success, or NULL if it could not be transferred. passing NULL as ptr will always return NULL with no side effects. */ -void *talloc_steal(const void *new_ctx, const void *ptr) +static void *talloc_steal(const void *new_ctx, const void *ptr) { struct talloc_chunk *tc, *new_tc; @@ -1138,9 +1139,7 @@ char *talloc_asprintf(const void *t, const char *fmt, ...) * accumulating output into a string buffer. **/ -static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0); - -static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) +char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) { struct talloc_chunk *tc; int len, s_len; diff --git a/source3/lib/talloctort.c b/source3/lib/talloctort.c index 6504203a7a..3ce45e2071 100644 --- a/source3/lib/talloctort.c +++ b/source3/lib/talloctort.c @@ -656,6 +656,7 @@ static BOOL test_type(void) return True; } +#if 0 /* test steal */ @@ -709,6 +710,7 @@ static BOOL test_steal(void) return True; } +#endif /* test talloc_realloc_fn @@ -819,7 +821,7 @@ BOOL torture_local_talloc(void) ret &= test_misc(); ret &= test_realloc(); ret &= test_realloc_child(); - ret &= test_steal(); +/* ret &= test_steal(); */ ret &= test_unref_reparent(); ret &= test_realloc_fn(); ret &= test_type(); diff --git a/source3/lib/time.c b/source3/lib/time.c index 9a539d415e..0bfdfac856 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -635,7 +635,7 @@ char *http_timestring(time_t t) Return the date and time as a string ****************************************************************************/ -char *timestring(BOOL hires) +char *current_timestring(BOOL hires) { static fstring TimeBuf; struct timeval tp; @@ -1056,6 +1056,51 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) } #endif + +/** + Return the date and time as a string +**/ +char *timestring(TALLOC_CTX *mem_ctx, time_t t) +{ + char *TimeBuf; + char tempTime[80]; + struct tm *tm; + + tm = localtime(&t); + if (!tm) { + return talloc_asprintf(mem_ctx, + "%ld seconds since the Epoch", + (long)t); + } + +#ifdef HAVE_STRFTIME + /* some versions of gcc complain about using %c. This is a bug + in the gcc warning, not a bug in this code. See a recent + strftime() manual page for details. + */ + strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); + TimeBuf = talloc_strdup(mem_ctx, tempTime); +#else + TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); +#endif + + return TimeBuf; +} + + +/** + return a talloced string representing a NTTIME for human consumption +*/ +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) +{ + time_t t; + if (nt.low == 0 && nt.high == 0) { + return "NTTIME(0)"; + } + t = nt_time_to_unix(&nt); + return timestring(mem_ctx, t); +} + /**************************************************************************** Utility function that always returns a const string even if localtime and asctime fail. diff --git a/source3/lib/util.c b/source3/lib/util.c index a1efecfbbb..96263bf394 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -753,7 +753,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn) size_t num_to_read_thistime; size_t num_written = 0; - if ((buf = SMB_MALLOC(TRANSFER_BUF_SIZE)) == NULL) + if ((buf = SMB_MALLOC_ARRAY(char, TRANSFER_BUF_SIZE)) == NULL) return -1; while (total < n) { @@ -1052,9 +1052,11 @@ void *realloc_array(void *p, size_t el_size, unsigned int count, BOOL free_old_o ****************************************************************************/ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size, - void *element, void **array, uint32 *num_elements, + void *element, void *_array, uint32 *num_elements, ssize_t *array_size) { + void **array = (void **)_array; + if (*array_size < 0) { return; } diff --git a/source3/lib/util_reg.c b/source3/lib/util_reg.c new file mode 100644 index 0000000000..3f0b2d6a42 --- /dev/null +++ b/source3/lib/util_reg.c @@ -0,0 +1,110 @@ +/* + * Unix SMB/CIFS implementation. + * Registry helper routines + * Copyright (C) Volker Lendecke 2006 + * + * 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" + +const char *reg_type_lookup(uint32 type) +{ + const char *result; + + switch(type) { + case REG_NONE: + result = "REG_NONE"; + break; + case REG_SZ: + result = "REG_SZ"; + break; + case REG_EXPAND_SZ: + result = "REG_EXPAND_SZ"; + break; + case REG_BINARY: + result = "REG_BINARY"; + break; + case REG_DWORD: + result = "REG_DWORD"; + break; + case REG_DWORD_BE: + result = "REG_DWORD_BE"; + break; + case REG_LINK: + result = "REG_LINK"; + break; + case REG_MULTI_SZ: + result = "REG_MULTI_SZ"; + break; + case REG_RESOURCE_LIST: + result = "REG_RESOURCE_LIST"; + break; + case REG_FULL_RESOURCE_DESCRIPTOR: + result = "REG_FULL_RESOURCE_DESCRIPTOR"; + break; + case REG_RESOURCE_REQUIREMENTS_LIST: + result = "REG_RESOURCE_REQUIREMENTS_LIST"; + break; + case REG_QWORD: + result = "REG_QWORD"; + break; + default: + result = "REG TYPE IS UNKNOWN"; + break; + } + return result; +} + +NTSTATUS reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len, + int *num_values, char ***values) +{ + const smb_ucs2_t *p = (const smb_ucs2_t *)buf; + *num_values = 0; + + /* + * Make sure that a talloc context for the strings retrieved exists + */ + + if (!(*values = TALLOC_ARRAY(mem_ctx, char *, 1))) { + return NT_STATUS_NO_MEMORY; + } + + len /= 2; /* buf is a set of UCS2 strings */ + + while (len > 0) { + char *val; + size_t dstlen, thislen; + + thislen = strnlen_w(p, len) + 1; + dstlen = convert_string_allocate(*values, CH_UCS2, CH_UNIX, + p, thislen*2, (void *)&val, + True); + if (dstlen == (size_t)-1) { + TALLOC_FREE(*values); + return NT_STATUS_NO_MEMORY; + } + + ADD_TO_ARRAY(*values, char *, val, values, num_values); + if (*values == NULL) { + return NT_STATUS_NO_MEMORY; + } + + p += thislen; + len -= thislen; + } + + return NT_STATUS_OK; +} diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 938fb0f47b..2580521c3b 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -5,6 +5,7 @@ Copyright (C) Andrew Tridgell 1992-2001 Copyright (C) Simo Sorce 2001-2002 Copyright (C) Martin Pool 2003 + Copyright (C) James Peach 2006 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 @@ -1914,13 +1915,14 @@ int str_list_count( const char **list ) for the work *****************************************************************************/ -BOOL str_list_sub_basic( char **list, const char *smb_name ) +BOOL str_list_sub_basic( char **list, const char *smb_name, + const char *domain_name ) { char *s, *tmpstr; while ( *list ) { s = *list; - tmpstr = alloc_sub_basic(smb_name, s); + tmpstr = alloc_sub_basic(smb_name, domain_name, s); if ( !tmpstr ) { DEBUG(0,("str_list_sub_basic: alloc_sub_basic() return NULL!\n")); return False; @@ -2302,6 +2304,73 @@ SMB_BIG_UINT STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr) return val; } +/* Convert a size specification to a count of bytes. We accept the following + * suffixes: + * bytes if there is no suffix + * kK kibibytes + * mM mebibytes + * gG gibibytes + * tT tibibytes + * pP whatever the ISO name for petabytes is + * + * Returns 0 if the string can't be converted. + */ +SMB_OFF_T conv_str_size(const char * str) +{ + SMB_OFF_T lval; + char * end; + + if (str == NULL || *str == '\0') { + return 0; + } + +#ifdef HAVE_STRTOULL + if (sizeof(SMB_OFF_T) == 8) { + lval = strtoull(str, &end, 10 /* base */); + } else { + lval = strtoul(str, &end, 10 /* base */); + } +#else + lval = strtoul(str, &end, 10 /* base */); +#endif + + if (end == NULL || end == str) { + return 0; + } + + if (*end) { + SMB_OFF_T lval_orig = lval; + + if (strwicmp(end, "K") == 0) { + lval *= (SMB_OFF_T)1024; + } else if (strwicmp(end, "M") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024); + } else if (strwicmp(end, "G") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024); + } else if (strwicmp(end, "T") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024 * (SMB_OFF_T)1024); + } else if (strwicmp(end, "P") == 0) { + lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024 * (SMB_OFF_T)1024 * + (SMB_OFF_T)1024); + } else { + return 0; + } + + /* Primitive attempt to detect wrapping on platforms with + * 4-byte SMB_OFF_T. It's better to let the caller handle + * a failure than some random number. + */ + if (lval_orig <= lval) { + return 0; + } + } + + return lval; +} + void string_append(char **left, const char *right) { int new_len = strlen(right) + 1; @@ -2454,3 +2523,52 @@ BOOL validate_net_name( const char *name, const char *invalid_chars, int max_len return True; } + +/** +return the number of bytes occupied by a buffer in ASCII format +the result includes the null termination +limited by 'n' bytes +**/ +size_t ascii_len_n(const char *src, size_t n) +{ + size_t len; + + len = strnlen(src, n); + if (len+1 <= n) { + len += 1; + } + + return len; +} + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +**/ +size_t utf16_len(const void *buf) +{ + size_t len; + + for (len = 0; SVAL(buf,len); len += 2) ; + + return len + 2; +} + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +limited by 'n' bytes +**/ +size_t utf16_len_n(const void *src, size_t n) +{ + size_t len; + + for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ; + + if (len+2 <= n) { + len += 2; + } + + return len; +} + |