~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/rpc_server/srv_srvsvc_nt.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#undef DBGC_CLASS
30
30
#define DBGC_CLASS DBGC_RPC_SRV
31
31
 
32
 
#define INVALID_SHARENAME_CHARS "<>*?|/\\+=;:\","
33
 
 
34
 
/********************************************************************
35
 
 Check a string for any occurrences of a specified list of invalid 
36
 
 characters.
37
 
********************************************************************/
38
 
 
39
 
static BOOL validate_net_name( const char *name, const char *invalid_chars, int max_len )
40
 
{
41
 
        int i;
42
 
 
43
 
        for ( i=0; i<max_len && name[i]; i++ ) {
44
 
                /* fail if strchr_m() finds one of the invalid characters */
45
 
                if ( name[i] && strchr_m( invalid_chars, name[i] ) )
46
 
                        return False;
47
 
        }
48
 
 
49
 
        return True;
50
 
}
51
 
 
52
32
/*******************************************************************
53
33
 Utility function to get the 'type' of a share from an snum.
54
34
 ********************************************************************/
132
112
}
133
113
 
134
114
/*******************************************************************
135
 
 What to do when smb.conf is updated.
136
 
 ********************************************************************/
137
 
 
138
 
static void smb_conf_updated(int msg_type, struct process_id src,
139
 
                             void *buf, size_t len)
140
 
{
141
 
        DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n"));
142
 
        reload_services(False);
143
 
}
144
 
 
145
 
/*******************************************************************
146
 
 Create the share security tdb.
147
 
 ********************************************************************/
148
 
 
149
 
static TDB_CONTEXT *share_tdb; /* used for share security descriptors */
150
 
#define SHARE_DATABASE_VERSION_V1 1
151
 
#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
152
 
 
153
 
BOOL share_info_db_init(void)
154
 
{
155
 
        static pid_t local_pid;
156
 
        const char *vstring = "INFO/version";
157
 
        int32 vers_id;
158
 
 
159
 
        if (share_tdb && local_pid == sys_getpid())
160
 
                return True;
161
 
        share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
162
 
        if (!share_tdb) {
163
 
                DEBUG(0,("Failed to open share info database %s (%s)\n",
164
 
                        lock_path("share_info.tdb"), strerror(errno) ));
165
 
                return False;
166
 
        }
167
 
 
168
 
        local_pid = sys_getpid();
169
 
 
170
 
        /* handle a Samba upgrade */
171
 
        tdb_lock_bystring(share_tdb, vstring, 0);
172
 
 
173
 
        /* Cope with byte-reversed older versions of the db. */
174
 
        vers_id = tdb_fetch_int32(share_tdb, vstring);
175
 
        if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
176
 
                /* Written on a bigendian machine with old fetch_int code. Save as le. */
177
 
                tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
178
 
                vers_id = SHARE_DATABASE_VERSION_V2;
179
 
        }
180
 
 
181
 
        if (vers_id != SHARE_DATABASE_VERSION_V2) {
182
 
                tdb_traverse(share_tdb, tdb_traverse_delete_fn, NULL);
183
 
                tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
184
 
        }
185
 
        tdb_unlock_bystring(share_tdb, vstring);
186
 
 
187
 
        message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated);
188
 
 
189
 
        return True;
190
 
}
191
 
 
192
 
/*******************************************************************
193
 
 Fake up a Everyone, full access as a default.
194
 
 ********************************************************************/
195
 
 
196
 
static SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, int snum, size_t *psize)
197
 
{
198
 
        SEC_ACCESS sa;
199
 
        SEC_ACE ace;
200
 
        SEC_ACL *psa = NULL;
201
 
        SEC_DESC *psd = NULL;
202
 
        uint32 def_access = GENERIC_ALL_ACCESS;
203
 
 
204
 
        se_map_generic(&def_access, &file_generic_mapping);
205
 
 
206
 
        init_sec_access(&sa, GENERIC_ALL_ACCESS | def_access );
207
 
        init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
208
 
 
209
 
        if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &ace)) != NULL) {
210
 
                psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, psa, psize);
211
 
        }
212
 
 
213
 
        if (!psd) {
214
 
                DEBUG(0,("get_share_security: Failed to make SEC_DESC.\n"));
215
 
                return NULL;
216
 
        }
