The FSF has moved around a lot. This fixes their Mass Ave address.
[metze/old/v3-2-winbind-ndr.git] / source / rpc_server / srv_srvsvc_nt.c
index 615f5e1b073b58ffeedc7f8557bc0ed23fa7c06f..ed32f6a765c4d8e544d6619a5f54bf5b6b8de5c8 100644 (file)
@@ -9,7 +9,7 @@
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
  *  
  *  This program is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
  *  GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /* This is the implementation of the srvsvc pipe. */
@@ -43,7 +42,7 @@ struct file_enum_count {
 };
 
 struct sess_file_count {
-       pid_t pid;
+       struct server_id pid;
        uid_t uid;
        int count;
 };
@@ -52,15 +51,15 @@ struct sess_file_count {
  Count the entries belonging to a service in the connection db.
 ****************************************************************************/
 
-static int pipe_enum_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *p)
+static int pipe_enum_fn( struct db_record *rec, void *p)
 {
        struct pipe_open_rec prec;
        struct file_enum_count *fenum = (struct file_enum_count *)p;
  
-       if (dbuf.dsize != sizeof(struct pipe_open_rec))
+       if (rec->value.dsize != sizeof(struct pipe_open_rec))
                return 0;
 
-       memcpy(&prec, dbuf.dptr, sizeof(struct pipe_open_rec));
+       memcpy(&prec, rec->value.dptr, sizeof(struct pipe_open_rec));
  
        if ( process_exists(prec.pid) ) {
                struct srvsvc_NetFileInfo3 *f;
@@ -104,39 +103,32 @@ static WERROR net_enum_pipes( TALLOC_CTX *ctx, struct srvsvc_NetFileInfo3 **info
                               uint32 *count, uint32 *resume )
 {
        struct file_enum_count fenum;
-       TDB_CONTEXT *conn_tdb = conn_tdb_ctx();
 
-       if ( !conn_tdb ) {
-               DEBUG(0,("net_enum_pipes: Failed to retrieve the connections tdb handle!\n"));
-               return WERR_ACCESS_DENIED;
-       }
-       
        fenum.ctx = ctx;
        fenum.info = *info;
        fenum.count = *count;
 
-       if (tdb_traverse(conn_tdb, pipe_enum_fn, &fenum) == -1) {
-               DEBUG(0,("net_enum_pipes: traverse of connections.tdb failed with error %s.\n",
-                       tdb_errorstr(conn_tdb) ));
+       if (connections_traverse(pipe_enum_fn, &fenum) == -1) {
+               DEBUG(0,("net_enum_pipes: traverse of connections.tdb "
+                        "failed\n"));
                return WERR_NOMEM;
        }
        
        *info  = fenum.info;
        *count = fenum.count;
        
-       return WERR_OK;}
+       return WERR_OK;
+}
 
 /*******************************************************************
 ********************************************************************/
 
-/* global needed to make use of the share_mode_forall() callback */
-static struct file_enum_count f_enum_cnt;
-
 static void enum_file_fn( const struct share_mode_entry *e, 
                           const char *sharepath, const char *fname,
-                         void *dummy )
+                         void *private_data )
 {
-       struct file_enum_count *fenum = &f_enum_cnt;
+       struct file_enum_count *fenum =
+               (struct file_enum_count *)&private_data;
  
        /* If the pid was not found delete the entry from connections.tdb */
 
@@ -159,8 +151,7 @@ static void enum_file_fn( const struct share_mode_entry *e,
                /* need to count the number of locks on a file */
                
                ZERO_STRUCT( fsp );             
-               fsp.dev   = e->dev;
-               fsp.inode = e->inode;
+               fsp.file_id = e->id;
                
                if ( (brl = brl_get_locks_readonly(NULL,&fsp)) != NULL ) {
                        num_locks = brl->num_locks;
@@ -204,11 +195,13 @@ static void enum_file_fn( const struct share_mode_entry *e,
 static WERROR net_enum_files( TALLOC_CTX *ctx, struct srvsvc_NetFileInfo3 **info, 
                               uint32 *count, uint32 *resume )
 {
+       struct file_enum_count f_enum_cnt;
+
        f_enum_cnt.ctx = ctx;
        f_enum_cnt.count = *count;
        f_enum_cnt.info = *info;
        
-       share_mode_forall( enum_file_fn, NULL );
+       share_mode_forall( enum_file_fn, (void *)&f_enum_cnt );
        
        *info  = f_enum_cnt.info;
        *count = f_enum_cnt.count;
@@ -544,61 +537,61 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
 
        switch (info_level) {
        case 0:
-               if (!(ctr->ctr0 = talloc_zero(
+               if (!(ctr->ctr0 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr0))) {
                        goto done;
                }
                break;
        case 1:
-               if (!(ctr->ctr1 = talloc_zero(
+               if (!(ctr->ctr1 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr1))) {
                        goto done;
                }
                break;
        case 2:
-               if (!(ctr->ctr2 = talloc_zero(
+               if (!(ctr->ctr2 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr2))) {
                        goto done;
                }
                break;
        case 501:
-               if (!(ctr->ctr501 = talloc_zero(
+               if (!(ctr->ctr501 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr501))) {
                        goto done;
                }
                break;
        case 502:
-               if (!(ctr->ctr502 = talloc_zero(
+               if (!(ctr->ctr502 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr502))) {
                        goto done;
                }
                break;
        case 1004:
-               if (!(ctr->ctr1004 = talloc_zero(
+               if (!(ctr->ctr1004 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr1004))) {
                        goto done;
                }
                break;
        case 1005:
-               if (!(ctr->ctr1005 = talloc_zero(
+               if (!(ctr->ctr1005 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr1005))) {
                        goto done;
                }
                break;
        case 1006:
-               if (!(ctr->ctr1006 = talloc_zero(
+               if (!(ctr->ctr1006 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr1006))) {
                        goto done;
                }
                break;
        case 1007:
-               if (!(ctr->ctr1007 = talloc_zero(
+               if (!(ctr->ctr1007 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr1007))) {
                        goto done;
                }
                break;
        case 1501:
-               if (!(ctr->ctr1501 = talloc_zero(
+               if (!(ctr->ctr1501 = TALLOC_ZERO_P(
                              p->mem_ctx, struct srvsvc_NetShareCtr1501))) {
                        goto done;
                }
@@ -769,19 +762,18 @@ static void init_srv_sess_info_0(pipes_struct *p, struct srvsvc_NetSessCtr0 *ss0
 {
        struct sessionid *session_list;
        uint32 num_entries = 0;
-       (*stot) = list_sessions(&session_list);
+       (*stot) = list_sessions(p->mem_ctx, &session_list);
 
        if (ss0 == NULL) {
                if (snum) {
                        (*snum) = 0;
                }
-               SAFE_FREE(session_list);
                return;
        }
 
        DEBUG(5,("init_srv_sess_0_ss0\n"));
 
-       ss0->array = talloc_array(p->mem_ctx, struct srvsvc_NetSessInfo0, *stot);
+       ss0->array = TALLOC_ARRAY(p->mem_ctx, struct srvsvc_NetSessInfo0, *stot);
 
        if (snum) {
                for (; (*snum) < (*stot); (*snum)++) {
@@ -799,7 +791,6 @@ static void init_srv_sess_info_0(pipes_struct *p, struct srvsvc_NetSessCtr0 *ss0
                ss0->array = NULL;
                ss0->count = 0;
        }
-       SAFE_FREE(session_list);
 }
 
 /*******************************************************************
@@ -811,7 +802,7 @@ static void sess_file_fn( const struct share_mode_entry *e,
 {
        struct sess_file_count *sess = (struct sess_file_count *)private_data;
  
-       if ( (procid_to_pid(&e->pid) == sess->pid) && (sess->uid == e->uid) ) {
+       if ( procid_equal(&e->pid, &sess->pid) && (sess->uid == e->uid) ) {
                sess->count++;
        }
        
@@ -821,7 +812,7 @@ static void sess_file_fn( const struct share_mode_entry *e,
 /*******************************************************************
 ********************************************************************/
 
-static int net_count_files( uid_t uid, pid_t pid )
+static int net_count_files( uid_t uid, struct server_id pid )
 {
        struct sess_file_count s_file_cnt;
 
@@ -859,9 +850,9 @@ static void init_srv_sess_info_1(pipes_struct *p, struct srvsvc_NetSessCtr1 *ss1
                return;
        }
 
-       (*stot) = list_sessions(&session_list);
+       (*stot) = list_sessions(p->mem_ctx, &session_list);
 
-       ss1->array = talloc_array(p->mem_ctx, struct srvsvc_NetSessInfo1, *stot);
+       ss1->array = TALLOC_ARRAY(p->mem_ctx, struct srvsvc_NetSessInfo1, *stot);
        
        for (; (*snum) < (*stot); (*snum)++) {
                uint32 num_files;
@@ -900,8 +891,6 @@ static void init_srv_sess_info_1(pipes_struct *p, struct srvsvc_NetSessCtr1 *ss1
        if ((*snum) >= (*stot)) {
                (*snum) = 0;
        }
-
-       SAFE_FREE(session_list);
 }
 
 /*******************************************************************
@@ -954,7 +943,7 @@ static void init_srv_conn_info_0(pipes_struct *p, struct srvsvc_NetConnCtr0 *ss0
        DEBUG(5,("init_srv_conn_0_ss0\n"));
 
        if (snum) {
-               ss0->array = talloc_array(p->mem_ctx, struct srvsvc_NetConnInfo0, *stot);
+               ss0->array = TALLOC_ARRAY(p->mem_ctx, struct srvsvc_NetConnInfo0, *stot);
                for (; (*snum) < (*stot); (*snum)++) {
 
                        ss0->array[num_entries].conn_id = (*stot);
@@ -996,7 +985,7 @@ static void init_srv_conn_info_1(pipes_struct *p, struct srvsvc_NetConnCtr1 *ss1
        DEBUG(5,("init_srv_conn_1_ss1\n"));
 
        if (snum) {
-               ss1->array = talloc_array(p->mem_ctx, struct srvsvc_NetConnInfo1, *stot);
+               ss1->array = TALLOC_ARRAY(p->mem_ctx, struct srvsvc_NetConnInfo1, *stot);
                for (; (*snum) < (*stot); (*snum)++) {
                        ss1->array[num_entries].conn_id = (*stot);
                        ss1->array[num_entries].conn_type = 0x3;
@@ -1067,7 +1056,7 @@ static WERROR net_file_enum_3(pipes_struct *p, union srvsvc_NetFileCtr *ctr, uin
           (b) active pipes
           (c) open directories and files */
 
-       ctr->ctr3 = talloc_zero(p->mem_ctx, struct srvsvc_NetFileCtr3);
+       ctr->ctr3 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetFileCtr3);
        
        status = net_enum_files( ctx, &ctr->ctr3->array, num_entries, resume_hnd );
        if ( !W_ERROR_IS_OK(status))
@@ -1121,7 +1110,7 @@ WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p, struct srvsvc_NetSrvGetInfo *r)
                   here, as most of it is made up. */
 
        case 102:
-               r->out.info->info102 = talloc_zero(p->mem_ctx, struct srvsvc_NetSrvInfo102);
+               r->out.info->info102 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetSrvInfo102);
 
                r->out.info->info102->platform_id = 500;
                r->out.info->info102->version_major = lp_major_announce_version();
@@ -1138,7 +1127,7 @@ WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p, struct srvsvc_NetSrvGetInfo *r)
                r->out.info->info102->comment = lp_serverstring();
                break;
        case 101:
-               r->out.info->info101 = talloc_zero(p->mem_ctx, struct srvsvc_NetSrvInfo101);
+               r->out.info->info101 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetSrvInfo101);
                        r->out.info->info101->platform_id = 500;
                        r->out.info->info101->server_name = global_myname();
                        r->out.info->info101->version_major = lp_major_announce_version();
@@ -1147,7 +1136,7 @@ WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p, struct srvsvc_NetSrvGetInfo *r)
                        r->out.info->info101->comment = lp_serverstring();
                break;
        case 100:
-               r->out.info->info100 = talloc_zero(p->mem_ctx, struct srvsvc_NetSrvInfo100);
+               r->out.info->info100 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetSrvInfo100);
                r->out.info->info100->platform_id = 500;
                r->out.info->info100->server_name = global_myname();
                break;
@@ -1222,7 +1211,7 @@ WERROR _srvsvc_NetSessDel(pipes_struct *p, struct srvsvc_NetSessDel *r)
                memmove(machine, &machine[1], strlen(machine));
        }
 
-       num_sessions = list_sessions(&session_list);
+       num_sessions = list_sessions(p->mem_ctx, &session_list);
 
        DEBUG(5,("_srv_net_sess_del: %d\n", __LINE__));
 
@@ -1240,18 +1229,20 @@ WERROR _srvsvc_NetSessDel(pipes_struct *p, struct srvsvc_NetSessDel *r)
 
                if ((strequal(session_list[snum].username, r->in.user) || r->in.user[0] == '\0' ) &&
                     strequal(session_list[snum].remote_machine, machine)) {
+                       NTSTATUS ntstat;
+
+                       ntstat = messaging_send(smbd_messaging_context(),
+                                               session_list[snum].pid,
+                                               MSG_SHUTDOWN, &data_blob_null);
                
-                       if (NT_STATUS_IS_OK(message_send_pid(pid_to_procid(session_list[snum].pid), MSG_SHUTDOWN, NULL, 0, False)))
+                       if (NT_STATUS_IS_OK(ntstat))
                                status = WERR_OK;
                }
        }
 
        DEBUG(5,("_srv_net_sess_del: %d\n", __LINE__));
 
-
 done:
-       SAFE_FREE(session_list);
-
        return status;
 }
 
@@ -1428,8 +1419,9 @@ static WERROR add_share(const char *share_name, const char *path,
 
                if ( (ret = smbrun(command, NULL)) == 0 ) {
                        /* Tell everyone we updated smb.conf. */
-                       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED,
-                                        NULL, 0, False, NULL);
+                       message_send_all(smbd_messaging_context(),
+                                        MSG_SMB_CONF_UPDATED,
+                                        NULL, 0, NULL);
                }
 
                if ( is_disk_op )
@@ -1524,8 +1516,9 @@ static WERROR delete_share(const char *sharename,
 
                if ( (ret = smbrun(command, NULL)) == 0 ) {
                        /* Tell everyone we updated smb.conf. */
-                       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED,
-                                        NULL, 0, False, NULL);
+                       message_send_all(smbd_messaging_context(),
+                                        MSG_SMB_CONF_UPDATED,
+                                        NULL, 0, NULL);
                }
 
                if ( is_disk_op )
@@ -1582,8 +1575,9 @@ static WERROR change_share(const char *share_name, const char *path,
                        
                if ( (ret = smbrun(command, NULL)) == 0 ) {
                        /* Tell everyone we updated smb.conf. */
-                       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED,
-                                        NULL, 0, False, NULL);
+                       message_send_all(smbd_messaging_context(),
+                                        MSG_SMB_CONF_UPDATED,
+                                        NULL, 0, NULL);
                }
                
                if ( is_disk_op )
@@ -2060,7 +2054,7 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p, struct srvsvc_NetGetFileSecur
 
 
        /* Null password is ok - we are already an authenticated user... */
-       null_pw = data_blob(NULL, 0);
+       null_pw = data_blob_null;
 
        become_root();
        conn = make_connection(r->in.share, null_pw, "A:", p->pipe_user.vuid, &nt_status);
@@ -2094,11 +2088,11 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p, struct srvsvc_NetGetFileSecur
                goto error_exit;
        }
 
-       nt_status = open_file_stat(conn, r->in.file, &st, &fsp);
+       nt_status = open_file_stat(conn, NULL, r->in.file, &st, &fsp);
        if (!NT_STATUS_IS_OK(nt_status)) {
                /* Perhaps it is a directory */
                if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_IS_A_DIRECTORY))
-                       nt_status = open_directory(conn, r->in.file, &st,
+                       nt_status = open_directory(conn, NULL, r->in.file, &st,
                                        READ_CONTROL_ACCESS,
                                        FILE_SHARE_READ|FILE_SHARE_WRITE,
                                        FILE_OPEN,
@@ -2152,7 +2146,6 @@ error_exit:
 
 WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p, struct srvsvc_NetSetFileSecurity *r)
 {
-       BOOL ret;
        DATA_BLOB null_pw;
        files_struct *fsp = NULL;
        SMB_STRUCT_STAT st;
@@ -2165,7 +2158,7 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p, struct srvsvc_NetSetFileSecur
        ZERO_STRUCT(st);
 
        /* Null password is ok - we are already an authenticated user... */
-       null_pw = data_blob(NULL, 0);
+       null_pw = data_blob_null;
 
        become_root();
        conn = make_connection(r->in.share, null_pw, "A:", p->pipe_user.vuid, &nt_status);
@@ -2200,12 +2193,12 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p, struct srvsvc_NetSetFileSecur
        }
 
 
-       nt_status = open_file_stat(conn, r->in.file, &st, &fsp);
+       nt_status = open_file_stat(conn, NULL, r->in.file, &st, &fsp);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                /* Perhaps it is a directory */
                if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_IS_A_DIRECTORY))
-                       nt_status = open_directory(conn, r->in.file, &st,
+                       nt_status = open_directory(conn, NULL, r->in.file, &st,
                                                FILE_READ_ATTRIBUTES,
                                                FILE_SHARE_READ|FILE_SHARE_WRITE,
                                                FILE_OPEN,
@@ -2220,9 +2213,9 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p, struct srvsvc_NetSetFileSecur
                }
        }
 
-       ret = SMB_VFS_SET_NT_ACL(fsp, fsp->fsp_name, r->in.securityinformation, r->in.sd_buf.sd);
+       nt_status = SMB_VFS_SET_NT_ACL(fsp, fsp->fsp_name, r->in.securityinformation, r->in.sd_buf.sd);
 
-       if (ret == False) {
+       if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srv_net_file_set_secdesc: Unable to set NT ACL on file %s\n", r->in.file));
                status = WERR_ACCESS_DENIED;
                goto error_exit;