sample input file ----------------------------------------------------------------------------- ## this is a comment. # drink klim s0000001 milk s0000002 milk=klim # food bread s0003001 rice s0003002 # tree pine s0008001 oak s0008003 ----------------------------------------------------------------------------- sample intermediate file ----------------------------------------------------------------------------- drink klim s0000001 p14861v2 CzG9D0lSUmTfs drink milk s0000002 milk=kli AzVa1Je1k4PVw food bread s0003001 xsyy0f94 Szro0OkE/myWA food rice s0003002 k5p69y52 GzEyZAoMXgfEM tree pine s0008001 2TxR6kg0 WzBFpFT3gf04Y tree oak s0008002 Ln80g7wL GzQoL3hBdS8L6 ----------------------------------------------------------------------------- sample passwd file ----------------------------------------------------------------------------- euclid:OzEbHyW5D/3to:1024:101:Geometry:/home/math/euclid:/bin/bash turing:BzHM6W1Wib8jw:1025:102:Alan Turing:/home/cs/turing:/bin/bash erdos:Nz1clPXbUqA/Q:1026:102:Paul Erdos:/home/cs/erdos:/bin/bash polya:BzV/p.1pmVT/6:1027:101:George Polya:/home/math/polya:/bin/bash ----------------------------------------------------------------------------- sample MAP ----------------------------------------------------------------------------- # department home gid math math 101 cs cs 102 drink drink 201 food food 202 tree plant/tree 301 flower plant/flower 302 ----------------------------------------------------------------------------- the pseudo code for account ----------------------------------------------------------------------------- label=..... process the input, generate the intermediate file for each entry in intermediate file if a new user get a unique uid get his(her) home gid from MAP generate some stuff into the script for NEW-user if an old one generate some sutff ino the script for OLD-user end for if NEW-user existed then run it endif if OLD-user existed then run it endif moving files into the log directory The input file , intermediate file, NEW-user (if has one), and OLD-user (if has one) are moved into the log directory. All of them must have the same prefix as the label created at the beginning. So it is easy to track the modification. For example, the four files may be 20061130.0007-data 20061130.0007-intermediate 20061130.0007-NEW 20061130.0007-OLD The NEW-user is a script. When it is run, the new users will be added. Of course, there are many things to do. For example, create the home directory, set the quota, setup the environment and update the passwd entry. But here you need to update the passwd entry only. The OLD-user is a script. When is is run, the password for existed users will be changed. (The cipher field in passwd.) You must invent a method to maintain the unique uid. You must invent a method to generate a random password. The code to generate a cipher for a given password is ---------------------------------------------------------------------------- #include #include #include #include main(int args, char *argv[]) { char salt[3]; char passwd[16]; int t; time((time_t*)&t); salt[0] = ((t&0x0000FFFF) ) % 26 + 'A'; salt[1] = ((t&0xFFFF0000)>>16) % 26 + 'a'; salt[2] = '\0'; if( args == 1 ){ scanf("%s", passwd); printf("%s\n", crypt(passwd,salt)); } else if( args == 2 ) printf("%s\n", crypt(argv[1],salt)); else if( args == 3 ) printf("%s\n", crypt(argv[1],argv[2])); } ----------------------------------------------------------------------------