Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

Location:
vendor/current/source4/ntvfs/unixuid
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/ntvfs/unixuid/vfs_unixuid.c

    r740 r988  
    2929#define TEVENT_DEPRECATED
    3030#include <tevent.h>
    31 
    32 #if defined(UID_WRAPPER)
    33 #if !defined(UID_WRAPPER_REPLACE) && !defined(UID_WRAPPER_NOT_REPLACE)
    34 #define UID_WRAPPER_REPLACE
    35 #include "../uid_wrapper/uid_wrapper.h"
    36 #endif
    37 #else
    38 #define uwrap_enabled() 0
    39 #endif
    40 
     31#include "../lib/util/setid.h"
     32
     33NTSTATUS ntvfs_unixuid_init(void);
    4134
    4235struct unixuid_private {
    43         struct wbc_context *wbc_ctx;
    44         struct unix_sec_ctx *last_sec_ctx;
     36        struct security_unix_token *last_sec_ctx;
    4537        struct security_token *last_token;
    4638};
    4739
    4840
    49 
    50 struct unix_sec_ctx {
    51         uid_t uid;
    52         gid_t gid;
    53         unsigned int ngroups;
    54         gid_t *groups;
    55 };
    56 
    57 /*
    58   pull the current security context into a unix_sec_ctx
    59 */
    60 static struct unix_sec_ctx *save_unix_security(TALLOC_CTX *mem_ctx)
    61 {
    62         struct unix_sec_ctx *sec = talloc(mem_ctx, struct unix_sec_ctx);
     41/*
     42  pull the current security context into a security_unix_token
     43*/
     44static struct security_unix_token *save_unix_security(TALLOC_CTX *mem_ctx)
     45{
     46        struct security_unix_token *sec = talloc(mem_ctx, struct security_unix_token);
    6347        if (sec == NULL) {
    6448                return NULL;
     
    8670
    8771/*
    88   set the current security context from a unix_sec_ctx
    89 */
    90 static NTSTATUS set_unix_security(struct unix_sec_ctx *sec)
    91 {
    92         seteuid(0);
    93 
    94         if (setgroups(sec->ngroups, sec->groups) != 0) {
     72  set the current security context from a security_unix_token
     73*/
     74static NTSTATUS set_unix_security(struct security_unix_token *sec)
     75{
     76        samba_seteuid(0);
     77
     78        if (samba_setgroups(sec->ngroups, sec->groups) != 0) {
     79                DBG_ERR("*** samba_setgroups failed\n");
    9580                return NT_STATUS_ACCESS_DENIED;
    9681        }
    97         if (setegid(sec->gid) != 0) {
     82        if (samba_setegid(sec->gid) != 0) {
     83                DBG_ERR("*** samba_setegid(%u) failed\n", sec->gid);
    9884                return NT_STATUS_ACCESS_DENIED;
    9985        }
    100         if (seteuid(sec->uid) != 0) {
     86        if (samba_seteuid(sec->uid) != 0) {
     87                DBG_ERR("*** samba_seteuid(%u) failed\n", sec->uid);
    10188                return NT_STATUS_ACCESS_DENIED;
    10289        }
     
    117104                                      const char *location)
    118105{
    119         struct unix_sec_ctx *sec_ctx;
     106        struct security_unix_token *sec_ctx;
    120107
    121108        if (unixuid_nesting_level == 0) {
     
    131118                        return -1;
    132119                }
    133                 *(struct unix_sec_ctx **)stack_ptr = sec_ctx;
    134                 if (seteuid(0) != 0 || setegid(0) != 0) {
     120                *(struct security_unix_token **)stack_ptr = sec_ctx;
     121                if (samba_seteuid(0) != 0 || samba_setegid(0) != 0) {
    135122                        DEBUG(0,("%s: Failed to change to root\n", location));
    136123                        return -1;                     
     
    140127                NTSTATUS status;
    141128
    142                 sec_ctx = *(struct unix_sec_ctx **)stack_ptr;
     129                sec_ctx = *(struct security_unix_token **)stack_ptr;
    143130                if (sec_ctx == NULL) {
    144131                        /* this happens the first time this function
     
    148135                }
    149136
    150                 sec_ctx = talloc_get_type_abort(sec_ctx, struct unix_sec_ctx);
     137                sec_ctx = talloc_get_type_abort(sec_ctx, struct security_unix_token);
    151138                status = set_unix_security(sec_ctx);
    152139                talloc_free(sec_ctx);
     
    163150
    164151/*
    165   form a unix_sec_ctx from the current security_token
     152  form a security_unix_token from the current security_token
    166153*/
    167154static NTSTATUS nt_token_to_unix_security(struct ntvfs_module_context *ntvfs,
    168155                                          struct ntvfs_request *req,
    169156                                          struct security_token *token,
    170                                           struct unix_sec_ctx **sec)
    171 {
    172         struct unixuid_private *priv = ntvfs->private_data;
    173         int i;
    174         NTSTATUS status;
    175         struct id_map *ids;
    176         struct composite_context *ctx;
    177         *sec = talloc(req, struct unix_sec_ctx);
    178 
    179         /* we can't do unix security without a user and group */
    180         if (token->num_sids < 2) {
    181                 return NT_STATUS_ACCESS_DENIED;
    182         }
    183 
    184         ids = talloc_array(req, struct id_map, token->num_sids);
    185         NT_STATUS_HAVE_NO_MEMORY(ids);
    186 
    187         (*sec)->ngroups = token->num_sids - 2;
    188         (*sec)->groups = talloc_array(*sec, gid_t, (*sec)->ngroups);
    189         NT_STATUS_HAVE_NO_MEMORY((*sec)->groups);
    190 
    191         for (i=0;i<token->num_sids;i++) {
    192                 ZERO_STRUCT(ids[i].xid);
    193                 ids[i].sid = &token->sids[i];
    194                 ids[i].status = ID_UNKNOWN;
    195         }
    196 
    197         ctx = wbc_sids_to_xids_send(priv->wbc_ctx, ids, token->num_sids, ids);
    198         NT_STATUS_HAVE_NO_MEMORY(ctx);
    199 
    200         status = wbc_sids_to_xids_recv(ctx, &ids);
    201         NT_STATUS_NOT_OK_RETURN(status);
    202 
    203         if (ids[0].xid.type == ID_TYPE_BOTH ||
    204             ids[0].xid.type == ID_TYPE_UID) {
    205                 (*sec)->uid = ids[0].xid.id;
    206         } else {
    207                 return NT_STATUS_INVALID_SID;
    208         }
    209 
    210         if (ids[1].xid.type == ID_TYPE_BOTH ||
    211             ids[1].xid.type == ID_TYPE_GID) {
    212                 (*sec)->gid = ids[1].xid.id;
    213         } else {
    214                 return NT_STATUS_INVALID_SID;
    215         }
    216 
    217         for (i=0;i<(*sec)->ngroups;i++) {
    218                 if (ids[i+2].xid.type == ID_TYPE_BOTH ||
    219                     ids[i+2].xid.type == ID_TYPE_GID) {
    220                         (*sec)->groups[i] = ids[i+2].xid.id;
    221                 } else {
    222                         return NT_STATUS_INVALID_SID;
    223                 }
    224         }
    225 
    226         return NT_STATUS_OK;
     157                                          struct security_unix_token **sec)
     158{
     159        return security_token_to_unix_token(req,
     160                                            ntvfs->ctx->event_ctx,
     161                                            token, sec);
    227162}
    228163
     
    231166*/
    232167static NTSTATUS unixuid_setup_security(struct ntvfs_module_context *ntvfs,
    233                                        struct ntvfs_request *req, struct unix_sec_ctx **sec)
     168                                       struct ntvfs_request *req, struct security_unix_token **sec)
    234169{
    235170        struct unixuid_private *priv = ntvfs->private_data;
    236171        struct security_token *token;
    237         struct unix_sec_ctx *newsec;
     172        struct security_unix_token *newsec;
    238173        NTSTATUS status;
    239174
     
    282217#define PASS_THRU_REQ(ntvfs, req, op, args) do { \
    283218        NTSTATUS status2; \
    284         struct unix_sec_ctx *sec; \
     219        struct security_unix_token *sec; \
    285220        status = unixuid_setup_security(ntvfs, req, &sec); \
    286221        NT_STATUS_NOT_OK_RETURN(status); \
     
    309244        }
    310245
    311         priv->wbc_ctx = wbc_init(priv, ntvfs->ctx->msg_ctx,
    312                                     ntvfs->ctx->event_ctx);
    313         if (priv->wbc_ctx == NULL) {
    314                 talloc_free(priv);
    315                 return NT_STATUS_INTERNAL_ERROR;
    316         }
    317 
    318246        priv->last_sec_ctx = NULL;
    319247        priv->last_token = NULL;
     
    747675
    748676        /* fill in all the operations */
    749         ops.connect = unixuid_connect;
    750         ops.disconnect = unixuid_disconnect;
    751         ops.unlink = unixuid_unlink;
    752         ops.chkpath = unixuid_chkpath;
    753         ops.qpathinfo = unixuid_qpathinfo;
    754         ops.setpathinfo = unixuid_setpathinfo;
    755         ops.open = unixuid_open;
    756         ops.mkdir = unixuid_mkdir;
    757         ops.rmdir = unixuid_rmdir;
    758         ops.rename = unixuid_rename;
    759         ops.copy = unixuid_copy;
    760         ops.ioctl = unixuid_ioctl;
    761         ops.read = unixuid_read;
    762         ops.write = unixuid_write;
    763         ops.seek = unixuid_seek;
    764         ops.flush = unixuid_flush;     
    765         ops.close = unixuid_close;
    766         ops.exit = unixuid_exit;
    767         ops.lock = unixuid_lock;
    768         ops.setfileinfo = unixuid_setfileinfo;
    769         ops.qfileinfo = unixuid_qfileinfo;
    770         ops.fsinfo = unixuid_fsinfo;
    771         ops.lpq = unixuid_lpq;
    772         ops.search_first = unixuid_search_first;
    773         ops.search_next = unixuid_search_next;
    774         ops.search_close = unixuid_search_close;
    775         ops.trans = unixuid_trans;
    776         ops.logoff = unixuid_logoff;
    777         ops.async_setup = unixuid_async_setup;
    778         ops.cancel = unixuid_cancel;
    779         ops.notify = unixuid_notify;
     677        ops.connect_fn = unixuid_connect;
     678        ops.disconnect_fn = unixuid_disconnect;
     679        ops.unlink_fn = unixuid_unlink;
     680        ops.chkpath_fn = unixuid_chkpath;
     681        ops.qpathinfo_fn = unixuid_qpathinfo;
     682        ops.setpathinfo_fn = unixuid_setpathinfo;
     683        ops.open_fn = unixuid_open;
     684        ops.mkdir_fn = unixuid_mkdir;
     685        ops.rmdir_fn = unixuid_rmdir;
     686        ops.rename_fn = unixuid_rename;
     687        ops.copy_fn = unixuid_copy;
     688        ops.ioctl_fn = unixuid_ioctl;
     689        ops.read_fn = unixuid_read;
     690        ops.write_fn = unixuid_write;
     691        ops.seek_fn = unixuid_seek;
     692        ops.flush_fn = unixuid_flush;
     693        ops.close_fn = unixuid_close;
     694        ops.exit_fn = unixuid_exit;
     695        ops.lock_fn = unixuid_lock;
     696        ops.setfileinfo_fn = unixuid_setfileinfo;
     697        ops.qfileinfo_fn = unixuid_qfileinfo;
     698        ops.fsinfo_fn = unixuid_fsinfo;
     699        ops.lpq_fn = unixuid_lpq;
     700        ops.search_first_fn = unixuid_search_first;
     701        ops.search_next_fn = unixuid_search_next;
     702        ops.search_close_fn = unixuid_search_close;
     703        ops.trans_fn = unixuid_trans;
     704        ops.logoff_fn = unixuid_logoff;
     705        ops.async_setup_fn = unixuid_async_setup;
     706        ops.cancel_fn = unixuid_cancel;
     707        ops.notify_fn = unixuid_notify;
    780708
    781709        ops.name = "unixuid";
  • vendor/current/source4/ntvfs/unixuid/wscript_build

    r740 r988  
    55        subsystem='ntvfs',
    66        init_function='ntvfs_unixuid_init',
    7         deps='samdb'
     7        deps='auth_unix_token talloc'
    88        )
    99
Note: See TracChangeset for help on using the changeset viewer.