diff options
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/config.mk | 52 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsnet/config.mk | 13 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsnet/mpr_host.c | 74 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsnet/mpr_user.c | 173 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsnet/net_ctx.c | 230 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsnet/net_host.c | 124 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsnet/net_user.c | 359 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsrpc.c | 424 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsrpc.h | 172 | ||||
-rw-r--r-- | source4/scripting/ejs/literal.c | 797 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls.c | 4 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_cli.c | 722 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_data.c | 284 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_nbt.c | 93 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_nss.c | 160 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_param.c | 259 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_rand.c | 104 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_reg.c | 90 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_rpc.c | 385 | ||||
-rw-r--r-- | source4/scripting/ejs/smbscript.c | 2 |
20 files changed, 3 insertions, 4518 deletions
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index c1a1ca1f0f..34c0a9678e 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -1,7 +1,3 @@ -[SUBSYSTEM::EJSRPC] - -EJSRPC_OBJ_FILES = $(ejsscriptsrcdir)/ejsrpc.o - [MODULE::smbcalls_config] OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls @@ -17,43 +13,6 @@ PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR smbcalls_ldb_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_ldb.o -[MODULE::smbcalls_reg] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_reg -PRIVATE_DEPENDENCIES = registry SAMDB LIBNDR - -smbcalls_reg_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_reg.o - -[MODULE::smbcalls_nbt] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_nbt - -smbcalls_nbt_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_nbt.o - -[MODULE::smbcalls_rand] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_random - -smbcalls_rand_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_rand.o - -[MODULE::smbcalls_nss] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_nss -PRIVATE_DEPENDENCIES = NSS_WRAPPER - -smbcalls_nss_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_nss.o - -[MODULE::smbcalls_data] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_datablob - -smbcalls_data_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_data.o - [MODULE::smbcalls_auth] OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls @@ -78,26 +37,19 @@ INIT_FUNCTION = smb_setup_ejs_system smbcalls_sys_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_sys.o -mkinclude ejsnet/config.mk - [SUBSYSTEM::smbcalls] PRIVATE_DEPENDENCIES = \ EJS LIBSAMBA-UTIL \ - EJSRPC MESSAGING \ + MESSAGING \ LIBSAMBA-NET LIBCLI_SMB LIBPOPT \ CREDENTIALS POPT_CREDENTIALS POPT_SAMBA \ - dcerpc \ NDR_TABLE smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ - smbcalls_cli.o \ - smbcalls_rpc.o \ smbcalls_options.o \ smbcalls_creds.o \ - smbcalls_param.o \ - mprutil.o \ - literal.o) + mprutil.o) $(eval $(call proto_header_template,$(ejsscriptsrcdir)/proto.h,$(smbcalls_OBJ_FILES:.o=.c))) diff --git a/source4/scripting/ejs/ejsnet/config.mk b/source4/scripting/ejs/ejsnet/config.mk deleted file mode 100644 index 710221e37d..0000000000 --- a/source4/scripting/ejs/ejsnet/config.mk +++ /dev/null @@ -1,13 +0,0 @@ -[MODULE::smbcalls_net] -SUBSYSTEM = smbcalls -INIT_FUNCTION = smb_setup_ejs_net -PRIVATE_DEPENDENCIES = LIBSAMBA-NET LIBCLI_SMB CREDENTIALS - -smbcalls_net_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/ejsnet/, \ - net_ctx.o \ - net_user.o \ - mpr_user.o \ - net_host.o \ - mpr_host.o) - -$(eval $(call proto_header_template,$(ejsscriptsrcdir)/ejsnet/proto.h,$(smbcalls_net_OBJ_FILES:.o=.c))) diff --git a/source4/scripting/ejs/ejsnet/mpr_host.c b/source4/scripting/ejs/ejsnet/mpr_host.c deleted file mode 100644 index 8258ea5256..0000000000 --- a/source4/scripting/ejs/ejsnet/mpr_host.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -/* - Properties: - DomainsList.Domains[0] - DomainsList.Status -*/ -struct MprVar mprDomainsList(TALLOC_CTX *mem_ctx, struct libnet_DomainList *list, NTSTATUS result) -{ - const char *name = "DomainsList"; - NTSTATUS status; - struct MprVar mprDomainList, mprDomains; - struct MprVar mprSid, mprDomainName; - struct MprVar mprDomain; - int i; - - if (list == NULL || mem_ctx == NULL) { - mprDomainList = mprCreateNullVar(); - goto done; - } - - mprDomains = mprArray("Domains"); - for (i = 0; i < list->out.count; i++) { - struct domainlist d = list->out.domains[i]; - - /* get domainlist fields */ - mprSid = mprString(d.sid); - mprDomainName = mprString(d.name); - - mprDomain = mprObject("Domain"); - mprSetVar(&mprDomain, "Name", mprDomainName); - mprSetVar(&mprDomain, "SID", mprSid); - - mprAddArray(&mprDomains, i, mprDomain); - } - - mprDomainList = mprObject(name); - status = mprSetVar(&mprDomainList, "Domains", mprDomains); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprDomainList, "Count", mprCreateIntegerVar(list->out.count)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprDomainList, "Status", mprNTSTATUS(result)); - -done: - return mprDomainList; -} diff --git a/source4/scripting/ejs/ejsnet/mpr_user.c b/source4/scripting/ejs/ejsnet/mpr_user.c deleted file mode 100644 index 6691a0f955..0000000000 --- a/source4/scripting/ejs/ejsnet/mpr_user.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -/* - Properties: - UserInfo.AccountName - UserInfo.FullName - UserInfo.Description - UserInfo.HomeDirectory - UserInfo.HomeDrive - UserInfo.Comment - UserInfo.LogonScript - UserInfo.AcctExpiry - UserInfo.AllowPasswordChange - UserInfo.ForcePasswordChange - */ -struct MprVar mprCreateUserInfo(TALLOC_CTX *mem_ctx, struct libnet_UserInfo *info) -{ - const char *name = "UserInfo"; - NTSTATUS status; - struct MprVar mprUserInfo; - struct MprVar mprAccountName, mprFullName, mprDescription; - struct MprVar mprHomeDir, mprHomeDrive, mprComment; - struct MprVar mprLogonScript; - struct MprVar mprAcctExpiry, mprAllowPassChange, mprForcePassChange; - - if (info == NULL || mem_ctx == NULL) { - mprUserInfo = mprCreateNullVar(); - goto done; - } - - mprUserInfo = mprObject(name); - - mprAccountName = mprString(info->out.account_name); - mprFullName = mprString(info->out.full_name); - mprDescription = mprString(info->out.description); - mprHomeDir = mprString(info->out.home_directory); - mprHomeDrive = mprString(info->out.home_drive); - mprComment = mprString(info->out.comment); - mprLogonScript = mprString(info->out.logon_script); - mprAcctExpiry = mprString(timestring(mem_ctx, info->out.acct_expiry->tv_sec)); - mprAllowPassChange = mprString(timestring(mem_ctx, info->out.allow_password_change->tv_sec)); - mprForcePassChange = mprString(timestring(mem_ctx, info->out.force_password_change->tv_sec)); - - status = mprSetVar(&mprUserInfo, "AccountName", mprAccountName); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "FullName", mprFullName); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "Description", mprDescription); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "HomeDirectory", mprHomeDir); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "HomeDrive", mprHomeDrive); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "Comment", mprComment); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "LogonScript", mprLogonScript); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "AcctExpiry", mprAcctExpiry); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "AllowPasswordChange", mprAllowPassChange); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "ForcePasswordChange", mprForcePassChange); - if (!NT_STATUS_IS_OK(status)) goto done; - -done: - return mprUserInfo; -} - - -/* - Properties: - UserListCtx.Users[] - UserListCtx.ResumeIndex - UserListCtx.Count - UserListCtx.EndOfList - UserListCtx.Status - */ -struct MprVar mprUserListCtx(TALLOC_CTX *mem_ctx, struct libnet_UserList *list, NTSTATUS result) -{ - const char *name = "UserListCtx"; - NTSTATUS status; - bool endOfList; - struct MprVar mprListCtx, mprUserList; - struct MprVar mprUser, mprSid, mprUsername; - int i; - - if (list == NULL || mem_ctx == NULL) { - mprListCtx = mprCreateNullVar(); - goto done; - } - - endOfList = (NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) || - NT_STATUS_IS_OK(result)); - - mprUserList = mprArray("Users"); - for (i = 0; i < list->out.count; i++) { - struct userlist u = list->out.users[i]; - - /* get userlist fields */ - mprSid = mprString(u.sid); - mprUsername = mprString(u.username); - - /* create userlist object */ - mprUser = mprObject("User"); - mprSetVar(&mprUser, "Username", mprUsername); - mprSetVar(&mprUser, "SID", mprSid); - - /* add the object to the array being constructed */ - mprAddArray(&mprUserList, i, mprUser); - } - - mprListCtx = mprObject(name); - status = mprSetVar(&mprListCtx, "Users", mprUserList); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "Count", mprCreateIntegerVar(list->out.count)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "ResumeIndex", mprCreateIntegerVar((int)list->out.resume_index)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "EndOfList", mprCreateBoolVar(endOfList)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "Status", mprNTSTATUS(result)); - -done: - return mprListCtx; -} - - -/* - Returns UserListCtx.ResumeIndex out of passed UserListCtx - */ -unsigned int mprListGetResumeIndex(struct MprVar *listCtx) -{ - NTSTATUS status; - unsigned int resume = 0; - struct MprVar *mprResumeIndex; - if (listCtx == NULL) return 0; - - mprResumeIndex = listCtx; - status = mprGetVar(&mprResumeIndex, "ResumeIndex"); - if (!NT_STATUS_IS_OK(status)) goto done; - - resume = (unsigned int) mprVarToInteger(mprResumeIndex); - -done: - return resume; -} diff --git a/source4/scripting/ejs/ejsnet/net_ctx.c b/source4/scripting/ejs/ejsnet/net_ctx.c deleted file mode 100644 index cbe163552e..0000000000 --- a/source4/scripting/ejs/ejsnet/net_ctx.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "scripting/ejs/smbcalls.h" -#include "libnet/libnet.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar** argv); -int ejs_net_hostman(MprVarHandle eid, int argc, struct MprVar** argv); - -static int ejs_net_join_domain(MprVarHandle eid, int argc, struct MprVar **argv); -static int ejs_net_samsync_ldb(MprVarHandle eid, int argc, struct MprVar **argv); - -/* - Usage: - net = NetContext(credentials); -*/ - -static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *event_mem_ctx = talloc_new(mprMemCtx()); - struct cli_credentials *creds; - struct libnet_context *ctx; - struct MprVar obj, mprCreds; - struct event_context *ev; - - if (!event_mem_ctx) { - ejsSetErrorMsg(eid, "talloc_new() failed"); - return -1; - } - ev = mprEventCtx(); - - ctx = libnet_context_init(ev, mprLpCtx()); - /* IF we generated a new event context, it will be under here, - * and we need it to last as long as the libnet context, so - * make it a child */ - talloc_steal(ctx, event_mem_ctx); - - if (argc == 0 || (argc == 1 && argv[0]->type == MPR_TYPE_NULL)) { - /* - create the default credentials - */ - creds = cli_credentials_init(ctx); - if (creds == NULL) { - ejsSetErrorMsg(eid, "cli_credential_init() failed"); - talloc_free(ctx); - return -1; - } - cli_credentials_set_conf(creds, mprLpCtx()); - cli_credentials_set_anonymous(creds); - - mprCreds = mprCredentials(creds); - - } else if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) { - /* - get credential values from credentials object - */ - mprCreds = *(argv[0]); - creds = (struct cli_credentials *)mprGetPtr(&mprCreds, "creds"); - if (creds == NULL) { - ejsSetErrorMsg(eid, "invalid credentials parameter"); - talloc_free(ctx); - return -1; - } - - } else { - ejsSetErrorMsg(eid, "NetContext invalid arguments, this function requires an object."); - talloc_free(ctx); - return -1; - } - - /* setup libnet_context credentials */ - ctx->cred = creds; - - /* create the NetContext object */ - obj = mprObject("NetContext"); - - /* add internal libnet_context pointer to the NetContext object */ - mprSetPtrChild(&obj, "ctx", ctx); - - /* add properties publicly available from js code */ - mprCreateProperty(&obj, "credentials", &mprCreds); - - /* add methods to the object */ - mprSetCFunction(&obj, "UserMgr", ejs_net_userman); - mprSetCFunction(&obj, "HostMgr", ejs_net_hostman); - mprSetCFunction(&obj, "JoinDomain", ejs_net_join_domain); - mprSetCFunction(&obj, "SamSyncLdb", ejs_net_samsync_ldb); - - /* return the object */ - mpr_Return(eid, obj); - - return 0; -} - - -static int ejs_net_join_domain(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - struct libnet_Join *join; - NTSTATUS status; - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - mem_ctx = talloc_new(mprMemCtx()); - - join = talloc(mem_ctx, struct libnet_Join); - if (!join) { - talloc_free(mem_ctx); - return -1; - } - - /* prepare parameters for the join */ - join->in.netbios_name = NULL; - join->in.join_type = SEC_CHAN_WKSTA; - join->in.domain_name = cli_credentials_get_domain(ctx->cred); - join->in.level = LIBNET_JOIN_AUTOMATIC; - join->out.error_string = NULL; - - if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) { - MprVar *netbios_name = mprGetProperty(argv[0], "netbios_name", NULL); - MprVar *domain_name = mprGetProperty(argv[0], "domain_name", NULL); - MprVar *join_type = mprGetProperty(argv[0], "join_type", NULL); - if (netbios_name) { - join->in.netbios_name = mprToString(netbios_name); - } - if (domain_name) { - join->in.domain_name = mprToString(domain_name); - } - if (join_type) { - join->in.join_type = mprToInt(join_type); - } - } - - if (!join->in.domain_name) { - ejsSetErrorMsg(eid, "a domain must be specified for to join"); - talloc_free(mem_ctx); - return -1; - } - - /* do the domain join */ - status = libnet_Join(ctx, join, join); - - if (!NT_STATUS_IS_OK(status)) { - MprVar error_string = mprString(join->out.error_string); - - mprSetPropertyValue(argv[0], "error_string", error_string); - mpr_Return(eid, mprCreateBoolVar(false)); - } else { - mpr_Return(eid, mprCreateBoolVar(true)); - } - talloc_free(mem_ctx); - return 0; -} - - -static int ejs_net_samsync_ldb(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - struct libnet_samsync_ldb *samsync; - NTSTATUS status; - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - mem_ctx = talloc_new(mprMemCtx()); - - samsync = talloc(mem_ctx, struct libnet_samsync_ldb); - if (!samsync) { - talloc_free(mem_ctx); - return -1; - } - - /* prepare parameters for the samsync */ - samsync->in.machine_account = NULL; - samsync->in.session_info = NULL; - samsync->in.binding_string = NULL; - samsync->out.error_string = NULL; - - if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) { - MprVar *credentials = mprGetProperty(argv[0], "machine_account", NULL); - MprVar *session_info = mprGetProperty(argv[0], "session_info", NULL); - if (credentials) { - samsync->in.machine_account = talloc_get_type(mprGetPtr(credentials, "creds"), struct cli_credentials); - } - if (session_info) { - samsync->in.session_info = talloc_get_type(mprGetPtr(session_info, "session_info"), struct auth_session_info); - } - } - - /* do the domain samsync */ - status = libnet_samsync_ldb(ctx, samsync, samsync); - - if (!NT_STATUS_IS_OK(status)) { - MprVar error_string = mprString(samsync->out.error_string); - - mprSetPropertyValue(argv[0], "error_string", error_string); - mpr_Return(eid, mprCreateBoolVar(false)); - } else { - mpr_Return(eid, mprCreateBoolVar(true)); - } - talloc_free(mem_ctx); - return 0; -} - - -NTSTATUS smb_setup_ejs_net(void) -{ - ejsDefineCFunction(-1, "NetContext", ejs_net_context, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/ejsnet/net_host.c b/source4/scripting/ejs/ejsnet/net_host.c deleted file mode 100644 index 478da19db3..0000000000 --- a/source4/scripting/ejs/ejsnet/net_host.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/ejsnet/proto.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv); - - -/* - Usage: - hostCtx = net.HostMgr(hostname = <default from credentials>) -*/ -int ejs_net_hostman(MprVarHandle eid, int argc, struct MprVar** argv) -{ - struct libnet_context *ctx; - const char *hostname; - struct MprVar obj; - - /* libnet context */ - ctx = mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - return 0; - } - - /* fetch the arguments: host name */ - if (argc == 0) { - /* default host (machine) name is supplied in credentials */ - hostname = cli_credentials_get_workstation(ctx->cred); - - } else if (argc == 1 && mprVarIsString(argv[0]->type)) { - /* host name has been specified */ - hostname = mprToString(argv[0]); - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - return 0; - } - - /* create the NetHostCtx object */ - obj = mprObject("NetHostCtx"); - - /* create a copy of the string for the object */ - hostname = talloc_strdup(ctx, hostname); - - /* add internal libnet_context pointer to the NetHostCtx object */ - mprSetPtrChild(&obj, "ctx", ctx); - mprSetPtrChild(&obj, "hostname", hostname); - - /* add methods to the object */ - mprSetStringCFunction(&obj, "DomainList", ejs_net_domainlist); - - /* set the object returned by this function */ - mpr_Return(eid, obj); - - return 0; -} - - -static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status; - TALLOC_CTX *mem_ctx; - const char* hostname; - struct libnet_context *ctx; - struct libnet_DomainList req; - struct MprVar mprDomains; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* libnet context */ - ctx = mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - hostname = mprGetThisPtr(eid, "hostname"); - if (hostname == NULL) { - ejsSetErrorMsg(eid, "hostname property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.hostname = hostname; - - status = libnet_DomainList(ctx, mem_ctx, &req); - mprDomains = mprDomainsList(mem_ctx, &req, status); - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprDomains); - return 0; -} diff --git a/source4/scripting/ejs/ejsnet/net_user.c b/source4/scripting/ejs/ejsnet/net_user.c deleted file mode 100644 index 0c32035c6c..0000000000 --- a/source4/scripting/ejs/ejsnet/net_user.c +++ /dev/null @@ -1,359 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/ejsnet/proto.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv); -static int ejs_net_deleteuser(MprVarHandle eid, int argc, char **argv); -static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv); -static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv); - - -/* - Usage: - usrCtx = net.UserMgr(domain = <default from credentials>); -*/ -int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct libnet_context *ctx; - const char *userman_domain = NULL; - struct MprVar obj; - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - return 0; - } - - /* fetch the arguments: domain name */ - if (argc == 0) { - /* default domain name is supplied in credentials */ - userman_domain = cli_credentials_get_domain(ctx->cred); - - } else if (argc == 1 && mprVarIsString(argv[0]->type)) { - /* domain name can also be specified explicitly - (e.g. to connect BUILTIN domain) */ - userman_domain = mprToString(argv[0]); - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - return 0; - } - - /* any domain name must be specified anyway */ - if (userman_domain == NULL) { - ejsSetErrorMsg(eid, "a domain must be specified for user management"); - return 0; - } - - /* create 'net user' subcontext */ - obj = mprObject("NetUsrCtx"); - - /* we need to make a copy of the string for this object */ - userman_domain = talloc_strdup(ctx, userman_domain); - - /* add properties */ - mprSetPtrChild(&obj, "ctx", ctx); - mprSetPtrChild(&obj, "domain", userman_domain); - - /* add methods */ - mprSetStringCFunction(&obj, "Create", ejs_net_createuser); - mprSetStringCFunction(&obj, "Delete", ejs_net_deleteuser); - mprSetStringCFunction(&obj, "Info", ejs_net_userinfo); - mprSetCFunction(&obj, "List", ejs_net_userlist); - - /* set the object returned by this function */ - mpr_Return(eid, obj); - - return 0; -} - - -/* - Usage: - NTSTATUS = NetUsrCtx.Create(Username) -*/ -static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - const char *userman_domain = NULL; - const char *username = NULL; - struct libnet_CreateUser req; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments: username */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - username = argv[0]; - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where the account is to be created */ - userman_domain = (const char *)mprGetThisPtr(eid, "domain"); - if (userman_domain == NULL) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.domain_name = userman_domain; - req.in.user_name = argv[0]; - - status = libnet_CreateUser(ctx, mem_ctx, &req); - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "%s", req.out.error_string); - } - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - Usage: - NTSTATUS = NetUsrCtx.Delete(Username) -*/ -static int ejs_net_deleteuser(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - const char *userman_domain = NULL; - const char *username = NULL; - struct libnet_DeleteUser req; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments: username */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - username = argv[0]; - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where the account is to be deleted */ - userman_domain = mprGetThisPtr(eid, "domain"); - if (!userman_domain) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.domain_name = userman_domain; - req.in.user_name = username; - - status = libnet_DeleteUser(ctx, mem_ctx, &req); - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "%s", req.out.error_string); - } - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - Usage: - UserInfo = NetUsrCtx.Info(Username) -*/ -static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - const char *userman_domain = NULL; - const char *username = NULL; - struct libnet_UserInfo req; - struct MprVar mprUserInfo; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments: username */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - username = argv[0]; - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where the user account is to be queried */ - userman_domain = mprGetThisPtr(eid, "domain"); - if (userman_domain == NULL) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - return -1; - } - - /* call the libnet function */ - req.in.domain_name = userman_domain; - req.in.data.user_name = username; - req.in.level = USER_INFO_BY_NAME; - - status = libnet_UserInfo(ctx, mem_ctx, &req); - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "%s", req.out.error_string); - - /* create null object to return */ - mprUserInfo = mprCreateNullVar(); - goto done; - } - - /* create UserInfo object */ - mprUserInfo = mprCreateUserInfo(ctx, &req); - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprUserInfo); - return 0; -} - - -/* - Usage: - UserListCtx = NetUsrCtx.List(UserListCtx) -*/ -static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *mem_ctx; - NTSTATUS status; - struct libnet_context *ctx; - const char *userlist_domain; - int page_size = 512; /* TODO: this should be specified in a nicer way */ - struct libnet_UserList req; - struct MprVar mprListCtx, *mprInListCtx; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - if (mprVarIsObject(argv[0]->type)) { - /* this is a continuation call */ - mprInListCtx = argv[0]; - req.in.resume_index = mprListGetResumeIndex(mprInListCtx); - - } else { - /* this is a first call */ - req.in.resume_index = 0; - } - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where user accounts are to be enumerated */ - userlist_domain = mprGetThisPtr(eid, "domain"); - if (userlist_domain == NULL) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.domain_name = userlist_domain; - req.in.page_size = page_size; - - status = libnet_UserList(ctx, mem_ctx, &req); - mprListCtx = mprUserListCtx(mem_ctx, &req, status); - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprListCtx); - return 0; -} diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c deleted file mode 100644 index c7c02dbd64..0000000000 --- a/source4/scripting/ejs/ejsrpc.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide interfaces to rpc calls from ejs scripts - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "scripting/ejs/smbcalls.h" -#include "librpc/gen_ndr/lsa.h" -#include "librpc/gen_ndr/winreg.h" -#include "scripting/ejs/ejsrpc.h" -#include "libcli/security/security.h" - -/* - set the switch var to be used by the next union switch -*/ -void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var) -{ - ejs->switch_var = switch_var; -} - -/* - panic in the ejs wrapper code - */ -NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why) -{ - ejsSetErrorMsg(ejs->eid, "rpc_call '%s' failed - %s", ejs->callname, why); - return NT_STATUS_INTERNAL_ERROR; -} - -/* - start the ejs pull process for a structure -*/ -NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) -{ - return mprGetVar(v, name); -} - - -/* - start the ejs push process for a structure -*/ -NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) -{ - EJS_CHECK(mprSetVar(*v, name, mprObject(name))); - return mprGetVar(v, name); -} - -/* - pull a uint8 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint8_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint8_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint16 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint16_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint16_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint32_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint32_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a int32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int32_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int32_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, time_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const time_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToNumber(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return mprSetVar(v, name, mprCreateNumberVar(*r)); -} - -NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, (uint64_t *)r); -} - -NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int64_t *r) -{ - return ejs_push_hyper(ejs, v, name, (const uint64_t *)r); -} - -NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return ejs_push_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return ejs_push_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const WERROR *r) -{ - return ejs_push_string(ejs, v, name, win_errstr(*r)); -} - -NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const NTSTATUS *r) -{ - return ejs_push_string(ejs, v, name, nt_errstr(*r)); -} - - -/* - pull a enum from a mpr variable to a C element - a enum is just treating as an unsigned integer at this level -*/ -NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, unsigned *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const unsigned *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - - -/* - pull a string -*/ -NTSTATUS ejs_pull_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s) -{ - EJS_CHECK(mprGetVar(&v, name)); - *s = mprToString(v); - return NT_STATUS_OK; -} - -/* - push a string -*/ -NTSTATUS ejs_push_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s) -{ - return mprSetVar(v, name, mprString(s)); -} - - -/* - pull a ipv4address (internally a string) -*/ -NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s) -{ - return ejs_pull_string(ejs, v, name, s); -} - -/* - push a ipv4address (internally a string) -*/ -NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s) -{ - return ejs_push_string(ejs, v, name, s); -} - - -NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct dom_sid *r) -{ - struct dom_sid *sid; - EJS_CHECK(mprGetVar(&v, name)); - sid = dom_sid_parse_talloc(ejs, mprToString(v)); - NT_STATUS_HAVE_NO_MEMORY(sid); - *r = *sid; - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct dom_sid *r) -{ - char *sidstr = dom_sid_string(ejs, r); - NT_STATUS_HAVE_NO_MEMORY(sidstr); - return mprSetVar(v, name, mprString(sidstr)); -} - -NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct GUID *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - return GUID_from_string(mprToString(v), r); -} - -NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct GUID *r) -{ - char *guid = GUID_string(ejs, r); - NT_STATUS_HAVE_NO_MEMORY(guid); - return mprSetVar(v, name, mprString(guid)); -} - -NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name) -{ - return mprSetVar(v, name, mprCreatePtrVar(NULL)); -} - -bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name) -{ - NTSTATUS status = mprGetVar(&v, name); - if (!NT_STATUS_IS_OK(status)) { - return false; - } - if (v->type == MPR_TYPE_PTR && v->ptr == NULL) { - return true; - } - return false; -} - -/* - pull a lsa_String -*/ -NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct lsa_String *r) -{ - return ejs_pull_string(ejs, v, name, &r->string); -} - -/* - push a lsa_String -*/ -NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct lsa_String *r) -{ - return ejs_push_string(ejs, v, name, r->string); -} - -/* - pull a winreg_String -*/ -NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct winreg_String *r) -{ - return ejs_pull_string(ejs, v, name, &r->name); -} - -/* - push a winreg_String -*/ -NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct winreg_String *r) -{ - return ejs_push_string(ejs, v, name, r->name); -} - -NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, DATA_BLOB *r) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const DATA_BLOB *r) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, bool *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToBool(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const bool *r) -{ - return mprSetVar(v, name, mprCreateBoolVar(*r)); -} - - -/* - pull a uint8 array from a mpr variable to a C element - treating as a data blob -*/ -NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - uint8_t *r, uint32_t length) -{ - NTSTATUS status; - DATA_BLOB *blob; - - status = mprGetVar(&v, name); - NT_STATUS_NOT_OK_RETURN(status); - - blob = mprToDataBlob(v); - if (blob == NULL) { - return NT_STATUS_OBJECT_NAME_INVALID; - } - if (blob->length != length) { - return NT_STATUS_INFO_LENGTH_MISMATCH; - } - memcpy(r, blob->data, length); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const uint8_t *r, uint32_t length) -{ - DATA_BLOB blob; - blob.data = (uint8_t *)discard_const(r); - blob.length = length; - mprSetVar(v, name, mprDataBlob(blob)); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h deleted file mode 100644 index cc22a26700..0000000000 --- a/source4/scripting/ejs/ejsrpc.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - ejs <-> rpc interface definitions - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "librpc/gen_ndr/security.h" -#include "librpc/rpc/dcerpc.h" - -struct ejs_rpc { - int eid; - const char *callname; - /* as ejs does only one pass, we can use a single var for switch - handling */ - uint32_t switch_var; -}; - -typedef NTSTATUS (*ejs_pull_t)(struct ejs_rpc *, struct MprVar *, const char *, void *); -typedef NTSTATUS (*ejs_push_t)(struct ejs_rpc *, struct MprVar *, const char *, const void *); -typedef NTSTATUS (*ejs_pull_function_t)(struct ejs_rpc *, struct MprVar *, void *); -typedef NTSTATUS (*ejs_push_function_t)(struct ejs_rpc *, struct MprVar *, const void *); - -NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why); -void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var); - -NTSTATUS smbcalls_register_ejs(const char *name, MprCFunction fn); - - -int ejs_rpc_call(int eid, int argc, struct MprVar **argv, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push); - -NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name); -NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name); - -NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint8_t *r); -NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint8_t *r); -NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint16_t *r); -NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint16_t *r); -NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint32_t *r); -NTSTATUS ejs_push_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int32_t *r); -NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int32_t *r); -NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint32_t *r); -NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int64_t *r); -NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int64_t *r); -NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, time_t *r); -NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const time_t *r); -NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, unsigned *r); -NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const unsigned *r); -NTSTATUS ejs_pull_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s); -NTSTATUS ejs_push_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s); -NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s); -NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s); -void ejs_set_constant_int(int eid, const char *name, int value); -void ejs_set_constant_string(int eid, const char *name, const char *value); - -NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct dom_sid *r); -NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct dom_sid *r); -NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name); -bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name); -NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const WERROR *r); -NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const NTSTATUS *r); -NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, DATA_BLOB *r); -NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const DATA_BLOB *r); -NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, bool *r); -NTSTATUS ejs_push_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const bool *r); - -NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - uint8_t *r, uint32_t length); -NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const uint8_t *r, uint32_t length); - -NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct GUID *r); -NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct GUID *r); - -struct lsa_String; -NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct lsa_String *r); -NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct lsa_String *r); - -struct winreg_String; -NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct winreg_String *r); -NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct winreg_String *r); - -#define EJS_ALLOC(ejs, s) do { \ - (s) = talloc_ptrtype(ejs, (s)); \ - if (!(s)) return ejs_panic(ejs, "out of memory"); \ -} while (0) - -#define EJS_ALLOC_N(ejs, s, n) do { \ - (s) = talloc_array_ptrtype(ejs, (s), n); \ - if (!(s)) return ejs_panic(ejs, "out of memory"); \ -} while (0) - -#define EJS_CHECK(cmd) do { \ - NTSTATUS _status; \ - _status = cmd; \ - if (!NT_STATUS_IS_OK(_status)) { \ - return _status; \ - } \ -} while (0) - -/* some types are equivalent for ejs */ -#define ejs_pull_dom_sid2 ejs_pull_dom_sid -#define ejs_push_dom_sid2 ejs_push_dom_sid -#define ejs_pull_dom_sid28 ejs_pull_dom_sid -#define ejs_push_dom_sid28 ejs_push_dom_sid -#define ejs_pull_NTTIME_hyper ejs_pull_NTTIME -#define ejs_push_NTTIME_hyper ejs_push_NTTIME -#define ejs_pull_NTTIME_1sec ejs_pull_NTTIME -#define ejs_push_NTTIME_1sec ejs_push_NTTIME - diff --git a/source4/scripting/ejs/literal.c b/source4/scripting/ejs/literal.c deleted file mode 100644 index 8307c211d3..0000000000 --- a/source4/scripting/ejs/literal.c +++ /dev/null @@ -1,797 +0,0 @@ -/* - * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. - * Michael Clark <michael@metaparadigm.com> - * Copyright (c) 2006 Derrell Lipman - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See COPYING for details. - * - * Derrell Lipman: - * This version is modified from the original. It has been modified to - * natively use EJS variables rather than the original C object interface, and - * to use the talloc() family of functions for memory allocation. - */ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" - -enum json_tokener_error { - json_tokener_success, - json_tokener_error_oom, /* out of memory */ - json_tokener_error_parse_unexpected, - json_tokener_error_parse_null, - json_tokener_error_parse_date, - json_tokener_error_parse_boolean, - json_tokener_error_parse_number, - json_tokener_error_parse_array, - json_tokener_error_parse_object, - json_tokener_error_parse_string, - json_tokener_error_parse_comment, - json_tokener_error_parse_eof -}; - -enum json_tokener_state { - json_tokener_state_eatws, - json_tokener_state_start, - json_tokener_state_finish, - json_tokener_state_null, - json_tokener_state_date, - json_tokener_state_comment_start, - json_tokener_state_comment, - json_tokener_state_comment_eol, - json_tokener_state_comment_end, - json_tokener_state_string, - json_tokener_state_string_escape, - json_tokener_state_escape_unicode, - json_tokener_state_boolean, - json_tokener_state_number, - json_tokener_state_array, - json_tokener_state_datelist, - json_tokener_state_array_sep, - json_tokener_state_datelist_sep, - json_tokener_state_object, - json_tokener_state_object_field_start, - json_tokener_state_object_field, - json_tokener_state_object_field_end, - json_tokener_state_object_value, - json_tokener_state_object_sep -}; - -enum date_field { - date_field_year, - date_field_month, - date_field_day, - date_field_hour, - date_field_minute, - date_field_second, - date_field_millisecond -}; - -struct json_tokener -{ - char *source; - int pos; - void *ctx; - void *pb; -}; - -static const char *json_number_chars = "0123456789.+-e"; -static const char *json_hex_chars = "0123456789abcdef"; - -#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) - -extern struct MprVar json_tokener_parse(char *s); -static struct MprVar json_tokener_do_parse(struct json_tokener *this, - enum json_tokener_error *err_p); - -/* - * literal_to_var() parses a string into an ejs variable. The ejs - * variable is returned. Upon error, the javascript variable will be - * `undefined`. This was created for parsing JSON, but is generally useful - * for parsing the literal forms of objects and arrays, since ejs doesn't - * procide that functionality. - */ -int literal_to_var(int eid, int argc, char **argv) -{ - struct json_tokener tok; - struct MprVar obj; - enum json_tokener_error err = json_tokener_success; - - if (argc != 1) { - ejsSetErrorMsg(eid, - "literal_to_var() requires one parameter: " - "the string to be parsed."); - return -1; - } - - tok.source = argv[0]; - tok.pos = 0; - tok.ctx = talloc_new(mprMemCtx()); - if (tok.ctx == NULL) { - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; - } - tok.pb = talloc_zero_size(tok.ctx, 1); - if (tok.pb == NULL) { - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; - } - obj = json_tokener_do_parse(&tok, &err); - talloc_free(tok.pb); - if (err != json_tokener_success) { - mprDestroyVar(&obj); - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; - } - mpr_Return(eid, obj); - return 0; -} - -static void *append_string(void *ctx, - char *orig, - char *append, - int size) -{ - if (!orig) { - return talloc_strndup(ctx, append, size); - } - - return talloc_strndup_append(orig, append, size); -} - - -static struct MprVar json_tokener_do_parse(struct json_tokener *this, - enum json_tokener_error *err_p) -{ - enum json_tokener_state state; - enum json_tokener_state saved_state; - enum date_field date_field; - struct MprVar current = mprCreateUndefinedVar(); - struct MprVar tempObj; - struct MprVar obj; - enum json_tokener_error err = json_tokener_success; - char date_script[] = "JSON_Date.create(0);"; - char *obj_field_name = NULL; - char *emsg = NULL; - char quote_char; - int deemed_double; - int start_offset; - char c; - - state = json_tokener_state_eatws; - saved_state = json_tokener_state_start; - - - do { - c = this->source[this->pos]; - switch(state) { - - case json_tokener_state_eatws: - if(isspace(c)) { - this->pos++; - } else if(c == '/') { - state = json_tokener_state_comment_start; - start_offset = this->pos++; - } else { - state = saved_state; - } - break; - - case json_tokener_state_start: - switch(c) { - case '{': - state = json_tokener_state_eatws; - saved_state = json_tokener_state_object; - current = mprObject(NULL); - this->pos++; - break; - case '[': - state = json_tokener_state_eatws; - saved_state = json_tokener_state_array; - current = mprArray(NULL); - this->pos++; - break; - case 'N': - case 'n': - start_offset = this->pos++; - if (this->source[this->pos] == 'e') { - state = json_tokener_state_date; - } else { - state = json_tokener_state_null; - } - break; - case '"': - case '\'': - quote_char = c; - talloc_free(this->pb); - this->pb = talloc_zero_size(this->ctx, 1); - if (this->pb == NULL) { - *err_p = json_tokener_error_oom; - goto out; - } - state = json_tokener_state_string; - start_offset = ++this->pos; - break; - case 'T': - case 't': - case 'F': - case 'f': - state = json_tokener_state_boolean; - start_offset = this->pos++; - break; -#if defined(__GNUC__) - case '0' ... '9': -#else - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': -#endif - case '-': - deemed_double = 0; - state = json_tokener_state_number; - start_offset = this->pos++; - break; - default: - err = json_tokener_error_parse_unexpected; - goto out; - } - break; - - case json_tokener_state_finish: - goto out; - - case json_tokener_state_null: - if(strncasecmp("null", - this->source + start_offset, - this->pos - start_offset)) { - *err_p = json_tokener_error_parse_null; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - - if(this->pos - start_offset == 4) { - mprDestroyVar(¤t); - current = mprCreateNullVar(); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - this->pos++; - } - break; - - case json_tokener_state_date: - if (this->pos - start_offset <= 18) { - if (strncasecmp("new Date(Date.UTC(", - this->source + start_offset, - this->pos - start_offset)) { - *err_p = json_tokener_error_parse_date; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } else { - this->pos++; - break; - } - } - - this->pos--; /* we went one too far */ - state = json_tokener_state_eatws; - saved_state = json_tokener_state_datelist; - - /* Create a JsonDate object */ - if (ejsEvalScript(0, - date_script, - &tempObj, - &emsg) != 0) { - *err_p = json_tokener_error_parse_date; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - mprDestroyVar(¤t); - mprCopyVar(¤t, &tempObj, MPR_DEEP_COPY); - date_field = date_field_year; - break; - - case json_tokener_state_comment_start: - if(c == '*') { - state = json_tokener_state_comment; - } else if(c == '/') { - state = json_tokener_state_comment_eol; - } else { - err = json_tokener_error_parse_comment; - goto out; - } - this->pos++; - break; - - case json_tokener_state_comment: - if(c == '*') state = json_tokener_state_comment_end; - this->pos++; - break; - - case json_tokener_state_comment_eol: - if(c == '\n') { - state = json_tokener_state_eatws; - } - this->pos++; - break; - - case json_tokener_state_comment_end: - if(c == '/') { - state = json_tokener_state_eatws; - } else { - state = json_tokener_state_comment; - } - this->pos++; - break; - - case json_tokener_state_string: - if(c == quote_char) { - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - current = mprString(this->pb); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == '\\') { - saved_state = json_tokener_state_string; - state = json_tokener_state_string_escape; - } - this->pos++; - break; - - case json_tokener_state_string_escape: - switch(c) { - case '"': - case '\\': - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - start_offset = this->pos++; - state = saved_state; - break; - case 'b': - case 'n': - case 'r': - case 't': - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - if (c == 'b') { - /* - * second param to append_string() - * gets temporarily modified; can't - * pass string constant. - */ - char buf[] = "\b"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (c == 'n') { - char buf[] = "\n"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (c == 'r') { - char buf[] = "\r"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (c == 't') { - char buf[] = "\t"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } - start_offset = ++this->pos; - state = saved_state; - break; - case 'u': - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - start_offset = ++this->pos; - state = json_tokener_state_escape_unicode; - break; - default: - err = json_tokener_error_parse_string; - goto out; - } - break; - - case json_tokener_state_escape_unicode: - if(strchr(json_hex_chars, c)) { - this->pos++; - if(this->pos - start_offset == 4) { - unsigned char utf_out[3]; - unsigned int ucs_char = - (hexdigit(*(this->source + start_offset)) << 12) + - (hexdigit(*(this->source + start_offset + 1)) << 8) + - (hexdigit(*(this->source + start_offset + 2)) << 4) + - hexdigit(*(this->source + start_offset + 3)); - if (ucs_char < 0x80) { - utf_out[0] = ucs_char; - this->pb = append_string( - this->ctx, - this->pb, - (char *) utf_out, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (ucs_char < 0x800) { - utf_out[0] = 0xc0 | (ucs_char >> 6); - utf_out[1] = 0x80 | (ucs_char & 0x3f); - this->pb = append_string( - this->ctx, - this->pb, - (char *) utf_out, - 2); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else { - utf_out[0] = 0xe0 | (ucs_char >> 12); - utf_out[1] = 0x80 | ((ucs_char >> 6) & 0x3f); - utf_out[2] = 0x80 | (ucs_char & 0x3f); - this->pb = append_string( - this->ctx, - this->pb, - (char *) utf_out, - 3); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } - start_offset = this->pos; - state = saved_state; - } - } else { - err = json_tokener_error_parse_string; - goto out; - } - break; - - case json_tokener_state_boolean: - if(strncasecmp("true", this->source + start_offset, - this->pos - start_offset) == 0) { - if(this->pos - start_offset == 4) { - current = mprCreateBoolVar(1); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - this->pos++; - } - } else if(strncasecmp("false", this->source + start_offset, - this->pos - start_offset) == 0) { - if(this->pos - start_offset == 5) { - current = mprCreateBoolVar(0); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - this->pos++; - } - } else { - err = json_tokener_error_parse_boolean; - goto out; - } - break; - - case json_tokener_state_number: - if(!c || !strchr(json_number_chars, c)) { - int numi; - double numd; - char *tmp = talloc_strndup( - this->ctx, - this->source + start_offset, - this->pos - start_offset); - if (tmp == NULL) { - err = json_tokener_error_oom; - goto out; - } - if(!deemed_double && sscanf(tmp, "%d", &numi) == 1) { - current = mprCreateIntegerVar(numi); - } else if(deemed_double && sscanf(tmp, "%lf", &numd) == 1) { - current = mprCreateFloatVar(numd); - } else { - talloc_free(tmp); - err = json_tokener_error_parse_number; - goto out; - } - talloc_free(tmp); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - if(c == '.' || c == 'e') deemed_double = 1; - this->pos++; - } - break; - - case json_tokener_state_array: - if(c == ']') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - int oldlen; - char idx[16]; - - obj = json_tokener_do_parse(this, &err); - if (err != json_tokener_success) { - goto out; - } - oldlen = mprToInt(mprGetProperty(¤t, - "length", - NULL)); - mprItoa(oldlen, idx, sizeof(idx)); - mprSetVar(¤t, idx, obj); - saved_state = json_tokener_state_array_sep; - state = json_tokener_state_eatws; - } - break; - - case json_tokener_state_datelist: - if(c == ')') { - if (this->source[this->pos+1] == ')') { - this->pos += 2; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - err = json_tokener_error_parse_date; - goto out; - } - } else { - obj = json_tokener_do_parse(this, &err); - if (err != json_tokener_success) { - goto out; - } - - /* date list items must be integers */ - if (obj.type != MPR_TYPE_INT) { - err = json_tokener_error_parse_date; - goto out; - } - - switch(date_field) { - case date_field_year: - mprSetVar(¤t, "year", obj); - break; - case date_field_month: - mprSetVar(¤t, "month", obj); - break; - case date_field_day: - mprSetVar(¤t, "day", obj); - break; - case date_field_hour: - mprSetVar(¤t, "hour", obj); - break; - case date_field_minute: - mprSetVar(¤t, "minute", obj); - break; - case date_field_second: - mprSetVar(¤t, "second", obj); - break; - case date_field_millisecond: - mprSetVar(¤t, "millisecond", obj); - break; - default: - err = json_tokener_error_parse_date; - goto out; - } - - /* advance to the next date field */ - date_field++; - - saved_state = json_tokener_state_datelist_sep; - state = json_tokener_state_eatws; - } - break; - - case json_tokener_state_array_sep: - if(c == ']') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == ',') { - this->pos++; - saved_state = json_tokener_state_array; - state = json_tokener_state_eatws; - } else { - *err_p = json_tokener_error_parse_array; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - break; - - case json_tokener_state_datelist_sep: - if(c == ')') { - if (this->source[this->pos+1] == ')') { - this->pos += 2; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - err = json_tokener_error_parse_date; - goto out; - } - } else if(c == ',') { - this->pos++; - saved_state = json_tokener_state_datelist; - state = json_tokener_state_eatws; - } else { - *err_p = json_tokener_error_parse_date; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - break; - - case json_tokener_state_object: - state = json_tokener_state_object_field_start; - start_offset = this->pos; - break; - - case json_tokener_state_object_field_start: - if(c == '}') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if (c == '"' || c == '\'') { - quote_char = c; - talloc_free(this->pb); - this->pb = talloc_zero_size(this->ctx, 1); - if (this->pb == NULL) { - *err_p = json_tokener_error_oom; - goto out; - } - state = json_tokener_state_object_field; - start_offset = ++this->pos; - } else { - err = json_tokener_error_parse_object; - goto out; - } - break; - - case json_tokener_state_object_field: - if(c == quote_char) { - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - obj_field_name = talloc_strdup(this->ctx, - this->pb); - if (obj_field_name == NULL) { - err = json_tokener_error_oom; - goto out; - } - saved_state = json_tokener_state_object_field_end; - state = json_tokener_state_eatws; - } else if(c == '\\') { - saved_state = json_tokener_state_object_field; - state = json_tokener_state_string_escape; - } - this->pos++; - break; - - case json_tokener_state_object_field_end: - if(c == ':') { - this->pos++; - saved_state = json_tokener_state_object_value; - state = json_tokener_state_eatws; - } else { - *err_p = json_tokener_error_parse_object; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - break; - - case json_tokener_state_object_value: - obj = json_tokener_do_parse(this, &err); - if (err != json_tokener_success) { - goto out; - } - mprSetVar(¤t, obj_field_name, obj); - talloc_free(obj_field_name); - obj_field_name = NULL; - saved_state = json_tokener_state_object_sep; - state = json_tokener_state_eatws; - break; - - case json_tokener_state_object_sep: - if(c == '}') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == ',') { - this->pos++; - saved_state = json_tokener_state_object; - state = json_tokener_state_eatws; - } else { - err = json_tokener_error_parse_object; - goto out; - } - break; - - } - } while(c); - - if(state != json_tokener_state_finish && - saved_state != json_tokener_state_finish) - err = json_tokener_error_parse_eof; - -out: - talloc_free(obj_field_name); - if(err == json_tokener_success) { - return current; - } else { - mprDestroyVar(¤t); - *err_p = err; - return mprCreateUndefinedVar(); - } -} - - -void smb_setup_ejs_literal(void) -{ - ejsDefineStringCFunction(-1, - "literal_to_var", - literal_to_var, - NULL, - MPR_VAR_SCRIPT_HANDLE); -} diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index 98d6be07bf..4314b51455 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -191,7 +191,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) extern NTSTATUS smb_setup_ejs_system(void); extern NTSTATUS smb_setup_ejs_ldb(void); extern NTSTATUS ejs_init_svcctl(void); - extern NTSTATUS smb_setup_ejs_nbt(void); extern NTSTATUS smb_setup_ejs_net(void); extern NTSTATUS ejs_init_srvsvc(void); extern NTSTATUS ejs_init_netlogon(void); @@ -203,11 +202,8 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) ejs_exception_handler = exception_handler; - smb_setup_ejs_cli(); smb_setup_ejs_options(); smb_setup_ejs_credentials(); - smb_setup_ejs_param(); - smb_setup_ejs_literal(); shared_init = load_samba_modules(NULL, mprLpCtx(), "smbcalls"); diff --git a/source4/scripting/ejs/smbcalls_cli.c b/source4/scripting/ejs/smbcalls_cli.c deleted file mode 100644 index dbb36312da..0000000000 --- a/source4/scripting/ejs/smbcalls_cli.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Tim Potter 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "libcli/raw/libcliraw.h" -#include "libcli/composite/composite.h" -#include "libcli/smb_composite/smb_composite.h" -#include "libcli/libcli.h" -#include "libcli/resolve/resolve.h" -#include "auth/credentials/credentials.h" -#include "param/param.h" - -#if 0 - -#include "librpc/gen_ndr/ndr_nbt.h" - -/* Connect to a server */ - -static int ejs_cli_connect(MprVarHandle eid, int argc, char **argv) -{ - struct smbcli_socket *sock; - struct smbcli_transport *transport; - struct nbt_name calling, called; - NTSTATUS result; - - if (argc != 1) { - ejsSetErrorMsg(eid, "connect invalid arguments"); - return -1; - } - - /* Socket connect */ - - sock = smbcli_sock_init(NULL, NULL); - - if (!sock) { - ejsSetErrorMsg(eid, "socket initialisation failed"); - return -1; - } - - if (!smbcli_sock_connect_byname(sock, argv[0], 0)) { - ejsSetErrorMsg(eid, "socket connect failed"); - return -1; - } - - transport = smbcli_transport_init(sock, sock, false); - - if (!transport) { - ejsSetErrorMsg(eid, "transport init failed"); - return -1; - } - - /* Send a netbios session request */ - - make_nbt_name_client(&calling, lp_netbios_name()); - - nbt_choose_called_name(NULL, &called, argv[0], NBT_NAME_SERVER); - - if (!smbcli_transport_connect(transport, &calling, &called)) { - ejsSetErrorMsg(eid, "transport establishment failed"); - return -1; - } - - result = smb_raw_negotiate(transport, lp_maxprotocol()); - - if (!NT_STATUS_IS_OK(result)) { - mpr_Return(eid, mprNTSTATUS(result)); - return 0; - } - - /* Return a socket object */ - - mpr_Return(eid, mprCreatePtrVar(transport)); - - return 0; -} - -/* Perform a session setup: - - session_setup(conn, "DOMAIN\\USERNAME%PASSWORD"); - session_setup(conn, USERNAME, PASSWORD); - session_setup(conn, DOMAIN, USERNAME, PASSWORD); - session_setup(conn); // anonymous - - */ - -static int ejs_cli_ssetup(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_transport *transport; - struct smbcli_session *session; - struct smb_composite_sesssetup setup; - struct cli_credentials *creds; - NTSTATUS status; - int result = -1; - - /* Argument parsing */ - - if (argc < 1 || argc > 4) { - ejsSetErrorMsg(eid, "session_setup invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a connect handle"); - return -1; - } - - transport = argv[0]->ptr; - creds = cli_credentials_init(transport); - cli_credentials_set_conf(creds); - - if (argc == 4) { - - /* DOMAIN, USERNAME, PASSWORD form */ - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 1 must be a string"); - goto done; - } - - cli_credentials_set_domain(creds, argv[1]->string, - CRED_SPECIFIED); - - if (!mprVarIsString(argv[2]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - goto done; - } - - cli_credentials_set_username(creds, argv[2]->string, - CRED_SPECIFIED); - - if (!mprVarIsString(argv[3]->type)) { - ejsSetErrorMsg(eid, "arg 3 must be a string"); - goto done; - } - - cli_credentials_set_password(creds, argv[3]->string, - CRED_SPECIFIED); - - } else if (argc == 3) { - - /* USERNAME, PASSWORD form */ - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg1 must be a string"); - goto done; - } - - cli_credentials_set_username(creds, argv[1]->string, - CRED_SPECIFIED); - - if (!mprVarIsString(argv[2]->type)) { - - ejsSetErrorMsg(eid, "arg2 must be a string"); - goto done; - } - - cli_credentials_set_password(creds, argv[2]->string, - CRED_SPECIFIED); - - } else if (argc == 2) { - - /* DOMAIN/USERNAME%PASSWORD form */ - - cli_credentials_parse_string(creds, argv[1]->string, - CRED_SPECIFIED); - - } else { - - /* Anonymous connection */ - - cli_credentials_set_anonymous(creds); - } - - /* Do session setup */ - - session = smbcli_session_init(transport, transport, false); - - if (!session) { - ejsSetErrorMsg(eid, "session init failed"); - return -1; - } - - setup.in.sesskey = transport->negotiate.sesskey; - setup.in.capabilities = transport->negotiate.capabilities; - setup.in.credentials = creds; - setup.in.workgroup = lp_workgroup(); - - status = smb_composite_sesssetup(session, &setup); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "session_setup: %s", nt_errstr(status)); - return -1; - } - - session->vuid = setup.out.vuid; - - /* Return a session object */ - - mpr_Return(eid, mprCreatePtrVar(session)); - - result = 0; - - done: - talloc_free(creds); - return result; -} - -/* Perform a tree connect - - tree_connect(session, SHARE); - - */ - -static int ejs_cli_tree_connect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_session *session; - struct smbcli_tree *tree; - union smb_tcon tcon; - TALLOC_CTX *mem_ctx; - NTSTATUS status; - const char *password = ""; - - /* Argument parsing */ - - if (argc != 2) { - ejsSetErrorMsg(eid, "tree_connect invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a session handle"); - return -1; - } - - session = argv[0]->ptr; - tree = smbcli_tree_init(session, session, false); - - if (!tree) { - ejsSetErrorMsg(eid, "tree init failed"); - return -1; - } - - mem_ctx = talloc_init("tcon"); - if (!mem_ctx) { - ejsSetErrorMsg(eid, "talloc_init failed"); - return -1; - } - - /* Do tree connect */ - - tcon.generic.level = RAW_TCON_TCONX; - tcon.tconx.in.flags = 0; - - if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL) { - tcon.tconx.in.password = data_blob(NULL, 0); - } else if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { - tcon.tconx.in.password = data_blob_talloc(mem_ctx, NULL, 24); - if (session->transport->negotiate.secblob.length < 8) { - ejsSetErrorMsg(eid, "invalid security blob"); - return -1; - } - SMBencrypt(password, session->transport->negotiate.secblob.data, tcon.tconx.in.password.data); - } else { - tcon.tconx.in.password = data_blob_talloc(mem_ctx, password, strlen(password)+1); - } - - tcon.tconx.in.path = argv[1]->string; - tcon.tconx.in.device = "?????"; - - status = smb_tree_connect(tree, mem_ctx, &tcon); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "tree_connect: %s", nt_errstr(status)); - return -1; - } - - tree->tid = tcon.tconx.out.tid; - - talloc_free(mem_ctx); - - mpr_Return(eid, mprCreatePtrVar(tree)); - - return 0; -} - -/* Perform a tree disconnect - - tree_disconnect(tree); - - */ -static int ejs_cli_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS status; - - /* Argument parsing */ - - if (argc != 1) { - ejsSetErrorMsg(eid, "tree_disconnect invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = argv[0]->ptr; - - status = smb_tree_disconnect(tree); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "tree_disconnect: %s", nt_errstr(status)); - return -1; - } - - talloc_free(tree); - - return 0; -} - -/* Perform a ulogoff - - session_logoff(session); - - */ -static int ejs_cli_session_logoff(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_session *session; - NTSTATUS status; - - /* Argument parsing */ - - if (argc != 1) { - ejsSetErrorMsg(eid, "session_logoff invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a session handle"); - return -1; - } - - session = argv[0]->ptr; - - status = smb_raw_ulogoff(session); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "session_logoff: %s", nt_errstr(status)); - return -1; - } - - talloc_free(session); - - return 0; -} - -/* Perform a connection close - - disconnect(conn); - - */ -static int ejs_cli_disconnect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_sock *sock; - - /* Argument parsing */ - - if (argc != 1) { - ejsSetErrorMsg(eid, "disconnect invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a connect handle"); - return -1; - } - - sock = argv[0]->ptr; - - talloc_free(sock); - - return 0; -} - -#endif - -/* Perform a tree connect: - - tree_handle = tree_connect("\\\\frogurt\\homes", "user%pass"); - */ - -static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds; - struct smb_composite_connect io; - struct smbcli_tree *tree; - char *hostname, *sharename; - NTSTATUS result; - TALLOC_CTX *mem_ctx; - - if (argc != 2) { - ejsSetErrorMsg(eid, "tree_connect(): invalid number of args"); - return -1; - } - - /* Set up host, share destination */ - - mem_ctx = talloc_new(mprMemCtx()); - smbcli_parse_unc(argv[0], mem_ctx, &hostname, &sharename); - - /* Set up credentials */ - - creds = cli_credentials_init(NULL); - cli_credentials_set_conf(creds, mprLpCtx()); - cli_credentials_parse_string(creds, argv[1], CRED_SPECIFIED); - - /* Do connect */ - - io.in.dest_host = hostname; - io.in.dest_ports = lp_smb_ports(mprLpCtx()); - io.in.called_name = strupper_talloc(mem_ctx, hostname); - io.in.service = sharename; - io.in.service_type = "?????"; - io.in.credentials = creds; - io.in.fallback_to_anonymous = false; - io.in.workgroup = lp_workgroup(mprLpCtx()); - lp_smbcli_options(mprLpCtx(), &io.in.options); - - result = smb_composite_connect(&io, mem_ctx, - lp_resolve_context(mprLpCtx()), - NULL); - tree = io.out.tree; - - talloc_free(mem_ctx); - - if (!NT_STATUS_IS_OK(result)) { - mpr_Return(eid, mprNTSTATUS(result)); - return 0; - } - - mpr_Return(eid, mprCreatePtrVar(tree)); - - return 0; -} - -#define IS_TREE_HANDLE(x) (mprVarIsPtr((x)->type) && \ - talloc_check_name((x)->ptr, "struct smbcli_tree")) - -/* Perform a tree disconnect: - - tree_disconnect(tree_handle); - */ - -static int ejs_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 1) { - ejsSetErrorMsg(eid, - "tree_disconnect(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = talloc_get_type(argv[0]->ptr, struct smbcli_tree); - - result = smb_tree_disconnect(tree); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Create a directory: - - result = mkdir(tree_handle, DIRNAME); - */ - -static int ejs_mkdir(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 2) { - ejsSetErrorMsg(eid, "mkdir(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - result = smbcli_mkdir(tree, argv[1]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Remove a directory: - - result = rmdir(tree_handle, DIRNAME); - */ - -static int ejs_rmdir(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 2) { - ejsSetErrorMsg(eid, "rmdir(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - result = smbcli_rmdir(tree, argv[1]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Rename a file or directory: - - result = rename(tree_handle, SRCFILE, DESTFILE); - */ - -static int ejs_rename(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 3) { - ejsSetErrorMsg(eid, "rename(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - if (!mprVarIsString(argv[2]->type)) { - ejsSetErrorMsg(eid, "arg 3 must be a string"); - return -1; - } - - result = smbcli_rename(tree, argv[1]->string, argv[2]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Unlink a file or directory: - - result = unlink(tree_handle, FILENAME); - */ - -static int ejs_unlink(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 2) { - ejsSetErrorMsg(eid, "unlink(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - result = smbcli_unlink(tree, argv[1]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* List directory contents - - result = list(tree_handle, ARG1, ...); - */ - -static void ejs_list_helper(struct clilist_file_info *info, const char *mask, - void *state) - -{ - MprVar *result = (MprVar *)state; - char idx[16]; - - mprItoa(result->properties->numDataItems, idx, sizeof(idx)); - mprSetVar(result, idx, mprString(info->name)); -} - -static int ejs_list(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - char *mask; - uint16_t attribute; - MprVar result; - - if (argc != 3) { - ejsSetErrorMsg(eid, "list(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - mask = argv[1]->string; - - if (!mprVarIsNumber(argv[2]->type)) { - ejsSetErrorMsg(eid, "arg 3 must be a number"); - return -1; - } - - attribute = mprVarToInteger(argv[2]); - - result = mprObject("list"); - - smbcli_list(tree, mask, attribute, ejs_list_helper, &result); - - mpr_Return(eid, result); - - return 0; -} - -/* - setup C functions that be called from ejs -*/ -void smb_setup_ejs_cli(void) -{ - ejsDefineStringCFunction(-1, "tree_connect", ejs_tree_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "tree_disconnect", ejs_tree_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE); - - ejsDefineCFunction(-1, "mkdir", ejs_mkdir, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "rmdir", ejs_rmdir, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "rename", ejs_rename, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "unlink", ejs_unlink, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "list", ejs_list, NULL, MPR_VAR_SCRIPT_HANDLE); - - -#if 0 - ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "session_setup", ejs_cli_ssetup, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "tree_connect", ejs_cli_tree_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "tree_disconnect", ejs_cli_tree_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "session_logoff", ejs_cli_session_logoff, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "disconnect", ejs_cli_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE); -#endif -} diff --git a/source4/scripting/ejs/smbcalls_data.c b/source4/scripting/ejs/smbcalls_data.c deleted file mode 100644 index 19e1e173d6..0000000000 --- a/source4/scripting/ejs/smbcalls_data.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide access to data blobs - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/winreg.h" - -/* - create a data blob object from a ejs array of integers -*/ -static int ejs_blobFromArray(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *array, *v; - unsigned length, i; - DATA_BLOB blob; - - if (argc != 1) { - ejsSetErrorMsg(eid, "blobFromArray invalid arguments"); - return -1; - } - array = argv[0]; - - v = mprGetProperty(array, "length", NULL); - if (v == NULL) { - goto failed; - } - length = mprToInt(v); - - blob = data_blob_talloc(mprMemCtx(), NULL, length); - if (length != 0 && blob.data == NULL) { - goto failed; - } - - for (i=0;i<length;i++) { - struct MprVar *vs; - char idx[16]; - mprItoa(i, idx, sizeof(idx)); - vs = mprGetProperty(array, idx, NULL); - if (vs == NULL) { - goto failed; - } - blob.data[i] = mprVarToNumber(vs); - } - - mpr_Return(eid, mprDataBlob(blob)); - return 0; - -failed: - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; -} - -/* - create a ejs array of integers from a data blob -*/ -static int ejs_blobToArray(MprVarHandle eid, int argc, struct MprVar **argv) -{ - DATA_BLOB *blob; - struct MprVar array; - int i; - - if (argc != 1) { - ejsSetErrorMsg(eid, "blobToArray invalid arguments"); - return -1; - } - blob = mprToDataBlob(argv[0]); - if (blob == NULL) { - goto failed; - } - - array = mprArray("array"); - - for (i=0;i<blob->length;i++) { - mprAddArray(&array, i, mprCreateNumberVar(blob->data[i])); - } - mpr_Return(eid, array); - return 0; - -failed: - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; -} - - -/* - compare two data blobs -*/ -static int ejs_blobCompare(MprVarHandle eid, int argc, struct MprVar **argv) -{ - DATA_BLOB *blob1, *blob2; - bool ret = false; - - if (argc != 2) { - ejsSetErrorMsg(eid, "blobCompare invalid arguments"); - return -1; - } - - blob1 = mprToDataBlob(argv[0]); - blob2 = mprToDataBlob(argv[1]); - - if (blob1 == blob2) { - ret = true; - goto done; - } - if (blob1 == NULL || blob2 == NULL) { - ret = false; - goto done; - } - - if (blob1->length != blob2->length) { - ret = false; - goto done; - } - - if (memcmp(blob1->data, blob2->data, blob1->length) != 0) { - ret = false; - goto done; - } - ret = true; - -done: - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - - -/* - convert a blob in winreg format to a mpr variable - - usage: - v = data.regToVar(blob, type); -*/ -static int ejs_regToVar(MprVarHandle eid, int argc, struct MprVar **argv) -{ - DATA_BLOB *blob; - enum winreg_Type type; - struct MprVar v; - - if (argc != 2) { - ejsSetErrorMsg(eid, "regToVar invalid arguments"); - return -1; - } - - blob = mprToDataBlob(argv[0]); - type = mprToInt(argv[1]); - - if (blob == NULL) { - ejsSetErrorMsg(eid, "regToVar null data"); - return -1; - } - - switch (type) { - case REG_NONE: - v = mprCreateUndefinedVar(); - break; - - case REG_SZ: - case REG_EXPAND_SZ: { - char *s; - ssize_t len; - len = convert_string_talloc(mprMemCtx(), lp_iconv_convenience(mprLpCtx()), CH_UTF16, CH_UNIX, - blob->data, blob->length, (void **)&s); - if (len == -1) { - ejsSetErrorMsg(eid, "regToVar invalid REG_SZ string"); - return -1; - } - v = mprString(s); - talloc_free(s); - break; - } - - case REG_DWORD: { - if (blob->length != 4) { - ejsSetErrorMsg(eid, "regToVar invalid REG_DWORD length %ld", (long)blob->length); - return -1; - } - v = mprCreateNumberVar(IVAL(blob->data, 0)); - break; - } - - case REG_DWORD_BIG_ENDIAN: { - if (blob->length != 4) { - ejsSetErrorMsg(eid, "regToVar invalid REG_DWORD_BIG_ENDIAN length %ld", (long)blob->length); - return -1; - } - v = mprCreateNumberVar(RIVAL(blob->data, 0)); - break; - } - - case REG_QWORD: { - if (blob->length != 8) { - ejsSetErrorMsg(eid, "regToVar invalid REG_QWORD length %ld", (long)blob->length); - return -1; - } - v = mprCreateNumberVar(BVAL(blob->data, 0)); - break; - } - - case REG_MULTI_SZ: { - DATA_BLOB b = *blob; - const char **list = NULL; - while (b.length > 0) { - char *s; - ssize_t len; - size_t slen = utf16_len_n(b.data, b.length); - if (slen == 2 && b.length == 2 && SVAL(b.data, 0) == 0) { - break; - } - len = convert_string_talloc(mprMemCtx(), lp_iconv_convenience(mprLpCtx()), CH_UTF16, CH_UNIX, - b.data, slen, (void **)&s); - if (len == -1) { - ejsSetErrorMsg(eid, "regToVar invalid REG_MULTI_SZ string"); - return -1; - } - list = str_list_add(list, s); - talloc_free(s); - talloc_steal(mprMemCtx(), list); - b.data += slen; - b.length -= slen; - } - v = mprList("REG_MULTI_SZ", list); - talloc_free(list); - break; - } - - - case REG_FULL_RESOURCE_DESCRIPTOR: - case REG_RESOURCE_LIST: - case REG_BINARY: - case REG_RESOURCE_REQUIREMENTS_LIST: - case REG_LINK: - return ejs_blobToArray(eid, 1, argv); - - default: - ejsSetErrorMsg(eid, "regToVar invalid type %d", type); - return -1; - } - - mpr_Return(eid, v); - return 0; -} - -/* - initialise datablob ejs subsystem -*/ -static int ejs_datablob_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "datablob", argc, argv); - - mprSetCFunction(obj, "blobFromArray", ejs_blobFromArray); - mprSetCFunction(obj, "blobToArray", ejs_blobToArray); - mprSetCFunction(obj, "blobCompare", ejs_blobCompare); - mprSetCFunction(obj, "regToVar", ejs_regToVar); - - return 0; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_datablob(void) -{ - ejsDefineCFunction(-1, "datablob_init", ejs_datablob_init, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/smbcalls_nbt.c b/source4/scripting/ejs/smbcalls_nbt.c deleted file mode 100644 index 8c555bf821..0000000000 --- a/source4/scripting/ejs/smbcalls_nbt.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Tim Potter 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/nbt.h" -#include "lib/events/events.h" -#include "libcli/resolve/resolve.h" - -/* - look up a netbios name - - syntax: - resolveName(result, "frogurt"); - resolveName(result, "frogurt", 0x1c); -*/ - -static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv) -{ - int result = -1; - struct nbt_name name; - TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx()); - NTSTATUS nt_status; - const char *reply_addr; - - /* validate arguments */ - if (argc < 2 || argc > 3) { - ejsSetErrorMsg(eid, "resolveName invalid arguments"); - goto done; - } - - if (argv[0]->type != MPR_TYPE_OBJECT) { - ejsSetErrorMsg(eid, "resolvename invalid arguments"); - goto done; - } - - if (argv[1]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "resolveName invalid arguments"); - goto done; - } - - if (argc == 2) { - make_nbt_name_client(&name, mprToString(argv[1])); - } else { - if (!mprVarIsNumber(argv[1]->type)) { - ejsSetErrorMsg(eid, "resolveName invalid arguments"); - goto done; - } - make_nbt_name(&name, mprToString(argv[1]), mprToInt(argv[2])); - } - - result = 0; - - nt_status = resolve_name(lp_resolve_context(mprLpCtx()), &name, tmp_ctx, &reply_addr, mprEventCtx()); - - if (NT_STATUS_IS_OK(nt_status)) { - mprSetPropertyValue(argv[0], "value", mprString(reply_addr)); - } - - mpr_Return(eid, mprNTSTATUS(nt_status)); - - done: - talloc_free(tmp_ctx); - return result; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_nbt(void) -{ - ejsDefineCFunction(-1, "resolveName", ejs_resolve_name, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/smbcalls_nss.c b/source4/scripting/ejs/smbcalls_nss.c deleted file mode 100644 index 58f86d3b6c..0000000000 --- a/source4/scripting/ejs/smbcalls_nss.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide access to getpwnam() and related calls - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "system/passwd.h" - - -/* - return a struct passwd as an object -*/ -static struct MprVar mpr_passwd(struct passwd *pwd) -{ - struct MprVar ret; - if (pwd == NULL) { - return mprCreateUndefinedVar(); - } - ret = mprObject("passwd"); - - mprSetVar(&ret, "pw_name", mprString(pwd->pw_name)); - mprSetVar(&ret, "pw_passwd", mprString(pwd->pw_passwd)); - mprSetVar(&ret, "pw_uid", mprCreateIntegerVar(pwd->pw_uid)); - mprSetVar(&ret, "pw_gid", mprCreateIntegerVar(pwd->pw_gid)); - mprSetVar(&ret, "pw_gecos", mprString(pwd->pw_gecos)); - mprSetVar(&ret, "pw_dir", mprString(pwd->pw_dir)); - mprSetVar(&ret, "pw_shell", mprString(pwd->pw_shell)); - return ret; -} - -/* - return a struct passwd as an object -*/ -static struct MprVar mpr_group(struct group *grp) -{ - struct MprVar ret; - if (grp == NULL) { - return mprCreateUndefinedVar(); - } - ret = mprObject("group"); - - mprSetVar(&ret, "gr_name", mprString(grp->gr_name)); - mprSetVar(&ret, "gr_passwd", mprString(grp->gr_passwd)); - mprSetVar(&ret, "gr_gid", mprCreateIntegerVar(grp->gr_gid)); - mprSetVar(&ret, "gr_mem", mprList("gr_mem", (const char **)grp->gr_mem)); - return ret; -} - - -/* - usage: - var pw = nss.getpwnam("root"); - - returns an object containing struct passwd entries -*/ -static int ejs_getpwnam(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "getpwnam invalid arguments"); - return -1; - } - - mpr_Return(eid, mpr_passwd(getpwnam(mprToString(argv[0])))); - return 0; -} - -/* - usage: - var pw = nss.getpwuid(0); - - returns an object containing struct passwd entries -*/ -static int ejs_getpwuid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || !mprVarIsNumber(argv[0]->type)) { - ejsSetErrorMsg(eid, "getpwuid invalid arguments"); - return -1; - } - mpr_Return(eid, mpr_passwd(getpwuid(mprToInt(argv[0])))); - return 0; -} - -/* - usage: - var pw = nss.getgrnam("users"); - - returns an object containing struct group entries -*/ -static int ejs_getgrnam(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "getgrnam invalid arguments"); - return -1; - } - mpr_Return(eid, mpr_group(getgrnam(mprToString(argv[0])))); - return 0; -} - -/* - usage: - var pw = nss.getgrgid(0); - - returns an object containing struct group entries -*/ -static int ejs_getgrgid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "getgrgid invalid arguments"); - return -1; - } - mpr_Return(eid, mpr_group(getgrgid(mprToInt(argv[0])))); - return 0; -} - - -/* - initialise nss ejs subsystem -*/ -static int ejs_nss_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *nss = mprInitObject(eid, "nss", argc, argv); - - mprSetCFunction(nss, "getpwnam", ejs_getpwnam); - mprSetCFunction(nss, "getpwuid", ejs_getpwuid); - mprSetCFunction(nss, "getgrnam", ejs_getgrnam); - mprSetCFunction(nss, "getgrgid", ejs_getgrgid); - - return 0; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_nss(void) -{ - ejsDefineCFunction(-1, "nss_init", ejs_nss_init, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/smbcalls_param.c b/source4/scripting/ejs/smbcalls_param.c deleted file mode 100644 index 5fbb0bb017..0000000000 --- a/source4/scripting/ejs/smbcalls_param.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "param/param.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" - -/* - get parameter - - value = param.get("name"); - value = param.get("section", "name"); -*/ -static int ejs_param_get(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - const char *ret; - if (argc != 1 && argc != 2) { - ejsSetErrorMsg(eid, "param.get invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - if (argc == 2) { - ret = param_get_string(ctx, argv[0], argv[1]); - } else { - ret = param_get_string(ctx, argv[0], NULL); - } - - if (ret) { - mpr_Return(eid, mprString(ret)); - } else { - mpr_Return(eid, mprCreateUndefinedVar()); - } - return 0; -} - -/* - get list parameter - - ok = param.get_list("name"); - ok = param.get_list("section", "name"); -*/ -static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - const char **ret; - - if (argc != 1 && argc != 2) { - ejsSetErrorMsg(eid, "param.get_list invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - if (argc == 2) { - ret = param_get_string_list(ctx, argv[0], argv[1], NULL); - } else { - ret = param_get_string_list(ctx, argv[0], NULL, NULL); - } - - if (ret != NULL) { - mpr_Return(eid, mprList("array", ret)); - } else { - mpr_Return(eid, mprCreateUndefinedVar()); - } - return 0; -} - -/* - set parameter - - ok = param.set("name", "value"); - ok = param.set("section", "name", "value"); -*/ -static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct param_context *ctx; - const char **list; - const char *section, *paramname; - struct MprVar *value; - bool ret; - if (argc != 2 && argc != 3) { - ejsSetErrorMsg(eid, "param.set invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - - if (argc == 3) { - section = mprToString(argv[0]); - paramname = mprToString(argv[1]); - value = argv[2]; - } else { - section = NULL; - paramname = mprToString(argv[0]); - value = argv[1]; - } - - list = mprToList(mprMemCtx(), value); - if (list) { - ret = param_set_string_list(ctx, paramname, list, section); - } else { - ret = param_set_string(ctx, paramname, mprToString(value), section); - } - - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - -/* - param data as a two-level array - - data = param.data; - */ -static int ejs_param_data(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - struct MprVar ret; - struct param_section *sec; - - if (argc != 0) { - ejsSetErrorMsg(eid, "param.data does not take arguments"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - ret = mprObject("array"); - - for (sec = ctx->sections; sec; sec = sec->next) { - struct MprVar ps = mprObject("array"); - struct param_opt *p; - - for (p = sec->parameters; p; p = p->next) { - mprSetVar(&ps, p->key, mprString(p->value)); - } - - mprSetVar(&ret, sec->name, ps); - } - - mpr_Return(eid, ret); - - return 0; -} - -/* - load file - - ok = param.load(file); -*/ -static int ejs_param_load(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - bool ret; - - if (argc != 1) { - ejsSetErrorMsg(eid, "param.load invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - ret = param_read(ctx, argv[0]); - - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - - -/* - save file - - ok = param.save(file); -*/ -static int ejs_param_save(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - bool ret; - - if (argc != 1) { - ejsSetErrorMsg(eid, "param.save invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - ret = param_write(ctx, argv[0]); - - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - -static void param_add_members(struct MprVar *obj) -{ - mprSetStringCFunction(obj, "get", ejs_param_get); - mprSetStringCFunction(obj, "get_list", ejs_param_get_list); - mprSetCFunction(obj, "set", ejs_param_set); - mprSetStringCFunction(obj, "load", ejs_param_load); - mprSetStringCFunction(obj, "save", ejs_param_save); - mprSetStringCFunction(obj, "data", ejs_param_data); -} - -/* - initialise param ejs subsystem -*/ -static int ejs_param_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "param", argc, argv); - - mprSetPtrChild(obj, "param", param_init(mprMemCtx())); - - param_add_members(obj); - - return 0; -} - -struct MprVar mprParam(struct param_context *ctx) -{ - struct MprVar mpv = mprObject("param"); - mprSetPtrChild(&mpv, "param", ctx); - param_add_members(&mpv); - return mpv; -} - -/* - setup C functions that be called from ejs -*/ -void smb_setup_ejs_param(void) -{ - ejsDefineCFunction(-1, "param_init", ejs_param_init, NULL, MPR_VAR_SCRIPT_HANDLE); -} diff --git a/source4/scripting/ejs/smbcalls_rand.c b/source4/scripting/ejs/smbcalls_rand.c deleted file mode 100644 index 58e0fa1fd1..0000000000 --- a/source4/scripting/ejs/smbcalls_rand.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide access to randomisation functions - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/ndr_misc.h" -#include "librpc/ndr/libndr.h" - -/* - usage: - var i = random(); -*/ -static int ejs_random(MprVarHandle eid, int argc, struct MprVar **argv) -{ - mpr_Return(eid, mprCreateIntegerVar(generate_random())); - return 0; -} - -/* - usage: - var s = randpass(len); -*/ -static int ejs_randpass(MprVarHandle eid, int argc, struct MprVar **argv) -{ - char *s; - if (argc != 1 || !mprVarIsNumber(argv[0]->type)) { - ejsSetErrorMsg(eid, "randpass invalid arguments"); - return -1; - } - s = generate_random_str(mprMemCtx(), mprToInt(argv[0])); - mpr_Return(eid, mprString(s)); - talloc_free(s); - return 0; -} - -/* - usage: - var guid = randguid(); -*/ -static int ejs_randguid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct GUID guid = GUID_random(); - char *s = GUID_string(mprMemCtx(), &guid); - mpr_Return(eid, mprString(s)); - talloc_free(s); - return 0; -} - -/* - usage: - var sid = randsid(); -*/ -static int ejs_randsid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - char *s = talloc_asprintf(mprMemCtx(), "S-1-5-21-%u-%u-%u", - (unsigned)generate_random(), - (unsigned)generate_random(), - (unsigned)generate_random()); - mpr_Return(eid, mprString(s)); - talloc_free(s); - return 0; -} - -/* - initialise random ejs subsystem -*/ -static int ejs_random_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "random", argc, argv); - - mprSetCFunction(obj, "random", ejs_random); - mprSetCFunction(obj, "randpass", ejs_randpass); - mprSetCFunction(obj, "randguid", ejs_randguid); - mprSetCFunction(obj, "randsid", ejs_randsid); - return 0; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_random(void) -{ - ejsDefineCFunction(-1, "random_init", ejs_random_init, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/smbcalls_reg.c b/source4/scripting/ejs/smbcalls_reg.c deleted file mode 100644 index ed8653d3a7..0000000000 --- a/source4/scripting/ejs/smbcalls_reg.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Jelmer Vernooij 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "dsdb/samdb/samdb.h" -#include "librpc/ndr/libndr.h" -#include "lib/registry/registry.h" - -/* - get the connected db - */ -static struct registry_context *ejs_get_reg_context(int eid) -{ - struct registry_context *rctx = (struct registry_context *)mprGetThisPtr(eid, "registry"); - if (rctx == NULL) { - ejsSetErrorMsg(eid, "unable to find registry"); - } - return rctx; -} - -static int ejs_apply_patchfile(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct registry_context *rctx; - WERROR error; - - /* validate arguments */ - if (argc != 1) { - ejsSetErrorMsg(eid, "reg.apply_patchfile invalid number of arguments"); - return -1; - } - - rctx = ejs_get_reg_context(eid); - if (rctx == NULL) { - return -1; - } - - error = reg_diff_apply(rctx, mprToString(argv[0])); - - mpr_Return(eid, mprWERROR(error)); - - return 0; -} - -/* - initialise registry ejs subsystem -*/ -static int ejs_reg_open(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *reg = mprInitObject(eid, "registry", argc, argv); - struct registry_context *rctx; - WERROR error; - - error = reg_open_samba(mprMemCtx(), &rctx, mprEventCtx(), mprLpCtx(), NULL, NULL); - SMB_ASSERT(W_ERROR_IS_OK(error)); - - mprSetPtrChild(reg, "registry", rctx); - mprSetCFunction(reg, "apply_patchfile", ejs_apply_patchfile); - - return 0; -} - - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_reg(void) -{ - ejsDefineCFunction(-1, "reg_open", ejs_reg_open, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c deleted file mode 100644 index 94774d708b..0000000000 --- a/source4/scripting/ejs/smbcalls_rpc.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide interfaces to rpc calls from ejs scripts - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/echo.h" -#include "lib/cmdline/popt_common.h" -#include "lib/messaging/irpc.h" -#include "scripting/ejs/ejsrpc.h" -#include "lib/util/dlinklist.h" -#include "lib/events/events.h" -#include "librpc/ndr/ndr_table.h" -#include "auth/credentials/credentials.h" -#include "librpc/rpc/dcerpc.h" -#include "cluster/cluster.h" - -/* - state of a irpc 'connection' -*/ -struct ejs_irpc_connection { - const char *server_name; - struct server_id *dest_ids; - struct messaging_context *msg_ctx; -}; - -/* - messaging clients need server IDs as well ... - */ -#define EJS_ID_BASE 0x30000000 - -/* - setup a context for talking to a irpc server - example: - status = irpc.connect("smb_server"); -*/ -static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status; - int i; - struct event_context *ev; - struct ejs_irpc_connection *p; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); - - /* validate arguments */ - if (argc != 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; - } - - p = talloc(this, struct ejs_irpc_connection); - if (p == NULL) { - return -1; - } - - p->server_name = argv[0]; - - ev = mprEventCtx(); - - /* create a messaging context, looping as we have no way to - allocate temporary server ids automatically */ - for (i=0;i<10000;i++) { - p->msg_ctx = messaging_init(p, - lp_messaging_path(p, mprLpCtx()), - cluster_id(EJS_ID_BASE, i), - lp_iconv_convenience(mprLpCtx()), - ev); - if (p->msg_ctx) break; - } - if (p->msg_ctx == NULL) { - ejsSetErrorMsg(eid, "irpc_connect unable to create a messaging context"); - talloc_free(p); - return -1; - } - - p->dest_ids = irpc_servers_byname(p->msg_ctx, p, p->server_name); - if (p->dest_ids == NULL || p->dest_ids[0].id == 0) { - talloc_free(p); - status = NT_STATUS_OBJECT_NAME_NOT_FOUND; - } else { - mprSetPtrChild(this, "irpc", p); - status = NT_STATUS_OK; - } - - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - connect to an rpc server - examples: - status = rpc.connect("ncacn_ip_tcp:localhost"); - status = rpc.connect("ncacn_ip_tcp:localhost", "pipe_name"); -*/ -static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv) -{ - const char *binding, *pipe_name; - const struct ndr_interface_table *iface; - NTSTATUS status; - struct dcerpc_pipe *p; - struct cli_credentials *creds; - struct event_context *ev; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); - struct MprVar *credentials; - - /* validate arguments */ - if (argc < 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; - } - - binding = argv[0]; - if (strchr(binding, ':') == NULL) { - /* its an irpc connect */ - return ejs_irpc_connect(eid, argc, argv); - } - - if (argc > 1) { - pipe_name = argv[1]; - } else { - pipe_name = mprToString(mprGetProperty(this, "pipe_name", NULL)); - } - - iface = ndr_table_by_name(pipe_name); - if (iface == NULL) { - status = NT_STATUS_OBJECT_NAME_INVALID; - goto done; - } - - credentials = mprGetProperty(this, "credentials", NULL); - if (credentials) { - creds = (struct cli_credentials *) - mprGetPtr(credentials, "creds"); - } else { - creds = cmdline_credentials; - } - if (creds == NULL) { - creds = cli_credentials_init(mprMemCtx()); - cli_credentials_set_anonymous(creds); - } - - ev = mprEventCtx(); - - status = dcerpc_pipe_connect(this, &p, binding, iface, creds, ev, - mprLpCtx()); - if (!NT_STATUS_IS_OK(status)) goto done; - - /* callers don't allocate ref vars in the ejs interface */ - p->conn->flags |= DCERPC_NDR_REF_ALLOC; - - /* by making the pipe a child of the connection variable, it will - auto close when it goes out of scope in the script */ - mprSetPtrChild(this, "pipe", p); - -done: - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - make an irpc call - called via the same interface as rpc -*/ -static int ejs_irpc_call(int eid, struct MprVar *io, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) -{ - NTSTATUS status; - void *ptr; - struct ejs_rpc *ejs; - const struct ndr_interface_call *call; - struct ejs_irpc_connection *p; - struct irpc_request **reqs; - int i, count; - struct MprVar *results; - - p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc"); - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; - - /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - for (count=0;p->dest_ids[count].id;count++) /* noop */ ; - - /* we need to make a call per server */ - reqs = talloc_array(ejs, struct irpc_request *, count); - if (reqs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* make the actual calls */ - for (i=0;i<count;i++) { - reqs[i] = irpc_call_send(p->msg_ctx, p->dest_ids[i], - iface, callnum, ptr, ptr); - if (reqs[i] == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - talloc_steal(reqs, reqs[i]); - } - - mprSetVar(io, "results", mprObject("results")); - results = mprGetProperty(io, "results", NULL); - - /* and receive the results, placing them in io.results[i] */ - for (i=0;i<count;i++) { - struct MprVar *output; - - status = irpc_call_recv(reqs[i]); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - status = ejs_push(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* add to the results array */ - output = mprGetProperty(io, "output", NULL); - if (output) { - char idx[16]; - mprItoa(i, idx, sizeof(idx)); - mprSetProperty(results, idx, output); - mprDeleteProperty(io, "output"); - } - } - mprSetVar(results, "length", mprCreateIntegerVar(i)); - -done: - talloc_free(ejs); - mpr_Return(eid, mprNTSTATUS(status)); - if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) { - return -1; - } - return 0; -} - - -/* - backend code for making an rpc call - this is called from the pidl generated ejs - code -*/ - int ejs_rpc_call(int eid, int argc, struct MprVar **argv, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) -{ - struct MprVar *io; - struct dcerpc_pipe *p; - NTSTATUS status; - void *ptr; - struct rpc_request *req; - struct ejs_rpc *ejs; - const struct ndr_interface_call *call; - - if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) { - ejsSetErrorMsg(eid, "rpc_call invalid arguments"); - return -1; - } - - io = argv[0]; - - if (mprGetThisPtr(eid, "irpc")) { - /* its an irpc call */ - return ejs_irpc_call(eid, io, iface, callnum, ejs_pull, ejs_push); - } - - /* get the pipe info */ - p = mprGetThisPtr(eid, "pipe"); - if (p == NULL) { - ejsSetErrorMsg(eid, "rpc_call invalid pipe"); - return -1; - } - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; - - /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* make the actual call */ - req = dcerpc_ndr_request_send(p, NULL, iface, callnum, ptr, ptr); - - /* if requested, print the structure */ - if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) { - ndr_print_function_debug(call->ndr_print, call->name, NDR_IN, ptr); - } - - if (req == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - status = dcerpc_ndr_request_recv(req); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* print the 'out' structure, if needed */ - if (p->conn->flags & DCERPC_DEBUG_PRINT_OUT) { - ndr_print_function_debug(call->ndr_print, call->name, NDR_OUT, ptr); - } - - status = ejs_push(ejs, io, ptr); - -done: - talloc_free(ejs); - mpr_Return(eid, mprNTSTATUS(status)); - if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) { - return -1; - } - return 0; -} - -/* - hook called by generated RPC interfaces at the end of their init routines - used to add generic operations on the pipe -*/ -int ejs_rpc_init(struct MprVar *obj, const char *name) -{ - ndr_table_init(); - - mprSetStringCFunction(obj, "connect", ejs_rpc_connect); - if (mprGetProperty(obj, "pipe_name", NULL) == NULL) { - mprSetVar(obj, "pipe_name", mprString(name)); - } - return 0; -} diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 9ed4aa490f..db9fc9affa 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -26,7 +26,7 @@ #include "scripting/ejs/smbcalls.h" #include "auth/gensec/gensec.h" #include "ldb/include/ldb.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" static EjsId eid; |