1 /* vi: set sw=4 ts=4: */
3 * deluser (remove lusers from the system ;) for TinyLogin
5 * Copyright (C) 1999 by Lineo, inc. and John Beppu
6 * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org>
7 * Unified with delgroup by Tito Ragusa <farmatito@tiscali.it>
9 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
15 static void del_line_matching(const char *login, const char *filename)
19 int len = strlen(login);
21 llist_t *plist = NULL;
23 passwd = fopen_or_warn(filename, "r");
26 while ((line = xmalloc_fgets(passwd))) {
27 if (!strncmp(line, login, len)
33 llist_add_to_end(&plist, line);
38 bb_error_msg("can't find '%s' in '%s'", login, filename);
39 if (!ENABLE_FEATURE_CLEAN_UP) return;
43 if (ENABLE_FEATURE_CLEAN_UP)
46 passwd = fopen_or_warn(filename, "w");
48 if (ENABLE_FEATURE_CLEAN_UP) {
50 while ((line = llist_pop(&plist))) {
51 if (found) fputs(line, passwd);
56 /* found != 0 here, no need to check */
57 while ((line = llist_pop(&plist)))
63 int deluser_main(int argc, char **argv)
69 && (!ENABLE_DELGROUP || applet_name[3] == 'u')
71 del_line_matching(argv[1], bb_path_passwd_file);
72 if (ENABLE_FEATURE_SHADOWPASSWDS)
73 del_line_matching(argv[1], bb_path_shadow_file);
75 del_line_matching(argv[1], bb_path_group_file);
76 if (ENABLE_FEATURE_SHADOWPASSWDS)
77 del_line_matching(argv[1], bb_path_gshadow_file);
82 /* $Id: deluser.c,v 1.4 2003/07/14 20:20:45 andersen Exp $ */