#include <windows.h>
#include <strsafe.h>
#include <winldap.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include "idmap.h"
#include "nfs41_const.h"
#include "list.h"
#include "daemon_debug.h"
Go to the source code of this file.
|
#define | IDLVL 2 /* dprintf level for idmap logging */ |
|
#define | FILTER_LEN 1024 |
|
#define | NAME_LEN 32 |
|
#define | VAL_LEN 257 |
|
#define | ATTR_FLAG(attr) (1 << (attr)) |
|
#define | ATTR_ISSET(mask, attr) (((mask) & ATTR_FLAG(attr)) != 0) |
|
#define | OPT_INT(key, def, field) { key, def, TYPE_INT, FIELD_OFFSET(struct idmap_config, field), 0 } |
|
#define | OPT_STR(key, def, field, len) { key, def, TYPE_STR, FIELD_OFFSET(struct idmap_config, field), len } |
|
#define | OPT_CLASS(key, def, index) { key, def, TYPE_STR, FIELD_OFFSET(struct idmap_config, classes[index]), NAME_LEN } |
|
#define | OPT_ATTR(key, def, index) { key, def, TYPE_STR, FIELD_OFFSET(struct idmap_config, attributes[index]), NAME_LEN } |
|
|
static int | config_parse_pair (char *line, struct config_pair *pair) |
|
static BOOL | parse_uint (const char *str, UINT *id_out) |
|
static int | config_defaults (struct idmap_config *config) |
|
static int | config_find_option (const struct config_pair *pair, const struct config_option **option) |
|
static int | config_load (struct idmap_config *config, const char *filename) |
|
static int | config_init (struct idmap_config *config) |
|
static void | cache_init (struct idmap_cache *cache, const struct cache_ops *ops) |
|
static void | cache_cleanup (struct idmap_cache *cache) |
|
static int | cache_insert (struct idmap_cache *cache, const struct idmap_lookup *lookup, const struct list_entry *src) |
|
static int | cache_lookup (struct idmap_cache *cache, const struct idmap_lookup *lookup, struct list_entry *entry_out) |
|
static struct list_entry * | user_cache_alloc () |
|
static void | user_cache_free (struct list_entry *entry) |
|
static void | user_cache_copy (struct list_entry *lhs, const struct list_entry *rhs) |
|
static struct list_entry * | group_cache_alloc () |
|
static void | group_cache_free (struct list_entry *entry) |
|
static void | group_cache_copy (struct list_entry *lhs, const struct list_entry *rhs) |
|
static int | idmap_filter (struct idmap_config *config, const struct idmap_lookup *lookup, char *filter, size_t filter_len) |
|
static int | idmap_query_attrs (struct idmap_context *context, const struct idmap_lookup *lookup, const unsigned attributes, const unsigned optional, PCHAR *values[], const int len) |
|
static int | idmap_lookup_user (struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_user *user) |
|
static int | idmap_lookup_group (struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_group *group) |
|
int | nfs41_idmap_create (struct idmap_context **context_out) |
|
void | nfs41_idmap_free (struct idmap_context *context) |
|
static int | username_cmp (const struct list_entry *list, const void *value) |
|
int | nfs41_idmap_name_to_ids (struct idmap_context *context, const char *username, uid_t *uid_out, gid_t *gid_out) |
|
static int | uid_cmp (const struct list_entry *list, const void *value) |
|
int | nfs41_idmap_uid_to_name (struct idmap_context *context, uid_t uid, char *name, size_t len) |
|
static int | principal_cmp (const struct list_entry *list, const void *value) |
|
int | nfs41_idmap_principal_to_ids (struct idmap_context *context, const char *principal, uid_t *uid_out, gid_t *gid_out) |
|
static int | group_cmp (const struct list_entry *list, const void *value) |
|
int | nfs41_idmap_group_to_gid (struct idmap_context *context, const char *name, gid_t *gid_out) |
|
static int | gid_cmp (const struct list_entry *list, const void *value) |
|
int | nfs41_idmap_gid_to_group (struct idmap_context *context, gid_t gid, char *name, size_t len) |
|
◆ ATTR_FLAG
◆ ATTR_ISSET
◆ FILTER_LEN
◆ IDLVL
◆ NAME_LEN
◆ OPT_ATTR
◆ OPT_CLASS
◆ OPT_INT
◆ OPT_STR
◆ VAL_LEN
◆ entry_alloc_fn
◆ entry_copy_fn
◆ entry_free_fn
◆ config_type
Enumerator |
---|
TYPE_STR | |
TYPE_INT | |
Definition at line 99 of file idmap.c.
◆ ldap_attr
Enumerator |
---|
ATTR_USER_NAME | |
ATTR_GROUP_NAME | |
ATTR_PRINCIPAL | |
ATTR_UID | |
ATTR_GID | |
NUM_ATTRIBUTES | |
Definition at line 49 of file idmap.c.
◆ ldap_class
Enumerator |
---|
CLASS_USER | |
CLASS_GROUP | |
NUM_CLASSES | |
Definition at line 42 of file idmap.c.
◆ cache_cleanup()
Definition at line 436 of file idmap.c.
438{
443}
struct outqueuenode * head
#define list_for_each_tmp(entry, tmp, head)
static void list_init(struct list_entry *head)
Referenced by nfs41_idmap_free().
◆ cache_init()
Definition at line 427 of file idmap.c.
430{
434}
VOID WINAPI InitializeSRWLock(PSRWLOCK Lock)
◆ cache_insert()
Definition at line 445 of file idmap.c.
449{
452
454
455
458
461 }
462
463
468 }
474}
static void list_add_head(struct list_entry *head, struct list_entry *entry)
static struct list_entry * list_search(const struct list_entry *head, const void *value, list_compare_fn compare)
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
DWORD WINAPI GetLastError(void)
Referenced by idmap_lookup_group(), and idmap_lookup_user().
◆ cache_lookup()
◆ config_defaults()
Definition at line 243 of file idmap.c.
245{
250
254
258 eprintf(
"failed to parse default value of %s=\"%s\": "
260 break;
261 }
262 } else {
265 eprintf(
"failed to parse default value of %s=\"%s\": "
268 break;
269 }
270 }
271 }
273}
void eprintf(LPCSTR format,...)
#define ERROR_INVALID_PARAMETER
GLuint GLuint GLsizei count
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
static BOOL parse_uint(const char *str, UINT *id_out)
static const struct config_option g_options[]
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
#define ERROR_BUFFER_OVERFLOW
Referenced by config_init().
◆ config_find_option()
Definition at line 275 of file idmap.c.
278{
281
282
287 break;
288 }
289 }
291}
#define stricmp(_String1, _String2)
Referenced by config_load().
◆ config_init()
Definition at line 362 of file idmap.c.
364{
366#ifdef __REACTOS__
368#endif
369
370
375 }
376
377#ifdef __REACTOS__
379 {
381 }
382 else
383 {
387 }
388#endif
389
390
391#ifdef __REACTOS__
393#else
395#endif
397#ifdef __REACTOS__
398 eprintf(
"config_load('%s') failed with %d\n", config_path,
status);
399#else
401#endif
403 }
406}
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
static int config_load(struct idmap_config *config, const char *filename)
static int config_defaults(struct idmap_config *config)
static const char CONFIG_FILENAME[]
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Referenced by nfs41_idmap_create().
◆ config_load()
Definition at line 293 of file idmap.c.
296{
303
304
309 }
310
311
314
315
318
319
320 if (*
pos ==
'#' || *
pos == 0)
321 continue;
322
323
327 break;
328 }
329
330
333 eprintf(
"unrecognized option '%s' on line %d: %s\n",
336 break;
337 }
338
342 eprintf(
"expected a number on line %d: %s=\"%s\"\n",
344 break;
345 }
346 } else {
350 eprintf(
"overflow on line %d: %s=\"%s\"\n",
352 break;
353 }
354 }
355 }
356
360}
static int config_find_option(const struct config_pair *pair, const struct config_option **option)
static int config_parse_pair(char *line, struct config_pair *pair)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
Referenced by config_init().
◆ config_parse_pair()
Definition at line 153 of file idmap.c.
156{
159
160
163
164
168
174 }
175
176
180
181 if (
pair->key_len <= 0) {
185 }
186
187
190
192 eprintf(
"end of line looking for value\n");
195 }
196
198
205 }
207 } else {
210
211
214 }
215
216
217 ((
char*)
pair->key)[
pair->key_len] = 0;
218 ((
char*)
pair->value)[
pair->value_len] = 0;
221}
ACPI_SIZE strlen(const char *String)
char * strchr(const char *String, int ch)
Referenced by config_load().
◆ gid_cmp()
◆ group_cache_alloc()
◆ group_cache_copy()
Definition at line 553 of file idmap.c.
556{
561 dst->last_updated =
src->last_updated;
562}
◆ group_cache_free()
◆ group_cmp()
◆ idmap_filter()
Definition at line 579 of file idmap.c.
584{
587
592 "(&(objectClass=%s)(%s=%u))",
596 eprintf(
"ldap filter buffer overflow: '%s=%u'\n",
598 }
599 break;
600
603 "(&(objectClass=%s)(%s=%s))",
607 eprintf(
"ldap filter buffer overflow: '%s=%s'\n",
609 }
610 break;
611
612 default:
614 break;
615 }
617}
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
STRSAFEAPI StringCchPrintfA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszFormat,...)
Referenced by idmap_query_attrs().
◆ idmap_lookup_group()
Definition at line 750 of file idmap.c.
754{
759
760
763
764
767 }
768
769
773 goto out_free_values;
774
775
778 eprintf(
"ldap attribute %s='%s' longer than %u characters\n",
782 goto out_free_values;
783 }
785 eprintf(
"failed to parse ldap attribute %s='%s'\n",
788 goto out_free_values;
789 }
791
792 if (
context->config.cache_ttl) {
793
795 }
796out_free_values:
801}
GLboolean GLenum GLenum GLvoid * values
static int idmap_query_attrs(struct idmap_context *context, const struct idmap_lookup *lookup, const unsigned attributes, const unsigned optional, PCHAR *values[], const int len)
static int cache_insert(struct idmap_cache *cache, const struct idmap_lookup *lookup, const struct list_entry *src)
static int cache_lookup(struct idmap_cache *cache, const struct idmap_lookup *lookup, struct list_entry *entry_out)
Referenced by nfs41_idmap_gid_to_group(), and nfs41_idmap_group_to_gid().
◆ idmap_lookup_user()
Definition at line 679 of file idmap.c.
683{
689
692
693
696
697
700 }
701
702
706 goto out_free_values;
707
708
711 eprintf(
"ldap attribute %s='%s' longer than %u characters\n",
715 goto out_free_values;
716 }
719 eprintf(
"ldap attribute %s='%s' longer than %u characters\n",
723 goto out_free_values;
724 }
726 eprintf(
"failed to parse ldap attribute %s='%s'\n",
729 goto out_free_values;
730 }
732 eprintf(
"failed to parse ldap attribute %s='%s'\n",
735 goto out_free_values;
736 }
738
739 if (
context->config.cache_ttl) {
740
742 }
743out_free_values:
748}
void user(int argc, const char *argv[])
Referenced by nfs41_idmap_name_to_ids(), nfs41_idmap_principal_to_ids(), and nfs41_idmap_uid_to_name().
◆ idmap_query_attrs()
Definition at line 619 of file idmap.c.
626{
631
632
636
637
641 eprintf(
"ldap search for '%s' failed with %d: %s\n",
645 }
646
650 eprintf(
"ldap search for '%s' failed with %d: %s\n",
654 }
655
656
657 for (
i = 0;
i <
len;
i++) {
661
662
665 eprintf(
"ldap entry for '%s' missing required "
666 "attribute '%s', returning %d: %s\n",
671 }
672 }
673 }
677}
PCHAR CDECL ldap_err2stringA(ULONG err)
ULONG CDECL LdapMapErrorToWin32(ULONG err)
static int idmap_filter(struct idmap_config *config, const struct idmap_lookup *lookup, char *filter, size_t filter_len)
#define ATTR_ISSET(mask, attr)
char attributes[NUM_ATTRIBUTES][NAME_LEN]
#define LDAP_NO_SUCH_ATTRIBUTE
WINLDAPAPI ULONG ldap_msgfree(LDAPMessage *)
#define LDAP_SCOPE_SUBTREE
WINLDAPAPI PLDAPMessage ldap_first_entry(LDAP *, LDAPMessage *)
#define LDAP_NO_RESULTS_RETURNED
Referenced by idmap_lookup_group(), and idmap_lookup_user().
◆ nfs41_idmap_create()
Definition at line 805 of file idmap.c.
807{
810
815 }
816
817
820
821
825 goto out_err_free;
826 }
827
828
832 eprintf(
"ldap_init(%s) failed with %d: %s\n",
835 goto out_err_free;
836 }
837
839 (
void *)&
context->config.version);
841 eprintf(
"ldap_set_option(version=%d) failed with %d\n",
844 goto out_err_free;
845 }
846
849 (
void *)&
context->config.timeout);
851 eprintf(
"ldap_set_option(timeout=%d) failed with %d\n",
854 goto out_err_free;
855 }
856 }
857
861
862out_err_free:
865}
ULONG CDECL LdapGetLastError(void)
static const struct cache_ops group_cache_ops
void nfs41_idmap_free(struct idmap_context *context)
static int config_init(struct idmap_config *config)
static const struct cache_ops user_cache_ops
#define LDAP_OPT_TIMELIMIT
#define LDAP_OPT_PROTOCOL_VERSION
Referenced by ServiceStart().
◆ nfs41_idmap_free()
◆ nfs41_idmap_gid_to_group()
Definition at line 1055 of file idmap.c.
1060{
1065
1067
1068 lookup.value = (
const void*)gidp;
1069
1070
1076 }
1077
1080 eprintf(
"group name buffer overflow: '%s' > %u\n",
1083 }
1084
1086 "returning '%s'\n",
gid,
name);
1089}
static int gid_cmp(const struct list_entry *list, const void *value)
static int idmap_lookup_group(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_group *group)
◆ nfs41_idmap_group_to_gid()
Definition at line 1017 of file idmap.c.
1021{
1026
1028
1030
1031
1037 }
1038
1039 *gid_out =
group.gid;
1044}
static int group_cmp(const struct list_entry *list, const void *value)
◆ nfs41_idmap_name_to_ids()
Definition at line 889 of file idmap.c.
894{
899
902
904
906
907
913 }
914
921}
static int username_cmp(const struct list_entry *list, const void *value)
static int idmap_lookup_user(struct idmap_context *context, const struct idmap_lookup *lookup, struct idmap_user *user)
#define ERROR_FILE_NOT_FOUND
Referenced by map_user_to_ids().
◆ nfs41_idmap_principal_to_ids()
Definition at line 977 of file idmap.c.
982{
987
989
991
992
995 dprintf(
IDLVL,
"<-- nfs41_idmap_principal_to_ids('%s') "
998 }
999
1000 *uid_out =
user.uid;
1001 *gid_out =
user.gid;
1002 dprintf(
IDLVL,
"<-- nfs41_idmap_principal_to_ids('%s') "
1006}
static int principal_cmp(const struct list_entry *list, const void *value)
◆ nfs41_idmap_uid_to_name()
Definition at line 932 of file idmap.c.
937{
942
944
945 lookup.value = (
const void*)uidp;
946
947
953 }
954
957 eprintf(
"username buffer overflow: '%s' > %u\n",
960 }
961
963 "returning '%s'\n",
uid,
name);
966}
static int uid_cmp(const struct list_entry *list, const void *value)
◆ parse_uint()
◆ principal_cmp()
◆ uid_cmp()
◆ user_cache_alloc()
◆ user_cache_copy()
Definition at line 517 of file idmap.c.
520{
527 dst->last_updated =
src->last_updated;
528}
◆ user_cache_free()
◆ username_cmp()
◆ CONFIG_FILENAME
const char CONFIG_FILENAME[] = "C:\\ReactOS\\System32\\drivers\\etc\\ms-nfs41-idmap.conf" |
|
static |
◆ g_options
Initial value:= {
OPT_INT(
"cache_ttl",
"60", cache_ttl),
}
static const WCHAR version[]
#define OPT_INT(key, def, field)
#define OPT_STR(key, def, field, len)
#define OPT_ATTR(key, def, index)
#define OPT_CLASS(key, def, index)
#define NFS41_HOSTNAME_LEN
Definition at line 123 of file idmap.c.
Referenced by config_defaults(), and config_find_option().
◆ group_cache_ops
Initial value:= {
}
static void group_cache_free(struct list_entry *entry)
static void group_cache_copy(struct list_entry *lhs, const struct list_entry *rhs)
static struct list_entry * group_cache_alloc()
Definition at line 563 of file idmap.c.
Referenced by nfs41_idmap_create().
◆ user_cache_ops
Initial value:= {
}
static void user_cache_free(struct list_entry *entry)
static void user_cache_copy(struct list_entry *lhs, const struct list_entry *rhs)
static struct list_entry * user_cache_alloc()
Definition at line 529 of file idmap.c.
Referenced by nfs41_idmap_create().