Esempio n. 1
0
NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN *ptoken)
{
	NT_USER_TOKEN *token;

	if (!ptoken)
		return NULL;

	token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
	if (token == NULL) {
		DEBUG(0, ("talloc failed\n"));
		return NULL;
	}

	if (ptoken->user_sids && ptoken->num_sids) {
		token->user_sids = (DOM_SID *)talloc_memdup(
			token, ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids );

		if (token->user_sids == NULL) {
			DEBUG(0, ("talloc_memdup failed\n"));
			TALLOC_FREE(token);
			return NULL;
		}
		token->num_sids = ptoken->num_sids;
	}
	
	/* copy the privileges; don't consider failure to be critical here */
	
	if ( !se_priv_copy( &token->privileges, &ptoken->privileges ) ) {
		DEBUG(0,("dup_nt_token: Failure to copy SE_PRIV!.  "
			 "Continuing with 0 privileges assigned.\n"));
	}

	return token;
}
Esempio n. 2
0
NTSTATUS auth_ntlmssp_start(AUTH_NTLMSSP_STATE **auth_ntlmssp_state)
{
	NTSTATUS nt_status;
	TALLOC_CTX *mem_ctx;

	mem_ctx = talloc_init("AUTH NTLMSSP context");
	
	*auth_ntlmssp_state = TALLOC_ZERO_P(mem_ctx, AUTH_NTLMSSP_STATE);
	if (!*auth_ntlmssp_state) {
		DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
		talloc_destroy(mem_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	ZERO_STRUCTP(*auth_ntlmssp_state);

	(*auth_ntlmssp_state)->mem_ctx = mem_ctx;

	if (!NT_STATUS_IS_OK(nt_status = ntlmssp_server_start(&(*auth_ntlmssp_state)->ntlmssp_state))) {
		return nt_status;
	}

	if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(&(*auth_ntlmssp_state)->auth_context))) {
		return nt_status;
	}

	(*auth_ntlmssp_state)->ntlmssp_state->auth_context = (*auth_ntlmssp_state);
	(*auth_ntlmssp_state)->ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
	(*auth_ntlmssp_state)->ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
	(*auth_ntlmssp_state)->ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
	(*auth_ntlmssp_state)->ntlmssp_state->check_password = auth_ntlmssp_check_password;
	(*auth_ntlmssp_state)->ntlmssp_state->server_role = (enum server_types)lp_server_role();

	return NT_STATUS_OK;
}
Esempio n. 3
0
struct _FAKE_FILE_HANDLE *init_fake_file_handle(enum FAKE_FILE_TYPE type)
{
    TALLOC_CTX *mem_ctx = NULL;
    FAKE_FILE_HANDLE *fh = NULL;
    int i;

    for (i=0; fake_files[i].name!=NULL; i++) {
        if (fake_files[i].type==type) {
            DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));

            if ((mem_ctx=talloc_init("fake_file_handle"))==NULL) {
                DEBUG(0,("talloc_init(fake_file_handle) failed.\n"));
                return NULL;
            }

            if ((fh =TALLOC_ZERO_P(mem_ctx, FAKE_FILE_HANDLE))==NULL) {
                DEBUG(0,("talloc_zero() failed.\n"));
                talloc_destroy(mem_ctx);
                return NULL;
            }

            fh->type = type;
            fh->mem_ctx = mem_ctx;

            if (fake_files[i].init_pd)
                fh->pd = fake_files[i].init_pd(fh->mem_ctx);

            fh->free_pd = fake_files[i].free_pd;

