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