28e8164e |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: cvssh.c,v 1.1 1999/04/21 09:04:24 mdw Exp $ |
4 | * |
5 | * Login shell for an anonymous CVS user |
6 | * |
7 | * (c) 1999 Mark Wooding |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of the background resolver (resolve). |
13 | * |
14 | * resolve 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 | * resolve 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 resolve; 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: cvssh.c,v $ |
32 | * Revision 1.1 1999/04/21 09:04:24 mdw |
33 | * Add `cvssh' shell for anonymous CVS support. |
34 | * |
35 | */ |
36 | |
37 | /*----- Header files ------------------------------------------------------*/ |
38 | |
39 | #include <stdio.h> |
40 | #include <stdlib.h> |
41 | #include <string.h> |
42 | |
43 | #include <sys/types.h> |
44 | #include <netdb.h> |
45 | #include <unistd.h> |
46 | #include <pwd.h> |
47 | #include <sys/utsname.h> |
48 | |
49 | /*----- Main code ---------------------------------------------------------*/ |
50 | |
51 | const static char help[] = "\ |
52 | Welcome to the anonymous CVS server.\n\ |
53 | \n\ |
54 | To use the CVS server, set your `CVSROOT' environment variable to\n\ |
55 | `%s@%s:%s', and use the `cvs checkout' and `cvs update'\n\ |
56 | commands. See the manual for more information on how to use CVS.\n\ |
57 | "; |
58 | |
59 | void dummy(void) |
60 | { |
61 | char *p; |
62 | char *host; |
63 | char *home; |
64 | |
65 | home = getenv("HOME"); |
66 | p = getenv("USER"); |
67 | |
68 | if (!p || !home) { |
69 | struct passwd *pw = getpwuid(getuid()); |
70 | if (!p) |
71 | p = (pw ? pw->pw_name : "anoncvs"); |
72 | if (!home) |
73 | home = (pw ? pw->pw_dir : "/cvs"); |
74 | } |
75 | |
76 | { |
77 | struct utsname u; |
78 | struct hostent *h; |
79 | uname(&u); |
80 | h = gethostbyname(u.nodename); |
81 | if (h) |
82 | host = h->h_name; |
83 | else |
84 | host = u.nodename; |
85 | } |
86 | |
87 | printf(help, p, host, home); |
88 | exit(0); |
89 | } |
90 | |
91 | int main(int argc, char *argv[]) |
92 | { |
93 | if (argc == 2 && (strcmp(argv[1], ".ssh/rc")) == 0) |
94 | exit(0); |
95 | if (argc != 3 || strcmp(argv[1], "-c") || strcmp(argv[2], "cvs server")) |
96 | dummy(); |
97 | execl("/bin/cvs", "cvs", "-A", "server", (char *)0); |
98 | perror("cvssh (exec)"); |
99 | exit(1); |
100 | } |
101 | |
102 | /*----- That's all, folks -------------------------------------------------*/ |