• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/samba/source/script/
1#!/usr/bin/awk -f
2# edit the line above to point to your real location of awk interpreter
3
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
7#
8# Michal Jaegermann, michal@ellpspace.math.ualberta.ca, 1995-11-09
9
10BEGIN {
11  me = "addtosmbpass";
12  count = ARGC;
13  FS = ":";
14 
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;
21  }
22
23  for(i = 1; i < count; i++) {
24    names[ARGV[i]] = " ";
25    delete ARGV[i];
26  }
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;
31#
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 = "";
37  }
38  pwdf = "/etc/passwd";
39}
40#check for names already present in input
41{
42  print $0;
43  for(name in names) {
44    if($1 ~ name) {
45      delete names[name];
46    }
47  }
48}
49END {
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;
59      }
60      notfound = "n";
61    }
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);
69      }
70      close(command);
71    }
72  }
73}
74
75