            return fh;
        }
    }

    return NULL;
}
Esempio n. 4
0
NTSTATUS ntlmssp_client_start(NTLMSSP_STATE **ntlmssp_state)
{
	*ntlmssp_state = TALLOC_ZERO_P(NULL, NTLMSSP_STATE);
	if (!*ntlmssp_state) {
		DEBUG(0,("ntlmssp_client_start: talloc failed!\n"));
		talloc_destroy(*ntlmssp_state);
		return NT_STATUS_NO_MEMORY;
	}

	(*ntlmssp_state)->role = NTLMSSP_CLIENT;

	(*ntlmssp_state)->get_global_myname = global_myname;
	(*ntlmssp_state)->get_domain = lp_workgroup;

	(*ntlmssp_state)->unicode = True;

	(*ntlmssp_state)->use_ntlmv2 = lp_client_ntlmv2_auth();

	(*ntlmssp_state)->expected_state = NTLMSSP_INITIAL;

	(*ntlmssp_state)->ref_count = 1;

	(*ntlmssp_state)->neg_flags = 
		NTLMSSP_NEGOTIATE_128 |
		NTLMSSP_NEGOTIATE_ALWAYS_SIGN |
		NTLMSSP_NEGOTIATE_NTLM |
		NTLMSSP_NEGOTIATE_NTLM2 |
		NTLMSSP_NEGOTIATE_KEY_EXCH |
		NTLMSSP_REQUEST_TARGET;

	return NT_STATUS_OK;
}
Esempio n. 5
0
DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src)
{
	DOM_SID *dst;
	
	if(!src)
		return NULL;
	
	if((dst = TALLOC_ZERO_P(ctx, DOM_SID)) != NULL) {
		sid_copy( dst, src);
	}
	
	return dst;
}
Esempio n. 6
0
void *init_quota_handle(TALLOC_CTX *mem_ctx)
{
	SMB_NTQUOTA_HANDLE *qt_handle;

	if (!mem_ctx)
		return False;

	qt_handle = TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_HANDLE);
	if (qt_handle==NULL) {
		DEBUG(0,("TALLOC_ZERO() failed\n"));
		return NULL;
	}

	return (void *)qt_handle;	
}
Esempio n. 7
0
SEC_DESC_BUF *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, SEC_DESC *sec_desc)
{
	SEC_DESC_BUF *dst;

	if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL)
		return NULL;

	/* max buffer size (allocated size) */
	dst->sd_size = (uint32)len;
	
	if(sec_desc && ((dst->sd = dup_sec_desc(ctx, sec_desc)) == NULL)) {
		return NULL;
	}

	return dst;
}
Esempio n. 8
0
static NTSTATUS password_policy(struct winbindd_domain *domain,
				TALLOC_CTX *mem_ctx,
				SAM_UNK_INFO_1 *policy)
{
	uint32 min_pass_len,pass_hist,password_properties;
	time_t u_expire, u_min_age;
	NTTIME nt_expire, nt_min_age;
	uint32 account_policy_temp;

	if ((policy = TALLOC_ZERO_P(mem_ctx, SAM_UNK_INFO_1)) == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	if (!pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &account_policy_temp)) {
		return NT_STATUS_ACCESS_DENIED;
	}
	min_pass_len = account_policy_temp;

	if (!pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp)) {
		return NT_STATUS_ACCESS_DENIED;
	}
	pass_hist = account_policy_temp;

	if (!pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp)) {
		return NT_STATUS_ACCESS_DENIED;
	}
	password_properties = account_policy_temp;
	
	if (!pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp)) {
		return NT_STATUS_ACCESS_DENIED;
	}
	u_expire = account_policy_temp;

	if (!pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp)) {
		return NT_STATUS_ACCESS_DENIED;
	}
	u_min_age = account_policy_temp;

	unix_to_nt_time_abs(&nt_expire, u_expire);
	unix_to_nt_time_abs(&nt_min_age, u_min_age);

	init_unk_info1(policy, (uint16)min_pass_len, (uint16)pass_hist, 
	               password_properties, nt_expire, nt_min_age);

	return NT_STATUS_OK;
}
Esempio n. 9
0
NTSTATUS ntlmssp_client_start(NTLMSSP_STATE **ntlmssp_state)
{
	TALLOC_CTX *mem_ctx;

	mem_ctx = talloc_init("NTLMSSP Client context");
	
	*ntlmssp_state = TALLOC_ZERO_P(mem_ctx, NTLMSSP_STATE);
	if (!*ntlmssp_state) {
		DEBUG(0,("ntlmssp_client_start: talloc failed!\n"));
		talloc_destroy(mem_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	(*ntlmssp_state)->role = NTLMSSP_CLIENT;

	(*ntlmssp_state)->mem_ctx = mem_ctx;

	(*ntlmssp_state)->get_global_myname = global_myname;
	(*ntlmssp_state)->get_domain = lp_workgroup;

	(*ntlmssp_state)->unicode = True;

	(*ntlmssp_state)->use_ntlmv2 = lp_client_ntlmv2_auth();

	(*ntlmssp_state)->expected_state = NTLMSSP_INITIAL;

	(*ntlmssp_state)->ref_count = 1;

	(*ntlmssp_state)->neg_flags = 
		NTLMSSP_NEGOTIATE_128 |
		NTLMSSP_NEGOTIATE_NTLM |
		NTLMSSP_NEGOTIATE_NTLM2 |
		NTLMSSP_NEGOTIATE_KEY_EXCH |
		/*
		 * We need to set this to allow a later SetPassword
		 * via the SAMR pipe to succeed. Strange.... We could
		 * also add  NTLMSSP_NEGOTIATE_SEAL here. JRA.
		 * */
		NTLMSSP_NEGOTIATE_SIGN |
		NTLMSSP_REQUEST_TARGET;

	return NT_STATUS_OK;
}
Esempio n. 10
0
NTSTATUS ntlmssp_server_start(NTLMSSP_STATE **ntlmssp_state)
{
	TALLOC_CTX *mem_ctx;

	mem_ctx = talloc_init("NTLMSSP context");
	
	*ntlmssp_state = TALLOC_ZERO_P(mem_ctx, NTLMSSP_STATE);
	if (!*ntlmssp_state) {
		DEBUG(0,("ntlmssp_server_start: talloc failed!\n"));
		talloc_destroy(mem_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	(*ntlmssp_state)->role = NTLMSSP_SERVER;

	(*ntlmssp_state)->mem_ctx = mem_ctx;
	(*ntlmssp_state)->get_challenge = get_challenge;
	(*ntlmssp_state)->set_challenge = set_challenge;
	(*ntlmssp_state)->may_set_challenge = may_set_challenge;

	(*ntlmssp_state)->get_global_myname = global_myname;
	(*ntlmssp_state)->get_domain = lp_workgroup;
	(*ntlmssp_state)->server_role = ROLE_DOMAIN_MEMBER; /* a good default */

	(*ntlmssp_state)->expected_state = NTLMSSP_NEGOTIATE;

	(*ntlmssp_state)->ref_count = 1;

	(*ntlmssp_state)->neg_flags = 
		NTLMSSP_NEGOTIATE_128 |
		NTLMSSP_NEGOTIATE_56 |
		NTLMSSP_NEGOTIATE_VERSION |
		NTLMSSP_NEGOTIATE_ALWAYS_SIGN |
		NTLMSSP_NEGOTIATE_NTLM |
		NTLMSSP_NEGOTIATE_NTLM2 |
		NTLMSSP_NEGOTIATE_KEY_EXCH |
		NTLMSSP_NEGOTIATE_SIGN |
		NTLMSSP_NEGOTIATE_SEAL;

	return NT_STATUS_OK;
}
Esempio n. 11
0
/****************************************************************************
  find first available connection slot, starting from a random position.
The randomisation stops problems with the server dieing and clients
thinking the server is still available.
****************************************************************************/
connection_struct *conn_new(void)
{
	TALLOC_CTX *mem_ctx;
	connection_struct *conn;
	int i;
        int find_offset = 1;

find_again:
	i = bitmap_find(bmap, find_offset);
	
	if (i == -1) {
                /* Expand the connections bitmap. */
                int             oldsz = bmap->n;
                int             newsz = bmap->n + BITMAP_BLOCK_SZ;
                struct bitmap * nbmap;

                if (newsz <= 0) {
                        /* Integer wrap. */
		        DEBUG(0,("ERROR! Out of connection structures\n"));
                        return NULL;
                }

		DEBUG(4,("resizing connections bitmap from %d to %d\n",
                        oldsz, newsz));

                nbmap = bitmap_allocate(newsz);
		if (!nbmap) {
			DEBUG(0,("ERROR! malloc fail.\n"));
			return NULL;
		}

                bitmap_copy(nbmap, bmap);
                bitmap_free(bmap);

                bmap = nbmap;
                find_offset = oldsz; /* Start next search in the new portion. */

                goto find_again;
	}

	if ((mem_ctx=talloc_init("connection_struct"))==NULL) {
		DEBUG(0,("talloc_init(connection_struct) failed!\n"));
		return NULL;
	}

	if ((conn=TALLOC_ZERO_P(mem_ctx, connection_struct))==NULL) {
		DEBUG(0,("talloc_zero() failed!\n"));
		return NULL;
	}
	conn->mem_ctx = mem_ctx;
	conn->cnum = i;

	bitmap_set(bmap, i);

	num_open++;

	string_set(&conn->user,"");
	string_set(&conn->dirpath,"");
	string_set(&conn->connectpath,"");
	string_set(&conn->origpath,"");
	
	DLIST_ADD(Connections, conn);

	return conn;
}
Esempio n. 12
0
bool eventlog_init_keys(void)
{
    /* Find all of the eventlogs, add keys for each of them */
    const char **elogs = lp_eventlog_list();
    char *evtlogpath = NULL;
    char *evtfilepath = NULL;
    struct regsubkey_ctr *subkeys;
    REGVAL_CTR *values;
    uint32 uiMaxSize;
    uint32 uiRetention;
    uint32 uiCategoryCount;
    UNISTR2 data;
    TALLOC_CTX *ctx = talloc_tos();
    WERROR werr;

    while (elogs && *elogs) {
        werr = regsubkey_ctr_init(ctx, &subkeys);
        if (!W_ERROR_IS_OK(werr)) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        regdb_fetch_keys(KEY_EVENTLOG, subkeys);
        regsubkey_ctr_addkey( subkeys, *elogs );
        if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
            TALLOC_FREE(subkeys);
            return False;
        }
        TALLOC_FREE(subkeys);

        /* add in the key of form KEY_EVENTLOG/Application */
        DEBUG( 5,
               ( "Adding key of [%s] to path of [%s]\n", *elogs,
                 KEY_EVENTLOG ) );

        evtlogpath = talloc_asprintf(ctx, "%s\\%s",
                                     KEY_EVENTLOG, *elogs);
        if (!evtlogpath) {
            return false;
        }
        /* add in the key of form KEY_EVENTLOG/Application/Application */
        DEBUG( 5,
               ( "Adding key of [%s] to path of [%s]\n", *elogs,
                 evtlogpath ) );
        werr = regsubkey_ctr_init(ctx, &subkeys);
        if (!W_ERROR_IS_OK(werr)) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        regdb_fetch_keys( evtlogpath, subkeys );
        regsubkey_ctr_addkey( subkeys, *elogs );

        if ( !regdb_store_keys( evtlogpath, subkeys ) ) {
            TALLOC_FREE(subkeys);
            return False;
        }
        TALLOC_FREE( subkeys );

        /* now add the values to the KEY_EVENTLOG/Application form key */
        if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        DEBUG( 5,
               ( "Storing values to eventlog path of [%s]\n",
                 evtlogpath ) );
        regdb_fetch_values( evtlogpath, values );


        if (!regval_ctr_key_exists(values, "MaxSize")) {

            /* assume we have none, add them all */

            /* hard code some initial values */

            /* uiDisplayNameId = 0x00000100; */
            uiMaxSize = 0x00080000;
            uiRetention = 0x93A80;

            regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
                                (char *)&uiMaxSize,
                                sizeof(uint32));

            regval_ctr_addvalue(values, "Retention", REG_DWORD,
                                (char *)&uiRetention,
                                sizeof(uint32));
            init_unistr2(&data, *elogs, UNI_STR_TERMINATE);

            regval_ctr_addvalue(values, "PrimaryModule", REG_SZ,
                                (char *)data.buffer,
                                data.uni_str_len *
                                sizeof(uint16));
            init_unistr2(&data, *elogs, UNI_STR_TERMINATE);

            regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
                                (char *)data.buffer,
                                data.uni_str_len *
                                sizeof(uint16));

            evtfilepath = talloc_asprintf(ctx,
                                          "%%SystemRoot%%\\system32\\config\\%s.tdb",
                                          *elogs);
            if (!evtfilepath) {
                TALLOC_FREE(values);
            }
            init_unistr2(&data, evtfilepath, UNI_STR_TERMINATE);
            regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, (char *)data.buffer,
                                data.uni_str_len * sizeof(uint16));
            regdb_store_values(evtlogpath, values);

        }

        TALLOC_FREE(values);

        /* now do the values under KEY_EVENTLOG/Application/Application */
        TALLOC_FREE(evtlogpath);
        evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
                                     KEY_EVENTLOG, *elogs, *elogs);
        if (!evtlogpath) {
            return false;
        }
        if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
            DEBUG( 0, ( "talloc() failure!\n" ) );
            return False;
        }
        DEBUG( 5,
               ( "Storing values to eventlog path of [%s]\n",
                 evtlogpath));
        regdb_fetch_values(evtlogpath, values);
        if (!regval_ctr_key_exists( values, "CategoryCount")) {

            /* hard code some initial values */

            uiCategoryCount = 0x00000007;
            regval_ctr_addvalue( values, "CategoryCount",
                                 REG_DWORD,
                                 ( char * ) &uiCategoryCount,
                                 sizeof( uint32 ) );
            init_unistr2( &data,
                          "%SystemRoot%\\system32\\eventlog.dll",
                          UNI_STR_TERMINATE );

            regval_ctr_addvalue( values, "CategoryMessageFile",
                                 REG_EXPAND_SZ,
                                 ( char * ) data.buffer,
                                 data.uni_str_len *
                                 sizeof( uint16 ) );
            regdb_store_values( evtlogpath, values );
        }
        TALLOC_FREE(values);
        elogs++;
    }

    return true;
}
Esempio n. 13
0
bool eventlog_add_source( const char *eventlog, const char *sourcename,
                          const char *messagefile )
{
    /* Find all of the eventlogs, add keys for each of them */
    /* need to add to the value KEY_EVENTLOG/<eventlog>/Sources string (Creating if necessary)
       need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */

    const char **elogs = lp_eventlog_list(  );
    char **wrklist, **wp;
    char *evtlogpath = NULL;
    struct regsubkey_ctr *subkeys;
    REGVAL_CTR *values;
    REGISTRY_VALUE *rval;
    UNISTR2 data;
    uint16 *msz_wp;
    int mbytes, ii;
    bool already_in;
    int i;
    int numsources;
    TALLOC_CTX *ctx = talloc_tos();
    WERROR werr;

    if (!elogs) {
        return False;
    }

    for ( i = 0; elogs[i]; i++ ) {
        if ( strequal( elogs[i], eventlog ) )
            break;
    }

    if ( !elogs[i] ) {
        DEBUG( 0,
               ( "Eventlog [%s] not found in list of valid event logs\n",
                 eventlog ) );
        return false;	/* invalid named passed in */
    }

    /* have to assume that the evenlog key itself exists at this point */
    /* add in a key of [sourcename] under the eventlog key */

    /* todo add to Sources */

    if (!( values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
        DEBUG( 0, ( "talloc() failure!\n" ));
        return false;
    }

    evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
    if (!evtlogpath) {
        TALLOC_FREE(values);
        return false;
    }

    regdb_fetch_values( evtlogpath, values );


    if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
        DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
        return False;
    }
    /* perhaps this adding a new string to a multi_sz should be a fn? */
    /* check to see if it's there already */

    if ( rval->type != REG_MULTI_SZ ) {
        DEBUG( 0,
               ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
        return False;
    }
    /* convert to a 'regulah' chars to do some comparisons */

    already_in = False;
    wrklist = NULL;
    dump_data( 1, rval->data_p, rval->size );
    if ( ( numsources =
                regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
                                         &wrklist ) ) > 0 ) {

        ii = numsources;
        /* see if it's in there already */
        wp = wrklist;

        while ( ii && wp && *wp ) {
            if ( strequal( *wp, sourcename ) ) {
                DEBUG( 5,
                       ( "Source name [%s] already in list for [%s] \n",
                         sourcename, eventlog ) );
                already_in = True;
                break;
            }
            wp++;
            ii--;
        }
    } else {
        if ( numsources < 0 ) {
            DEBUG( 3, ( "problem in getting the sources\n" ) );
            return False;
        }
        DEBUG( 3,
               ( "Nothing in the sources list, this might be a problem\n" ) );
    }

    wp = wrklist;

    if ( !already_in ) {
        /* make a new list with an additional entry; copy values, add another */
        wp = TALLOC_ARRAY(ctx, char *, numsources + 2 );

        if ( !wp ) {
            DEBUG( 0, ( "talloc() failed \n" ) );
            return False;
        }
        memcpy( wp, wrklist, sizeof( char * ) * numsources );
        *( wp + numsources ) = ( char * ) sourcename;
        *( wp + numsources + 1 ) = NULL;
        mbytes = regval_build_multi_sz( wp, &msz_wp );
        dump_data( 1, ( uint8 * ) msz_wp, mbytes );
        regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
                             ( char * ) msz_wp, mbytes );
        regdb_store_values( evtlogpath, values );
        TALLOC_FREE(msz_wp);
    } else {
Esempio n. 14
0
ELOG_TDB *elog_open_tdb( const char *logname, bool force_clear, bool read_only )
{
	TDB_CONTEXT *tdb = NULL;
	uint32_t vers_id;
	ELOG_TDB *ptr;
	char *tdbpath = NULL;
	ELOG_TDB *tdb_node = NULL;
	char *eventlogdir;
	TALLOC_CTX *ctx = talloc_tos();

	/* check for invalid options */

	if (force_clear && read_only) {
		DEBUG(1,("elog_open_tdb: Invalid flags\n"));
		return NULL;
	}

	/* first see if we have an open context */

	for ( ptr=open_elog_list; ptr; ptr=ptr->next ) {
		if ( strequal( ptr->name, logname ) ) {
			ptr->ref_count++;

			/* trick to alow clearing of the eventlog tdb.
			   The force_clear flag should imply that someone
			   has done a force close.  So make sure the tdb
			   is NULL.  If this is a normal open, then just
			   return the existing reference */

			if ( force_clear ) {
				SMB_ASSERT( ptr->tdb == NULL );
				break;
			}
			else
				return ptr;
		}
	}

	/* make sure that the eventlog dir exists */

	eventlogdir = state_path( "eventlog" );
	if ( !directory_exist( eventlogdir ) )
		mkdir( eventlogdir, 0755 );

	/* get the path on disk */

	tdbpath = elog_tdbname(ctx, logname);
	if (!tdbpath) {
		return NULL;
	}

	DEBUG(7,("elog_open_tdb: Opening %s...(force_clear == %s)\n",
		tdbpath, force_clear?"True":"False" ));

	/* the tdb wasn't already open or this is a forced clear open */

	if ( !force_clear ) {

		tdb = tdb_open_log( tdbpath, 0, TDB_DEFAULT, read_only ? O_RDONLY : O_RDWR , 0 );
		if ( tdb ) {
			vers_id = tdb_fetch_int32( tdb, EVT_VERSION );

			if ( vers_id != EVENTLOG_DATABASE_VERSION_V1 ) {
				DEBUG(1,("elog_open_tdb: Invalid version [%d] on file [%s].\n",
					vers_id, tdbpath));
				tdb_close( tdb );
				tdb = elog_init_tdb( tdbpath );
			}
		}
	}

	if ( !tdb )
		tdb = elog_init_tdb( tdbpath );

	/* if we got a valid context, then add it to the list */

	if ( tdb ) {
		/* on a forced clear, just reset the tdb context if we already
		   have an open entry in the list */

		if ( ptr ) {
			ptr->tdb = tdb;
			return ptr;
		}

		if ( !(tdb_node = TALLOC_ZERO_P( NULL, ELOG_TDB)) ) {
			DEBUG(0,("elog_open_tdb: talloc() failure!\n"));
			tdb_close( tdb );
			return NULL;
		}

		tdb_node->name = talloc_strdup( tdb_node, logname );
		tdb_node->tdb = tdb;
		tdb_node->ref_count = 1;

		DLIST_ADD( open_elog_list, tdb_node );
	}

	return tdb_node;
}
Esempio n. 15
0
static NTSTATUS fill_dsrole_dominfo_basic(TALLOC_CTX *ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **info) 
{
	DSROLE_PRIMARY_DOMAIN_INFO_BASIC *basic;
	const char *netbios_domain = "";
	fstring dnsdomain;

	DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));

	if ( !(basic = TALLOC_ZERO_P(ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC)) ) {
		DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error!  talloc_xero() failed\n"));
		return NT_STATUS_NO_MEMORY;
	}

	switch ( lp_server_role() ) {
		case ROLE_STANDALONE:
			basic->machine_role = DSROLE_STANDALONE_SRV;
			basic->netbios_ptr = 1;
			netbios_domain = get_global_sam_name();
			break;
		case ROLE_DOMAIN_MEMBER:
			basic->netbios_ptr = 1;
			netbios_domain = lp_workgroup();
			basic->machine_role = DSROLE_DOMAIN_MEMBER_SRV;
			break;
		case ROLE_DOMAIN_BDC:
			basic->netbios_ptr = 1;
			netbios_domain = get_global_sam_name();
			basic->machine_role = DSROLE_BDC;
			break;
		case ROLE_DOMAIN_PDC:
			basic->netbios_ptr = 1;
			netbios_domain = get_global_sam_name();
			basic->machine_role = DSROLE_PDC;
			break;
	}

	/* always set netbios name */

	init_unistr2( &basic->netbios_domain, netbios_domain, UNI_STR_TERMINATE);

	if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
		basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;

	/* fill in some additional fields if we are a member of an AD domain */

	if ( lp_security() == SEC_ADS ) {
		fstrcpy( dnsdomain, lp_realm() );
		strlower_m( dnsdomain );
		
		basic->dnsname_ptr = 1;
		init_unistr2( &basic->dns_domain, dnsdomain, UNI_STR_TERMINATE);

		/* FIXME!! We really should fill in the correct forest
		   name.  Should get this information from winbindd.  */
		basic->forestname_ptr = 1;
		init_unistr2( &basic->forest_domain, dnsdomain, UNI_STR_TERMINATE);
	} else {
		/* security = domain should not fill in the dns or
		   forest name */
		basic->dnsname_ptr = 0;
		basic->forestname_ptr = 0;
	}

	*info = basic;

	return NT_STATUS_OK;
}
Esempio n. 16
0
WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli,
        TALLOC_CTX *mem_ctx,
        ADS_MODLIST *mods,
        const char *printer)
{
    WERROR result;
    char *printername, *servername;
    REGVAL_CTR *dsdriver_ctr, *dsspooler_ctr;
    uint32 i;
    POLICY_HND pol;

    asprintf(&servername, "\\\\%s", cli->cli->desthost);
    asprintf(&printername, "%s\\%s", servername, printer);
    if (!servername || !printername) {
        DEBUG(3, ("Insufficient memory\n"));
        return WERR_NOMEM;
    }

    result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername,
                                            "", MAXIMUM_ALLOWED_ACCESS,
                                            servername, cli->cli->user_name, &pol);
    if (!W_ERROR_IS_OK(result)) {
        DEBUG(3, ("Unable to open printer %s, error is %s.\n",
                  printername, dos_errstr(result)));
        SAFE_FREE(printername);
        return result;
    }

    if ( !(dsdriver_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) {
        SAFE_FREE(printername);
        return WERR_NOMEM;
    }

    result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, dsdriver_ctr);

    if (!W_ERROR_IS_OK(result)) {
        DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n",
                  printername, dos_errstr(result)));
    } else {
        uint32 num_values = regval_ctr_numvals( dsdriver_ctr );

        /* Have the data we need now, so start building */
        for (i=0; i < num_values; i++) {
            map_regval_to_ads(mem_ctx, mods, dsdriver_ctr->values[i]);
        }
    }

    if ( !(dsspooler_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) {
        SAFE_FREE(printername);
        return WERR_NOMEM;
    }

    result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, dsspooler_ctr);

    if (!W_ERROR_IS_OK(result)) {
        DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n",
                  printername, dos_errstr(result)));
    } else {
        uint32 num_values = regval_ctr_numvals( dsspooler_ctr );

        for (i=0; i<num_values; i++) {
            map_regval_to_ads(mem_ctx, mods, dsspooler_ctr->values[i]);
        }
    }

    ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer);

    TALLOC_FREE( dsdriver_ctr );
    TALLOC_FREE( dsspooler_ctr );

    rpccli_spoolss_close_printer(cli, mem_ctx, &pol);
    SAFE_FREE(printername);

    return result;
}
Esempio n. 17
0
NTSTATUS cli_list_user_quota(struct cli_state *cli, int quota_fnum,
			     SMB_NTQUOTA_LIST **pqt_list)
{
	uint16_t setup[1];
	uint8_t params[16];
	uint8_t *rparam=NULL, *rdata=NULL;
	uint32_t rparam_count=0, rdata_count=0;
	unsigned int offset;
	const uint8_t *curdata = NULL;
	unsigned int curdata_count = 0;
	TALLOC_CTX *mem_ctx = NULL;
	SMB_NTQUOTA_STRUCT qt;
	SMB_NTQUOTA_LIST *tmp_list_ent;
	NTSTATUS status;

	if (!cli||!pqt_list) {
		smb_panic("cli_list_user_quota() called with NULL Pointer!");
	}

	SSVAL(setup + 0, 0, NT_TRANSACT_GET_USER_QUOTA);

	SSVAL(params, 0,quota_fnum);
	SSVAL(params, 2,TRANSACT_GET_USER_QUOTA_LIST_START);
	SIVAL(params, 4,0x00000000);
	SIVAL(params, 8,0x00000000);
	SIVAL(params,12,0x00000000);

	status = cli_trans(talloc_tos(), cli, SMBnttrans,
			   NULL, -1, /* name, fid */
			   NT_TRANSACT_GET_USER_QUOTA, 0,
			   setup, 1, 0, /* setup */
			   params, 16, 4, /* params */
			   NULL, 0, 2048, /* data */
			   NULL,		/* recv_flags2 */
			   NULL, 0, NULL,	/* rsetup */
			   &rparam, 0, &rparam_count,
			   &rdata, 0, &rdata_count);

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("NT_TRANSACT_GET_USER_QUOTA failed: %s\n",
			  nt_errstr(status)));
		goto cleanup;
	}

	if (rdata_count == 0) {
		*pqt_list = NULL;
		return NT_STATUS_OK;
	}

	if ((mem_ctx=talloc_init("SMB_USER_QUOTA_LIST"))==NULL) {
		DEBUG(0,("talloc_init() failed\n"));
		return NT_STATUS_NO_MEMORY;
	}

	offset = 1;
	for (curdata=rdata,curdata_count=rdata_count;
		((curdata)&&(curdata_count>=8)&&(offset>0));
		curdata +=offset,curdata_count -= offset) {
		ZERO_STRUCT(qt);
		if (!parse_user_quota_record((uint8_t *)curdata, curdata_count,
					     &offset, &qt)) {
			DEBUG(1,("Failed to parse the quota record\n"));
			goto cleanup;
		}

		if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
			DEBUG(0,("TALLOC_ZERO() failed\n"));
			talloc_destroy(mem_ctx);
			return NT_STATUS_NO_MEMORY;
		}

		if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
			DEBUG(0,("TALLOC_ZERO() failed\n"));
			talloc_destroy(mem_ctx);
			return NT_STATUS_NO_MEMORY;
		}

		memcpy(tmp_list_ent->quotas,&qt,sizeof(qt));
		tmp_list_ent->mem_ctx = mem_ctx;		

		DLIST_ADD((*pqt_list),tmp_list_ent);
	}

	SSVAL(params, 2,TRANSACT_GET_USER_QUOTA_LIST_CONTINUE);	
	while(1) {

		TALLOC_FREE(rparam);
		TALLOC_FREE(rdata);

		status = cli_trans(talloc_tos(), cli, SMBnttrans,
				   NULL, -1, /* name, fid */
				   NT_TRANSACT_GET_USER_QUOTA, 0,
				   setup, 1, 0, /* setup */
				   params, 16, 4, /* params */
				   NULL, 0, 2048, /* data */
				   NULL,		/* recv_flags2 */
				   NULL, 0, NULL,	/* rsetup */
				   &rparam, 0, &rparam_count,
				   &rdata, 0, &rdata_count);

		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(1, ("NT_TRANSACT_GET_USER_QUOTA failed: %s\n",
				  nt_errstr(status)));
			goto cleanup;
		}

		if (rdata_count == 0) {
			break;
		}

		offset = 1;
		for (curdata=rdata,curdata_count=rdata_count;
			((curdata)&&(curdata_count>=8)&&(offset>0));
			curdata +=offset,curdata_count -= offset) {
			ZERO_STRUCT(qt);
			if (!parse_user_quota_record((uint8_t *)curdata,
						     curdata_count, &offset,
						     &qt)) {
				DEBUG(1,("Failed to parse the quota record\n"));
				goto cleanup;
			}

			if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
				DEBUG(0,("TALLOC_ZERO() failed\n"));
				talloc_destroy(mem_ctx);
				goto cleanup;
			}

			if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
				DEBUG(0,("TALLOC_ZERO() failed\n"));
				talloc_destroy(mem_ctx);
				goto cleanup;
			}

			memcpy(tmp_list_ent->quotas,&qt,sizeof(qt));
			tmp_list_ent->mem_ctx = mem_ctx;		

			DLIST_ADD((*pqt_list),tmp_list_ent);
		}
	}

 cleanup:
	TALLOC_FREE(rparam);
	TALLOC_FREE(rdata);

	return status;
}
Esempio n. 18
0
static NTSTATUS elog_open( pipes_struct * p, const char *logname, struct policy_handle *hnd )
{
	EVENTLOG_INFO *elog;

	/* first thing is to validate the eventlog name */

	if ( !elog_validate_logname( logname ) )
		return NT_STATUS_OBJECT_PATH_INVALID;

	if ( !(elog = TALLOC_ZERO_P( NULL, EVENTLOG_INFO )) )
		return NT_STATUS_NO_MEMORY;
	talloc_set_destructor(elog, eventlog_info_destructor);

	elog->logname = talloc_strdup( elog, logname );

	/* Open the tdb first (so that we can create any new tdbs if necessary).
	   We have to do this as root and then use an internal access check
	   on the file permissions since you can only have a tdb open once
	   in a single process */

	become_root();
	elog->etdb = elog_open_tdb( elog->logname, False, False );
	unbecome_root();

	if ( !elog->etdb ) {
		/* according to MSDN, if the logfile cannot be found, we should
		  default to the "Application" log */

		if ( !strequal( logname, ELOG_APPL ) ) {

			TALLOC_FREE( elog->logname );

			elog->logname = talloc_strdup( elog, ELOG_APPL );

			/* do the access check */
			if ( !elog_check_access( elog, p->server_info->ptok ) ) {
				TALLOC_FREE( elog );
				return NT_STATUS_ACCESS_DENIED;
			}

			become_root();
			elog->etdb = elog_open_tdb( elog->logname, False, False );
			unbecome_root();
		}

		if ( !elog->etdb ) {
			TALLOC_FREE( elog );
			return NT_STATUS_ACCESS_DENIED;	/* ??? */
		}
	}

	/* now do the access check.  Close the tdb if we fail here */

	if ( !elog_check_access( elog, p->server_info->ptok ) ) {
		TALLOC_FREE( elog );
		return NT_STATUS_ACCESS_DENIED;
	}

	/* create the policy handle */

	if ( !create_policy_hnd( p, hnd, elog ) ) {
		TALLOC_FREE(elog);
		return NT_STATUS_NO_MEMORY;
	}

	/* set the initial current_record pointer */

	if ( !get_oldest_entry_hook( elog ) ) {
		DEBUG(3,("elog_open: Successfully opened eventlog but can't "
			"get any information on internal records!\n"));
	}

	elog->current_record = elog->oldest_entry;

	return NT_STATUS_OK;
}
Esempio n. 19
0
int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list)
{
	struct passwd *usr;
	TALLOC_CTX *mem_ctx = NULL;

	if (!fsp||!fsp->conn||!qt_list)
		return (-1);

	*qt_list = NULL;

	if ((mem_ctx=talloc_init("SMB_USER_QUOTA_LIST"))==NULL) {
		DEBUG(0,("talloc_init() failed\n"));
		return (-1);
	}

	sys_setpwent();
	while ((usr = sys_getpwent()) != NULL) {
		SMB_NTQUOTA_STRUCT tmp_qt;
		SMB_NTQUOTA_LIST *tmp_list_ent;
		DOM_SID	sid;

		ZERO_STRUCT(tmp_qt);

		if (allready_in_quota_list((*qt_list),usr->pw_uid)) {
			DEBUG(5,("record for uid[%ld] allready in the list\n",(long)usr->pw_uid));
			continue;
		}

		uid_to_sid(&sid, usr->pw_uid);

		if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &tmp_qt)!=0) {
			DEBUG(5,("no quota entry for sid[%s] path[%s]\n",
				sid_string_static(&sid),fsp->conn->connectpath));
			continue;
		}

		DEBUG(15,("quota entry for id[%s] path[%s]\n",
			sid_string_static(&sid),fsp->conn->connectpath));

		if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
			DEBUG(0,("TALLOC_ZERO() failed\n"));
			*qt_list = NULL;
			talloc_destroy(mem_ctx);
			return (-1);
		}

		if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
			DEBUG(0,("TALLOC_ZERO() failed\n"));
			*qt_list = NULL;
			talloc_destroy(mem_ctx);
			return (-1);
		}

		tmp_list_ent->uid = usr->pw_uid;
		memcpy(tmp_list_ent->quotas,&tmp_qt,sizeof(tmp_qt));
		tmp_list_ent->mem_ctx = mem_ctx;

		DLIST_ADD((*qt_list),tmp_list_ent);
		
	}
	sys_endpwent();

	return 0;
}
Esempio n. 20
0
File: vfs.c Progetto: hajuuk/R7000
BOOL vfs_init_custom(connection_struct *conn, const char *vfs_object)
{
	vfs_op_tuple *ops;
	char *module_name = NULL;
	char *module_param = NULL, *p;
	int i;
	vfs_handle_struct *handle;
	struct vfs_init_function_entry *entry;
	
	if (!conn||!vfs_object||!vfs_object[0]) {
		DEBUG(0,("vfs_init_custon() called with NULL pointer or emtpy vfs_object!\n"));
		return False;
	}

	if(!backends) {
		static_init_vfs;
	}

	DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));

	module_name = smb_xstrdup(vfs_object);

	p = strchr_m(module_name, ':');

	if (p) {
		*p = 0;
		module_param = p+1;
		trim_char(module_param, ' ', ' ');
	}

	trim_char(module_name, ' ', ' ');

	/* First, try to load the module with the new module system */
	if((entry = vfs_find_backend_entry(module_name)) || 
	   (NT_STATUS_IS_OK(smb_probe_module("vfs", module_name)) && 
		(entry = vfs_find_backend_entry(module_name)))) {

		DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
		
	 	if ((ops = entry->vfs_op_tuples) == NULL) {
	 		DEBUG(0, ("entry->vfs_op_tuples==NULL for [%s] failed\n", vfs_object));
	 		SAFE_FREE(module_name);
	 		return False;
	 	}
	} else {
		DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
		SAFE_FREE(module_name);
		return False;
	}

	handle = TALLOC_ZERO_P(conn->mem_ctx,vfs_handle_struct);
	if (!handle) {
		DEBUG(0,("TALLOC_ZERO() failed!\n"));
		SAFE_FREE(module_name);
		return False;
	}
	memcpy(&handle->vfs_next, &conn->vfs, sizeof(struct vfs_ops));
	handle->conn = conn;
	if (module_param) {
		handle->param = talloc_strdup(conn->mem_ctx, module_param);
	}
	DLIST_ADD(conn->vfs_handles, handle);

 	for(i=0; ops[i].op != NULL; i++) {
		DEBUG(5, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
		if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
			/* If this operation was already made opaque by different module, it
			 * will be overridden here.
			 */
			DEBUGADD(5, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
			vfs_set_operation(&conn->vfs_opaque, ops[i].type, handle, ops[i].op);
		}
		/* Change current VFS disposition*/
		DEBUGADD(5, ("Accepting operation type %d from module %s\n", ops[i].type, vfs_object));
		vfs_set_operation(&conn->vfs, ops[i].type, handle, ops[i].op);
	}

	SAFE_FREE(module_name);
	return True;
}
Esempio n. 21
0
WERROR rpccli_svcctl_query_config(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                POLICY_HND *hService, SERVICE_CONFIG *config )
{
	SVCCTL_Q_QUERY_SERVICE_CONFIG in;
	SVCCTL_R_QUERY_SERVICE_CONFIG out;
	prs_struct qbuf, rbuf;
	
	ZERO_STRUCT(in);
	ZERO_STRUCT(out);
	
	memcpy( &in.handle, hService, sizeof(POLICY_HND) );
	in.buffer_size = 0;
	
	
	CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_SERVICE_CONFIG_W, 
	            in, out, 
	            qbuf, rbuf,
	            svcctl_io_q_query_service_config,
	            svcctl_io_r_query_service_config, 
	            WERR_GENERAL_FAILURE );
	
	if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
		in.buffer_size = out.needed;

		CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_SERVICE_CONFIG_W,
		            in, out, 
		            qbuf, rbuf,
		            svcctl_io_q_query_service_config,
		            svcctl_io_r_query_service_config, 
		            WERR_GENERAL_FAILURE );
	}
	
	if ( !W_ERROR_IS_OK( out.status ) )
		return out.status;

	memcpy( config, &out.config, sizeof(SERVICE_CONFIG) );
	
	config->executablepath = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
	config->loadordergroup = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
	config->dependencies   = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
	config->startname      = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
	config->displayname    = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
	
	if ( out.config.executablepath ) {
		config->executablepath = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
		copy_unistr2( config->executablepath, out.config.executablepath );
	}

	if ( out.config.loadordergroup ) {
		config->loadordergroup = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
		copy_unistr2( config->loadordergroup, out.config.loadordergroup );
	}

	if ( out.config.dependencies ) {
		config->dependencies = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
		copy_unistr2( config->dependencies, out.config.dependencies );
	}

	if ( out.config.startname ) {
		config->startname = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
		copy_unistr2( config->startname, out.config.startname );
	}

	if ( out.config.displayname ) {
		config->displayname = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
		copy_unistr2( config->displayname, out.config.displayname );
	}
	
	return out.status;
}
Esempio n. 22
0
bool cli_list_user_quota(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_LIST **pqt_list)
{
	bool ret = False;
	uint16 setup;
	char params[16];
	char *rparam=NULL, *rdata=NULL;
	unsigned int rparam_count=0, rdata_count=0;
	unsigned int offset;
	const char *curdata = NULL;
	unsigned int curdata_count = 0;
	TALLOC_CTX *mem_ctx = NULL;
	SMB_NTQUOTA_STRUCT qt;
	SMB_NTQUOTA_LIST *tmp_list_ent;

	if (!cli||!pqt_list) {
		smb_panic("cli_list_user_quota() called with NULL Pointer!");
	}

	setup = NT_TRANSACT_GET_USER_QUOTA;

	SSVAL(params, 0,quota_fnum);
	SSVAL(params, 2,TRANSACT_GET_USER_QUOTA_LIST_START);
	SIVAL(params, 4,0x00000000);
	SIVAL(params, 8,0x00000000);
	SIVAL(params,12,0x00000000);

	if (!cli_send_nt_trans(cli, 
			       NT_TRANSACT_GET_USER_QUOTA, 
			       0, 
			       &setup, 1, 0,
			       params, 16, 4,
			       NULL, 0, 2048)) {
		DEBUG(1,("Failed to send NT_TRANSACT_GET_USER_QUOTA\n"));
		goto cleanup;
	}


	if (!cli_receive_nt_trans(cli,
				  &rparam, &rparam_count,
				  &rdata, &rdata_count)) {
		DEBUG(1,("Failed to recv NT_TRANSACT_GET_USER_QUOTA\n"));
		goto cleanup;
	}

	if (cli_is_error(cli)) {
		ret = False;
		goto cleanup;
	} else {
		ret = True;
	}

	if (rdata_count == 0) {
		*pqt_list = NULL;
		return True;
	}

	if ((mem_ctx=talloc_init("SMB_USER_QUOTA_LIST"))==NULL) {
		DEBUG(0,("talloc_init() failed\n"));
		return (-1);
	}

	offset = 1;
	for (curdata=rdata,curdata_count=rdata_count;
		((curdata)&&(curdata_count>=8)&&(offset>0));
		curdata +=offset,curdata_count -= offset) {
		ZERO_STRUCT(qt);
		if (!parse_user_quota_record(curdata, curdata_count, &offset, &qt)) {
			DEBUG(1,("Failed to parse the quota record\n"));
			goto cleanup;
		}

		if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
			DEBUG(0,("TALLOC_ZERO() failed\n"));
			talloc_destroy(mem_ctx);
			return (-1);
		}

		if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
			DEBUG(0,("TALLOC_ZERO() failed\n"));
			talloc_destroy(mem_ctx);
			return (-1);
		}

		memcpy(tmp_list_ent->quotas,&qt,sizeof(qt));
		tmp_list_ent->mem_ctx = mem_ctx;		

		DLIST_ADD((*pqt_list),tmp_list_ent);
	}

	SSVAL(params, 2,TRANSACT_GET_USER_QUOTA_LIST_CONTINUE);	
	while(1) {
		if (!cli_send_nt_trans(cli, 
				       NT_TRANSACT_GET_USER_QUOTA, 
				       0, 
				       &setup, 1, 0,
				       params, 16, 4,
				       NULL, 0, 2048)) {
			DEBUG(1,("Failed to send NT_TRANSACT_GET_USER_QUOTA\n"));
			goto cleanup;
		}

		SAFE_FREE(rparam);
		SAFE_FREE(rdata);
		if (!cli_receive_nt_trans(cli,
					  &rparam, &rparam_count,
					  &rdata, &rdata_count)) {
			DEBUG(1,("Failed to recv NT_TRANSACT_GET_USER_QUOTA\n"));
			goto cleanup;
		}

		if (cli_is_error(cli)) {
			ret = False;
			goto cleanup;
		} else {
			ret = True;
		}

		if (rdata_count == 0) {
			break;	
		}

		offset = 1;
		for (curdata=rdata,curdata_count=rdata_count;
			((curdata)&&(curdata_count>=8)&&(offset>0));
			curdata +=offset,curdata_count -= offset) {
			ZERO_STRUCT(qt);
			if (!parse_user_quota_record(curdata, curdata_count, &offset, &qt)) {
				DEBUG(1,("Failed to parse the quota record\n"));
				goto cleanup;
			}

			if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
				DEBUG(0,("TALLOC_ZERO() failed\n"));
				talloc_destroy(mem_ctx);
				goto cleanup;
			}

			if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
				DEBUG(0,("TALLOC_ZERO() failed\n"));
				talloc_destroy(mem_ctx);
				goto cleanup;
			}

			memcpy(tmp_list_ent->quotas,&qt,sizeof(qt));
			tmp_list_ent->mem_ctx = mem_ctx;		

			DLIST_ADD((*pqt_list),tmp_list_ent);
		}
	}


	ret = True;
 cleanup:
	SAFE_FREE(rparam);
	SAFE_FREE(rdata);

	return ret;
}
Esempio n. 23
0
SEC_DESC *make_sec_desc(TALLOC_CTX *ctx,
			enum security_descriptor_revision revision,
			uint16 type,
			const DOM_SID *owner_sid, const DOM_SID *grp_sid,
			SEC_ACL *sacl, SEC_ACL *dacl, size_t *sd_size)
{
	SEC_DESC *dst;
	uint32 offset     = 0;

	*sd_size = 0;

	if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)
		return NULL;

	dst->revision = revision;
	dst->type = type;

	if (sacl)
		dst->type |= SEC_DESC_SACL_PRESENT;
	if (dacl)
		dst->type |= SEC_DESC_DACL_PRESENT;

	dst->owner_sid = NULL;
	dst->group_sid   = NULL;
	dst->sacl      = NULL;
	dst->dacl      = NULL;

	if(owner_sid && ((dst->owner_sid = sid_dup_talloc(dst,owner_sid)) == NULL))
		goto error_exit;

	if(grp_sid && ((dst->group_sid = sid_dup_talloc(dst,grp_sid)) == NULL))
		goto error_exit;

	if(sacl && ((dst->sacl = dup_sec_acl(dst, sacl)) == NULL))
		goto error_exit;

	if(dacl && ((dst->dacl = dup_sec_acl(dst, dacl)) == NULL))
		goto error_exit;

	offset = SEC_DESC_HEADER_SIZE;

	/*
	 * Work out the linearization sizes.
	 */

	if (dst->sacl != NULL) {
		offset += dst->sacl->size;
	}
	if (dst->dacl != NULL) {
		offset += dst->dacl->size;
	}

	if (dst->owner_sid != NULL) {
		offset += ndr_size_dom_sid(dst->owner_sid, 0);
	}

	if (dst->group_sid != NULL) {
		offset += ndr_size_dom_sid(dst->group_sid, 0);
	}

	*sd_size = (size_t)offset;
	return dst;

