Updates to the scripts for the new 14-char space format of account
[Samba/gebeck_regimport.git] / source / script / addtosmbpass
blob84a7e6fac050b7435e4c5e81b2eef8bc23f84c19
1 #!/usr/bin/awk -f
2 # edit the line above to point to your real location of awk interpreter
4 # awk program for adding new entries in smbpasswd files
5 # arguments are account names to add; feed it an existent Samba password
6 # file on stdin, results will be written on stdout
8 # Michal Jaegermann, michal@ellpspace.math.ualberta.ca, 1995-11-09
10 BEGIN {
11 me = "addtosmbpass";
12 count = ARGC;
13 FS = ":";
15 if (count == 1) {
16 print "Usage:", me,
17 "name1 [name2 ....] < smbpasswd.in > smbpasswd.out";
18 ARGV[1] = "/dev/null";
19 ARGC = 2;
20 exit;
23 for(i = 1; i < count; i++) {
24 names[ARGV[i]] = " ";
25 delete ARGV[i];
27 # sane awk should work simply with 'ARGC = 1', but not every awk
28 # implementation is sane - big sigh!!
29 ARGV[1] = "-";
30 ARGC = 2;
32 # If you have ypmatch but is not RPC registered (some Linux systems
33 # for example) comment out the next line.
34 # "which ypmatch" | getline ypmatch;
35 if (1 != match(ypmatch, /^\//)) {
36 ypmatch = "";
38 pwdf = "/etc/passwd";
40 #check for names already present in input
42 print $0;
43 for(name in names) {
44 if($1 ~ name) {
45 delete names[name];
49 END {
50 fmt = "%s:%s:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:";
51 fmt = fmt "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:[U ]:LCT-00000000:%s:\n";
52 for(name in names) {
53 while ((getline < pwdf) > 0) {
54 if ($1 == name) {
55 printf(fmt, $1, $3, $5);
56 close(pwdf);
57 notfound = "";
58 break;
60 notfound = "n";
62 $0 = "";
63 if (notfound && ypmatch) {
64 # try to find in NIS databases
65 command = ypmatch " " name " passwd";
66 command | getline;
67 if (NF > 0) {
68 printf(fmt, $1, $3, $5);
70 close(command);