VMware {code} Community
tanishsr
Contributor
Contributor

Create super user on ESX/ESXi

Hi,

Using " useradd -o -u 0 TestUser " , I am able to create a user with Uid 0 ( which is same as root Uid). I want to implement same functionality using web services sdk.

Here is the code using to create root user :

szNewUsername = "TestUser";

szNewPassword = "TestUserPassword";

ServiceContent sic = new ServiceContent();

sic = oVimWrapper.GetServiceContent();

VimService service = oVimWrapper.GetVimService();

ManagedObjectReference root = oVimWrapper.GetRootFolder();

ManagedObjectReference morAccManager = sic.accountManager;

ManagedObjectReference morAuthManager = sic.authorizationManager;

if (morAccManager == null || morAuthManager == null)

{

return false;

}

HostPosixAccountSpec hostAccountSpec = new HostPosixAccountSpec();

hostAccountSpec.posixId = 0;

hostAccountSpec.posixIdSpecified = true;

hostAccountSpec.id = szNewUsername;

hostAccountSpec.password = szNewPassword;

hostAccountSpec.shellAccess = true;

hostAccountSpec.shellAccessSpecified = true;

try

{

service.CreateUser(morAccManager, hostAccountSpec);

service.AssignUserToGroup(morAccManager, szNewUsername, "root");

Permission per = new Permission();

per.group = false;

per.principal = szNewUsername;

per.roleId = -1;

per.propagate = true;

per.entity = sic.rootFolder;

service.SetEntityPermissions(morAuthManager, root, new Permission[] { per });

}

catch (System.Web.Services.Protocols.SoapException se)

{

MessageBox.Show(se.Message);

}

On executing the code its throwing an exception " The specified key, name, or identifier already exists. " . If I commented out the posixid line then it works, creates TestUser ( Uid is different, not 0 , requirement is : TestUser Uid = 0 ). Is it possible to create user with uid = 0 using api?

-regards,

Tanish

0 Kudos
2 Replies
storm27
Enthusiast
Enthusiast

Hi,

I tried creating another root user(with UUID = 0) through vSphere Client instead of code and it gave the same error- "the specified key, name already exists". It means that it is not possible to create another user with UUID = 0 on the ESX host through VI APIs. Some operations are only possible through service console and not through APIs, as you mentioned that you can perform the same operation through service console.

- Angela

tanishsr
Contributor
Contributor

Hi,

thanks a lot for reply.

-regards,

Tanish

0 Kudos