KCC: test suite for the graph_utils
[Samba.git] / source3 / utils / net_sam.c
blob9fe7b6330dace628f95e42406f96c343861cf1bd
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_t 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_t value = 0;
484 uint32_t 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_t 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_t 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_t 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_t 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_t 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_ALIAS) &&
1224 (membertype != SID_NAME_DOM_GRP)) {
1225 d_fprintf(stderr, _("Can't add %s: only users, domain "
1226 "groups and domain local groups "
1227 "can be added. %s is a %s\n"),
1228 argv[0], argv[1],
1229 sid_type_lookup(membertype));
1230 return -1;
1232 status = pdb_add_aliasmem(&group, &member);
1234 if (!NT_STATUS_IS_OK(status)) {
1235 d_fprintf(stderr, _("Adding local group member failed "
1236 "with %s\n"), nt_errstr(status));
1237 return -1;
1239 } else if (grouptype == SID_NAME_DOM_GRP) {
1240 uint32_t grouprid, memberrid;
1242 sid_peek_rid(&group, &grouprid);
1243 sid_peek_rid(&member, &memberrid);
1245 status = pdb_add_groupmem(talloc_tos(), grouprid, memberrid);
1246 if (!NT_STATUS_IS_OK(status)) {
1247 d_fprintf(stderr, _("Adding domain group member failed "
1248 "with %s\n"), nt_errstr(status));
1249 return -1;
1251 } else {
1252 d_fprintf(stderr, _("Can only add members to local groups so "
1253 "far, %s is a %s\n"), argv[0],
1254 sid_type_lookup(grouptype));
1255 return -1;
1258 d_printf(_("Added %s\\%s to %s\\%s\n"), memberdomain, membername,
1259 groupdomain, groupname);
1261 return 0;
1265 * Delete a group member
1268 static int net_sam_delmem(struct net_context *c, int argc, const char **argv)
1270 const char *groupdomain, *groupname;
1271 const char *memberdomain = NULL;
1272 const char *membername = NULL;
1273 struct dom_sid group, member;
1274 enum lsa_SidType grouptype;
1275 NTSTATUS status;
1277 if (argc != 2 || c->display_usage) {
1278 d_fprintf(stderr,"%s\n%s",
1279 _("Usage:"),
1280 _("net sam delmem <group> <member>\n"));
1281 return -1;
1284 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1285 &groupdomain, &groupname, &group, &grouptype)) {
1286 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1287 return -1;
1290 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1291 &memberdomain, &membername, &member, NULL)) {
1292 if (!string_to_sid(&member, argv[1])) {
1293 d_fprintf(stderr, _("Could not find member %s\n"),
1294 argv[1]);
1295 return -1;
1299 if ((grouptype == SID_NAME_ALIAS) ||
1300 (grouptype == SID_NAME_WKN_GRP)) {
1301 status = pdb_del_aliasmem(&group, &member);
1303 if (!NT_STATUS_IS_OK(status)) {
1304 d_fprintf(stderr,_("Deleting local group member failed "
1305 "with %s\n"), nt_errstr(status));
1306 return -1;
1308 } else if (grouptype == SID_NAME_DOM_GRP) {
1309 uint32_t grouprid, memberrid;
1311 sid_peek_rid(&group, &grouprid);
1312 sid_peek_rid(&member, &memberrid);
1314 status = pdb_del_groupmem(talloc_tos(), grouprid, memberrid);
1315 if (!NT_STATUS_IS_OK(status)) {
1316 d_fprintf(stderr, _("Deleting domain group member "
1317 "failed with %s\n"), nt_errstr(status));
1318 return -1;
1320 } else {
1321 d_fprintf(stderr, _("Can only delete members from local groups "
1322 "so far, %s is a %s\n"), argv[0],
1323 sid_type_lookup(grouptype));
1324 return -1;
1327 if (membername != NULL) {
1328 d_printf(_("Deleted %s\\%s from %s\\%s\n"),
1329 memberdomain, membername, groupdomain, groupname);
1330 } else {
1331 d_printf(_("Deleted %s from %s\\%s\n"),
1332 sid_string_tos(&member), groupdomain, groupname);
1335 return 0;
1339 * List group members
1342 static int net_sam_listmem(struct net_context *c, int argc, const char **argv)
1344 const char *groupdomain, *groupname;
1345 struct dom_sid group;
1346 struct dom_sid *members = NULL;
1347 size_t i, num_members = 0;
1348 enum lsa_SidType grouptype;
1349 NTSTATUS status;
1351 if (argc != 1 || c->display_usage) {
1352 d_fprintf(stderr, "%s\n%s",
1353 _("Usage:"),
1354 _("net sam listmem <group>\n"));
1355 return -1;
1358 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1359 &groupdomain, &groupname, &group, &grouptype)) {
1360 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1361 return -1;
1364 if ((grouptype == SID_NAME_ALIAS) ||
1365 (grouptype == SID_NAME_WKN_GRP)) {
1366 status = pdb_enum_aliasmem(&group, talloc_tos(), &members,
1367 &num_members);
1368 if (!NT_STATUS_IS_OK(status)) {
1369 d_fprintf(stderr, _("Listing group members failed with "
1370 "%s\n"), nt_errstr(status));
1371 return -1;
1373 } else if (grouptype == SID_NAME_DOM_GRP) {
1374 uint32_t *rids;
1376 status = pdb_enum_group_members(talloc_tos(), &group,
1377 &rids, &num_members);
1378 if (!NT_STATUS_IS_OK(status)) {
1379 d_fprintf(stderr, _("Listing group members failed with "
1380 "%s\n"), nt_errstr(status));
1381 return -1;
1384 members = talloc_array(talloc_tos(), struct dom_sid,
1385 num_members);
1386 if (members == NULL) {
1387 TALLOC_FREE(rids);
1388 return -1;
1391 for (i=0; i<num_members; i++) {
1392 sid_compose(&members[i], get_global_sam_sid(),
1393 rids[i]);
1395 TALLOC_FREE(rids);
1396 } else {
1397 d_fprintf(stderr,_("Can only list local group members so far.\n"
1398 "%s is a %s\n"), argv[0], sid_type_lookup(grouptype));
1399 return -1;
1402 d_printf(_("%s\\%s has %u members\n"), groupdomain, groupname,
1403 (unsigned int)num_members);
1404 for (i=0; i<num_members; i++) {
1405 const char *dom, *name;
1406 if (lookup_sid(talloc_tos(), &members[i], &dom, &name, NULL)) {
1407 d_printf(" %s\\%s\n", dom, name);
1408 } else {
1409 d_printf(" %s\n", sid_string_tos(&members[i]));
1413 TALLOC_FREE(members);
1415 return 0;
1419 * Do the listing
1421 static int net_sam_do_list(struct net_context *c, int argc, const char **argv,
1422 struct pdb_search *search, const char *what)
1424 bool verbose = (argc == 1);
1426 if ((argc > 1) || c->display_usage ||
1427 ((argc == 1) && !strequal(argv[0], "verbose"))) {
1428 d_fprintf(stderr, "%s\n", _("Usage:"));
1429 d_fprintf(stderr, _("net sam list %s [verbose]\n"), what);
1430 return -1;
1433 if (search == NULL) {
1434 d_fprintf(stderr, _("Could not start search\n"));
1435 return -1;
1438 while (true) {
1439 struct samr_displayentry entry;
1440 if (!search->next_entry(search, &entry)) {
1441 break;
1443 if (verbose) {
1444 d_printf("%s:%d:%s\n",
1445 entry.account_name,
1446 entry.rid,
1447 entry.description);
1448 } else {
1449 d_printf("%s\n", entry.account_name);
1453 TALLOC_FREE(search);
1454 return 0;
1457 static int net_sam_list_users(struct net_context *c, int argc,
1458 const char **argv)
1460 return net_sam_do_list(c, argc, argv,
1461 pdb_search_users(talloc_tos(), ACB_NORMAL),
1462 "users");
1465 static int net_sam_list_groups(struct net_context *c, int argc,
1466 const char **argv)
1468 return net_sam_do_list(c, argc, argv, pdb_search_groups(talloc_tos()),
1469 "groups");
1472 static int net_sam_list_localgroups(struct net_context *c, int argc,
1473 const char **argv)
1475 return net_sam_do_list(c, argc, argv,
1476 pdb_search_aliases(talloc_tos(),
1477 get_global_sam_sid()),
1478 "localgroups");
1481 static int net_sam_list_builtin(struct net_context *c, int argc,
1482 const char **argv)
1484 return net_sam_do_list(c, argc, argv,
1485 pdb_search_aliases(talloc_tos(),
1486 &global_sid_Builtin),
1487 "builtin");
1490 static int net_sam_list_workstations(struct net_context *c, int argc,
1491 const char **argv)
1493 return net_sam_do_list(c, argc, argv,
1494 pdb_search_users(talloc_tos(), ACB_WSTRUST),
1495 "workstations");
1499 * List stuff
1502 static int net_sam_list(struct net_context *c, int argc, const char **argv)
1504 struct functable func[] = {
1506 "users",
1507 net_sam_list_users,
1508 NET_TRANSPORT_LOCAL,
1509 N_("List SAM users"),
1510 N_("net sam list users\n"
1511 " List SAM users")
1514 "groups",
1515 net_sam_list_groups,
1516 NET_TRANSPORT_LOCAL,
1517 N_("List SAM groups"),
1518 N_("net sam list groups\n"
1519 " List SAM groups")
1522 "localgroups",
1523 net_sam_list_localgroups,
1524 NET_TRANSPORT_LOCAL,
1525 N_("List SAM local groups"),
1526 N_("net sam list localgroups\n"
1527 " List SAM local groups")
1530 "builtin",
1531 net_sam_list_builtin,
1532 NET_TRANSPORT_LOCAL,
1533 N_("List builtin groups"),
1534 N_("net sam list builtin\n"
1535 " List builtin groups")
1538 "workstations",
1539 net_sam_list_workstations,
1540 NET_TRANSPORT_LOCAL,
1541 N_("List domain member workstations"),
1542 N_("net sam list workstations\n"
1543 " List domain member workstations")
1545 {NULL, NULL, 0, NULL, NULL}
1548 return net_run_function(c, argc, argv, "net sam list", func);
1552 * Show details of SAM entries
1555 static int net_sam_show(struct net_context *c, int argc, const char **argv)
1557 struct dom_sid sid;
1558 enum lsa_SidType type;
1559 const char *dom, *name;
1561 if (argc != 1 || c->display_usage) {
1562 d_fprintf(stderr, "%s\n%s",
1563 _("Usage:"),
1564 _("net sam show <name>\n"));
1565 return -1;
1568 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1569 &dom, &name, &sid, &type)) {
1570 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
1571 return -1;
1574 d_printf(_("%s\\%s is a %s with SID %s\n"), dom, name,
1575 sid_type_lookup(type), sid_string_tos(&sid));
1577 return 0;
1580 #ifdef HAVE_LDAP
1583 * Init an LDAP tree with default users and Groups
1584 * if ldapsam:editposix is enabled
1587 static int net_sam_provision(struct net_context *c, int argc, const char **argv)
1589 TALLOC_CTX *tc;
1590 char *ldap_bk;
1591 char *ldap_uri = NULL;
1592 char *p;
1593 struct smbldap_state *state = NULL;
1594 GROUP_MAP *gmap = NULL;
1595 struct dom_sid gsid;
1596 gid_t domusers_gid = -1;
1597 gid_t domadmins_gid = -1;
1598 struct samu *samuser;
1599 struct passwd *pwd;
1600 bool is_ipa = false;
1601 char *bind_dn = NULL;
1602 char *bind_secret = NULL;
1603 NTSTATUS status;
1605 if (c->display_usage) {
1606 d_printf( "%s\n"
1607 "net sam provision\n"
1608 " %s\n",
1609 _("Usage:"),
1610 _("Init an LDAP tree with default users/groups"));
1611 return 0;
1614 tc = talloc_new(NULL);
1615 if (!tc) {
1616 d_fprintf(stderr, _("Out of Memory!\n"));
1617 return -1;
1620 if ((ldap_bk = talloc_strdup(tc, lp_passdb_backend())) == NULL) {
1621 d_fprintf(stderr, _("talloc failed\n"));
1622 talloc_free(tc);
1623 return -1;
1625 p = strchr(ldap_bk, ':');
1626 if (p) {
1627 *p = 0;
1628 ldap_uri = talloc_strdup(tc, p+1);
1629 trim_char(ldap_uri, ' ', ' ');
1632 trim_char(ldap_bk, ' ', ' ');
1634 if (strcmp(ldap_bk, "IPA_ldapsam") == 0 ) {
1635 is_ipa = true;
1638 if (strcmp(ldap_bk, "ldapsam") != 0 && !is_ipa ) {
1639 d_fprintf(stderr,
1640 _("Provisioning works only with ldapsam backend\n"));
1641 goto failed;
1644 if (!lp_parm_bool(-1, "ldapsam", "trusted", false) ||
1645 !lp_parm_bool(-1, "ldapsam", "editposix", false)) {
1647 d_fprintf(stderr, _("Provisioning works only if ldapsam:trusted"
1648 " and ldapsam:editposix are enabled.\n"));
1649 goto failed;
1652 if (!is_ipa && !winbind_ping()) {
1653 d_fprintf(stderr, _("winbind seems not to run. Provisioning "
1654 "LDAP only works when winbind runs.\n"));
1655 goto failed;
1658 if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
1659 d_fprintf(stderr, _("Failed to retrieve LDAP password from secrets.tdb\n"));
1660 goto failed;
1663 status = smbldap_init(tc, NULL, ldap_uri, false, bind_dn, bind_secret, &state);
1665 memset(bind_secret, '\0', strlen(bind_secret));
1666 SAFE_FREE(bind_secret);
1667 SAFE_FREE(bind_dn);
1669 if (!NT_STATUS_IS_OK(status)) {
1670 d_fprintf(stderr, _("Unable to connect to the LDAP server.\n"));
1671 goto failed;
1674 d_printf(_("Checking for Domain Users group.\n"));
1676 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS);
1678 gmap = talloc_zero(tc, GROUP_MAP);
1679 if (!gmap) {
1680 d_printf(_("Out of memory!\n"));
1681 goto failed;
1684 if (!pdb_getgrsid(gmap, gsid)) {
1685 LDAPMod **mods = NULL;
1686 char *dn;
1687 char *uname;
1688 char *wname;
1689 char *gidstr;
1690 char *gtype;
1691 int rc;
1693 d_printf(_("Adding the Domain Users group.\n"));
1695 /* lets allocate a new groupid for this group */
1696 if (is_ipa) {
1697 domusers_gid = 999;
1698 } else {
1699 if (!winbind_allocate_gid(&domusers_gid)) {
1700 d_fprintf(stderr, _("Unable to allocate a new gid to "
1701 "create Domain Users group!\n"));
1702 goto domu_done;
1706 uname = talloc_strdup(tc, "domusers");
1707 wname = talloc_strdup(tc, "Domain Users");
1708 dn = talloc_asprintf(tc, "cn=%s,%s", "domusers",
1709 lp_ldap_group_suffix(talloc_tos()));
1710 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domusers_gid);
1711 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1713 if (!uname || !wname || !dn || !gidstr || !gtype) {
1714 d_fprintf(stderr, "Out of Memory!\n");
1715 goto failed;
1718 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1719 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1720 if (is_ipa) {
1721 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1722 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1723 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1725 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1726 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1727 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1728 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1729 sid_string_talloc(tc, &gsid));
1730 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1732 smbldap_talloc_autofree_ldapmod(tc, mods);
1734 rc = smbldap_add(state, dn, mods);
1736 if (rc != LDAP_SUCCESS) {
1737 d_fprintf(stderr, _("Failed to add Domain Users group "
1738 "to ldap directory\n"));
1741 if (is_ipa) {
1742 if (!pdb_getgrsid(gmap, gsid)) {
1743 d_fprintf(stderr, _("Failed to read just "
1744 "created domain group.\n"));
1745 goto failed;
1746 } else {
1747 domusers_gid = gmap->gid;
1750 } else {
1751 domusers_gid = gmap->gid;
1752 d_printf(_("found!\n"));
1755 domu_done:
1757 d_printf(_("Checking for Domain Admins group.\n"));
1759 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
1761 if (!pdb_getgrsid(gmap, gsid)) {
1762 LDAPMod **mods = NULL;
1763 char *dn;
1764 char *uname;
1765 char *wname;
1766 char *gidstr;
1767 char *gtype;
1768 int rc;
1770 d_printf(_("Adding the Domain Admins group.\n"));
1772 /* lets allocate a new groupid for this group */
1773 if (is_ipa) {
1774 domadmins_gid = 999;
1775 } else {
1776 if (!winbind_allocate_gid(&domadmins_gid)) {
1777 d_fprintf(stderr, _("Unable to allocate a new gid to "
1778 "create Domain Admins group!\n"));
1779 goto doma_done;
1783 uname = talloc_strdup(tc, "domadmins");
1784 wname = talloc_strdup(tc, "Domain Admins");
1785 dn = talloc_asprintf(tc, "cn=%s,%s", "domadmins",
1786 lp_ldap_group_suffix(talloc_tos()));
1787 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1788 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1790 if (!uname || !wname || !dn || !gidstr || !gtype) {
1791 d_fprintf(stderr, _("Out of Memory!\n"));
1792 goto failed;
1795 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1796 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1797 if (is_ipa) {
1798 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1799 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1800 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1802 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1803 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1804 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1805 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1806 sid_string_talloc(tc, &gsid));
1807 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1809 smbldap_talloc_autofree_ldapmod(tc, mods);
1811 rc = smbldap_add(state, dn, mods);
1813 if (rc != LDAP_SUCCESS) {
1814 d_fprintf(stderr, _("Failed to add Domain Admins group "
1815 "to ldap directory\n"));
1818 if (is_ipa) {
1819 if (!pdb_getgrsid(gmap, gsid)) {
1820 d_fprintf(stderr, _("Failed to read just "
1821 "created domain group.\n"));
1822 goto failed;
1823 } else {
1824 domadmins_gid = gmap->gid;
1827 } else {
1828 domadmins_gid = gmap->gid;
1829 d_printf(_("found!\n"));
1832 doma_done:
1834 d_printf(_("Check for Administrator account.\n"));
1836 samuser = samu_new(tc);
1837 if (!samuser) {
1838 d_fprintf(stderr, _("Out of Memory!\n"));
1839 goto failed;
1842 if (!pdb_getsampwnam(samuser, "Administrator")) {
1843 LDAPMod **mods = NULL;
1844 struct dom_sid sid;
1845 char *dn;
1846 char *name;
1847 char *uidstr;
1848 char *gidstr;
1849 char *shell;
1850 char *dir;
1851 char *princ;
1852 uid_t uid;
1853 int rc;
1855 d_printf(_("Adding the Administrator user.\n"));
1857 if (domadmins_gid == -1) {
1858 d_fprintf(stderr,
1859 _("Can't create Administrator user, Domain "
1860 "Admins group not available!\n"));
1861 goto done;
1864 if (is_ipa) {
1865 uid = 999;
1866 } else {
1867 if (!winbind_allocate_uid(&uid)) {
1868 d_fprintf(stderr,
1869 _("Unable to allocate a new uid to create "
1870 "the Administrator user!\n"));
1871 goto done;
1875 name = talloc_strdup(tc, "Administrator");
1876 dn = talloc_asprintf(tc, "uid=Administrator,%s",
1877 lp_ldap_user_suffix(talloc_tos()));
1878 uidstr = talloc_asprintf(tc, "%u", (unsigned int)uid);
1879 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1880 dir = talloc_sub_specified(tc, lp_template_homedir(),
1881 "Administrator",
1882 NULL,
1883 get_global_sam_name(),
1884 uid, domadmins_gid);
1885 shell = talloc_sub_specified(tc, lp_template_shell(),
1886 "Administrator",
1887 NULL,
1888 get_global_sam_name(),
1889 uid, domadmins_gid);
1891 if (!name || !dn || !uidstr || !gidstr || !dir || !shell) {
1892 d_fprintf(stderr, _("Out of Memory!\n"));
1893 goto failed;
1896 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
1898 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
1899 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
1900 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
1901 if (is_ipa) {
1902 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
1903 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
1904 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
1905 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
1906 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
1907 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
1908 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
1909 princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
1910 if (!princ) {
1911 d_fprintf(stderr, _("Out of Memory!\n"));
1912 goto failed;
1914 smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
1916 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
1917 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
1918 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
1919 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
1920 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1921 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", dir);
1922 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", shell);
1923 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
1924 sid_string_talloc(tc, &sid));
1925 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
1926 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
1927 NEW_PW_FORMAT_SPACE_PADDED_LEN));
1929 smbldap_talloc_autofree_ldapmod(tc, mods);
1931 rc = smbldap_add(state, dn, mods);
1933 if (rc != LDAP_SUCCESS) {
1934 d_fprintf(stderr, _("Failed to add Administrator user "
1935 "to ldap directory\n"));
1938 if (is_ipa) {
1939 if (!pdb_getsampwnam(samuser, "Administrator")) {
1940 d_fprintf(stderr, _("Failed to read just "
1941 "created user.\n"));
1942 goto failed;
1945 } else {
1946 d_printf(_("found!\n"));
1949 d_printf(_("Checking for Guest user.\n"));
1951 samuser = samu_new(tc);
1952 if (!samuser) {
1953 d_fprintf(stderr, _("Out of Memory!\n"));
1954 goto failed;
1957 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
1958 LDAPMod **mods = NULL;
1959 struct dom_sid sid;
1960 char *dn;
1961 char *uidstr;
1962 char *gidstr;
1963 int rc;
1965 d_printf(_("Adding the Guest user.\n"));
1967 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
1969 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
1971 if (!pwd) {
1972 if (domusers_gid == -1) {
1973 d_fprintf(stderr,
1974 _("Can't create Guest user, Domain "
1975 "Users group not available!\n"));
1976 goto done;
1978 if ((pwd = talloc(tc, struct passwd)) == NULL) {
1979 d_fprintf(stderr, _("talloc failed\n"));
1980 goto done;
1982 pwd->pw_name = talloc_strdup(pwd, lp_guest_account());
1984 if (is_ipa) {
1985 pwd->pw_uid = 999;
1986 } else {
1987 if (!winbind_allocate_uid(&(pwd->pw_uid))) {
1988 d_fprintf(stderr,
1989 _("Unable to allocate a new uid to "
1990 "create the Guest user!\n"));
1991 goto done;
1994 pwd->pw_gid = domusers_gid;
1995 pwd->pw_dir = talloc_strdup(tc, "/");
1996 pwd->pw_shell = talloc_strdup(tc, "/bin/false");
1997 if (!pwd->pw_dir || !pwd->pw_shell) {
1998 d_fprintf(stderr, _("Out of Memory!\n"));
1999 goto failed;
2003 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name,
2004 lp_ldap_user_suffix (talloc_tos()));
2005 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
2006 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2007 if (!dn || !uidstr || !gidstr) {
2008 d_fprintf(stderr, _("Out of Memory!\n"));
2009 goto failed;
2012 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
2013 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
2014 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
2015 if (is_ipa) {
2016 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
2017 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
2018 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
2019 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
2020 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
2021 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
2022 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
2024 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
2025 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
2026 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", pwd->pw_name);
2027 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
2028 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2029 if ((pwd->pw_dir != NULL) && (pwd->pw_dir[0] != '\0')) {
2030 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", pwd->pw_dir);
2032 if ((pwd->pw_shell != NULL) && (pwd->pw_shell[0] != '\0')) {
2033 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", pwd->pw_shell);
2035 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
2036 sid_string_talloc(tc, &sid));
2037 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
2038 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
2039 NEW_PW_FORMAT_SPACE_PADDED_LEN));
2041 smbldap_talloc_autofree_ldapmod(tc, mods);
2043 rc = smbldap_add(state, dn, mods);
2045 if (rc != LDAP_SUCCESS) {
2046 d_fprintf(stderr, _("Failed to add Guest user to "
2047 "ldap directory\n"));
2050 if (is_ipa) {
2051 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
2052 d_fprintf(stderr, _("Failed to read just "
2053 "created user.\n"));
2054 goto failed;
2057 } else {
2058 d_printf(_("found!\n"));
2061 d_printf(_("Checking Guest's group.\n"));
2063 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
2064 if (!pwd) {
2065 d_fprintf(stderr,
2066 _("Failed to find just created Guest account!\n"
2067 " Is nss properly configured?!\n"));
2068 goto failed;
2071 if (pwd->pw_gid == domusers_gid) {
2072 d_printf(_("found!\n"));
2073 goto done;
2076 if (!pdb_getgrgid(gmap, pwd->pw_gid)) {
2077 LDAPMod **mods = NULL;
2078 char *dn;
2079 char *uname;
2080 char *wname;
2081 char *gidstr;
2082 char *gtype;
2083 int rc;
2085 d_printf(_("Adding the Domain Guests group.\n"));
2087 uname = talloc_strdup(tc, "domguests");
2088 wname = talloc_strdup(tc, "Domain Guests");
2089 dn = talloc_asprintf(tc, "cn=%s,%s", "domguests",
2090 lp_ldap_group_suffix(talloc_tos()));
2091 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2092 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
2094 if (!uname || !wname || !dn || !gidstr || !gtype) {
2095 d_fprintf(stderr, _("Out of Memory!\n"));
2096 goto failed;
2099 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
2101 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
2102 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
2103 if (is_ipa) {
2104 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
2105 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
2106 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
2108 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
2109 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
2110 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2111 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
2112 sid_string_talloc(tc, &gsid));
2113 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
2115 smbldap_talloc_autofree_ldapmod(tc, mods);
2117 rc = smbldap_add(state, dn, mods);
2119 if (rc != LDAP_SUCCESS) {
2120 d_fprintf(stderr,
2121 _("Failed to add Domain Guests group to ldap "
2122 "directory\n"));
2124 } else {
2125 d_printf(_("found!\n"));
2129 done:
2130 talloc_free(state);
2131 return 0;
2133 failed:
2134 talloc_free(state);
2135 return -1;
2138 #endif
2140 /***********************************************************
2141 migrated functionality from smbgroupedit
2142 **********************************************************/
2143 int net_sam(struct net_context *c, int argc, const char **argv)
2145 struct functable func[] = {
2147 "createbuiltingroup",
2148 net_sam_createbuiltingroup,
2149 NET_TRANSPORT_LOCAL,
2150 N_("Create a new BUILTIN group"),
2151 N_("net sam createbuiltingroup\n"
2152 " Create a new BUILTIN group")
2155 "createlocalgroup",
2156 net_sam_createlocalgroup,
2157 NET_TRANSPORT_LOCAL,
2158 N_("Create a new local group"),
2159 N_("net sam createlocalgroup\n"
2160 " Create a new local group")
2163 "createdomaingroup",
2164 net_sam_createdomaingroup,
2165 NET_TRANSPORT_LOCAL,
2166 N_("Create a new group"),
2167 N_("net sam createdomaingroup\n"
2168 " Create a new group")
2171 "deletelocalgroup",
2172 net_sam_deletelocalgroup,
2173 NET_TRANSPORT_LOCAL,
2174 N_("Delete an existing local group"),
2175 N_("net sam deletelocalgroup\n"
2176 " Delete an existing local group")
2179 "deletedomaingroup",
2180 net_sam_deletedomaingroup,
2181 NET_TRANSPORT_LOCAL,
2182 N_("Delete a domain group"),
2183 N_("net sam deletedomaingroup\n"
2184 " Delete a group")
2187 "mapunixgroup",
2188 net_sam_mapunixgroup,
2189 NET_TRANSPORT_LOCAL,
2190 N_("Map a unix group to a domain group"),
2191 N_("net sam mapunixgroup\n"
2192 " Map a unix group to a domain group")
2195 "unmapunixgroup",
2196 net_sam_unmapunixgroup,
2197 NET_TRANSPORT_LOCAL,
2198 N_("Remove a group mapping of an unix group to a "
2199 "domain group"),
2200 N_("net sam unmapunixgroup\n"
2201 " Remove a group mapping of an unix group to a "
2202 "domain group")
2205 "addmem",
2206 net_sam_addmem,
2207 NET_TRANSPORT_LOCAL,
2208 N_("Add a member to a group"),
2209 N_("net sam addmem\n"
2210 " Add a member to a group")
2213 "delmem",
2214 net_sam_delmem,
2215 NET_TRANSPORT_LOCAL,
2216 N_("Delete a member from a group"),
2217 N_("net sam delmem\n"
2218 " Delete a member from a group")
2221 "listmem",
2222 net_sam_listmem,
2223 NET_TRANSPORT_LOCAL,
2224 N_("List group members"),
2225 N_("net sam listmem\n"
2226 " List group members")
2229 "list",
2230 net_sam_list,
2231 NET_TRANSPORT_LOCAL,
2232 N_("List users, groups and local groups"),
2233 N_("net sam list\n"
2234 " List users, groups and local groups")
2237 "show",
2238 net_sam_show,
2239 NET_TRANSPORT_LOCAL,
2240 N_("Show details of a SAM entry"),
2241 N_("net sam show\n"
2242 " Show details of a SAM entry")
2245 "set",
2246 net_sam_set,
2247 NET_TRANSPORT_LOCAL,
2248 N_("Set details of a SAM account"),
2249 N_("net sam set\n"
2250 " Set details of a SAM account")
2253 "policy",
2254 net_sam_policy,
2255 NET_TRANSPORT_LOCAL,
2256 N_("Set account policies"),
2257 N_("net sam policy\n"
2258 " Set account policies")
2261 "rights",
2262 net_sam_rights,
2263 NET_TRANSPORT_LOCAL,
2264 N_("Manipulate user privileges"),
2265 N_("net sam rights\n"
2266 " Manipulate user privileges")
2268 #ifdef HAVE_LDAP
2270 "provision",
2271 net_sam_provision,
2272 NET_TRANSPORT_LOCAL,
2273 N_("Provision a clean user database"),
2274 N_("net sam privison\n"
2275 " Provision a clear user database")
2277 #endif
2278 {NULL, NULL, 0, NULL, NULL}
2281 if (getuid() != 0) {
2282 d_fprintf(stderr, _("You are not root, most things won't "
2283 "work\n"));
2286 return net_run_function(c, argc, argv, "net sam", func);