ReactOS  0.4.12-dev-36-g472787f
idmap.h File Reference
#include "nfs41_types.h"
Include dependency graph for idmap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct idmap_context nfs41_idmapper
 

Functions

int nfs41_idmap_create (nfs41_idmapper **context_out)
 
void nfs41_idmap_free (nfs41_idmapper *context)
 
int nfs41_idmap_name_to_ids (nfs41_idmapper *context, const char *username, uid_t *uid_out, gid_t *gid_out)
 
int nfs41_idmap_uid_to_name (nfs41_idmapper *context, uid_t uid, char *name_out, size_t len)
 
int nfs41_idmap_principal_to_ids (nfs41_idmapper *context, const char *principal, uid_t *uid_out, gid_t *gid_out)
 
int nfs41_idmap_group_to_gid (nfs41_idmapper *context, const char *name, gid_t *gid_out)
 
int nfs41_idmap_gid_to_group (nfs41_idmapper *context, gid_t gid, char *name_out, size_t len)
 

Typedef Documentation

◆ nfs41_idmapper

Definition at line 29 of file idmap.h.

Function Documentation

◆ nfs41_idmap_create()

int nfs41_idmap_create ( nfs41_idmapper **  context_out)

Definition at line 803 of file idmap.c.

Referenced by ServiceStart().

805 {
806  struct idmap_context *context;
807  int status = NO_ERROR;
808 
809  context = calloc(1, sizeof(struct idmap_context));
810  if (context == NULL) {
811  status = GetLastError();
812  goto out;
813  }
814 
815  /* initialize the caches */
816  cache_init(&context->users, &user_cache_ops);
817  cache_init(&context->groups, &group_cache_ops);
818 
819  /* load ldap configuration from file */
820  status = config_init(&context->config);
821  if (status) {
822  eprintf("config_init() failed with %d\n", status);
823  goto out_err_free;
824  }
825 
826  /* initialize ldap and configure options */
827  context->ldap = ldap_init(context->config.hostname, context->config.port);
828  if (context->ldap == NULL) {
829  status = LdapGetLastError();
830  eprintf("ldap_init(%s) failed with %d: %s\n",
831  context->config.hostname, status, ldap_err2stringA(status));
832  status = LdapMapErrorToWin32(status);
833  goto out_err_free;
834  }
835 
837  (void *)&context->config.version);
838  if (status != LDAP_SUCCESS) {
839  eprintf("ldap_set_option(version=%d) failed with %d\n",
840  context->config.version, status);
841  status = LdapMapErrorToWin32(status);
842  goto out_err_free;
843  }
844 
845  if (context->config.timeout) {
846  status = ldap_set_option(context->ldap, LDAP_OPT_TIMELIMIT,
847  (void *)&context->config.timeout);
848  if (status != LDAP_SUCCESS) {
849  eprintf("ldap_set_option(timeout=%d) failed with %d\n",
850  context->config.timeout, status);
851  status = LdapMapErrorToWin32(status);
852  goto out_err_free;
853  }
854  }
855 
856  *context_out = context;
857 out:
858  return status;
859 
860 out_err_free:
861  nfs41_idmap_free(context);
862  goto out;
863 }
struct idmap_cache groups
Definition: idmap.c:572
static const struct cache_ops group_cache_ops
Definition: idmap.c:561
LDAP * ldap
Definition: idmap.c:573
Definition: http.c:6587
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
PCHAR CDECL ldap_err2stringA(ULONG err)
Definition: error.c:71
struct idmap_cache users
Definition: idmap.c:571
#define NO_ERROR
Definition: dderror.h:5
#define LDAP_OPT_PROTOCOL_VERSION
Definition: winldap.h:145
#define LDAP_OPT_TIMELIMIT
Definition: winldap.h:133
ULONG CDECL LdapMapErrorToWin32(ULONG err)
Definition: error.c:302
smooth NULL
Definition: ftsmooth.c:416
static const struct cache_ops user_cache_ops
Definition: idmap.c:527
static FILE * out
Definition: regtests2xml.c:44
struct idmap_config config
Definition: idmap.c:570
#define ldap_init
Definition: winldap.h:638
ULONG CDECL LdapGetLastError(void)
Definition: error.c:184
#define LDAP_SUCCESS
Definition: winldap.h:59
static int config_init(struct idmap_config *config)
Definition: idmap.c:362
#define calloc
Definition: rosglue.h:14
#define ldap_set_option
Definition: winldap.h:641
static void cache_init(struct idmap_cache *cache, const struct cache_ops *ops)
Definition: idmap.c:425
static SERVICE_STATUS status
Definition: service.c:31
void nfs41_idmap_free(struct idmap_context *context)
Definition: idmap.c:865
Definition: ps.c:97

◆ nfs41_idmap_free()

void nfs41_idmap_free ( nfs41_idmapper context)

