The branch, master has been updated
       via  f3aa2a2b73e3ece1d3b57698303980a26083b08d (commit)
       via  6985f3995f74d081cb8f2256a1c6fc2d80166713 (commit)
      from  47b5a55239fe21e24d47ce56e752a0ee328b697f (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f3aa2a2b73e3ece1d3b57698303980a26083b08d
Author: Günther Deschner <[email protected]>
Date:   Thu Jun 4 12:17:39 2009 +0200

    nss_wrapper: add skeleton for module nwrap_backend.
    
    Guenther

commit 6985f3995f74d081cb8f2256a1c6fc2d80166713
Author: Günther Deschner <[email protected]>
Date:   Thu Jun 4 11:59:32 2009 +0200

    nss_wrapper: add capability to load nss modules.
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 lib/nss_wrapper/nss_wrapper.c |  275 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 274 insertions(+), 1 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/nss_wrapper/nss_wrapper.c b/lib/nss_wrapper/nss_wrapper.c
index cffa044..862bb89 100644
--- a/lib/nss_wrapper/nss_wrapper.c
+++ b/lib/nss_wrapper/nss_wrapper.c
@@ -37,6 +37,7 @@
 #include "../replace/replace.h"
 #include "system/passwd.h"
 #include "system/filesys.h"
+#include "../nsswitch/nsstest.h"
 
 #else /* _SAMBA_BUILD_ */
 
@@ -139,9 +140,33 @@
 #define NWRAP_VERBOSE(args)
 #endif
 
+struct nwrap_module_nss_fns {
+       NSS_STATUS (*_nss_getpwnam_r)(const char *name, struct passwd *result, 
char *buffer,
+                                     size_t buflen, int *errnop);
+       NSS_STATUS (*_nss_getpwuid_r)(uid_t uid, struct passwd *result, char 
*buffer,
+                                     size_t buflen, int *errnop);
+       NSS_STATUS (*_nss_setpwent)(void);
+       NSS_STATUS (*_nss_getpwent_r)(struct passwd *result, char *buffer,
+                                     size_t buflen, int *errnop);
+       NSS_STATUS (*_nss_endpwent)(void);
+       NSS_STATUS (*_nss_initgroups)(const char *user, gid_t group, long int 
*start,
+                                     long int *size, gid_t **groups, long int 
limit, int *errnop);
+       NSS_STATUS (*_nss_getgrnam_r)(const char *name, struct group *result, 
char *buffer,
+                                     size_t buflen, int *errnop);
+       NSS_STATUS (*_nss_getgrgid_r)(gid_t gid, struct group *result, char 
*buffer,
+                                     size_t buflen, int *errnop);
+       NSS_STATUS (*_nss_setgrent)(void);
+       NSS_STATUS (*_nss_getgrent_r)(struct group *result, char *buffer,
+                                     size_t buflen, int *errnop);
+       NSS_STATUS (*_nss_endgrent)(void);
+};
+
 struct nwrap_backend {
        const char *name;
+       const char *so_path;
+       void *so_handle;
        struct nwrap_ops *ops;
+       struct nwrap_module_nss_fns *fns;
 };
 
 struct nwrap_ops {
@@ -219,6 +244,43 @@ static int nwrap_files_getgrent_r(struct nwrap_backend *b,
                                  size_t buflen, struct group **grdstp);
 static void nwrap_files_endgrent(struct nwrap_backend *b);
 
+/* protoypes for module backend */
+
+static struct passwd *nwrap_module_getpwent(struct nwrap_backend *b);
+static int nwrap_module_getpwent_r(struct nwrap_backend *b,
+                                  struct passwd *pwdst, char *buf,
+                                  size_t buflen, struct passwd **pwdstp);
+static struct passwd *nwrap_module_getpwnam(struct nwrap_backend *b,
+                                           const char *name);
+static int nwrap_module_getpwnam_r(struct nwrap_backend *b,
+                                  const char *name, struct passwd *pwdst,
+                                  char *buf, size_t buflen, struct passwd 
**pwdstp);
+static struct passwd *nwrap_module_getpwuid(struct nwrap_backend *b,
+                                           uid_t uid);
+static int nwrap_module_getpwuid_r(struct nwrap_backend *b,
+                                  uid_t uid, struct passwd *pwdst,
+                                  char *buf, size_t buflen, struct passwd 
**pwdstp);
+static void nwrap_module_setpwent(struct nwrap_backend *b);
+static void nwrap_module_endpwent(struct nwrap_backend *b);
+static struct group *nwrap_module_getgrent(struct nwrap_backend *b);
+static int nwrap_module_getgrent_r(struct nwrap_backend *b,
+                                  struct group *grdst, char *buf,
+                                  size_t buflen, struct group **grdstp);
+static struct group *nwrap_module_getgrnam(struct nwrap_backend *b,
+                                          const char *name);
+static int nwrap_module_getgrnam_r(struct nwrap_backend *b,
+                                  const char *name, struct group *grdst,
+                                  char *buf, size_t buflen, struct group 
**grdstp);
+static struct group *nwrap_module_getgrgid(struct nwrap_backend *b,
+                                          gid_t gid);
+static int nwrap_module_getgrgid_r(struct nwrap_backend *b,
+                                  gid_t gid, struct group *grdst,
+                                  char *buf, size_t buflen, struct group 
**grdstp);
+static void nwrap_module_setgrent(struct nwrap_backend *b);
+static void nwrap_module_endgrent(struct nwrap_backend *b);
+static int nwrap_module_initgroups(struct nwrap_backend *b,
+                                  const char *user, gid_t group);
+
 struct nwrap_ops nwrap_files_ops = {
        .nw_getpwnam    = nwrap_files_getpwnam,
        .nw_getpwnam_r  = nwrap_files_getpwnam_r,
@@ -239,6 +301,26 @@ struct nwrap_ops nwrap_files_ops = {
        .nw_endgrent    = nwrap_files_endgrent,
 };
 
+struct nwrap_ops nwrap_module_ops = {
+       .nw_getpwnam    = nwrap_module_getpwnam,
+       .nw_getpwnam_r  = nwrap_module_getpwnam_r,
+       .nw_getpwuid    = nwrap_module_getpwuid,
+       .nw_getpwuid_r  = nwrap_module_getpwuid_r,
+       .nw_setpwent    = nwrap_module_setpwent,
+       .nw_getpwent    = nwrap_module_getpwent,
+       .nw_getpwent_r  = nwrap_module_getpwent_r,
+       .nw_endpwent    = nwrap_module_endpwent,
+       .nw_initgroups  = nwrap_module_initgroups,
+       .nw_getgrnam    = nwrap_module_getgrnam,
+       .nw_getgrnam_r  = nwrap_module_getgrnam_r,
+       .nw_getgrgid    = nwrap_module_getgrgid,
+       .nw_getgrgid_r  = nwrap_module_getgrgid_r,
+       .nw_setgrent    = nwrap_module_setgrent,
+       .nw_getgrent    = nwrap_module_getgrent,
+       .nw_getgrent_r  = nwrap_module_getgrent_r,
+       .nw_endgrent    = nwrap_module_endgrent,
+};
+
 struct nwrap_main {
        const char *nwrap_switch;
        int num_backends;
@@ -286,8 +368,94 @@ struct nwrap_gr nwrap_gr_global;
 static bool nwrap_gr_parse_line(struct nwrap_cache *nwrap, char *line);
 static void nwrap_gr_unload(struct nwrap_cache *nwrap);
 
+static void *nwrap_load_module_fn(struct nwrap_backend *b,
+                                 const char *fn_name)
+{
+       void *res;
+       char *s;
+
+       if (!b->so_handle) {
+               NWRAP_ERROR(("%s: no handle\n",
+                            __location__));
+               return NULL;
+       }
+
+       if (asprintf(&s, "_nss_%s_%s", b->name, fn_name) == -1) {
+               NWRAP_ERROR(("%s: out of memory\n",
+                            __location__));
+               return NULL;
+       }
+
+       res = dlsym(b->so_handle, s);
+       if (!res) {
+               NWRAP_ERROR(("%s: cannot find function %s in %s\n",
+                            __location__, s, b->so_path));
+       }
+       free(s);
+       s = NULL;
+       return res;
+}
+
+static struct nwrap_module_nss_fns *nwrap_load_module_fns(struct nwrap_backend 
*b)
+{
+       struct nwrap_module_nss_fns *fns;
+
+       if (!b->so_handle) {
+               return NULL;
+       }
+
+       fns = (struct nwrap_module_nss_fns *)malloc(sizeof(struct 
nwrap_module_nss_fns));
+       if (!fns) {
+               return NULL;
+       }
+
+       fns->_nss_getpwnam_r    = (NSS_STATUS (*)(const char *, struct passwd 
*, char *, size_t, int *))
+                                 nwrap_load_module_fn(b, "getpwnam_r");
+       fns->_nss_getpwuid_r    = (NSS_STATUS (*)(uid_t, struct passwd *, char 
*, size_t, int *))
+                                 nwrap_load_module_fn(b, "getpwuid_r");
+       fns->_nss_setpwent      = (NSS_STATUS(*)(void))
+                                 nwrap_load_module_fn(b, "setpwent");
+       fns->_nss_getpwent_r    = (NSS_STATUS (*)(struct passwd *, char *, 
size_t, int *))
+                                 nwrap_load_module_fn(b, "getpwent_r");
+       fns->_nss_endpwent      = (NSS_STATUS(*)(void))
+                                 nwrap_load_module_fn(b, "endpwent");
+       fns->_nss_initgroups    = (NSS_STATUS (*)(const char *, gid_t, long int 
*, long int *, gid_t **, long int, int *))
+                                 nwrap_load_module_fn(b, "initgroups_dyn");
+       fns->_nss_getgrnam_r    = (NSS_STATUS (*)(const char *, struct group *, 
char *, size_t, int *))
+                                 nwrap_load_module_fn(b, "getgrnam_r");
+       fns->_nss_getgrgid_r    = (NSS_STATUS (*)(gid_t, struct group *, char 
*, size_t, int *))
+                                 nwrap_load_module_fn(b, "getgrgid_r");
+       fns->_nss_setgrent      = (NSS_STATUS(*)(void))
+                                 nwrap_load_module_fn(b, "setgrent");
+       fns->_nss_getgrent_r    = (NSS_STATUS (*)(struct group *, char *, 
size_t, int *))
+                                 nwrap_load_module_fn(b, "getgrent_r");
+       fns->_nss_endgrent      = (NSS_STATUS(*)(void))
+                                 nwrap_load_module_fn(b, "endgrent");
+
+       return fns;
+}
+
+static void *nwrap_load_module(const char *so_path)
+{
+       void *h;
+
+       if (!so_path || !strlen(so_path)) {
+               return NULL;
+       }
+
+       h = dlopen(so_path, RTLD_LAZY);
+       if (!h) {
+               NWRAP_ERROR(("%s: cannot open shared library %s\n",
+                            __location__, so_path));
+               return NULL;
+       }
+
+       return h;
+}
+
 static bool nwrap_module_init(const char *name,
                              struct nwrap_ops *ops,
+                             const char *so_path,
                              int *num_backends,
                              struct nwrap_backend **backends)
 {
@@ -300,6 +468,9 @@ static bool nwrap_module_init(const char *name,
 
        (*backends)[*num_backends].name = name;
        (*backends)[*num_backends].ops = ops;
+       (*backends)[*num_backends].so_path = so_path;
+       (*backends)[*num_backends].so_handle = nwrap_load_module(so_path);
+       (*backends)[*num_backends].fns = 
nwrap_load_module_fns(&((*backends)[*num_backends]));
 
        (*num_backends)++;
 
@@ -311,7 +482,7 @@ static void nwrap_backend_init(struct nwrap_main *r)
        r->num_backends = 0;
        r->backends = NULL;
 
-       if (!nwrap_module_init("files", &nwrap_files_ops,
+       if (!nwrap_module_init("files", &nwrap_files_ops, NULL,
                               &r->num_backends,
                               &r->backends)) {
                NWRAP_ERROR(("%s: failed to initialize 'files' backend\n",
@@ -1201,6 +1372,108 @@ static void nwrap_files_endgrent(struct nwrap_backend 
*b)
 }
 
 /*
+ * module backend
+ */
+
+static struct passwd *nwrap_module_getpwnam(struct nwrap_backend *b,
+                                           const char *name)
+{
+       return NULL;
+}
+
+static int nwrap_module_getpwnam_r(struct nwrap_backend *b,
+                                  const char *name, struct passwd *pwdst,
+                                  char *buf, size_t buflen, struct passwd 
**pwdstp)
+{
+       return ENOENT;
+}
+
+static struct passwd *nwrap_module_getpwuid(struct nwrap_backend *b,
+                                           uid_t uid)
+{
+       return NULL;
+}
+
+static int nwrap_module_getpwuid_r(struct nwrap_backend *b,
+                                  uid_t uid, struct passwd *pwdst,
+                                  char *buf, size_t buflen, struct passwd 
**pwdstp)
+{
+       return ENOENT;
+}
+
+static void nwrap_module_setpwent(struct nwrap_backend *b)
+{
+}
+
+static struct passwd *nwrap_module_getpwent(struct nwrap_backend *b)
+{
+       return NULL;
+}
+
+static int nwrap_module_getpwent_r(struct nwrap_backend *b,
+                                  struct passwd *pwdst, char *buf,
+                                  size_t buflen, struct passwd **pwdstp)
+{
+       return ENOENT;
+}
+
+static void nwrap_module_endpwent(struct nwrap_backend *b)
+{
+}
+
+static int nwrap_module_initgroups(struct nwrap_backend *b,
+                                  const char *user, gid_t group)
+{
+       return -1;
+}
+
+static struct group *nwrap_module_getgrnam(struct nwrap_backend *b,
+                                          const char *name)
+{
+       return NULL;
+}
+
+static int nwrap_module_getgrnam_r(struct nwrap_backend *b,
+                                  const char *name, struct group *grdst,
+                                  char *buf, size_t buflen, struct group 
**grdstp)
+{
+       return ENOENT;
+}
+
+static struct group *nwrap_module_getgrgid(struct nwrap_backend *b,
+                                          gid_t gid)
+{
+       return NULL;
+}
+
+static int nwrap_module_getgrgid_r(struct nwrap_backend *b,
+                                  gid_t gid, struct group *grdst,
+                                  char *buf, size_t buflen, struct group 
**grdstp)
+{
+       return ENOENT;
+}
+
+static void nwrap_module_setgrent(struct nwrap_backend *b)
+{
+}
+
+static struct group *nwrap_module_getgrent(struct nwrap_backend *b)
+{
+       return NULL;
+}
+
+static int nwrap_module_getgrent_r(struct nwrap_backend *b,
+                                  struct group *grdst, char *buf,
+                                  size_t buflen, struct group **grdstp)
+{
+       return 0;
+}
+
+static void nwrap_module_endgrent(struct nwrap_backend *b)
+{
+}
+
+/*
  * PUBLIC interface
  */
 


-- 
Samba Shared Repository

Reply via email to