s3:tests: Fix syntax error in test_smbclient_kerberos.sh
[samba4-gss.git] / source3 / utils / net_sam.c
blob5c1e007381e7f2ba2b15c751865d01a0bcff8d57
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"
34 #include "lib/util/smb_strtox.h"
35 #include "lib/util/string_wrappers.h"
36 #include "source3/lib/substitute.h"
39 * Set a user's data
42 static int net_sam_userset(struct net_context *c, int argc, const char **argv,
43 const char *field,
44 bool (*fn)(struct samu *, const char *,
45 enum pdb_value_state))
47 struct samu *sam_acct = NULL;
48 struct dom_sid sid;
49 enum lsa_SidType type;
50 const char *dom, *name;
51 NTSTATUS status;
53 if (argc != 2 || c->display_usage) {
54 d_fprintf(stderr, "%s\n", _("Usage:"));
55 d_fprintf(stderr, _("net sam set %s <user> <value>\n"),
56 field);
57 return -1;
60 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
61 &dom, &name, &sid, &type)) {
62 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
63 return -1;
66 if (type != SID_NAME_USER) {
67 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
68 sid_type_lookup(type));
69 return -1;
72 if ( !(sam_acct = samu_new( NULL )) ) {
73 d_fprintf(stderr, _("Internal error\n"));
74 return -1;
77 if (!pdb_getsampwsid(sam_acct, &sid)) {
78 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
79 return -1;
82 if (!fn(sam_acct, argv[1], PDB_CHANGED)) {
83 d_fprintf(stderr, _("Internal error\n"));
84 return -1;
87 status = pdb_update_sam_account(sam_acct);
88 if (!NT_STATUS_IS_OK(status)) {
89 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
90 argv[0], nt_errstr(status));
91 return -1;
94 TALLOC_FREE(sam_acct);
96 d_printf(_("Updated %s for %s\\%s to %s\n"), field, dom, name, argv[1]);
97 return 0;
100 static int net_sam_set_fullname(struct net_context *c, int argc,
101 const char **argv)
103 return net_sam_userset(c, argc, argv, "fullname",
104 pdb_set_fullname);
107 static int net_sam_set_logonscript(struct net_context *c, int argc,
108 const char **argv)
110 return net_sam_userset(c, argc, argv, "logonscript",
111 pdb_set_logon_script);
114 static int net_sam_set_profilepath(struct net_context *c, int argc,
115 const char **argv)
117 return net_sam_userset(c, argc, argv, "profilepath",
118 pdb_set_profile_path);
121 static int net_sam_set_homedrive(struct net_context *c, int argc,
122 const char **argv)
124 return net_sam_userset(c, argc, argv, "homedrive",
125 pdb_set_dir_drive);
128 static int net_sam_set_homedir(struct net_context *c, int argc,
129 const char **argv)
131 return net_sam_userset(c, argc, argv, "homedir",
132 pdb_set_homedir);
135 static int net_sam_set_workstations(struct net_context *c, int argc,
136 const char **argv)
138 return net_sam_userset(c, argc, argv, "workstations",
139 pdb_set_workstations);
143 * Set account flags
146 static int net_sam_set_userflag(struct net_context *c, int argc,
147 const char **argv, const char *field,
148 uint16_t flag)
150 struct samu *sam_acct = NULL;
151 struct dom_sid sid;
152 enum lsa_SidType type;
153 const char *dom, *name;
154 NTSTATUS status;
155 uint32_t acct_flags;
157 if ((argc != 2) || c->display_usage ||
158 (!strequal(argv[1], "yes") &&
159 !strequal(argv[1], "no"))) {
160 d_fprintf(stderr, "%s\n", _("Usage:"));
161 d_fprintf(stderr, _("net sam set %s <user> [yes|no]\n"),
162 field);
163 return -1;
166 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
167 &dom, &name, &sid, &type)) {
168 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
169 return -1;
172 if (type != SID_NAME_USER) {
173 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
174 sid_type_lookup(type));
175 return -1;
178 if ( !(sam_acct = samu_new( NULL )) ) {
179 d_fprintf(stderr, _("Internal error\n"));
180 return -1;
183 if (!pdb_getsampwsid(sam_acct, &sid)) {
184 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
185 return -1;
188 acct_flags = pdb_get_acct_ctrl(sam_acct);
190 if (strequal(argv[1], "yes")) {
191 acct_flags |= flag;
192 } else {
193 acct_flags &= ~flag;
196 pdb_set_acct_ctrl(sam_acct, acct_flags, PDB_CHANGED);
198 status = pdb_update_sam_account(sam_acct);
199 if (!NT_STATUS_IS_OK(status)) {
200 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
201 argv[0], nt_errstr(status));
202 return -1;
205 TALLOC_FREE(sam_acct);
207 d_fprintf(stderr, _("Updated flag %s for %s\\%s to %s\n"), field, dom,
208 name, argv[1]);
209 return 0;
212 static int net_sam_set_disabled(struct net_context *c, int argc,
213 const char **argv)
215 return net_sam_set_userflag(c, argc, argv, "disabled", ACB_DISABLED);
218 static int net_sam_set_pwnotreq(struct net_context *c, int argc,
219 const char **argv)
221 return net_sam_set_userflag(c, argc, argv, "pwnotreq", ACB_PWNOTREQ);
224 static int net_sam_set_autolock(struct net_context *c, int argc,
225 const char **argv)
227 return net_sam_set_userflag(c, argc, argv, "autolock", ACB_AUTOLOCK);
230 static int net_sam_set_pwnoexp(struct net_context *c, int argc,
231 const char **argv)
233 return net_sam_set_userflag(c, argc, argv, "pwnoexp", ACB_PWNOEXP);
237 * Set pass last change time, based on force pass change now
240 static int net_sam_set_pwdmustchangenow(struct net_context *c, int argc,
241 const char **argv)
243 struct samu *sam_acct = NULL;
244 struct dom_sid sid;
245 enum lsa_SidType type;
246 const char *dom, *name;
247 NTSTATUS status;
249 if ((argc != 2) || c->display_usage ||
250 (!strequal(argv[1], "yes") &&
251 !strequal(argv[1], "no"))) {
252 d_fprintf(stderr, "%s\n%s",
253 _("Usage:"),
254 _("net sam set pwdmustchangenow <user> [yes|no]\n"));
255 return -1;
258 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
259 &dom, &name, &sid, &type)) {
260 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
261 return -1;
264 if (type != SID_NAME_USER) {
265 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
266 sid_type_lookup(type));
267 return -1;
270 if ( !(sam_acct = samu_new( NULL )) ) {
271 d_fprintf(stderr, _("Internal error\n"));
272 return -1;
275 if (!pdb_getsampwsid(sam_acct, &sid)) {
276 d_fprintf(stderr, _("Loading user %s failed\n"), argv[0]);
277 return -1;
280 if (strequal(argv[1], "yes")) {
281 pdb_set_pass_last_set_time(sam_acct, 0, PDB_CHANGED);
282 } else {
283 pdb_set_pass_last_set_time(sam_acct, time(NULL), PDB_CHANGED);
286 status = pdb_update_sam_account(sam_acct);
287 if (!NT_STATUS_IS_OK(status)) {
288 d_fprintf(stderr, _("Updating sam account %s failed with %s\n"),
289 argv[0], nt_errstr(status));
290 return -1;
293 TALLOC_FREE(sam_acct);
295 d_fprintf(stderr, _("Updated 'user must change password at next logon' "
296 "for %s\\%s to %s\n"), dom,
297 name, argv[1]);
298 return 0;
303 * Set a user's or a group's comment
306 static int net_sam_set_comment(struct net_context *c, int argc,
307 const char **argv)
309 GROUP_MAP *map;
310 struct dom_sid sid;
311 enum lsa_SidType type;
312 const char *dom, *name;
313 NTSTATUS status;
315 if (argc != 2 || c->display_usage) {
316 d_fprintf(stderr, "%s\n%s",
317 _("Usage:"),
318 _("net sam set comment <name> <comment>\n"));
319 return -1;
322 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
323 &dom, &name, &sid, &type)) {
324 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
325 return -1;
328 if (type == SID_NAME_USER) {
329 return net_sam_userset(c, argc, argv, "comment",
330 pdb_set_acct_desc);
333 if ((type != SID_NAME_DOM_GRP) && (type != SID_NAME_ALIAS) &&
334 (type != SID_NAME_WKN_GRP)) {
335 d_fprintf(stderr, _("%s is a %s, not a group\n"), argv[0],
336 sid_type_lookup(type));
337 return -1;
340 map = talloc_zero(talloc_tos(), GROUP_MAP);
341 if (!map) {
342 d_fprintf(stderr, _("Out of memory!\n"));
343 return -1;
346 if (!pdb_getgrsid(map, sid)) {
347 d_fprintf(stderr, _("Could not load group %s\n"), argv[0]);
348 return -1;
351 map->comment = talloc_strdup(map, argv[1]);
352 if (!map->comment) {
353 d_fprintf(stderr, _("Out of memory!\n"));
354 return -1;
357 status = pdb_update_group_mapping_entry(map);
359 if (!NT_STATUS_IS_OK(status)) {
360 d_fprintf(stderr, _("Updating group mapping entry failed with "
361 "%s\n"), nt_errstr(status));
362 return -1;
365 d_printf("Updated comment of group %s\\%s to %s\n", dom, name,
366 argv[1]);
368 TALLOC_FREE(map);
369 return 0;
372 static int net_sam_set(struct net_context *c, int argc, const char **argv)
374 struct functable func[] = {
376 "homedir",
377 net_sam_set_homedir,
378 NET_TRANSPORT_LOCAL,
379 N_("Change a user's home directory"),
380 N_("net sam set homedir\n"
381 " Change a user's home directory")
384 "profilepath",
385 net_sam_set_profilepath,
386 NET_TRANSPORT_LOCAL,
387 N_("Change a user's profile path"),
388 N_("net sam set profilepath\n"
389 " Change a user's profile path")
392 "comment",
393 net_sam_set_comment,
394 NET_TRANSPORT_LOCAL,
395 N_("Change a users or groups description"),
396 N_("net sam set comment\n"
397 " Change a users or groups description")
400 "fullname",
401 net_sam_set_fullname,
402 NET_TRANSPORT_LOCAL,
403 N_("Change a user's full name"),
404 N_("net sam set fullname\n"
405 " Change a user's full name")
408 "logonscript",
409 net_sam_set_logonscript,
410 NET_TRANSPORT_LOCAL,
411 N_("Change a user's logon script"),
412 N_("net sam set logonscript\n"
413 " Change a user's logon script")
416 "homedrive",
417 net_sam_set_homedrive,
418 NET_TRANSPORT_LOCAL,
419 N_("Change a user's home drive"),
420 N_("net sam set homedrive\n"
421 " Change a user's home drive")
424 "workstations",
425 net_sam_set_workstations,
426 NET_TRANSPORT_LOCAL,
427 N_("Change a user's allowed workstations"),
428 N_("net sam set workstations\n"
429 " Change a user's allowed workstations")
432 "disabled",
433 net_sam_set_disabled,
434 NET_TRANSPORT_LOCAL,
435 N_("Disable/Enable a user"),
436 N_("net sam set disable\n"
437 " Disable/Enable a user")
440 "pwnotreq",
441 net_sam_set_pwnotreq,
442 NET_TRANSPORT_LOCAL,
443 N_("Disable/Enable the password not required flag"),
444 N_("net sam set pwnotreq\n"
445 " Disable/Enable the password not required flag")
448 "autolock",
449 net_sam_set_autolock,
450 NET_TRANSPORT_LOCAL,
451 N_("Disable/Enable a user's lockout flag"),
452 N_("net sam set autolock\n"
453 " Disable/Enable a user's lockout flag")
456 "pwnoexp",
457 net_sam_set_pwnoexp,
458 NET_TRANSPORT_LOCAL,
459 N_("Disable/Enable whether a user's pw does not "
460 "expire"),
461 N_("net sam set pwnoexp\n"
462 " Disable/Enable whether a user's pw does not "
463 "expire")
466 "pwdmustchangenow",
467 net_sam_set_pwdmustchangenow,
468 NET_TRANSPORT_LOCAL,
469 N_("Force users password must change at next logon"),
470 N_("net sam set pwdmustchangenow\n"
471 " Force users password must change at next logon")
473 {NULL, NULL, 0, NULL, NULL}
476 return net_run_function(c, argc, argv, "net sam set", func);
480 * Manage account policies
483 static int net_sam_policy_set(struct net_context *c, int argc, const char **argv)
485 const char *account_policy = NULL;
486 uint32_t value = 0;
487 uint32_t old_value = 0;
488 enum pdb_policy_type field;
489 int err = 0;
491 if (argc != 2 || c->display_usage) {
492 d_fprintf(stderr, "%s\n%s",
493 _("Usage:"),
494 _("net sam policy set \"<account policy>\" <value>\n"));
495 return -1;
498 account_policy = argv[0];
499 field = account_policy_name_to_typenum(account_policy);
501 if (strequal(argv[1], "forever") || strequal(argv[1], "never")
502 || strequal(argv[1], "off")) {
503 value = -1;
505 else {
506 value = smb_strtoul(argv[1],
507 NULL,
509 &err,
510 SMB_STR_FULL_STR_CONV);
512 if (err != 0) {
513 d_printf(_("Unable to set policy \"%s\"! Invalid value "
514 "\"%s\".\n"),
515 account_policy, argv[1]);
516 return -1;
520 if (field == 0) {
521 const char **names;
522 int i, count;
524 account_policy_names_list(talloc_tos(), &names, &count);
525 d_fprintf(stderr, _("No account policy \"%s\"!\n\n"), argv[0]);
526 d_fprintf(stderr, _("Valid account policies are:\n"));
528 for (i=0; i<count; i++) {
529 d_fprintf(stderr, "%s\n", names[i]);
532 TALLOC_FREE(names);
534 return -1;
537 if (!pdb_get_account_policy(field, &old_value)) {
538 d_fprintf(stderr, _("Valid account policy, but unable to fetch "
539 "value!\n"));
540 } else {
541 d_printf(_("Account policy \"%s\" value was: %d\n"),
542 account_policy, old_value);
545 if (!pdb_set_account_policy(field, value)) {
546 d_fprintf(stderr, _("Valid account policy, but unable to "
547 "set value!\n"));
548 return -1;
549 } else {
550 d_printf(_("Account policy \"%s\" value is now: %d\n"),
551 account_policy, value);
554 return 0;
557 static int net_sam_policy_show(struct net_context *c, int argc, const char **argv)
559 const char *account_policy = NULL;
560 uint32_t old_value;
561 enum pdb_policy_type field;
563 if (argc != 1 || c->display_usage) {
564 d_fprintf(stderr, "%s\n%s",
565 _("Usage:"),
566 _("net sam policy show \"<account policy>\"\n"));
567 return -1;
570 account_policy = argv[0];
571 field = account_policy_name_to_typenum(account_policy);
573 if (field == 0) {
574 const char **names;
575 int count;
576 int i;
577 account_policy_names_list(talloc_tos(), &names, &count);
578 d_fprintf(stderr, _("No account policy by that name!\n"));
579 if (count != 0) {
580 d_fprintf(stderr, _("Valid account policies "
581 "are:\n"));
582 for (i=0; i<count; i++) {
583 d_fprintf(stderr, "%s\n", names[i]);
586 TALLOC_FREE(names);
587 return -1;
590 if (!pdb_get_account_policy(field, &old_value)) {
591 fprintf(stderr, _("Valid account policy, but unable to "
592 "fetch value!\n"));
593 return -1;
596 printf(_("Account policy \"%s\" description: %s\n"),
597 account_policy, account_policy_get_desc(field));
598 printf(_("Account policy \"%s\" value is: %d\n"), account_policy,
599 old_value);
600 return 0;
603 static int net_sam_policy_list(struct net_context *c, int argc, const char **argv)
605 const char **names;
606 int count;
607 int i;
609 if (c->display_usage) {
610 d_printf( "%s\n"
611 "net sam policy list\n"
612 " %s\n",
613 _("Usage:"),
614 _("List account policies"));
615 return 0;
618 account_policy_names_list(talloc_tos(), &names, &count);
619 if (count != 0) {
620 d_fprintf(stderr, _("Valid account policies "
621 "are:\n"));
622 for (i = 0; i < count ; i++) {
623 d_fprintf(stderr, "%s\n", names[i]);
626 TALLOC_FREE(names);
627 return -1;
630 static int net_sam_policy(struct net_context *c, int argc, const char **argv)
632 struct functable func[] = {
634 "list",
635 net_sam_policy_list,
636 NET_TRANSPORT_LOCAL,
637 N_("List account policies"),
638 N_("net sam policy list\n"
639 " List account policies")
642 "show",
643 net_sam_policy_show,
644 NET_TRANSPORT_LOCAL,
645 N_("Show account policies"),
646 N_("net sam policy show\n"
647 " Show account policies")
650 "set",
651 net_sam_policy_set,
652 NET_TRANSPORT_LOCAL,
653 N_("Change account policies"),
654 N_("net sam policy set\n"
655 " Change account policies")
657 {NULL, NULL, 0, NULL, NULL}
660 return net_run_function(c, argc, argv, "net sam policy", func);
663 static int net_sam_rights_list(struct net_context *c, int argc,
664 const char **argv)
666 enum sec_privilege privilege;
668 if (argc > 1 || c->display_usage) {
669 d_fprintf(stderr, "%s\n%s",
670 _("Usage:"),
671 _("net sam rights list [privilege name]\n"));
672 return -1;
675 if (argc == 0) {
676 int i;
677 int num = num_privileges_in_short_list();
679 for (i=0; i<num; i++) {
680 d_printf("%s\n", sec_privilege_name_from_index(i));
682 return 0;
685 privilege = sec_privilege_id(argv[0]);
687 if (privilege != SEC_PRIV_INVALID) {
688 struct dom_sid *sids;
689 int i, num_sids;
690 NTSTATUS status;
692 status = privilege_enum_sids(privilege, talloc_tos(),
693 &sids, &num_sids);
694 if (!NT_STATUS_IS_OK(status)) {
695 d_fprintf(stderr, _("Could not list rights: %s\n"),
696 nt_errstr(status));
697 return -1;
700 for (i=0; i<num_sids; i++) {
701 const char *dom, *name;
702 enum lsa_SidType type;
703 struct dom_sid_buf buf;
705 if (lookup_sid(talloc_tos(), &sids[i], &dom, &name,
706 &type)) {
707 d_printf("%s\\%s\n", dom, name);
709 else {
710 d_printf("%s\n",
711 dom_sid_str_buf(&sids[i], &buf));
714 return 0;
717 return -1;
720 static int net_sam_rights_grant(struct net_context *c, int argc,
721 const char **argv)
723 struct dom_sid sid;
724 enum lsa_SidType type;
725 const char *dom, *name;
726 int i;
728 if (argc < 2 || c->display_usage) {
729 d_fprintf(stderr, "%s\n%s",
730 _("Usage:"),
731 _("net sam rights grant <name> <rights> ...\n"));
732 return -1;
735 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
736 &dom, &name, &sid, &type)) {
737 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
738 return -1;
741 for (i=1; i < argc; i++) {
742 enum sec_privilege privilege = sec_privilege_id(argv[i]);
743 if (privilege == SEC_PRIV_INVALID) {
744 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
745 return -1;
748 if (!grant_privilege_by_name(&sid, argv[i])) {
749 d_fprintf(stderr, _("Could not grant privilege\n"));
750 return -1;
753 d_printf(_("Granted %s to %s\\%s\n"), argv[i], dom, name);
756 return 0;
759 static int net_sam_rights_revoke(struct net_context *c, int argc,
760 const char **argv)
762 struct dom_sid sid;
763 enum lsa_SidType type;
764 const char *dom, *name;
765 int i;
767 if (argc < 2 || c->display_usage) {
768 d_fprintf(stderr, "%s\n%s",
769 _("Usage:"),
770 _("net sam rights revoke <name> <rights>\n"));
771 return -1;
774 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
775 &dom, &name, &sid, &type)) {
776 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
777 return -1;
780 for (i=1; i < argc; i++) {
781 enum sec_privilege privilege = sec_privilege_id(argv[i]);
782 if (privilege == SEC_PRIV_INVALID) {
783 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
784 return -1;
787 if (!revoke_privilege_by_name(&sid, argv[i])) {
788 d_fprintf(stderr, _("Could not revoke privilege\n"));
789 return -1;
792 d_printf(_("Revoked %s from %s\\%s\n"), argv[i], dom, name);
795 return 0;
798 static int net_sam_rights(struct net_context *c, int argc, const char **argv)
800 struct functable func[] = {
802 "list",
803 net_sam_rights_list,
804 NET_TRANSPORT_LOCAL,
805 N_("List possible user rights"),
806 N_("net sam rights list\n"
807 " List possible user rights")
810 "grant",
811 net_sam_rights_grant,
812 NET_TRANSPORT_LOCAL,
813 N_("Grant right(s)"),
814 N_("net sam rights grant\n"
815 " Grant right(s)")
818 "revoke",
819 net_sam_rights_revoke,
820 NET_TRANSPORT_LOCAL,
821 N_("Revoke right(s)"),
822 N_("net sam rights revoke\n"
823 " Revoke right(s)")
825 {NULL, NULL, 0, NULL, NULL}
827 return net_run_function(c, argc, argv, "net sam rights", func);
831 * Map a unix group to a domain group
834 static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *map)
836 const char *dom, *name;
837 uint32_t rid;
839 if (pdb_getgrgid(map, grp->gr_gid)) {
840 return NT_STATUS_GROUP_EXISTS;
843 map->gid = grp->gr_gid;
845 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
846 &dom, &name, NULL, NULL)) {
848 map->nt_name = talloc_asprintf(map, "Unix Group %s",
849 grp->gr_name);
851 DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
852 grp->gr_name, dom, name, map->nt_name));
855 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
856 NULL, NULL, NULL, NULL)) {
857 DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
858 return NT_STATUS_GROUP_EXISTS;
861 if (pdb_capabilities() & PDB_CAP_STORE_RIDS) {
862 if (!pdb_new_rid(&rid)) {
863 DEBUG(3, ("Could not get a new RID for %s\n",
864 grp->gr_name));
865 return NT_STATUS_ACCESS_DENIED;
867 } else {
868 rid = algorithmic_pdb_gid_to_group_rid( grp->gr_gid );
871 sid_compose(&map->sid, get_global_sam_sid(), rid);
872 map->sid_name_use = SID_NAME_DOM_GRP;
873 map->comment = talloc_asprintf(map, "Unix Group %s", grp->gr_name);
875 return pdb_add_group_mapping_entry(map);
878 static int net_sam_mapunixgroup(struct net_context *c, int argc, const char **argv)
880 NTSTATUS status;
881 GROUP_MAP *map;
882 struct group *grp;
883 struct dom_sid_buf buf;
885 if (argc != 1 || c->display_usage) {
886 d_fprintf(stderr, "%s\n%s",
887 _("Usage:"),
888 _("net sam mapunixgroup <name>\n"));
889 return -1;
892 grp = getgrnam(argv[0]);
893 if (grp == NULL) {
894 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
895 return -1;
898 map = talloc_zero(talloc_tos(), GROUP_MAP);
899 if (!map) {
900 d_fprintf(stderr, _("Out of memory!\n"));
901 return -1;
904 status = map_unix_group(grp, map);
906 if (!NT_STATUS_IS_OK(status)) {
907 d_fprintf(stderr, _("Mapping group %s failed with %s\n"),
908 argv[0], nt_errstr(status));
909 return -1;
912 d_printf(_("Mapped unix group %s to SID %s\n"), argv[0],
913 dom_sid_str_buf(&map->sid, &buf));
915 TALLOC_FREE(map);
916 return 0;
920 * Remove a group mapping
923 static NTSTATUS unmap_unix_group(const struct group *grp)
925 struct dom_sid dom_sid;
926 struct unixid id;
928 if (!lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
929 NULL, NULL, NULL, NULL)) {
930 DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
931 return NT_STATUS_NO_SUCH_GROUP;
934 id.id = grp->gr_gid;
935 id.type = ID_TYPE_GID;
936 if (!pdb_id_to_sid(&id, &dom_sid)) {
937 return NT_STATUS_UNSUCCESSFUL;
940 return pdb_delete_group_mapping_entry(dom_sid);
943 static int net_sam_unmapunixgroup(struct net_context *c, int argc, const char **argv)
945 NTSTATUS status;
946 struct group *grp;
948 if (argc != 1 || c->display_usage) {
949 d_fprintf(stderr, "%s\n%s",
950 _("Usage:"),
951 _("net sam unmapunixgroup <name>\n"));
952 return -1;
955 grp = getgrnam(argv[0]);
956 if (grp == NULL) {
957 d_fprintf(stderr, _("Could not find mapping for group %s.\n"),
958 argv[0]);
959 return -1;
962 status = unmap_unix_group(grp);
964 if (!NT_STATUS_IS_OK(status)) {
965 d_fprintf(stderr, _("Unmapping group %s failed with %s.\n"),
966 argv[0], nt_errstr(status));
967 return -1;
970 d_printf(_("Unmapped unix group %s.\n"), argv[0]);
972 return 0;
976 * Create a domain group
979 static int net_sam_createdomaingroup(struct net_context *c, int argc,
980 const char **argv)
982 NTSTATUS status;
983 uint32_t rid;
985 if (argc != 1 || c->display_usage) {
986 d_fprintf(stderr, "%s\n%s",
987 _("Usage:"),
988 _("net sam createdomaingroup <name>\n"));
989 return -1;
992 status = pdb_create_dom_group(talloc_tos(), argv[0], &rid);
994 if (!NT_STATUS_IS_OK(status)) {
995 d_fprintf(stderr, _("Creating %s failed with %s\n"),
996 argv[0], nt_errstr(status));
997 return -1;
1000 d_printf(_("Created domain group %s with RID %d\n"), argv[0], rid);
1002 return 0;
1006 * Delete a domain group
1009 static int net_sam_deletedomaingroup(struct net_context *c, int argc,
1010 const char **argv)
1012 struct dom_sid sid;
1013 uint32_t rid;
1014 enum lsa_SidType type;
1015 const char *dom, *name;
1016 NTSTATUS status;
1018 if (argc != 1 || c->display_usage) {
1019 d_fprintf(stderr, "%s\n%s",
1020 _("Usage:"),
1021 _("net sam deletelocalgroup <name>\n"));
1022 return -1;
1025 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1026 &dom, &name, &sid, &type)) {
1027 d_fprintf(stderr, _("Could not find %s.\n"), argv[0]);
1028 return -1;
1031 if (type != SID_NAME_DOM_GRP) {
1032 d_fprintf(stderr, _("%s is a %s, not a domain group.\n"),
1033 argv[0], sid_type_lookup(type));
1034 return -1;
1037 sid_peek_rid(&sid, &rid);
1039 status = pdb_delete_dom_group(talloc_tos(), rid);
1041 if (!NT_STATUS_IS_OK(status)) {
1042 d_fprintf(stderr,_("Deleting domain group %s failed with %s\n"),
1043 argv[0], nt_errstr(status));
1044 return -1;
1047 d_printf(_("Deleted domain group %s.\n"), argv[0]);
1049 return 0;
1053 * Create a local group
1056 static int net_sam_createlocalgroup(struct net_context *c, int argc, const char **argv)
1058 NTSTATUS status;
1059 uint32_t rid;
1061 if (argc != 1 || c->display_usage) {
1062 d_fprintf(stderr, "%s\n%s",
1063 _("Usage:"),
1064 _("net sam createlocalgroup <name>\n"));
1065 return -1;
1068 if (!winbind_ping()) {
1069 d_fprintf(stderr, _("winbind seems not to run. "
1070 "createlocalgroup only works when winbind runs.\n"));
1071 return -1;
1074 status = pdb_create_alias(argv[0], &rid);
1076 if (!NT_STATUS_IS_OK(status)) {
1077 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1078 argv[0], nt_errstr(status));
1079 return -1;
1082 d_printf(_("Created local group %s with RID %d\n"), argv[0], rid);
1084 return 0;
1088 * Delete a local group
1091 static int net_sam_deletelocalgroup(struct net_context *c, int argc, const char **argv)
1093 struct dom_sid sid;
1094 enum lsa_SidType type;
1095 const char *dom, *name;
1096 NTSTATUS status;
1098 if (argc != 1 || c->display_usage) {
1099 d_fprintf(stderr, "%s\n%s",
1100 _("Usage:"),
1101 _("net sam deletelocalgroup <name>\n"));
1102 return -1;
1105 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1106 &dom, &name, &sid, &type)) {
1107 d_fprintf(stderr,_("Could not find %s.\n"), argv[0]);
1108 return -1;
1111 if (type != SID_NAME_ALIAS) {
1112 d_fprintf(stderr, _("%s is a %s, not a local group.\n"),argv[0],
1113 sid_type_lookup(type));
1114 return -1;
1117 status = pdb_delete_alias(&sid);
1119 if (!NT_STATUS_IS_OK(status)) {
1120 d_fprintf(stderr, _("Deleting local group %s failed with %s\n"),
1121 argv[0], nt_errstr(status));
1122 return -1;
1125 d_printf(_("Deleted local group %s.\n"), argv[0]);
1127 return 0;
1131 * Create a builtin group
1134 static int net_sam_createbuiltingroup(struct net_context *c, int argc, const char **argv)
1136 NTSTATUS status;
1137 uint32_t rid;
1138 enum lsa_SidType type;
1139 fstring groupname;
1140 struct dom_sid sid;
1142 if (argc != 1 || c->display_usage) {
1143 d_fprintf(stderr, "%s\n%s",
1144 _("Usage:"),
1145 _("net sam createbuiltingroup <name>\n"));
1146 return -1;
1149 if (!winbind_ping()) {
1150 d_fprintf(stderr, _("winbind seems not to run. "
1151 "createbuiltingroup only works when winbind "
1152 "runs.\n"));
1153 return -1;
1156 /* validate the name and get the group */
1158 fstrcpy( groupname, "BUILTIN\\" );
1159 fstrcat( groupname, argv[0] );
1161 if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
1162 NULL, &sid, &type)) {
1163 d_fprintf(stderr, _("%s is not a BUILTIN group\n"), argv[0]);
1164 return -1;
1167 if ( !sid_peek_rid( &sid, &rid ) ) {
1168 d_fprintf(stderr, _("Failed to get RID for %s\n"), argv[0]);
1169 return -1;
1172 status = pdb_create_builtin(rid);
1174 if (!NT_STATUS_IS_OK(status)) {
1175 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1176 argv[0], nt_errstr(status));
1177 return -1;
1180 d_printf(_("Created BUILTIN group %s with RID %d\n"), argv[0], rid);
1182 return 0;
1186 * Add a group member
1189 static int net_sam_addmem(struct net_context *c, int argc, const char **argv)
1191 const char *groupdomain, *groupname, *memberdomain, *membername;
1192 struct dom_sid group, member;
1193 enum lsa_SidType grouptype, membertype;
1194 NTSTATUS status;
1196 if (argc != 2 || c->display_usage) {
1197 d_fprintf(stderr, "%s\n%s",
1198 _("Usage:"),
1199 _("net sam addmem <group> <member>\n"));
1200 return -1;
1203 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1204 &groupdomain, &groupname, &group, &grouptype)) {
1205 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1206 return -1;
1209 /* check to see if the member to be added is a name or a SID */
1211 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1212 &memberdomain, &membername, &member, &membertype))
1214 /* try it as a SID */
1216 if ( !string_to_sid( &member, argv[1] ) ) {
1217 d_fprintf(stderr, _("Could not find member %s\n"),
1218 argv[1]);
1219 return -1;
1222 if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
1223 &membername, &membertype) )
1225 d_fprintf(stderr, _("Could not resolve SID %s\n"),
1226 argv[1]);
1227 return -1;
1231 if ((grouptype == SID_NAME_ALIAS) || (grouptype == SID_NAME_WKN_GRP)) {
1232 if ((membertype != SID_NAME_USER) &&
1233 (membertype != SID_NAME_ALIAS) &&
1234 (membertype != SID_NAME_DOM_GRP)) {
1235 d_fprintf(stderr, _("Can't add %s: only users, domain "
1236 "groups and domain local groups "
1237 "can be added. %s is a %s\n"),
1238 argv[0], argv[1],
1239 sid_type_lookup(membertype));
1240 return -1;
1242 status = pdb_add_aliasmem(&group, &member);
1244 if (!NT_STATUS_IS_OK(status)) {
1245 d_fprintf(stderr, _("Adding local group member failed "
1246 "with %s\n"), nt_errstr(status));
1247 return -1;
1249 } else if (grouptype == SID_NAME_DOM_GRP) {
1250 uint32_t grouprid, memberrid;
1252 sid_peek_rid(&group, &grouprid);
1253 sid_peek_rid(&member, &memberrid);
1255 status = pdb_add_groupmem(talloc_tos(), grouprid, memberrid);
1256 if (!NT_STATUS_IS_OK(status)) {
1257 d_fprintf(stderr, _("Adding domain group member failed "
1258 "with %s\n"), nt_errstr(status));
1259 return -1;
1261 } else {
1262 d_fprintf(stderr, _("Can only add members to local groups so "
1263 "far, %s is a %s\n"), argv[0],
1264 sid_type_lookup(grouptype));
1265 return -1;
1268 d_printf(_("Added %s\\%s to %s\\%s\n"), memberdomain, membername,
1269 groupdomain, groupname);
1271 return 0;
1275 * Delete a group member
1278 static int net_sam_delmem(struct net_context *c, int argc, const char **argv)
1280 const char *groupdomain, *groupname;
1281 const char *memberdomain = NULL;
1282 const char *membername = NULL;
1283 struct dom_sid group, member;
1284 enum lsa_SidType grouptype;
1285 NTSTATUS status;
1287 if (argc != 2 || c->display_usage) {
1288 d_fprintf(stderr,"%s\n%s",
1289 _("Usage:"),
1290 _("net sam delmem <group> <member>\n"));
1291 return -1;
1294 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1295 &groupdomain, &groupname, &group, &grouptype)) {
1296 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1297 return -1;
1300 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1301 &memberdomain, &membername, &member, NULL)) {
1302 if (!string_to_sid(&member, argv[1])) {
1303 d_fprintf(stderr, _("Could not find member %s\n"),
1304 argv[1]);
1305 return -1;
1309 if ((grouptype == SID_NAME_ALIAS) ||
1310 (grouptype == SID_NAME_WKN_GRP)) {
1311 status = pdb_del_aliasmem(&group, &member);
1313 if (!NT_STATUS_IS_OK(status)) {
1314 d_fprintf(stderr,_("Deleting local group member failed "
1315 "with %s\n"), nt_errstr(status));
1316 return -1;
1318 } else if (grouptype == SID_NAME_DOM_GRP) {
1319 uint32_t grouprid, memberrid;
1321 sid_peek_rid(&group, &grouprid);
1322 sid_peek_rid(&member, &memberrid);
1324 status = pdb_del_groupmem(talloc_tos(), grouprid, memberrid);
1325 if (!NT_STATUS_IS_OK(status)) {
1326 d_fprintf(stderr, _("Deleting domain group member "
1327 "failed with %s\n"), nt_errstr(status));
1328 return -1;
1330 } else {
1331 d_fprintf(stderr, _("Can only delete members from local groups "
1332 "so far, %s is a %s\n"), argv[0],
1333 sid_type_lookup(grouptype));
1334 return -1;
1337 if (membername != NULL) {
1338 d_printf(_("Deleted %s\\%s from %s\\%s\n"),
1339 memberdomain, membername, groupdomain, groupname);
1340 } else {
1341 struct dom_sid_buf buf;
1342 d_printf(_("Deleted %s from %s\\%s\n"),
1343 dom_sid_str_buf(&member, &buf),
1344 groupdomain,
1345 groupname);
1348 return 0;
1352 * List group members
1355 static int net_sam_listmem(struct net_context *c, int argc, const char **argv)
1357 const char *groupdomain, *groupname;
1358 struct dom_sid group;
1359 struct dom_sid *members = NULL;
1360 size_t i, num_members = 0;
1361 enum lsa_SidType grouptype;
1362 NTSTATUS status;
1364 if (argc != 1 || c->display_usage) {
1365 d_fprintf(stderr, "%s\n%s",
1366 _("Usage:"),
1367 _("net sam listmem <group>\n"));
1368 return -1;
1371 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1372 &groupdomain, &groupname, &group, &grouptype)) {
1373 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1374 return -1;
1377 if ((grouptype == SID_NAME_ALIAS) ||
1378 (grouptype == SID_NAME_WKN_GRP)) {
1379 status = pdb_enum_aliasmem(&group, talloc_tos(), &members,
1380 &num_members);
1381 if (!NT_STATUS_IS_OK(status)) {
1382 d_fprintf(stderr, _("Listing group members failed with "
1383 "%s\n"), nt_errstr(status));
1384 return -1;
1386 } else if (grouptype == SID_NAME_DOM_GRP) {
1387 uint32_t *rids;
1389 status = pdb_enum_group_members(talloc_tos(), &group,
1390 &rids, &num_members);
1391 if (!NT_STATUS_IS_OK(status)) {
1392 d_fprintf(stderr, _("Listing group members failed with "
1393 "%s\n"), nt_errstr(status));
1394 return -1;
1397 members = talloc_array(talloc_tos(), struct dom_sid,
1398 num_members);
1399 if (members == NULL) {
1400 TALLOC_FREE(rids);
1401 return -1;
1404 for (i=0; i<num_members; i++) {
1405 sid_compose(&members[i], get_global_sam_sid(),
1406 rids[i]);
1408 TALLOC_FREE(rids);
1409 } else {
1410 d_fprintf(stderr,_("Can only list local group members so far.\n"
1411 "%s is a %s\n"), argv[0], sid_type_lookup(grouptype));
1412 return -1;
1415 d_printf(_("%s\\%s has %u members\n"), groupdomain, groupname,
1416 (unsigned int)num_members);
1417 for (i=0; i<num_members; i++) {
1418 const char *dom, *name;
1419 if (lookup_sid(talloc_tos(), &members[i], &dom, &name, NULL)) {
1420 d_printf(" %s\\%s\n", dom, name);
1421 } else {
1422 struct dom_sid_buf buf;
1423 d_printf(" %s\n",
1424 dom_sid_str_buf(&members[i], &buf));
1428 TALLOC_FREE(members);
1430 return 0;
1434 * Do the listing
1436 static int net_sam_do_list(struct net_context *c, int argc, const char **argv,
1437 struct pdb_search *search, const char *what)
1439 bool verbose = (argc == 1);
1441 if ((argc > 1) || c->display_usage ||
1442 ((argc == 1) && !strequal(argv[0], "verbose"))) {
1443 d_fprintf(stderr, "%s\n", _("Usage:"));
1444 d_fprintf(stderr, _("net sam list %s [verbose]\n"), what);
1445 return -1;
1448 if (search == NULL) {
1449 d_fprintf(stderr, _("Could not start search\n"));
1450 return -1;
1453 while (true) {
1454 struct samr_displayentry entry;
1455 if (!search->next_entry(search, &entry)) {
1456 break;
1458 if (verbose) {
1459 d_printf("%s:%d:%s\n",
1460 entry.account_name,
1461 entry.rid,
1462 entry.description);
1463 } else {
1464 d_printf("%s\n", entry.account_name);
1468 TALLOC_FREE(search);
1469 return 0;
1472 static int net_sam_list_users(struct net_context *c, int argc,
1473 const char **argv)
1475 return net_sam_do_list(c, argc, argv,
1476 pdb_search_users(talloc_tos(), ACB_NORMAL),
1477 "users");
1480 static int net_sam_list_groups(struct net_context *c, int argc,
1481 const char **argv)
1483 return net_sam_do_list(c, argc, argv, pdb_search_groups(talloc_tos()),
1484 "groups");
1487 static int net_sam_list_localgroups(struct net_context *c, int argc,
1488 const char **argv)
1490 return net_sam_do_list(c, argc, argv,
1491 pdb_search_aliases(talloc_tos(),
1492 get_global_sam_sid()),
1493 "localgroups");
1496 static int net_sam_list_builtin(struct net_context *c, int argc,
1497 const char **argv)
1499 return net_sam_do_list(c, argc, argv,
1500 pdb_search_aliases(talloc_tos(),
1501 &global_sid_Builtin),
1502 "builtin");
1505 static int net_sam_list_workstations(struct net_context *c, int argc,
1506 const char **argv)
1508 return net_sam_do_list(c, argc, argv,
1509 pdb_search_users(talloc_tos(), ACB_WSTRUST),
1510 "workstations");
1514 * List stuff
1517 static int net_sam_list(struct net_context *c, int argc, const char **argv)
1519 struct functable func[] = {
1521 "users",
1522 net_sam_list_users,
1523 NET_TRANSPORT_LOCAL,
1524 N_("List SAM users"),
1525 N_("net sam list users\n"
1526 " List SAM users")
1529 "groups",
1530 net_sam_list_groups,
1531 NET_TRANSPORT_LOCAL,
1532 N_("List SAM groups"),
1533 N_("net sam list groups\n"
1534 " List SAM groups")
1537 "localgroups",
1538 net_sam_list_localgroups,
1539 NET_TRANSPORT_LOCAL,
1540 N_("List SAM local groups"),
1541 N_("net sam list localgroups\n"
1542 " List SAM local groups")
1545 "builtin",
1546 net_sam_list_builtin,
1547 NET_TRANSPORT_LOCAL,
1548 N_("List builtin groups"),
1549 N_("net sam list builtin\n"
1550 " List builtin groups")
1553 "workstations",
1554 net_sam_list_workstations,
1555 NET_TRANSPORT_LOCAL,
1556 N_("List domain member workstations"),
1557 N_("net sam list workstations\n"
1558 " List domain member workstations")
1560 {NULL, NULL, 0, NULL, NULL}
1563 return net_run_function(c, argc, argv, "net sam list", func);
1567 * Show details of SAM entries
1570 static int net_sam_show(struct net_context *c, int argc, const char **argv)
1572 struct dom_sid sid;
1573 struct dom_sid_buf buf;
1574 enum lsa_SidType type;
1575 const char *dom, *name;
1577 if (argc != 1 || c->display_usage) {
1578 d_fprintf(stderr, "%s\n%s",
1579 _("Usage:"),
1580 _("net sam show <name>\n"));
1581 return -1;
1584 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1585 &dom, &name, &sid, &type)) {
1586 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
1587 return -1;
1590 d_printf(_("%s\\%s is a %s with SID %s\n"), dom, name,
1591 sid_type_lookup(type), dom_sid_str_buf(&sid, &buf));
1593 return 0;
1596 #ifdef HAVE_LDAP
1599 * Init an LDAP tree with default users and Groups
1600 * if ldapsam:editposix is enabled
1603 static int net_sam_provision(struct net_context *c, int argc, const char **argv)
1605 TALLOC_CTX *tc;
1606 char *ldap_bk;
1607 char *ldap_uri = NULL;
1608 char *p;
1609 struct smbldap_state *state = NULL;
1610 GROUP_MAP *gmap = NULL;
1611 struct dom_sid gsid;
1612 gid_t domusers_gid = -1;
1613 gid_t domadmins_gid = -1;
1614 struct samu *samuser;
1615 struct passwd *pwd;
1616 bool is_ipa = false;
1617 char *bind_dn = NULL;
1618 char *bind_secret = NULL;
1619 NTSTATUS status;
1621 if (c->display_usage) {
1622 d_printf( "%s\n"
1623 "net sam provision\n"
1624 " %s\n",
1625 _("Usage:"),
1626 _("Init an LDAP tree with default users/groups"));
1627 return 0;
1630 tc = talloc_new(NULL);
1631 if (!tc) {
1632 d_fprintf(stderr, _("Out of Memory!\n"));
1633 return -1;
1636 if ((ldap_bk = talloc_strdup(tc, lp_passdb_backend())) == NULL) {
1637 d_fprintf(stderr, _("talloc failed\n"));
1638 talloc_free(tc);
1639 return -1;
1641 p = strchr(ldap_bk, ':');
1642 if (p) {
1643 *p = 0;
1644 ldap_uri = talloc_strdup(tc, p+1);
1645 trim_char(ldap_uri, ' ', ' ');
1648 trim_char(ldap_bk, ' ', ' ');
1650 if (strcmp(ldap_bk, "IPA_ldapsam") == 0 ) {
1651 is_ipa = true;
1654 if (strcmp(ldap_bk, "ldapsam") != 0 && !is_ipa ) {
1655 d_fprintf(stderr,
1656 _("Provisioning works only with ldapsam backend\n"));
1657 goto failed;
1660 if (!lp_parm_bool(-1, "ldapsam", "trusted", false) ||
1661 !lp_parm_bool(-1, "ldapsam", "editposix", false)) {
1663 d_fprintf(stderr, _("Provisioning works only if ldapsam:trusted"
1664 " and ldapsam:editposix are enabled.\n"));
1665 goto failed;
1668 if (!is_ipa && !winbind_ping()) {
1669 d_fprintf(stderr, _("winbind seems not to run. Provisioning "
1670 "LDAP only works when winbind runs.\n"));
1671 goto failed;
1674 if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
1675 d_fprintf(stderr, _("Failed to retrieve LDAP password from secrets.tdb\n"));
1676 goto failed;
1679 status = smbldap_init(tc, NULL, ldap_uri, false, bind_dn, bind_secret, &state);
1681 BURN_FREE_STR(bind_secret);
1682 SAFE_FREE(bind_dn);
1684 if (!NT_STATUS_IS_OK(status)) {
1685 d_fprintf(stderr, _("Unable to connect to the LDAP server.\n"));
1686 goto failed;
1689 d_printf(_("Checking for Domain Users group.\n"));
1691 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS);
1693 gmap = talloc_zero(tc, GROUP_MAP);
1694 if (!gmap) {
1695 d_printf(_("Out of memory!\n"));
1696 goto failed;
1699 if (!pdb_getgrsid(gmap, gsid)) {
1700 struct dom_sid_buf gsid_str;
1701 LDAPMod **mods = NULL;
1702 char *dn;
1703 char *uname;
1704 char *wname;
1705 char *gidstr;
1706 char *gtype;
1707 int rc;
1709 d_printf(_("Adding the Domain Users group.\n"));
1711 /* lets allocate a new groupid for this group */
1712 if (is_ipa) {
1713 domusers_gid = 999;
1714 } else {
1715 if (!winbind_allocate_gid(&domusers_gid)) {
1716 d_fprintf(stderr, _("Unable to allocate a new gid to "
1717 "create Domain Users group!\n"));
1718 goto domu_done;
1722 uname = talloc_strdup(tc, "domusers");
1723 wname = talloc_strdup(tc, "Domain Users");
1724 dn = talloc_asprintf(tc, "cn=%s,%s", "domusers",
1725 lp_ldap_group_suffix(talloc_tos()));
1726 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domusers_gid);
1727 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1729 if (!uname || !wname || !dn || !gidstr || !gtype) {
1730 d_fprintf(stderr, "Out of Memory!\n");
1731 goto failed;
1734 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1735 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1736 if (is_ipa) {
1737 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1738 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1739 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1741 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1742 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1743 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1744 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1745 dom_sid_str_buf(&gsid, &gsid_str));
1746 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1748 smbldap_talloc_autofree_ldapmod(tc, mods);
1750 rc = smbldap_add(state, dn, mods);
1752 if (rc != LDAP_SUCCESS) {
1753 d_fprintf(stderr, _("Failed to add Domain Users group "
1754 "to ldap directory\n"));
1757 if (is_ipa) {
1758 if (!pdb_getgrsid(gmap, gsid)) {
1759 d_fprintf(stderr, _("Failed to read just "
1760 "created domain group.\n"));
1761 goto failed;
1762 } else {
1763 domusers_gid = gmap->gid;
1766 } else {
1767 domusers_gid = gmap->gid;
1768 d_printf(_("found!\n"));
1771 domu_done:
1773 d_printf(_("Checking for Domain Admins group.\n"));
1775 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
1777 if (!pdb_getgrsid(gmap, gsid)) {
1778 struct dom_sid_buf gsid_str;
1779 LDAPMod **mods = NULL;
1780 char *dn;
1781 char *uname;
1782 char *wname;
1783 char *gidstr;
1784 char *gtype;
1785 int rc;
1787 d_printf(_("Adding the Domain Admins group.\n"));
1789 /* lets allocate a new groupid for this group */
1790 if (is_ipa) {
1791 domadmins_gid = 999;
1792 } else {
1793 if (!winbind_allocate_gid(&domadmins_gid)) {
1794 d_fprintf(stderr, _("Unable to allocate a new gid to "
1795 "create Domain Admins group!\n"));
1796 goto doma_done;
1800 uname = talloc_strdup(tc, "domadmins");
1801 wname = talloc_strdup(tc, "Domain Admins");
1802 dn = talloc_asprintf(tc, "cn=%s,%s", "domadmins",
1803 lp_ldap_group_suffix(talloc_tos()));
1804 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1805 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1807 if (!uname || !wname || !dn || !gidstr || !gtype) {
1808 d_fprintf(stderr, _("Out of Memory!\n"));
1809 goto failed;
1812 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1813 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1814 if (is_ipa) {
1815 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1816 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1817 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1819 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1820 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1821 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1822 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1823 dom_sid_str_buf(&gsid, &gsid_str));
1824 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1826 smbldap_talloc_autofree_ldapmod(tc, mods);
1828 rc = smbldap_add(state, dn, mods);
1830 if (rc != LDAP_SUCCESS) {
1831 d_fprintf(stderr, _("Failed to add Domain Admins group "
1832 "to ldap directory\n"));
1835 if (is_ipa) {
1836 if (!pdb_getgrsid(gmap, gsid)) {
1837 d_fprintf(stderr, _("Failed to read just "
1838 "created domain group.\n"));
1839 goto failed;
1840 } else {
1841 domadmins_gid = gmap->gid;
1844 } else {
1845 domadmins_gid = gmap->gid;
1846 d_printf(_("found!\n"));
1849 doma_done:
1851 d_printf(_("Check for Administrator account.\n"));
1853 samuser = samu_new(tc);
1854 if (!samuser) {
1855 d_fprintf(stderr, _("Out of Memory!\n"));
1856 goto failed;
1859 if (!pdb_getsampwnam(samuser, "Administrator")) {
1860 LDAPMod **mods = NULL;
1861 struct dom_sid sid;
1862 struct dom_sid_buf sid_str;
1863 char *dn;
1864 char *name;
1865 char *uidstr;
1866 char *gidstr;
1867 char *shell;
1868 char *dir;
1869 char *princ;
1870 uid_t uid;
1871 int rc;
1873 d_printf(_("Adding the Administrator user.\n"));
1875 if (domadmins_gid == -1) {
1876 d_fprintf(stderr,
1877 _("Can't create Administrator user, Domain "
1878 "Admins group not available!\n"));
1879 goto done;
1882 if (is_ipa) {
1883 uid = 999;
1884 } else {
1885 if (!winbind_allocate_uid(&uid)) {
1886 d_fprintf(stderr,
1887 _("Unable to allocate a new uid to create "
1888 "the Administrator user!\n"));
1889 goto done;
1893 name = talloc_strdup(tc, "Administrator");
1894 dn = talloc_asprintf(tc, "uid=Administrator,%s",
1895 lp_ldap_user_suffix(talloc_tos()));
1896 uidstr = talloc_asprintf(tc, "%u", (unsigned int)uid);
1897 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1898 dir = talloc_sub_specified(tc, lp_template_homedir(),
1899 "Administrator",
1900 NULL,
1901 get_global_sam_name(),
1902 uid, domadmins_gid);
1903 shell = talloc_sub_specified(tc, lp_template_shell(),
1904 "Administrator",
1905 NULL,
1906 get_global_sam_name(),
1907 uid, domadmins_gid);
1909 if (!name || !dn || !uidstr || !gidstr || !dir || !shell) {
1910 d_fprintf(stderr, _("Out of Memory!\n"));
1911 goto failed;
1914 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
1916 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
1917 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
1918 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
1919 if (is_ipa) {
1920 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
1921 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
1922 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
1923 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
1924 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
1925 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
1926 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
1927 princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
1928 if (!princ) {
1929 d_fprintf(stderr, _("Out of Memory!\n"));
1930 goto failed;
1932 smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
1934 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
1935 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
1936 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
1937 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
1938 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1939 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", dir);
1940 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", shell);
1941 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
1942 dom_sid_str_buf(&sid, &sid_str));
1943 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
1944 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
1945 NEW_PW_FORMAT_SPACE_PADDED_LEN));
1947 smbldap_talloc_autofree_ldapmod(tc, mods);
1949 rc = smbldap_add(state, dn, mods);
1951 if (rc != LDAP_SUCCESS) {
1952 d_fprintf(stderr, _("Failed to add Administrator user "
1953 "to ldap directory\n"));
1956 if (is_ipa) {
1957 if (!pdb_getsampwnam(samuser, "Administrator")) {
1958 d_fprintf(stderr, _("Failed to read just "
1959 "created user.\n"));
1960 goto failed;
1963 } else {
1964 d_printf(_("found!\n"));
1967 d_printf(_("Checking for Guest user.\n"));
1969 samuser = samu_new(tc);
1970 if (!samuser) {
1971 d_fprintf(stderr, _("Out of Memory!\n"));
1972 goto failed;
1975 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
1976 LDAPMod **mods = NULL;
1977 struct dom_sid sid;
1978 struct dom_sid_buf sid_str;
1979 char *dn;
1980 char *uidstr;
1981 char *gidstr;
1982 int rc;
1984 d_printf(_("Adding the Guest user.\n"));
1986 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
1988 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
1990 if (!pwd) {
1991 if (domusers_gid == -1) {
1992 d_fprintf(stderr,
1993 _("Can't create Guest user, Domain "
1994 "Users group not available!\n"));
1995 goto done;
1997 if ((pwd = talloc(tc, struct passwd)) == NULL) {
1998 d_fprintf(stderr, _("talloc failed\n"));
1999 goto done;
2001 pwd->pw_name = talloc_strdup(pwd, lp_guest_account());
2003 if (is_ipa) {
2004 pwd->pw_uid = 999;
2005 } else {
2006 if (!winbind_allocate_uid(&(pwd->pw_uid))) {
2007 d_fprintf(stderr,
2008 _("Unable to allocate a new uid to "
2009 "create the Guest user!\n"));
2010 goto done;
2013 pwd->pw_gid = domusers_gid;
2014 pwd->pw_dir = talloc_strdup(tc, "/");
2015 pwd->pw_shell = talloc_strdup(tc, "/bin/false");
2016 if (!pwd->pw_dir || !pwd->pw_shell) {
2017 d_fprintf(stderr, _("Out of Memory!\n"));
2018 goto failed;
2022 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name,
2023 lp_ldap_user_suffix (talloc_tos()));
2024 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
2025 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2026 if (!dn || !uidstr || !gidstr) {
2027 d_fprintf(stderr, _("Out of Memory!\n"));
2028 goto failed;
2031 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
2032 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
2033 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
2034 if (is_ipa) {
2035 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
2036 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
2037 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
2038 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
2039 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
2040 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
2041 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
2043 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
2044 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
2045 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", pwd->pw_name);
2046 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
2047 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2048 if ((pwd->pw_dir != NULL) && (pwd->pw_dir[0] != '\0')) {
2049 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", pwd->pw_dir);
2051 if ((pwd->pw_shell != NULL) && (pwd->pw_shell[0] != '\0')) {
2052 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", pwd->pw_shell);
2054 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
2055 dom_sid_str_buf(&sid, &sid_str));
2056 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
2057 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
2058 NEW_PW_FORMAT_SPACE_PADDED_LEN));
2060 smbldap_talloc_autofree_ldapmod(tc, mods);
2062 rc = smbldap_add(state, dn, mods);
2064 if (rc != LDAP_SUCCESS) {
2065 d_fprintf(stderr, _("Failed to add Guest user to "
2066 "ldap directory\n"));
2069 if (is_ipa) {
2070 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
2071 d_fprintf(stderr, _("Failed to read just "
2072 "created user.\n"));
2073 goto failed;
2076 } else {
2077 d_printf(_("found!\n"));
2080 d_printf(_("Checking Guest's group.\n"));
2082 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
2083 if (!pwd) {
2084 d_fprintf(stderr,
2085 _("Failed to find just created Guest account!\n"
2086 " Is nss properly configured?!\n"));
2087 goto failed;
2090 if (pwd->pw_gid == domusers_gid) {
2091 d_printf(_("found!\n"));
2092 goto done;
2095 if (!pdb_getgrgid(gmap, pwd->pw_gid)) {
2096 struct dom_sid_buf gsid_str;
2097 LDAPMod **mods = NULL;
2098 char *dn;
2099 char *uname;
2100 char *wname;
2101 char *gidstr;
2102 char *gtype;
2103 int rc;
2105 d_printf(_("Adding the Domain Guests group.\n"));
2107 uname = talloc_strdup(tc, "domguests");
2108 wname = talloc_strdup(tc, "Domain Guests");
2109 dn = talloc_asprintf(tc, "cn=%s,%s", "domguests",
2110 lp_ldap_group_suffix(talloc_tos()));
2111 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2112 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
2114 if (!uname || !wname || !dn || !gidstr || !gtype) {
2115 d_fprintf(stderr, _("Out of Memory!\n"));
2116 goto failed;
2119 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
2121 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
2122 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
2123 if (is_ipa) {
2124 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
2125 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
2126 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
2128 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
2129 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
2130 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2131 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
2132 dom_sid_str_buf(&gsid, &gsid_str));
2133 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
2135 smbldap_talloc_autofree_ldapmod(tc, mods);
2137 rc = smbldap_add(state, dn, mods);
2139 if (rc != LDAP_SUCCESS) {
2140 d_fprintf(stderr,
2141 _("Failed to add Domain Guests group to ldap "
2142 "directory\n"));
2144 } else {
2145 d_printf(_("found!\n"));
2149 done:
2150 talloc_free(state);
2151 return 0;
2153 failed:
2154 talloc_free(state);
2155 return -1;
2158 #endif
2160 /***********************************************************
2161 migrated functionality from smbgroupedit
2162 **********************************************************/
2163 int net_sam(struct net_context *c, int argc, const char **argv)
2165 struct functable func[] = {
2167 "createbuiltingroup",
2168 net_sam_createbuiltingroup,
2169 NET_TRANSPORT_LOCAL,
2170 N_("Create a new BUILTIN group"),
2171 N_("net sam createbuiltingroup\n"
2172 " Create a new BUILTIN group")
2175 "createlocalgroup",
2176 net_sam_createlocalgroup,
2177 NET_TRANSPORT_LOCAL,
2178 N_("Create a new local group"),
2179 N_("net sam createlocalgroup\n"
2180 " Create a new local group")
2183 "createdomaingroup",
2184 net_sam_createdomaingroup,
2185 NET_TRANSPORT_LOCAL,
2186 N_("Create a new group"),
2187 N_("net sam createdomaingroup\n"
2188 " Create a new group")
2191 "deletelocalgroup",
2192 net_sam_deletelocalgroup,
2193 NET_TRANSPORT_LOCAL,
2194 N_("Delete an existing local group"),
2195 N_("net sam deletelocalgroup\n"
2196 " Delete an existing local group")
2199 "deletedomaingroup",
2200 net_sam_deletedomaingroup,
2201 NET_TRANSPORT_LOCAL,
2202 N_("Delete a domain group"),
2203 N_("net sam deletedomaingroup\n"
2204 " Delete a group")
2207 "mapunixgroup",
2208 net_sam_mapunixgroup,
2209 NET_TRANSPORT_LOCAL,
2210 N_("Map a unix group to a domain group"),
2211 N_("net sam mapunixgroup\n"
2212 " Map a unix group to a domain group")
2215 "unmapunixgroup",
2216 net_sam_unmapunixgroup,
2217 NET_TRANSPORT_LOCAL,
2218 N_("Remove a group mapping of an unix group to a "
2219 "domain group"),
2220 N_("net sam unmapunixgroup\n"
2221 " Remove a group mapping of an unix group to a "
2222 "domain group")
2225 "addmem",
2226 net_sam_addmem,
2227 NET_TRANSPORT_LOCAL,
2228 N_("Add a member to a group"),
2229 N_("net sam addmem\n"
2230 " Add a member to a group")
2233 "delmem",
2234 net_sam_delmem,
2235 NET_TRANSPORT_LOCAL,
2236 N_("Delete a member from a group"),
2237 N_("net sam delmem\n"
2238 " Delete a member from a group")
2241 "listmem",
2242 net_sam_listmem,
2243 NET_TRANSPORT_LOCAL,
2244 N_("List group members"),
2245 N_("net sam listmem\n"
2246 " List group members")
2249 "list",
2250 net_sam_list,
2251 NET_TRANSPORT_LOCAL,
2252 N_("List users, groups and local groups"),
2253 N_("net sam list\n"
2254 " List users, groups and local groups")
2257 "show",
2258 net_sam_show,
2259 NET_TRANSPORT_LOCAL,
2260 N_("Show details of a SAM entry"),
2261 N_("net sam show\n"
2262 " Show details of a SAM entry")
2265 "set",
2266 net_sam_set,
2267 NET_TRANSPORT_LOCAL,
2268 N_("Set details of a SAM account"),
2269 N_("net sam set\n"
2270 " Set details of a SAM account")
2273 "policy",
2274 net_sam_policy,
2275 NET_TRANSPORT_LOCAL,
2276 N_("Set account policies"),
2277 N_("net sam policy\n"
2278 " Set account policies")
2281 "rights",
2282 net_sam_rights,
2283 NET_TRANSPORT_LOCAL,
2284 N_("Manipulate user privileges"),
2285 N_("net sam rights\n"
2286 " Manipulate user privileges")
2288 #ifdef HAVE_LDAP
2290 "provision",
2291 net_sam_provision,
2292 NET_TRANSPORT_LOCAL,
2293 N_("Provision a clean user database"),
2294 N_("net sam privison\n"
2295 " Provision a clear user database")
2297 #endif
2298 {NULL, NULL, 0, NULL, NULL}
2301 if (getuid() != 0) {
2302 d_fprintf(stderr, _("You are not root, most things won't "
2303 "work\n"));
2306 return net_run_function(c, argc, argv, "net sam", func);