306 static PyObject *py_sss_userdel(PySssLocalObject *self,
307 PyObject *args,
308 PyObject *kwds)
309 {
310 struct tools_ctx *tctx = NULL;
311 char *username = NULL;
312 int ret;
313 PyObject *py_remove = Py_None;
314 int remove_home = 0;
315 PyObject *py_force = Py_None;
316 const char * const kwlist[] = { "username", "remove", "force", NULL };
317
318 if(!PyArg_ParseTupleAndKeywords(args, kwds,
319 discard_const_p(char, "s|O!O!"),
when PyArg_ParseTupleAndKeywords() succeeds
taking False path
320 discard_const_p(char *, kwlist),
321 &username,
322 &PyBool_Type,
323 &py_remove,
324 &PyBool_Type,
325 &py_force)) {
326 goto fail;
327 }
328
329 tctx = init_ctx(self->mem_ctx, self);
330 if (!tctx) {
331 PyErr_NoMemory();
when treating unknown struct tools_ctx * from src/python/pysss.c:330 as non-NULL
taking False path
332 return NULL;
333 }
334
335 tctx->octx->name = username;
336
when treating unknown struct ops_ctx * from src/python/pysss.c:336 as non-NULL
337 if (py_remove == Py_True) {
338 remove_home = DO_REMOVE_HOME;
taking False path
339 } else if (py_remove == Py_False) {
340 remove_home = DO_NOT_REMOVE_HOME;
taking False path
341 }
342
343 /*
344 * Fills in defaults for ops_ctx user did not specify.
345 */
346 ret = userdel_defaults(tctx,
347 tctx->confdb,
348 tctx->octx,
349 remove_home);
350 if (ret != EOK) {
351 PyErr_SetSssError(ret);
when considering value == (int)0 from src/python/pysss.c:347
taking False path
352 goto fail;
353 }
354
355 ret = run_userdel_cmd(tctx);
356 if (ret != EOK) {
357 PyErr_SetSssError(ret);
when considering value == (int)0 from src/python/pysss.c:356
taking False path
358 goto fail;
359 }
360
361 if (tctx->octx->remove_homedir) {
362 ret = sysdb_getpwnam_sync(tctx,
when treating unknown struct ops_ctx * from src/python/pysss.c:362 as non-NULL
when taking False path
363 tctx->sysdb,
364 tctx->octx->name,
365 tctx->local,
366 tctx->octx);
367 if (ret != EOK) {
368 PyErr_SetSssError(ret);
369 goto fail;
370 }
371 }
372
373 /* Delete the user */
374 ret = userdel(tctx, self->sysdb, tctx->octx);
375 if (ret != EOK) {
376 PyErr_SetSssError(ret);
when considering range: -0x80000000 <= value <= -1
taking True path
377 goto fail;
378 }
379
380 if (tctx->octx->remove_homedir) {
381 ret = remove_homedir(tctx,
382 tctx->octx->home,
383 tctx->octx->maildir,
384 tctx->octx->name,
385 tctx->octx->uid,
386 (py_force == Py_True));
387 if (ret != EOK) {
388 PyErr_SetSssError(ret);
389 goto fail;
390 }
391 }
392
393 talloc_zfree(tctx);
394 Py_RETURN_NONE;
395
396 fail:
397 talloc_zfree(tctx);
398 return NULL;
399 }
400