lib: Update all consumers of strtoul_err(), strtoull_err() to new API
[samba.git] / source3 / utils / net_sam.c
blob164d9408c56f4b9a7d38a8860ea952d54b55f073
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;
487 int err = 0;
489 if (argc != 2 || c->display_usage) {
490 d_fprintf(stderr, "%s\n%s",
491 _("Usage:"),
492 _("net sam policy set \"<account policy>\" <value>\n"));
493 return -1;
496 account_policy = argv[0];
497 field = account_policy_name_to_typenum(account_policy);
499 if (strequal(argv[1], "forever") || strequal(argv[1], "never")
500 || strequal(argv[1], "off")) {
501 value = -1;
503 else {
504 value = strtoul_err(argv[1], &endptr, 10, &err);
506 if (err != 0 || *endptr != '\0') {
507 d_printf(_("Unable to set policy \"%s\"! Invalid value "
508 "\"%s\".\n"),
509 account_policy, argv[1]);
510 return -1;
514 if (field == 0) {
515 const char **names;
516 int i, count;
518 account_policy_names_list(talloc_tos(), &names, &count);
519 d_fprintf(stderr, _("No account policy \"%s\"!\n\n"), argv[0]);
520 d_fprintf(stderr, _("Valid account policies are:\n"));
522 for (i=0; i<count; i++) {
523 d_fprintf(stderr, "%s\n", names[i]);
526 TALLOC_FREE(names);
528 return -1;
531 if (!pdb_get_account_policy(field, &old_value)) {
532 d_fprintf(stderr, _("Valid account policy, but unable to fetch "
533 "value!\n"));
534 } else {
535 d_printf(_("Account policy \"%s\" value was: %d\n"),
536 account_policy, old_value);
539 if (!pdb_set_account_policy(field, value)) {
540 d_fprintf(stderr, _("Valid account policy, but unable to "
541 "set value!\n"));
542 return -1;
543 } else {
544 d_printf(_("Account policy \"%s\" value is now: %d\n"),
545 account_policy, value);
548 return 0;
551 static int net_sam_policy_show(struct net_context *c, int argc, const char **argv)
553 const char *account_policy = NULL;
554 uint32_t old_value;
555 enum pdb_policy_type field;
557 if (argc != 1 || c->display_usage) {
558 d_fprintf(stderr, "%s\n%s",
559 _("Usage:"),
560 _("net sam policy show \"<account policy>\"\n"));
561 return -1;
564 account_policy = argv[0];
565 field = account_policy_name_to_typenum(account_policy);
567 if (field == 0) {
568 const char **names;
569 int count;
570 int i;
571 account_policy_names_list(talloc_tos(), &names, &count);
572 d_fprintf(stderr, _("No account policy by that name!\n"));
573 if (count != 0) {
574 d_fprintf(stderr, _("Valid account policies "
575 "are:\n"));
576 for (i=0; i<count; i++) {
577 d_fprintf(stderr, "%s\n", names[i]);
580 TALLOC_FREE(names);
581 return -1;
584 if (!pdb_get_account_policy(field, &old_value)) {
585 fprintf(stderr, _("Valid account policy, but unable to "
586 "fetch value!\n"));
587 return -1;
590 printf(_("Account policy \"%s\" description: %s\n"),
591 account_policy, account_policy_get_desc(field));
592 printf(_("Account policy \"%s\" value is: %d\n"), account_policy,
593 old_value);
594 return 0;
597 static int net_sam_policy_list(struct net_context *c, int argc, const char **argv)
599 const char **names;
600 int count;
601 int i;
603 if (c->display_usage) {
604 d_printf( "%s\n"
605 "net sam policy list\n"
606 " %s\n",
607 _("Usage:"),
608 _("List account policies"));
609 return 0;
612 account_policy_names_list(talloc_tos(), &names, &count);
613 if (count != 0) {
614 d_fprintf(stderr, _("Valid account policies "
615 "are:\n"));
616 for (i = 0; i < count ; i++) {
617 d_fprintf(stderr, "%s\n", names[i]);
620 TALLOC_FREE(names);
621 return -1;
624 static int net_sam_policy(struct net_context *c, int argc, const char **argv)
626 struct functable func[] = {
628 "list",
629 net_sam_policy_list,
630 NET_TRANSPORT_LOCAL,
631 N_("List account policies"),
632 N_("net sam policy list\n"
633 " List account policies")
636 "show",
637 net_sam_policy_show,
638 NET_TRANSPORT_LOCAL,
639 N_("Show account policies"),
640 N_("net sam policy show\n"
641 " Show account policies")
644 "set",
645 net_sam_policy_set,
646 NET_TRANSPORT_LOCAL,
647 N_("Change account policies"),
648 N_("net sam policy set\n"
649 " Change account policies")
651 {NULL, NULL, 0, NULL, NULL}
654 return net_run_function(c, argc, argv, "net sam policy", func);
657 static int net_sam_rights_list(struct net_context *c, int argc,
658 const char **argv)
660 enum sec_privilege privilege;
662 if (argc > 1 || c->display_usage) {
663 d_fprintf(stderr, "%s\n%s",
664 _("Usage:"),
665 _("net sam rights list [privilege name]\n"));
666 return -1;
669 if (argc == 0) {
670 int i;
671 int num = num_privileges_in_short_list();
673 for (i=0; i<num; i++) {
674 d_printf("%s\n", sec_privilege_name_from_index(i));
676 return 0;
679 privilege = sec_privilege_id(argv[0]);
681 if (privilege != SEC_PRIV_INVALID) {
682 struct dom_sid *sids;
683 int i, num_sids;
684 NTSTATUS status;
686 status = privilege_enum_sids(privilege, talloc_tos(),
687 &sids, &num_sids);
688 if (!NT_STATUS_IS_OK(status)) {
689 d_fprintf(stderr, _("Could not list rights: %s\n"),
690 nt_errstr(status));
691 return -1;
694 for (i=0; i<num_sids; i++) {
695 const char *dom, *name;
696 enum lsa_SidType type;
697 struct dom_sid_buf buf;
699 if (lookup_sid(talloc_tos(), &sids[i], &dom, &name,
700 &type)) {
701 d_printf("%s\\%s\n", dom, name);
703 else {
704 d_printf("%s\n",
705 dom_sid_str_buf(&sids[i], &buf));
708 return 0;
711 return -1;
714 static int net_sam_rights_grant(struct net_context *c, int argc,
715 const char **argv)
717 struct dom_sid sid;
718 enum lsa_SidType type;
719 const char *dom, *name;
720 int i;
722 if (argc < 2 || c->display_usage) {
723 d_fprintf(stderr, "%s\n%s",
724 _("Usage:"),
725 _("net sam rights grant <name> <rights> ...\n"));
726 return -1;
729 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
730 &dom, &name, &sid, &type)) {
731 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
732 return -1;
735 for (i=1; i < argc; i++) {
736 enum sec_privilege privilege = sec_privilege_id(argv[i]);
737 if (privilege == SEC_PRIV_INVALID) {
738 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
739 return -1;
742 if (!grant_privilege_by_name(&sid, argv[i])) {
743 d_fprintf(stderr, _("Could not grant privilege\n"));
744 return -1;
747 d_printf(_("Granted %s to %s\\%s\n"), argv[i], dom, name);
750 return 0;
753 static int net_sam_rights_revoke(struct net_context *c, int argc,
754 const char **argv)
756 struct dom_sid sid;
757 enum lsa_SidType type;
758 const char *dom, *name;
759 int i;
761 if (argc < 2 || c->display_usage) {
762 d_fprintf(stderr, "%s\n%s",
763 _("Usage:"),
764 _("net sam rights revoke <name> <rights>\n"));
765 return -1;
768 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
769 &dom, &name, &sid, &type)) {
770 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
771 return -1;
774 for (i=1; i < argc; i++) {
775 enum sec_privilege privilege = sec_privilege_id(argv[i]);
776 if (privilege == SEC_PRIV_INVALID) {
777 d_fprintf(stderr, _("%s unknown\n"), argv[i]);
778 return -1;
781 if (!revoke_privilege_by_name(&sid, argv[i])) {
782 d_fprintf(stderr, _("Could not revoke privilege\n"));
783 return -1;
786 d_printf(_("Revoked %s from %s\\%s\n"), argv[i], dom, name);
789 return 0;
792 static int net_sam_rights(struct net_context *c, int argc, const char **argv)
794 struct functable func[] = {
796 "list",
797 net_sam_rights_list,
798 NET_TRANSPORT_LOCAL,
799 N_("List possible user rights"),
800 N_("net sam rights list\n"
801 " List possible user rights")
804 "grant",
805 net_sam_rights_grant,
806 NET_TRANSPORT_LOCAL,
807 N_("Grant right(s)"),
808 N_("net sam rights grant\n"
809 " Grant right(s)")
812 "revoke",
813 net_sam_rights_revoke,
814 NET_TRANSPORT_LOCAL,
815 N_("Revoke right(s)"),
816 N_("net sam rights revoke\n"
817 " Revoke right(s)")
819 {NULL, NULL, 0, NULL, NULL}
821 return net_run_function(c, argc, argv, "net sam rights", func);
825 * Map a unix group to a domain group
828 static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *map)
830 const char *dom, *name;
831 uint32_t rid;
833 if (pdb_getgrgid(map, grp->gr_gid)) {
834 return NT_STATUS_GROUP_EXISTS;
837 map->gid = grp->gr_gid;
839 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
840 &dom, &name, NULL, NULL)) {
842 map->nt_name = talloc_asprintf(map, "Unix Group %s",
843 grp->gr_name);
845 DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
846 grp->gr_name, dom, name, map->nt_name));
849 if (lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
850 NULL, NULL, NULL, NULL)) {
851 DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
852 return NT_STATUS_GROUP_EXISTS;
855 if (pdb_capabilities() & PDB_CAP_STORE_RIDS) {
856 if (!pdb_new_rid(&rid)) {
857 DEBUG(3, ("Could not get a new RID for %s\n",
858 grp->gr_name));
859 return NT_STATUS_ACCESS_DENIED;
861 } else {
862 rid = algorithmic_pdb_gid_to_group_rid( grp->gr_gid );
865 sid_compose(&map->sid, get_global_sam_sid(), rid);
866 map->sid_name_use = SID_NAME_DOM_GRP;
867 map->comment = talloc_asprintf(map, "Unix Group %s", grp->gr_name);
869 return pdb_add_group_mapping_entry(map);
872 static int net_sam_mapunixgroup(struct net_context *c, int argc, const char **argv)
874 NTSTATUS status;
875 GROUP_MAP *map;
876 struct group *grp;
877 struct dom_sid_buf buf;
879 if (argc != 1 || c->display_usage) {
880 d_fprintf(stderr, "%s\n%s",
881 _("Usage:"),
882 _("net sam mapunixgroup <name>\n"));
883 return -1;
886 grp = getgrnam(argv[0]);
887 if (grp == NULL) {
888 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
889 return -1;
892 map = talloc_zero(talloc_tos(), GROUP_MAP);
893 if (!map) {
894 d_fprintf(stderr, _("Out of memory!\n"));
895 return -1;
898 status = map_unix_group(grp, map);
900 if (!NT_STATUS_IS_OK(status)) {
901 d_fprintf(stderr, _("Mapping group %s failed with %s\n"),
902 argv[0], nt_errstr(status));
903 return -1;
906 d_printf(_("Mapped unix group %s to SID %s\n"), argv[0],
907 dom_sid_str_buf(&map->sid, &buf));
909 TALLOC_FREE(map);
910 return 0;
914 * Remove a group mapping
917 static NTSTATUS unmap_unix_group(const struct group *grp)
919 struct dom_sid dom_sid;
920 struct unixid id;
922 if (!lookup_name(talloc_tos(), grp->gr_name, LOOKUP_NAME_LOCAL,
923 NULL, NULL, NULL, NULL)) {
924 DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
925 return NT_STATUS_NO_SUCH_GROUP;
928 id.id = grp->gr_gid;
929 id.type = ID_TYPE_GID;
930 if (!pdb_id_to_sid(&id, &dom_sid)) {
931 return NT_STATUS_UNSUCCESSFUL;
934 return pdb_delete_group_mapping_entry(dom_sid);
937 static int net_sam_unmapunixgroup(struct net_context *c, int argc, const char **argv)
939 NTSTATUS status;
940 struct group *grp;
942 if (argc != 1 || c->display_usage) {
943 d_fprintf(stderr, "%s\n%s",
944 _("Usage:"),
945 _("net sam unmapunixgroup <name>\n"));
946 return -1;
949 grp = getgrnam(argv[0]);
950 if (grp == NULL) {
951 d_fprintf(stderr, _("Could not find mapping for group %s.\n"),
952 argv[0]);
953 return -1;
956 status = unmap_unix_group(grp);
958 if (!NT_STATUS_IS_OK(status)) {
959 d_fprintf(stderr, _("Unmapping group %s failed with %s.\n"),
960 argv[0], nt_errstr(status));
961 return -1;
964 d_printf(_("Unmapped unix group %s.\n"), argv[0]);
966 return 0;
970 * Create a domain group
973 static int net_sam_createdomaingroup(struct net_context *c, int argc,
974 const char **argv)
976 NTSTATUS status;
977 uint32_t rid;
979 if (argc != 1 || c->display_usage) {
980 d_fprintf(stderr, "%s\n%s",
981 _("Usage:"),
982 _("net sam createdomaingroup <name>\n"));
983 return -1;
986 status = pdb_create_dom_group(talloc_tos(), argv[0], &rid);
988 if (!NT_STATUS_IS_OK(status)) {
989 d_fprintf(stderr, _("Creating %s failed with %s\n"),
990 argv[0], nt_errstr(status));
991 return -1;
994 d_printf(_("Created domain group %s with RID %d\n"), argv[0], rid);
996 return 0;
1000 * Delete a domain group
1003 static int net_sam_deletedomaingroup(struct net_context *c, int argc,
1004 const char **argv)
1006 struct dom_sid sid;
1007 uint32_t rid;
1008 enum lsa_SidType type;
1009 const char *dom, *name;
1010 NTSTATUS status;
1012 if (argc != 1 || c->display_usage) {
1013 d_fprintf(stderr, "%s\n%s",
1014 _("Usage:"),
1015 _("net sam deletelocalgroup <name>\n"));
1016 return -1;
1019 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1020 &dom, &name, &sid, &type)) {
1021 d_fprintf(stderr, _("Could not find %s.\n"), argv[0]);
1022 return -1;
1025 if (type != SID_NAME_DOM_GRP) {
1026 d_fprintf(stderr, _("%s is a %s, not a domain group.\n"),
1027 argv[0], sid_type_lookup(type));
1028 return -1;
1031 sid_peek_rid(&sid, &rid);
1033 status = pdb_delete_dom_group(talloc_tos(), rid);
1035 if (!NT_STATUS_IS_OK(status)) {
1036 d_fprintf(stderr,_("Deleting domain group %s failed with %s\n"),
1037 argv[0], nt_errstr(status));
1038 return -1;
1041 d_printf(_("Deleted domain group %s.\n"), argv[0]);
1043 return 0;
1047 * Create a local group
1050 static int net_sam_createlocalgroup(struct net_context *c, int argc, const char **argv)
1052 NTSTATUS status;
1053 uint32_t rid;
1055 if (argc != 1 || c->display_usage) {
1056 d_fprintf(stderr, "%s\n%s",
1057 _("Usage:"),
1058 _("net sam createlocalgroup <name>\n"));
1059 return -1;
1062 if (!winbind_ping()) {
1063 d_fprintf(stderr, _("winbind seems not to run. "
1064 "createlocalgroup only works when winbind runs.\n"));
1065 return -1;
1068 status = pdb_create_alias(argv[0], &rid);
1070 if (!NT_STATUS_IS_OK(status)) {
1071 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1072 argv[0], nt_errstr(status));
1073 return -1;
1076 d_printf(_("Created local group %s with RID %d\n"), argv[0], rid);
1078 return 0;
1082 * Delete a local group
1085 static int net_sam_deletelocalgroup(struct net_context *c, int argc, const char **argv)
1087 struct dom_sid sid;
1088 enum lsa_SidType type;
1089 const char *dom, *name;
1090 NTSTATUS status;
1092 if (argc != 1 || c->display_usage) {
1093 d_fprintf(stderr, "%s\n%s",
1094 _("Usage:"),
1095 _("net sam deletelocalgroup <name>\n"));
1096 return -1;
1099 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1100 &dom, &name, &sid, &type)) {
1101 d_fprintf(stderr,_("Could not find %s.\n"), argv[0]);
1102 return -1;
1105 if (type != SID_NAME_ALIAS) {
1106 d_fprintf(stderr, _("%s is a %s, not a local group.\n"),argv[0],
1107 sid_type_lookup(type));
1108 return -1;
1111 status = pdb_delete_alias(&sid);
1113 if (!NT_STATUS_IS_OK(status)) {
1114 d_fprintf(stderr, _("Deleting local group %s failed with %s\n"),
1115 argv[0], nt_errstr(status));
1116 return -1;
1119 d_printf(_("Deleted local group %s.\n"), argv[0]);
1121 return 0;
1125 * Create a builtin group
1128 static int net_sam_createbuiltingroup(struct net_context *c, int argc, const char **argv)
1130 NTSTATUS status;
1131 uint32_t rid;
1132 enum lsa_SidType type;
1133 fstring groupname;
1134 struct dom_sid sid;
1136 if (argc != 1 || c->display_usage) {
1137 d_fprintf(stderr, "%s\n%s",
1138 _("Usage:"),
1139 _("net sam createbuiltingroup <name>\n"));
1140 return -1;
1143 if (!winbind_ping()) {
1144 d_fprintf(stderr, _("winbind seems not to run. "
1145 "createbuiltingroup only works when winbind "
1146 "runs.\n"));
1147 return -1;
1150 /* validate the name and get the group */
1152 fstrcpy( groupname, "BUILTIN\\" );
1153 fstrcat( groupname, argv[0] );
1155 if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
1156 NULL, &sid, &type)) {
1157 d_fprintf(stderr, _("%s is not a BUILTIN group\n"), argv[0]);
1158 return -1;
1161 if ( !sid_peek_rid( &sid, &rid ) ) {
1162 d_fprintf(stderr, _("Failed to get RID for %s\n"), argv[0]);
1163 return -1;
1166 status = pdb_create_builtin(rid);
1168 if (!NT_STATUS_IS_OK(status)) {
1169 d_fprintf(stderr, _("Creating %s failed with %s\n"),
1170 argv[0], nt_errstr(status));
1171 return -1;
1174 d_printf(_("Created BUILTIN group %s with RID %d\n"), argv[0], rid);
1176 return 0;
1180 * Add a group member
1183 static int net_sam_addmem(struct net_context *c, int argc, const char **argv)
1185 const char *groupdomain, *groupname, *memberdomain, *membername;
1186 struct dom_sid group, member;
1187 enum lsa_SidType grouptype, membertype;
1188 NTSTATUS status;
1190 if (argc != 2 || c->display_usage) {
1191 d_fprintf(stderr, "%s\n%s",
1192 _("Usage:"),
1193 _("net sam addmem <group> <member>\n"));
1194 return -1;
1197 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1198 &groupdomain, &groupname, &group, &grouptype)) {
1199 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1200 return -1;
1203 /* check to see if the member to be added is a name or a SID */
1205 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1206 &memberdomain, &membername, &member, &membertype))
1208 /* try it as a SID */
1210 if ( !string_to_sid( &member, argv[1] ) ) {
1211 d_fprintf(stderr, _("Could not find member %s\n"),
1212 argv[1]);
1213 return -1;
1216 if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
1217 &membername, &membertype) )
1219 d_fprintf(stderr, _("Could not resolve SID %s\n"),
1220 argv[1]);
1221 return -1;
1225 if ((grouptype == SID_NAME_ALIAS) || (grouptype == SID_NAME_WKN_GRP)) {
1226 if ((membertype != SID_NAME_USER) &&
1227 (membertype != SID_NAME_ALIAS) &&
1228 (membertype != SID_NAME_DOM_GRP)) {
1229 d_fprintf(stderr, _("Can't add %s: only users, domain "
1230 "groups and domain local groups "
1231 "can be added. %s is a %s\n"),
1232 argv[0], argv[1],
1233 sid_type_lookup(membertype));
1234 return -1;
1236 status = pdb_add_aliasmem(&group, &member);
1238 if (!NT_STATUS_IS_OK(status)) {
1239 d_fprintf(stderr, _("Adding local group member failed "
1240 "with %s\n"), nt_errstr(status));
1241 return -1;
1243 } else if (grouptype == SID_NAME_DOM_GRP) {
1244 uint32_t grouprid, memberrid;
1246 sid_peek_rid(&group, &grouprid);
1247 sid_peek_rid(&member, &memberrid);
1249 status = pdb_add_groupmem(talloc_tos(), grouprid, memberrid);
1250 if (!NT_STATUS_IS_OK(status)) {
1251 d_fprintf(stderr, _("Adding domain group member failed "
1252 "with %s\n"), nt_errstr(status));
1253 return -1;
1255 } else {
1256 d_fprintf(stderr, _("Can only add members to local groups so "
1257 "far, %s is a %s\n"), argv[0],
1258 sid_type_lookup(grouptype));
1259 return -1;
1262 d_printf(_("Added %s\\%s to %s\\%s\n"), memberdomain, membername,
1263 groupdomain, groupname);
1265 return 0;
1269 * Delete a group member
1272 static int net_sam_delmem(struct net_context *c, int argc, const char **argv)
1274 const char *groupdomain, *groupname;
1275 const char *memberdomain = NULL;
1276 const char *membername = NULL;
1277 struct dom_sid group, member;
1278 enum lsa_SidType grouptype;
1279 NTSTATUS status;
1281 if (argc != 2 || c->display_usage) {
1282 d_fprintf(stderr,"%s\n%s",
1283 _("Usage:"),
1284 _("net sam delmem <group> <member>\n"));
1285 return -1;
1288 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1289 &groupdomain, &groupname, &group, &grouptype)) {
1290 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1291 return -1;
1294 if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_LOCAL,
1295 &memberdomain, &membername, &member, NULL)) {
1296 if (!string_to_sid(&member, argv[1])) {
1297 d_fprintf(stderr, _("Could not find member %s\n"),
1298 argv[1]);
1299 return -1;
1303 if ((grouptype == SID_NAME_ALIAS) ||
1304 (grouptype == SID_NAME_WKN_GRP)) {
1305 status = pdb_del_aliasmem(&group, &member);
1307 if (!NT_STATUS_IS_OK(status)) {
1308 d_fprintf(stderr,_("Deleting local group member failed "
1309 "with %s\n"), nt_errstr(status));
1310 return -1;
1312 } else if (grouptype == SID_NAME_DOM_GRP) {
1313 uint32_t grouprid, memberrid;
1315 sid_peek_rid(&group, &grouprid);
1316 sid_peek_rid(&member, &memberrid);
1318 status = pdb_del_groupmem(talloc_tos(), grouprid, memberrid);
1319 if (!NT_STATUS_IS_OK(status)) {
1320 d_fprintf(stderr, _("Deleting domain group member "
1321 "failed with %s\n"), nt_errstr(status));
1322 return -1;
1324 } else {
1325 d_fprintf(stderr, _("Can only delete members from local groups "
1326 "so far, %s is a %s\n"), argv[0],
1327 sid_type_lookup(grouptype));
1328 return -1;
1331 if (membername != NULL) {
1332 d_printf(_("Deleted %s\\%s from %s\\%s\n"),
1333 memberdomain, membername, groupdomain, groupname);
1334 } else {
1335 struct dom_sid_buf buf;
1336 d_printf(_("Deleted %s from %s\\%s\n"),
1337 dom_sid_str_buf(&member, &buf),
1338 groupdomain,
1339 groupname);
1342 return 0;
1346 * List group members
1349 static int net_sam_listmem(struct net_context *c, int argc, const char **argv)
1351 const char *groupdomain, *groupname;
1352 struct dom_sid group;
1353 struct dom_sid *members = NULL;
1354 size_t i, num_members = 0;
1355 enum lsa_SidType grouptype;
1356 NTSTATUS status;
1358 if (argc != 1 || c->display_usage) {
1359 d_fprintf(stderr, "%s\n%s",
1360 _("Usage:"),
1361 _("net sam listmem <group>\n"));
1362 return -1;
1365 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1366 &groupdomain, &groupname, &group, &grouptype)) {
1367 d_fprintf(stderr, _("Could not find group %s\n"), argv[0]);
1368 return -1;
1371 if ((grouptype == SID_NAME_ALIAS) ||
1372 (grouptype == SID_NAME_WKN_GRP)) {
1373 status = pdb_enum_aliasmem(&group, talloc_tos(), &members,
1374 &num_members);
1375 if (!NT_STATUS_IS_OK(status)) {
1376 d_fprintf(stderr, _("Listing group members failed with "
1377 "%s\n"), nt_errstr(status));
1378 return -1;
1380 } else if (grouptype == SID_NAME_DOM_GRP) {
1381 uint32_t *rids;
1383 status = pdb_enum_group_members(talloc_tos(), &group,
1384 &rids, &num_members);
1385 if (!NT_STATUS_IS_OK(status)) {
1386 d_fprintf(stderr, _("Listing group members failed with "
1387 "%s\n"), nt_errstr(status));
1388 return -1;
1391 members = talloc_array(talloc_tos(), struct dom_sid,
1392 num_members);
1393 if (members == NULL) {
1394 TALLOC_FREE(rids);
1395 return -1;
1398 for (i=0; i<num_members; i++) {
1399 sid_compose(&members[i], get_global_sam_sid(),
1400 rids[i]);
1402 TALLOC_FREE(rids);
1403 } else {
1404 d_fprintf(stderr,_("Can only list local group members so far.\n"
1405 "%s is a %s\n"), argv[0], sid_type_lookup(grouptype));
1406 return -1;
1409 d_printf(_("%s\\%s has %u members\n"), groupdomain, groupname,
1410 (unsigned int)num_members);
1411 for (i=0; i<num_members; i++) {
1412 const char *dom, *name;
1413 if (lookup_sid(talloc_tos(), &members[i], &dom, &name, NULL)) {
1414 d_printf(" %s\\%s\n", dom, name);
1415 } else {
1416 struct dom_sid_buf buf;
1417 d_printf(" %s\n",
1418 dom_sid_str_buf(&members[i], &buf));
1422 TALLOC_FREE(members);
1424 return 0;
1428 * Do the listing
1430 static int net_sam_do_list(struct net_context *c, int argc, const char **argv,
1431 struct pdb_search *search, const char *what)
1433 bool verbose = (argc == 1);
1435 if ((argc > 1) || c->display_usage ||
1436 ((argc == 1) && !strequal(argv[0], "verbose"))) {
1437 d_fprintf(stderr, "%s\n", _("Usage:"));
1438 d_fprintf(stderr, _("net sam list %s [verbose]\n"), what);
1439 return -1;
1442 if (search == NULL) {
1443 d_fprintf(stderr, _("Could not start search\n"));
1444 return -1;
1447 while (true) {
1448 struct samr_displayentry entry;
1449 if (!search->next_entry(search, &entry)) {
1450 break;
1452 if (verbose) {
1453 d_printf("%s:%d:%s\n",
1454 entry.account_name,
1455 entry.rid,
1456 entry.description);
1457 } else {
1458 d_printf("%s\n", entry.account_name);
1462 TALLOC_FREE(search);
1463 return 0;
1466 static int net_sam_list_users(struct net_context *c, int argc,
1467 const char **argv)
1469 return net_sam_do_list(c, argc, argv,
1470 pdb_search_users(talloc_tos(), ACB_NORMAL),
1471 "users");
1474 static int net_sam_list_groups(struct net_context *c, int argc,
1475 const char **argv)
1477 return net_sam_do_list(c, argc, argv, pdb_search_groups(talloc_tos()),
1478 "groups");
1481 static int net_sam_list_localgroups(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 get_global_sam_sid()),
1487 "localgroups");
1490 static int net_sam_list_builtin(struct net_context *c, int argc,
1491 const char **argv)
1493 return net_sam_do_list(c, argc, argv,
1494 pdb_search_aliases(talloc_tos(),
1495 &global_sid_Builtin),
1496 "builtin");
1499 static int net_sam_list_workstations(struct net_context *c, int argc,
1500 const char **argv)
1502 return net_sam_do_list(c, argc, argv,
1503 pdb_search_users(talloc_tos(), ACB_WSTRUST),
1504 "workstations");
1508 * List stuff
1511 static int net_sam_list(struct net_context *c, int argc, const char **argv)
1513 struct functable func[] = {
1515 "users",
1516 net_sam_list_users,
1517 NET_TRANSPORT_LOCAL,
1518 N_("List SAM users"),
1519 N_("net sam list users\n"
1520 " List SAM users")
1523 "groups",
1524 net_sam_list_groups,
1525 NET_TRANSPORT_LOCAL,
1526 N_("List SAM groups"),
1527 N_("net sam list groups\n"
1528 " List SAM groups")
1531 "localgroups",
1532 net_sam_list_localgroups,
1533 NET_TRANSPORT_LOCAL,
1534 N_("List SAM local groups"),
1535 N_("net sam list localgroups\n"
1536 " List SAM local groups")
1539 "builtin",
1540 net_sam_list_builtin,
1541 NET_TRANSPORT_LOCAL,
1542 N_("List builtin groups"),
1543 N_("net sam list builtin\n"
1544 " List builtin groups")
1547 "workstations",
1548 net_sam_list_workstations,
1549 NET_TRANSPORT_LOCAL,
1550 N_("List domain member workstations"),
1551 N_("net sam list workstations\n"
1552 " List domain member workstations")
1554 {NULL, NULL, 0, NULL, NULL}
1557 return net_run_function(c, argc, argv, "net sam list", func);
1561 * Show details of SAM entries
1564 static int net_sam_show(struct net_context *c, int argc, const char **argv)
1566 struct dom_sid sid;
1567 struct dom_sid_buf buf;
1568 enum lsa_SidType type;
1569 const char *dom, *name;
1571 if (argc != 1 || c->display_usage) {
1572 d_fprintf(stderr, "%s\n%s",
1573 _("Usage:"),
1574 _("net sam show <name>\n"));
1575 return -1;
1578 if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_LOCAL,
1579 &dom, &name, &sid, &type)) {
1580 d_fprintf(stderr, _("Could not find name %s\n"), argv[0]);
1581 return -1;
1584 d_printf(_("%s\\%s is a %s with SID %s\n"), dom, name,
1585 sid_type_lookup(type), dom_sid_str_buf(&sid, &buf));
1587 return 0;
1590 #ifdef HAVE_LDAP
1593 * Init an LDAP tree with default users and Groups
1594 * if ldapsam:editposix is enabled
1597 static int net_sam_provision(struct net_context *c, int argc, const char **argv)
1599 TALLOC_CTX *tc;
1600 char *ldap_bk;
1601 char *ldap_uri = NULL;
1602 char *p;
1603 struct smbldap_state *state = NULL;
1604 GROUP_MAP *gmap = NULL;
1605 struct dom_sid gsid;
1606 gid_t domusers_gid = -1;
1607 gid_t domadmins_gid = -1;
1608 struct samu *samuser;
1609 struct passwd *pwd;
1610 bool is_ipa = false;
1611 char *bind_dn = NULL;
1612 char *bind_secret = NULL;
1613 NTSTATUS status;
1615 if (c->display_usage) {
1616 d_printf( "%s\n"
1617 "net sam provision\n"
1618 " %s\n",
1619 _("Usage:"),
1620 _("Init an LDAP tree with default users/groups"));
1621 return 0;
1624 tc = talloc_new(NULL);
1625 if (!tc) {
1626 d_fprintf(stderr, _("Out of Memory!\n"));
1627 return -1;
1630 if ((ldap_bk = talloc_strdup(tc, lp_passdb_backend())) == NULL) {
1631 d_fprintf(stderr, _("talloc failed\n"));
1632 talloc_free(tc);
1633 return -1;
1635 p = strchr(ldap_bk, ':');
1636 if (p) {
1637 *p = 0;
1638 ldap_uri = talloc_strdup(tc, p+1);
1639 trim_char(ldap_uri, ' ', ' ');
1642 trim_char(ldap_bk, ' ', ' ');
1644 if (strcmp(ldap_bk, "IPA_ldapsam") == 0 ) {
1645 is_ipa = true;
1648 if (strcmp(ldap_bk, "ldapsam") != 0 && !is_ipa ) {
1649 d_fprintf(stderr,
1650 _("Provisioning works only with ldapsam backend\n"));
1651 goto failed;
1654 if (!lp_parm_bool(-1, "ldapsam", "trusted", false) ||
1655 !lp_parm_bool(-1, "ldapsam", "editposix", false)) {
1657 d_fprintf(stderr, _("Provisioning works only if ldapsam:trusted"
1658 " and ldapsam:editposix are enabled.\n"));
1659 goto failed;
1662 if (!is_ipa && !winbind_ping()) {
1663 d_fprintf(stderr, _("winbind seems not to run. Provisioning "
1664 "LDAP only works when winbind runs.\n"));
1665 goto failed;
1668 if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
1669 d_fprintf(stderr, _("Failed to retrieve LDAP password from secrets.tdb\n"));
1670 goto failed;
1673 status = smbldap_init(tc, NULL, ldap_uri, false, bind_dn, bind_secret, &state);
1675 memset(bind_secret, '\0', strlen(bind_secret));
1676 SAFE_FREE(bind_secret);
1677 SAFE_FREE(bind_dn);
1679 if (!NT_STATUS_IS_OK(status)) {
1680 d_fprintf(stderr, _("Unable to connect to the LDAP server.\n"));
1681 goto failed;
1684 d_printf(_("Checking for Domain Users group.\n"));
1686 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_USERS);
1688 gmap = talloc_zero(tc, GROUP_MAP);
1689 if (!gmap) {
1690 d_printf(_("Out of memory!\n"));
1691 goto failed;
1694 if (!pdb_getgrsid(gmap, gsid)) {
1695 struct dom_sid_buf gsid_str;
1696 LDAPMod **mods = NULL;
1697 char *dn;
1698 char *uname;
1699 char *wname;
1700 char *gidstr;
1701 char *gtype;
1702 int rc;
1704 d_printf(_("Adding the Domain Users group.\n"));
1706 /* lets allocate a new groupid for this group */
1707 if (is_ipa) {
1708 domusers_gid = 999;
1709 } else {
1710 if (!winbind_allocate_gid(&domusers_gid)) {
1711 d_fprintf(stderr, _("Unable to allocate a new gid to "
1712 "create Domain Users group!\n"));
1713 goto domu_done;
1717 uname = talloc_strdup(tc, "domusers");
1718 wname = talloc_strdup(tc, "Domain Users");
1719 dn = talloc_asprintf(tc, "cn=%s,%s", "domusers",
1720 lp_ldap_group_suffix(talloc_tos()));
1721 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domusers_gid);
1722 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1724 if (!uname || !wname || !dn || !gidstr || !gtype) {
1725 d_fprintf(stderr, "Out of Memory!\n");
1726 goto failed;
1729 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1730 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1731 if (is_ipa) {
1732 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1733 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1734 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1736 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1737 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1738 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1739 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1740 dom_sid_str_buf(&gsid, &gsid_str));
1741 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1743 smbldap_talloc_autofree_ldapmod(tc, mods);
1745 rc = smbldap_add(state, dn, mods);
1747 if (rc != LDAP_SUCCESS) {
1748 d_fprintf(stderr, _("Failed to add Domain Users group "
1749 "to ldap directory\n"));
1752 if (is_ipa) {
1753 if (!pdb_getgrsid(gmap, gsid)) {
1754 d_fprintf(stderr, _("Failed to read just "
1755 "created domain group.\n"));
1756 goto failed;
1757 } else {
1758 domusers_gid = gmap->gid;
1761 } else {
1762 domusers_gid = gmap->gid;
1763 d_printf(_("found!\n"));
1766 domu_done:
1768 d_printf(_("Checking for Domain Admins group.\n"));
1770 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_ADMINS);
1772 if (!pdb_getgrsid(gmap, gsid)) {
1773 struct dom_sid_buf gsid_str;
1774 LDAPMod **mods = NULL;
1775 char *dn;
1776 char *uname;
1777 char *wname;
1778 char *gidstr;
1779 char *gtype;
1780 int rc;
1782 d_printf(_("Adding the Domain Admins group.\n"));
1784 /* lets allocate a new groupid for this group */
1785 if (is_ipa) {
1786 domadmins_gid = 999;
1787 } else {
1788 if (!winbind_allocate_gid(&domadmins_gid)) {
1789 d_fprintf(stderr, _("Unable to allocate a new gid to "
1790 "create Domain Admins group!\n"));
1791 goto doma_done;
1795 uname = talloc_strdup(tc, "domadmins");
1796 wname = talloc_strdup(tc, "Domain Admins");
1797 dn = talloc_asprintf(tc, "cn=%s,%s", "domadmins",
1798 lp_ldap_group_suffix(talloc_tos()));
1799 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1800 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
1802 if (!uname || !wname || !dn || !gidstr || !gtype) {
1803 d_fprintf(stderr, _("Out of Memory!\n"));
1804 goto failed;
1807 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
1808 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
1809 if (is_ipa) {
1810 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
1811 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
1812 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
1814 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
1815 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
1816 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1817 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
1818 dom_sid_str_buf(&gsid, &gsid_str));
1819 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
1821 smbldap_talloc_autofree_ldapmod(tc, mods);
1823 rc = smbldap_add(state, dn, mods);
1825 if (rc != LDAP_SUCCESS) {
1826 d_fprintf(stderr, _("Failed to add Domain Admins group "
1827 "to ldap directory\n"));
1830 if (is_ipa) {
1831 if (!pdb_getgrsid(gmap, gsid)) {
1832 d_fprintf(stderr, _("Failed to read just "
1833 "created domain group.\n"));
1834 goto failed;
1835 } else {
1836 domadmins_gid = gmap->gid;
1839 } else {
1840 domadmins_gid = gmap->gid;
1841 d_printf(_("found!\n"));
1844 doma_done:
1846 d_printf(_("Check for Administrator account.\n"));
1848 samuser = samu_new(tc);
1849 if (!samuser) {
1850 d_fprintf(stderr, _("Out of Memory!\n"));
1851 goto failed;
1854 if (!pdb_getsampwnam(samuser, "Administrator")) {
1855 LDAPMod **mods = NULL;
1856 struct dom_sid sid;
1857 struct dom_sid_buf sid_str;
1858 char *dn;
1859 char *name;
1860 char *uidstr;
1861 char *gidstr;
1862 char *shell;
1863 char *dir;
1864 char *princ;
1865 uid_t uid;
1866 int rc;
1868 d_printf(_("Adding the Administrator user.\n"));
1870 if (domadmins_gid == -1) {
1871 d_fprintf(stderr,
1872 _("Can't create Administrator user, Domain "
1873 "Admins group not available!\n"));
1874 goto done;
1877 if (is_ipa) {
1878 uid = 999;
1879 } else {
1880 if (!winbind_allocate_uid(&uid)) {
1881 d_fprintf(stderr,
1882 _("Unable to allocate a new uid to create "
1883 "the Administrator user!\n"));
1884 goto done;
1888 name = talloc_strdup(tc, "Administrator");
1889 dn = talloc_asprintf(tc, "uid=Administrator,%s",
1890 lp_ldap_user_suffix(talloc_tos()));
1891 uidstr = talloc_asprintf(tc, "%u", (unsigned int)uid);
1892 gidstr = talloc_asprintf(tc, "%u", (unsigned int)domadmins_gid);
1893 dir = talloc_sub_specified(tc, lp_template_homedir(),
1894 "Administrator",
1895 NULL,
1896 get_global_sam_name(),
1897 uid, domadmins_gid);
1898 shell = talloc_sub_specified(tc, lp_template_shell(),
1899 "Administrator",
1900 NULL,
1901 get_global_sam_name(),
1902 uid, domadmins_gid);
1904 if (!name || !dn || !uidstr || !gidstr || !dir || !shell) {
1905 d_fprintf(stderr, _("Out of Memory!\n"));
1906 goto failed;
1909 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_ADMINISTRATOR);
1911 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
1912 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
1913 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
1914 if (is_ipa) {
1915 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
1916 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
1917 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
1918 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
1919 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
1920 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
1921 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", name);
1922 princ = talloc_asprintf(tc, "%s@%s", name, lp_realm());
1923 if (!princ) {
1924 d_fprintf(stderr, _("Out of Memory!\n"));
1925 goto failed;
1927 smbldap_set_mod(&mods, LDAP_MOD_ADD, "krbPrincipalName", princ);
1929 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", name);
1930 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", name);
1931 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
1932 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
1933 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
1934 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", dir);
1935 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", shell);
1936 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
1937 dom_sid_str_buf(&sid, &sid_str));
1938 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
1939 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
1940 NEW_PW_FORMAT_SPACE_PADDED_LEN));
1942 smbldap_talloc_autofree_ldapmod(tc, mods);
1944 rc = smbldap_add(state, dn, mods);
1946 if (rc != LDAP_SUCCESS) {
1947 d_fprintf(stderr, _("Failed to add Administrator user "
1948 "to ldap directory\n"));
1951 if (is_ipa) {
1952 if (!pdb_getsampwnam(samuser, "Administrator")) {
1953 d_fprintf(stderr, _("Failed to read just "
1954 "created user.\n"));
1955 goto failed;
1958 } else {
1959 d_printf(_("found!\n"));
1962 d_printf(_("Checking for Guest user.\n"));
1964 samuser = samu_new(tc);
1965 if (!samuser) {
1966 d_fprintf(stderr, _("Out of Memory!\n"));
1967 goto failed;
1970 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
1971 LDAPMod **mods = NULL;
1972 struct dom_sid sid;
1973 struct dom_sid_buf sid_str;
1974 char *dn;
1975 char *uidstr;
1976 char *gidstr;
1977 int rc;
1979 d_printf(_("Adding the Guest user.\n"));
1981 sid_compose(&sid, get_global_sam_sid(), DOMAIN_RID_GUEST);
1983 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
1985 if (!pwd) {
1986 if (domusers_gid == -1) {
1987 d_fprintf(stderr,
1988 _("Can't create Guest user, Domain "
1989 "Users group not available!\n"));
1990 goto done;
1992 if ((pwd = talloc(tc, struct passwd)) == NULL) {
1993 d_fprintf(stderr, _("talloc failed\n"));
1994 goto done;
1996 pwd->pw_name = talloc_strdup(pwd, lp_guest_account());
1998 if (is_ipa) {
1999 pwd->pw_uid = 999;
2000 } else {
2001 if (!winbind_allocate_uid(&(pwd->pw_uid))) {
2002 d_fprintf(stderr,
2003 _("Unable to allocate a new uid to "
2004 "create the Guest user!\n"));
2005 goto done;
2008 pwd->pw_gid = domusers_gid;
2009 pwd->pw_dir = talloc_strdup(tc, "/");
2010 pwd->pw_shell = talloc_strdup(tc, "/bin/false");
2011 if (!pwd->pw_dir || !pwd->pw_shell) {
2012 d_fprintf(stderr, _("Out of Memory!\n"));
2013 goto failed;
2017 dn = talloc_asprintf(tc, "uid=%s,%s", pwd->pw_name,
2018 lp_ldap_user_suffix (talloc_tos()));
2019 uidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_uid);
2020 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2021 if (!dn || !uidstr || !gidstr) {
2022 d_fprintf(stderr, _("Out of Memory!\n"));
2023 goto failed;
2026 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_ACCOUNT);
2027 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXACCOUNT);
2028 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SAMBASAMACCOUNT);
2029 if (is_ipa) {
2030 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "person");
2031 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "organizationalperson");
2032 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetorgperson");
2033 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "inetuser");
2034 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbprincipalaux");
2035 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "krbticketpolicyaux");
2036 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sn", pwd->pw_name);
2038 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uid", pwd->pw_name);
2039 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", pwd->pw_name);
2040 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", pwd->pw_name);
2041 smbldap_set_mod(&mods, LDAP_MOD_ADD, "uidNumber", uidstr);
2042 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2043 if ((pwd->pw_dir != NULL) && (pwd->pw_dir[0] != '\0')) {
2044 smbldap_set_mod(&mods, LDAP_MOD_ADD, "homeDirectory", pwd->pw_dir);
2046 if ((pwd->pw_shell != NULL) && (pwd->pw_shell[0] != '\0')) {
2047 smbldap_set_mod(&mods, LDAP_MOD_ADD, "loginShell", pwd->pw_shell);
2049 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSID",
2050 dom_sid_str_buf(&sid, &sid_str));
2051 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaAcctFlags",
2052 pdb_encode_acct_ctrl(ACB_NORMAL|ACB_DISABLED,
2053 NEW_PW_FORMAT_SPACE_PADDED_LEN));
2055 smbldap_talloc_autofree_ldapmod(tc, mods);
2057 rc = smbldap_add(state, dn, mods);
2059 if (rc != LDAP_SUCCESS) {
2060 d_fprintf(stderr, _("Failed to add Guest user to "
2061 "ldap directory\n"));
2064 if (is_ipa) {
2065 if (!pdb_getsampwnam(samuser, lp_guest_account())) {
2066 d_fprintf(stderr, _("Failed to read just "
2067 "created user.\n"));
2068 goto failed;
2071 } else {
2072 d_printf(_("found!\n"));
2075 d_printf(_("Checking Guest's group.\n"));
2077 pwd = Get_Pwnam_alloc(tc, lp_guest_account());
2078 if (!pwd) {
2079 d_fprintf(stderr,
2080 _("Failed to find just created Guest account!\n"
2081 " Is nss properly configured?!\n"));
2082 goto failed;
2085 if (pwd->pw_gid == domusers_gid) {
2086 d_printf(_("found!\n"));
2087 goto done;
2090 if (!pdb_getgrgid(gmap, pwd->pw_gid)) {
2091 struct dom_sid_buf gsid_str;
2092 LDAPMod **mods = NULL;
2093 char *dn;
2094 char *uname;
2095 char *wname;
2096 char *gidstr;
2097 char *gtype;
2098 int rc;
2100 d_printf(_("Adding the Domain Guests group.\n"));
2102 uname = talloc_strdup(tc, "domguests");
2103 wname = talloc_strdup(tc, "Domain Guests");
2104 dn = talloc_asprintf(tc, "cn=%s,%s", "domguests",
2105 lp_ldap_group_suffix(talloc_tos()));
2106 gidstr = talloc_asprintf(tc, "%u", (unsigned int)pwd->pw_gid);
2107 gtype = talloc_asprintf(tc, "%d", SID_NAME_DOM_GRP);
2109 if (!uname || !wname || !dn || !gidstr || !gtype) {
2110 d_fprintf(stderr, _("Out of Memory!\n"));
2111 goto failed;
2114 sid_compose(&gsid, get_global_sam_sid(), DOMAIN_RID_GUESTS);
2116 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_POSIXGROUP);
2117 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
2118 if (is_ipa) {
2119 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "groupofnames");
2120 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "nestedgroup");
2121 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", "ipausergroup");
2123 smbldap_set_mod(&mods, LDAP_MOD_ADD, "cn", uname);
2124 smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", wname);
2125 smbldap_set_mod(&mods, LDAP_MOD_ADD, "gidNumber", gidstr);
2126 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid",
2127 dom_sid_str_buf(&gsid, &gsid_str));
2128 smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", gtype);
2130 smbldap_talloc_autofree_ldapmod(tc, mods);
2132 rc = smbldap_add(state, dn, mods);
2134 if (rc != LDAP_SUCCESS) {
2135 d_fprintf(stderr,
2136 _("Failed to add Domain Guests group to ldap "
2137 "directory\n"));
2139 } else {
2140 d_printf(_("found!\n"));
2144 done:
2145 talloc_free(state);
2146 return 0;
2148 failed:
2149 talloc_free(state);
2150 return -1;
2153 #endif
2155 /***********************************************************
2156 migrated functionality from smbgroupedit
2157 **********************************************************/
2158 int net_sam(struct net_context *c, int argc, const char **argv)
2160 struct functable func[] = {
2162 "createbuiltingroup",
2163 net_sam_createbuiltingroup,
2164 NET_TRANSPORT_LOCAL,
2165 N_("Create a new BUILTIN group"),
2166 N_("net sam createbuiltingroup\n"
2167 " Create a new BUILTIN group")
2170 "createlocalgroup",
2171 net_sam_createlocalgroup,
2172 NET_TRANSPORT_LOCAL,
2173 N_("Create a new local group"),
2174 N_("net sam createlocalgroup\n"
2175 " Create a new local group")
2178 "createdomaingroup",
2179 net_sam_createdomaingroup,
2180 NET_TRANSPORT_LOCAL,
2181 N_("Create a new group"),
2182 N_("net sam createdomaingroup\n"
2183 " Create a new group")
2186 "deletelocalgroup",
2187 net_sam_deletelocalgroup,
2188 NET_TRANSPORT_LOCAL,
2189 N_("Delete an existing local group"),
2190 N_("net sam deletelocalgroup\n"
2191 " Delete an existing local group")
2194 "deletedomaingroup",
2195 net_sam_deletedomaingroup,
2196 NET_TRANSPORT_LOCAL,
2197 N_("Delete a domain group"),
2198 N_("net sam deletedomaingroup\n"
2199 " Delete a group")
2202 "mapunixgroup",
2203 net_sam_mapunixgroup,
2204 NET_TRANSPORT_LOCAL,
2205 N_("Map a unix group to a domain group"),
2206 N_("net sam mapunixgroup\n"
2207 " Map a unix group to a domain group")
2210 "unmapunixgroup",
2211 net_sam_unmapunixgroup,
2212 NET_TRANSPORT_LOCAL,
2213 N_("Remove a group mapping of an unix group to a "
2214 "domain group"),
2215 N_("net sam unmapunixgroup\n"
2216 " Remove a group mapping of an unix group to a "
2217 "domain group")
2220 "addmem",
2221 net_sam_addmem,
2222 NET_TRANSPORT_LOCAL,
2223 N_("Add a member to a group"),
2224 N_("net sam addmem\n"
2225 " Add a member to a group")
2228 "delmem",
2229 net_sam_delmem,
2230 NET_TRANSPORT_LOCAL,
2231 N_("Delete a member from a group"),
2232 N_("net sam delmem\n"
2233 " Delete a member from a group")
2236 "listmem",
2237 net_sam_listmem,
2238 NET_TRANSPORT_LOCAL,
2239 N_("List group members"),
2240 N_("net sam listmem\n"
2241 " List group members")
2244 "list",
2245 net_sam_list,
2246 NET_TRANSPORT_LOCAL,
2247 N_("List users, groups and local groups"),
2248 N_("net sam list\n"
2249 " List users, groups and local groups")
2252 "show",
2253 net_sam_show,
2254 NET_TRANSPORT_LOCAL,
2255 N_("Show details of a SAM entry"),
2256 N_("net sam show\n"
2257 " Show details of a SAM entry")
2260 "set",
2261 net_sam_set,
2262 NET_TRANSPORT_LOCAL,
2263 N_("Set details of a SAM account"),
2264 N_("net sam set\n"
2265 " Set details of a SAM account")
2268 "policy",
2269 net_sam_policy,
2270 NET_TRANSPORT_LOCAL,
2271 N_("Set account policies"),
2272 N_("net sam policy\n"
2273 " Set account policies")
2276 "rights",
2277 net_sam_rights,
2278 NET_TRANSPORT_LOCAL,
2279 N_("Manipulate user privileges"),
2280 N_("net sam rights\n"
2281 " Manipulate user privileges")
2283 #ifdef HAVE_LDAP
2285 "provision",
2286 net_sam_provision,
2287 NET_TRANSPORT_LOCAL,
2288 N_("Provision a clean user database"),
2289 N_("net sam privison\n"
2290 " Provision a clear user database")
2292 #endif
2293 {NULL, NULL, 0, NULL, NULL}
2296 if (getuid() != 0) {
2297 d_fprintf(stderr, _("You are not root, most things won't "
2298 "work\n"));
2301 return net_run_function(c, argc, argv, "net sam", func);