- From 10045684053b8b9e130712c6bd1e177bcb85090e Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Sat, 14 Oct 2023 14:32:39 +0200
- Subject: [PATCH 1/2] daemon/idmap: Add support for using Cygwin as idmapping
- service
- Adding support for using Cygwin as idmapping service via Cygwin
- /usr/bin/getent, including the option that numeric uid and gid values
- differ between NFS server and NFS client (this is actually
- a design feature of NFSv4).
- The code is currently disabled (set
- |NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN| to |1| in
- sys/nfs41_build_features.h to enable it), until the feature is
- complete and fully tested.
- ToDo:
- - Command line option to select { LDAP, Cygwin } as idmap service
- - Autodetection Cygwin idmap service via testing for
- "C:\cygwin64\bin\getent.exe
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/acl.c | 650 ++++++++++++++++++-------------------
- daemon/ea.c | 4 +-
- daemon/getattr.c | 2 +-
- daemon/idmap.c | 395 +++++++++++++++++++++-
- daemon/lock.c | 4 +-
- daemon/mount.c | 4 +-
- daemon/nfs41_const.h | 3 +
- daemon/nfs41_daemon.c | 61 ++--
- daemon/nfs41_daemon.h | 39 +++
- daemon/open.c | 324 +++++++++---------
- daemon/readdir.c | 16 +-
- daemon/readwrite.c | 6 +-
- daemon/setattr.c | 24 +-
- daemon/symlink.c | 2 +-
- daemon/upcall.c | 3 +-
- daemon/upcall.h | 37 ++-
- daemon/volume.c | 2 +-
- libtirpc/src/auth_unix.c | 7 +-
- sys/nfs41_build_features.h | 7 +-
- 19 files changed, 1000 insertions(+), 590 deletions(-)
- create mode 100644 daemon/nfs41_daemon.h
- diff --git a/daemon/acl.c b/daemon/acl.c
- index e65548e..401fcd6 100644
- --- a/daemon/acl.c
- +++ b/daemon/acl.c
- @@ -20,22 +20,23 @@
- */
- #include <Windows.h>
- +#include <stdio.h>
- #include <strsafe.h>
- -#include <sddl.h>
- -
- -#include "nfs41_ops.h"
- -#include "nfs41_build_features.h"
- -#include "delegation.h"
- -#include "daemon_debug.h"
- -#include "util.h"
- +#include <sddl.h>
- +
- +#include "nfs41_ops.h"
- +#include "nfs41_build_features.h"
- +#include "nfs41_daemon.h"
- +#include "delegation.h"
- +#include "daemon_debug.h"
- +#include "util.h"
- #include "upcall.h"
- #include "nfs41_xdr.h"
- +#include "idmap.h"
- //#define DEBUG_ACLS
- #define ACLLVL 2 /* dprintf level for acl logging */
- -extern char localdomain_name[NFS41_HOSTNAME_LEN];
- -
- static int parse_getacl(unsigned char *buffer, uint32_t length,
- nfs41_upcall *upcall)
- {
- @@ -58,32 +59,32 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
- *sid = NULL;
- status = CreateWellKnownSid(type, NULL, *sid, sid_len);
- - dprintf(ACLLVL, "create_unknownsid: CreateWellKnownSid type %d returned %d "
- - "GetLastError %d sid len %d needed\n", type, status,
- - GetLastError(), *sid_len);
- - if (status) {
- - status = ERROR_INTERNAL_ERROR;
- - goto err;
- - }
- - status = GetLastError();
- - if (status != ERROR_INSUFFICIENT_BUFFER)
- - goto err;
- -
- - *sid = malloc(*sid_len);
- - if (*sid == NULL) {
- - status = ERROR_INSUFFICIENT_BUFFER;
- - goto err;
- - }
- - status = CreateWellKnownSid(type, NULL, *sid, sid_len);
- - if (status)
- - return ERROR_SUCCESS;
- - free(*sid);
- - *sid = NULL;
- - status = GetLastError();
- -err:
- - eprintf("create_unknownsid: CreateWellKnownSid failed with %d\n", status);
- - return status;
- -}
- + dprintf(ACLLVL, "create_unknownsid: CreateWellKnownSid type %d returned %d "
- + "GetLastError %d sid len %d needed\n", type, status,
- + GetLastError(), *sid_len);
- + if (status) {
- + status = ERROR_INTERNAL_ERROR;
- + goto err;
- + }
- + status = GetLastError();
- + if (status != ERROR_INSUFFICIENT_BUFFER)
- + goto err;
- +
- + *sid = malloc(*sid_len);
- + if (*sid == NULL) {
- + status = ERROR_INSUFFICIENT_BUFFER;
- + goto err;
- + }
- + status = CreateWellKnownSid(type, NULL, *sid, sid_len);
- + if (status)
- + return ERROR_SUCCESS;
- + free(*sid);
- + *sid = NULL;
- + status = GetLastError();
- +err:
- + eprintf("create_unknownsid: CreateWellKnownSid failed with %d\n", status);
- + return status;
- +}
- static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
- LPSTR *domain)
- @@ -92,145 +93,146 @@ static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
- for(; p[0] != '\0'; p++) {
- if (p[0] == '@') {
- p[0] = '\0';
- +
- *domain = &p[1];
- break;
- }
- - }
- -}
- -
- -#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- -/*
- - * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an
- - * UNIX/POSIX uid directly into a SID.
- - *
- - * Examples:
- - * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the
- - * SID as "S-1-22-1-1616":
- - * $ getent passwd Unix_User+1616
- - * Unix_User+1616:*:4278191696:4278191696:U-Unix_User616,S-1-22-1-1616:/:/sbin/nologin
- - *
- - * GID 1984 gets mapped to "Unix_Group+1984", encoding the GID into the
- - * SID as "S-1-22-2-1984":
- - * $ getent group Unix_Group+1984
- - * Unix_Group+1984:S-1-22-2-1984:4278192064:
- - *
- - */
- -
- -#define SECURITY_SAMBA_UNIX_AUTHORITY { { 0,0,0,0,0,22 } }
- -SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
- -
- -static
- -BOOL allocate_unixuser_sid(unsigned long uid, PSID *pSid)
- -{
- - PSID sid = NULL;
- - PSID malloced_sid = NULL;
- - DWORD sid_len;
- -
- - if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid,
- - 0, 0, 0, 0, 0, 0, &sid)) {
- - sid_len = GetLengthSid(sid);
- -
- - malloced_sid = malloc(sid_len);
- -
- - if (malloced_sid) {
- - /*
- - * |AllocateAndInitializeSid()| has an own memory
- - * allocator, but we need the sid in memory from
- - * |malloc()|
- - */
- - if (CopySid(sid_len, malloced_sid, sid)) {
- - FreeSid(sid);
- - *pSid = malloced_sid;
- - dprintf(ACLLVL, "allocate_unixuser_sid(): Allocated "
- - "Unix_User+%lu: success, len=%ld\n",
- - uid, (long)sid_len);
- - return TRUE;
- - }
- - }
- - }
- -
- - FreeSid(sid);
- - free(malloced_sid);
- - dprintf(ACLLVL, "allocate_unixuser_sid(): Failed to allocate "
- - "SID for Unix_User+%lu: error code %d\n",
- - uid, GetLastError());
- - return FALSE;
- -}
- -
- -static
- -BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
- -{
- - PSID sid = NULL;
- - PSID malloced_sid = NULL;
- - DWORD sid_len;
- -
- - if (AllocateAndInitializeSid(&sid_id_auth, 2, 2, (DWORD)gid,
- - 0, 0, 0, 0, 0, 0, &sid)) {
- - sid_len = GetLengthSid(sid);
- -
- - malloced_sid = malloc(sid_len);
- -
- - if (malloced_sid) {
- - /*
- - * |AllocateAndInitializeSid()| has an own memory
- - * allocator, but we need the sid in memory from
- - * |malloc()|
- - */
- - if (CopySid(sid_len, malloced_sid, sid)) {
- - FreeSid(sid);
- - *pSid = malloced_sid;
- - dprintf(ACLLVL, "allocate_unixgroup_sid(): Allocated "
- - "Unix_Group+%lu: success, len=%ld\n",
- - gid, (long)sid_len);
- - return TRUE;
- - }
- - }
- - }
- -
- - FreeSid(sid);
- - free(malloced_sid);
- - dprintf(ACLLVL, "allocate_unixgroup_sid(): Failed to allocate "
- - "SID for Unix_Group+%lu: error code %d\n",
- - gid, GetLastError());
- - return FALSE;
- -}
- -#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- -
- -static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
- -{
- - int status = ERROR_INTERNAL_ERROR;
- - SID_NAME_USE sid_type;
- - LPSTR tmp_buf = NULL;
- - DWORD tmp = 0;
- -#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- - signed long user_uid = -1;
- - signed long group_gid = -1;
- -#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- -
- -#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- - if (query & OWNER_SECURITY_INFORMATION) {
- - if (!strcmp(name, "rmainz")) {
- - name = "roland_mainz";
- - dprintf(ACLLVL, "map_name_2_sid: remap rmainz --> roland_mainz\n");
- - }
- - else if (!strcmp(name, "197608")) {
- - name = "roland_mainz";
- - dprintf(ACLLVL, "map_name_2_sid: remap 197608 --> roland_mainz\n");
- - }
- - else if (!strcmp(name, "1616")) {
- - name = "roland_mainz";
- - dprintf(ACLLVL, "map_name_2_sid: remap 1616 --> roland_mainz\n");
- - }
- - }
- -#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- -
- - status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type);
- - dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): LookupAccountName returned %d "
- - "GetLastError %d name len %d domain len %d\n",
- - query, name, status, GetLastError(), *sid_len, tmp);
- - if (status)
- - return ERROR_INTERNAL_ERROR;
- -
- + }
- +}
- +
- +#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- +/*
- + * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an
- + * UNIX/POSIX uid directly into a SID.
- + *
- + * Examples:
- + * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the
- + * SID as "S-1-22-1-1616":
- + * $ getent passwd Unix_User+1616
- + * Unix_User+1616:*:4278191696:4278191696:U-Unix_User616,S-1-22-1-1616:/:/sbin/nologin
- + *
- + * GID 1984 gets mapped to "Unix_Group+1984", encoding the GID into the
- + * SID as "S-1-22-2-1984":
- + * $ getent group Unix_Group+1984
- + * Unix_Group+1984:S-1-22-2-1984:4278192064:
- + *
- + */
- +
- +#define SECURITY_SAMBA_UNIX_AUTHORITY { { 0,0,0,0,0,22 } }
- +SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
- +
- +static
- +BOOL allocate_unixuser_sid(unsigned long uid, PSID *pSid)
- +{
- + PSID sid = NULL;
- + PSID malloced_sid = NULL;
- + DWORD sid_len;
- +
- + if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid,
- + 0, 0, 0, 0, 0, 0, &sid)) {
- + sid_len = GetLengthSid(sid);
- +
- + malloced_sid = malloc(sid_len);
- +
- + if (malloced_sid) {
- + /*
- + * |AllocateAndInitializeSid()| has an own memory
- + * allocator, but we need the sid in memory from
- + * |malloc()|
- + */
- + if (CopySid(sid_len, malloced_sid, sid)) {
- + FreeSid(sid);
- + *pSid = malloced_sid;
- + dprintf(ACLLVL, "allocate_unixuser_sid(): Allocated "
- + "Unix_User+%lu: success, len=%ld\n",
- + uid, (long)sid_len);
- + return TRUE;
- + }
- + }
- + }
- +
- + FreeSid(sid);
- + free(malloced_sid);
- + dprintf(ACLLVL, "allocate_unixuser_sid(): Failed to allocate "
- + "SID for Unix_User+%lu: error code %d\n",
- + uid, GetLastError());
- + return FALSE;
- +}
- +
- +static
- +BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
- +{
- + PSID sid = NULL;
- + PSID malloced_sid = NULL;
- + DWORD sid_len;
- +
- + if (AllocateAndInitializeSid(&sid_id_auth, 2, 2, (DWORD)gid,
- + 0, 0, 0, 0, 0, 0, &sid)) {
- + sid_len = GetLengthSid(sid);
- +
- + malloced_sid = malloc(sid_len);
- +
- + if (malloced_sid) {
- + /*
- + * |AllocateAndInitializeSid()| has an own memory
- + * allocator, but we need the sid in memory from
- + * |malloc()|
- + */
- + if (CopySid(sid_len, malloced_sid, sid)) {
- + FreeSid(sid);
- + *pSid = malloced_sid;
- + dprintf(ACLLVL, "allocate_unixgroup_sid(): Allocated "
- + "Unix_Group+%lu: success, len=%ld\n",
- + gid, (long)sid_len);
- + return TRUE;
- + }
- + }
- + }
- +
- + FreeSid(sid);
- + free(malloced_sid);
- + dprintf(ACLLVL, "allocate_unixgroup_sid(): Failed to allocate "
- + "SID for Unix_Group+%lu: error code %d\n",
- + gid, GetLastError());
- + return FALSE;
- +}
- +#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- +
- +static int map_name_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *sid_len, PSID *sid, LPCSTR name)
- +{
- + int status = ERROR_INTERNAL_ERROR;
- + SID_NAME_USE sid_type;
- + LPSTR tmp_buf = NULL;
- + DWORD tmp = 0;
- +#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- + signed long user_uid = -1;
- + signed long group_gid = -1;
- +#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- +
- +#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- + if (query & OWNER_SECURITY_INFORMATION) {
- + if (!strcmp(name, "rmainz")) {
- + name = "roland_mainz";
- + dprintf(ACLLVL, "map_name_2_sid: remap rmainz --> roland_mainz\n");
- + }
- + else if (!strcmp(name, "197608")) {
- + name = "roland_mainz";
- + dprintf(ACLLVL, "map_name_2_sid: remap 197608 --> roland_mainz\n");
- + }
- + else if (!strcmp(name, "1616")) {
- + name = "roland_mainz";
- + dprintf(ACLLVL, "map_name_2_sid: remap 1616 --> roland_mainz\n");
- + }
- + }
- +#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- +
- + status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type);
- + dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): LookupAccountName returned %d "
- + "GetLastError %d name len %d domain len %d\n",
- + query, name, status, GetLastError(), *sid_len, tmp);
- + if (status)
- + return ERROR_INTERNAL_ERROR;
- +
- status = GetLastError();
- switch(status) {
- case ERROR_INSUFFICIENT_BUFFER:
- @@ -243,14 +245,14 @@ static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
- if (tmp_buf == NULL)
- goto out_free_sid;
- status = LookupAccountName(NULL, name, *sid, sid_len, tmp_buf,
- - &tmp, &sid_type);
- - free(tmp_buf);
- - if (!status) {
- - eprintf("map_name_2_sid(query=%x,name='%s'): LookupAccountName failed "
- - "with %d\n", query, name, GetLastError());
- - goto out_free_sid;
- - } else {
- -#ifdef DEBUG_ACLS
- + &tmp, &sid_type);
- + free(tmp_buf);
- + if (!status) {
- + eprintf("map_name_2_sid(query=%x,name='%s'): LookupAccountName failed "
- + "with %d\n", query, name, GetLastError());
- + goto out_free_sid;
- + } else {
- +#ifdef DEBUG_ACLS
- LPSTR ssid = NULL;
- if (IsValidSid(*sid))
- if (ConvertSidToStringSidA(*sid, &ssid))
- @@ -264,115 +266,101 @@ static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
- if (ssid) LocalFree(ssid);
- #endif
- }
- - status = ERROR_SUCCESS;
- - break;
- - case ERROR_NONE_MAPPED:
- -#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- - dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
- - "trying Unix_User+/Unix_Group+ mapping\n",
- - query, name);
- -
- - if ((user_uid == -1) && (query & OWNER_SECURITY_INFORMATION)) {
- - if (isdigit(name[0])) {
- - user_uid = atol(name);
- - }
- - else if(!strcmp(name, "nobody")) {
- - user_uid = 65534;
- - }
- - else if(!strcmp(name, "root")) {
- - user_uid = 0;
- - }
- - else if(!strcmp(name, "rmainz")) {
- - user_uid = 1616;
- - }
- - else if(!strcmp(name, "swulsch")) {
- - user_uid = 1818;
- - }
- - else if(!strcmp(name, "mwenzel")) {
- - user_uid = 8239;
- - }
- - else if(!strcmp(name, "test001")) {
- - user_uid = 1000;
- - }
- - }
- -
- - if ((group_gid == -1) && (query & GROUP_SECURITY_INFORMATION)) {
- - if (isdigit(name[0])) {
- - group_gid = atol(name);
- - }
- - else if(!strcmp(name, "nobody")) {
- - group_gid = 65534;
- - }
- - else if(!strcmp(name, "root")) {
- - group_gid = 0;
- - }
- - else if(!strcmp(name, "rmainz")) {
- - group_gid = 1616;
- - }
- - else if(!strcmp(name, "swulsch")) {
- - group_gid = 1818;
- - }
- - else if(!strcmp(name, "mwenzel")) {
- - group_gid = 8239;
- - }
- - else if(!strcmp(name, "test001")) {
- - group_gid = 1000;
- - }
- - }
- -
- - if (user_uid != -1) {
- - if (allocate_unixuser_sid(user_uid, sid)) {
- - dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- - "allocate_unixuser_sid(uid=%ld) success\n",
- - query, name, user_uid);
- - return ERROR_SUCCESS;
- - }
- -
- - status = GetLastError();
- - dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- - "allocate_unixuser_sid(uid=%ld) failed, error=%d\n",
- - query, name, user_uid, status);
- - return status;
- - }
- -
- - if (group_gid != -1) {
- - if (allocate_unixgroup_sid(group_gid, sid)) {
- - dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- - "allocate_unixgroup_sid(gid=%ld) success\n",
- - query, name, group_gid);
- - return ERROR_SUCCESS;
- - }
- -
- - status = GetLastError();
- - dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- - "allocate_unixgroup_sid(gid=%ld) failed, error=%d\n",
- - query, name, group_gid, status);
- - return status;
- - }
- -#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- -
- - dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
- - "using WinNullSid mapping\n",
- - query, name);
- -
- - status = create_unknownsid(WinNullSid, sid, sid_len);
- - if (status)
- - goto out_free_sid;
- - break;
- - default:
- - dprintf(1, "map_name_2_sid(query=%x,name='%s'): error %d not handled\n",
- - query, name, GetLastError());
- - break;
- - }
- -out:
- - return status;
- -out_free_sid:
- - status = GetLastError();
- - free(*sid);
- - *sid = NULL;
- - goto out;
- -}
- -
- + status = ERROR_SUCCESS;
- + break;
- + case ERROR_NONE_MAPPED:
- +#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
- + dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
- + "trying Unix_User+/Unix_Group+ mapping\n",
- + query, name);
- +
- + if ((user_uid == -1) && (query & OWNER_SECURITY_INFORMATION)) {
- + uid_t map_uid = -1;
- + gid_t gid_dummy = -1;
- +
- + if (nfs41_idmap_name_to_ids(
- + nfs41dg->idmapper,
- + name,
- + &map_uid,
- + &gid_dummy) == 0) {
- + user_uid = map_uid;
- + }
- + else {
- + dprintf(1, "map_name_2_sid(query=%x,name='%s'): nfs41_idmap_name_to_ids() failed\n",
- + query, name);
- + /* fixme: try harder here, "1234" should to to |atol()| */
- + }
- + }
- +
- + if ((group_gid == -1) && (query & GROUP_SECURITY_INFORMATION)) {
- + gid_t map_gid = -1;
- +
- + if (nfs41_idmap_group_to_gid(
- + nfs41dg->idmapper,
- + name,
- + &map_gid) == 0) {
- + group_gid = map_gid;
- + }
- + else {
- + dprintf(1, "map_name_2_sid(query=%x,name='%s'): nfs41_idmap_group_to_gid() failed\n",
- + query, name);
- + /* fixme: try harder here, "1234" should to to |atol()| */
- + }
- + }
- +
- + if (user_uid != -1) {
- + if (allocate_unixuser_sid(user_uid, sid)) {
- + dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- + "allocate_unixuser_sid(uid=%ld) success\n",
- + query, name, user_uid);
- + return ERROR_SUCCESS;
- + }
- +
- + status = GetLastError();
- + dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- + "allocate_unixuser_sid(uid=%ld) failed, error=%d\n",
- + query, name, user_uid, status);
- + return status;
- + }
- +
- + if (group_gid != -1) {
- + if (allocate_unixgroup_sid(group_gid, sid)) {
- + dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- + "allocate_unixgroup_sid(gid=%ld) success\n",
- + query, name, group_gid);
- + return ERROR_SUCCESS;
- + }
- +
- + status = GetLastError();
- + dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
- + "allocate_unixgroup_sid(gid=%ld) failed, error=%d\n",
- + query, name, group_gid, status);
- + return status;
- + }
- +#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- +
- + dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
- + "using WinNullSid mapping\n",
- + query, name);
- +
- + status = create_unknownsid(WinNullSid, sid, sid_len);
- + if (status)
- + goto out_free_sid;
- + break;
- + default:
- + dprintf(1, "map_name_2_sid(query=%x,name='%s'): error %d not handled\n",
- + query, name, GetLastError());
- + break;
- + }
- +out:
- + return status;
- +out_free_sid:
- + status = GetLastError();
- + free(*sid);
- + *sid = NULL;
- + goto out;
- +}
- +
- static void free_sids(PSID *sids, int count)
- {
- int i;
- @@ -402,8 +390,8 @@ static int check_4_special_identifiers(char *who, PSID *sid, DWORD *sid_len,
- return status;
- }
- -static int convert_nfs4acl_2_dacl(nfsacl41 *acl, int file_type,
- - PACL *dacl_out, PSID **sids_out)
- +static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
- + nfsacl41 *acl, int file_type, PACL *dacl_out, PSID **sids_out)
- {
- int status = ERROR_NOT_SUPPORTED, size = 0;
- uint32_t i;
- @@ -426,14 +414,15 @@ static int convert_nfs4acl_2_dacl(nfsacl41 *acl, int file_type,
- &sid_len, &flag);
- if (status) {
- free_sids(sids, i);
- - goto out;
- - }
- - if (!flag) {
- - status = map_name_2_sid(0xFFFF /* fixme: Unknown whether user or group */,
- - &sid_len, &sids[i], acl->aces[i].who);
- - if (status) {
- - free_sids(sids, i);
- - goto out;
- + goto out;
- + }
- + if (!flag) {
- + status = map_name_2_sid(nfs41dg,
- + 0xFFFF /* fixme: Unknown whether user or group */,
- + &sid_len, &sids[i], acl->aces[i].who);
- + if (status) {
- + free_sids(sids, i);
- + goto out;
- }
- }
- size += sid_len - sizeof(DWORD);
- @@ -493,9 +482,10 @@ out_free_sids:
- goto out;
- }
- -static int handle_getacl(nfs41_upcall *upcall)
- +static int handle_getacl(void *daemon_context, nfs41_upcall *upcall)
- {
- int status = ERROR_NOT_SUPPORTED;
- + nfs41_daemon_globals *nfs41dg = daemon_context;
- getacl_upcall_args *args = &upcall->args.getacl;
- nfs41_open_state *state = upcall->state_ref;
- nfs41_file_info info = { 0 };
- @@ -541,30 +531,32 @@ static int handle_getacl(nfs41_upcall *upcall)
- if (args->query & OWNER_SECURITY_INFORMATION) {
- // parse user@domain. currently ignoring domain part XX
- convert_nfs4name_2_user_domain(info.owner, &domain);
- - dprintf(ACLLVL, "handle_getacl: OWNER_SECURITY_INFORMATION: for user=%s "
- - "domain=%s\n", info.owner, domain?domain:"<null>");
- - sid_len = 0;
- - status = map_name_2_sid(OWNER_SECURITY_INFORMATION, &sid_len, &osid, info.owner);
- - if (status)
- - goto out;
- - status = SetSecurityDescriptorOwner(&sec_desc, osid, TRUE);
- + dprintf(ACLLVL, "handle_getacl: OWNER_SECURITY_INFORMATION: for user=%s "
- + "domain=%s\n", info.owner, domain?domain:"<null>");
- + sid_len = 0;
- + status = map_name_2_sid(nfs41dg,
- + OWNER_SECURITY_INFORMATION, &sid_len, &osid, info.owner);
- + if (status)
- + goto out;
- + status = SetSecurityDescriptorOwner(&sec_desc, osid, TRUE);
- if (!status) {
- status = GetLastError();
- eprintf("handle_getacl: SetSecurityDescriptorOwner failed with "
- "%d\n", status);
- - goto out;
- - }
- - }
- -
- - if (args->query & GROUP_SECURITY_INFORMATION) {
- - convert_nfs4name_2_user_domain(info.owner_group, &domain);
- - dprintf(ACLLVL, "handle_getacl: GROUP_SECURITY_INFORMATION: for %s "
- - "domain=%s\n", info.owner_group, domain?domain:"<null>");
- - sid_len = 0;
- - status = map_name_2_sid(GROUP_SECURITY_INFORMATION, &sid_len, &gsid, info.owner_group);
- - if (status)
- - goto out;
- - status = SetSecurityDescriptorGroup(&sec_desc, gsid, TRUE);
- + goto out;
- + }
- + }
- +
- + if (args->query & GROUP_SECURITY_INFORMATION) {
- + convert_nfs4name_2_user_domain(info.owner_group, &domain);
- + dprintf(ACLLVL, "handle_getacl: GROUP_SECURITY_INFORMATION: for %s "
- + "domain=%s\n", info.owner_group, domain?domain:"<null>");
- + sid_len = 0;
- + status = map_name_2_sid(nfs41dg,
- + GROUP_SECURITY_INFORMATION, &sid_len, &gsid, info.owner_group);
- + if (status)
- + goto out;
- + status = SetSecurityDescriptorGroup(&sec_desc, gsid, TRUE);
- if (!status) {
- status = GetLastError();
- eprintf("handle_getacl: SetSecurityDescriptorGroup failed with "
- @@ -574,7 +566,8 @@ static int handle_getacl(nfs41_upcall *upcall)
- }
- if (args->query & DACL_SECURITY_INFORMATION) {
- dprintf(ACLLVL, "handle_getacl: DACL_SECURITY_INFORMATION\n");
- - status = convert_nfs4acl_2_dacl(info.acl, state->type, &dacl, &sids);
- + status = convert_nfs4acl_2_dacl(nfs41dg,
- + info.acl, state->type, &dacl, &sids);
- if (status)
- goto out;
- status = SetSecurityDescriptorDacl(&sec_desc, TRUE, dacl, TRUE);
- @@ -910,9 +903,10 @@ out_free:
- goto out;
- }
- -static int handle_setacl(nfs41_upcall *upcall)
- +static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
- {
- int status = ERROR_NOT_SUPPORTED;
- + nfs41_daemon_globals *nfs41dg = daemon_context;
- setacl_upcall_args *args = &upcall->args.setacl;
- nfs41_open_state *state = upcall->state_ref;
- nfs41_file_info info = { 0 };
- @@ -931,7 +925,7 @@ static int handle_setacl(nfs41_upcall *upcall)
- goto out;
- }
- info.owner = owner;
- - status = map_nfs4ace_who(sid, NULL, NULL, info.owner, localdomain_name);
- + status = map_nfs4ace_who(sid, NULL, NULL, info.owner, nfs41dg->localdomain_name);
- if (status)
- goto out;
- else {
- @@ -950,7 +944,7 @@ static int handle_setacl(nfs41_upcall *upcall)
- }
- info.owner_group = group;
- status = map_nfs4ace_who(sid, NULL, NULL, info.owner_group,
- - localdomain_name);
- + nfs41dg->localdomain_name);
- if (status)
- goto out;
- else {
- @@ -982,7 +976,7 @@ static int handle_setacl(nfs41_upcall *upcall)
- goto out;
- }
- status = map_dacl_2_nfs4acl(acl, sid, gsid, &nfs4_acl, state->type,
- - localdomain_name);
- + nfs41dg->localdomain_name);
- if (status)
- goto out;
- else {
- @@ -1018,7 +1012,7 @@ static int marshall_setacl(unsigned char *buffer, uint32_t *length, nfs41_upcall
- }
- const nfs41_upcall_op nfs41_op_setacl = {
- - parse_setacl,
- - handle_setacl,
- - marshall_setacl
- -};
- + parse_setacl,
- + handle_setacl,
- + marshall_setacl
- +};
- diff --git a/daemon/ea.c b/daemon/ea.c
- index 4909ad5..0cba5f8 100644
- --- a/daemon/ea.c
- +++ b/daemon/ea.c
- @@ -159,7 +159,7 @@ out:
- return status;
- }
- -static int handle_setexattr(nfs41_upcall *upcall)
- +static int handle_setexattr(void *daemon_context, nfs41_upcall *upcall)
- {
- int status;
- setexattr_upcall_args *args = &upcall->args.setexattr;
- @@ -527,7 +527,7 @@ static int overflow_error(
- return NO_ERROR;
- }
- -static int handle_getexattr(nfs41_upcall *upcall)
- +static int handle_getexattr(void *daemon_context, nfs41_upcall *upcall)
- {
- getexattr_upcall_args *args = &upcall->args.getexattr;
- PFILE_GET_EA_INFORMATION query = (PFILE_GET_EA_INFORMATION)args->ealist;
- diff --git a/daemon/getattr.c b/daemon/getattr.c
- index e9249a4..fa853a3 100644
- --- a/daemon/getattr.c
- +++ b/daemon/getattr.c
- @@ -73,7 +73,7 @@ out:
- return status;
- }
- -static int handle_getattr(nfs41_upcall *upcall)
- +static int handle_getattr(void *daemon_context, nfs41_upcall *upcall)
- {
- int status;
- getattr_upcall_args *args = &upcall->args.getattr;
- diff --git a/daemon/idmap.c b/daemon/idmap.c
- index 0dfa8ef..7662393 100644
- --- a/daemon/idmap.c
- +++ b/daemon/idmap.c
- @@ -26,13 +26,14 @@
- #include <errno.h>
- #include <time.h>
- +#include "nfs41_build_features.h"
- #include "idmap.h"
- #include "nfs41_const.h"
- #include "list.h"
- #include "daemon_debug.h"
- -
- -#define IDLVL 2 /* dprintf level for idmap logging */
- +#define IDLVL 2 /* dprintf level for idmap logging */
- +#define CYGWINIDLVL 2 /* dprintf level for idmap logging */
- #define FILTER_LEN 1024
- #define NAME_LEN 32
- @@ -375,6 +376,246 @@ out:
- return status;
- }
- +#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
- +int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid, gid_t *res_gid)
- +{
- + char cmdbuff[1024];
- + char passwd_line[1024];
- + FILE* getent_pipe = NULL;
- + int res = 1;
- + unsigned long uid = -1;
- + unsigned long gid = -1;
- + struct _cypwent {
- + char* loginname;
- + char* passwd;
- + char* uidstr;
- + char* gidstr;
- + char* comment;
- + char* homedir;
- + char* shell;
- + } pwent = { 0 };
- +#define PWENT_ENTRY(var, prevvar) \
- + (((var) = strchr((prevvar), ':'))?(*(var)++ = '\0',(var)):(NULL))
- +
- + dprintf(CYGWINIDLVL, "--> cygwin_getent_passwd('%s')\n", name);
- +
- +#if 1
- + /* hack for testing, map "roland_mainz" to rmainz account */
- + if ((!strcmp(name, "rmainz")) || (!strcmp(name, "1616"))) {
- + uid = 1616;
- + gid = 1616;
- + pwent.loginname = "rmainz";
- + goto found;
- + }
- + if ((!strcmp(name, "nobody")) || (!strcmp(name, "no+body")) ||
- + (!strcmp(name, "65534"))) {
- + uid = 65534;
- + gid = 65534;
- + pwent.loginname = "no+body"; /* Cygwin-specific */
- + goto found;
- + }
- + if ((!strcmp(name, "root")) || (!strcmp(name, "0"))) {
- + uid = 0;
- + gid = 0;
- + pwent.loginname = "root";
- + goto found;
- + }
- + if ((!strcmp(name, "iam")) || (!strcmp(name, "2010"))) {
- + uid = 2010;
- + gid = 2010;
- + pwent.loginname = "iam";
- + goto found;
- + }
- + if ((!strcmp(name, "swulsch")) || (!strcmp(name, "1818"))) {
- + uid = 1818;
- + gid = 1818;
- + pwent.loginname = "swulsch";
- + goto found;
- + }
- + if ((!strcmp(name, "mwenzel")) || (!strcmp(name, "8239"))) {
- + uid = 8239;
- + gid = 8239;
- + pwent.loginname = "mwenzel";
- + goto found;
- + }
- +#endif
- +
- + /* fixme: better quoting for |name| needed */
- + (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s passwd \"%s\"",
- + "C:\\cygwin64\\bin\\getent.exe",
- + name);
- + if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL) {
- + dprintf(CYGWINIDLVL, "cygwin_getent_passwd: /usr/bin/getent failed, errno='%s'\n",
- + strerror(errno));
- + goto fail;
- + }
- +
- + if (fgets(passwd_line, sizeof(passwd_line), getent_pipe)) {
- + pwent.loginname = passwd_line;
- + if (!PWENT_ENTRY(pwent.passwd, pwent.loginname)) goto fail;
- + if (!PWENT_ENTRY(pwent.uidstr, pwent.passwd)) goto fail;
- + if (!PWENT_ENTRY(pwent.gidstr, pwent.uidstr)) goto fail;
- + if (!PWENT_ENTRY(pwent.comment, pwent.gidstr)) goto fail;
- + if (!PWENT_ENTRY(pwent.homedir, pwent.comment)) goto fail;
- + PWENT_ENTRY(pwent.shell, pwent.homedir);
- +
- + errno = 0;
- + uid = strtol(pwent.uidstr, NULL, 10);
- + if (errno != 0)
- + goto fail;
- +
- + errno = 0;
- + gid = strtol(pwent.gidstr, NULL, 10);
- + if (errno != 0)
- + goto fail;
- +
- +#if 0
- + dprintf(CYGWINIDLVL, "cygwin_getent_passwd(): name='%s'\n", name);
- + dprintf(CYGWINIDLVL, "loginname\t='%s'\n", pwent.loginname);
- + dprintf(CYGWINIDLVL, "passwd\t='%s'\n", pwent.passwd);
- + dprintf(CYGWINIDLVL, "uidstr\t='%s' (%lu)\n", pwent.uidstr, (unsigned long)uid);
- + dprintf(CYGWINIDLVL, "gidstr\t='%s' (%lu)\n", pwent.gidstr, (unsigned long)gid);
- + dprintf(CYGWINIDLVL, "comment\t='%s'\n", pwent.comment);
- + dprintf(CYGWINIDLVL, "homedir\t='%s'\n", pwent.homedir);
- + dprintf(CYGWINIDLVL, "shell\t='%s'\n", pwent.shell);
- +#endif
- +
- +found:
- + if (res_loginname)
- + (void)strcpy_s(res_loginname, VAL_LEN, pwent.loginname);
- + *res_uid = uid;
- + *res_gid = gid;
- + res = 0;
- + }
- +
- +fail:
- + if (getent_pipe)
- + (void)_pclose(getent_pipe);
- +
- + if (res == 0) {
- + dprintf(CYGWINIDLVL, "<-- cygwin_getent_passwd('%s'): "
- + "returning res_uid=%lu, res_gid=%lu, res_loginname='%s'\n",
- + name,
- + (unsigned long)(*res_uid),
- + (unsigned long)(*res_gid),
- + res_loginname?res_loginname:"<NULL>");
- + }
- + else {
- + dprintf(CYGWINIDLVL, "<-- cygwin_getent_passwd('%s'): no match found\n",
- + name);
- + }
- +
- + return res;
- +}
- +
- +int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid)
- +{
- + char cmdbuff[1024];
- + char group_line[1024];
- + FILE* getent_pipe = NULL;
- + int res = 1;
- + unsigned long gid = -1;
- + struct _cygrent
- + {
- + char* group_name;
- + char* passwd;
- + char* gidstr;
- + char* userlist;
- + } grent = { 0 };
- +
- + dprintf(CYGWINIDLVL, "--> cygwin_getent_group('%s')\n", name);
- +
- +#if 1
- + if ((!strcmp(name, "rmainz")) || (!strcmp(name, "1616"))) {
- + gid = 1616;
- + grent.group_name = "rmainz";
- + goto found;
- + }
- + if ((!strcmp(name, "nogroup")) || (!strcmp(name, "no+body")) ||
- + (!strcmp(name, "65534"))) {
- + gid = 65534;
- + grent.group_name = "no+body"; /* Cygwin-specific */
- + goto found;
- + }
- + if ((!strcmp(name, "root")) || (!strcmp(name, "0"))) {
- + gid = 0;
- + grent.group_name = "root";
- + goto found;
- + }
- + if ((!strcmp(name, "iam")) || (!strcmp(name, "2010"))) {
- + gid = 2010;
- + grent.group_name = "iam";
- + goto found;
- + }
- + if ((!strcmp(name, "swulsch")) || (!strcmp(name, "1818"))) {
- + gid = 1818;
- + grent.group_name = "swulsch";
- + goto found;
- + }
- + if ((!strcmp(name, "mwenzel")) || (!strcmp(name, "8239"))) {
- + gid = 8239;
- + grent.group_name = "mwenzel";
- + goto found;
- + }
- +#endif
- +
- + /* fixme: better quoting for |name| needed */
- + (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s group \"%s\"",
- + "C:\\cygwin64\\bin\\getent.exe",
- + name);
- + if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL) {
- + dprintf(CYGWINIDLVL,
- + "cygwin_getent_group: /usr/bin/getent failed, errno='%s'\n",
- + strerror(errno));
- + goto fail;
- + }
- +
- + if (fgets(group_line, sizeof(group_line), getent_pipe))
- + {
- + grent.group_name = group_line;
- + if (!PWENT_ENTRY(grent.passwd, grent.group_name)) goto fail;
- + if (!PWENT_ENTRY(grent.gidstr, grent.passwd)) goto fail;
- + PWENT_ENTRY(grent.userlist, grent.gidstr);
- +
- + errno = 0;
- + gid = strtol(grent.gidstr, NULL, 10);
- + if (errno != 0)
- + goto fail;
- +
- +#if 0
- + dprintf(CYGWINIDLVL, "cygwin_getent_group(): name='%s'\n", name);
- + dprintf(CYGWINIDLVL, "group_name\t='%s'\n", grent.group_name);
- + dprintf(CYGWINIDLVL, "passwd\t='%s'\n", grent.passwd);
- + dprintf(CYGWINIDLVL, "gidstr\t='%s' (%lu)\n", grent.gidstr, (unsigned long)gid);
- + dprintf(CYGWINIDLVL, "userlist\t='%s'\n", grent.userlist);
- +#endif
- +
- +found:
- + if (res_group_name)
- + (void)strcpy_s(res_group_name, VAL_LEN, grent.group_name);
- + *res_gid = gid;
- + res = 0;
- + }
- +
- +fail:
- + if (getent_pipe)
- + (void)_pclose(getent_pipe);
- +
- + if (res == 0) {
- + dprintf(CYGWINIDLVL, "<-- cygwin_getent_group('%s'): "
- + "returning res_gid=%lu, res_group_name='%s'\n",
- + name, (unsigned long)(*res_gid),
- + res_group_name?res_group_name:"<NULL>");
- + }
- + else {
- + dprintf(CYGWINIDLVL,
- + "<-- cygwin_getent_group('%s'): no match found\n",
- + name);
- + }
- +
- + return res;
- +}
- +#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
- /* generic cache */
- typedef struct list_entry* (*entry_alloc_fn)();
- @@ -665,10 +906,10 @@ static int idmap_lookup_user(
- if (status == NO_ERROR) {
- /* don't return expired entries; query new attributes
- * and overwrite the entry with cache_insert() */
- - if (time(NULL) - user->last_updated < context->config.cache_ttl)
- + if ((time(NULL) - user->last_updated) < context->config.cache_ttl)
- goto out;
- }
- -
- +#ifndef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
- /* send the query to the ldap server */
- status = idmap_query_attrs(context, lookup,
- attributes, optional, values, NUM_ATTRIBUTES);
- @@ -705,7 +946,94 @@ static int idmap_lookup_user(
- goto out_free_values;
- }
- user->last_updated = time(NULL);
- +#else
- + if (lookup->attr == ATTR_USER_NAME) {
- + char principal_name[VAL_LEN];
- + uid_t cy_uid = 0;
- + gid_t cy_gid = 0;
- +
- + status = ERROR_NOT_FOUND;
- +
- + if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) {
- + dprintf(CYGWINIDLVL, "# ATTR_USER_NAME: cygwin_getent_passwd: returned '%s', uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid);
- + (void)snprintf(principal_name, sizeof(principal_name),
- + "%s@%s", (const char *)lookup->value, "GLOBAL.LOC");
- + StringCchCopyA(user->username, VAL_LEN, lookup->value);
- + StringCchCopyA(user->principal, VAL_LEN, principal_name);
- + user->uid = cy_uid;
- + user->gid = cy_gid;
- + status = 0;
- + }
- + }
- + else if (lookup->attr == ATTR_PRINCIPAL) {
- + char search_name[VAL_LEN];
- + char principal_name[VAL_LEN];
- + char *s;
- + uid_t cy_uid = 0;
- + gid_t cy_gid = 0;
- +
- + status = ERROR_NOT_FOUND;
- +
- + /*
- + * strip '@' from principal name and use that for getent
- + * fixme: This does not work with multiple domains
- + */
- + (void)strcpy_s(search_name, sizeof(search_name), lookup->value);
- + if (s = strchr(search_name, '@'))
- + *s = '\0';
- +
- + if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) {
- + dprintf(CYGWINIDLVL, "# ATTR_PRINCIPAL: cygwin_getent_passwd: returned '%s', uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid);
- + (void)snprintf(principal_name, sizeof(principal_name),
- + "%s@%s", (const char *)lookup->value, "GLOBAL.LOC");
- +
- + if (!strcmp(principal_name, lookup->value)) {
- + StringCchCopyA(user->username, VAL_LEN, search_name);
- + StringCchCopyA(user->principal, VAL_LEN, principal_name);
- + user->uid = cy_uid;
- + user->gid = cy_gid;
- + status = 0;
- + }
- + }
- + }
- + else if (lookup->attr == ATTR_UID) {
- + uid_t search_uid = (uid_t)(lookup->value);
- + char search_name[VAL_LEN];
- + char res_username[VAL_LEN];
- + char principal_name[VAL_LEN];
- + uid_t cy_uid = 0;
- + gid_t cy_gid = 0;
- +
- + status = ERROR_NOT_FOUND;
- +
- + (void)snprintf(search_name, sizeof(search_name), "%lu", (unsigned long)search_uid);
- +
- + if (!cygwin_getent_passwd(search_name, res_username, &cy_uid, &cy_gid)) {
- + dprintf(CYGWINIDLVL, "# ATTR_UID: cygwin_getent_passwd: returned '%s', uid=%d, gid=%d\n", res_username, (int)cy_uid, (int)cy_gid);
- + (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", res_username, "GLOBAL.LOC");
- +
- + StringCchCopyA(user->username, VAL_LEN, res_username);
- + StringCchCopyA(user->principal, VAL_LEN, principal_name);
- + user->uid = cy_uid;
- + user->gid = cy_gid;
- + status = 0;
- + }
- + }
- + else
- + {
- + status = ERROR_NOT_FOUND;
- + }
- + if (status == 0) {
- + user->last_updated = time(NULL);
- + dprintf(CYGWINIDLVL, "## idmap_lookup_user: "
- + "found username='%s', principal='%s', uid=%lu, gid=%lu\n",
- + user->username,
- + user->principal,
- + (unsigned long)user->uid,
- + (unsigned long)user->gid);
- + }
- +#endif /* !NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
- if (context->config.cache_ttl) {
- /* insert the entry into the cache */
- cache_insert(&context->users, lookup, &user->entry);
- @@ -732,10 +1060,10 @@ static int idmap_lookup_group(
- if (status == NO_ERROR) {
- /* don't return expired entries; query new attributes
- * and overwrite the entry with cache_insert() */
- - if (time(NULL) - group->last_updated < context->config.cache_ttl)
- + if ((time(NULL) - group->last_updated) < context->config.cache_ttl)
- goto out;
- }
- -
- +#ifndef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
- /* send the query to the ldap server */
- status = idmap_query_attrs(context, lookup,
- attributes, 0, values, NUM_ATTRIBUTES);
- @@ -758,7 +1086,55 @@ static int idmap_lookup_group(
- goto out_free_values;
- }
- group->last_updated = time(NULL);
- +#else
- + if (lookup->attr == ATTR_GROUP_NAME) {
- + gid_t cy_gid = 0;
- +
- + status = ERROR_NOT_FOUND;
- +
- + if (!cygwin_getent_group(lookup->value, NULL, &cy_gid)) {
- + dprintf(CYGWINIDLVL,
- + "# ATTR_GROUP_NAME: cygwin_getent_group: "
- + "returned '%s', gid=%d\n",
- + lookup->value, (int)cy_gid);
- + StringCchCopyA(group->name, VAL_LEN, lookup->value);
- + group->gid = cy_gid;
- + status = 0;
- + }
- + }
- + else if (lookup->attr == ATTR_GID) {
- + gid_t search_gid = (gid_t)(lookup->value);
- + char search_name[VAL_LEN];
- + char res_groupname[VAL_LEN];
- + gid_t cy_gid = 0;
- +
- + status = ERROR_NOT_FOUND;
- +
- + (void)snprintf(search_name, sizeof(search_name),
- + "%lu", (unsigned long)search_gid);
- +
- + if (!cygwin_getent_group(search_name, res_groupname, &cy_gid)) {
- + dprintf(CYGWINIDLVL,
- + "# ATTR_GID: cygwin_getent_group: returned '%s', gid=%d\n",
- + res_groupname, (int)cy_gid);
- + StringCchCopyA(group->name, VAL_LEN, res_groupname);
- + group->gid = cy_gid;
- + status = 0;
- + }
- + }
- + else
- + {
- + status = ERROR_NOT_FOUND;
- + }
- + if (status == 0) {
- + group->last_updated = time(NULL);
- + dprintf(CYGWINIDLVL,
- + "## idmap_lookup_group: found name='%s', gid=%lu\n",
- + group->name,
- + (unsigned long)group->gid);
- + }
- +#endif /* !NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
- if (context->config.cache_ttl) {
- /* insert the entry into the cache */
- cache_insert(&context->groups, lookup, &group->entry);
- @@ -770,7 +1146,6 @@ out:
- return status;
- }
- -
- /* public idmap interface */
- int nfs41_idmap_create(
- struct idmap_context **context_out)
- @@ -795,6 +1170,7 @@ int nfs41_idmap_create(
- goto out_err_free;
- }
- +#ifndef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
- /* initialize ldap and configure options */
- context->ldap = ldap_init(context->config.hostname, context->config.port);
- if (context->ldap == NULL) {
- @@ -824,8 +1200,13 @@ int nfs41_idmap_create(
- goto out_err_free;
- }
- }
- +#else
- + dprintf(CYGWINIDLVL, "nfs41_idmap_create: Force context->config.timeout = 6000;\n");
- + context->config.timeout = 6000;
- +#endif
- *context_out = context;
- +
- out:
- return status;
- diff --git a/daemon/lock.c b/daemon/lock.c
- index c1ac146..4d5294d 100644
- --- a/daemon/lock.c
- +++ b/daemon/lock.c
- @@ -194,7 +194,7 @@ static __inline uint32_t get_lock_type(BOOLEAN exclusive, BOOLEAN blocking)
- : ( exclusive == 0 ? READW_LT : WRITEW_LT );
- }
- -static int handle_lock(nfs41_upcall *upcall)
- +static int handle_lock(void *deamon_context, nfs41_upcall *upcall)
- {
- stateid_arg stateid;
- lock_upcall_args *args = &upcall->args.lock;
- @@ -318,7 +318,7 @@ out:
- return status;
- }
- -static int handle_unlock(nfs41_upcall *upcall)
- +static int handle_unlock(void *daemon_context, nfs41_upcall *upcall)
- {
- nfs41_lock_state input;
- stateid_arg stateid;
- diff --git a/daemon/mount.c b/daemon/mount.c
- index fc6ec47..8d51020 100644
- --- a/daemon/mount.c
- +++ b/daemon/mount.c
- @@ -56,7 +56,7 @@ out:
- return status;
- }
- -static int handle_mount(nfs41_upcall *upcall)
- +static int handle_mount(void *daemon_context, nfs41_upcall *upcall)
- {
- int status;
- mount_upcall_args *args = &upcall->args.mount;
- @@ -192,7 +192,7 @@ static int parse_unmount(unsigned char *buffer, uint32_t length, nfs41_upcall *u
- return ERROR_SUCCESS;
- }
- -static int handle_unmount(nfs41_upcall *upcall)
- +static int handle_unmount(void *daemon_context, nfs41_upcall *upcall)
- {
- /* release the original reference from nfs41_root_create() */
- nfs41_root_deref(upcall->root_ref);
- diff --git a/daemon/nfs41_const.h b/daemon/nfs41_const.h
- index f1e6177..0e96586 100644
- --- a/daemon/nfs41_const.h
- +++ b/daemon/nfs41_const.h
- @@ -395,5 +395,8 @@ enum nfs_ftype4 {
- #define ACL4_PROTECTED 0x00000002
- #define ACL4_DEFAULTED 0x00000004
- +/* Common user and group names */
- +#define NFS_USER_NOBODY_UID 65534
- +#define NFS_GROUP_NOGROUP_GID 65534
- #endif /* !__NFS41_NFS_CONST_H__ */
- diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
- index bb485cb..04086ea 100644
- --- a/daemon/nfs41_daemon.c
- +++ b/daemon/nfs41_daemon.c
- @@ -30,7 +30,7 @@
- #include "nfs41_driver.h" /* for NFS41_USER_DEVICE_NAME_A */
- #include "nfs41_np.h" /* for NFS41NP_SHARED_MEMORY */
- -#include "idmap.h"
- +#include "nfs41_daemon.h"
- #include "daemon_debug.h"
- #include "upcall.h"
- #include "util.h"
- @@ -41,9 +41,11 @@ DWORD NFS41D_VERSION = 0;
- static const char FILE_NETCONFIG[] = "C:\\etc\\netconfig";
- /* Globals */
- -char localdomain_name[NFS41_HOSTNAME_LEN];
- -int default_uid = 666;
- -int default_gid = 777;
- +nfs41_daemon_globals nfs41_dg = {
- + .default_uid = NFS_USER_NOBODY_UID,
- + .default_gid = NFS_GROUP_NOGROUP_GID,
- +};
- +
- #ifndef STANDALONE_NFSD //make sure to define it in "sources" not here
- #include "service.h"
- @@ -54,7 +56,7 @@ typedef struct _nfs41_process_thread {
- uint32_t tid;
- } nfs41_process_thread;
- -static int map_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
- +static int map_current_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
- {
- char username[UNLEN + 1];
- DWORD len = UNLEN + 1;
- @@ -62,15 +64,15 @@ static int map_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
- if (!GetUserNameA(username, &len)) {
- status = GetLastError();
- - eprintf("GetUserName() failed with %d\n", status);
- + eprintf("map_current_user_to_ids: GetUserName() failed with %d\n", status);
- goto out;
- }
- - dprintf(1, "map_user_to_ids: mapping user %s\n", username);
- + dprintf(1, "map_current_user_to_ids: mapping user %s\n", username);
- if (nfs41_idmap_name_to_ids(idmapper, username, uid, gid)) {
- /* instead of failing for auth_sys, fall back to 'nobody' uid/gid */
- - *uid = default_uid;
- - *gid = default_gid;
- + *uid = nfs41_dg.default_uid;
- + *gid = nfs41_dg.default_gid;
- }
- out:
- return status;
- @@ -78,7 +80,7 @@ out:
- static unsigned int WINAPI thread_main(void *args)
- {
- - nfs41_idmapper *idmapper = (nfs41_idmapper*)args;
- + nfs41_daemon_globals *nfs41dg = (nfs41_daemon_globals *)args;
- DWORD status = 0;
- HANDLE pipe;
- // buffer used to process upcall, assumed to be fixed size.
- @@ -110,8 +112,12 @@ static unsigned int WINAPI thread_main(void *args)
- goto write_downcall;
- }
- - /* map username to uid/gid */
- - status = map_user_to_ids(idmapper, &upcall.uid, &upcall.gid);
- + /*
- + * Map current username to uid/gid
- + * Each thread can handle a different user
- + */
- + status = map_current_user_to_ids(nfs41dg->idmapper,
- + &upcall.uid, &upcall.gid);
- if (status) {
- upcall.status = status;
- goto write_downcall;
- @@ -122,7 +128,7 @@ static unsigned int WINAPI thread_main(void *args)
- exit(0);
- }
- - status = upcall_handle(&upcall);
- + status = upcall_handle(&nfs41_dg, &upcall);
- write_downcall:
- dprintf(1, "writing downcall: xid=%lld opcode=%s status=%d "
- @@ -212,10 +218,10 @@ static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
- PrintUsage();
- return FALSE;
- }
- - default_uid = _ttoi(argv[i]);
- - if (!default_uid) {
- + nfs41_dg.default_uid = _ttoi(argv[i]);
- + if (!nfs41_dg.default_uid) {
- fprintf(stderr, "Invalid (or missing) anonymous uid value of %d\n",
- - default_uid);
- + nfs41_dg.default_uid);
- return FALSE;
- }
- }
- @@ -226,7 +232,7 @@ static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
- PrintUsage();
- return FALSE;
- }
- - default_gid = _ttoi(argv[i]);
- + nfs41_dg.default_gid = _ttoi(argv[i]);
- }
- else
- fprintf(stderr, "Unrecognized option '%s', disregarding.\n", argv[i]);
- @@ -320,9 +326,9 @@ static int getdomainname()
- if (i == len)
- break;
- flag = TRUE;
- - memcpy(localdomain_name, &hostname[i+1], len-i);
- + memcpy(nfs41_dg.localdomain_name, &hostname[i+1], len-i);
- dprintf(1, "getdomainname: domainname %s %d\n",
- - localdomain_name, strlen(localdomain_name));
- + nfs41_dg.localdomain_name, strlen(nfs41_dg.localdomain_name));
- goto out_loop;
- }
- break;
- @@ -340,9 +346,9 @@ out_loop:
- freeaddrinfo(result);
- } else {
- dprintf(1, "domain name is %s\n", net_info->DomainName);
- - memcpy(localdomain_name, net_info->DomainName,
- + memcpy(nfs41_dg.localdomain_name, net_info->DomainName,
- strlen(net_info->DomainName));
- - localdomain_name[strlen(net_info->DomainName)] = '\0';
- + nfs41_dg.localdomain_name[strlen(net_info->DomainName)] = '\0';
- }
- out_free:
- free(net_info);
- @@ -360,7 +366,6 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
- // handle to our drivers
- HANDLE pipe;
- nfs41_process_thread tids[MAX_NUM_THREADS];
- - nfs41_idmapper *idmapper = NULL;
- int i;
- nfsd_args cmd_args;
- @@ -389,10 +394,15 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
- exit(1);
- }
- +#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
- + /* force enable for cygwin getent passwd/group testing */
- + cmd_args.ldap_enable = TRUE;
- +#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
- +
- nfs41_server_list_init();
- if (cmd_args.ldap_enable) {
- - status = nfs41_idmap_create(&idmapper);
- + status = nfs41_idmap_create(&(nfs41_dg.idmapper));
- if (status) {
- eprintf("id mapping initialization failed with %d\n", status);
- goto out_logs;
- @@ -428,7 +438,7 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
- for (i = 0; i < MAX_NUM_THREADS; i++) {
- tids[i].handle = (HANDLE)_beginthreadex(NULL, 0, thread_main,
- - idmapper, 0, &tids[i].tid);
- + &nfs41_dg, 0, &tids[i].tid);
- if (tids[i].handle == INVALID_HANDLE_VALUE) {
- status = GetLastError();
- eprintf("_beginthreadex failed %d\n", status);
- @@ -451,7 +461,8 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
- out_pipe:
- CloseHandle(pipe);
- out_idmap:
- - if (idmapper) nfs41_idmap_free(idmapper);
- + if (nfs41_dg.idmapper)
- + nfs41_idmap_free(nfs41_dg.idmapper);
- out_logs:
- #ifndef STANDALONE_NFSD
- close_log_files();
- diff --git a/daemon/nfs41_daemon.h b/daemon/nfs41_daemon.h
- new file mode 100644
- index 0000000..6c91e41
- --- /dev/null
- +++ b/daemon/nfs41_daemon.h
- @@ -0,0 +1,39 @@
- +/* NFSv4.1 client for Windows
- + * Copyright © 2012 The Regents of the University of Michigan
- + *
- + * Olga Kornievskaia <aglo@umich.edu>
- + * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- + *
- + * This library is free software; you can redistribute it and/or modify it
- + * under the terms of the GNU Lesser General Public License as published by
- + * the Free Software Foundation; either version 2.1 of the License, or (at
- + * your option) any later version.
- + *
- + * This library 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 Lesser General Public
- + * License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public License
- + * along with this library; if not, write to the Free Software Foundation,
- + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- + */
- +
- +#ifndef __NFS41_DAEMON_H_
- +#define __NFS41_DAEMON_H_ 1
- +
- +#include "nfs41_build_features.h"
- +#include "idmap.h"
- +
- +/*
- + * Global data of the daemon process
- + */
- +typedef struct __nfs41_daemon_globals {
- + struct idmap_context *idmapper;
- + char localdomain_name[NFS41_HOSTNAME_LEN];
- + int default_uid;
- + int default_gid;
- +} nfs41_daemon_globals;
- +
- +#endif /* !__NFS41_DAEMON_H_ */
- diff --git a/daemon/open.c b/daemon/open.c
- index e59939b..87b71cd 100644
- --- a/daemon/open.c
- +++ b/daemon/open.c
- @@ -18,23 +18,25 @@
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- */
- -
- -#include <Windows.h>
- -#include <stdio.h>
- -#include <ctype.h>
- -#include <strsafe.h>
- -
- -#include "nfs41_ops.h"
- -#include "nfs41_build_features.h"
- -#include "delegation.h"
- -#include "from_kernel.h"
- -#include "daemon_debug.h"
- -#include "upcall.h"
- -#include "util.h"
- -
- -static int create_open_state(
- - IN const char *path,
- - IN uint32_t open_owner_id,
- +
- +#include <Windows.h>
- +#include <stdio.h>
- +#include <ctype.h>
- +#include <strsafe.h>
- +
- +#include "nfs41_ops.h"
- +#include "nfs41_build_features.h"
- +#include "nfs41_daemon.h"
- +#include "delegation.h"
- +#include "from_kernel.h"
- +#include "daemon_debug.h"
- +#include "upcall.h"
- +#include "util.h"
- +#include "idmap.h"
- +
- +static int create_open_state(
- + IN const char *path,
- + IN uint32_t open_owner_id,
- OUT nfs41_open_state **state_out)
- {
- int status;
- @@ -293,38 +295,38 @@ static int parse_open(unsigned char *buffer, uint32_t length, nfs41_upcall *upca
- status = safe_read(&buffer, &length, &args->disposition, sizeof(ULONG));
- if (status) goto out;
- status = safe_read(&buffer, &length, &args->open_owner_id, sizeof(LONG));
- - if (status) goto out;
- - status = safe_read(&buffer, &length, &args->mode, sizeof(DWORD));
- - if (status) goto out;
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- - status = safe_read(&buffer, &length, &args->owner_local_uid, sizeof(DWORD));
- - if (status) goto out;
- - status = safe_read(&buffer, &length, &args->owner_group_local_gid, sizeof(DWORD));
- - if (status) goto out;
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- - status = safe_read(&buffer, &length, &args->srv_open, sizeof(HANDLE));
- - if (status) goto out;
- - status = parse_abs_path(&buffer, &length, &args->symlink);
- + if (status) goto out;
- + status = safe_read(&buffer, &length, &args->mode, sizeof(DWORD));
- + if (status) goto out;
- +#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- + status = safe_read(&buffer, &length, &args->owner_local_uid, sizeof(DWORD));
- + if (status) goto out;
- + status = safe_read(&buffer, &length, &args->owner_group_local_gid, sizeof(DWORD));
- + if (status) goto out;
- +#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- + status = safe_read(&buffer, &length, &args->srv_open, sizeof(HANDLE));
- + if (status) goto out;
- + status = parse_abs_path(&buffer, &length, &args->symlink);
- if (status) goto out;
- status = safe_read(&buffer, &length, &args->ea, sizeof(HANDLE));
- if (status) goto out;
- - dprintf(1, "parsing NFS41_OPEN: filename='%s' access mask=%d "
- - "access mode=%d\n\tfile attrs=0x%x create attrs=0x%x "
- - "(kernel) disposition=%d\n\topen_owner_id=%d mode=%o "
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- - "owner_local_uid=%u owner_group_local_gid=%u "
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- - "srv_open=%p symlink=%s ea=%p\n", args->path, args->access_mask,
- - args->access_mode, args->file_attrs, args->create_opts,
- - args->disposition, args->open_owner_id, args->mode,
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- - (unsigned int)args->owner_local_uid, (unsigned int)args->owner_group_local_gid,
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- - args->srv_open,
- - args->symlink.path, args->ea);
- - print_disposition(2, args->disposition);
- - print_access_mask(2, args->access_mask);
- + dprintf(1, "parsing NFS41_OPEN: filename='%s' access mask=%d "
- + "access mode=%d\n\tfile attrs=0x%x create attrs=0x%x "
- + "(kernel) disposition=%d\n\topen_owner_id=%d mode=%o "
- +#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- + "owner_local_uid=%u owner_group_local_gid=%u "
- +#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- + "srv_open=%p symlink=%s ea=%p\n", args->path, args->access_mask,
- + args->access_mode, args->file_attrs, args->create_opts,
- + args->disposition, args->open_owner_id, args->mode,
- +#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- + (unsigned int)args->owner_local_uid, (unsigned int)args->owner_group_local_gid,
- +#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- + args->srv_open,
- + args->symlink.path, args->ea);
- + print_disposition(2, args->disposition);
- + print_access_mask(2, args->access_mask);
- print_share_mode(2, args->access_mode);
- print_create_attributes(2, args->create_opts);
- out:
- @@ -491,9 +493,10 @@ static int create_with_ea(
- || (disposition == FILE_OPEN_IF && lookup_status == NFS4ERR_NOENT);
- }
- -static int handle_open(nfs41_upcall *upcall)
- +static int handle_open(void *daemon_context, nfs41_upcall *upcall)
- {
- int status = 0;
- + nfs41_daemon_globals *nfs41dg = daemon_context;
- open_upcall_args *args = &upcall->args.open;
- nfs41_open_state *state;
- nfs41_file_info info = { 0 };
- @@ -655,123 +658,92 @@ static int handle_open(nfs41_upcall *upcall)
- }
- nfs_to_basic_info(&info, &args->basic_info);
- - nfs_to_standard_info(&info, &args->std_info);
- - args->mode = info.mode;
- - args->changeattr = info.change;
- -
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- - bitmap4 og_attr_request = { 0 };
- - nfs41_file_info og_info = { 0 };
- - char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
- - nfsacl41 acl = { 0 };
- -
- - /*
- - * gisburn:
- - * 1. We should cache owner/group information
- - * 2. We should always ask for
- - * FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP with the other
- - * attributes
- - */
- - og_attr_request.count = 2;
- - og_attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
- - og_info.owner = owner;
- - og_info.owner_group = group;
- - status = nfs41_getattr(state->session, &state->file, &og_attr_request, &og_info);
- - if (status) {
- - eprintf("get_stat_data: nfs41_cached_getattr() failed with %d\n",
- - status);
- - }
- -
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_TESTMAPPING
- - /*
- - * Map owner to local uid
- - *
- - * |owner| can be numeric string ("1616"), plain username
- - * ("gisburn") or username@domain ("gisburn@sun.com")
- - */
- - /* stomp over '@' */
- - char *at_ch; /* pointer to '@' */
- - if (at_ch = strchr(og_info.owner, '@'))
- - *at_ch = '\0';
- -
- - if (isdigit(og_info.owner[0])) {
- - args->owner_local_uid = atol(og_info.owner);
- - }
- - else if(!strcmp(og_info.owner, "nobody")) {
- - args->owner_local_uid = 65534;
- - }
- - else if(!strcmp(og_info.owner, "root")) {
- - args->owner_local_uid = 0;
- - }
- - else if(!strcmp(og_info.owner, "rmainz")) {
- - args->owner_local_uid = 1616;
- - }
- - else if(!strcmp(og_info.owner, "roland_mainz")) {
- - args->owner_local_uid = 197608;
- - }
- - else if(!strcmp(og_info.owner, "swulsch")) {
- - args->owner_local_uid = 1818;
- - }
- - else if(!strcmp(og_info.owner, "iam")) {
- - args->owner_local_uid = 2010;
- - }
- - else if(!strcmp(og_info.owner, "mwenzel")) {
- - args->owner_local_uid = 8239;
- - }
- - else if(!strcmp(og_info.owner, "test001")) {
- - args->owner_local_uid = 1000;
- - }
- - else {
- - args->owner_local_uid = 666; /* debug: number of the beast */
- - }
- -
- - /*
- - * Map owner_group to local gid
- - *
- - * |owner_group| can be numeric string ("1616"), plain username
- - * ("gisgrp") or username@domain ("gisgrp@sun.com")
- - */
- - if (at_ch = strchr(og_info.owner_group, '@'))
- - *at_ch = '\0';
- - if (isdigit(og_info.owner_group[0])) {
- - args->owner_group_local_gid = atol(og_info.owner_group);
- - }
- - else if(!strcmp(og_info.owner_group, "nogroup")) {
- - args->owner_group_local_gid = 65534;
- - }
- - else if(!strcmp(og_info.owner_group, "root")) {
- - args->owner_group_local_gid = 0;
- - }
- - else if(!strcmp(og_info.owner_group, "Kein")) {
- - args->owner_group_local_gid = 197121;
- - }
- - else if(!strcmp(og_info.owner_group, "rmainz")) {
- - args->owner_group_local_gid = 1616;
- - }
- - else if(!strcmp(og_info.owner, "iam")) {
- - args->owner_group_local_gid = 2010;
- - }
- - else if(!strcmp(og_info.owner_group, "swulsch")) {
- - args->owner_group_local_gid = 1818;
- - }
- - else if(!strcmp(og_info.owner_group, "mwenzel")) {
- - args->owner_group_local_gid = 8239;
- - }
- - else if(!strcmp(og_info.owner_group, "test001")) {
- - args->owner_group_local_gid = 1000;
- - }
- - else {
- - args->owner_group_local_gid = 666; /* debug: number of the beast */
- - }
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_TESTMAPPING */
- -
- - dprintf(1, "handle_open: stat: owner=%u/'%s', owner_group=%u/'%s'\n",
- - (unsigned int)args->owner_local_uid, og_info.owner,
- - (unsigned int)args->owner_group_local_gid, og_info.owner_group);
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- - } else {
- - nfs41_file_info createattrs = { 0 };
- - uint32_t create = 0, createhowmode = 0, lookup_status = status;
- + nfs_to_standard_info(&info, &args->std_info);
- + args->mode = info.mode;
- + args->changeattr = info.change;
- +
- +#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- + bitmap4 og_attr_request = { 0 };
- + nfs41_file_info og_info = { 0 };
- + char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
- + nfsacl41 acl = { 0 };
- +
- + /*
- + * gisburn:
- + * 1. We should cache owner/group information
- + * 2. We should always ask for
- + * FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP with the other
- + * attributes
- + */
- + og_attr_request.count = 2;
- + og_attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
- + og_info.owner = owner;
- + og_info.owner_group = group;
- + status = nfs41_getattr(state->session, &state->file, &og_attr_request, &og_info);
- + if (status) {
- + eprintf("get_stat_data: nfs41_cached_getattr() failed with %d\n",
- + status);
- + }
- +
- + uid_t map_uid = -1;
- + gid_t gid_dummy = -1;
- + gid_t map_gid = -1;
- + char *at_ch; /* pointer to '@' */
- +
- + /*
- + * Map owner to local uid
- + *
- + * |owner| can be numeric string ("1616"), plain username
- + * ("gisburn") or username@domain ("gisburn@sun.com")
- + */
- + /* stomp over '@' */
- + if (at_ch = strchr(og_info.owner, '@'))
- + *at_ch = '\0';
- +
- + if (nfs41_idmap_name_to_ids(
- + nfs41dg->idmapper,
- + og_info.owner,
- + &map_uid,
- + &gid_dummy) == 0) {
- + args->owner_local_uid = map_uid;
- + }
- + else {
- + args->owner_local_uid = NFS_USER_NOBODY_UID;
- + eprintf("get_stat_data: "
- + "no username mapping for '%s', fake uid=%d\n",
- + og_info.owner, args->owner_local_uid);
- + }
- +
- + /*
- + * Map owner_group to local gid
- + *
- + * |owner_group| can be numeric string ("1616"), plain username
- + * ("gisgrp") or username@domain ("gisgrp@sun.com")
- + */
- + /* stomp over '@' */
- + if (at_ch = strchr(og_info.owner_group, '@'))
- + *at_ch = '\0';
- +
- + if (nfs41_idmap_group_to_gid(
- + nfs41dg->idmapper,
- + og_info.owner_group,
- + &map_gid) == 0) {
- + args->owner_group_local_gid = map_gid;
- + }
- + else {
- + args->owner_group_local_gid = NFS_GROUP_NOGROUP_GID;
- + eprintf("get_stat_data: "
- + "no group mapping for '%s', fake gid=%d\n",
- + og_info.owner_group, args->owner_group_local_gid);
- + }
- +
- + dprintf(1, "handle_open: stat: owner=%u/'%s', owner_group=%u/'%s'\n",
- + (unsigned int)args->owner_local_uid, og_info.owner,
- + (unsigned int)args->owner_group_local_gid, og_info.owner_group);
- +#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- + } else {
- + nfs41_file_info createattrs = { 0 };
- + uint32_t create = 0, createhowmode = 0, lookup_status = status;
- if (!lookup_status && (args->disposition == FILE_OVERWRITE ||
- args->disposition == FILE_OVERWRITE_IF ||
- @@ -875,18 +847,18 @@ static int marshall_open(unsigned char *buffer, uint32_t *length, nfs41_upcall *
- status = safe_write(&buffer, length, &args->std_info, sizeof(args->std_info));
- if (status) goto out;
- status = safe_write(&buffer, length, &upcall->state_ref, sizeof(HANDLE));
- - if (status) goto out;
- - status = safe_write(&buffer, length, &args->mode, sizeof(args->mode));
- - if (status) goto out;
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- - status = safe_write(&buffer, length, &args->owner_local_uid, sizeof(args->owner_local_uid));
- - if (status) goto out;
- - status = safe_write(&buffer, length, &args->owner_group_local_gid, sizeof(args->owner_group_local_gid));
- - if (status) goto out;
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- - status = safe_write(&buffer, length, &args->changeattr, sizeof(args->changeattr));
- - if (status) goto out;
- - status = safe_write(&buffer, length, &args->deleg_type, sizeof(args->deleg_type));
- + if (status) goto out;
- + status = safe_write(&buffer, length, &args->mode, sizeof(args->mode));
- + if (status) goto out;
- +#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- + status = safe_write(&buffer, length, &args->owner_local_uid, sizeof(args->owner_local_uid));
- + if (status) goto out;
- + status = safe_write(&buffer, length, &args->owner_group_local_gid, sizeof(args->owner_group_local_gid));
- + if (status) goto out;
- +#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- + status = safe_write(&buffer, length, &args->changeattr, sizeof(args->changeattr));
- + if (status) goto out;
- + status = safe_write(&buffer, length, &args->deleg_type, sizeof(args->deleg_type));
- if (status) goto out;
- if (upcall->last_error == ERROR_REPARSE) {
- unsigned short len = (args->symlink.len + 1) * sizeof(WCHAR);
- @@ -996,7 +968,7 @@ static int do_nfs41_close(nfs41_open_state *state)
- return status;
- }
- -static int handle_close(nfs41_upcall *upcall)
- +static int handle_close(void *deamon_context, nfs41_upcall *upcall)
- {
- int status = NFS4_OK, rm_status = NFS4_OK;
- close_upcall_args *args = &upcall->args.close;
- diff --git a/daemon/readdir.c b/daemon/readdir.c
- index 3742ffd..ab15539 100644
- --- a/daemon/readdir.c
- +++ b/daemon/readdir.c
- @@ -162,13 +162,13 @@ static void readdir_copy_shortname(
- OUT LPWSTR name_out,
- OUT CCHAR *name_size_out)
- {
- - /* GetShortPathName returns number of characters, not including \0 */
- - *name_size_out = (CCHAR)GetShortPathNameW(name, name_out, 12);
- - if (*name_size_out) {
- - (*name_size_out)++;
- - *name_size_out *= sizeof(WCHAR);
- - }
- -}
- + /* GetShortPathName returns number of characters, not including \0 */
- + *name_size_out = (CCHAR)GetShortPathNameW(name, name_out, 12);
- + if (*name_size_out) {
- + (*name_size_out)++;
- + *name_size_out *= sizeof(WCHAR);
- + }
- +}
- static void readdir_copy_full_dir_info(
- IN nfs41_readdir_entry *entry,
- @@ -448,7 +448,7 @@ out:
- return status;
- }
- -static int handle_readdir(nfs41_upcall *upcall)
- +static int handle_readdir(void *deamon_context, nfs41_upcall *upcall)
- {
- int status;
- readdir_upcall_args *args = &upcall->args.readdir;
- diff --git a/daemon/readwrite.c b/daemon/readwrite.c
- index 6a8f0c0..b35f9c0 100644
- --- a/daemon/readwrite.c
- +++ b/daemon/readwrite.c
- @@ -135,7 +135,7 @@ out:
- return status;
- }
- -static int handle_read(nfs41_upcall *upcall)
- +static int handle_read(void *daemon_context, nfs41_upcall *upcall)
- {
- readwrite_upcall_args *args = &upcall->args.rw;
- stateid_arg stateid;
- @@ -271,7 +271,7 @@ out:
- return status;
- }
- -static int handle_write(nfs41_upcall *upcall)
- +static int handle_write(void *daemon_context, nfs41_upcall *upcall)
- {
- readwrite_upcall_args *args = &upcall->args.rw;
- stateid_arg stateid;
- @@ -322,4 +322,4 @@ const nfs41_upcall_op nfs41_op_write = {
- parse_rw,
- handle_write,
- marshall_rw
- -};
- \ No newline at end of file
- +};
- diff --git a/daemon/setattr.c b/daemon/setattr.c
- index 23c2703..8cb8e3a 100644
- --- a/daemon/setattr.c
- +++ b/daemon/setattr.c
- @@ -55,7 +55,7 @@ out:
- return status;
- }
- -static int handle_nfs41_setattr(setattr_upcall_args *args)
- +static int handle_nfs41_setattr(void *daemon_context, setattr_upcall_args *args)
- {
- PFILE_BASIC_INFO basic_info = (PFILE_BASIC_INFO)args->buf;
- nfs41_open_state *state = args->state;
- @@ -149,7 +149,7 @@ out:
- return status;
- }
- -static int handle_nfs41_remove(setattr_upcall_args *args)
- +static int handle_nfs41_remove(void *daemon_context, setattr_upcall_args *args)
- {
- nfs41_open_state *state = args->state;
- int status;
- @@ -208,7 +208,7 @@ static int is_dst_name_opened(nfs41_abs_path *dst_path, nfs41_session *dst_sessi
- return status;
- }
- -static int handle_nfs41_rename(setattr_upcall_args *args)
- +static int handle_nfs41_rename(void *daemon_context, setattr_upcall_args *args)
- {
- nfs41_open_state *state = args->state;
- nfs41_session *dst_session;
- @@ -341,7 +341,7 @@ out:
- return status;
- }
- -static int handle_nfs41_set_size(setattr_upcall_args *args)
- +static int handle_nfs41_set_size(void *daemon_context, setattr_upcall_args *args)
- {
- nfs41_file_info info = { 0 };
- stateid_arg stateid;
- @@ -378,7 +378,7 @@ out:
- return status = nfs_to_windows_error(status, ERROR_NOT_SUPPORTED);
- }
- -static int handle_nfs41_link(setattr_upcall_args *args)
- +static int handle_nfs41_link(void *daemon_context, setattr_upcall_args *args)
- {
- nfs41_open_state *state = args->state;
- PFILE_LINK_INFORMATION link = (PFILE_LINK_INFORMATION)args->buf;
- @@ -480,30 +480,30 @@ out:
- return status;
- }
- -static int handle_setattr(nfs41_upcall *upcall)
- +static int handle_setattr(void *daemon_context, nfs41_upcall *upcall)
- {
- setattr_upcall_args *args = &upcall->args.setattr;
- int status;
- switch (args->set_class) {
- case FileBasicInformation:
- - status = handle_nfs41_setattr(args);
- + status = handle_nfs41_setattr(daemon_context, args);
- break;
- case FileDispositionInformation:
- - status = handle_nfs41_remove(args);
- + status = handle_nfs41_remove(daemon_context, args);
- break;
- case FileRenameInformation:
- - status = handle_nfs41_rename(args);
- + status = handle_nfs41_rename(daemon_context, args);
- break;
- case FileAllocationInformation:
- case FileEndOfFileInformation:
- - status = handle_nfs41_set_size(args);
- + status = handle_nfs41_set_size(daemon_context, args);
- break;
- case FileLinkInformation:
- - status = handle_nfs41_link(args);
- + status = handle_nfs41_link(daemon_context, args);
- break;
- default:
- - eprintf("unknown set_file information class %d\n",
- + eprintf("handle_setattr: unknown set_file information class %d\n",
- args->set_class);
- status = ERROR_NOT_SUPPORTED;
- break;
- diff --git a/daemon/symlink.c b/daemon/symlink.c
- index 9709e4f..f27d0a4 100644
- --- a/daemon/symlink.c
- +++ b/daemon/symlink.c
- @@ -208,7 +208,7 @@ out:
- return status;
- }
- -static int handle_symlink(nfs41_upcall *upcall)
- +static int handle_symlink(void *daemon_context, nfs41_upcall *upcall)
- {
- symlink_upcall_args *args = &upcall->args.symlink;
- nfs41_open_state *state = upcall->state_ref;
- diff --git a/daemon/upcall.c b/daemon/upcall.c
- index 16fa4a4..e2ead20 100644
- --- a/daemon/upcall.c
- +++ b/daemon/upcall.c
- @@ -133,6 +133,7 @@ out:
- }
- int upcall_handle(
- + IN void *daemon_context,
- IN nfs41_upcall *upcall)
- {
- int status = NO_ERROR;
- @@ -146,7 +147,7 @@ int upcall_handle(
- goto out;
- }
- - upcall->status = op->handle(upcall);
- + upcall->status = op->handle(daemon_context, upcall);
- out:
- return status;
- }
- diff --git a/daemon/upcall.h b/daemon/upcall.h
- index 8c72cbb..8340497 100644
- --- a/daemon/upcall.h
- +++ b/daemon/upcall.h
- @@ -20,13 +20,13 @@
- */
- #ifndef __NFS41_DAEMON_UPCALL_H__
- -#define __NFS41_DAEMON_UPCALL_H__
- -
- -#include "nfs41_ops.h"
- -#include "nfs41_build_features.h"
- -#include "from_kernel.h"
- -
- -#define NFSD_VERSION_MISMATCH 116
- +#define __NFS41_DAEMON_UPCALL_H__
- +
- +#include "nfs41_ops.h"
- +#include "nfs41_build_features.h"
- +#include "from_kernel.h"
- +
- +#define NFSD_VERSION_MISMATCH 116
- /* structures for upcall arguments */
- typedef struct __mount_upcall_args {
- @@ -48,16 +48,16 @@ typedef struct __open_upcall_args {
- ULONG access_mode;
- ULONG file_attrs;
- ULONG disposition;
- - ULONG create_opts;
- - LONG open_owner_id;
- - DWORD mode;
- -#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- - DWORD owner_local_uid; /* owner mapped into local uid */
- - DWORD owner_group_local_gid; /* owner group mapped into local gid */
- -#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- - ULONGLONG changeattr;
- - HANDLE srv_open;
- - DWORD deleg_type;
- + ULONG create_opts;
- + LONG open_owner_id;
- + DWORD mode;
- +#ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- + DWORD owner_local_uid; /* owner mapped into local uid */
- + DWORD owner_group_local_gid; /* owner group mapped into local gid */
- +#endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
- + ULONGLONG changeattr;
- + HANDLE srv_open;
- + DWORD deleg_type;
- PFILE_FULL_EA_INFORMATION ea;
- BOOLEAN created;
- BOOLEAN symlink_embedded;
- @@ -215,7 +215,7 @@ typedef struct __nfs41_upcall {
- /* upcall operation interface */
- typedef int (*upcall_parse_proc)(unsigned char*, uint32_t, nfs41_upcall*);
- -typedef int (*upcall_handle_proc)(nfs41_upcall*);
- +typedef int (*upcall_handle_proc)(void*, nfs41_upcall*);
- typedef int (*upcall_marshall_proc)(unsigned char*, uint32_t*, nfs41_upcall*);
- typedef void (*upcall_cancel_proc)(nfs41_upcall*);
- typedef void (*upcall_cleanup_proc)(nfs41_upcall*);
- @@ -236,6 +236,7 @@ int upcall_parse(
- OUT nfs41_upcall *upcall);
- int upcall_handle(
- + IN void *daemon_context,
- IN nfs41_upcall *upcall);
- void upcall_marshall(
- diff --git a/daemon/volume.c b/daemon/volume.c
- index 3c6381f..d23c68a 100644
- --- a/daemon/volume.c
- +++ b/daemon/volume.c
- @@ -112,7 +112,7 @@ out:
- return status;
- }
- -static int handle_volume(nfs41_upcall *upcall)
- +static int handle_volume(void *daemon_context, nfs41_upcall *upcall)
- {
- volume_upcall_args *args = &upcall->args.volume;
- int status = NO_ERROR;
- diff --git a/libtirpc/src/auth_unix.c b/libtirpc/src/auth_unix.c
- index ca8c908..8261b9e 100644
- --- a/libtirpc/src/auth_unix.c
- +++ b/libtirpc/src/auth_unix.c
- @@ -213,10 +213,13 @@ authunix_create_default()
- abort();
- #else
- // XXX Need to figure out what to do here!
- - uid = 666;
- - gid = 777;
- + uid = 10666;
- + gid = 10777;
- gids[0] = 0;
- len = 0;
- + (void)fprintf(stderr, "authunix_create_default(): fixme, "
- + "do not know what do to, returning fake uid=%d/gid=%d",
- + (int)uid, (int)gid);
- #endif
- /* XXX: interface problem; those should all have been unsigned */
- return (authunix_create(machname, uid, gid, len, gids));
- diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
- index f8ea548..93ee7a9 100644
- --- a/sys/nfs41_build_features.h
- +++ b/sys/nfs41_build_features.h
- @@ -33,7 +33,6 @@
- * NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES - return local uid/gid values
- */
- // #define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
- -// #define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_TESTMAPPING 1
- /*
- * NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID - give NFS
- @@ -42,4 +41,10 @@
- */
- // #define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
- +/*
- + * NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN - use Cygwin /usr/bin/getent
- + * as "name service"
- + */
- +// #define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
- +
- #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
- --
- 2.39.0
daemon/idmap: Add support for using Cygwin as idmapping service
Posted by Anonymous on Sat 14th Oct 2023 14:03
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.