error_exit:

	*sd_size = 0;
	return NULL;
}
Esempio n. 24
0
BOOL regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr )
{
	int num_subkeys, i;
	pstring path;
	REGSUBKEY_CTR *subkeys, *old_subkeys;
	char *oldkeyname;
	
	/* fetch a list of the old subkeys so we can determine if any were deleted */
	
	if ( !(old_subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {
		DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
		return False;
	}

	regdb_fetch_keys( key, old_subkeys );
	
	/* store the subkey list for the parent */
	
	if ( !regdb_store_keys_internal( key, ctr ) ) {
		DEBUG(0,("regdb_store_keys: Failed to store new subkey list for parent [%s}\n", key ));
		return False;
	}
	
	/* now delete removed keys */
	
	num_subkeys = regsubkey_ctr_numkeys( old_subkeys );
	for ( i=0; i<num_subkeys; i++ ) {
		oldkeyname = regsubkey_ctr_specific_key( old_subkeys, i );
		if ( !regsubkey_ctr_key_exists( ctr, oldkeyname ) ) {
			pstr_sprintf( path, "%s%c%s", key, '/', oldkeyname );
			normalize_reg_path( path );
			tdb_delete_bystring( tdb_reg, path );
		}
	}

	TALLOC_FREE( old_subkeys );
	
	/* now create records for any subkeys that don't already exist */
	
	num_subkeys = regsubkey_ctr_numkeys( ctr );
	for ( i=0; i<num_subkeys; i++ ) {
		pstr_sprintf( path, "%s%c%s", key, '/', regsubkey_ctr_specific_key( ctr, i ) );

		if ( !(subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {
			DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
			return False;
		}

		if ( regdb_fetch_keys( path, subkeys ) == -1 ) {
			/* create a record with 0 subkeys */
			if ( !regdb_store_keys_internal( path, subkeys ) ) {
				DEBUG(0,("regdb_store_keys: Failed to store new record for key [%s}\n", path ));
				TALLOC_FREE( subkeys );
				return False;
			}
		}

		TALLOC_FREE( subkeys );
	}
	
	return True;
}
Esempio n. 25
0
static NTSTATUS fill_dsrole_dominfo_basic(TALLOC_CTX *ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **info) 
{
	DSROLE_PRIMARY_DOMAIN_INFO_BASIC *basic;
	const char *netbios_domain;
	fstring dnsdomain;

	DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));

	if ( !(basic = TALLOC_ZERO_P(ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC)) ) {
		DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error!  talloc_xero() failed\n"));
		return NT_STATUS_NO_MEMORY;
	}

	get_mydnsdomname(dnsdomain);
	strlower_m(dnsdomain);

	switch ( lp_server_role() ) {
		case ROLE_STANDALONE:
			basic->machine_role = DSROLE_STANDALONE_SRV;
			break;
		case ROLE_DOMAIN_MEMBER:
			basic->machine_role = DSROLE_DOMAIN_MEMBER_SRV;
			break;
		case ROLE_DOMAIN_BDC:
			basic->machine_role = DSROLE_BDC;
			basic->flags = DSROLE_PRIMARY_DS_RUNNING|DSROLE_PRIMARY_DS_MIXED_MODE;
			if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
				basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;
			break;
		case ROLE_DOMAIN_PDC:
			basic->machine_role = DSROLE_PDC;
			basic->flags = DSROLE_PRIMARY_DS_RUNNING|DSROLE_PRIMARY_DS_MIXED_MODE;
			if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
				basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;
			break;
	}

	basic->unknown = 0x6173;		/* seen on the wire; maybe padding */

	/* always set netbios name */

	basic->netbios_ptr = 1;
	netbios_domain = get_global_sam_name();
	init_unistr2( &basic->netbios_domain, netbios_domain, UNI_FLAGS_NONE);

	basic->dnsname_ptr = 1;
	init_unistr2( &basic->dns_domain, dnsdomain, UNI_FLAGS_NONE);
	basic->forestname_ptr = 1;
	init_unistr2( &basic->forest_domain, dnsdomain, UNI_FLAGS_NONE);
	

	/* fill in some additional fields if we are a member of an AD domain */

	if ( lp_security() == SEC_ADS ) {	
		/* TODO */
		;;
	}

	*info = basic;

	return NT_STATUS_OK;
}
Esempio n. 26
0
static BOOL init_registry_data( void )
{
	pstring path, base, remaining;
	fstring keyname, subkeyname;
	REGSUBKEY_CTR *subkeys;
	REGVAL_CTR *values;
	int i;
	const char *p, *p2;
	UNISTR2 data;

	/*
	 * There are potentially quite a few store operations which are all
	 * indiviually wrapped in tdb transactions. Wrapping them in a single
	 * transaction gives just a single transaction_commit() to actually do
	 * its fsync()s. See tdb/common/transaction.c for info about nested
	 * transaction behaviour.
	 */

	if ( tdb_transaction_start( tdb_reg ) == -1 ) {
		DEBUG(0, ("init_registry_data: tdb_transaction_start "
			  "failed\n"));
		return False;
	}
	
	/* loop over all of the predefined paths and add each component */
	
	for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {

		DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));

		pstrcpy( path, builtin_registry_paths[i] );
		pstrcpy( base, "" );
		p = path;
		
		while ( next_token(&p, keyname, "\\", sizeof(keyname)) ) {
		
			/* build up the registry path from the components */
			
			if ( *base )
				pstrcat( base, "\\" );
			pstrcat( base, keyname );
			
			/* get the immediate subkeyname (if we have one ) */
			
			*subkeyname = '\0';
			if ( *p ) {
				pstrcpy( remaining, p );
				p2 = remaining;
				
				if ( !next_token(&p2, subkeyname, "\\", sizeof(subkeyname)) )
					fstrcpy( subkeyname, p2 );
			}

			DEBUG(10,("init_registry_data: Storing key [%s] with subkey [%s]\n",
				base, *subkeyname ? subkeyname : "NULL"));
			
			/* we don't really care if the lookup succeeds or not since
			   we are about to update the record.  We just want any 
			   subkeys already present */
			
			if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
				DEBUG(0,("talloc() failure!\n"));
				goto fail;
			}

			regdb_fetch_keys( base, subkeys );
			if ( *subkeyname ) 
				regsubkey_ctr_addkey( subkeys, subkeyname );
			if ( !regdb_store_keys( base, subkeys ))
				goto fail;
			
			TALLOC_FREE( subkeys );
		}
	}

	/* loop over all of the predefined values and add each component */
	
	for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
		if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
			DEBUG(0,("talloc() failure!\n"));
			goto fail;
		}

		regdb_fetch_values( builtin_registry_values[i].path, values );

		/* preserve existing values across restarts.  Only add new ones */

		if ( !regval_ctr_key_exists( values, builtin_registry_values[i].valuename ) ) 
		{
			switch( builtin_registry_values[i].type ) {
			case REG_DWORD:
				regval_ctr_addvalue( values, 
				                     builtin_registry_values[i].valuename,
						     REG_DWORD,
						     (char*)&builtin_registry_values[i].data.dw_value,
						     sizeof(uint32) );
				break;
				
			case REG_SZ:
				init_unistr2( &data, builtin_registry_values[i].data.string, UNI_STR_TERMINATE);
				regval_ctr_addvalue( values, 
				                     builtin_registry_values[i].valuename,
						     REG_SZ,
						     (char*)data.buffer,
						     data.uni_str_len*sizeof(uint16) );
				break;
			
			default:
				DEBUG(0,("init_registry_data: invalid value type in builtin_registry_values [%d]\n",
					builtin_registry_values[i].type));
			}
			regdb_store_values( builtin_registry_values[i].path, values );
		}
		
		TALLOC_FREE( values );
	}
	
	if (tdb_transaction_commit( tdb_reg ) == -1) {
		DEBUG(0, ("init_registry_data: Could not commit "
			  "transaction\n"));
		return False;
	}

	return True;

 fail:

	if (tdb_transaction_cancel( tdb_reg ) == -1) {
		smb_panic("init_registry_data: tdb_transaction_cancel "
			  "failed\n");
	}

	return False;
}
Esempio n. 27
0
bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
{
	char *module_path = NULL;
	char *module_name = NULL;
	char *module_param = NULL, *p;
	vfs_handle_struct *handle;
	const struct vfs_init_function_entry *entry;

	if (!conn||!vfs_object||!vfs_object[0]) {
		DEBUG(0,("vfs_init_custon() called with NULL pointer or emtpy vfs_object!\n"));
		return False;
	}

	if(!backends) {
		static_init_vfs;
	}

	DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));

	module_path = smb_xstrdup(vfs_object);

	p = strchr_m(module_path, ':');

	if (p) {
		*p = 0;
		module_param = p+1;
		trim_char(module_param, ' ', ' ');
	}

	trim_char(module_path, ' ', ' ');

	module_name = smb_xstrdup(module_path);

	if ((module_name[0] == '/') &&
	    (strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {

		/*
		 * Extract the module name from the path. Just use the base
		 * name of the last path component.
		 */

		SAFE_FREE(module_name);
		module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);

		p = strchr_m(module_name, '.');

		if (p != NULL) {
			*p = '\0';
		}
	}

	/* First, try to load the module with the new module system */
	entry = vfs_find_backend_entry(module_name);
	if (!entry) {
		NTSTATUS status;

		DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
			  vfs_object));

		status = smb_probe_module("vfs", module_path);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(0, ("error probing vfs module '%s': %s\n",
				  module_path, nt_errstr(status)));
			goto fail;
		}

		entry = vfs_find_backend_entry(module_name);
		if (!entry) {
			DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
			goto fail;
		}
	}

	DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));

	handle = TALLOC_ZERO_P(conn, vfs_handle_struct);
	if (!handle) {
		DEBUG(0,("TALLOC_ZERO() failed!\n"));
		goto fail;
	}
	handle->conn = conn;
	handle->fns = entry->fns;
	if (module_param) {
		handle->param = talloc_strdup(conn, module_param);
	}
	DLIST_ADD(conn->vfs_handles, handle);

	SAFE_FREE(module_path);
	SAFE_FREE(module_name);
	return True;

 fail:
	SAFE_FREE(module_path);
	SAFE_FREE(module_name);
	return False;
}