r7440: * merge registry server changes from trunk (so far) for more
authorGerald Carter <jerry@samba.org>
Thu, 9 Jun 2005 15:20:11 +0000 (15:20 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:57:09 +0000 (10:57 -0500)
  printmig.exe work
* merge the sys_select_signal(char c) change from trunk
  in order to keeo the winbind code in sync
(This used to be commit a112c5570a7f8ddddde1af0fa665f40a6067e8cf)

13 files changed:
source3/include/doserr.h
source3/include/privileges.h
source3/lib/messages.c
source3/lib/privileges.c
source3/lib/select.c
source3/nmbd/nmbd.c
source3/nsswitch/winbindd.c
source3/registry/reg_cachehook.c
source3/rpc_server/srv_reg_nt.c
source3/smbd/notify_kernel.c
source3/smbd/oplock_linux.c
source3/smbd/server.c
source3/wrepld/server.c

index 60a3c335ec4046e7cc2628394f3b28a323cd0511..38cd87515e2f25b70bcd6ee2de37b96cc5fecfa6 100644 (file)
 #define WERR_INVALID_OWNER W_ERROR(1307)
 #define WERR_IO_PENDING W_ERROR(997)
 #define WERR_CAN_NOT_COMPLETE W_ERROR(1003)
+#define WERR_REG_CORRUPT W_ERROR(1015)
+#define WERR_REG_IO_FAILURE W_ERROR(1016)
+#define WERR_REG_FILE_INVALID W_ERROR(1017)
 #define WERR_NO_SUCH_SERVICE W_ERROR(1060)
 #define WERR_INVALID_SERVICE_CONTROL W_ERROR(1052)
 #define WERR_INVALID_SECURITY_DESCRIPTOR W_ERROR(1338)
index c7a9b0560da45c7bc6ed93d519040610a9dbf965..38edee84e8131e0f50e9aa9be1fbb7672e810cf9 100644 (file)
@@ -57,6 +57,9 @@ typedef struct {
 #define SE_ADD_USERS                   { { 0x00000040, 0x00000000, 0x00000000, 0x00000000 } }
 #define SE_DISK_OPERATOR               { { 0x00000080, 0x00000000, 0x00000000, 0x00000000 } }
 #define SE_REMOTE_SHUTDOWN             { { 0x00000100, 0x00000000, 0x00000000, 0x00000000 } }
+#define SE_BACKUP                      { { 0x00000200, 0x00000000, 0x00000000, 0x00000000 } }
+#define SE_RESTORE                     { { 0x00000400, 0x00000000, 0x00000000, 0x00000000 } }
+#define SE_TAKE_OWNERSHIP              { { 0x00000800, 0x00000000, 0x00000000, 0x00000000 } }
 
 /* defined in lib/privilegs.c */
 
@@ -66,6 +69,7 @@ extern const SE_PRIV se_print_operator;
 extern const SE_PRIV se_add_users;
 extern const SE_PRIV se_disk_operators;
 extern const SE_PRIV se_remote_shutdown;
+extern const SE_PRIV se_restore;
 
 
 /*
index dca4b94844ad7ddb02c21292493cabf8a63f4918..21b5531c898916f62eb79af38e6d3e1e8081ac26 100644 (file)
@@ -76,7 +76,7 @@ static struct dispatch_fns {
 static void sig_usr1(void)
 {
        received_signal = 1;
-       sys_select_signal();
+       sys_select_signal(SIGUSR1);
 }
 
 /****************************************************************************
index e01561de06f4d2dea1dc96da2be2bfd0e8bfd556..ae98d8940ffd0265c5195903407a23c6e123c599 100644 (file)
@@ -39,6 +39,7 @@ const SE_PRIV se_print_operator  = SE_PRINT_OPERATOR;
 const SE_PRIV se_add_users       = SE_ADD_USERS;
 const SE_PRIV se_disk_operators  = SE_DISK_OPERATOR;
 const SE_PRIV se_remote_shutdown = SE_REMOTE_SHUTDOWN;
+const SE_PRIV se_restore         = SE_RESTORE;
 
 /********************************************************************
  This is a list of privileges reported by a WIndows 2000 SP4 AD DC
@@ -91,6 +92,9 @@ PRIVS privs[] = {
        {SE_ADD_USERS,                  "SeAddUsersPrivilege",                  "Add users and groups to the domain"},
        {SE_REMOTE_SHUTDOWN,            "SeRemoteShutdownPrivilege",            "Force shutdown from a remote system"},
        {SE_DISK_OPERATOR,              "SeDiskOperatorPrivilege",              "Manage disk shares"},
+        {SE_BACKUP,                     "SeBackupPrivilege",                    "Back up files and directories"},
+        {SE_RESTORE,                    "SeRestorePrivilege",                   "Restore files and directories"},
+       {SE_TAKE_OWNERSHIP,             "SeTakeOwnershipPrivilege",             "Take ownership of files or other objects"},
 
        {SE_END,                        "",                                     ""}
 };
@@ -636,6 +640,7 @@ NTSTATUS privilege_create_account(const DOM_SID *sid )
 /****************************************************************************
  initialise a privilege list and set the talloc context 
  ****************************************************************************/
 NTSTATUS privilege_set_init(PRIVILEGE_SET *priv_set)
 {
        TALLOC_CTX *mem_ctx;
index 2e55f9753dbea30d8deed99fd2eb288f1d967c41..f63221f7cfa5614d8955f68bf76fa74224f172d3 100644 (file)
@@ -38,9 +38,8 @@ static VOLATILE unsigned pipe_written, pipe_read;
  nasty signal race condition.
 ********************************************************************/
 
-void sys_select_signal(void)
+void sys_select_signal(char c)
 {
-       char c = 1;
        if (!initialised) return;
 
        if (pipe_written > pipe_read+256) return;
@@ -111,6 +110,10 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s
                           byte in the pipe and lose the signal. JRA.
                        */
                        ret = -1;
+#if 0
+                       /* JRA - we can use this to debug the signal messaging... */
+                       DEBUG(0,("select got %u signal\n", (unsigned int)c));
+#endif
                        errno = EINTR;
                } else {
                        FD_CLR(select_pipe[0], readfds2);
index af93bf5197cad6a1f76b0c6a35c7cdb7384fe1c3..97e22943b14a3499dd2148f4d86624107708c206 100644 (file)
@@ -90,7 +90,7 @@ static SIG_ATOMIC_T got_sig_term;
 static void sig_term(int sig)
 {
        got_sig_term = 1;
-       sys_select_signal();
+       sys_select_signal(SIGTERM);
 }
 
 /**************************************************************************** **
@@ -102,7 +102,7 @@ static SIG_ATOMIC_T reload_after_sighup;
 static void sig_hup(int sig)
 {
        reload_after_sighup = 1;
-       sys_select_signal();
+       sys_select_signal(SIGHUP);
 }
 
 #if DUMP_CORE
index f083dfe44ac6bcd6a75afeadb89bc08c0ea21dd0..c3a27a7deb4d84f0c4bde462ef08e31ee31ee175 100644 (file)
@@ -183,7 +183,7 @@ static BOOL do_sigterm;
 static void termination_handler(int signum)
 {
        do_sigterm = True;
-       sys_select_signal();
+       sys_select_signal(signum);
 }
 
 static BOOL do_sigusr2;
@@ -191,7 +191,7 @@ static BOOL do_sigusr2;
 static void sigusr2_handler(int signum)
 {
        do_sigusr2 = True;
-       sys_select_signal();
+       sys_select_signal(SIGUSR2);
 }
 
 static BOOL do_sighup;
@@ -199,7 +199,7 @@ static BOOL do_sighup;
 static void sighup_handler(int signum)
 {
        do_sighup = True;
-       sys_select_signal();
+       sys_select_signal(SIGHUP);
 }
 
 static BOOL do_sigchld;
@@ -207,7 +207,7 @@ static BOOL do_sigchld;
 static void sigchld_handler(int signum)
 {
        do_sigchld = True;
-       sys_select_signal();
+       sys_select_signal(SIGCHLD);
 }
 
 /* React on 'smbcontrol winbindd reload-config' in the same way as on SIGHUP*/
index 4b03a69acf7153b2da543e803a126acc3f8f2edb..c8a23777be0995b5acce88c0cbeffb0b5f8cdbf8 100644 (file)
@@ -67,7 +67,7 @@ BOOL reghook_cache_add( REGISTRY_HOOK *hook )
  Initialize the cache tree
  *********************************************************************/
 
-REGISTRY_HOOK* reghook_cache_find( char *keyname )
+REGISTRY_HOOK* reghook_cache_find( const char *keyname )
 {
        char *key;
        int len;
index 4211e9b9f4f1156e02408edea09e7858f158d246..9792592c197d3933a81977de3d60ee27bd04f2a6 100644 (file)
@@ -762,6 +762,113 @@ static int validate_reg_filename( pstring fname )
        return (snum < num_services) ? snum : -1;
 }
 
+/*******************************************************************
+ Note: topkeypaty is the *full* path that this *key will be 
+ loaded into (including the name of the key)
+ ********************************************************************/
+
+static WERROR reg_load_tree( REGF_FILE *regfile, const char *topkeypath,
+                             REGF_NK_REC *key )
+{
+       REGF_NK_REC *subkey;
+       REGISTRY_KEY registry_key;
+       REGVAL_CTR values;
+       REGSUBKEY_CTR subkeys;
+       int i;
+       pstring path;
+       WERROR result = WERR_OK;
+       
+       /* initialize the REGISTRY_KEY structure */
+       
+       if ( !(registry_key.hook = reghook_cache_find(topkeypath)) ) {
+               DEBUG(0,("reg_load_tree: Failed to assigned a REGISTRY_HOOK to [%s]\n",
+                       topkeypath ));
+               return WERR_BADFILE;
+       }
+       pstrcpy( registry_key.name, topkeypath );
+       
+       /* now start parsing the values and subkeys */
+
+       ZERO_STRUCT( values );
+       ZERO_STRUCT( subkeys );
+
+       regsubkey_ctr_init( &subkeys );
+       regval_ctr_init( &values );
+       
+       /* copy values into the REGVAL_CTR */
+       
+       for ( i=0; i<key->num_values; i++ ) {
+               regval_ctr_addvalue( &values, key->values[i].valuename, key->values[i].type,
+                       key->values[i].data, (key->values[i].data_size & ~VK_DATA_IN_OFFSET) );
+       }
+
+       /* copy subkeys into the REGSUBKEY_CTR */
+       
+       key->subkey_index = 0;
+       while ( (subkey = regfio_fetch_subkey( regfile, key )) ) {
+               regsubkey_ctr_addkey( &subkeys, subkey->keyname );
+       }
+       
+       /* write this key and values out */
+       
+       if ( !store_reg_values( &registry_key, &values ) 
+               || !store_reg_keys( &registry_key, &subkeys ) )
+       {
+               DEBUG(0,("reg_load_tree: Failed to load %s!\n", topkeypath));
+               result = WERR_REG_IO_FAILURE;
+       }
+       
+       regval_ctr_destroy( &values );
+       regsubkey_ctr_destroy( &subkeys );
+       
+       if ( !W_ERROR_IS_OK(result) )
+               return result;
+       
+       /* now continue to load each subkey registry tree */
+
+       key->subkey_index = 0;
+       while ( (subkey = regfio_fetch_subkey( regfile, key )) ) {
+               pstr_sprintf( path, "%s%s%s", topkeypath, "\\", subkey->keyname );
+               result = reg_load_tree( regfile, path, subkey );
+               if ( !W_ERROR_IS_OK(result) )
+                       break;
+       }
+
+       return result;
+}
+
+/*******************************************************************
+ ********************************************************************/
+
+static WERROR restore_registry_key ( REGISTRY_KEY *krecord, const char *fname )
+{
+       REGF_FILE *regfile;
+       REGF_NK_REC *rootkey;
+       WERROR result;
+               
+       /* open the registry file....fail if the file already exists */
+       
+       if ( !(regfile = regfio_open( fname, (O_RDONLY), 0 )) ) {
+                DEBUG(0,("backup_registry_key: failed to open \"%s\" (%s)\n", 
+                       fname, strerror(errno) ));
+               return ( ntstatus_to_werror(map_nt_error_from_unix( errno )) );
+        }
+       
+       /* get the rootkey from the regf file and then load the tree
+          via recursive calls */
+          
+       if ( !(rootkey = regfio_rootkey( regfile )) )
+               return WERR_REG_FILE_INVALID;
+       
+       result = reg_load_tree( regfile, krecord->name, rootkey );
+               
+       /* cleanup */
+       
+       regfio_close( regfile );
+       
+       return result;
+}
+
 /*******************************************************************
  ********************************************************************/
 
@@ -783,13 +890,14 @@ WERROR _reg_restore_key(pipes_struct *p, REG_Q_RESTORE_KEY  *q_u, REG_R_RESTORE_
        if ( (snum = validate_reg_filename( filename )) == -1 )
                return WERR_OBJECT_PATH_INVALID;
                
+       /* user must posses SeRestorePrivilege for this this proceed */
+       
+       if ( !user_has_privileges( p->pipe_user.nt_user_token, &se_restore ) )
+               return WERR_ACCESS_DENIED;
+               
        DEBUG(2,("_reg_restore_key: Restoring [%s] from %s in share %s\n", regkey->name, filename, lp_servicename(snum) ));
 
-#if 0
        return restore_registry_key( regkey, filename );
-#endif
-
-       return WERR_OK;
 }
 
 /********************************************************************
index 6d1f550241e00af5f13a7add16aac5b657e27985..02abe0b4b60eccaa159ba8f649a6f48b615f6ea7 100644 (file)
@@ -74,7 +74,7 @@ static void signal_handler(int sig, siginfo_t *info, void *unused)
                fd_pending_array[signals_received] = (SIG_ATOMIC_T)info->si_fd;
                signals_received++;
        } /* Else signal is lost. */
-       sys_select_signal();
+       sys_select_signal(RT_SIGNAL_NOTIFY);
 }
 
 /****************************************************************************
index 6d1bc64ce102d974055425f8d35370e5184cdcf9..78dc260939ed719f3cf88cc64fadca3b6619669e 100644 (file)
@@ -72,7 +72,7 @@ static void signal_handler(int sig, siginfo_t *info, void *unused)
                fd_pending_array[signals_received] = (SIG_ATOMIC_T)info->si_fd;
                signals_received++;
        } /* Else signal is lost. */
-       sys_select_signal();
+       sys_select_signal(RT_SIGNAL_LEASE);
 }
 
 /****************************************************************************
index 301534d750cf20de5333773fd3cde5261ba3ea79..01515a57266e71355de5fdd443e71cc3e108ab8d 100644 (file)
@@ -66,7 +66,7 @@ static void smbd_set_server_fd(int fd)
 static void sig_term(void)
 {
        got_sig_term = 1;
-       sys_select_signal();
+       sys_select_signal(SIGTERM);
 }
 
 /****************************************************************************
@@ -76,7 +76,7 @@ static void sig_term(void)
 static void sig_hup(int sig)
 {
        reload_after_sighup = 1;
-       sys_select_signal();
+       sys_select_signal(SIGHUP);
 }
 
 /****************************************************************************
index 9d035a6cbffb1708ed9951d0d92789831f584b50..06fab1ab1ab87194dbc779b5649710eaf8b63c09 100644 (file)
@@ -89,7 +89,7 @@ static void sig_hup(int sig)
        BlockSignals(True,SIGHUP);
        DEBUG(0,("Got SIGHUP\n"));
 
-       sys_select_signal();
+       sys_select_signal(SIGHUP);
        reload_after_sighup = True;
        BlockSignals(False,SIGHUP);
 }