b39d888c3950f69bcc4340c9ed90f8036d14ba6d
[ira/wip.git] / testprogs / ejs / ejsnet.js
1 #!/usr/bin/env smbscript
2
3 var options = GetOptions(ARGV, 
4                 "POPT_AUTOHELP",
5                 "POPT_COMMON_SAMBA",
6                 "POPT_COMMON_CREDENTIALS");
7 if (options == undefined) {
8    println("Failed to parse options");
9    return -1;
10 }
11
12 if (options.ARGV.length != 2) {
13    println("Usage: ejsnet.js <DOMAIN> <NEW USER NAME>");
14    return -1;
15 }
16
17 /* use command line creds if available */
18 var creds = options.get_credentials();
19
20 var ctx = NetContext(creds);
21 var usr_ctx = ctx.UserMgr(options.ARGV[0]);
22 if (usr_ctx == undefined) {
23         println("Couldn't get user management context.");
24         return -1;
25 }
26
27 var status = usr_ctx.Create(options.ARGV[1]);
28 if (status.is_ok != true) {
29         println("Failed to create user account " + options.ARGV[1] + ": " + status.errstr);
30         return -1;
31 }
32
33
34 var info = usr_ctx.Info(options.ARGV[1]);
35 if (info != null) {
36         println("UserInfo.AccountName = " + info.AccountName);
37         println("UserInfo.Description = " + info.Description);
38         println("UserInfo.FullName = " + info.FullName);
39         println("UserInfo.AcctExpiry = " + info.AcctExpiry);
40 } else {
41         println("Null UserInfo returned - account unknown");
42 }
43
44
45 var status = usr_ctx.Delete(options.ARGV[1]);
46 if (status.is_ok != true) {
47         println("Failed to delete user account " + options.ARGV[1] + ": " + status.errstr);
48         return -1;
49 }
50
51 print ("OK\n");
52 return 0;