diff options
author | David Zeuthen <davidz@redhat.com> | 2012-05-21 13:42:43 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2012-05-21 13:42:43 -0400 |
commit | 31c0ce425a03c59726b7c1a83aaf8cd8dfab79f7 (patch) | |
tree | a61d6b510f2289a6170da77d784c03cb1e6a6546 /src/polkitbackend/polkitbackendjsauthority.c | |
parent | 8e0c53ecf7129cd1be8bc9ac322aab4af992ce61 (diff) | |
download | polkit-31c0ce425a03c59726b7c1a83aaf8cd8dfab79f7.tar.gz |
Add netgroup support
Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'src/polkitbackend/polkitbackendjsauthority.c')
-rw-r--r-- | src/polkitbackend/polkitbackendjsauthority.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c index 8c1d189..7798d45 100644 --- a/src/polkitbackend/polkitbackendjsauthority.c +++ b/src/polkitbackend/polkitbackendjsauthority.c @@ -144,11 +144,13 @@ static JSClass js_polkit_class = { static JSBool js_polkit_log (JSContext *cx, uintN argc, jsval *vp); static JSBool js_polkit_spawn (JSContext *cx, uintN argc, jsval *vp); +static JSBool js_polkit_user_is_in_netgroup (JSContext *cx, uintN argc, jsval *vp); static JSFunctionSpec js_polkit_functions[] = { JS_FS("log", js_polkit_log, 0, 0), JS_FS("spawn", js_polkit_spawn, 0, 0), + JS_FS("_userIsInNetGroup", js_polkit_user_is_in_netgroup, 0, 0), JS_FS_END }; @@ -1225,3 +1227,42 @@ js_polkit_spawn (JSContext *cx, } /* ---------------------------------------------------------------------------------------------------- */ + + +static JSBool +js_polkit_user_is_in_netgroup (JSContext *cx, + uintN argc, + jsval *vp) +{ + /* PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); */ + JSBool ret = JS_FALSE; + JSString *user_str; + JSString *netgroup_str; + char *user; + char *netgroup; + JSBool is_in_netgroup = JS_FALSE; + + if (!JS_ConvertArguments (cx, argc, JS_ARGV (cx, vp), "SS", &user_str, &netgroup_str)) + goto out; + + user = JS_EncodeString (cx, user_str); + netgroup = JS_EncodeString (cx, netgroup_str); + + if (innetgr (netgroup, + NULL, /* host */ + user, + NULL)) /* domain */ + { + is_in_netgroup = JS_TRUE; + } + + JS_free (cx, netgroup); + JS_free (cx, user); + + ret = JS_TRUE; + + JS_SET_RVAL (cx, vp, BOOLEAN_TO_JSVAL (is_in_netgroup)); + out: + return ret; +} + |