Initial revision
[shells] / ushell.c
1 /* -*-c-*-
2 *
3 * $Id: ushell.c,v 1.1 1999/04/20 00:19:04 mdw Exp $
4 *
5 * Extract a user's shell
6 *
7 * (c) 1999 Mark Wooding
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of ushell.
13 *
14 * ushell is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * ushell is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with ushell; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: ushell.c,v $
32 * Revision 1.1 1999/04/20 00:19:04 mdw
33 * Initial revision
34 *
35 */
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #include <errno.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <pwd.h>
44 #include <sys/types.h>
45 #include <unistd.h>
46
47 /*----- Main code ---------------------------------------------------------*/
48
49 static const char *quis;
50
51 int main(int argc, char *argv[])
52 {
53 struct passwd *pw;
54
55 /* --- Resolve the program name --- */
56
57 {
58 char *p, *q;
59 p = argv[0];
60 for (q = argv[0]; *q; q++) {
61 if (*q == '/')
62 p = q + 1;
63 }
64 quis = p;
65 }
66
67 /* --- Get the argument name --- */
68
69 if (argc != 2) {
70 fprintf(stderr, "Usage: %s username\n", quis);
71 exit(EXIT_FAILURE);
72 }
73
74 /* --- Read the user information --- */
75
76 if ((pw = getpwnam(argv[1])) == 0) {
77 fprintf(stderr, "%s: user `%s' doesn't exist", quis, argv[1]);
78 exit(EXIT_FAILURE);
79 }
80
81 /* --- Done --- */
82
83 puts(pw->pw_shell);
84 return (0);
85 }
86
87 /*----- That's all, folks -------------------------------------------------*/