source: trunk/athena/bin/xquota/main.c @ 1749

Revision 1749, 3.4 KB checked in by kit, 35 years ago (diff)
Initial revision
Line 
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
38static void ParseHesiodInfo();
39static void GetUserFilsys();
40
41Info info;                      /* external for action proc only. */
42
43/*      Function Name: main
44 *      Description: main driver for the quota check program.
45 *      Arguments: argc, argv - you all know about these right?
46 *      Returns: none.
47 */
48
49void
50main(argc, argv)
51int argc;
52char ** argv;
53{
54  Widget top;
55
56  GetUserFilsys(&info);
57
58  top = InitializeWorld(&info, &argc, argv);
59  CreateWidgets(top, &info);
60
61  XtRealizeWidget(top);
62  XtAppMainLoop(info.appcon);
63}
64
65/*      Function Name: GetQuota
66 *      Description: Gets the quota for user who invoke this program.
67 *      Arguments: dqblk - the quota info ** RETURNED **
68 *      Returns: none.
69 */
70
71static void
72GetUserFilsys(info)
73Info * info;
74{
75  struct passwd *user_info;
76  char ** hesinfo;
77  char *type;
78
79/*
80 * Proceedure:
81 *
82 * o Get users filsys entries from hesiod.
83 * o Use first entry only.
84 * o If it is not an NFS filsys or hesiod failed the give up.
85 */
86
87  info->uid = getuid();
88  user_info = getpwuid(info->uid);
89  hesinfo = hes_resolve(user_info->pw_name, FILSYS);
90  if ( hesinfo != NULL ) {
91    ParseHesiodInfo(*hesinfo, &type, &(info->host), &(info->path) );
92    if ( !streq(type, NFS) ) {
93      printf("Your home filesystem is not NFS, giving up.\n");
94      exit(0);
95    }
96  }
97  else {
98    printf("hesiod failure, giving up.\n");
99    hes_error();
100    exit(0);
101  }
102
103  hesinfo++;                    /* We are still using this space. */
104
105  if (*hesinfo != NULL) {
106    printf("You have more than one filesystem we will only provide a quota\n");
107    printf("graph for the filsys: %s on machine %s.\n",
108           info->path, info->host);
109    while (*hesinfo != NULL)    /* clean up. */
110      free(*hesinfo++);
111  }
112}
113
114/*      Function Name: ParseHesiodInfo
115 *      Description: Parses a hesiod filsys entry.
116 *      Arguments: string - string from hesiod.
117 *                 type - type of filsys ** RETURNED **
118 *                 host - host of filsys ** RETURNED **
119 *                 path - path to filsys ** RETURNED **
120 *      Returns: none
121 */
122
123static void
124ParseHesiodInfo(string, type, host, path)
125char * string;
126char **type, **host, **path;
127{
128  char * c = string;
129
130  *type = string;
131  while( !isspace(*c) ) c++;
132  *c = '\0';
133  *path = ++c;
134  while( !isspace(*c) ) c++;
135  *c = '\0';
136  *host = ++c;
137  while( !isspace(*c) ) c++;
138  *c = '\0';
139}
Note: See TracBrowser for help on using the repository browser.