s3:vfs: add SMB_VFS_READDIR_ATTR()
[Samba.git] / source3 / utils / net_sam.c
blob2ee9a91b704238e10713b1d9641481800f1d20c2
1 /*
2 * Unix SMB/CIFS implementation.
3 * Local SAM access routines
4 * Copyright (C) Volker Lendecke 2006
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "system/passwd.h"
23 #include "utils/net.h"
24 #include "../librpc/gen_ndr/samr.h"
25 #include "smbldap.h"
26 #include "../libcli/security/security.h"
27 #include "lib/winbind_util.h"
28 #include "passdb.h"
29 #include "passdb/pdb_ldap_util.h"
30 #include "passdb/pdb_ldap_schema.h"
31 #include "lib/privileges.h"
32 #include "secrets.h"
33 #include "idmap.h"
36 * Set a user's data
39 static int net_sam_userset(struct net_context *c, int argc, const char **argv,
40 const char *field,
41 bool (*fn)(struct samu *, const char *,
42 enum pdb_value_state))
44 struct samu *sam_acct = NULL;
45 struct dom_sid sid;
46 enum lsa_SidType type;
47 const char *dom, *name;
48 NTSTATUS status;
50 if (argc != 2 || c->display_usage) {
51 d_fprintf(stderr, "%s\n", _("Usage:"));
52 d_fprintf(stderr, _("net sam set %s <user> <value>\n"),
53 field);
54 return -1;
57 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
58 &dom, &name, &sid, &type)) {
59 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
60 return -1;
63 if (type != SID_NAME_USER) {
64 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
65 sid_type_lookup(type));
66 return -1;
69 if ( !(sam_acct = samu_new( NULL )) ) {
70 d_fprintf(stderr, _("Internal error\n"));
71 return -1;
74 if (!pdb_getsampwsid(sam_acct, &sid)) {
75 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
76 return -1;
79 if (!fn(sam_acct, argv[1], PDB_CHANGED)) {
80 d_fprintf(stderr, _("Internal error\n"));
81 return -1;
84 status = pdb_update_sam_account(sam_acct);
85 if (!NT_STATUS_IS_OK(status)) {
86 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
87 argv[0], nt_errstr(status));
88 return -1;
91 TALLOC_FREE(sam_acct);
93 d_printf(_("Updated %s for %s\\%s to %s\n"), field, dom, name, argv[1]);
94 return 0;
97 static int net_sam_set_fullname(struct net_context *c, int argc,
98 const char **argv)
100 return net_sam_userset(c, argc, argv, "fullname",
101 pdb_set_fullname);
104 static int net_sam_set_logonscript(struct net_context *c, int argc,
105 const char **argv)
107 return net_sam_userset(c, argc, argv, "logonscript",
108 pdb_set_logon_script);
111 static int net_sam_set_profilepath(struct net_context *c, int argc,
112 const char **argv)
114 return net_sam_userset(c, argc, argv, "profilepath",
115 pdb_set_profile_path);
118 static int net_sam_set_homedrive(struct net_context *c, int argc,
119 const char **argv)
121 return net_sam_userset(c, argc, argv, "homedrive",
122 pdb_set_dir_drive);
125 static int net_sam_set_homedir(struct net_context *c, int argc,
126 const char **argv)
128 return net_sam_userset(c, argc, argv, "homedir",
129 pdb_set_homedir);
132 static int net_sam_set_workstations(struct net_context *c, int argc,
133 const char **argv)
135 return net_sam_userset(c, argc, argv, "workstations",
136 pdb_set_workstations);
140 * Set account flags
143 static int net_sam_set_userflag(struct net_context *c, int argc,
144 const char **argv, const char *field,
145 uint16 flag)
147 struct samu *sam_acct = NULL;
148 struct dom_sid sid;
149 enum lsa_SidType type;
150 const char *dom, *name;
151 NTSTATUS status;
152 uint32_t acct_flags;
154 if ((argc != 2) || c->display_usage ||
155 (!strequal(argv[1], "yes") &&
156 !strequal(argv[1], "no"))) {
157 d_fprintf(stderr, "%s\n", _("Usage:"));
158 d_fprintf(stderr, _("net sam set %s <user> [yes|no]\n"),
159 field);
160 return -1;
163 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
164 &dom, &name, &sid, &type)) {
165 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
166 return -1;
169 if (type != SID_NAME_USER) {
170 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
171 sid_type_lookup(type));
172 return -1;
175 if ( !(sam_acct = samu_new( NULL )) ) {
176 d_fprintf(stderr, _("Internal error\n"));
177 return -1;
180 if (!pdb_getsampwsid(sam_acct, &sid)) {
181 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
182 return -1;
185 acct_flags = pdb_get_acct_ctrl(sam_acct);
187 if (strequal(argv[1], "yes")) {
188 acct_flags |= flag;
189 } else {
190 acct_flags &= ~flag;
193 pdb_set_acct_ctrl(sam_acct, acct_flags, PDB_CHANGED);
195 status = pdb_update_sam_account(sam_acct);
196 if (!NT_STATUS_IS_OK(status)) {
197 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
198 argv[0], nt_errstr(status));
199 return -1;
202 TALLOC_FREE(sam_acct);
204 d_fprintf(stderr, _("Updated flag %s for %s\\%s to %s\n"), field, dom,
205 name, argv[1]);
206 return 0;
209 static int net_sam_set_disabled(struct net_context *c, int argc,
210 const char **argv)
212 return net_sam_set_userflag(c, argc, argv, "disabled", ACB_DISABLED);
215 static int net_sam_set_pwnotreq(struct net_context *c, int argc,
216 const char **argv)
218 return net_sam_set_userflag(c, argc, argv, "pwnotreq", ACB_PWNOTREQ);
221 static int net_sam_set_autolock(struct net_context *c, int argc,
222 const char **argv)
224 return net_sam_set_userflag(c, argc, argv, "autolock", ACB_AUTOLOCK);
227 static int net_sam_set_pwnoexp(struct net_context *c, int argc,
228 const char **argv)
230 return net_sam_set_userflag(c, argc, argv, "pwnoexp", ACB_PWNOEXP);
234 * Set pass last change time, based on force pass change now
237 static int net_sam_set_pwdmustchangenow(struct net_context *c, int argc,
238 const char **argv)
240 struct samu *sam_acct = NULL;
241 struct dom_sid sid;
242 enum lsa_SidType type;
243 const char *dom, *name;
244 NTSTATUS status;
246 if ((argc != 2) || c->display_usage ||
247 (!strequal(argv[1], "yes") &&
248 !strequal(argv[1], "no"))) {
249 d_fprintf(stderr, "%s\n%s",
250 _("Usage:"),
251 _("net sam set pwdmustchangenow <user> [yes|no]\n"));
252 return -1;
255 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
256 &dom, &name, &sid, &type)) {
257 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
258 return -1;
261 if (type != SID_NAME_USER) {
262 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
263 sid_type_lookup(type));
264 return -1;
267 if ( !(sam_acct = samu_new( NULL )) ) {
268 d_fprintf(stderr, _("Internal error\n"));
269 return -1;
272 if (!pdb_getsampwsid(sam_acct, &sid)) {
273 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
274 return -1;
277 if (strequal(argv[1], "yes")) {
278 pdb_set_pass_last_set_time(sam_acct, 0, PDB_CHANGED);
279 } else {
280 pdb_set_pass_last_set_time(sam_acct, time(NULL), PDB_CHANGED);
283 status = pdb_update_sam_account(sam_acct);
284 if (!NT_STATUS_IS_OK(status)) {
285 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
286 argv[0], nt_errstr(status));
287 return -1;
290 TALLOC_FREE(sam_acct);
292 d_fprintf(stderr, _("Updated 'user must change password at next logon' "
293 "for %s\\%s to %s\n"), dom,
294 name, argv[1]);
295 return 0;
300 * Set a user's or a group's comment
303 static int net_sam_set_comment(struct net_context *c, int argc,
304 const char **argv)
306 GROUP_MAP *map;
307 struct dom_sid sid;
308 enum lsa_SidType type;
309 const char *dom, *name;
310 NTSTATUS status;
312 if (argc != 2 || c->display_usage) {
313 d_fprintf(stderr, "%s\n%s",
314 _("Usage:"),
315 _("net sam set comment <name> <comment>\n"));
316 return -1;
319 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
320 &dom, &name, &sid, &type)) {
321 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
322 return -1;
325 if (type == SID_NAME_USER) {
326 return net_sam_userset(c, argc, argv, "comment",
327 pdb_set_acct_desc);
330 if ((type != SID_NAME_DOM_GRP) && (type != SID_NAME_ALIAS) &&
331 (type != SID_NAME_WKN_GRP)) {
332 d_fprintf(stderr, _("%s is a %s, not a group\n"), argv[0],
333 sid_type_lookup(type));
334 return -1;
337 map = talloc_zero(talloc_tos(), GROUP_MAP);
338 if (!map) {
339 d_fprintf(stderr, _("Out of memory!\n"));
340 return -1;
343 if (!pdb_getgrsid(map, sid)) {
344 d_fprintf(stderr, _("Could not load group %s\n"), argv[0]);
345 return -1;
348 map->comment = talloc_strdup(map, argv[1]);
349 if (!map->comment) {
350 d_fprintf(stderr, _("Out of memory!\n"));
351 return -1;
354 status = pdb_update_group_mapping_entry(map);
356 if (!NT_STATUS_IS_OK(status)) {
357 d_fprintf(stderr, _("Updating group mapping entry failed with "
358 "%s\n"), nt_errstr(status));
359 return -1;
362 d_printf("Updated comment of group %s\\%s to %s\n", dom, name,
363 argv[1]);
365 TALLOC_FREE(map);
366 return 0;
369 static int net_sam_set(struct net_context *c, int argc, const char **argv)
371 struct functable func[] = {
373 "homedir",
374 net_sam_set_homedir,
375 NET_TRANSPORT_LOCAL,
376 N_("Change a user's home directory"),
377 N_("net sam set homedir\n"
378 " Change a user's home directory")
381 "profilepath",
382 net_sam_set_profilepath,
383 NET_TRANSPORT_LOCAL,
384 N_("Change a user's profile path"),
385 N_("net sam set profilepath\n"
386 " Change a user's profile path")
389 "comment",
390 net_sam_set_comment,
391 NET_TRANSPORT_LOCAL,
392 N_("Change a users or groups description"),
393 N_("net sam set comment\n"
394 " Change a users or groups description")
397 "fullname",
398 net_sam_set_fullname,
399 NET_TRANSPORT_LOCAL,
400 N_("Change a user's full name"),
401 N_("net sam set fullname\n"
402 " Change a user's full name")
405 "logonscript",
406 net_sam_set_logonscript,
407 NET_TRANSPORT_LOCAL,
408 N_("Change a user's logon script"),
409 N_("net sam set logonscript\n"
410 " Change a user's logon script")
413 "homedrive",
414 net_sam_set_homedrive,
415 NET_TRANSPORT_LOCAL,
416 N_("Change a user's home drive"),
417 N_("net sam set homedrive\n"
418 " Change a user's home drive")
421 "workstations",
422 net_sam_set_workstations,
423 NET_TRANSPORT_LOCAL,
424 N_("Change a user's allowed workstations"),
425 N_("net sam set workstations\n"
426 " Change a user's allowed workstations")
429 "disabled",
430 net_sam_set_disabled,
431 NET_TRANSPORT_LOCAL,
432 N_("Disable/Enable a user"),
433 N_("net sam set disable\n"
434 " Disable/Enable a user")
437 "pwnotreq",
438 net_sam_set_pwnotreq,
439 NET_TRANSPORT_LOCAL,
440 N_("Disable/Enable the password not required flag"),
441 N_("net sam set pwnotreq\n"
442 " Disable/Enable the password not required flag")
445 "autolock",
446 net_sam_set_autolock,
447 NET_TRANSPORT_LOCAL,
448 N_("Disable/Enable a user's lockout flag"),
449 N_("net sam set autolock\n"
450 " Disable/Enable a user's lockout flag")
453 "pwnoexp",
454 net_sam_set_pwnoexp,
455 NET_TRANSPORT_LOCAL,
456 N_("Disable/Enable whether a user's pw does not "
457 "expire"),
458 N_("net sam set pwnoexp\n"
459 " Disable/Enable whether a user's pw does not "
460 "expire")
463 "pwdmustchangenow",
464 net_sam_set_pwdmustchangenow,
465 NET_TRANSPORT_LOCAL,
466 N_("Force users password must change at next logon"),
467 N_("net sam set pwdmustchangenow\n"
468 " Force users password must change at next logon")
470 {NULL, NULL, 0, NULL, NULL}
473 return net_run_function(c, argc, argv, "net sam set", func);
477 * Manage account policies
480 static int net_sam_policy_set(struct net_context *c, int argc, const char **argv)
482 const char *account_policy = NULL;
483 uint32 value = 0;
484 uint32 old_value = 0;
485 enum pdb_policy_type field;
486 char *endptr;
488 if (argc != 2 || c->display_usage) {
489 d_fprintf(stderr, "%s\n%s",
490 _("Usage:"),
491 _("net sam policy set \"<account policy>\" <value>\n"));
492 return -1;
495 account_policy = argv[0];
496 field = account_policy_name_to_typenum(account_policy);
498 if (strequal(argv[1], "forever") || strequal(argv[1], "never")
499 || strequal(argv[1], "off")) {
500 value = -1;
502 else {
503 value = strtoul(argv[1], &endptr, 10);
505 if ((endptr == argv[1]) || (endptr[0] != '\0')) {
506 d_printf(_("Unable to set policy \"%s\"! Invalid value "
507 "\"%s\".\n"),
508 account_policy, argv[1]);
509 return -1;
513 if (field == 0) {
514 const char **names;
515 int i, count;
517 account_policy_names_list(talloc_tos(), &names, &count);
518 d_fprintf(stderr, _("No account policy \"%s\"!\n\n"), argv[0]);
519 d_fprintf(stderr, _("Valid account policies are:\n"));
521 for (i=0; i<count; i++) {
522 d_fprintf(stderr, "%s\n", names[i]);
525 TALLOC_FREE(names);
527 return -1;
530 if (!pdb_get_account_policy(field, &old_value)) {
531 d_fprintf(stderr, _("Valid account policy, but unable to fetch "
532 "value!\n"));
533 } else {
534 d_printf(_("Account policy \"%s\" value was: %d\n"),
535 account_policy, old_value);
538 if (!pdb_set_account_policy(field, value)) {
539 d_fprintf(stderr, _("Valid account policy, but unable to "
540 "set value!\n"));
541 return -1;
542 } else {
543 d_printf(_("Account policy \"%s\" value is now: %d\n"),
544 account_policy, value);
547 return 0;
550 static int net_sam_policy_show(struct net_context *c, int argc, const char **argv)
552 const char *account_policy = NULL;
553 uint32 old_value;
554 enum pdb_policy_type field;
556 if (argc != 1 || c->display_usage) {
557 d_fprintf(stderr, "%s\n%s",
558 _("Usage:"),
559 _("net sam policy show \"<account policy>\"\n"));
560 return -1;
563 account_policy = argv[0];
564 field = account_policy_name_to_typenum(account_policy);
566 if (field == 0) {
567 const char **names;
568 int count;
569 int i;
570 account_policy_names_list(talloc_tos(), &names, &count);
571 d_fprintf(stderr, _("No account policy by that name!\n"));
572 if (count != 0) {
573 d_fprintf(stderr, _("Valid account policies "
574 "are:\n"));
575 for (i=0; i<count; i++) {
576 d_fprintf(stderr, "%s\n", names[i]);
579 TALLOC_FREE(names);
580 return -1;
583 if (!pdb_get_account_policy(field, &old_value)) {
584 fprintf(stderr, _("Valid account policy, but unable to "
585 "fetch value!\n"));
586 return -1;
589 printf(_("Account policy \"%s\" description: %s\n"),
590 account_policy, account_policy_get_desc(field));
591 printf(_("Account policy \"%s\" value is: %d\n"), account_policy,
592 old_value);
593 return 0;
596 static int net_sam_policy_list(struct net_context *c, int argc, const char **argv)
598 const char **names;
599 int count;
600 int i;
602 if (c->display_usage) {
603 d_printf( "%s\n"
604 "net sam policy list\n"
605 " %s\n",
606 _("Usage:"),
607 _("List account policies"));
608 return 0;
611 account_policy_names_list(talloc_tos(), &names, &count);
612 if (count != 0) {
613 d_fprintf(stderr, _("Valid account policies "
614 "are:\n"));
615 for (i = 0; i < count ; i++) {
616 d_fprintf(stderr, "%s\n", names[i]);
619 TALLOC_FREE(names);
620 return -1;
623 static int net_sam_policy(struct net_context *c, int argc, const char **argv)
625 struct functable func[] = {
627 "list",
628 net_sam_policy_list,
629 NET_TRANSPORT_LOCAL,
630 N_("List account policies"),
631 N_("net sam policy list\n"
632 " List account policies")
635 "show",
636 net_sam_policy_show,
637 NET_TRANSPORT_LOCAL,
638 N_("Show account policies"),
639 N_("net sam policy show\n"
640 " Show account policies")
643 "set",
644 net_sam_policy_set,
645 NET_TRANSPORT_LOCAL,
646 N_("Change account policies"),
647 N_("net sam policy set\n"
648 " Change account policies")
650 {NULL, NULL, 0, NULL, NULL}
653 return net_run_function(c, argc, argv, "net sam policy", func);
656 static int net_sam_rights_list(struct net_context *c, int argc,
657 const char **argv)
659 enum sec_privilege privilege;
661 if (argc > 1 || c->display_usage) {
662 d_fprintf(stderr, "%s\n%s",
663 _("Usage:"),
664 _("net sam rights list [privilege name]\n"));
665 return -1;
668 if (argc == 0) {
669 int i;
670 int num = num_privileges_in_short_list();
672 for (i=0; i<num; i++) {
673 d_printf("%s\n", sec_privilege_name_from_index(i));
675 return 0;
678 privilege = sec_privilege_id(argv[0]);
680 if (privilege != SEC_PRIV_INVALID) {
681 struct dom_sid *sids;
682 int i, num_sids;
683 NTSTATUS status;
685 status = privilege_enum_sids(privilege, talloc_tos(),
686 &sids, &num_sids);
687 if (!NT_STATUS_IS_OK(status)) {
688 d_fprintf(stderr, _("Could not list rights: %s\n"),
689 nt_errstr(status));
690 return -1;
693 for (i=0; i<num_sids; i++) {
694 const char *dom, *name;
695 enum lsa_SidType type;
697 if (lookup_sid(talloc_tos(), &sids[i], &dom, &name,
698 &type)) {
699 d_printf("%s\\%s\n", dom, name);
701 else {
702 d_printf("%s\n", sid_string_tos(&sids[i]));
705 return 0;
708 return -1;
711 static int net_sam_rights_grant(struct net_context *c, int argc,
712 const char **argv)
714 struct dom_sid sid;
715 enum lsa_SidType type;
716 const char *dom, *name;
717 int i;
719 if (argc < 2 || c->display_usage) {
720 d_fprintf(stderr, "%s\n%s",
721 _("Usage:"),
722 _("net sam rights grant <name> <rights> ...\n"));
723 return -1;
726 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
727 &dom, &name, &sid, &type)) {
728 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
729 return -1;
732 for (i=1; i < argc; i++) {
733 enum sec_privilege privilege = sec_privilege_id(argv[i]);
734 if (privilege == SEC_PRIV_INVALID) {
735 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
736 return -1;
739 if (!grant_privilege_by_name(&sid, argv[i])) {
740 d_fprintf(stderr, _("Could not grant privilege\n"));
741 return -1;
744 d_printf(_("Granted %s to %s\\%s\n"), argv[i], dom, name);
747 return 0;
750 static int net_sam_rights_revoke(struct net_context *c, int argc,
751 const char **argv)
753 struct dom_sid sid;
754 enum lsa_SidType type;
755 const char *dom, *name;
756 int i;
758 if (argc < 2 || c->display_usage) {
759 d_fprintf(stderr, "%s\n%s",
760 _("Usage:"),
761 _("net sam rights revoke <name> <rights>\n"));
762 return -1;
765 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
766 &dom, &name, &sid, &type)) {
767 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
768 return -1;
771 for (i=1; i < argc; i++) {
772 enum sec_privilege privilege = sec_privilege_id(argv[i]);
773 if (privilege == SEC_PRIV_INVALID) {
774 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
775 return -1;
778 if (!revoke_privilege_by_name(&sid, argv[i])) {
779 d_fprintf(stderr, _("Could not revoke privilege\n"));
780 return -1;
783 d_printf(_("Revoked %s from %s\\%s\n"), argv[i], dom, name);
786 return 0;
789 static int net_sam_rights(struct net_context *c, int argc, const char **argv)
791 struct functable func[] = {
793 "list",
794 net_sam_rights_list,
795 NET_TRANSPORT_LOCAL,
796 N_("List possible user rights"),
797 N_("net sam rights list\n"
798 " List possible user rights")
801 "grant",
802 net_sam_rights_grant,
803 NET_TRANSPORT_LOCAL,
804 N_("Grant right(s)"),
805 N_("net sam rights grant\n"
806 " Grant right(s)")
809 "revoke",
810 net_sam_rights_revoke,
811 NET_TRANSPORT_LOCAL,
812 N_("Revoke right(s)"),
813 N_("net sam rights revoke\n"
814 " Revoke right(s)")
816 {NULL, NULL, 0, NULL, NULL}
818 return net_run_function(c, argc, argv, "net sam rights", func);
822 * Map a unix group to a domain group
825 static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *map)
827 const char *dom, *name;
828 uint32 rid;
830 if (pdb_getgrgid(map, grp->gr_gid)) {
831 return NT_STATUS_GROUP_EXISTS;
834 map->gid = grp->gr_gid;
836 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
837 &dom, &name, NULL, NULL)) {
839 map->nt_name = talloc_asprintf(map, "Unix Group %s",
840 grp->gr_name);
842 DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
843 grp->gr_name, dom, name, map->nt_name));
846 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
847 NULL, NULL, NULL, NULL)) {
848 DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
849 return NT_STATUS_GROUP_EXISTS;
852 if (pdb_capabilities() & PDB_CAP_STORE_RIDS) {
853 if (!pdb_new_rid(&rid)) {
854 DEBUG(3, ("Could not get a new RID for %s\n",
855 grp->gr_name));
856 return NT_STATUS_ACCESS_DENIED;
858 } else {
859 rid = algorithmic_pdb_gid_to_group_rid( grp->gr_gid );
862 sid_compose(&map->sid, get_global_sam_sid(), rid);
863 map->sid_name_use = SID_NAME_DOM_GRP;
864 map->comment = talloc_asprintf(map, "Unix Group %s", grp->gr_name);
866 return pdb_add_group_mapping_entry(map);
869 static int net_sam_mapunixgroup(struct net_context *c, int argc, const char **argv)
871 NTSTATUS status;
872 GROUP_MAP *map;
873 struct group *grp;
875 if (argc != 1 || c->display_usage) {
876 d_fprintf(stderr, "%s\n%s",
877 _("Usage:"),
878 _("net sam mapunixgroup <name>\n"));
879 return -1;
882 grp = getgrnam(argv[0]);
883 if (grp == NULL) {
884 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
885 return -1;
888 map = talloc_zero(talloc_tos(), GROUP_MAP);
889 if (!map) {
890 d_fprintf(stderr, _("Out of memory!\n"));
891 return -1;
894 status = map_unix_group(grp, map);
896 if (!NT_STATUS_IS_OK(status)) {
897 d_fprintf(stderr, _("Mapping group %s failed with %s\n"),
898 argv[0], nt_errstr(status));
899 return -1;
902 d_printf(_("Mapped unix group %s to SID %s\n"), argv[0],
903 sid_string_tos(&map->sid));
905 TALLOC_FREE(map);
906 return 0;
910 * Remove a group mapping
913 static NTSTATUS unmap_unix_group(const struct group *grp)
915 struct dom_sid dom_sid;
916 struct unixid id;
918 if (!lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
919 NULL, NULL, NULL, NULL)) {
920 DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
921 return NT_STATUS_NO_SUCH_GROUP;
924 id.id = grp->gr_gid;
925 id.type = ID_TYPE_GID;
926 if (!pdb_id_to_sid(&id, &dom_sid)) {
927 return NT_STATUS_UNSUCCESSFUL;
930 return pdb_delete_group_mapping_entry(dom_sid);
933 static int net_sam_unmapunixgroup(struct net_context *c, int argc, const char **argv)
935 NTSTATUS status;
936 struct group *grp;
938 if (argc != 1 || c->display_usage) {
939 d_fprintf(stderr, "%s\n%s",
940 _("Usage:"),
941 _("net sam unmapunixgroup <name>\n"));
942 return -1;
945 grp = getgrnam(argv[0]);
946 if (grp == NULL) {
947 d_fprintf(stderr, _("Could not find mapping for group %s.\n"),
948 argv[0]);
949 return -1;
952 status = unmap_unix_group(grp);
954 if (!NT_STATUS_IS_OK(status)) {
955 d_fprintf(stderr, _("Unmapping group %s failed with %s.\n"),
956 argv[0], nt_errstr(status));
957 return -1;
960 d_printf(_("Unmapped unix group %s.\n"), argv[0]);
962 return 0;
966 * Create a domain group
969 static int net_sam_createdomaingroup(struct net_context *c, int argc,
970 const char **argv)
972 NTSTATUS status;
973 uint32 rid;
975 if (argc != 1 || c->display_usage) {
976 d_fprintf(stderr, "%s\n%s",
977 _("Usage:"),
978 _("net sam createdomaingroup <name>\n"));
979 return -1;
982 status = pdb_create_dom_group(talloc_tos(), argv[0], &rid);
984 if (!NT_STATUS_IS_OK(status)) {
985 d_fprintf(stderr, _("Creating %s failed with %s\n"),
986 argv[0], nt_errstr(status));
987 return -1;
990 d_printf(_("Created domain group %s with RID %d\n"), argv[0], rid);
992 return 0;
996 * Delete a domain group
999 static int net_sam_deletedomaingroup(struct net_context *c, int argc,
1000 const char **argv)
1002 struct dom_sid sid;
1003 uint32_t rid;
1004 enum lsa_SidType type;
1005 const char *dom, *name;
1006 NTSTATUS status;
1008 if (argc != 1 || c->display_usage) {
1009 d_fprintf(stderr, "%s\n%s",
1010 _("Usage:"),
1011 _("net sam deletelocalgroup <name>\n"));
1012 return -1;
1015 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1016 &dom, &name, &sid, &type)) {
1017 d_fprintf(stderr, _("Could not find %s.\n"), argv[0]);
1018 return -1;
1021 if (type != SID_NAME_DOM_GRP) {
1022 d_fprintf(stderr, _("%s is a %s, not a domain group.\n"),
1023 argv[0], sid_type_lookup(type));
1024 return -1;
1027 sid_peek_rid(&sid, &rid);
1029 status = pdb_delete_dom_group(talloc_tos(), rid);
1031 if (!NT_STATUS_IS_OK(status)) {
1032 d_fprintf(stderr,_("Deleting domain group %s failed with %s\n"),
1033 argv[0], nt_errstr(status));
1034 return -1;
1037 d_printf(_("Deleted domain group %s.\n"), argv[0]);
1039 return 0;
1043 * Create a local group
1046 static int net_sam_createlocalgroup(struct net_context *c, int argc, const char **argv)
1048 NTSTATUS status;
1049 uint32 rid;
1051 if (argc != 1 || c->display_usage) {
1052 d_fprintf(stderr, "%s\n%s",
1053 _("Usage:"),
1054 _("net sam createlocalgroup <name>\n"));
1055 return -1;
1058 if (!winbind_ping()) {
1059 d_fprintf(stderr, _("winbind seems not to run. "
1060 "createlocalgroup only works when winbind runs.\n"));
1061 return -1;
1064 status = pdb_create_alias(argv[0], &rid);
1066 if (!NT_STATUS_IS_OK(status)) {
1067 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1068 argv[0], nt_errstr(status));
1069 return -1;
1072 d_printf(_("Created local group %s with RID %d\n"), argv[0], rid);
1074 return 0;
1078 * Delete a local group
1081 static int net_sam_deletelocalgroup(struct net_context *c, int argc, const char **argv)
1083 struct dom_sid sid;
1084 enum lsa_SidType type;
1085 const char *dom, *name;
1086 NTSTATUS status;
1088 if (argc != 1 || c->display_usage) {
1089 d_fprintf(stderr, "%s\n%s",
1090 _("Usage:"),
1091 _("net sam deletelocalgroup <name>\n"));
1092 return -1;
1095 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1096 &dom, &name, &sid, &type)) {
1097 d_fprintf(stderr,_("Could not find %s.\n"), argv[0]);
1098 return -1;
1101 if (type != SID_NAME_ALIAS) {
1102 d_fprintf(stderr, _("%s is a %s, not a local group.\n"),argv[0],
1103 sid_type_lookup(type));
1104 return -1;
1107 status = pdb_delete_alias(&sid);
1109 if (!NT_STATUS_IS_OK(status)) {
1110 d_fprintf(stderr, _("Deleting local group %s failed with %s\n"),
1111 argv[0], nt_errstr(status));
1112 return -1;
1115 d_printf(_("Deleted local group %s.\n"), argv[0]);
1117 return 0;
1121 * Create a builtin group
1124 static int net_sam_createbuiltingroup(struct net_context *c, int argc, const char **argv)
1126 NTSTATUS status;
1127 uint32 rid;
1128 enum lsa_SidType type;
1129 fstring groupname;
1130 struct dom_sid sid;
1132 if (argc != 1 || c->display_usage) {
1133 d_fprintf(stderr, "%s\n%s",
1134 _("Usage:"),
1135 _("net sam createbuiltingroup <name>\n"));
1136 return -1;
1139 if (!winbind_ping()) {
1140 d_fprintf(stderr, _("winbind seems not to run. "
1141 "createbuiltingroup only works when winbind "
1142 "runs.\n"));
1143 return -1;
1146 /* validate the name and get the group */
1148 fstrcpy( groupname, "BUILTIN\\" );
1149 fstrcat( groupname, argv[0] );
1151 if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
1152 NULL, &sid, &type)) {
1153 d_fprintf(stderr, _("%s is not a BUILTIN group\n"), argv[0]);
1154 return -1;
1157 if ( !sid_peek_rid( &sid, &rid ) ) {
1158 d_fprintf(stderr, _("Failed to get RID for %s\n"), argv[0]);
1159 return -1;
1162 status = pdb_create_builtin(rid);
1164 if (!NT_STATUS_IS_OK(status)) {
1165 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1166 argv[0], nt_errstr(status));
1167 return -1;
1170 d_printf(_("Created BUILTIN group %s with RID %d\n"), argv[0], rid);
1172 return 0;
1176 * Add a group member
1179 static int net_sam_addmem(struct net_context *c, int argc, const char **argv)
1181 const char *groupdomain, *groupname, *memberdomain, *membername;
1182 struct dom_sid group, member;
1183 enum lsa_SidType grouptype, membertype;
1184 NTSTATUS status;
1186 if (argc != 2 || c->display_usage) {
1187 d_fprintf(stderr, "%s\n%s",
1188 _("Usage:"),
1189 _("net sam addmem <group> <member>\n"));
1190 return -1;
1193 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1194 &groupdomain, &groupname, &group, &grouptype)) {
1195 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1196 return -1;
1199 /* check to see if the member to be added is a name or a SID */
1201 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1202 &memberdomain, &membername, &member, &membertype))
1204 /* try it as a SID */
1206 if ( !string_to_sid( &member, argv[1] ) ) {
1207 d_fprintf(stderr, _("Could not find member %s\n"),
1208 argv[1]);
1209 return -1;
1212 if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
1213 &membername, &membertype) )
1215 d_fprintf(stderr, _("Could not resolve SID %s\n"),
1216 argv[1]);
1217 return -1;
1221 if ((grouptype == SID_NAME_ALIAS) || (grouptype == SID_NAME_WKN_GRP)) {
1222 if ((membertype != SID_NAME_USER) &&
1223 (membertype != SID_NAME_DOM_GRP)) {
1224 d_fprintf(stderr, _("%s is a local group, only users "
1225 "and domain groups can be added.\n"
1226 "%s is a %s\n"), argv[0], argv[1],
1227 sid_type_lookup(membertype));
1228 return -1;
1230 status = pdb_add_aliasmem(&group, &member);
1232 if (!NT_STATUS_IS_OK(status)) {
1233 d_fprintf(stderr, _("Adding local group member failed "
1234 "with %s\n"), nt_errstr(status));
1235 return -1;
1237 } else if (grouptype == SID_NAME_DOM_GRP) {
1238 uint32_t grouprid, memberrid;
1240 sid_peek_rid(&group, &grouprid);
1241 sid_peek_rid(&member, &memberrid);
1243 status = pdb_add_groupmem(talloc_tos(), grouprid, memberrid);
1244 if (!NT_STATUS_IS_OK(status)) {
1245 d_fprintf(stderr, _("Adding domain group member failed "
1246 "with %s\n"), nt_errstr(status));
1247 return -1;
1249 } else {
1250 d_fprintf(stderr, _("Can only add members to local groups so "
1251 "far, %s is a %s\n"), argv[0],
1252 sid_type_lookup(grouptype));
1253 return -1;
1256 d_printf(_("Added %s\\%s to %s\\%s\n"), memberdomain, membername,
1257 groupdomain, groupname);
1259 return 0;
1263 * Delete a group member
1266 static int net_sam_delmem(struct net_context *c, int argc, const char **argv)
1268 const char *groupdomain, *groupname;
1269 const char *memberdomain = NULL;
1270 const char *membername = NULL;
1271 struct dom_sid group, member;
1272 enum lsa_SidType grouptype;
1273 NTSTATUS status;
1275 if (argc != 2 || c->display_usage) {
1276 d_fprintf(stderr,"%s\n%s",
1277 _("Usage:"),
1278 _("net sam delmem <group> <member>\n"));
1279 return -1;
1282 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1283 &groupdomain, &groupname, &group, &grouptype)) {
1284 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1285 return -1;
1288 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1289 &memberdomain, &membername, &member, NULL)) {
1290 if (!string_to_sid(&member, argv[1])) {
1291 d_fprintf(stderr, _("Could not find member %s\n"),
1292 argv[1]);
1293 return -1;
1297 if ((grouptype == SID_NAME_ALIAS) ||
1298 (grouptype == SID_NAME_WKN_GRP)) {
1299 status = pdb_del_aliasmem(&group, &member);
1301 if (!NT_STATUS_IS_OK(status)) {
1302 d_fprintf(stderr,_("Deleting local group member failed "
1303 "with %s\n"), nt_errstr(status));
1304 return -1;
1306 } else if (grouptype == SID_NAME_DOM_GRP) {
1307 uint32_t grouprid, memberrid;
1309 sid_peek_rid(&group, &grouprid);
1310 sid_peek_rid(&member, &memberrid);
1312 status = pdb_del_groupmem(talloc_tos(), grouprid, memberrid);
1313 if (!NT_STATUS_IS_OK(status)) {
1314 d_fprintf(stderr, _("Deleting domain group member "
1315 "failed with %s\n"), nt_errstr(status));
1316 return -1;
1318 } else {
1319 d_fprintf(stderr, _("Can only delete members from local groups "
1320 "so far, %s is a %s\n"), argv[0],
1321 sid_type_lookup(grouptype));
1322 return -1;
1325 if (membername != NULL) {
1326 d_printf(_("Deleted %s\\%s from %s\\%s\n"),
1327 memberdomain, membername, groupdomain, groupname);
1328 } else {
1329 d_printf(_("Deleted %s from %s\\%s\n"),
1330 sid_string_tos(&member), groupdomain, groupname);
1333 return 0;
1337 * List group members
1340 static int net_sam_listmem(struct net_context *c, int argc, const char **argv)
1342 const char *groupdomain, *groupname;
1343 struct dom_sid group;
1344 struct dom_sid *members = NULL;
1345 size_t i, num_members = 0;
1346 enum lsa_SidType grouptype;
1347 NTSTATUS status;
1349 if (argc != 1 || c->display_usage) {
1350 d_fprintf(stderr, "%s\n%s",
1351 _("Usage:"),
1352 _("net sam listmem <group>\n"));
1353 return -1;
1356 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1357 &groupdomain, &groupname, &group, &grouptype)) {
1358 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1359 return -1;
1362 if ((grouptype == SID_NAME_ALIAS) ||
1363 (grouptype == SID_NAME_WKN_GRP)) {
1364 status = pdb_enum_aliasmem(&group, talloc_tos(), &members,
1365 &num_members);
1366 if (!NT_STATUS_IS_OK(status)) {
1367 d_fprintf(stderr, _("Listing group members failed with "
1368 "%s\n"), nt_errstr(status));
1369 return -1;
1371 } else if (grouptype == SID_NAME_DOM_GRP) {
1372 uint32_t *rids;
1374 status = pdb_enum_group_members(talloc_tos(), &group,
1375 &rids, &num_members);
1376 if (!NT_STATUS_IS_OK(status)) {
1377 d_fprintf(stderr, _("Listing group members failed with "
1378 "%s\n"), nt_errstr(status));
1379 return -1;
1382 members = talloc_array(talloc_tos(), struct dom_sid,
1383 num_members);
1384 if (members == NULL) {
1385 TALLOC_FREE(rids);
1386 return -1;
1389 for (i=0; i<num_members; i++) {
1390 sid_compose(&members[i], get_global_sam_sid(),
1391 rids[i]);
1393 TALLOC_FREE(rids);
1394 } else {
1395 d_fprintf(stderr,_("Can only list local group members so far.\n"
1396 "%s is a %s\n"), argv[0], sid_type_lookup(grouptype));
1397 return -1;
1400 d_printf(_("%s\\%s has %u members\n"), groupdomain, groupname,
1401 (unsigned int)num_members);
1402 for (i=0; i<num_members; i++) {
1403 const char *dom, *name;
1404 if (lookup_sid(talloc_tos(), &members[i], &dom, &name, NULL)) {
1405 d_printf(" %s\\%s\n", dom, name);
1406 } else {
1407 d_printf(" %s\n", sid_string_tos(&members[i]));
1411 TALLOC_FREE(members);
1413 return 0;
1417 * Do the listing
1419 static int net_sam_do_list(struct net_context *c, int argc, const char **argv,
1420 struct pdb_search *search, const char *what)
1422 bool verbose = (argc == 1);
1424 if ((argc > 1) || c->display_usage ||
1425 ((argc == 1) && !strequal(argv[0], "verbose"))) {
1426 d_fprintf(stderr, "%s\n", _("Usage:"));
1427 d_fprintf(stderr, _("net sam list %s [verbose]\n"), what);
1428 return -1;
1431 if (search == NULL) {
1432 d_fprintf(stderr, _("Could not start search\n"));
1433 return -1;
1436 while (true) {
1437 struct samr_displayentry entry;
1438 if (!search->next_entry(search, &entry)) {
1439 break;
1441 if (verbose) {
1442 d_printf("%s:%d:%s\n",
1443 entry.account_name,
1444 entry.rid,
1445 entry.description);
1446 } else {
1447 d_printf("%s\n", entry.account_name);
1451 TALLOC_FREE(search);
1452 return 0;
1455 static int net_sam_list_users(struct net_context *c, int argc,
1456 const char **argv)
1458 return net_sam_do_list(c, argc, argv,
1459 pdb_search_users(talloc_tos(), ACB_NORMAL),
1460 "users");
1463 static int net_sam_list_groups(struct net_context *c, int argc,
1464 const char **argv)
1466 return net_sam_do_list(c, argc, argv, pdb_search_groups(talloc_tos()),
1467 "groups");
1470 static int net_sam_list_localgroups(struct net_context *c, int argc,
1471 const char **argv)
1473 return net_sam_do_list(c, argc, argv,
1474 pdb_search_aliases(talloc_tos(),
1475 get_global_sam_sid()),
1476 "localgroups");
1479 static int net_sam_list_builtin(struct net_context *c, int argc,
1480 const char **argv)
1482 return net_sam_do_list(c, argc, argv,
1483 pdb_search_aliases(talloc_tos(),
1484 &global_sid_Builtin),
1485 "builtin");
1488 static int net_sam_list_workstations(struct net_context *c, int argc,
1489 const char **argv)
1491 return net_sam_do_list(c, argc, argv,
1492 pdb_search_users(talloc_tos(), ACB_WSTRUST),
1493 "workstations");
1497 * List stuff
1500 static int net_sam_list(struct net_context *c, int argc, const char **argv)
1502 struct functable func[] = {
1504 "users",
1505 net_sam_list_users,
1506 NET_TRANSPORT_LOCAL,
1507 N_("List SAM users"),
1508 N_("net sam list users\n"
1509 " List SAM users")
1512 "groups",
1513 net_sam_list_groups,
1514 NET_TRANSPORT_LOCAL,
1515 N_("List SAM groups"),
1516 N_("net sam list groups\n"
1517 " List SAM groups")
1520 "localgroups",
1521 net_sam_list_localgroups,
1522 NET_TRANSPORT_LOCAL,
1523 N_("List SAM local groups"),
1524 N_("net sam list localgroups\n"
1525 " List SAM local groups")
1528 "builtin",
1529 net_sam_list_builtin,
1530 NET_TRANSPORT_LOCAL,
1531 N_("List builtin groups"),
1532 N_("net sam list builtin\n"
1533 " List builtin groups")
1536 "workstations",
1537 net_sam_list_workstations,
1538 NET_TRANSPORT_LOCAL,
1539 N_("List domain member workstations"),
1540 N_("net sam list workstations\n"
1541 " List domain member workstations")
1543 {NULL, NULL, 0, NULL, NULL}
1546 return net_run_function(c, argc, argv, "net sam list", func);
1550 * Show details of SAM entries
1553 static int net_sam_show(struct net_context *c, int argc, const char **argv)
1555 struct dom_sid sid;
1556 enum lsa_SidType type;
1557 const char *dom, *name;
1559 if (argc != 1 || c->display_usage) {
1560 d_fprintf(stderr, "%s\n%s",
1561 _("Usage:"),
1562 _("net sam show <name>\n"));
1563 return -1;
1566 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1567 &dom, &name, &sid, &type)) {
1568 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
1569 return -1;
1572 d_printf(_("%s\\%s is a %s with SID %s\n"), dom, name,
1573 sid_type_lookup(type), sid_string_tos(&sid));
1575 return 0;
1578 #ifdef HAVE_LDAP
1581 * Init an LDAP tree with default users and Groups
1582 * if ldapsam:editposix is enabled
1585 static int net_sam_provision(struct net_context *c, int argc, const char **argv)
1587 TALLOC_CTX *tc;
1588 char *ldap_bk;
1589 char *ldap_uri = NULL;
1590 char *p;
1591 struct smbldap_state *state = NULL;
1592 GROUP_MAP *gmap = NULL;
1593 struct dom_sid gsid;
1594 gid_t domusers_gid = -1;
1595 gid_t domadmins_gid = -1;
1596 struct samu *samuser;
1597 struct passwd *pwd;
1598 bool is_ipa = false;
1599 char *bind_dn = NULL;
1600 char *bind_secret = NULL;
1601 NTSTATUS status;
1603 if (c->display_usage) {
1604 d_printf( "%s\n"
1605 "net sam provision\n"
1606 " %s\n",
1607 _("Usage:"),
1608 _("Init an LDAP tree with default users/groups"));
1609 return 0;
1612 tc = talloc_new(NULL);
1613 if (!tc) {
1614 d_fprintf(stderr, _("Out of Memory!\n"));
1615 return -1;
1618 if ((ldap_bk = talloc_strdup(tc, lp_passdb_backend())) == NULL) {
1619 d_fprintf(stderr, _("talloc failed\n"));
1620 talloc_free(tc);
1621 return -1;
1623 p = strchr(ldap_bk, ':');
1624 if (p) {
1625 *p = 0;
1626 ldap_uri = talloc_strdup(tc, p+1);
1627 trim_char(ldap_uri, ' ', ' ');
1630 trim_char(ldap_bk, ' ', ' ');
1632 if (strcmp(ldap_bk, "IPA_ldapsam") == 0 ) {
1633 is_ipa = true;
1636 if (strcmp(ldap_bk, "ldapsam") != 0 && !is_ipa ) {
1637 d_fprintf(stderr,
1638 _("Provisioning works only with ldapsam backend\n"));
1639 goto failed;
1642 if (!lp_parm_bool(-1, "ldapsam", "trusted", false) ||
1643 !lp_parm_bool(-1, "ldapsam", "editposix", false)) {
1645 d_fprintf(stderr, _("Provisioning works only if ldapsam:trusted"
1646 " and ldapsam:editposix are enabled.\n"));
1647 goto failed;
1650 if (!is_ipa && !winbind_ping()) {
1651 d_fprintf(stderr, _("winbind seems not to run. Provisioning "
1652 "LDAP only works when winbind runs.\n"));
1653 goto failed;
1656 if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
1657 d_fprintf(stderr, _("Failed to retrieve LDAP password from secrets.tdb\n"));
1658 goto failed;
1661 status = smbldap_init(tc, NULL, ldap_uri, false, bind_dn, bind_secret, &state);
1663 memset(bind_secret, '\0', strlen(bind_secret));
1664 SAFE_FREE(bind_secret);
1665 SAFE_FREE(bind_dn);
1667 if (!NT_STATUS_IS_OK(status)) {
1668 d_fprintf(stderr, _("Unable to connect to the LDAP server.\n"));
1669 goto failed;
1672 d_printf(_("Checking for Domain Users group.\n"));
1674 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS);
1676 gmap = talloc_zero(tc, GROUP_MAP);
1677 if (!gmap) {
1678 d_printf(_("Out of memory!\n"));
1679 goto failed;
1682 if (!pdb_getgrsid(gmap, gsid)) {
1683 LDAPMod **mods = NULL;
1684 char *dn;
1685 char *uname;
1686 char *wname;
1687 char *gidstr;
1688 char *gtype;
1689 int rc;
1691 d_printf(_("Adding the Domain Users group.\n"));
1693 /* lets allocate a new groupid for this group */
1694 if (is_ipa) {
1695 domusers_gid = 999;
1696 } else {
1697 if (!winbind_allocate_gid(&domusers_gid)) {
1698 d_fprintf(stderr, _("Unable to allocate a new gid to "
1699 "create Domain Users group!\n"));
1700 goto domu_done;
1704 uname = talloc_strdup(tc, "domusers");
1705 wname = talloc_strdup(tc, "Domain Users");
1706 dn = talloc_asprintf(tc, "cn=%s,%s", "domusers",
1707 lp_ldap_group_suffix(talloc_tos()));
1708 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domusers_gid);
1709 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1711 if (!uname || !wname || !dn || !gidstr || !gtype) {
1712 d_fprintf(stderr, "Out of Memory!\n");
1713 goto failed;
1716 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1717 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1718 if (is_ipa) {
1719 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1720 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1721 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1723 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1724 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1725 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1726 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1727 sid_string_talloc(tc, &gsid));
1728 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1730 smbldap_talloc_autofree_ldapmod(tc, mods);
1732 rc = smbldap_add(state, dn, mods);
1734 if (rc != LDAP_SUCCESS) {
1735 d_fprintf(stderr, _("Failed to add Domain Users group "
1736 "to ldap directory\n"));
1739 if (is_ipa) {
1740 if (!pdb_getgrsid(gmap, gsid)) {
1741 d_fprintf(stderr, _("Failed to read just "
1742 "created domain group.\n"));
1743 goto failed;
1744 } else {
1745 domusers_gid = gmap->gid;
1748 } else {
1749 domusers_gid = gmap->gid;
1750 d_printf(_("found!\n"));
1753 domu_done:
1755 d_printf(_("Checking for Domain Admins group.\n"));
1757 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
1759 if (!pdb_getgrsid(gmap, gsid)) {
1760 LDAPMod **mods = NULL;
1761 char *dn;
1762 char *uname;
1763 char *wname;
1764 char *gidstr;
1765 char *gtype;
1766 int rc;
1768 d_printf(_("Adding the Domain Admins group.\n"));
1770 /* lets allocate a new groupid for this group */
1771 if (is_ipa) {
1772 domadmins_gid = 999;
1773 } else {
1774 if (!winbind_allocate_gid(&domadmins_gid)) {
1775 d_fprintf(stderr, _("Unable to allocate a new gid to "
1776 "create Domain Admins group!\n"));
1777 goto doma_done;
1781 uname = talloc_strdup(tc, "domadmins");
1782 wname = talloc_strdup(tc, "Domain Admins");
1783 dn = talloc_asprintf(tc, "cn=%s,%s", "domadmins",
1784 lp_ldap_group_suffix(talloc_tos()));
1785 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1786 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1788 if (!uname || !wname || !dn || !gidstr || !gtype) {
1789 d_fprintf(stderr, _("Out of Memory!\n"));
1790 goto failed;
1793 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1794 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1795 if (is_ipa) {
1796 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1797 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1798 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1800 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1801 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1802 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1803 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1804 sid_string_talloc(tc, &gsid));
1805 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1807 smbldap_talloc_autofree_ldapmod(tc, mods);
1809 rc = smbldap_add(state, dn, mods);
1811 if (rc != LDAP_SUCCESS) {
1812 d_fprintf(stderr, _("Failed to add Domain Admins group "
1813 "to ldap directory\n"));
1816 if (is_ipa) {
1817 if (!pdb_getgrsid(gmap, gsid)) {
1818 d_fprintf(stderr, _("Failed to read just "
1819 "created domain group.\n"));
1820 goto failed;
1821 } else {
1822 domadmins_gid = gmap->gid;
1825 } else {
1826 domadmins_gid = gmap->gid;
1827 d_printf(_("found!\n"));
1830 doma_done:
1832 d_printf(_("Check for Administrator account.\n"));
1834 samuser = samu_new(tc);
1835 if (!samuser) {
1836 d_fprintf(stderr, _("Out of Memory!\n"));
1837 goto failed;
1840 if (!pdb_getsampwnam(samuser, "Administrator")) {
1841 LDAPMod **mods = NULL;
1842 struct dom_sid sid;
1843 char *dn;
1844 char *name;
1845 char *uidstr;
1846 char *gidstr;
1847 char *shell;
1848 char *dir;
1849 char *princ;
1850 uid_t uid;
1851 int rc;
1853 d_printf(_("Adding the Administrator user.\n"));
1855 if (domadmins_gid == -1) {
1856 d_fprintf(stderr,
1857 _("Can't create Administrator user, Domain "
1858 "Admins group not available!\n"));
1859 goto done;
1862 if (is_ipa) {
1863 uid = 999;
1864 } else {
1865 if (!winbind_allocate_uid(&uid)) {
1866 d_fprintf(stderr,
1867 _("Unable to allocate a new uid to create "
1868 "the Administrator user!\n"));
1869 goto done;
1873 name = talloc_strdup(tc, "Administrator");
1874 dn = talloc_asprintf(tc, "uid=Administrator,%s",
1875 lp_ldap_user_suffix(talloc_tos()));
1876 uidstr = talloc_asprintf(tc, "%u", (unsigned int)uid);
1877 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1878 dir = talloc_sub_specified(tc, lp_template_homedir(),
1879 "Administrator",
1880 NULL,
1881 get_global_sam_name(),
1882 uid, domadmins_gid);
1883 shell = talloc_sub_specified(tc, lp_template_shell(),
1884 "Administrator",
1885 NULL,
1886 get_global_sam_name(),
1887 uid, domadmins_gid);
1889 if (!name || !dn || !uidstr || !gidstr || !dir || !shell) {
1890 d_fprintf(stderr, _("Out of Memory!\n"));
1891 goto failed;
1894 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
1896 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
1897 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
1898 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
1899 if (is_ipa) {
1900 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
1901 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
1902 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
1903 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
1904 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
1905 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
1906 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
1907 princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
1908 if (!princ) {
1909 d_fprintf(stderr, _("Out of Memory!\n"));
1910 goto failed;
1912 smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
1914 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
1915 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
1916 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
1917 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
1918 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1919 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", dir);
1920 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", shell);
1921 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
1922 sid_string_talloc(tc, &sid));
1923 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
1924 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
1925 NEW_PW_FORMAT_SPACE_PADDED_LEN));
1927 smbldap_talloc_autofree_ldapmod(tc, mods);
1929 rc = smbldap_add(state, dn, mods);
1931 if (rc != LDAP_SUCCESS) {
1932 d_fprintf(stderr, _("Failed to add Administrator user "
1933 "to ldap directory\n"));
1936 if (is_ipa) {
1937 if (!pdb_getsampwnam(samuser, "Administrator")) {
1938 d_fprintf(stderr, _("Failed to read just "
1939 "created user.\n"));
1940 goto failed;
1943 } else {
1944 d_printf(_("found!\n"));
1947 d_printf(_("Checking for Guest user.\n"));
1949 samuser = samu_new(tc);
1950 if (!samuser) {
1951 d_fprintf(stderr, _("Out of Memory!\n"));
1952 goto failed;
1955 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
1956 LDAPMod **mods = NULL;
1957 struct dom_sid sid;
1958 char *dn;
1959 char *uidstr;
1960 char *gidstr;
1961 int rc;
1963 d_printf(_("Adding the Guest user.\n"));
1965 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
1967 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
1969 if (!pwd) {
1970 if (domusers_gid == -1) {
1971 d_fprintf(stderr,
1972 _("Can't create Guest user, Domain "
1973 "Users group not available!\n"));
1974 goto done;
1976 if ((pwd = talloc(tc, struct passwd)) == NULL) {
1977 d_fprintf(stderr, _("talloc failed\n"));
1978 goto done;
1980 pwd->pw_name = talloc_strdup(pwd, lp_guest_account());
1982 if (is_ipa) {
1983 pwd->pw_uid = 999;
1984 } else {
1985 if (!winbind_allocate_uid(&(pwd->pw_uid))) {
1986 d_fprintf(stderr,
1987 _("Unable to allocate a new uid to "
1988 "create the Guest user!\n"));
1989 goto done;
1992 pwd->pw_gid = domusers_gid;
1993 pwd->pw_dir = talloc_strdup(tc, "/");
1994 pwd->pw_shell = talloc_strdup(tc, "/bin/false");
1995 if (!pwd->pw_dir || !pwd->pw_shell) {
1996 d_fprintf(stderr, _("Out of Memory!\n"));
1997 goto failed;
2001 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name,
2002 lp_ldap_user_suffix (talloc_tos()));
2003 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
2004 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2005 if (!dn || !uidstr || !gidstr) {
2006 d_fprintf(stderr, _("Out of Memory!\n"));
2007 goto failed;
2010 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
2011 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
2012 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
2013 if (is_ipa) {
2014 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
2015 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
2016 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
2017 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
2018 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
2019 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
2020 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
2022 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
2023 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
2024 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", pwd->pw_name);
2025 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
2026 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2027 if ((pwd->pw_dir != NULL) && (pwd->pw_dir[0] != '\0')) {
2028 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", pwd->pw_dir);
2030 if ((pwd->pw_shell != NULL) && (pwd->pw_shell[0] != '\0')) {
2031 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", pwd->pw_shell);
2033 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
2034 sid_string_talloc(tc, &sid));
2035 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
2036 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
2037 NEW_PW_FORMAT_SPACE_PADDED_LEN));
2039 smbldap_talloc_autofree_ldapmod(tc, mods);
2041 rc = smbldap_add(state, dn, mods);
2043 if (rc != LDAP_SUCCESS) {
2044 d_fprintf(stderr, _("Failed to add Guest user to "
2045 "ldap directory\n"));
2048 if (is_ipa) {
2049 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
2050 d_fprintf(stderr, _("Failed to read just "
2051 "created user.\n"));
2052 goto failed;
2055 } else {
2056 d_printf(_("found!\n"));
2059 d_printf(_("Checking Guest's group.\n"));
2061 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
2062 if (!pwd) {
2063 d_fprintf(stderr,
2064 _("Failed to find just created Guest account!\n"
2065 " Is nss properly configured?!\n"));
2066 goto failed;
2069 if (pwd->pw_gid == domusers_gid) {
2070 d_printf(_("found!\n"));
2071 goto done;
2074 if (!pdb_getgrgid(gmap, pwd->pw_gid)) {
2075 LDAPMod **mods = NULL;
2076 char *dn;
2077 char *uname;
2078 char *wname;
2079 char *gidstr;
2080 char *gtype;
2081 int rc;
2083 d_printf(_("Adding the Domain Guests group.\n"));
2085 uname = talloc_strdup(tc, "domguests");
2086 wname = talloc_strdup(tc, "Domain Guests");
2087 dn = talloc_asprintf(tc, "cn=%s,%s", "domguests",
2088 lp_ldap_group_suffix(talloc_tos()));
2089 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2090 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
2092 if (!uname || !wname || !dn || !gidstr || !gtype) {
2093 d_fprintf(stderr, _("Out of Memory!\n"));
2094 goto failed;
2097 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
2099 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
2100 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
2101 if (is_ipa) {
2102 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
2103 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
2104 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
2106 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
2107 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
2108 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2109 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
2110 sid_string_talloc(tc, &gsid));
2111 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
2113 smbldap_talloc_autofree_ldapmod(tc, mods);
2115 rc = smbldap_add(state, dn, mods);
2117 if (rc != LDAP_SUCCESS) {
2118 d_fprintf(stderr,
2119 _("Failed to add Domain Guests group to ldap "
2120 "directory\n"));
2122 } else {
2123 d_printf(_("found!\n"));
2127 done:
2128 talloc_free(state);
2129 return 0;
2131 failed:
2132 talloc_free(state);
2133 return -1;
2136 #endif
2138 /***********************************************************
2139 migrated functionality from smbgroupedit
2140 **********************************************************/
2141 int net_sam(struct net_context *c, int argc, const char **argv)
2143 struct functable func[] = {
2145 "createbuiltingroup",
2146 net_sam_createbuiltingroup,
2147 NET_TRANSPORT_LOCAL,
2148 N_("Create a new BUILTIN group"),
2149 N_("net sam createbuiltingroup\n"
2150 " Create a new BUILTIN group")
2153 "createlocalgroup",
2154 net_sam_createlocalgroup,
2155 NET_TRANSPORT_LOCAL,
2156 N_("Create a new local group"),
2157 N_("net sam createlocalgroup\n"
2158 " Create a new local group")
2161 "createdomaingroup",
2162 net_sam_createdomaingroup,
2163 NET_TRANSPORT_LOCAL,
2164 N_("Create a new group"),
2165 N_("net sam createdomaingroup\n"
2166 " Create a new group")
2169 "deletelocalgroup",
2170 net_sam_deletelocalgroup,
2171 NET_TRANSPORT_LOCAL,
2172 N_("Delete an existing local group"),
2173 N_("net sam deletelocalgroup\n"
2174 " Delete an existing local group")
2177 "deletedomaingroup",
2178 net_sam_deletedomaingroup,
2179 NET_TRANSPORT_LOCAL,
2180 N_("Delete a domain group"),
2181 N_("net sam deletedomaingroup\n"
2182 " Delete a group")
2185 "mapunixgroup",
2186 net_sam_mapunixgroup,
2187 NET_TRANSPORT_LOCAL,
2188 N_("Map a unix group to a domain group"),
2189 N_("net sam mapunixgroup\n"
2190 " Map a unix group to a domain group")
2193 "unmapunixgroup",
2194 net_sam_unmapunixgroup,
2195 NET_TRANSPORT_LOCAL,
2196 N_("Remove a group mapping of an unix group to a "
2197 "domain group"),
2198 N_("net sam unmapunixgroup\n"
2199 " Remove a group mapping of an unix group to a "
2200 "domain group")
2203 "addmem",
2204 net_sam_addmem,
2205 NET_TRANSPORT_LOCAL,
2206 N_("Add a member to a group"),
2207 N_("net sam addmem\n"
2208 " Add a member to a group")
2211 "delmem",
2212 net_sam_delmem,
2213 NET_TRANSPORT_LOCAL,
2214 N_("Delete a member from a group"),
2215 N_("net sam delmem\n"
2216 " Delete a member from a group")
2219 "listmem",
2220 net_sam_listmem,
2221 NET_TRANSPORT_LOCAL,
2222 N_("List group members"),
2223 N_("net sam listmem\n"
2224 " List group members")
2227 "list",
2228 net_sam_list,
2229 NET_TRANSPORT_LOCAL,
2230 N_("List users, groups and local groups"),
2231 N_("net sam list\n"
2232 " List users, groups and local groups")
2235 "show",
2236 net_sam_show,
2237 NET_TRANSPORT_LOCAL,
2238 N_("Show details of a SAM entry"),
2239 N_("net sam show\n"
2240 " Show details of a SAM entry")
2243 "set",
2244 net_sam_set,
2245 NET_TRANSPORT_LOCAL,
2246 N_("Set details of a SAM account"),
2247 N_("net sam set\n"
2248 " Set details of a SAM account")
2251 "policy",
2252 net_sam_policy,
2253 NET_TRANSPORT_LOCAL,
2254 N_("Set account policies"),
2255 N_("net sam policy\n"
2256 " Set account policies")
2259 "rights",
2260 net_sam_rights,
2261 NET_TRANSPORT_LOCAL,
2262 N_("Manipulate user privileges"),
2263 N_("net sam rights\n"
2264 " Manipulate user privileges")
2266 #ifdef HAVE_LDAP
2268 "provision",
2269 net_sam_provision,
2270 NET_TRANSPORT_LOCAL,
2271 N_("Provision a clean user database"),
2272 N_("net sam privison\n"
2273 " Provision a clear user database")
2275 #endif
2276 {NULL, NULL, 0, NULL, NULL}
2279 if (getuid() != 0) {
2280 d_fprintf(stderr, _("You are not root, most things won't "
2281 "work\n"));
2284 return net_run_function(c, argc, argv, "net sam", func);