static BOOL send_message(pid_t pid, int msg_type, const void *buf, int len, BOOL duplicates) { TDB_CONTEXT *tdb; BOOL ret; int n_sent = 0; if (!message_init()) return False; if (pid != 0) return message_send_pid(pid, msg_type, buf, len, duplicates); tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 0); if (!tdb) { fprintf(stderr,"Failed to open connections database" ": %s\n", strerror(errno)); return False; } ret = message_send_all(tdb,msg_type, buf, len, duplicates, &n_sent); DEBUG(10,("smbcontrol/send_message: broadcast message to " "%d processes\n", n_sent)); tdb_close(tdb); return ret; }
static BOOL send_status_message(struct process_id pid) { TDB_CONTEXT *tdb; BOOL ret; int n_sent = 0; if (!message_init()) return False; if (procid_to_pid(&pid) != 0) { return NT_STATUS_IS_OK(message_send_pid(pid, MSG_USR_STATS, NULL, 0, False /* duplicates */)); } tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 0); if (!tdb) { fprintf(stderr,"Failed to open connections database" ": %s\n", strerror(errno)); return False; } ret = message_send_all(tdb, MSG_USR_STATS, NULL, 0, False /* duplicates */, &n_sent); DEBUG(10,("smbcontrol/send_message: broadcast message to " "%d processes\n", n_sent)); tdb_close(tdb); return ret; }
/**************************************************************************** send a message to a named destination ****************************************************************************/ static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates) { BOOL retval = False; pid_t pid = 0; TDB_CONTEXT *the_tdb; the_tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 0); if (!the_tdb) { fprintf(stderr,"Failed to open connections database in send_message.\n"); return False; } /* "smbd" is the only broadcast operation */ if (strequal(dest,"smbd")) { retval = message_send_all(the_tdb,msg_type, buf, len, duplicates, NULL); } else if (strequal(dest,"nmbd")) { pid = pidfile_pid(dest); if (pid == 0) { fprintf(stderr,"Can't find pid for nmbd\n"); } } else if (strequal(dest,"self")) { pid = getpid(); } else { pid = atoi(dest); if (pid == 0) { fprintf(stderr,"Not a valid pid\n"); } } tdb_close(the_tdb); if (pid) return message_send_pid(pid, msg_type, buf, len, duplicates); else return retval; }
void smbd_send_stat_cache_delete_message(struct messaging_context *msg_ctx, const char *name) { #ifdef DEVELOPER message_send_all(msg_ctx, MSG_SMB_STAT_CACHE_DELETE, name, strlen(name)+1, NULL); #endif }
static void cleanup_timeout_fn(struct event_context *event_ctx, struct timed_event *te, struct timeval now, void *private_data) { struct timed_event **cleanup_te = (struct timed_event **)private_data; DEBUG(1,("Cleaning up brl and lock database after unclean shutdown\n")); message_send_all(smbd_messaging_context(), MSG_SMB_UNLOCK, NULL, 0, NULL); messaging_send_buf(smbd_messaging_context(), procid_self(), MSG_SMB_BRL_VALIDATE, NULL, 0); /* mark the cleanup as having been done */ (*cleanup_te) = NULL; }
static void cleanup_timeout_fn(struct tevent_context *event_ctx, struct tevent_timer *te, struct timeval now, void *private_data) { struct smbd_parent_context *parent = talloc_get_type_abort(private_data, struct smbd_parent_context); parent->cleanup_te = NULL; DEBUG(1,("Cleaning up brl and lock database after unclean shutdown\n")); message_send_all(parent->msg_ctx, MSG_SMB_UNLOCK, NULL, 0, NULL); messaging_send_buf(parent->msg_ctx, messaging_server_id(parent->msg_ctx), MSG_SMB_BRL_VALIDATE, NULL, 0); }
static bool send_message(struct messaging_context *msg_ctx, struct server_id pid, int msg_type, const void *buf, int len) { bool ret; int n_sent = 0; if (procid_to_pid(&pid) != 0) return NT_STATUS_IS_OK( messaging_send_buf(msg_ctx, pid, msg_type, (const uint8 *)buf, len)); ret = message_send_all(msg_ctx, msg_type, buf, len, &n_sent); DEBUG(10,("smbcontrol/send_message: broadcast message to " "%d processes\n", n_sent)); return ret; }
/**************************************************************************** Send a message to smbd to do a sam synchronisation **************************************************************************/ static void send_sync_message(void) { TDB_CONTEXT *tdb; tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { DEBUG(3, ("send_sync_message(): failed to open connections " "database\n")); return; } DEBUG(3, ("sending sam synchronisation message\n")); message_send_all(tdb, MSG_SMB_SAM_SYNC, NULL, 0, False, NULL); tdb_close(tdb); }
BOOL CALLBACK AnnDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { t_message *message; switch (Message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: { int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT1)); if (len > 0) { char* buf; buf = (char*)GlobalAlloc(GPTR, len + 1); GetDlgItemText(hwnd, IDC_EDIT1, buf, len + 1); if ((message = message_create(message_type_error, NULL, buf))) { message_send_all(message); message_destroy(message); } GlobalFree((HANDLE)buf); SetDlgItemText(hwnd, IDC_EDIT1, ""); } else { MessageBox(hwnd, "You didn't enter anything!", "Warning", MB_OK); } break; } } break; case WM_CLOSE: EndDialog(hwnd, IDOK); break; default: return FALSE; } return TRUE; }
static void send_repl_message(uint32 low_serial) { TDB_CONTEXT *tdb; tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { DEBUG(3, ("send_repl_message(): failed to open connections " "database\n")); return; } DEBUG(3, ("sending replication message, serial = 0x%04x\n", low_serial)); message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial, sizeof(low_serial), False, NULL); tdb_close(tdb); }
/**************************************************************************** Notify smbds of new printcap data **************************************************************************/ static void reload_pcap_change_notify(struct tevent_context *ev, struct messaging_context *msg_ctx) { message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL); }
uint32_t _fss_DeleteShareMapping(struct pipes_struct *p, struct fss_DeleteShareMapping *r) { struct fss_sc_set *sc_set; struct fss_sc *sc; struct fss_sc_smap *sc_smap; char *share; NTSTATUS status; TALLOC_CTX *tmp_ctx; struct connection_struct *conn; int snum; char *service; if (!fss_permitted(p)) { status = NT_STATUS_ACCESS_DENIED; goto err_out; } tmp_ctx = talloc_new(p->mem_ctx); if (tmp_ctx == NULL) { status = NT_STATUS_NO_MEMORY; goto err_out; } sc_set = sc_set_lookup(fss_global.sc_sets, &r->in.ShadowCopySetId); if (sc_set == NULL) { /* docs say HRES_E_INVALIDARG */ status = NT_STATUS_OBJECTID_NOT_FOUND; goto err_tmp_free; } if ((sc_set->state != FSS_SC_EXPOSED) && (sc_set->state != FSS_SC_RECOVERED)) { status = NT_STATUS_INVALID_SERVER_STATE; goto err_tmp_free; } sc = sc_lookup(sc_set->scs, &r->in.ShadowCopyId); if (sc == NULL) { status = NT_STATUS_INVALID_PARAMETER; goto err_tmp_free; } status = fss_unc_parse(tmp_ctx, r->in.ShareName, NULL, &share); if (!NT_STATUS_IS_OK(status)) { goto err_tmp_free; } sc_smap = sc_smap_lookup(sc->smaps, share); if (sc_smap == NULL) { status = NT_STATUS_INVALID_PARAMETER; goto err_tmp_free; } status = sc_smap_unexpose(p->msg_ctx, sc_smap, false); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("failed to remove share %s: %s\n", sc_smap->sc_share_name, nt_errstr(status))); goto err_tmp_free; } message_send_all(p->msg_ctx, MSG_SMB_FORCE_TDIS, sc_smap->sc_share_name, strlen(sc_smap->sc_share_name) + 1, NULL); if (sc->smaps_count > 1) { /* do not delete the underlying snapshot - still in use */ status = NT_STATUS_OK; goto err_tmp_free; } snum = find_service(tmp_ctx, sc_smap->share_name, &service); if ((snum == -1) || (service == NULL)) { DEBUG(0, ("share at %s not found\n", sc_smap->share_name)); status = NT_STATUS_UNSUCCESSFUL; goto err_tmp_free; } status = fss_vfs_conn_create(tmp_ctx, server_event_context(), p->msg_ctx, p->session_info, snum, &conn); if (!NT_STATUS_IS_OK(status)) { goto err_tmp_free; } if (!become_user_by_session(conn, p->session_info)) { DEBUG(0, ("failed to become user\n")); status = NT_STATUS_ACCESS_DENIED; goto err_conn_destroy; } status = SMB_VFS_SNAP_DELETE(conn, tmp_ctx, sc->volume_name, sc->sc_path); unbecome_user(); if (!NT_STATUS_IS_OK(status)) { goto err_conn_destroy; } /* XXX set timeout r->in.TimeOutInMilliseconds */ DEBUG(6, ("good snap delete\n")); DLIST_REMOVE(sc->smaps, sc_smap); sc->smaps_count--; talloc_free(sc_smap); if (sc->smaps_count == 0) { DLIST_REMOVE(sc_set->scs, sc); sc_set->scs_count--; talloc_free(sc); if (sc_set->scs_count == 0) { DLIST_REMOVE(fss_global.sc_sets, sc_set); fss_global.sc_sets_count--; talloc_free(sc_set); } } become_root(); status = fss_state_store(fss_global.mem_ctx, fss_global.sc_sets, fss_global.sc_sets_count, fss_global.db_path); unbecome_root(); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("failed to store fss server state: %s\n", nt_errstr(status))); } status = NT_STATUS_OK; err_conn_destroy: fss_vfs_conn_destroy(conn); err_tmp_free: talloc_free(tmp_ctx); err_out: return fss_ntstatus_map(status); }
static NTSTATUS sc_smap_unexpose(struct messaging_context *msg_ctx, struct fss_sc_smap *sc_smap, bool delete_all) { NTSTATUS ret; struct smbconf_ctx *conf_ctx; sbcErr cerr; bool is_modified = false; TALLOC_CTX *tmp_ctx = talloc_new(sc_smap); if (tmp_ctx == NULL) { return NT_STATUS_NO_MEMORY; } cerr = smbconf_init(tmp_ctx, &conf_ctx, "registry"); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("failed registry smbconf init: %s\n", sbcErrorString(cerr))); ret = NT_STATUS_UNSUCCESSFUL; goto err_tmp; } /* registry IO must be done as root */ become_root(); cerr = smbconf_transaction_start(conf_ctx); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("error starting transaction: %s\n", sbcErrorString(cerr))); ret = NT_STATUS_UNSUCCESSFUL; goto err_conf; } while (sc_smap) { struct fss_sc_smap *sc_map_next = sc_smap->next; if (!smbconf_share_exists(conf_ctx, sc_smap->sc_share_name)) { DEBUG(2, ("no such share: %s\n", sc_smap->sc_share_name)); if (!delete_all) { ret = NT_STATUS_OK; goto err_cancel; } sc_smap = sc_map_next; continue; } cerr = smbconf_delete_share(conf_ctx, sc_smap->sc_share_name); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("error deleting share: %s\n", sbcErrorString(cerr))); ret = NT_STATUS_UNSUCCESSFUL; goto err_cancel; } is_modified = true; sc_smap->is_exposed = false; if (delete_all) { sc_smap = sc_map_next; } else { sc_smap = NULL; /* only process single sc_map entry */ } } if (is_modified) { cerr = smbconf_transaction_commit(conf_ctx); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("error committing transaction: %s\n", sbcErrorString(cerr))); ret = NT_STATUS_UNSUCCESSFUL; goto err_cancel; } message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL); } else { ret = NT_STATUS_OK; goto err_cancel; } ret = NT_STATUS_OK; err_conf: talloc_free(conf_ctx); unbecome_root(); err_tmp: talloc_free(tmp_ctx); return ret; err_cancel: smbconf_transaction_cancel(conf_ctx); talloc_free(conf_ctx); unbecome_root(); talloc_free(tmp_ctx); return ret; }
uint32_t _fss_ExposeShadowCopySet(struct pipes_struct *p, struct fss_ExposeShadowCopySet *r) { NTSTATUS status; struct fss_sc_set *sc_set; struct fss_sc *sc; uint32_t ret; struct smbconf_ctx *fconf_ctx; struct smbconf_ctx *rconf_ctx; sbcErr cerr; char *fconf_path; TALLOC_CTX *tmp_ctx = talloc_new(p->mem_ctx); if (tmp_ctx == NULL) { return HRES_ERROR_V(HRES_E_OUTOFMEMORY); } if (!fss_permitted(p)) { ret = HRES_ERROR_V(HRES_E_ACCESSDENIED); goto err_out; } sc_set = sc_set_lookup(fss_global.sc_sets, &r->in.ShadowCopySetId); if (sc_set == NULL) { ret = HRES_ERROR_V(HRES_E_INVALIDARG); goto err_out; } if (sc_set->state != FSS_SC_COMMITED) { ret = FSRVP_E_BAD_STATE; goto err_out; } /* stop message sequence timer */ TALLOC_FREE(fss_global.seq_tmr); /* * Prepare to clone the base share definition for the snapshot share. * Create both registry and file conf contexts, as the base share * definition may be located in either. The snapshot share definition * is always written to the registry. */ cerr = smbconf_init(tmp_ctx, &rconf_ctx, "registry"); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("failed registry smbconf init: %s\n", sbcErrorString(cerr))); ret = HRES_ERROR_V(HRES_E_FAIL); goto err_tmr_restart; } fconf_path = talloc_asprintf(tmp_ctx, "file:%s", get_dyn_CONFIGFILE()); if (fconf_path == NULL) { ret = HRES_ERROR_V(HRES_E_OUTOFMEMORY); goto err_tmr_restart; } cerr = smbconf_init(tmp_ctx, &fconf_ctx, fconf_path); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("failed %s smbconf init: %s\n", fconf_path, sbcErrorString(cerr))); ret = HRES_ERROR_V(HRES_E_FAIL); goto err_tmr_restart; } /* registry IO must be done as root */ become_root(); cerr = smbconf_transaction_start(rconf_ctx); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("error starting transaction: %s\n", sbcErrorString(cerr))); ret = HRES_ERROR_V(HRES_E_FAIL); unbecome_root(); goto err_tmr_restart; } for (sc = sc_set->scs; sc; sc = sc->next) { ret = fss_sc_expose(fconf_ctx, rconf_ctx, tmp_ctx, sc); if (ret) { DEBUG(0,("failed to expose shadow copy of %s\n", sc->volume_name)); goto err_cancel; } } cerr = smbconf_transaction_commit(rconf_ctx); if (!SBC_ERROR_IS_OK(cerr)) { DEBUG(0, ("error committing transaction: %s\n", sbcErrorString(cerr))); ret = HRES_ERROR_V(HRES_E_FAIL); goto err_cancel; } unbecome_root(); message_send_all(p->msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL); for (sc = sc_set->scs; sc; sc = sc->next) { struct fss_sc_smap *sm; for (sm = sc->smaps; sm; sm = sm->next) sm->is_exposed = true; } sc_set->state = FSS_SC_EXPOSED; become_root(); status = fss_state_store(fss_global.mem_ctx, fss_global.sc_sets, fss_global.sc_sets_count, fss_global.db_path); unbecome_root(); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("failed to store fss server state: %s\n", nt_errstr(status))); } /* start message sequence timer */ fss_seq_tout_set(fss_global.mem_ctx, 180, sc_set, &fss_global.seq_tmr); talloc_free(tmp_ctx); return 0; err_cancel: smbconf_transaction_cancel(rconf_ctx); unbecome_root(); err_tmr_restart: fss_seq_tout_set(fss_global.mem_ctx, 180, sc_set, &fss_global.seq_tmr); err_out: talloc_free(tmp_ctx); return ret; }