~ubuntu-branches/ubuntu/maverick/samba/maverick-security

« back to all changes in this revision

Viewing changes to source/utils/net_rpc_service.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2009-05-18 13:26:04 UTC
  • mfrom: (0.28.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090518132604-ebyuqimgymtr3h0k
Tags: 2:3.3.4-2ubuntu1
* Merge from debian unstable, remaining changes:
  + debian/patches/VERSION.patch:
    - setup SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted (LP: #312449)
  + debian/mksambapasswd.awk:
    - Do not add user with UID less than 1000 to smbpasswd.
  + debian/control:
    - Make libwbclient0 replace/conflict with hardy's likewise-open.
    - Don't build against ctdb.
    - Add suggests keyutils for smbfs. (LP: #300221)
  + debian/rules:
    - enable "native" PIE hardening.
    - remove --with-ctdb and --with-cluster-support=yes
  + Add ufw integration:
    - Created debian/samba.ufw profile.
    - debian/rules, debian/samba.dirs, debian/samba.files: install 
      profile
    - debian/control: have samba sugguest ufw.
* Dropped patches:
  + debian/patches/fix-upstream-bug-6186.patch: Merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
582
582
/********************************************************************
583
583
********************************************************************/
584
584
 
 
585
static NTSTATUS rpc_service_delete_internal(struct net_context *c,
 
586
                                            const DOM_SID *domain_sid,
 
587
                                            const char *domain_name,
 
588
                                            struct cli_state *cli,
 
589
                                            struct rpc_pipe_client *pipe_hnd,
 
590
                                            TALLOC_CTX *mem_ctx,
 
591
                                            int argc,
 
592
                                            const char **argv)
 
593
{
 
594
        struct policy_handle hSCM, hService;
 
595
        WERROR result = WERR_GENERAL_FAILURE;
 
596
        NTSTATUS status;
 
597
 
 
598
        if (argc != 1 ) {
 
599
                d_printf("Usage: net rpc service delete <service>\n");
 
600
                return NT_STATUS_OK;
 
601
        }
 
602
 
 
603
        /* Open the Service Control Manager */
 
604
        status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
 
605
                                              pipe_hnd->srv_name_slash,
 
606
                                              NULL,
 
607
                                              SC_RIGHT_MGR_ENUMERATE_SERVICE,
 
608
                                              &hSCM,
 
609
                                              &result);
 
610
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
 
611
                d_fprintf(stderr, "Failed to open Service Control Manager.  [%s]\n",
 
612
                        win_errstr(result));
 
613
                return werror_to_ntstatus(result);
 
614
        }
 
615
 
 
616
        /* Open the Service */
 
617
 
 
618
        status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx,
 
619
                                            &hSCM,
 
620
                                            argv[0],
 
621
                                            SERVICE_ALL_ACCESS,
 
622
                                            &hService,
 
623
                                            &result);
 
624
 
 
625
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
 
626
                d_fprintf(stderr, "Failed to open service.  [%s]\n",
 
627
                        win_errstr(result));
 
628
                goto done;
 
629
        }
 
630
 
 
631
        /* Delete the Service */
 
632
 
 
633
        status = rpccli_svcctl_DeleteService(pipe_hnd, mem_ctx,
 
634
                                             &hService,
 
635
                                             &result);
 
636
 
 
637
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
 
638
                d_fprintf(stderr, "Delete service request failed.  [%s]\n",
 
639
                        win_errstr(result));
 
640
                goto done;
 
641
        }
 
642
 
 
643
        d_printf("Successfully deleted Service: %s\n", argv[0]);
 
644
 
 
645
 done:
 
646
        if (is_valid_policy_hnd(&hService)) {
 
647
                rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
 
648
        }
 
649
        if (is_valid_policy_hnd(&hSCM)) {
 
650
                rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
 
651
        }
 
652
 
 
653
        return werror_to_ntstatus(result);
 
654
}
 
655
 
 
656
/********************************************************************
 
657
********************************************************************/
 
658
 
 
659
static NTSTATUS rpc_service_create_internal(struct net_context *c,
 
660
                                            const DOM_SID *domain_sid,
 
661
                                            const char *domain_name,
 
662
                                            struct cli_state *cli,
 
663
                                            struct rpc_pipe_client *pipe_hnd,
 
664
                                            TALLOC_CTX *mem_ctx,
 
665
                                            int argc,
 
666
                                            const char **argv)
 