217
 
 
218
 
        return psd;
219
 
}
220
 
 
221
 
/*******************************************************************
222
 
 Pull a security descriptor from the share tdb.
223
 
 ********************************************************************/
224
 
 
225
 
static SEC_DESC *get_share_security( TALLOC_CTX *ctx, int snum, size_t *psize)
226
 
{
227
 
        prs_struct ps;
228
 
        fstring key;
229
 
        SEC_DESC *psd = NULL;
230
 
 
231
 
        *psize = 0;
232
 
 
233
 
        /* Fetch security descriptor from tdb */
234
 
 
235
 
        slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
236
 
 
237
 
        if (tdb_prs_fetch(share_tdb, key, &ps, ctx)!=0 ||
238
 
                !sec_io_desc("get_share_security", &psd, &ps, 1)) {
239
 
 
240
 
                DEBUG(4,("get_share_security: using default secdesc for %s\n", lp_servicename(snum) ));
241
 
 
242
 
                return get_share_security_default(ctx, snum, psize);
243
 
        }
244
 
 
245
 
        if (psd)
246
 
                *psize = sec_desc_size(psd);
247
 
 
248
 
        prs_mem_free(&ps);
249
 
        return psd;
250
 
}
251
 
 
252
 
/*******************************************************************
253
 
 Store a security descriptor in the share db.
254
 
 ********************************************************************/
255
 
 
256
 
static BOOL set_share_security(TALLOC_CTX *ctx, const char *share_name, SEC_DESC *psd)
257
 
{
258
 
        prs_struct ps;
259
 
        TALLOC_CTX *mem_ctx = NULL;
260
 
        fstring key;
261
 
        BOOL ret = False;
262
 
 
263
 
        mem_ctx = talloc_init("set_share_security");
264
 
        if (mem_ctx == NULL)
265
 
                return False;
266
 
 
267
 
        prs_init(&ps, (uint32)sec_desc_size(psd), mem_ctx, MARSHALL);
268
 
 
269
 
        if (!sec_io_desc("share_security", &psd, &ps, 1))
270
 
                goto out;
271
 
 
272
 
        slprintf(key, sizeof(key)-1, "SECDESC/%s", share_name);
273
 
 
274
 
        if (tdb_prs_store(share_tdb, key, &ps)==0) {
275
 
                ret = True;
276
 
                DEBUG(5,("set_share_security: stored secdesc for %s\n", share_name ));
277
 
        } else {
278
 
                DEBUG(1,("set_share_security: Failed to store secdesc for %s\n", share_name ));
279
 
        } 
280
 
 
281
 
        /* Free malloc'ed memory */
282
 
 
283
 
out:
284
 
 
285
 
        prs_mem_free(&ps);
286
 
        if (mem_ctx)
287
 
                talloc_destroy(mem_ctx);
288
 
        return ret;
289
 
}
290
 
 
291
 
/*******************************************************************
292
 
 Delete a security descriptor.
293
 
********************************************************************/
294
 
 
295
 
static BOOL delete_share_security(int snum)
296
 
{
297
 
        TDB_DATA kbuf;
298
 
        fstring key;
299
 
 
300
 
        slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
301
 
        kbuf.dptr = key;
302
 
        kbuf.dsize = strlen(key)+1;
303
 
 
304
 
        if (tdb_delete(share_tdb, kbuf) != 0) {
305
 
                DEBUG(0,("delete_share_security: Failed to delete entry for share %s\n",
306
 
                                lp_servicename(snum) ));
307
 
                return False;
308
 
        }
309
 
 
310
 
        return True;
311
 
}
312
 
 
313
 
/*******************************************************************
314
115
 Map any generic bits to file specific bits.
315
116
********************************************************************/
316
117
 
317
 
void map_generic_share_sd_bits(SEC_DESC *psd)
 
118
static void map_generic_share_sd_bits(SEC_DESC *psd)
318
119
{
319
120
        int i;
320
121
        SEC_ACL *ps_dacl = NULL;
517
318
               uint32 info_level, uint32 *resume_hnd, uint32 *total_entries, BOOL all_shares)
