NT_USER_TOKEN *get_root_nt_token( void )
{
- struct nt_user_token *token = NULL;
+ struct nt_user_token *token, *for_cache;
DOM_SID u_sid, g_sid;
struct passwd *pw;
void *cache_data;
cache_data = memcache_lookup_talloc(
NULL, SINGLETON_CACHE_TALLOC,
- data_blob_string_const("root_nt_token"));
+ data_blob_string_const_null("root_nt_token"));
if (cache_data != NULL) {
return talloc_get_type_abort(
cache_data, struct nt_user_token);
}
- if ( !(pw = sys_getpwnam( "root" )) ) {
- DEBUG(0,("get_root_nt_token: getpwnam(\"root\") failed!\n"));
- return NULL;
+ if ( !(pw = sys_getpwuid(0)) ) {
+ if ( !(pw = sys_getpwnam("root")) ) {
+ DEBUG(0,("get_root_nt_token: both sys_getpwuid(0) "
+ "and sys_getpwnam(\"root\") failed!\n"));
+ return NULL;
+ }
}
/* get the user and primary group SIDs; although the
uid_to_sid(&u_sid, pw->pw_uid);
gid_to_sid(&g_sid, pw->pw_gid);
- token = create_local_nt_token(NULL, &u_sid, False,
+ token = create_local_nt_token(talloc_autofree_context(), &u_sid, False,
1, &global_sid_Builtin_Administrators);
token->privileges = se_disk_operators;
+ for_cache = token;
+
memcache_add_talloc(
NULL, SINGLETON_CACHE_TALLOC,
- data_blob_string_const("root_nt_token"), token);
+ data_blob_string_const_null("root_nt_token"), &for_cache);
return token;
}
{
NTSTATUS status;
DOM_SID dom_admins, root_sid;
+ fstring root_name;
enum lsa_SidType type;
TALLOC_CTX *ctx;
bool ret;
if ( (ctx = talloc_init("create_builtin_administrators")) == NULL ) {
return NT_STATUS_NO_MEMORY;
}
- ret = lookup_domain_name(ctx, get_global_sam_name(), "root",
- LOOKUP_NAME_DOMAIN,
- NULL, NULL, &root_sid, &type);
+ fstr_sprintf( root_name, "%s\\root", get_global_sam_name() );
+ ret = lookup_name(ctx, root_name, LOOKUP_NAME_DOMAIN, NULL, NULL,
+ &root_sid, &type);
TALLOC_FREE( ctx );
if ( ret ) {