~ubuntu-branches/ubuntu/oneiric/samba/oneiric-security

« back to all changes in this revision

Viewing changes to source3/smbd/posix_acls.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-03-10 10:03:01 UTC
  • mfrom: (0.39.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110310100301-jfjg41wv0iq05zj4
Tags: 2:3.5.8~dfsg-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set 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/mksmbpasswd.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 or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
    - Add cuups breaks to push the package to aslo upgrade cups (LP: #639768)
  + debian/rules:
    - enable "native" PIE hardening.
    - Add BIND_NOW to maximize benefit of RELRO hardening.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
    - Don't ship the /etc/network/if-up.d file.
  + debian/samba.postinst: 
    - Fixed bashism.
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/samba.logrotate: Make it upstart compatible
  + debian/samba-common.dhcp: Fix typo to get a proper parsing in
    /etc/samba/dhcp.
  + Dropped:
    - debian/patches/fix-windows7-print-connection.patch: Merged upstream.
    - debian/patches/security-CVE-2011-0719.patch: Merged upstream. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1748
1748
                                continue;
1749
1749
                        }
1750
1750
 
 
1751
                        if (lp_force_unknown_acl_user(SNUM(fsp->conn))) {
 
1752
                                DEBUG(10, ("create_canon_ace_lists: ignoring "
 
1753
                                        "unknown or foreign SID %s\n",
 
1754
                                        sid_string_dbg(&psa->trustee)));
 
1755
                                        SAFE_FREE(current_ace);
 
1756
                                continue;
 
1757
                        }
 
1758
 
1751
1759
                        free_canon_ace_list(file_ace);
1752
1760
                        free_canon_ace_list(dir_ace);
1753
1761
                        DEBUG(0, ("create_canon_ace_lists: unable to map SID "
3591
3599
                return -1;
3592
3600
        }
3593
3601
 
3594
 
        if (!NT_STATUS_IS_OK(open_file_fchmod(NULL, conn, smb_fname, &fsp))) {
 
3602
        if (!NT_STATUS_IS_OK(open_file_fchmod(conn, smb_fname, &fsp))) {
3595
3603
                return -1;
3596
3604
        }
3597
3605
 
3610
3618
        }
3611
3619
        unbecome_root();
3612
3620
 
3613
 
        close_file_fchmod(NULL, fsp);
 
3621
        close_file(NULL, fsp, NORMAL_CLOSE);
3614
3622
 
3615
3623
        return ret;
3616
3624
}
3822
3830
 This should be the only external function needed for the UNIX style set ACL.
3823
3831
****************************************************************************/
3824
3832
 
3825
 
NTSTATUS set_nt_acl(files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
 
3833
NTSTATUS set_nt_acl(files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd_orig)
3826
3834
{
3827
3835
        connection_struct *conn = fsp->conn;
3828
3836
        uid_t user = (uid_t)-1;
3837
3845
        bool set_acl_as_root = false;
3838
3846
        bool acl_set_support = false;
3839
3847
        bool ret = false;
 
3848
        SEC_DESC *psd = NULL;
3840
3849
 
3841
3850
        DEBUG(10,("set_nt_acl: called for file %s\n",
3842
3851
                  fsp_str_dbg(fsp)));
3846
3855
                return NT_STATUS_MEDIA_WRITE_PROTECTED;
3847
3856
        }
3848
3857
 
 
3858
        if (!psd_orig) {
 
3859
                return NT_STATUS_INVALID_PARAMETER;
 
3860
        }
 
3861
 
 
3862
        psd = dup_sec_desc(talloc_tos(), psd_orig);
 
3863
        if (!psd) {
 
3864
                return NT_STATUS_NO_MEMORY;
 
3865
        }
 
3866
 
3849
3867
        /*
3850
3868
         * Get the current state of the file.
3851
3869
         */
3862
3880
         * Unpack the user/group/world id's.
3863
3881
         */
3864
3882
 
 
3883
        /* POSIX can't cope with missing owner/group. */
 
3884
        if ((security_info_sent & SECINFO_OWNER) && (psd->owner_sid == NULL)) {
 
3885
                security_info_sent &= ~SECINFO_OWNER;
 
3886
        }
 
3887
        if ((security_info_sent & SECINFO_GROUP) && (psd->group_sid == NULL)) {
 
3888
                security_info_sent &= ~SECINFO_GROUP;
 
3889
        }
 
3890
 
3865
3891
        status = unpack_nt_owners( SNUM(conn), &user, &grp, security_info_sent, psd);
3866
3892
        if (!NT_STATUS_IS_OK(status)) {
3867
3893
                return status;
3912
3938
 
3913
3939
        create_file_sids(&fsp->fsp_name->st, &file_owner_sid, &file_grp_sid);
3914
3940
 
 
3941
        if((security_info_sent & SECINFO_DACL) &&
 
3942
                        (psd->type & SEC_DESC_DACL_PRESENT) &&
 
3943
                        (psd->dacl == NULL)) {
 
3944
                SEC_ACE ace[3];
 
3945
 
 
3946
                /* We can't have NULL DACL in POSIX.
 
3947
                   Use owner/group/Everyone -> full access. */
 
3948
 
 
3949
                init_sec_ace(&ace[0],
 
3950
                                &file_owner_sid,
 
3951
                                SEC_ACE_TYPE_ACCESS_ALLOWED,
 
3952
                                GENERIC_ALL_ACCESS,
 
3953
                                0);
 
3954
                init_sec_ace(&ace[1],
 
3955
                                &file_grp_sid,
 
3956
                                SEC_ACE_TYPE_ACCESS_ALLOWED,
 
3957
                                GENERIC_ALL_ACCESS,
 
3958
                                0);
 
3959
                init_sec_ace(&ace[2],
 
3960
                                &global_sid_World,
 
3961
                                SEC_ACE_TYPE_ACCESS_ALLOWED,
 
3962
                                GENERIC_ALL_ACCESS,
 
3963
                                0);
 
3964
                psd->dacl = make_sec_acl(talloc_tos(),
 
3965
                                        NT4_ACL_REVISION,
 
3966
                                        3,
 
3967
                                        ace);
 
3968
                if (psd->dacl == NULL) {
 
3969
                        return NT_STATUS_NO_MEMORY;
 
3970
                }
 
3971
                security_acl_map_generic(psd->dacl, &file_generic_mapping);
 
3972
        }
 
3973
 
3915
3974
        acl_perms = unpack_canon_ace(fsp, &fsp->fsp_name->st, &file_owner_sid,
3916
3975
                                     &file_grp_sid, &file_ace_list,
3917
3976
                                     &dir_ace_list, security_info_sent, psd);
4756
4815
 
4757
4816
        return ret_sd;
4758
4817
}
 
4818
 
 
4819
/* Stolen shamelessly from pvfs_default_acl() in source4 :-). */
 
4820
 
 
4821
NTSTATUS make_default_filesystem_acl(TALLOC_CTX *ctx,
 
4822
                                        const char *name,
 
4823
                                        SMB_STRUCT_STAT *psbuf,
 
4824
                                        SEC_DESC **ppdesc)
 
4825
{
 
4826
        struct dom_sid owner_sid, group_sid;
 
4827
        size_t size = 0;
 
4828
        SEC_ACE aces[4];
 
4829
        uint32_t access_mask = 0;
 
4830
        mode_t mode = psbuf->st_ex_mode;
 
4831
        SEC_ACL *new_dacl = NULL;
 
4832
        int idx = 0;
 
4833
 
 
4834
        DEBUG(10,("make_default_filesystem_acl: file %s mode = 0%o\n",
 
4835
                name, (int)mode ));
 
4836
 
 
4837
        uid_to_sid(&owner_sid, psbuf->st_ex_uid);
 
4838
        gid_to_sid(&group_sid, psbuf->st_ex_gid);
 
4839
 
 
4840
        /*
 
4841
         We provide up to 4 ACEs
 
4842
                - Owner
 
4843
                - Group
 
4844
                - Everyone
 
4845
                - NT System
 
4846
        */
 
4847
 
 
4848
        if (mode & S_IRUSR) {
 
4849
                if (mode & S_IWUSR) {
 
4850
                        access_mask |= SEC_RIGHTS_FILE_ALL;
 
4851
                } else {
 
4852
                        access_mask |= SEC_RIGHTS_FILE_READ | SEC_FILE_EXECUTE;
 
4853
                }
 
4854
        }
 
4855
        if (mode & S_IWUSR) {
 
4856
                access_mask |= SEC_RIGHTS_FILE_WRITE | SEC_STD_DELETE;
 
4857
        }
 
4858
 
 
4859
        init_sec_ace(&aces[idx],
 
4860
                        &owner_sid,
 
4861
                        SEC_ACE_TYPE_ACCESS_ALLOWED,
 
4862
                        access_mask,
 
4863
                        0);
 
4864
        idx++;
 
4865
 
 
4866
        access_mask = 0;
 
4867
        if (mode & S_IRGRP) {
 
4868
                access_mask |= SEC_RIGHTS_FILE_READ | SEC_FILE_EXECUTE;
 
4869
        }
 
4870
        if (mode & S_IWGRP) {
 
4871
                /* note that delete is not granted - this matches posix behaviour */
 
4872
                access_mask |= SEC_RIGHTS_FILE_WRITE;
 
4873
        }
 
4874
        if (access_mask) {
 
4875
                init_sec_ace(&aces[idx],
 
4876
                        &group_sid,
 
4877
                        SEC_ACE_TYPE_ACCESS_ALLOWED,
 
4878
                        access_mask,
 
4879
                        0);
 
4880
                idx++;
 
4881
        }
 
4882
 
 
4883
        access_mask = 0;
 
4884
        if (mode & S_IROTH) {
 
4885
                access_mask |= SEC_RIGHTS_FILE_READ | SEC_FILE_EXECUTE;
 
4886
        }
 
4887
        if (mode & S_IWOTH) {
 
4888
                access_mask |= SEC_RIGHTS_FILE_WRITE;
 
4889
        }
 
4890
        if (access_mask) {
 
4891
                init_sec_ace(&aces[idx],
 
4892
                        &global_sid_World,
 
4893
                        SEC_ACE_TYPE_ACCESS_ALLOWED,
 
4894
                        access_mask,
 
4895
                        0);
 
4896
                idx++;
 
4897
        }
 
4898
 
 
4899
        init_sec_ace(&aces[idx],
 
4900
                        &global_sid_System,
 
4901
                        SEC_ACE_TYPE_ACCESS_ALLOWED,
 
4902
                        SEC_RIGHTS_FILE_ALL,
 
4903
                        0);
 
4904
        idx++;
 
4905
 
 
4906
        new_dacl = make_sec_acl(ctx,
 
4907
                        NT4_ACL_REVISION,
 
4908
                        idx,
 
4909
                        aces);
 
4910
 
 
4911
        if (!new_dacl) {
 
4912
                return NT_STATUS_NO_MEMORY;
 
4913
        }
 
4914
 
 
4915
        *ppdesc = make_sec_desc(ctx,
 
4916
                        SECURITY_DESCRIPTOR_REVISION_1,
 
4917
                        SEC_DESC_SELF_RELATIVE|SEC_DESC_DACL_PRESENT,
 
4918
                        &owner_sid,
 
4919
                        &group_sid,
 
4920
                        NULL,
 
4921
                        new_dacl,
 
4922
                        &size);
 
4923
        if (!*ppdesc) {
 
4924
                return NT_STATUS_NO_MEMORY;
 
4925
        }
 
4926
        return NT_STATUS_OK;
 
4927
}