Definition at line 865 of file idmap.c.

Referenced by nfs41_idmap_create(), and ServiceStart().

867 {
868  /* clean up the connection */
869  if (context->ldap)
870  ldap_unbind(context->ldap);
871 
872  cache_cleanup(&context->users);
873  cache_cleanup(&context->groups);
874  free(context);
875 }
struct idmap_cache groups
Definition: idmap.c:572
LDAP * ldap
Definition: idmap.c:573
#define free
Definition: debug_ros.c:5
WINLDAPAPI ULONG ldap_unbind(LDAP *)
struct idmap_cache users
Definition: idmap.c:571
static void cache_cleanup(struct idmap_cache *cache)
Definition: idmap.c:434

◆ nfs41_idmap_gid_to_group()

int nfs41_idmap_gid_to_group ( nfs41_idmapper context,
gid_t  gid,
char name_out,
size_t  len 
)

Definition at line 1053 of file idmap.c.

1058 {
1059  UINT_PTR gidp = gid; /* convert to pointer size to pass as void* */
1061  struct idmap_group group;
1062  int status;
1063 
1064  dprintf(IDLVL, "--> nfs41_idmap_gid_to_group(%u)\n", gid);
1065 
1066  lookup.value = (const void*)gidp;
1067 
1068  /* look up the group entry */
1069  status = idmap_lookup_group(context, &lookup, &group);
1070  if (status) {
1071  dprintf(IDLVL, "<-- nfs41_idmap_gid_to_group(%u) "
1072  "failed with %d\n", gid, status);
1073  goto out;
1074  }
1075 
1076  if (FAILED(StringCchCopyA(name, len, group.name))) {
1077  status = ERROR_BUFFER_OVERFLOW;
1078  eprintf("group name buffer overflow: '%s' > %u\n",
1079  group.name, len);
1080  goto out;
1081  }
1082 
1083  dprintf(IDLVL, "<-- nfs41_idmap_gid_to_group(%u) "
1084  "returning '%s'\n", gid, name);
1085 out:
1086  return status;
1087 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
static ULONG lookup[16]
Definition: vga.c:46
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
gid_t gid
Definition: idmap.c:538
#define dprintf
Definition: regdump.c:33
#define IDLVL
Definition: idmap.c:35
GLboolean GLuint group
Definition: glext.h:11120
static int idmap_lookup_group(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_group *group)
Definition: idmap.c:748
static FILE * out
Definition: regtests2xml.c:44
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
GLenum GLsizei len
Definition: glext.h:6722
static int gid_cmp(const struct list_entry *list, const void *value)
Definition: idmap.c:1045
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
Definition: name.c:36
Definition: idmap.c:54
const void * value
Definition: idmap.c:73
static SERVICE_STATUS status
Definition: service.c:31
WCHAR * name
Definition: name.c:40

◆ nfs41_idmap_group_to_gid()

int nfs41_idmap_group_to_gid ( nfs41_idmapper context,
const char name,
gid_t gid_out 
)

Definition at line 1015 of file idmap.c.

1019 {
1020  struct idmap_lookup lookup = { ATTR_GROUP_NAME,
1022  struct idmap_group group;
1023  int status;
1024 
1025  dprintf(IDLVL, "--> nfs41_idmap_group_to_gid('%s')\n", name);
1026 
1027  lookup.value = name;
1028 
1029  /* look up the group entry */
1030  status = idmap_lookup_group(context, &lookup, &group);
1031  if (status) {
1032  dprintf(IDLVL, "<-- nfs41_idmap_group_to_gid('%s') "
1033  "failed with %d\n", name, status);
1034  goto out;
1035  }
1036 
1037  *gid_out = group.gid;
1038  dprintf(IDLVL, "<-- nfs41_idmap_group_to_gid('%s') "
1039  "returning %u\n", name, group.gid);
1040 out:
1041  return status;
1042 }
static ULONG lookup[16]
Definition: vga.c:46
#define dprintf
Definition: regdump.c:33
static int group_cmp(const struct list_entry *list, const void *value)
Definition: idmap.c:1007
#define IDLVL
Definition: idmap.c:35
GLboolean GLuint group
Definition: glext.h:11120
static int idmap_lookup_group(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_group *group)
Definition: idmap.c:748
static FILE * out
Definition: regtests2xml.c:44
Definition: name.c:36
const void * value
Definition: idmap.c:73
static SERVICE_STATUS status
Definition: service.c:31
GLuint const GLchar * name
Definition: glext.h:6031

◆ nfs41_idmap_name_to_ids()

int nfs41_idmap_name_to_ids ( nfs41_idmapper context,
const char username,
uid_t uid_out,
gid_t gid_out 
)

Definition at line 887 of file idmap.c.

Referenced by map_user_to_ids().

892 {
895  struct idmap_user user;
896  int status;
897 
898  if (context == NULL)
899  return ERROR_FILE_NOT_FOUND;
900 
901  dprintf(IDLVL, "--> nfs41_idmap_name_to_ids('%s')\n", username);
902 
903  lookup.value = username;
904 
905  /* look up the user entry */
906  status = idmap_lookup_user(context, &lookup, &user);
907  if (status) {
908  dprintf(IDLVL, "<-- nfs41_idmap_name_to_ids('%s') "
909  "failed with %d\n", username, status);
910  goto out;
911  }
912 
913  *uid_out = user.uid;
914  *gid_out = user.gid;
915  dprintf(IDLVL, "<-- nfs41_idmap_name_to_ids('%s') "
916  "returning uid=%u, gid=%u\n", username, user.uid, user.gid);
917 out:
918  return status;
919 }
static ULONG lookup[16]
Definition: vga.c:46
static int idmap_lookup_user(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_user *user)
Definition: idmap.c:677
static int username_cmp(const struct list_entry *list, const void *value)
Definition: idmap.c:879
#define dprintf
Definition: regdump.c:33
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static WCHAR username[]
Definition: url.c:32
#define IDLVL
Definition: idmap.c:35
static FILE * out
Definition: regtests2xml.c:44
const void * value
Definition: idmap.c:73
static SERVICE_STATUS status
Definition: service.c:31
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ nfs41_idmap_principal_to_ids()

int nfs41_idmap_principal_to_ids ( nfs41_idmapper context,
const char principal,
uid_t uid_out,
gid_t gid_out 
)

Definition at line 975 of file idmap.c.

980 {
983  struct idmap_user user;
984  int status;
985 
986  dprintf(IDLVL, "--> nfs41_idmap_principal_to_ids('%s')\n", principal);
987 
988  lookup.value = principal;
989 
990  /* look up the user entry */
991  status = idmap_lookup_user(context, &lookup, &user);
992  if (status) {
993  dprintf(IDLVL, "<-- nfs41_idmap_principal_to_ids('%s') "
994  "failed with %d\n", principal, status);
995  goto out;
996  }
997 
998  *uid_out = user.uid;
999  *gid_out = user.gid;
1000  dprintf(IDLVL, "<-- nfs41_idmap_principal_to_ids('%s') "
1001  "returning uid=%u, gid=%u\n", principal, user.uid, user.gid);
1002 out:
1003  return status;
1004 }
static ULONG lookup[16]
Definition: vga.c:46
static int idmap_lookup_user(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_user *user)
Definition: idmap.c:677
static int principal_cmp(const struct list_entry *list, const void *value)
Definition: idmap.c:967
#define dprintf
Definition: regdump.c:33
#define IDLVL
Definition: idmap.c:35
static FILE * out
Definition: regtests2xml.c:44
char principal[VAL_LEN]
Definition: idmap.c:500
const void * value
Definition: idmap.c:73
static SERVICE_STATUS status
Definition: service.c:31
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ nfs41_idmap_uid_to_name()

int nfs41_idmap_uid_to_name ( nfs41_idmapper context,
uid_t  uid,
char name_out,
size_t  len 
)

Definition at line 930 of file idmap.c.

935 {
936  UINT_PTR uidp = uid; /* convert to pointer size to pass as void* */
938  struct idmap_user user;
939  int status;
940 
941  dprintf(IDLVL, "--> nfs41_idmap_uid_to_name(%u)\n", uid);
942 
943  lookup.value = (const void*)uidp;
944 
945  /* look up the user entry */
946  status = idmap_lookup_user(context, &lookup, &user);
947  if (status) {
948  dprintf(IDLVL, "<-- nfs41_idmap_uid_to_name(%u) "
949  "failed with %d\n", uid, status);
950  goto out;
951  }
952 
953  if (FAILED(StringCchCopyA(name, len, user.username))) {
954  status = ERROR_BUFFER_OVERFLOW;
955  eprintf("username buffer overflow: '%s' > %u\n",
956  user.username, len);
957  goto out;
958  }
959 
960  dprintf(IDLVL, "<-- nfs41_idmap_uid_to_name(%u) "
961  "returning '%s'\n", uid, name);
962 out:
963  return status;
964 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
uid_t uid
Definition: idmap.c:501
static int uid_cmp(const struct list_entry *list, const void *value)
Definition: idmap.c:922
Definition: idmap.c:53
static ULONG lookup[16]
Definition: vga.c:46
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
static int idmap_lookup_user(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_user *user)
Definition: idmap.c:677
#define dprintf
Definition: regdump.c:33
#define IDLVL
Definition: idmap.c:35
static FILE * out
Definition: regtests2xml.c:44
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
GLenum GLsizei len
Definition: glext.h:6722
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
Definition: name.c:36
const void * value
Definition: idmap.c:73
static SERVICE_STATUS status
Definition: service.c:31
void user(int argc, const char *argv[])
Definition: cmds.c:1350