518
319
{
519
320
        int num_entries = 0;
520
 
        int num_services = lp_numservices();
 
321
        int num_services = 0;
521
322
        int snum;
522
323
        TALLOC_CTX *ctx = p->mem_ctx;
523
324
 
528
329
        ctr->info_level = ctr->switch_value = info_level;
529
330
        *resume_hnd = 0;
530
331
 
 
332
        /* Ensure all the usershares are loaded. */
 
333
        become_root();
 
334
        num_services = load_usershare_shares();
 
335
        unbecome_root();
 
336
 
531
337
        /* Count the number of entries. */
532
338
        for (snum = 0; snum < num_services; snum++) {
533
339
                if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) )
847
653
        (*stot) = list_sessions(&session_list);
848
654
 
849
655
        if (ss0 == NULL) {
850
 
                (*snum) = 0;
 
656
                if (snum) {
 
657
                        (*snum) = 0;
 
658
                }
851
659
                SAFE_FREE(session_list);
852
660
                return;
853
661
        }
940
748
                
941
749
                (*stot) = 0;
942
750
        }
 
751
 
 
752
        SAFE_FREE(session_list);
943
753
}
944
754
 
945
755
/*******************************************************************
1401
1211
 
1402
1212
        /* fail out now if you are not root or not a domain admin */
1403
1213
 
1404
 
        if ((user.uid != sec_initial_uid()) && 
 
1214
        if ((user.ut.uid != sec_initial_uid()) && 
1405
1215
                ( ! nt_token_check_domain_rid(p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS))) {
1406
1216
 
1407
1217
                goto done;
1412
1222
                if ((strequal(session_list[snum].username, username) || username[0] == '\0' ) &&
1413
1223
                    strequal(session_list[snum].remote_machine, machine)) {
1414
1224
                
1415
 
                        if (user.uid != sec_initial_uid()) {
 
1225
                        if (user.ut.uid != sec_initial_uid()) {
1416
1226
                                not_root = True;
1417
1227
                                become_root();
1418
1228
                        }
1572
1382
        
1573
1383
        /* fail out now if you are not root and not a disk op */
1574
1384
        
1575
 
        if ( user.uid != sec_initial_uid() && !is_disk_op )
 
1385
        if ( user.ut.uid != sec_initial_uid() && !is_disk_op )
1576
1386
                return WERR_ACCESS_DENIED;
1577
1387
 
1578
1388
        switch (q_u->info_level) {
1739
1549
 
1740
1550
        is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
1741
1551
 
1742
 
        if (user.uid != sec_initial_uid()  && !is_disk_op ) 
 
1552
        if (user.ut.uid != sec_initial_uid()  && !is_disk_op ) 
1743
1553
                return WERR_ACCESS_DENIED;
1744
1554
 
1745
1555
        if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {
1906
1716
 
1907
1717
        is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
1908
1718
 
1909
 
        if (user.uid != sec_initial_uid()  && !is_disk_op ) 
 
1719
        if (user.ut.uid != sec_initial_uid()  && !is_disk_op ) 
1910
1720
                return WERR_ACCESS_DENIED;
1911
1721
 
1912
1722
        if (!lp_delete_share_cmd() || !*lp_delete_share_cmd()) {
2098
1908
 
2099
1909
        psd->dacl->revision = (uint16) NT4_ACL_REVISION;
2100
1910
 
2101
 
        close_file(fsp, True);
 
1911
        close_file(fsp, NORMAL_CLOSE);
2102
1912
        unbecome_user();
2103
1913
        close_cnum(conn, user.vuid);
2104
1914
        return r_u->status;
2106
1916
error_exit:
2107
1917
 
2108
1918
        if(fsp) {
2109
 
                close_file(fsp, True);
 
1919
                close_file(fsp, NORMAL_CLOSE);
2110
1920
        }
2111
1921
 
2112
1922
        if (became_user)
2207
2017
                goto error_exit;
2208
2018
        }
2209
2019
 
2210
 
        close_file(fsp, True);
 
2020
        close_file(fsp, NORMAL_CLOSE);
2211
2021
        unbecome_user();
2212
2022
        close_cnum(conn, user.vuid);
2213
2023
        return r_u->status;
2215
2025
error_exit:
2216
2026
 
2217
2027
        if(fsp) {
2218
 
                close_file(fsp, True);
 
2028
                close_file(fsp, NORMAL_CLOSE);
2219
2029
        }
2220
2030
 
2221
2031
        if (became_user) {