Esempio n. 1
0
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;
	struct event_context *ev;

	if (!event_mem_ctx) {
		ejsSetErrorMsg(eid, "talloc_new() failed");
		return -1;
	}
	ev = event_context_find(event_mem_ctx);
	ctx = libnet_context_init(ev);
	/* 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)) {
		creds = cli_credentials_init(ctx);
		if (creds == NULL) {
			ejsSetErrorMsg(eid, "cli_credential_init() failed");
			talloc_free(ctx);
			return -1;
		}
		cli_credentials_set_conf(creds);
		cli_credentials_set_anonymous(creds);
	} else if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) {
		/* get credential values from credentials object */
		creds = mprGetPtr(argv[0], "creds");
		if (creds == NULL) {
			ejsSetErrorMsg(eid, "userAuth requires a 'creds' first parameter");
			talloc_free(ctx);
			return -1;
		}
	} else {
		ejsSetErrorMsg(eid, "NetContext invalid arguments, this function requires an object.");
		talloc_free(ctx);
		return -1;
	}
	ctx->cred = creds;

	obj = mprObject("NetCtx");
	mprSetPtrChild(&obj, "ctx", ctx);
	
	mprSetCFunction(&obj, "UserMgr", ejs_net_userman);
	mprSetCFunction(&obj, "JoinDomain", ejs_net_join_domain);
	mprSetCFunction(&obj, "SamSyncLdb", ejs_net_samsync_ldb);
	mpr_Return(eid, obj);

	return 0;
}
Esempio n. 2
0
/*
  initialise a system change notify backend
*/
_PUBLIC_ struct sys_notify_context *sys_notify_context_create(struct share_config *scfg,
        TALLOC_CTX *mem_ctx,
        struct event_context *ev)
{
    struct sys_notify_context *ctx;
    const char *bname;
    int i;

    if (num_backends == 0) {
        return NULL;
    }

    if (ev == NULL) {
        ev = event_context_find(mem_ctx);
    }

    ctx = talloc_zero(mem_ctx, struct sys_notify_context);
    if (ctx == NULL) {
        return NULL;
    }

    ctx->ev = ev;

    bname = share_string_option(scfg, NOTIFY_BACKEND, NULL);
    if (!bname) {
        if (num_backends) {
            bname = backends[0].name;
        } else {
            bname = "__unknown__";
        }
    }

    for (i=0; i<num_backends; i++) {
        if (strcasecmp(backends[i].name, bname) == 0) {
            bname = backends[i].name;
            break;
        }
    }

    ctx->name = bname;
    ctx->notify_watch = NULL;

    if (i < num_backends) {
        ctx->notify_watch = backends[i].notify_watch;
    }

    return ctx;
}
Esempio n. 3
0
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(&name, tmp_ctx, &reply_addr, event_context_find(tmp_ctx));

    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;
}
Esempio n. 4
0
/**
 * Fill in credentials for the machine trust account, from the secrets database.
 * 
 * @param cred Credentials structure to fill in
 * @retval NTSTATUS error detailing any failure
 */
_PUBLIC_ NTSTATUS cli_credentials_set_machine_account(struct cli_credentials *cred,
						      struct loadparm_context *lp_ctx)
{
	NTSTATUS status;
	char *filter;
	/* Bleh, nasty recursion issues: We are setting a machine
	 * account here, so we don't want the 'pending' flag around
	 * any more */
	cred->machine_account_pending = false;
	filter = talloc_asprintf(cred, SECRETS_PRIMARY_DOMAIN_FILTER, 
				       cli_credentials_get_domain(cred));
	status = cli_credentials_set_secrets(cred, event_context_find(cred), lp_ctx, NULL, 
					   SECRETS_PRIMARY_DOMAIN_DN,
					   filter);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("Could not find machine account in secrets database: %s", nt_errstr(status)));
	}
	return status;
}
Esempio n. 5
0
/*
  connect to a share - used when a tree_connect operation comes
  in. For a disk based backend we needs to ensure that the base
  directory exists (tho it doesn't need to be accessible by the user,
  that comes later)
*/
static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
			     struct ntvfs_request *req, const char *sharename)
{
	struct pvfs_state *pvfs;
	struct stat st;
	char *base_directory;
	NTSTATUS status;

	pvfs = talloc_zero(ntvfs, struct pvfs_state);
	NT_STATUS_HAVE_NO_MEMORY(pvfs);

	/* for simplicity of path construction, remove any trailing slash now */
	base_directory = talloc_strdup(pvfs, share_string_option(ntvfs->ctx->config, SHARE_PATH, ""));
	NT_STATUS_HAVE_NO_MEMORY(base_directory);
	if (strcmp(base_directory, "/") != 0) {
		trim_string(base_directory, NULL, "/");
	}

	pvfs->ntvfs = ntvfs;
	pvfs->base_directory = base_directory;

	/* the directory must exist. Note that we deliberately don't
	   check that it is readable */
	if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
		DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n", 
			 pvfs->base_directory, sharename));
		return NT_STATUS_BAD_NETWORK_NAME;
	}

	ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
	NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);

	ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
	NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);

	ntvfs->private_data = pvfs;

	pvfs->brl_context = brl_init(pvfs, 
				     pvfs->ntvfs->ctx->server_id,
				     pvfs->ntvfs->ctx->msg_ctx);
	if (pvfs->brl_context == NULL) {
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	pvfs->odb_context = odb_init(pvfs, pvfs->ntvfs->ctx);
	if (pvfs->odb_context == NULL) {
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	/* allow this to be NULL - we just disable change notify */
	pvfs->notify_context = notify_init(pvfs, 
					   pvfs->ntvfs->ctx->server_id,  
					   pvfs->ntvfs->ctx->msg_ctx, 
					   event_context_find(pvfs),
					   pvfs->ntvfs->ctx->config);

	pvfs->sidmap = sidmap_open(pvfs);
	if (pvfs->sidmap == NULL) {
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	/* allocate the search handle -> ptr tree */
	pvfs->search.idtree = idr_init(pvfs);
	NT_STATUS_HAVE_NO_MEMORY(pvfs->search.idtree);

	status = pvfs_mangle_init(pvfs);
	NT_STATUS_NOT_OK_RETURN(status);

	pvfs_setup_options(pvfs);

	talloc_set_destructor(pvfs, pvfs_state_destructor);

#ifdef SIGXFSZ
	/* who had the stupid idea to generate a signal on a large
	   file write instead of just failing it!? */
	BlockSignals(True, SIGXFSZ);
#endif

	return NT_STATUS_OK;
}