Annotation of /tags/mkinitrd-6_3_1/busybox/loginutils/deluser.c
Parent Directory | Revision Log
Revision 532 -
(hide annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (17 years ago) by niro
Original Path: trunk/mkinitrd-magellan/busybox/loginutils/deluser.c
File MIME type: text/plain
File size: 1878 byte(s)
Sat Sep 1 22:45:15 2007 UTC (17 years ago) by niro
Original Path: trunk/mkinitrd-magellan/busybox/loginutils/deluser.c
File MIME type: text/plain
File size: 1878 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * deluser (remove lusers from the system ;) for TinyLogin | ||
4 | * | ||
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> | ||
8 | * | ||
9 | * Licensed under GPL version 2, see file LICENSE in this tarball for details. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include "busybox.h" | ||
14 | |||
15 | static void del_line_matching(const char *login, const char *filename) | ||
16 | { | ||
17 | char *line; | ||
18 | FILE *passwd; | ||
19 | int len = strlen(login); | ||
20 | int found = 0; | ||
21 | llist_t *plist = NULL; | ||
22 | |||
23 | passwd = fopen_or_warn(filename, "r"); | ||
24 | if (!passwd) return; | ||
25 | |||
26 | while ((line = xmalloc_fgets(passwd))) { | ||
27 | if (!strncmp(line, login, len) | ||
28 | && line[len] == ':' | ||
29 | ) { | ||
30 | found++; | ||
31 | free(line); | ||
32 | } else { | ||
33 | llist_add_to_end(&plist, line); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | if (!ENABLE_FEATURE_CLEAN_UP) { | ||
38 | if (!found) { | ||
39 | bb_error_msg("can't find '%s' in '%s'", login, filename); | ||
40 | return; | ||
41 | } | ||
42 | passwd = fopen_or_warn(filename, "w"); | ||
43 | if (passwd) | ||
44 | while ((line = llist_pop(&plist))) | ||
45 | fputs(line, passwd); | ||
46 | } else { | ||
47 | if (!found) { | ||
48 | bb_error_msg("can't find '%s' in '%s'", login, filename); | ||
49 | goto clean_up; | ||
50 | } | ||
51 | fclose(passwd); | ||
52 | passwd = fopen_or_warn(filename, "w"); | ||
53 | if (passwd) { | ||
54 | clean_up: | ||
55 | while ((line = llist_pop(&plist))) { | ||
56 | if (found) fputs(line, passwd); | ||
57 | free(line); | ||
58 | } | ||
59 | fclose(passwd); | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | int deluser_main(int argc, char **argv) | ||
65 | { | ||
66 | if (argc != 2) | ||
67 | bb_show_usage(); | ||
68 | |||
69 | if (ENABLE_DELUSER | ||
70 | && (!ENABLE_DELGROUP || applet_name[3] == 'u') | ||
71 | ) { | ||
72 | del_line_matching(argv[1], bb_path_passwd_file); | ||
73 | if (ENABLE_FEATURE_SHADOWPASSWDS) | ||
74 | del_line_matching(argv[1], bb_path_shadow_file); | ||
75 | } | ||
76 | del_line_matching(argv[1], bb_path_group_file); | ||
77 | if (ENABLE_FEATURE_SHADOWPASSWDS) | ||
78 | del_line_matching(argv[1], bb_path_gshadow_file); | ||
79 | |||
80 | return EXIT_SUCCESS; | ||
81 | } | ||
82 | |||
83 | /* $Id: deluser.c,v 1.1 2007-09-01 22:43:52 niro Exp $ */ |