28e8164e |
1 | /* -*-c-*- |
2 | * |
ffe3ac31 |
3 | * $Id: cvssh.c,v 1.2 1999/04/21 09:07:55 mdw Exp $ |
28e8164e |
4 | * |
5 | * Login shell for an anonymous CVS user |
6 | * |
7 | * (c) 1999 Mark Wooding |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
ffe3ac31 |
12 | * This program is free software; you can redistribute it and/or modify |
28e8164e |
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 | * |
ffe3ac31 |
17 | * This program is distributed in the hope that it will be useful, |
28e8164e |
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 |
ffe3ac31 |
23 | * along with this program; if not, write to the Free Software Foundation, |
28e8164e |
24 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | */ |
26 | |
27 | /*----- Revision history --------------------------------------------------* |
28 | * |
29 | * $Log: cvssh.c,v $ |
ffe3ac31 |
30 | * Revision 1.2 1999/04/21 09:07:55 mdw |
31 | * Fiddle with copyright messages so that they're correct. |
32 | * |
28e8164e |
33 | * Revision 1.1 1999/04/21 09:04:24 mdw |
34 | * Add `cvssh' shell for anonymous CVS support. |
35 | * |
36 | */ |
37 | |
38 | /*----- Header files ------------------------------------------------------*/ |
39 | |
40 | #include <stdio.h> |
41 | #include <stdlib.h> |
42 | #include <string.h> |
43 | |
44 | #include <sys/types.h> |
45 | #include <netdb.h> |
46 | #include <unistd.h> |
47 | #include <pwd.h> |
48 | #include <sys/utsname.h> |
49 | |
50 | /*----- Main code ---------------------------------------------------------*/ |
51 | |
52 | const static char help[] = "\ |
53 | Welcome to the anonymous CVS server.\n\ |
54 | \n\ |
55 | To use the CVS server, set your `CVSROOT' environment variable to\n\ |
56 | `%s@%s:%s', and use the `cvs checkout' and `cvs update'\n\ |
57 | commands. See the manual for more information on how to use CVS.\n\ |
58 | "; |
59 | |
60 | void dummy(void) |
61 | { |
62 | char *p; |
63 | char *host; |
64 | char *home; |
65 | |
66 | home = getenv("HOME"); |
67 | p = getenv("USER"); |
68 | |
69 | if (!p || !home) { |
70 | struct passwd *pw = getpwuid(getuid()); |
71 | if (!p) |
72 | p = (pw ? pw->pw_name : "anoncvs"); |
73 | if (!home) |
74 | home = (pw ? pw->pw_dir : "/cvs"); |
75 | } |
76 | |
77 | { |
78 | struct utsname u; |
79 | struct hostent *h; |
80 | uname(&u); |
81 | h = gethostbyname(u.nodename); |
82 | if (h) |
83 | host = h->h_name; |
84 | else |
85 | host = u.nodename; |
86 | } |
87 | |
88 | printf(help, p, host, home); |
89 | exit(0); |
90 | } |
91 | |
92 | int main(int argc, char *argv[]) |
93 | { |
94 | if (argc == 2 && (strcmp(argv[1], ".ssh/rc")) == 0) |
95 | exit(0); |
96 | if (argc != 3 || strcmp(argv[1], "-c") || strcmp(argv[2], "cvs server")) |
97 | dummy(); |
98 | execl("/bin/cvs", "cvs", "-A", "server", (char *)0); |
99 | perror("cvssh (exec)"); |
100 | exit(1); |
101 | } |
102 | |
103 | /*----- That's all, folks -------------------------------------------------*/ |