From 646aefd998c1af366dcaee6cbc2bad9359a71f45 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 Feb 2011 18:45:32 +1100 Subject: [PATCH] pidl Add support for uid_t and gid_t types These are mapped to uint64_t, which should be big enough. This is proposed to be used for internal Samba representations, where it would be more painful to convert all the callers to an uint64_t calling convention. Andrew Bartlett --- librpc/ndr/libndr.h | 2 + librpc/ndr/ndr_basic.c | 60 ++++++++++++++++++++++++++++ pidl/lib/Parse/Pidl/NDR.pm | 2 + pidl/lib/Parse/Pidl/Samba4/Python.pm | 4 +- pidl/lib/Parse/Pidl/Typelist.pm | 2 + 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 21e4bdaeec..c9e8a6272e 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -490,6 +490,8 @@ NDR_SCALAR_PROTO(dlong, int64_t) NDR_SCALAR_PROTO(hyper, uint64_t) NDR_SCALAR_PROTO(pointer, void *) NDR_SCALAR_PROTO(time_t, time_t) +NDR_SCALAR_PROTO(uid_t, uid_t) +NDR_SCALAR_PROTO(gid_t, gid_t) NDR_SCALAR_PROTO(NTSTATUS, NTSTATUS) NDR_SCALAR_PROTO(WERROR, WERROR) NDR_SCALAR_PROTO(NTTIME, NTTIME) diff --git a/librpc/ndr/ndr_basic.c b/librpc/ndr/ndr_basic.c index d8e1cf0f00..7323f6d7a0 100644 --- a/librpc/ndr/ndr_basic.c +++ b/librpc/ndr/ndr_basic.c @@ -809,6 +809,56 @@ _PUBLIC_ enum ndr_err_code ndr_pull_time_t(struct ndr_pull *ndr, int ndr_flags, } +/* + push a uid_t +*/ +_PUBLIC_ enum ndr_err_code ndr_push_uid_t(struct ndr_push *ndr, int ndr_flags, uid_t u) +{ + return ndr_push_udlong(ndr, NDR_SCALARS, (uint64_t)u); +} + +/* + pull a uid_t +*/ +_PUBLIC_ enum ndr_err_code ndr_pull_uid_t(struct ndr_pull *ndr, int ndr_flags, uid_t *u) +{ + uint64_t uu; + NDR_CHECK(ndr_pull_udlong(ndr, ndr_flags, &uu)); + *u = (uid_t)uu; + if (unlikely(uu != *u)) { + DEBUG(0,(__location__ ": uid_t pull doesn't fit 0x%016llx\n", + (unsigned long long)uu)); + return NDR_ERR_NDR64; + } + return NDR_ERR_SUCCESS; +} + + +/* + push a gid_t +*/ +_PUBLIC_ enum ndr_err_code ndr_push_gid_t(struct ndr_push *ndr, int ndr_flags, gid_t g) +{ + return ndr_push_udlong(ndr, NDR_SCALARS, (uint64_t)g); +} + +/* + pull a gid_t +*/ +_PUBLIC_ enum ndr_err_code ndr_pull_gid_t(struct ndr_pull *ndr, int ndr_flags, gid_t *g) +{ + uint64_t gg; + NDR_CHECK(ndr_pull_udlong(ndr, ndr_flags, &gg)); + *g = (gid_t)gg; + if (unlikely(gg != *g)) { + DEBUG(0,(__location__ ": gid_t pull doesn't fit 0x%016llx\n", + (unsigned long long)gg)); + return NDR_ERR_NDR64; + } + return NDR_ERR_SUCCESS; +} + + /* pull a ipv4address */ @@ -1050,6 +1100,16 @@ _PUBLIC_ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t } } +_PUBLIC_ void ndr_print_uid_t(struct ndr_print *ndr, const char *name, uid_t u) +{ + ndr_print_dlong(ndr, name, u); +} + +_PUBLIC_ void ndr_print_gid_t(struct ndr_print *ndr, const char *name, gid_t g) +{ + ndr_print_dlong(ndr, name, g); +} + _PUBLIC_ void ndr_print_union(struct ndr_print *ndr, const char *name, int level, const char *type) { if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) { diff --git a/pidl/lib/Parse/Pidl/NDR.pm b/pidl/lib/Parse/Pidl/NDR.pm index 3edb9b732f..5ade5c175a 100644 --- a/pidl/lib/Parse/Pidl/NDR.pm +++ b/pidl/lib/Parse/Pidl/NDR.pm @@ -66,6 +66,8 @@ my $scalar_alignment = { 'string' => 4, 'string_array' => 4, #??? 'time_t' => 4, + 'uid_t' => 8, + 'gid_t' => 8, 'NTTIME' => 4, 'NTTIME_1sec' => 4, 'NTTIME_hyper' => 8, diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 7f6f94e748..dfacfb3352 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -895,7 +895,7 @@ sub ConvertObjectFromPythonData($$$$$$;$) $self->pidl("}"); return; } - if (expandAlias($actual_ctype->{NAME}) =~ /^(char|u?int[0-9]*|time_t)$/) { + if (expandAlias($actual_ctype->{NAME}) =~ /^(char|u?int[0-9]*|time_t|uid_t|gid_t)$/) { $self->pidl("PY_CHECK_TYPE(&PyInt_Type, $cvar, $fail);"); $self->pidl("$target = PyInt_AsLong($cvar);"); return; @@ -1103,7 +1103,7 @@ sub ConvertScalarToPython($$$) return "PyLong_FromLongLong($cvar)"; } - if ($ctypename =~ /^(char|u?int[0-9]*|time_t)$/) { + if ($ctypename =~ /^(char|u?int[0-9]*|time_t|uid_t|gid_t)$/) { return "PyInt_FromLong($cvar)"; } diff --git a/pidl/lib/Parse/Pidl/Typelist.pm b/pidl/lib/Parse/Pidl/Typelist.pm index a89b1a74eb..307187b4f4 100644 --- a/pidl/lib/Parse/Pidl/Typelist.pm +++ b/pidl/lib/Parse/Pidl/Typelist.pm @@ -48,6 +48,8 @@ my %scalars = ( "string" => "const char *", "string_array" => "const char **", "time_t" => "time_t", + "uid_t" => "uid_t", + "gid_t" => "gid_t", "NTTIME" => "NTTIME", "NTTIME_1sec" => "NTTIME", "NTTIME_hyper" => "NTTIME", -- 2.34.1