/* ** open parts of the state that may cause memory-allocation errors */ static void f_luaopen (lua_State *L, void *ud) { global_State *g = G(L); UNUSED(ud); stack_init(L, L); /* init stack */ init_registry(L, g); luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaT_init(L); luaX_init(L); /* pre-create memory-error message */ g->memerrmsg = luaS_newliteral(L, MEMERRMSG); luaS_fix(g->memerrmsg); /* it should never be collected */ g->gcrunning = 1; /* allow gc */ }
long __stdcall RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size) { char* c; TRACE("Request to set value %s %d\n", name, *(const int*)data); if(!regs) init_registry(); c=build_keyname(key, name); if(c==NULL) return 1; insert_reg_value(key, name, v2, data, size); free(c); return 0; }
LONG WINAPI dllRegQueryValueExA (HKEY key, LPCSTR value, LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count) { struct reg_value* t; char* c; if(!regs) init_registry(); c=build_keyname((long)key, value); if (!c) return 1; t=find_value_by_name(c); free(c); if (t==0){ dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)" " => 0x%x\n", key, value, reserved, data, count, 2); memset(data, 0, *count); return 2; } if (type) *type=t->type; if (data) { memcpy(data, t->value, (t->len<(int)*count)?t->len:(int)*count); //mp_msg(0,0,"returning %d bytes: %d\n", t->len, *(int*)data); } if((int)*count<t->len) { *count=t->len; dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)" " => 0x%x\n", key, value, reserved, data, count, ERROR_MORE_DATA); if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data); return ERROR_MORE_DATA; } else { *count=t->len; } dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)" " => 0x%x\n", key, value, reserved, data, count, 0); if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data); return 0; }
long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size) { /* struct reg_value* t; -- unused */ char* c; TRACE("Request to set value %s\n", name); if(!regs) init_registry(); c=build_keyname(key, name); if(c==NULL) return 1; insert_reg_value(key, name, v2, data, size); free(c); return 0; }
LONG WINAPI dllRegSetValueExA(HKEY key, LPCTSTR name, DWORD v1, DWORD v2, const BYTE * data, DWORD size) { // struct reg_value* t; char* c; //mp_msg(0,0,"Request to set value %s %d\n", name, *(const int*)data); if(!regs) init_registry (); c=build_keyname((long)key, name); if(c==NULL) return 1; insert_reg_value((int)key, name, v2, data, size); free(c); return 0; }
/** * 完成与内存有关的初始化工作, 包括分配栈空间, 初始化注册表, 预分配 * 某些字符串资源(保留关键字等) */ static void f_luaopen (lua_State *L, void *ud) { Dlog("luaopen begin."); global_State *g = G(L); UNUSED(ud); stack_init(L, L); /* init stack */ init_registry(L, g); Dlog("ini size of string table with size %d", MINSTRTABSIZE); luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaT_init(L); luaX_init(L); /* pre-create memory-error message */ g->memerrmsg = luaS_newliteral(L, MEMERRMSG); luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ g->gcrunning = 1; /* allow gc */ g->version = lua_version(NULL); luai_userstateopen(L); Dlog("luaopen end."); }
int main( int argc, char *argv[] ) { parse_args( argc, argv ); /* setup temporary handlers before the real signal initialization is done */ signal( SIGPIPE, SIG_IGN ); signal( SIGHUP, sigterm_handler ); signal( SIGINT, sigterm_handler ); signal( SIGQUIT, sigterm_handler ); signal( SIGTERM, sigterm_handler ); signal( SIGABRT, sigterm_handler ); sock_init(); open_master_socket(); setvbuf( stderr, NULL, _IOLBF, 0 ); if (debug_level) fprintf( stderr, "wineserver: starting (pid=%ld)\n", (long) getpid() ); init_signals(); init_directories(); init_registry(); main_loop(); return 0; }
/* ** open parts of the state that may cause memory-allocation errors. ** ('g->version' != NULL flags that the state was completely build) */ static void f_luaopen (lua_State *L, void *ud) { global_State *g = G(L); UNUSED(ud); stack_init(L, L); /* init stack */ init_registry(L, g); #if LUA_FASTREF_SUPPORT { TValue n; sethvalue(L, &G(L)->l_refs, luaH_new(L)); /* refs */ setivalue(&n, 0); luaH_setint(L, hvalue(&G(L)->l_refs), LUA_RIDX_FASTREF_FREELIST, &n); setnilvalue(&g->fastrefNilValue); } #endif /* LUA_FASTREF_SUPPORT */ luaS_init(L); luaT_init(L); luaX_init(L); g->gcrunning = 1; /* allow gc */ g->version = lua_version(NULL); luai_userstateopen(L); }
static void save_registry(void) { int fd, i; if (!regs) init_registry(); fd = open(localregpathname, O_WRONLY | O_CREAT, 00666); if (fd == -1) { printf("Failed to open registry file '%s' for writing.\n", localregpathname); return; } write(fd, ®_size, 4); for(i=0; i<reg_size; i++) { unsigned len=strlen(regs[i].name); write(fd, ®s[i].type, 4); write(fd, &len, 4); write(fd, regs[i].name, len); write(fd, ®s[i].len, 4); write(fd, regs[i].value, regs[i].len); } close(fd); }
static void test_Language(void) { static const WCHAR vbW[] = {'V','B','S','c','r','i','p','t',0}; static const WCHAR jsW[] = {'J','S','c','r','i','p','t',0}; static const WCHAR vb2W[] = {'v','B','s','c','r','i','p','t',0}; static const WCHAR dummyW[] = {'d','u','m','m','y',0}; IScriptControl *sc; HRESULT hr; BSTR str; hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IScriptControl, (void**)&sc); ok(hr == S_OK, "got 0x%08x\n", hr); todo_wine { hr = IScriptControl_get_Language(sc, NULL); ok(hr == E_POINTER, "got 0x%08x\n", hr); str = (BSTR)0xdeadbeef; hr = IScriptControl_get_Language(sc, &str); ok(hr == S_OK, "got 0x%08x\n", hr); if (hr == S_OK) ok(str == NULL, "got %s\n", wine_dbgstr_w(str)); str = SysAllocString(vbW); hr = IScriptControl_put_Language(sc, str); ok(hr == S_OK, "got 0x%08x\n", hr); SysFreeString(str); str = SysAllocString(vb2W); hr = IScriptControl_put_Language(sc, str); ok(hr == S_OK, "got 0x%08x\n", hr); SysFreeString(str); hr = IScriptControl_get_Language(sc, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, vbW), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str); str = SysAllocString(dummyW); hr = IScriptControl_put_Language(sc, str); ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr); SysFreeString(str); hr = IScriptControl_get_Language(sc, &str); ok(hr == S_OK, "got 0x%08x\n", hr); if (hr == S_OK) ok(!lstrcmpW(str, vbW), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str); str = SysAllocString(jsW); hr = IScriptControl_put_Language(sc, str); ok(hr == S_OK, "got 0x%08x\n", hr); SysFreeString(str); hr = IScriptControl_get_Language(sc, &str); if (hr == S_OK) ok(!lstrcmpW(str, jsW), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str); hr = IScriptControl_put_Language(sc, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IScriptControl_get_Language(sc, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(str == NULL, "got %s\n", wine_dbgstr_w(str)); IScriptControl_Release(sc); } /* custom script engine */ if (register_script_engine()) { static const WCHAR testscriptW[] = {'t','e','s','t','s','c','r','i','p','t',0}; hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IScriptControl, (void**)&sc); ok(hr == S_OK, "got 0x%08x\n", hr); todo_wine { SET_EXPECT(CreateInstance); SET_EXPECT(SetInterfaceSafetyOptions); SET_EXPECT(SetScriptSite); SET_EXPECT(InitNew); str = SysAllocString(testscriptW); hr = IScriptControl_put_Language(sc, str); ok(hr == S_OK, "got 0x%08x\n", hr); SysFreeString(str); CHECK_CALLED(CreateInstance); CHECK_CALLED(SetInterfaceSafetyOptions); CHECK_CALLED(SetScriptSite); CHECK_CALLED(InitNew); hr = IScriptControl_get_Language(sc, &str); ok(hr == S_OK, "got 0x%08x\n", hr); if (hr == S_OK) ok(!lstrcmpW(testscriptW, str), "%s\n", wine_dbgstr_w(str)); SysFreeString(str); init_registry(FALSE); SET_EXPECT(Close); IScriptControl_Release(sc); CHECK_CALLED(Close); } } else
int main2(int argc,const char *argv[]) { /* shall I run as a daemon */ static BOOL is_daemon = False; static BOOL interactive = False; static BOOL Fork = True; static BOOL no_process_group = False; static BOOL log_stdout = False; static char *ports = NULL; int opt; #ifndef _XBOX poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" }, {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"}, {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" }, {"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" }, {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"}, POPT_COMMON_SAMBA POPT_COMMON_DYNCONFIG POPT_TABLEEND }; #else interactive = True; log_stdout = True; #endif load_case_tables(); #ifdef HAVE_SET_AUTH_PARAMETERS set_auth_parameters(argc,argv); #endif #ifndef _XBOX pc = poptGetContext("smbd", argc, argv, long_options, 0); while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'b': build_options(True); /* Display output to screen as well as debug */ exit(0); break; } } poptFreeContext(pc); #endif #ifdef HAVE_SETLUID /* needed for SecureWare on SCO */ setluid(0); #endif sec_init(); set_remote_machine_name("smbd", False); if (interactive) { Fork = False; log_stdout = True; } if (interactive && (DEBUGLEVEL >= 9)) { talloc_enable_leak_report(); } if (log_stdout && Fork) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); exit(1); } setup_logging(argv[0],log_stdout); /* we want to re-seed early to prevent time delays causing client problems at a later date. (tridge) */ generate_random_buffer(NULL, 0); /* make absolutely sure we run as root - to handle cases where people are crazy enough to have it setuid */ gain_root_privilege(); gain_root_group_privilege(); #ifndef _XBOX fault_setup((void (*)(void *))exit_server_fault); dump_core_setup("smbd"); #endif CatchSignal(SIGTERM , SIGNAL_CAST sig_term); #ifndef _XBOX CatchSignal(SIGHUP,SIGNAL_CAST sig_hup); /* we are never interested in SIGPIPE */ BlockSignals(True,SIGPIPE); #endif #if defined(SIGFPE) /* we are never interested in SIGFPE */ BlockSignals(True,SIGFPE); #endif #if defined(SIGUSR2) /* We are no longer interested in USR2 */ BlockSignals(True,SIGUSR2); #endif /* POSIX demands that signals are inherited. If the invoking process has * these signals masked, we will have problems, as we won't recieve them. */ #ifndef _XBOX BlockSignals(False, SIGHUP); #endif BlockSignals(False, SIGUSR1); BlockSignals(False, SIGTERM); /* we want total control over the permissions on created files, so set our umask to 0 */ umask(0); init_sec_ctx(); reopen_logs(); DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING)); DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) ); DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n", (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid())); /* Output the build options to the debug log */ build_options(False); if (sizeof(uint16) < 2 || sizeof(uint32) < 4) { DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n")); exit(1); } /* * Do this before reload_services. */ if (!reload_services(False)) return(-1); init_structs(); #ifdef WITH_PROFILE if (!profile_setup(False)) { DEBUG(0,("ERROR: failed to setup profiling\n")); return -1; } #endif DEBUG(3,( "loaded services\n")); if (!is_daemon && !is_a_socket(0)) { if (!interactive) DEBUG(0,("standard input is not a socket, assuming -D option\n")); /* * Setting is_daemon here prevents us from eventually calling * the open_sockets_inetd() */ is_daemon = True; } if (is_daemon && !interactive) { DEBUG( 3, ( "Becoming a daemon.\n" ) ); become_daemon(Fork, no_process_group); } #if HAVE_SETPGID /* * If we're interactive we want to set our own process group for * signal management. */ if (interactive && !no_process_group) setpgid( (pid_t)0, (pid_t)0); #endif if (!directory_exist(lp_lockdir(), NULL)) mkdir(lp_lockdir(), 0755); #ifndef _XBOX if (is_daemon) pidfile_create("smbd"); #endif /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */ if (!message_init()) exit(1); /* Initialize our global sam sid first -- quite a lot of the other * initialization routines further down depend on it. */ /* Initialise the password backed before the global_sam_sid to ensure that we fetch from ldap before we make a domain sid up */ if(!initialize_password_db(False)) exit(1); /* Fail gracefully if we can't open secrets.tdb */ if (!secrets_init()) { DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n")); exit(1); } if(!get_global_sam_sid()) { DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n")); exit(1); } if (!session_init()) exit(1); if (conn_tdb_ctx() == NULL) exit(1); if (!locking_init(0)) exit(1); namecache_enable(); if (!init_registry()) exit(1); #if 0 if (!init_svcctl_db()) exit(1); #endif #ifndef _XBOX if (!print_backend_init()) exit(1); #endif if (!init_guest_info()) { DEBUG(0,("ERROR: failed to setup guest info.\n")); return -1; } /* Setup the main smbd so that we can get messages. */ /* don't worry about general printing messages here */ claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD); /* only start the background queue daemon if we are running as a daemon -- bad things will happen if smbd is launched via inetd and we fork a copy of ourselves here */ #ifndef _XBOX if ( is_daemon && !interactive ) start_background_queue(); #endif /* Always attempt to initialize DMAPI. We will only use it later if * lp_dmapi_support is set on the share, but we need a single global * session to work with. */ dmapi_init_session(); if (!open_sockets_smbd(is_daemon, interactive, ports)) exit(1); /* * everything after this point is run after the fork() */ static_init_rpc; init_modules(); /* possibly reload the services file. */ reload_services(True); if (!init_account_policy()) { DEBUG(0,("Could not open account policy tdb.\n")); exit(1); } if (*lp_rootdir()) { if (sys_chroot(lp_rootdir()) == 0) DEBUG(2,("Changed root to %s\n", lp_rootdir())); } /* Setup oplocks */ if (!init_oplocks()) exit(1); /* Setup change notify */ if (!init_change_notify()) exit(1); /* Setup aio signal handler. */ initialize_async_io_handler(); /* re-initialise the timezone */ TimeInit(); /* register our message handlers */ message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis); smbd_process(); #ifdef _XBOX xb_DecClientCount(); #endif namecache_shutdown(); exit_server_cleanly(NULL); return(0); }