1 | /* |
---|
2 | * xquota - X window system quota display program. |
---|
3 | * |
---|
4 | * $Athena: man.c,v 1.7 89/02/15 16:06:44 kit Exp $ |
---|
5 | * |
---|
6 | * Copyright 1989 Massachusetts Institute of Technology |
---|
7 | * |
---|
8 | * Permission to use, copy, modify, and distribute this software and its |
---|
9 | * documentation for any purpose and without fee is hereby granted, provided |
---|
10 | * that the above copyright notice appear in all copies and that both that |
---|
11 | * copyright notice and this permission notice appear in supporting |
---|
12 | * documentation, and that the name of M.I.T. not be used in advertising or |
---|
13 | * publicity pertaining to distribution of the software without specific, |
---|
14 | * written prior permission. M.I.T. makes no representations about the |
---|
15 | * suitability of this software for any purpose. It is provided "as is" |
---|
16 | * without express or implied warranty. |
---|
17 | * |
---|
18 | * Author: Chris D. Peterson, MIT Project Athena |
---|
19 | * Created: March 5, 1989 |
---|
20 | */ |
---|
21 | |
---|
22 | #if ( !defined(lint) && !defined(SABER)) |
---|
23 | static char rcs_version[] = "$Athena: man.c,v 4.7 89/02/15 20:09:34 kit Locked $"; |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <stdio.h> |
---|
27 | #include <X11/Intrinsic.h> |
---|
28 | |
---|
29 | #include <pwd.h> |
---|
30 | #include <hesiod.h> |
---|
31 | #include <ctype.h> |
---|
32 | |
---|
33 | #include "xquota.h" |
---|
34 | |
---|
35 | #define FILSYS ("filsys") |
---|
36 | #define NFS ("NFS") |
---|
37 | #define AFS ("AFS") |
---|
38 | |
---|
39 | static void ParseHesiodInfo(); |
---|
40 | static void GetUserFilsys(); |
---|
41 | |
---|
42 | Info info; /* external for action proc only. */ |
---|
43 | |
---|
44 | int homeIsAFS = 0; |
---|
45 | |
---|
46 | /* Function Name: main |
---|
47 | * Description: main driver for the quota check program. |
---|
48 | * Arguments: argc, argv - you all know about these right? |
---|
49 | * Returns: none. |
---|
50 | */ |
---|
51 | |
---|
52 | void |
---|
53 | main(argc, argv) |
---|
54 | int argc; |
---|
55 | char ** argv; |
---|
56 | { |
---|
57 | Widget top; |
---|
58 | |
---|
59 | GetUserFilsys(&info); |
---|
60 | |
---|
61 | top = InitializeWorld(&info, &argc, argv); |
---|
62 | CreateWidgets(top, &info); |
---|
63 | |
---|
64 | XtRealizeWidget(top); |
---|
65 | XtAppMainLoop(info.appcon); |
---|
66 | } |
---|
67 | |
---|
68 | /* Function Name: GetQuota |
---|
69 | * Description: Gets the quota for user who invoke this program. |
---|
70 | * Arguments: dqblk - the quota info ** RETURNED ** |
---|
71 | * Returns: none. |
---|
72 | */ |
---|
73 | |
---|
74 | static void |
---|
75 | GetUserFilsys(info) |
---|
76 | Info * info; |
---|
77 | { |
---|
78 | struct passwd *user_info; |
---|
79 | char ** hesinfo; |
---|
80 | char *type; |
---|
81 | |
---|
82 | /* |
---|
83 | * Proceedure: |
---|
84 | * |
---|
85 | * o Get users filsys entries from hesiod. |
---|
86 | * o Use first entry only. |
---|
87 | * o If it is not an NFS or AFS filsys or hesiod failed the give up. |
---|
88 | */ |
---|
89 | |
---|
90 | info->uid = getuid(); |
---|
91 | user_info = getpwuid(info->uid); |
---|
92 | hesinfo = hes_resolve(user_info->pw_name, FILSYS); |
---|
93 | if ( hesinfo != NULL ) { |
---|
94 | ParseHesiodInfo(*hesinfo, &type, &(info->host), &(info->path) ); |
---|
95 | if ( !streq(type, NFS) && !streq(type, AFS) ) { |
---|
96 | printf("Your home filesystem is not NFS or AFS, giving up.\n"); |
---|
97 | exit(0); |
---|
98 | } |
---|
99 | if (streq(type, AFS)) { |
---|
100 | homeIsAFS = 1; |
---|
101 | info->host = "AFS cell"; |
---|
102 | } |
---|
103 | } |
---|
104 | else { |
---|
105 | printf("hesiod failure, giving up.\n"); |
---|
106 | hes_error(); |
---|
107 | exit(0); |
---|
108 | } |
---|
109 | |
---|
110 | hesinfo++; /* We are still using this space. */ |
---|
111 | |
---|
112 | if (*hesinfo != NULL) { |
---|
113 | printf("You have more than one filesystem we will only provide a quota\n"); |
---|
114 | printf("graph for the filsys: %s on machine %s.\n", |
---|
115 | info->path, info->host); |
---|
116 | while (*hesinfo != NULL) /* clean up. */ |
---|
117 | free(*hesinfo++); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | /* Function Name: ParseHesiodInfo |
---|
122 | * Description: Parses a hesiod filsys entry. |
---|
123 | * Arguments: string - string from hesiod. |
---|
124 | * type - type of filsys ** RETURNED ** |
---|
125 | * host - host of filsys ** RETURNED ** |
---|
126 | * path - path to filsys ** RETURNED ** |
---|
127 | * Returns: none |
---|
128 | */ |
---|
129 | |
---|
130 | static void |
---|
131 | ParseHesiodInfo(string, type, host, path) |
---|
132 | char * string; |
---|
133 | char **type, **host, **path; |
---|
134 | { |
---|
135 | char * c = string; |
---|
136 | |
---|
137 | *type = string; |
---|
138 | while( !isspace(*c) ) c++; |
---|
139 | *c = '\0'; |
---|
140 | *path = ++c; |
---|
141 | while( !isspace(*c) ) c++; |
---|
142 | *c = '\0'; |
---|
143 | *host = ++c; |
---|
144 | while( !isspace(*c) ) c++; |
---|
145 | *c = '\0'; |
---|
146 | } |
---|