uss-fix-typo-20020909
[openafs.git] / src / uss / uss_common.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  *      Storage for common variables employed by the AFS user
12  *      account facility.
13  */
14
15 /*
16  * --------------------- Required definitions ---------------------
17  */
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21 RCSID("$Header$");
22
23 #include "uss_common.h"         /*Interface definitions*/
24 #include <afs/kautils.h>        /*MAXKTCREALMLEN & MAXKTCNAMELEN*/
25
26
27 #ifdef HAVE_STRING_H
28 #include <string.h>
29 #else
30 #ifdef HAVE_STRINGS_H
31 #include <strings.h>
32 #endif
33 #endif
34
35
36 /*
37  * ---------------------- Exported variables ----------------------
38  */
39 #define uss_AutoLen     300
40 #define uss_NumVars      10
41
42 char uss_User[uss_UserLen+1];           /*User's account name*/
43 char uss_Uid[uss_UidLen+1];             /*User's uid*/
44 char uss_Server[uss_ServerLen+1];       /*FileServer hosting user's volume*/
45 char uss_Partition[uss_PartitionLen+1]; /*FileServer partition for above*/
46 char uss_MountPoint[uss_MountPointLen+1]; /*Mountpoint for user's volume*/
47 char uss_RealName[uss_RealNameLen+1];   /*User's full name*/
48 char uss_Pwd[uss_PwdLen+1];             /*User password*/
49 char uss_PwdPath[uss_PwdPathLen+1];     /*Curr pathname to password file*/
50 char uss_PwdFormat[uss_PwdFormatLen+1]; /*Curr password entry format*/
51 char uss_RestoreDir[uss_RestoreDirLen+1]; /*Curr directory for restore info*/
52 char uss_Auto[uss_AutoLen+1];           /*Curr choice of AUTO value*/
53 char uss_Var[uss_NumVars][uss_MAX_ARG_SIZE]; /*$1, $2, ... command variables*/
54 int uss_VarMax = 0;                     /*Largest index in above*/
55 char uss_Volume[uss_VolumeLen+1];       /*Name of user's volume*/
56 afs_int32 uss_VolumeID;                 /*Numerical volume ID*/
57 afs_int32 uss_ServerID;                 /*Numerical server ID*/
58 afs_int32 uss_PartitionID;                      /*Numerical partition ID*/
59 char uss_DirPool[100][uss_DirPoolLen];  /*List of all acceptable subdirs*/
60
61
62 /*
63  * Values saved across invocations.
64  */
65 char uss_PwdPath_Saved[uss_PwdPathLen];       /*Pathname to saved pwd file*/
66 char uss_PwdFormat_Saved[uss_PwdFormatLen];   /*Saved pwd entry format*/
67 char uss_RestoreDir_Saved[uss_RestoreDirLen]; /*Saved dir for restore info*/
68
69 int uss_NumGroups = 0;                  /*Number of $AUTO entries*/
70 int uss_SaveVolume;                     /*Save current user volume?*/
71 int uss_SaveVolume_Saved;               /*Saved value of above*/
72 int uss_DryRun = 0;                     /*Is this a dry run?*/
73 int uss_SkipKaserver = 0;               /*Don't talk to kaserver*/
74 int uss_Overwrite = 0;                  /*Overwrite user files?*/
75 int uss_OverwriteThisOne;               /*Overwrite on this pass?*/
76 char uss_Administrator[64];             /*Name of admin account*/
77 char uss_AccountCreator[MAXKTCNAMELEN]; /*Principal running this program*/
78 afs_int32 uss_DesiredUID;                       /*Uid to assign the user*/
79 afs_int32 uss_Expires;                  /*How long between password expires*/
80 char uss_Cell[MAXKTCREALMLEN];          /*Cell in which account lives*/
81 char uss_ConfDir[uss_PATH_SIZE];        /*Config directory*/
82 int uss_verbose = 0;                    /*Are we being verbose?*/
83 int uss_ignoreFlag = 0;                 /*Ignore yyparse errors?*/
84 int uss_perr = 0;
85 char uss_whoami[64];                    /*Program name used*/
86 int uss_syntax_err = 0;                 /*YACC syntax error?*/
87 struct uss_subdir *uss_currentDir = NULL; /*Current directory*/
88
89
90 /*
91  * ----------------------- Private variables ----------------------
92  */
93 static int initDone = 0;                /*Have we been initialized?*/
94
95
96 /*------------------------------------------------------------------------
97  * EXPORTED uss_common_Init
98  *
99  * Description:
100  *      Set up various common uss variables, especially the saved ones.
101  *
102  * Arguments:
103  *      None.
104  *
105  * Returns:
106  *      Nothing.
107  *
108  * Environment:
109  *      We only allow an initialization once.
110  *
111  * Side Effects:
112  *      As advertised.
113  *------------------------------------------------------------------------*/
114
115 void uss_common_Init()
116
117 { /*uss_common_Init*/
118
119     extern int line;            /*Current template line*/
120
121     if (initDone)
122         return;
123
124     strcpy(uss_ConfDir, AFSDIR_CLIENT_ETC_DIRPATH);
125     uss_PwdPath_Saved[0]= '\0';
126     uss_PwdFormat_Saved[0]= '\0';
127     uss_RestoreDir_Saved[0]= '\0';
128     uss_SaveVolume_Saved = 0;
129     uss_syntax_err = 0;
130     line = 1;
131
132 } /*uss_common_Init*/
133
134
135 /*------------------------------------------------------------------------
136  * EXPORTED uss_common_Reset
137  *
138  * Description:
139  *      Resets some of the common variables to their idle or
140  *      saved states.
141  *
142  * Arguments:
143  *      None.
144  *
145  * Returns:
146  *      Nothing.
147  *
148  * Environment:
149  *      Nothing interesting.
150  *
151  * Side Effects:
152  *      As advertised.
153  *------------------------------------------------------------------------*/
154
155 void uss_common_Reset()
156
157 { /*uss_common_Reset*/
158
159     extern int line;            /*Current template line*/
160     int i;                      /*Loop variable*/
161
162     uss_ignoreFlag = 0;
163     uss_NumGroups = 0;
164     uss_perr = 0;
165     uss_currentDir = NULL;
166     uss_DesiredUID = 0;
167     uss_VarMax = 0;
168     uss_User[0]= '\0';
169     uss_Uid[0]= '\0';
170     uss_Server[0]= '\0';
171     uss_Partition[0]= '\0';
172     uss_MountPoint[0]= '\0';
173     uss_RealName[0]= '\0';
174     sprintf(uss_Pwd, "%s", uss_DEFAULT_PASSWORD);
175     strcpy(uss_PwdPath, uss_PwdPath_Saved);
176     strcpy(uss_PwdFormat, uss_PwdFormat_Saved);
177     strcpy(uss_RestoreDir, uss_RestoreDir_Saved);
178     uss_SaveVolume = uss_SaveVolume_Saved;
179     uss_Auto[0]= '\0';
180     for(i = 1; i < 10; i++)
181         uss_Var[i][0] = '\0';
182
183     /*
184      * Reset the template line you think you're reading from, and
185      * remember you haven't seen any template file parsing errors
186      * on this run yet.
187      */
188     line = 1;
189     uss_syntax_err = 0;
190
191 } /*uss_common_Reset*/
192
193
194 /*------------------------------------------------------------------------
195  * EXPORTED uss_common_FieldCp
196  *
197  * Environment:
198  *      Nothing interesting.
199  *
200  * Side Effects:
201  *      As advertised.
202  *------------------------------------------------------------------------*/
203
204 char *uss_common_FieldCp(a_to, a_from, a_separator, a_maxChars, a_overflowP)
205     char *a_to;
206     char *a_from;
207     char a_separator;
208     int a_maxChars;
209     int *a_overflowP;
210     
211 { /*uss_common_FieldCp*/
212
213     register int chars_read;    /*Number of chars read so far*/
214
215     chars_read = 0;
216     *a_overflowP = 0;
217     /*
218      * It's OK to read in the separator/null after reading a_maxChars,
219      * so we need to bump a_maxChars by one.
220      */
221     a_maxChars++;
222
223     while (*a_from != a_separator &&
224            *a_from != '\0' &&
225            *a_from != '\n') {
226         *a_to++ = *a_from++;
227         if (++chars_read >= a_maxChars) {
228             /*
229              * Bummer, we've overflowed.  Remember the sad fact, and
230              * move the destination pointer back over the extra
231              * character.  Also, skip over any garbage sitting after
232              * the characters that won't fit in to the given field.
233              */
234             *a_overflowP = 1;
235             a_to--;
236 #if 0
237             printf("*** Skipping overflow char '%c'\n",
238                    *(a_from-1));
239 #endif /* 0 */
240             while (*a_from != a_separator &&
241                    *a_from != '\0' &&
242                    *a_from != '\n') {
243 #if 0
244                 printf("*** Skipping overflow char '%c'\n",
245                        *a_from);
246 #endif /* 0 */
247                 a_from++;
248             } /*Skip over excess chars*/
249             break;
250         } /*Found overflow*/
251     } /*Read til end of field*/
252
253     /*
254      * Make sure we return a null-terminated string.
255      */
256     *a_to = '\0';
257
258     /*
259      * Collapse any number of blanks, should we have ended up pointing
260      * to one.
261      */
262     if (a_separator == ' ')
263         while((*a_from == ' ') && (*(a_from+1) == ' '))
264             a_from++;
265
266     /*
267      * Return the position of the next non-separator char or
268      * the position of the null, if that's what was left.
269      */
270     if (*a_from == '\0')
271         return(a_from);
272     else
273         return(++a_from);
274
275 } /*uss_common_FieldCp*/