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