@@ -203,6 +203,98 @@ async def list_group_members(self, domain_name:str, group_name:str) -> AsyncGene
203203 except Exception as e :
204204 yield None , None , None , e
205205
206+ async def add_new_user (self , domain_name :str , user_name :str , password :str ):
207+ try :
208+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
209+ if domain_name is None or domain_name == '' or domain_name == 'Builtin' :
210+ dhandle , err = await samrpc .openBuiltinDomain ()
211+ else :
212+ dhandle , err = await samrpc .open_domain_by_name (domain_name )
213+ if err is not None :
214+ raise err
215+
216+ _ , err = await samrpc .create_user (dhandle , user_name , password )
217+ if err is not None :
218+ raise err
219+ return True , None
220+
221+ except Exception as e :
222+ return None , e
223+
224+ async def enable_user (self , domain_name :str , user_name :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
225+ try :
226+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
227+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
228+ return await samrpc .enable_account (uhandle )
229+
230+ except Exception as e :
231+ import traceback
232+ traceback .print_exc ()
233+ return None , e
234+
235+ async def disable_user (self , domain_name :str , user_name :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
236+ try :
237+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
238+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
239+ return await samrpc .disable_account (uhandle )
240+ except Exception as e :
241+ return None , e
242+
243+ async def delete_user (self , domain_name :str , user_name :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
244+ try :
245+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
246+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
247+ return await samrpc .disable_account (uhandle )
248+
249+ except Exception as e :
250+ return None , e
251+
252+ async def change_user_password (self , domain_name :str , user_name :str , old_password :str , new_password :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
253+ try :
254+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
255+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
256+ return await samrpc .change_account_password (uhandle , old_password , new_password )
257+
258+ except Exception as e :
259+ return None , e
260+
261+ async def change_user_password_nt (self , domain_name :str , user_name :str , old_pw_hash :str , new_password :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
262+ try :
263+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
264+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
265+ return await samrpc .change_account_password_nt (uhandle , old_pw_hash , new_password )
266+
267+ except Exception as e :
268+ return None , e
269+
270+ async def change_user_password_new (self , domain_name :str , user_name :str , new_password :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
271+ try :
272+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
273+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
274+ return await samrpc .change_account_password_4 (uhandle , new_password )
275+
276+ except Exception as e :
277+ return None , e
278+
279+
280+ async def change_user_password_internal (self , domain_name :str , user_name :str , new_password :str ) -> Awaitable [Tuple [str , Union [Exception , None ]]]:
281+ try :
282+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
283+ async with samrpc .get_user_handle (domain_name , user_name ) as uhandle :
284+ return await samrpc .change_account_password_internal (uhandle , new_password )
285+
286+ except Exception as e :
287+ return None , e
288+
289+ async def list_users_allowed_to_replicate (self , domain_name :str ):
290+ try :
291+ async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
292+ async for name , sid , rid , err in samrpc .list_users_allowed_to_replicate (domain_name ):
293+ yield name , sid , rid , err
294+ except Exception as e :
295+ yield None , None , None , err
296+
297+
206298 async def add_sid_to_group (self , domain_name :str , group_name :str , sid :str ) -> Awaitable [Tuple [bool , Union [Exception , None ]]]:
207299 try :
208300 async with samrrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as samrpc :
@@ -372,6 +464,13 @@ async def list_services(self) -> AsyncGenerator[Tuple[SMBService, Union[Exceptio
372464 except Exception as e :
373465 yield None , e
374466
467+ async def get_service_config (self , service_name :str ) -> Awaitable [Tuple [ServiceStatus , Union [Exception , None ]]]:
468+ try :
469+ async with remsvcrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as rpc :
470+ return await rpc .get_config (service_name )
471+ except Exception as e :
472+ return None , e
473+
375474 async def enable_service (self , service_name :str ) -> Awaitable [Tuple [bool , Union [Exception , None ]]]:
376475 try :
377476 async with remsvcrpc_from_smb (self .connection , auth_level = self .force_rpc_auth ) as rpc :
0 commit comments