667
{
 
668
        struct policy_handle hSCM, hService;
 
669
        WERROR result = WERR_GENERAL_FAILURE;
 
670
        NTSTATUS status;
 
671
        const char *ServiceName;
 
672
        const char *DisplayName;
 
673
        const char *binary_path;
 
674
 
 
675
        if (argc != 3) {
 
676
                d_printf("Usage: net rpc service create <service> <displayname> <binarypath>\n");
 
677
                return NT_STATUS_OK;
 
678
        }
 
679
 
 
680
        /* Open the Service Control Manager */
 
681
        status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
 
682
                                              pipe_hnd->srv_name_slash,
 
683
                                              NULL,
 
684
                                              SC_RIGHT_MGR_CREATE_SERVICE,
 
685
                                              &hSCM,
 
686
                                              &result);
 
687
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
 
688
                d_fprintf(stderr, "Failed to open Service Control Manager.  [%s]\n",
 
689
                        win_errstr(result));
 
690
                return werror_to_ntstatus(result);
 
691
        }
 
692
 
 
693
        /* Create the service */
 
694
 
 
695
        ServiceName = argv[0];
 
696
        DisplayName = argv[1];
 
697
        binary_path = argv[2];
 
698
 
 
699
        status = rpccli_svcctl_CreateServiceW(pipe_hnd, mem_ctx,
 
700
                                              &hSCM,
 
701
                                              ServiceName,
 
702
                                              DisplayName,
 
703
                                              SERVICE_ALL_ACCESS,
 
704
                                              SERVICE_TYPE_WIN32_OWN_PROCESS,
 
705
                                              SVCCTL_DEMAND_START,
 
706
                                              SVCCTL_SVC_ERROR_NORMAL,
 
707
                                              binary_path,
 
708
                                              NULL, /* LoadOrderGroupKey */
 
709
                                              NULL, /* TagId */
 
710
                                              NULL, /* dependencies */
 
711
                                              0, /* dependencies_size */
 
712
                                              NULL, /* service_start_name */
 
713
                                              NULL, /* password */
 
714
                                              0, /* password_size */
 
715
                                              &hService,
 
716
                                              &result);
 
717
 
 
718
        if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) {
 
719
                d_fprintf(stderr, "Create service request failed.  [%s]\n",
 
720
                        win_errstr(result));
 
721
                goto done;
 
722
        }
 
723
 
 
724
        d_printf("Successfully created Service: %s\n", argv[0]);
 
725
 
 
726
 done:
 
727
        if (is_valid_policy_hnd(&hService)) {
 
728
                rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL);
 
729
        }
 
730
        if (is_valid_policy_hnd(&hSCM)) {
 
731
                rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);
 
732
        }
 
733
 
 
734
        return werror_to_ntstatus(result);
 
735
}
 
736
 
 
737
/********************************************************************
 
738
********************************************************************/
 
739
 
585
740
static int rpc_service_list(struct net_context *c, int argc, const char **argv )
586
741
{
587
742
        if (c->display_usage) {
678
833
/********************************************************************
679
834
********************************************************************/
680
835
 
 
836
static int rpc_service_delete(struct net_context *c, int argc, const char **argv)
 
837
{
 
838
        if (c->display_usage) {
 
839
                d_printf("Usage:\n"
 
840
                         "net rpc service delete <service>\n"
 
841
                         "    Delete a Win32 service\n");
 
842
                return 0;
 
843
        }
 
844
 
 
845
        return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0,
 
846
                rpc_service_delete_internal, argc, argv);
 
847
}
 
848
 
 
849
/********************************************************************
 
850
********************************************************************/
 
851
 
 
852
static int rpc_service_create(struct net_context *c, int argc, const char **argv)
 
853
{
 
854
        if (c->display_usage) {
 
855
                d_printf("Usage:\n"
 
856
                         "net rpc service create <service>\n"
 
857
                         "    Create a Win32 service\n");
 
858
                return 0;
 
859
        }
 
860
 
 
861
        return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0,
 
862
                rpc_service_create_internal, argc, argv);
 
863
}
 
864
 
 
865
/********************************************************************
 
866
********************************************************************/
 
867
 
681
868
int net_rpc_service(struct net_context *c, int argc, const char **argv)
682
869
{
683
870
        struct functable func[] = {
729
916
                        "net rpc service status\n"
730
917
                        "    View current status of a service"
731
918
                },
 
919
                {
 
920
                        "delete",
 
921
                        rpc_service_delete,
 
922
                        NET_TRANSPORT_RPC,
 
923
                        "Delete a service",
 
924
                        "net rpc service delete\n"
 
925
                        "    Deletes a service"
 
926
                },
 
927
                {
 
928
                        "create",
 
929
                        rpc_service_create,
 
930
                        NET_TRANSPORT_RPC,
 
931
                        "Create a service",
 
932
                        "net rpc service create\n"
 
933
                        "    Creates a service"
 
934
                },
 
935
 
732
936
                {NULL, NULL, 0, NULL, NULL}
733
937
        };
734
938