Changeset 988 for vendor/current/source4/ntvfs/unixuid
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/source4/ntvfs/unixuid
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/ntvfs/unixuid/vfs_unixuid.c
r740 r988 29 29 #define TEVENT_DEPRECATED 30 30 #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 33 NTSTATUS ntvfs_unixuid_init(void); 41 34 42 35 struct unixuid_private { 43 struct wbc_context *wbc_ctx; 44 struct unix_sec_ctx *last_sec_ctx; 36 struct security_unix_token *last_sec_ctx; 45 37 struct security_token *last_token; 46 38 }; 47 39 48 40 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 */ 44 static 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); 63 47 if (sec == NULL) { 64 48 return NULL; … … 86 70 87 71 /* 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 */ 74 static 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"); 95 80 return NT_STATUS_ACCESS_DENIED; 96 81 } 97 if (setegid(sec->gid) != 0) { 82 if (samba_setegid(sec->gid) != 0) { 83 DBG_ERR("*** samba_setegid(%u) failed\n", sec->gid); 98 84 return NT_STATUS_ACCESS_DENIED; 99 85 } 100 if (seteuid(sec->uid) != 0) { 86 if (samba_seteuid(sec->uid) != 0) { 87 DBG_ERR("*** samba_seteuid(%u) failed\n", sec->uid); 101 88 return NT_STATUS_ACCESS_DENIED; 102 89 } … … 117 104 const char *location) 118 105 { 119 struct unix_sec_ctx*sec_ctx;106 struct security_unix_token *sec_ctx; 120 107 121 108 if (unixuid_nesting_level == 0) { … … 131 118 return -1; 132 119 } 133 *(struct unix_sec_ctx**)stack_ptr = sec_ctx;134 if (s eteuid(0) != 0 ||setegid(0) != 0) {120 *(struct security_unix_token **)stack_ptr = sec_ctx; 121 if (samba_seteuid(0) != 0 || samba_setegid(0) != 0) { 135 122 DEBUG(0,("%s: Failed to change to root\n", location)); 136 123 return -1; … … 140 127 NTSTATUS status; 141 128 142 sec_ctx = *(struct unix_sec_ctx**)stack_ptr;129 sec_ctx = *(struct security_unix_token **)stack_ptr; 143 130 if (sec_ctx == NULL) { 144 131 /* this happens the first time this function … … 148 135 } 149 136 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); 151 138 status = set_unix_security(sec_ctx); 152 139 talloc_free(sec_ctx); … … 163 150 164 151 /* 165 form a unix_sec_ctxfrom the current security_token152 form a security_unix_token from the current security_token 166 153 */ 167 154 static NTSTATUS nt_token_to_unix_security(struct ntvfs_module_context *ntvfs, 168 155 struct ntvfs_request *req, 169 156 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); 227 162 } 228 163 … … 231 166 */ 232 167 static 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) 234 169 { 235 170 struct unixuid_private *priv = ntvfs->private_data; 236 171 struct security_token *token; 237 struct unix_sec_ctx*newsec;172 struct security_unix_token *newsec; 238 173 NTSTATUS status; 239 174 … … 282 217 #define PASS_THRU_REQ(ntvfs, req, op, args) do { \ 283 218 NTSTATUS status2; \ 284 struct unix_sec_ctx*sec; \219 struct security_unix_token *sec; \ 285 220 status = unixuid_setup_security(ntvfs, req, &sec); \ 286 221 NT_STATUS_NOT_OK_RETURN(status); \ … … 309 244 } 310 245 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 318 246 priv->last_sec_ctx = NULL; 319 247 priv->last_token = NULL; … … 747 675 748 676 /* 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; 780 708 781 709 ops.name = "unixuid"; -
vendor/current/source4/ntvfs/unixuid/wscript_build
r740 r988 5 5 subsystem='ntvfs', 6 6 init_function='ntvfs_unixuid_init', 7 deps=' samdb'7 deps='auth_unix_token talloc' 8 8 ) 9 9
Note:
See TracChangeset
for help on using the changeset viewer.