lib/util/util_pw: share more code between lib/util/util_pw.c and source3/lib/username.c
authorGünther Deschner <gd@samba.org>
Wed, 2 Mar 2011 15:11:00 +0000 (16:11 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 29 Mar 2011 23:13:06 +0000 (01:13 +0200)
Guenther

lib/util/util_pw.c
lib/util/util_pw.h
source3/auth/auth_util.c
source3/include/proto.h
source3/lib/username.c
source3/lib/winbind_util.c
source3/passdb/passdb.c
source3/passdb/pdb_ldap.c
source3/utils/smbpasswd.c

index cb7b45c13567ebf7ef7f8dc0563619a490219e45..c6e4680ec3faa44f3db9f6c37f0196e7659a8d4b 100644 (file)
@@ -71,8 +71,8 @@ struct group *sys_getgrgid(gid_t gid)
        return getgrgid(gid);
 }
 
-static struct passwd *alloc_copy_passwd(TALLOC_CTX *mem_ctx, 
-                                       const struct passwd *from) 
+struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
+                           const struct passwd *from)
 {
        struct passwd *ret = talloc_zero(mem_ctx, struct passwd);
 
@@ -90,7 +90,7 @@ static struct passwd *alloc_copy_passwd(TALLOC_CTX *mem_ctx,
        return ret;
 }
 
-struct passwd *_getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
+struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
 {
        struct passwd *temp;
 
@@ -105,10 +105,14 @@ struct passwd *_getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
                return NULL;
        }
 
-       return alloc_copy_passwd(mem_ctx, temp);
+       return tcopy_passwd(mem_ctx, temp);
 }
 
-struct passwd *_getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
+/****************************************************************************
+ talloc'ed version of getpwuid.
+****************************************************************************/
+
+struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
 {
        struct passwd *temp;
 
@@ -123,5 +127,5 @@ struct passwd *_getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
                return NULL;
        }
 
-       return alloc_copy_passwd(mem_ctx, temp);
+       return tcopy_passwd(mem_ctx, temp);
 }
index fa212b9c6118adde9cd187ad9a3ab6296955399b..2967963459085aabb8e1a709cc02e9c4b4a0ac0d 100644 (file)
@@ -33,7 +33,7 @@ struct group *sys_getgrnam(const char *name);
 struct group *sys_getgrgid(gid_t gid);
 struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
                            const struct passwd *from);
-struct passwd *_getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name);
-struct passwd *_getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid);
+struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name);
+struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid);
 
 #endif /* __LIB_UTIL_UTIL_PW_H__ */
index c75b12e0b9a91c524f9e39eacf4cc98a49577d78..688aac487bbc14084cdd77d324b0c3a72c871bb8 100644 (file)
@@ -27,6 +27,7 @@
 #include "../lib/crypto/arcfour.h"
 #include "rpc_client/init_lsa.h"
 #include "../libcli/security/security.h"
+#include "../lib/util/util_pw.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_AUTH
index 94cc9f9baa4c980a29c4c19549a33a02bfdf3311..600ed7aa8f7934a6fd3857e8990a455fab5630b6 100644 (file)
@@ -967,9 +967,7 @@ bool nt_time_is_set(const NTTIME *nt);
 
 /* The following definitions come from lib/username.c  */
 
-struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from) ;
 void flush_pwnam_cache(void);
-struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) ;
 char *get_user_home_dir(TALLOC_CTX *mem_ctx, const char *user);
 struct passwd *Get_Pwnam_alloc(TALLOC_CTX *mem_ctx, const char *user);
 
index eea906128e1631bfd260e55a3e1be49ce19d7100..40e284a01a7a150878d7226ad3e98855c7f99148 100644 (file)
@@ -57,26 +57,6 @@ static struct passwd *getpwnam_alloc_cached(TALLOC_CTX *mem_ctx, const char *nam
        return tcopy_passwd(mem_ctx, pw);
 }
 
-/****************************************************************************
- talloc copy a struct passwd.
-****************************************************************************/
-
-struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from)
-{
-       struct passwd *ret = TALLOC_P(mem_ctx, struct passwd);
-       if (!ret) {
-               return NULL;
-       }
-       ret->pw_name = talloc_strdup(ret, from->pw_name);
-       ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
-       ret->pw_uid = from->pw_uid;
-       ret->pw_gid = from->pw_gid;
-       ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
-       ret->pw_dir = talloc_strdup(ret, from->pw_dir);
-       ret->pw_shell = talloc_strdup(ret, from->pw_shell);
-       return ret;
-}
-
 /****************************************************************************
  Flush all cached passwd structs.
 ****************************************************************************/
@@ -86,21 +66,6 @@ void flush_pwnam_cache(void)
         memcache_flush(NULL, GETPWNAM_CACHE);
 }
 
-/****************************************************************************
- talloc'ed version of getpwuid.
-****************************************************************************/
-
-struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
-{
-       struct passwd *temp = sys_getpwuid(uid);
-
-       if (!temp) {
-               return NULL;
-       }
-
-       return tcopy_passwd(mem_ctx, temp);
-}
-
 /****************************************************************************
  Get a users home directory.
 ****************************************************************************/
index 57cb3a9f6a547463545abd577b658312bba1fa2a..ad1ccf553848d195363578629fd0027da2b3c361 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "../libcli/security/security.h"
+#include "../lib/util/util_pw.h"
 
 #if defined(WITH_WINBIND)
 
index fdc4bdc48639c72652f489bf152f17cb60737014..ecf72786f0abfa94bbef3638e4f867529cb4b980 100644 (file)
@@ -26,6 +26,7 @@
 #include "../libcli/auth/libcli_auth.h"
 #include "secrets.h"
 #include "../libcli/security/security.h"
+#include "../lib/util/util_pw.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_PASSDB
index 07c56ebd43834149bc099998b8a82ca6d4b67dac..0ac9a9741153c83ed0d1f2ab9807d777ecc8bbb3 100644 (file)
@@ -48,6 +48,7 @@
 #include "secrets.h"
 #include "idmap_cache.h"
 #include "../libcli/security/security.h"
+#include "../lib/util/util_pw.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_PASSDB
index b4e8b19f1f8806f94af2d8c761fffbd9e3fb80fd..18d222373acacb1b5b060fe56c967f1cecf87ada 100644 (file)
@@ -19,6 +19,7 @@
 #include "includes.h"
 #include "secrets.h"
 #include "../librpc/gen_ndr/samr.h"
+#include "../lib/util/util_pw.h"
 
 /*
  * Next two lines needed for SunOS and don't