Changeset 740 for vendor/current/source4/smbd
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source4/smbd
- Files:
-
- 2 added
- 3 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/smbd/pidfile.c
r414 r740 39 39 char *pidFile; 40 40 41 asprintf(&pidFile, "%s/%s.pid", piddir, name); 41 if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) { 42 return 0; 43 } 42 44 43 45 fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644); … … 86 88 pid_t pid; 87 89 88 asprintf(&pidFile, "%s/%s.pid", piddir, name); 90 if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) { 91 DEBUG(0,("ERROR: Out of memory\n")); 92 exit(1); 93 } 89 94 90 95 pid = pidfile_pid(piddir, name); -
vendor/current/source4/smbd/process_model.c
r414 r740 23 23 #include "param/param.h" 24 24 25 static const struct model_ops *process_model_byname(const char *name); 25 /* the list of currently registered process models */ 26 static struct process_model { 27 const struct model_ops *ops; 28 bool initialised; 29 } *models = NULL; 30 static int num_models; 31 32 33 /* 34 return the operations structure for a named backend of the specified type 35 */ 36 static struct process_model *process_model_byname(const char *name) 37 { 38 int i; 39 40 for (i=0;i<num_models;i++) { 41 if (strcmp(models[i].ops->name, name) == 0) { 42 return &models[i]; 43 } 44 } 45 46 return NULL; 47 } 48 26 49 27 50 /* 28 51 setup the events for the chosen process model 29 52 */ 30 _PUBLIC_ const struct model_ops *process_model_startup( struct tevent_context *ev,const char *model)53 _PUBLIC_ const struct model_ops *process_model_startup(const char *model) 31 54 { 32 const struct model_ops *ops;55 struct process_model *m; 33 56 34 ops= process_model_byname(model);35 if ( !ops) {57 m = process_model_byname(model); 58 if (m == NULL) { 36 59 DEBUG(0,("Unknown process model '%s'\n", model)); 37 60 exit(-1); 38 61 } 39 62 40 ops->model_init(ev); 63 if (!m->initialised) { 64 m->initialised = true; 65 m->ops->model_init(); 66 } 41 67 42 return ops;68 return m->ops; 43 69 } 44 45 /* the list of currently registered process models */46 static struct process_model {47 struct model_ops *ops;48 } *models = NULL;49 static int num_models;50 70 51 71 /* … … 55 75 structure for this backend. 56 76 */ 57 _PUBLIC_ NTSTATUS register_process_model(const void *_ops)77 _PUBLIC_ NTSTATUS register_process_model(const struct model_ops *ops) 58 78 { 59 const struct model_ops *ops = _ops;60 61 79 if (process_model_byname(ops->name) != NULL) { 62 80 /* its already registered! */ … … 66 84 } 67 85 68 models = realloc_p(models, struct process_model, num_models+1);86 models = talloc_realloc(NULL, models, struct process_model, num_models+1); 69 87 if (!models) { 70 88 smb_panic("out of memory in register_process_model"); 71 89 } 72 90 73 models[num_models].ops = smb_xmemdup(ops, sizeof(*ops));74 models[num_models]. ops->name = smb_xstrdup(ops->name);91 models[num_models].ops = ops; 92 models[num_models].initialised = false; 75 93 76 94 num_models++; 77 95 78 DEBUG(3,("PROCESS_MODEL '%s' registered\n", 79 ops->name)); 96 DEBUG(3,("PROCESS_MODEL '%s' registered\n", ops->name)); 80 97 81 98 return NT_STATUS_OK; … … 84 101 _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx) 85 102 { 86 extern NTSTATUS process_model_thread_init(void); 87 extern NTSTATUS process_model_standard_init(void); 88 extern NTSTATUS process_model_prefork_init(void); 89 extern NTSTATUS process_model_single_init(void); 103 #define _MODULE_PROTO(init) extern NTSTATUS init(void); 104 STATIC_process_model_MODULES_PROTO; 90 105 init_module_fn static_init[] = { STATIC_process_model_MODULES }; 91 init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "process_model"); 106 init_module_fn *shared_init; 107 static bool initialised; 92 108 109 if (initialised) { 110 return NT_STATUS_OK; 111 } 112 initialised = true; 113 114 shared_init = load_samba_modules(NULL, lp_ctx, "process_model"); 115 93 116 run_init_functions(static_init); 94 117 run_init_functions(shared_init); 95 118 96 119 talloc_free(shared_init); 97 120 98 121 return NT_STATUS_OK; 99 }100 101 /*102 return the operations structure for a named backend of the specified type103 */104 static const struct model_ops *process_model_byname(const char *name)105 {106 int i;107 108 for (i=0;i<num_models;i++) {109 if (strcmp(models[i].ops->name, name) == 0) {110 return models[i].ops;111 }112 }113 114 return NULL;115 122 } 116 123 -
vendor/current/source4/smbd/process_model.h
r414 r740 27 27 #include "lib/socket/socket.h" 28 28 #include "smbd/service.h" 29 #include "smbd/process_model_proto.h" 29 30 30 31 /* modules can use the following to determine if the interface has changed … … 42 43 43 44 /* called at startup when the model is selected */ 44 void (*model_init)( struct tevent_context *);45 void (*model_init)(void); 45 46 46 47 /* function to accept new connection */ … … 56 57 /* function to create a task */ 57 58 void (*new_task)(struct tevent_context *, 58 struct loadparm_context *lp_ctx, 59 struct loadparm_context *lp_ctx, 59 60 const char *service_name, 60 61 void (*)(struct tevent_context *, … … 64 65 65 66 /* function to terminate a connection or task */ 66 void (*terminate)(struct tevent_context *, struct loadparm_context *lp_ctx, 67 void (*terminate)(struct tevent_context *, struct loadparm_context *lp_ctx, 67 68 const char *reason); 68 69 … … 79 80 extern const struct model_ops single_ops; 80 81 81 const struct model_ops *process_model_startup( struct tevent_context *ev,const char *model);82 NTSTATUS register_process_model(const void *_ops);82 const struct model_ops *process_model_startup(const char *model); 83 NTSTATUS register_process_model(const struct model_ops *ops); 83 84 NTSTATUS process_model_init(struct loadparm_context *lp_ctx); 84 85 -
vendor/current/source4/smbd/process_prefork.c
r414 r740 26 26 #include "includes.h" 27 27 #include "lib/events/events.h" 28 #include "../tdb/include/tdb.h"29 28 #include "lib/socket/socket.h" 30 29 #include "smbd/process_model.h" 31 #include "param/secrets.h"32 30 #include "system/filesys.h" 33 31 #include "cluster/cluster.h" 34 32 #include "param/param.h" 33 #include "ldb_wrap.h" 35 34 36 35 #ifdef HAVE_SETPROCTITLE … … 50 49 called when the process model is selected 51 50 */ 52 static void prefork_model_init( struct tevent_context *ev)51 static void prefork_model_init(void) 53 52 { 54 53 signal(SIGCHLD, SIG_IGN); … … 57 56 static void prefork_reload_after_fork(void) 58 57 { 59 /* tdb needs special fork handling */ 60 if (tdb_reopen_all(1) == -1) { 61 DEBUG(0,("prefork_reload_after_fork: tdb_reopen_all failed.\n")); 62 } 58 ldb_wrap_fork_hook(); 63 59 64 60 /* Ensure that the forked children do not expose identical random streams */ … … 98 94 struct loadparm_context *lp_ctx, 99 95 const char *service_name, 100 void (*new_task_fn)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 96 void (*new_task_fn)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 101 97 void *private_data) 102 98 { … … 127 123 talloc_free(ev); 128 124 129 setproctitle("task %s server_id[%d]", service_name, pid);125 setproctitle("task %s server_id[%d]", service_name, (int)pid); 130 126 131 127 prefork_reload_after_fork(); … … 134 130 new_task_fn(ev2, lp_ctx, cluster_id(pid, 0), private_data); 135 131 136 num_children = lp _parm_int(lp_ctx, NULL, "prefork children", service_name, 0);132 num_children = lpcfg_parm_int(lp_ctx, NULL, "prefork children", service_name, 0); 137 133 if (num_children == 0) { 138 134 … … 156 152 } else { 157 153 pid = getpid(); 158 setproctitle("task %s server_id[%d]", service_name, pid);154 setproctitle("task %s server_id[%d]", service_name, (int)pid); 159 155 160 156 prefork_reload_after_fork(); … … 175 171 /* But we need a events system to handle reaping children */ 176 172 ev_parent = s4_event_context_init(NULL); 177 173 178 174 /* TODO: Handle some events... */ 179 175 … … 190 186 191 187 /* called when a task goes down */ 192 _NORETURN_ static void prefork_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason) 188 static void prefork_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason) 193 189 { 194 190 DEBUG(2,("prefork_terminate: reason[%s]\n",reason)); -
vendor/current/source4/smbd/process_single.c
r414 r740 30 30 called when the process model is selected 31 31 */ 32 static void single_model_init( struct tevent_context *ev)32 static void single_model_init(void) 33 33 { 34 34 } … … 56 56 57 57 We can only be here if woken up from select, due to 58 an incom ming connection.58 an incoming connection. 59 59 60 60 We need to throttle things until the system clears … … 72 72 /* The cluster_id(0, fd) cannot collide with the incrementing 73 73 * task below, as the first component is 0, not 1 */ 74 new_conn(ev, lp_ctx, connected_socket, 74 new_conn(ev, lp_ctx, connected_socket, 75 75 cluster_id(0, socket_get_fd(connected_socket)), private_data); 76 76 } … … 80 80 */ 81 81 static void single_new_task(struct tevent_context *ev, 82 struct loadparm_context *lp_ctx, 82 struct loadparm_context *lp_ctx, 83 83 const char *service_name, 84 84 void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *), … … 98 98 99 99 /* called when a task goes down */ 100 static void single_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason) 100 static void single_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason) 101 101 { 102 DEBUG( 2,("single_terminate: reason[%s]\n",reason));102 DEBUG(3,("single_terminate: reason[%s]\n",reason)); 103 103 } 104 104 -
vendor/current/source4/smbd/process_standard.c
r414 r740 24 24 #include "includes.h" 25 25 #include "lib/events/events.h" 26 #include "../tdb/include/tdb.h"27 26 #include "smbd/process_model.h" 28 27 #include "system/filesys.h" 29 28 #include "cluster/cluster.h" 30 29 #include "param/param.h" 30 #include "ldb_wrap.h" 31 31 32 32 #ifdef HAVE_SETPROCTITLE … … 51 51 called when the process model is selected 52 52 */ 53 static void standard_model_init( struct tevent_context *ev)53 static void standard_model_init(void) 54 54 { 55 55 pipe(child_pipe); … … 81 81 struct socket_context *sock2; 82 82 pid_t pid; 83 struct tevent_context *ev2;84 83 struct socket_address *c, *s; 85 84 … … 107 106 108 107 /* This is now the child code. We need a completely new event_context to work with */ 109 ev2 = s4_event_context_init(NULL); 110 111 /* the service has given us a private pointer that 112 encapsulates the context it needs for this new connection - 113 everything else will be freed */ 114 talloc_steal(ev2, private_data); 115 talloc_steal(private_data, sock2); 108 109 if (tevent_re_initialise(ev) != 0) { 110 smb_panic("Failed to re-initialise tevent after fork"); 111 } 116 112 117 113 /* this will free all the listening sockets and all state that 118 114 is not associated with this new connection */ 119 115 talloc_free(sock); 120 talloc_free(ev);121 116 122 117 /* we don't care if the dup fails, as its only a select() … … 125 120 126 121 /* tdb needs special fork handling */ 127 if (tdb_reopen_all(1) == -1) { 128 DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n")); 129 } 130 131 tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ, 122 ldb_wrap_fork_hook(); 123 124 tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ, 132 125 standard_pipe_handler, NULL); 133 126 close(child_pipe[1]); … … 137 130 138 131 /* setup the process title */ 139 c = socket_get_peer_addr(sock2, ev 2);140 s = socket_get_my_addr(sock2, ev 2);132 c = socket_get_peer_addr(sock2, ev); 133 s = socket_get_my_addr(sock2, ev); 141 134 if (s && c) { 142 135 setproctitle("conn c[%s:%u] s[%s:%u] server_id[%d]", 143 c->addr, c->port, s->addr, s->port, pid);136 c->addr, c->port, s->addr, s->port, (int)pid); 144 137 } 145 138 talloc_free(c); … … 147 140 148 141 /* setup this new connection. Cluster ID is PID based for this process modal */ 149 new_conn(ev 2, lp_ctx, sock2, cluster_id(pid, 0), private_data);142 new_conn(ev, lp_ctx, sock2, cluster_id(pid, 0), private_data); 150 143 151 144 /* we can't return to the top level here, as that event context is gone, 152 145 so we now process events in the new event context until there are no 153 146 more to process */ 154 event_loop_wait(ev 2);155 156 talloc_free(ev 2);147 event_loop_wait(ev); 148 149 talloc_free(ev); 157 150 exit(0); 158 151 } … … 164 157 struct loadparm_context *lp_ctx, 165 158 const char *service_name, 166 void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 159 void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 167 160 void *private_data) 168 161 { 169 162 pid_t pid; 170 struct tevent_context *ev2;171 163 172 164 pid = fork(); … … 179 171 pid = getpid(); 180 172 181 /* This is now the child code. We need a completely new event_context to work with */182 ev2 = s4_event_context_init(NULL);183 184 /* the service has given us a private pointer that185 encapsulates the context it needs for this new connection -186 everything else will be freed */187 talloc_steal(ev2, private_data);188 189 173 /* this will free all the listening sockets and all state that 190 174 is not associated with this new connection */ 191 talloc_free(ev);192 193 /* tdb needs special fork handling */194 if (tdb_reopen_all(1) == -1) { 195 DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));196 }197 198 tevent_add_fd(ev 2, ev2, child_pipe[0], TEVENT_FD_READ,175 if (tevent_re_initialise(ev) != 0) { 176 smb_panic("Failed to re-initialise tevent after fork"); 177 } 178 179 /* ldb/tdb need special fork handling */ 180 ldb_wrap_fork_hook(); 181 182 tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ, 199 183 standard_pipe_handler, NULL); 200 184 close(child_pipe[1]); … … 203 187 set_need_random_reseed(); 204 188 205 setproctitle("task %s server_id[%d]", service_name, pid);189 setproctitle("task %s server_id[%d]", service_name, (int)pid); 206 190 207 191 /* setup this new task. Cluster ID is PID based for this process modal */ 208 new_task(ev 2, lp_ctx, cluster_id(pid, 0), private_data);192 new_task(ev, lp_ctx, cluster_id(pid, 0), private_data); 209 193 210 194 /* we can't return to the top level here, as that event context is gone, 211 195 so we now process events in the new event context until there are no 212 196 more to process */ 213 event_loop_wait(ev 2);214 215 talloc_free(ev 2);197 event_loop_wait(ev); 198 199 talloc_free(ev); 216 200 exit(0); 217 201 } … … 219 203 220 204 /* called when a task goes down */ 221 _NORETURN_ static void standard_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, 205 _NORETURN_ static void standard_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, 222 206 const char *reason) 223 207 { 224 208 DEBUG(2,("standard_terminate: reason[%s]\n",reason)); 209 210 talloc_free(ev); 225 211 226 212 /* this reload_charcnv() has the effect of freeing the iconv context memory, 227 213 which makes leak checking easier */ 228 214 reload_charcnv(lp_ctx); 229 230 talloc_free(ev);231 215 232 216 /* terminate this process */ -
vendor/current/source4/smbd/process_thread.c
r414 r740 30 30 #include "system/wait.h" 31 31 #include "system/filesys.h" 32 #include "system/time.h" 32 33 #include "lib/events/events.h" 33 34 #include "lib/util/dlinklist.h" … … 63 64 */ 64 65 static void thread_accept_connection(struct tevent_context *ev, 65 struct loadparm_context *lp_ctx, 66 struct loadparm_context *lp_ctx, 66 67 struct socket_context *sock, 67 68 void (*new_conn)(struct tevent_context *, … … 133 134 struct new_task_state *new_task = talloc_get_type(thread_parm, struct new_task_state); 134 135 135 new_task->new_task(new_task->ev, new_task->lp_ctx, pthread_self(), 136 new_task->new_task(new_task->ev, new_task->lp_ctx, pthread_self(), 136 137 new_task->private_data); 137 138 … … 189 190 190 191 /* called when a task goes down */ 191 static void thread_terminate(struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, const char *reason) 192 static void thread_terminate(struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, const char *reason) 192 193 { 193 194 DEBUG(10,("thread_terminate: reason[%s]\n",reason)); … … 234 235 } 235 236 236 static void mutex_start_timer(struct timeval *tp1) 237 { 238 gettimeofday(tp1,NULL); 239 } 240 241 static double mutex_end_timer(struct timeval tp1) 242 { 243 struct timeval tp2; 244 gettimeofday(&tp2,NULL); 237 static void mutex_start_timer(struct timespec *tp1) 238 { 239 clock_gettime_mono(tp1); 240 } 241 242 static double mutex_end_timer(struct timespec tp1) 243 { 244 struct timespec tp2; 245 246 clock_gettime_mono(&tp2); 245 247 return((tp2.tv_sec - tp1.tv_sec) + 246 (tp2.tv_ usec - tp1.tv_usec)*1.0e-6);248 (tp2.tv_nsec - tp1.tv_nsec)*1.0e-9); 247 249 } 248 250 … … 255 257 int rc; 256 258 double t; 257 struct time valtp1;259 struct timespec tp1; 258 260 /* Test below is ONLY for debugging */ 259 261 if ((rc = pthread_mutex_trylock(mutex))) { … … 317 319 int rc; 318 320 double t; 319 struct time valtp1;321 struct timespec tp1; 320 322 /* Test below is ONLY for debugging */ 321 323 if ((rc = pthread_rwlock_tryrdlock(rwlock))) { … … 346 348 int rc; 347 349 double t; 348 struct time valtp1;350 struct timespec tp1; 349 351 /* Test below is ONLY for debugging */ 350 352 if ((rc = pthread_rwlock_trywrlock(rwlock))) { … … 460 462 { 461 463 #ifdef SIGSEGV 462 CatchSignal(SIGSEGV, SIGNAL_CASTthread_sig_fault);464 CatchSignal(SIGSEGV, thread_sig_fault); 463 465 #endif 464 466 #ifdef SIGBUS 465 CatchSignal(SIGBUS, SIGNAL_CASTthread_sig_fault);467 CatchSignal(SIGBUS, thread_sig_fault); 466 468 #endif 467 469 #ifdef SIGABRT 468 CatchSignal(SIGABRT, SIGNAL_CASTthread_sig_fault);470 CatchSignal(SIGABRT, thread_sig_fault); 469 471 #endif 470 472 } … … 510 512 called when the process model is selected 511 513 */ 512 static void thread_model_init( struct tevent_context *event_context)514 static void thread_model_init(void) 513 515 { 514 516 struct mutex_ops m_ops; … … 519 521 520 522 pthread_key_create(&title_key, NULL); 521 pthread_setspecific(title_key, talloc_strdup(event_context, ""));523 pthread_setspecific(title_key, NULL); 522 524 523 525 /* register mutex/rwlock handlers */ -
vendor/current/source4/smbd/samba.8.xml
r414 r740 1 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE refentry PUBLIC "-// Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 3 3 <refentry id="samba.8"> 4 4 -
vendor/current/source4/smbd/server.c
r414 r740 32 32 #include "ntptr/ntptr.h" 33 33 #include "auth/gensec/gensec.h" 34 #include "libcli/auth/schannel.h" 34 35 #include "smbd/process_model.h" 35 36 #include "param/secrets.h" … … 41 42 #include "librpc/gen_ndr/ndr_irpc.h" 42 43 #include "cluster/cluster.h" 44 #include "dynconfig/dynconfig.h" 43 45 44 46 /* … … 116 118 #endif 117 119 DEBUG(0,("Exiting pid %d on SIGTERM\n", (int)getpid())); 118 exit( 0);120 exit(127); 119 121 } 120 122 … … 141 143 142 144 /* POSIX demands that signals are inherited. If the invoking process has 143 * these signals masked, we will have problems, as we won't rec ieve them. */145 * these signals masked, we will have problems, as we won't receive them. */ 144 146 BlockSignals(false, SIGHUP); 145 147 BlockSignals(false, SIGTERM); … … 177 179 { 178 180 const char *binary_name = (const char *)private_data; 179 DEBUG(0,("%s: maximum runtime exceeded - terminating\n", binary_name)); 181 struct timeval tv; 182 struct timezone tz; 183 if (gettimeofday(&tv, &tz) == 0) { 184 DEBUG(0,("%s: maximum runtime exceeded - terminating, current ts: %d\n", binary_name, (int)tv.tv_sec)); 185 } else { 186 DEBUG(0,("%s: maximum runtime exceeded - terminating\n", binary_name)); 187 } 180 188 exit(0); 181 189 } 182 190 183 191 /* 184 pre-open the sam ldb to ensure the schema has been loaded. This185 saves a lot of time in child processes192 pre-open the key databases. This saves a lot of time in child 193 processes 186 194 */ 187 static void prime_samdb_schema(struct tevent_context *event_ctx) 188 { 189 TALLOC_CTX *samdb_context; 190 samdb_context = talloc_new(event_ctx); 191 samdb_connect(samdb_context, event_ctx, cmdline_lp_ctx, system_session(samdb_context, cmdline_lp_ctx)); 192 talloc_free(samdb_context); 195 static void prime_ldb_databases(struct tevent_context *event_ctx) 196 { 197 TALLOC_CTX *db_context; 198 db_context = talloc_new(event_ctx); 199 200 samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx), 0); 201 privilege_connect(db_context, cmdline_lp_ctx); 202 203 /* we deliberately leave these open, which allows them to be 204 * re-used in ldb_wrap_connect() */ 193 205 } 194 206 … … 214 226 215 227 msg = messaging_init(talloc_autofree_context(), 216 lp_messaging_path(event_ctx, lp_ctx), 217 cluster_id(0, SAMBA_PARENT_TASKID), 218 lp_iconv_convenience(lp_ctx), 219 event_ctx); 228 lpcfg_messaging_path(event_ctx, lp_ctx), 229 cluster_id(0, SAMBA_PARENT_TASKID), event_ctx); 220 230 NT_STATUS_HAVE_NO_MEMORY(msg); 221 231 … … 229 239 230 240 241 /* 242 show build info 243 */ 244 static void show_build(void) 245 { 246 #define CONFIG_OPTION(n) { #n, dyn_ ## n } 247 struct { 248 const char *name; 249 const char *value; 250 } config_options[] = { 251 CONFIG_OPTION(BINDIR), 252 CONFIG_OPTION(SBINDIR), 253 CONFIG_OPTION(CONFIGFILE), 254 CONFIG_OPTION(NCALRPCDIR), 255 CONFIG_OPTION(LOGFILEBASE), 256 CONFIG_OPTION(LMHOSTSFILE), 257 CONFIG_OPTION(DATADIR), 258 CONFIG_OPTION(MODULESDIR), 259 CONFIG_OPTION(LOCKDIR), 260 CONFIG_OPTION(PIDDIR), 261 CONFIG_OPTION(PRIVATE_DIR), 262 CONFIG_OPTION(SWATDIR), 263 CONFIG_OPTION(CODEPAGEDIR), 264 CONFIG_OPTION(SETUPDIR), 265 CONFIG_OPTION(WINBINDD_SOCKET_DIR), 266 CONFIG_OPTION(WINBINDD_PRIVILEGED_SOCKET_DIR), 267 CONFIG_OPTION(NTP_SIGND_SOCKET_DIR), 268 { NULL, NULL} 269 }; 270 int i; 271 272 printf("Samba version: %s\n", SAMBA_VERSION_STRING); 273 printf("Build environment:\n"); 274 #ifdef BUILD_SYSTEM 275 printf(" Build host: %s\n", BUILD_SYSTEM); 276 #endif 277 278 printf("Paths:\n"); 279 for (i=0; config_options[i].name; i++) { 280 printf(" %s: %s\n", config_options[i].name, config_options[i].value); 281 } 282 283 exit(0); 284 } 231 285 232 286 /* … … 239 293 int opt; 240 294 poptContext pc; 241 extern NTSTATUS server_service_wrepl_init(void); 242 extern NTSTATUS server_service_kdc_init(void); 243 extern NTSTATUS server_service_ldap_init(void); 244 extern NTSTATUS server_service_web_init(void); 245 extern NTSTATUS server_service_ldap_init(void); 246 extern NTSTATUS server_service_winbind_init(void); 247 extern NTSTATUS server_service_nbtd_init(void); 248 extern NTSTATUS server_service_auth_init(void); 249 extern NTSTATUS server_service_cldapd_init(void); 250 extern NTSTATUS server_service_smb_init(void); 251 extern NTSTATUS server_service_drepl_init(void); 252 extern NTSTATUS server_service_kcc_init(void); 253 extern NTSTATUS server_service_rpc_init(void); 254 extern NTSTATUS server_service_ntp_signd_init(void); 255 extern NTSTATUS server_service_samba3_smb_init(void); 295 #define _MODULE_PROTO(init) extern NTSTATUS init(void); 296 STATIC_service_MODULES_PROTO; 256 297 init_module_fn static_init[] = { STATIC_service_MODULES }; 257 298 init_module_fn *shared_init; … … 264 305 OPT_DAEMON = 1000, 265 306 OPT_INTERACTIVE, 266 OPT_PROCESS_MODEL 307 OPT_PROCESS_MODEL, 308 OPT_SHOW_BUILD 267 309 }; 268 310 struct poptOption long_options[] = { … … 276 318 {"maximum-runtime",0, POPT_ARG_INT, &max_runtime, 0, 277 319 "set maximum runtime of the server process, till autotermination", "seconds"}, 320 {"show-build", 'b', POPT_ARG_NONE, NULL, OPT_SHOW_BUILD, "show build info", NULL }, 278 321 POPT_COMMON_SAMBA 279 322 POPT_COMMON_VERSION … … 293 336 model = poptGetOptArg(pc); 294 337 break; 338 case OPT_SHOW_BUILD: 339 show_build(); 340 break; 295 341 default: 296 342 fprintf(stderr, "\nInvalid option %s: %s\n\n", 297 343 poptBadOption(pc, 0), poptStrerror(opt)); 298 344 poptPrintUsage(pc, stderr, 0); 299 exit(1);345 return 1; 300 346 } 301 347 } … … 305 351 "Option -i|--interactive is not allowed together with -D|--daemon\n\n"); 306 352 poptPrintUsage(pc, stderr, 0); 307 exit(1);353 return 1; 308 354 } else if (!opt_interactive) { 309 355 /* default is --daemon */ … … 321 367 322 368 DEBUG(0,("%s version %s started.\n", binary_name, SAMBA_VERSION_STRING)); 323 DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-20 09\n"));369 DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2011\n")); 324 370 325 371 if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || sizeof(uint64_t) < 8) { … … 327 373 DEBUGADD(0,("sizeof(uint16_t) = %u, sizeof(uint32_t) %u, sizeof(uint64_t) = %u\n", 328 374 (unsigned int)sizeof(uint16_t), (unsigned int)sizeof(uint32_t), (unsigned int)sizeof(uint64_t))); 329 exit(1);375 return 1; 330 376 } 331 377 332 378 if (opt_daemon) { 333 379 DEBUG(3,("Becoming a daemon.\n")); 334 become_daemon(true, false );380 become_daemon(true, false, false); 335 381 } 336 382 337 383 cleanup_tmp_files(cmdline_lp_ctx); 338 384 339 if (!directory_exist(lp _lockdir(cmdline_lp_ctx))) {340 mkdir(lp _lockdir(cmdline_lp_ctx), 0755);341 } 342 343 pidfile_create(lp _piddir(cmdline_lp_ctx), binary_name);385 if (!directory_exist(lpcfg_lockdir(cmdline_lp_ctx))) { 386 mkdir(lpcfg_lockdir(cmdline_lp_ctx), 0755); 387 } 388 389 pidfile_create(lpcfg_piddir(cmdline_lp_ctx), binary_name); 344 390 345 391 /* Do *not* remove this, until you have removed … … 347 393 /* Setup the SECRETS subsystem */ 348 394 if (secrets_init(talloc_autofree_context(), cmdline_lp_ctx) == NULL) { 349 exit(1); 395 return 1; 396 } 397 398 if (lpcfg_server_role(cmdline_lp_ctx) == ROLE_DOMAIN_CONTROLLER) { 399 if (!open_schannel_session_store(talloc_autofree_context(), lpcfg_private_dir(cmdline_lp_ctx))) { 400 DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n")); 401 exit(1); 402 } 350 403 } 351 404 … … 393 446 394 447 if (max_runtime) { 448 struct timeval tv; 449 struct timezone tz; 450 451 if (gettimeofday(&tv, &tz) == 0) { 452 DEBUG(0,("Called with maxruntime %d - current ts %d\n", max_runtime, (int)tv.tv_sec)); 453 } else { 454 DEBUG(0,("Called with maxruntime %d\n", max_runtime)); 455 } 395 456 tevent_add_timer(event_ctx, event_ctx, 396 457 timeval_current_ofs(max_runtime, 0), … … 399 460 } 400 461 401 prime_ samdb_schema(event_ctx);462 prime_ldb_databases(event_ctx); 402 463 403 464 status = setup_parent_messaging(event_ctx, cmdline_lp_ctx); … … 410 471 411 472 status = server_service_startup(event_ctx, cmdline_lp_ctx, model, 412 lp _server_services(cmdline_lp_ctx));473 lpcfg_server_services(cmdline_lp_ctx)); 413 474 if (!NT_STATUS_IS_OK(status)) { 414 475 DEBUG(0,("Starting Services failed - %s\n", nt_errstr(status))); -
vendor/current/source4/smbd/service.c
r414 r740 84 84 } 85 85 86 model_ops = process_model_startup( event_ctx,model);86 model_ops = process_model_startup(model); 87 87 if (!model_ops) { 88 88 DEBUG(0,("process_model_startup('%s') failed\n", model)); -
vendor/current/source4/smbd/service_named_pipe.c
r414 r740 24 24 #include "smbd/service.h" 25 25 #include "param/param.h" 26 #include "auth/auth.h" 26 27 #include "auth/session.h" 27 28 #include "auth/auth_sam_reply.h" 28 #include "lib/stream/packet.h" 29 #include "lib/socket/socket.h" 30 #include "lib/tsocket/tsocket.h" 31 #include "libcli/util/tstream.h" 29 32 #include "librpc/gen_ndr/ndr_named_pipe_auth.h" 30 33 #include "system/passwd.h" 34 #include "system/network.h" 31 35 #include "libcli/raw/smb.h" 32 #include "auth/credentials/credentials.h" 33 #include "auth/credentials/credentials_krb5.h" 36 #include "auth/session.h" 37 #include "libcli/security/security.h" 38 #include "libcli/named_pipe_auth/npa_tstream.h" 34 39 35 40 struct named_pipe_socket { … … 40 45 }; 41 46 42 struct named_pipe_connection { 43 struct stream_connection *connection; 44 struct packet_context *packet; 45 const struct named_pipe_socket *pipe_sock; 46 NTSTATUS status; 47 }; 48 49 static void named_pipe_handover_connection(void *private_data) 50 { 51 struct named_pipe_connection *pipe_conn = talloc_get_type( 52 private_data, struct named_pipe_connection); 53 struct stream_connection *conn = pipe_conn->connection; 54 55 TEVENT_FD_NOT_WRITEABLE(conn->event.fde); 56 57 packet_set_socket(pipe_conn->packet, NULL); 58 packet_set_event_context(pipe_conn->packet, NULL); 59 packet_set_fde(pipe_conn->packet, NULL); 60 TALLOC_FREE(pipe_conn->packet); 61 62 if (!NT_STATUS_IS_OK(pipe_conn->status)) { 63 stream_terminate_connection(conn, nt_errstr(pipe_conn->status)); 47 static void named_pipe_accept_done(struct tevent_req *subreq); 48 49 static void named_pipe_accept(struct stream_connection *conn) 50 { 51 struct tstream_context *plain_tstream; 52 int fd; 53 struct tevent_req *subreq; 54 int ret; 55 56 /* Let tstream take over fd operations */ 57 58 fd = socket_get_fd(conn->socket); 59 socket_set_flags(conn->socket, SOCKET_FLAG_NOCLOSE); 60 TALLOC_FREE(conn->event.fde); 61 TALLOC_FREE(conn->socket); 62 63 ret = tstream_bsd_existing_socket(conn, fd, &plain_tstream); 64 if (ret != 0) { 65 stream_terminate_connection(conn, 66 "named_pipe_accept: out of memory"); 64 67 return; 65 68 } 66 69 67 /* 68 * remove the named_pipe layer together with its packet layer 69 */ 70 conn->ops = pipe_conn->pipe_sock->ops; 71 conn->private_data = pipe_conn->pipe_sock->private_data; 72 talloc_unlink(conn, pipe_conn); 73 74 /* we're now ready to start receiving events on this stream */ 75 TEVENT_FD_READABLE(conn->event.fde); 70 subreq = tstream_npa_accept_existing_send(conn, conn->event.ctx, 71 plain_tstream, 72 FILE_TYPE_MESSAGE_MODE_PIPE, 73 0xff | 0x0400 | 0x0100, 74 4096); 75 if (subreq == NULL) { 76 stream_terminate_connection(conn, 77 "named_pipe_accept: " 78 "no memory for tstream_npa_accept_existing_send"); 79 return; 80 } 81 tevent_req_set_callback(subreq, named_pipe_accept_done, conn); 82 } 83 84 static void named_pipe_accept_done(struct tevent_req *subreq) 85 { 86 struct stream_connection *conn = tevent_req_callback_data(subreq, 87 struct stream_connection); 88 struct named_pipe_socket *pipe_sock = 89 talloc_get_type(conn->private_data, 90 struct named_pipe_socket); 91 struct tsocket_address *client; 92 char *client_name; 93 struct tsocket_address *server; 94 char *server_name; 95 struct auth_session_info_transport *session_info_transport; 96 const char *reason = NULL; 97 TALLOC_CTX *tmp_ctx; 98 int error; 99 int ret; 100 101 tmp_ctx = talloc_new(conn); 102 if (!tmp_ctx) { 103 reason = "Out of memory!\n"; 104 goto out; 105 } 106 107 ret = tstream_npa_accept_existing_recv(subreq, &error, tmp_ctx, 108 &conn->tstream, 109 &client, 110 &client_name, 111 &server, 112 &server_name, 113 &session_info_transport); 114 TALLOC_FREE(subreq); 115 if (ret != 0) { 116 reason = talloc_asprintf(conn, 117 "tstream_npa_accept_existing_recv()" 118 " failed: %s", strerror(error)); 119 goto out; 120 } 121 122 DEBUG(10, ("Accepted npa connection from %s. " 123 "Client: %s (%s). Server: %s (%s)\n", 124 tsocket_address_string(conn->remote_address, tmp_ctx), 125 client_name, tsocket_address_string(client, tmp_ctx), 126 server_name, tsocket_address_string(server, tmp_ctx))); 127 128 conn->session_info = auth_session_info_from_transport(conn, session_info_transport, 129 conn->lp_ctx, 130 &reason); 131 if (!conn->session_info) { 132 goto out; 133 } 76 134 77 135 /* … … 79 137 * now that we have setup the transport session_info 80 138 */ 139 conn->ops = pipe_sock->ops; 140 conn->private_data = pipe_sock->private_data; 81 141 conn->ops->accept_connection(conn); 82 142 83 DEBUG(10,("named_pipe_handover_connection[%s]: succeeded\n", 84 conn->ops->name)); 85 } 86 87 static NTSTATUS named_pipe_recv_auth_request(void *private_data, 88 DATA_BLOB req_blob) 89 { 90 struct named_pipe_connection *pipe_conn = talloc_get_type( 91 private_data, struct named_pipe_connection); 92 struct stream_connection *conn = pipe_conn->connection; 93 enum ndr_err_code ndr_err; 94 struct named_pipe_auth_req req; 95 union netr_Validation val; 96 struct auth_serversupplied_info *server_info; 97 struct named_pipe_auth_rep rep; 98 DATA_BLOB rep_blob; 99 NTSTATUS status; 100 101 /* 102 * make sure nothing happens on the socket untill the 103 * real implemenation takes over 104 */ 105 packet_recv_disable(pipe_conn->packet); 106 107 /* 108 * TODO: check it's a root (uid == 0) pipe 109 */ 110 111 ZERO_STRUCT(rep); 112 rep.level = 0; 113 rep.status = NT_STATUS_INTERNAL_ERROR; 114 115 DEBUG(10,("named_pipe_auth: req_blob.length[%u]\n", 116 (unsigned int)req_blob.length)); 117 dump_data(11, req_blob.data, req_blob.length); 118 119 /* parse the passed credentials */ 120 ndr_err = ndr_pull_struct_blob_all( 121 &req_blob, 122 pipe_conn, 123 lp_iconv_convenience(conn->lp_ctx), 124 &req, 125 (ndr_pull_flags_fn_t)ndr_pull_named_pipe_auth_req); 126 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 127 rep.status = ndr_map_error2ntstatus(ndr_err); 128 DEBUG(2, ("Could not unmarshall named_pipe_auth_req: %s\n", 129 nt_errstr(rep.status))); 130 goto reply; 131 } 132 133 if (DEBUGLVL(10)) { 134 NDR_PRINT_DEBUG(named_pipe_auth_req, &req); 135 } 136 137 if (strcmp(NAMED_PIPE_AUTH_MAGIC, req.magic) != 0) { 138 DEBUG(2, ("named_pipe_auth_req: invalid magic '%s' != %s\n", 139 req.magic, NAMED_PIPE_AUTH_MAGIC)); 140 rep.status = NT_STATUS_INVALID_PARAMETER; 141 goto reply; 142 } 143 144 switch (req.level) { 145 case 0: 146 /* 147 * anon connection, we don't create a session info 148 * and leave it NULL 149 */ 150 rep.level = 0; 151 rep.status = NT_STATUS_OK; 152 break; 153 case 1: 154 val.sam3 = &req.info.info1; 155 156 rep.level = 1; 157 rep.status = make_server_info_netlogon_validation(pipe_conn, 158 "TODO", 159 3, &val, 160 &server_info); 161 if (!NT_STATUS_IS_OK(rep.status)) { 162 DEBUG(2, ("make_server_info_netlogon_validation returned " 163 "%s\n", nt_errstr(rep.status))); 164 goto reply; 165 } 166 167 /* setup the session_info on the connection */ 168 rep.status = auth_generate_session_info(conn, 169 conn->event.ctx, 170 conn->lp_ctx, 171 server_info, 172 &conn->session_info); 173 if (!NT_STATUS_IS_OK(rep.status)) { 174 DEBUG(2, ("auth_generate_session_info failed: %s\n", 175 nt_errstr(rep.status))); 176 goto reply; 177 } 178 179 break; 180 case 2: 181 rep.level = 2; 182 rep.info.info2.file_type = FILE_TYPE_MESSAGE_MODE_PIPE; 183 rep.info.info2.device_state = 0xff | 0x0400 | 0x0100; 184 rep.info.info2.allocation_size = 4096; 185 186 if (!req.info.info2.sam_info3) { 187 /* 188 * anon connection, we don't create a session info 189 * and leave it NULL 190 */ 191 rep.status = NT_STATUS_OK; 192 break; 193 } 194 195 val.sam3 = req.info.info2.sam_info3; 196 197 rep.status = make_server_info_netlogon_validation(pipe_conn, 198 val.sam3->base.account_name.string, 199 3, &val, &server_info); 200 if (!NT_STATUS_IS_OK(rep.status)) { 201 DEBUG(2, ("make_server_info_netlogon_validation returned " 202 "%s\n", nt_errstr(rep.status))); 203 goto reply; 204 } 205 206 /* setup the session_info on the connection */ 207 rep.status = auth_generate_session_info(conn, 208 conn->event.ctx, 209 conn->lp_ctx, 210 server_info, 211 &conn->session_info); 212 if (!NT_STATUS_IS_OK(rep.status)) { 213 DEBUG(2, ("auth_generate_session_info failed: %s\n", 214 nt_errstr(rep.status))); 215 goto reply; 216 } 217 218 conn->session_info->session_key = data_blob_const(req.info.info2.session_key, 219 req.info.info2.session_key_length); 220 talloc_steal(conn->session_info, req.info.info2.session_key); 221 222 break; 223 case 3: 224 rep.level = 3; 225 rep.info.info3.file_type = FILE_TYPE_MESSAGE_MODE_PIPE; 226 rep.info.info3.device_state = 0xff | 0x0400 | 0x0100; 227 rep.info.info3.allocation_size = 4096; 228 229 if (!req.info.info3.sam_info3) { 230 /* 231 * anon connection, we don't create a session info 232 * and leave it NULL 233 */ 234 rep.status = NT_STATUS_OK; 235 break; 236 } 237 238 val.sam3 = req.info.info3.sam_info3; 239 240 rep.status = make_server_info_netlogon_validation(pipe_conn, 241 val.sam3->base.account_name.string, 242 3, &val, &server_info); 243 if (!NT_STATUS_IS_OK(rep.status)) { 244 DEBUG(2, ("make_server_info_netlogon_validation returned " 245 "%s\n", nt_errstr(rep.status))); 246 goto reply; 247 } 248 249 /* setup the session_info on the connection */ 250 rep.status = auth_generate_session_info(conn, 251 conn->event.ctx, 252 conn->lp_ctx, 253 server_info, 254 &conn->session_info); 255 if (!NT_STATUS_IS_OK(rep.status)) { 256 DEBUG(2, ("auth_generate_session_info failed: %s\n", 257 nt_errstr(rep.status))); 258 goto reply; 259 } 260 261 if (req.info.info3.gssapi_delegated_creds_length) { 262 OM_uint32 minor_status; 263 gss_buffer_desc cred_token; 264 gss_cred_id_t cred_handle; 265 int ret; 266 267 DEBUG(10, ("named_pipe_auth: delegated credentials supplied by client\n")); 268 269 cred_token.value = req.info.info3.gssapi_delegated_creds; 270 cred_token.length = req.info.info3.gssapi_delegated_creds_length; 271 272 ret = gss_import_cred(&minor_status, 273 &cred_token, 274 &cred_handle); 275 if (ret != GSS_S_COMPLETE) { 276 rep.status = NT_STATUS_INTERNAL_ERROR; 277 goto reply; 278 } 279 280 conn->session_info->credentials = cli_credentials_init(conn->session_info); 281 if (!conn->session_info->credentials) { 282 rep.status = NT_STATUS_NO_MEMORY; 283 goto reply; 284 } 285 286 cli_credentials_set_conf(conn->session_info->credentials, 287 conn->lp_ctx); 288 /* Just so we don't segfault trying to get at a username */ 289 cli_credentials_set_anonymous(conn->session_info->credentials); 290 291 ret = cli_credentials_set_client_gss_creds(conn->session_info->credentials, 292 conn->event.ctx, 293 conn->lp_ctx, 294 cred_handle, 295 CRED_SPECIFIED); 296 if (ret) { 297 rep.status = NT_STATUS_INTERNAL_ERROR; 298 goto reply; 299 } 300 301 /* This credential handle isn't useful for password authentication, so ensure nobody tries to do that */ 302 cli_credentials_set_kerberos_state(conn->session_info->credentials, 303 CRED_MUST_USE_KERBEROS); 304 } 305 306 conn->session_info->session_key = data_blob_const(req.info.info3.session_key, 307 req.info.info3.session_key_length); 308 talloc_steal(conn->session_info, req.info.info3.session_key); 309 310 break; 311 default: 312 DEBUG(2, ("named_pipe_auth_req: unknown level %u\n", 313 req.level)); 314 rep.level = 0; 315 rep.status = NT_STATUS_INVALID_LEVEL; 316 goto reply; 317 } 318 319 reply: 320 /* create the output */ 321 ndr_err = ndr_push_struct_blob(&rep_blob, pipe_conn, 322 lp_iconv_convenience(conn->lp_ctx), 323 &rep, 324 (ndr_push_flags_fn_t)ndr_push_named_pipe_auth_rep); 325 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 326 status = ndr_map_error2ntstatus(ndr_err); 327 DEBUG(2, ("Could not marshall named_pipe_auth_rep: %s\n", 328 nt_errstr(status))); 329 return status; 330 } 331 332 DEBUG(10,("named_pipe_auth reply[%u]\n", (unsigned)rep_blob.length)); 333 dump_data(11, rep_blob.data, rep_blob.length); 334 if (DEBUGLVL(10)) { 335 NDR_PRINT_DEBUG(named_pipe_auth_rep, &rep); 336 } 337 338 pipe_conn->status = rep.status; 339 status = packet_send_callback(pipe_conn->packet, rep_blob, 340 named_pipe_handover_connection, 341 pipe_conn); 342 if (!NT_STATUS_IS_OK(status)) { 343 DEBUG(0, ("packet_send_callback returned %s\n", 344 nt_errstr(status))); 345 return status; 346 } 347 348 return NT_STATUS_OK; 143 DEBUG(10, ("named pipe connection [%s] established\n", 144 conn->ops->name)); 145 146 talloc_free(tmp_ctx); 147 return; 148 149 out: 150 talloc_free(tmp_ctx); 151 if (!reason) { 152 reason = "Internal error"; 153 } 154 stream_terminate_connection(conn, reason); 349 155 } 350 156 … … 354 160 static void named_pipe_recv(struct stream_connection *conn, uint16_t flags) 355 161 { 356 struct named_pipe_connection *pipe_conn = talloc_get_type( 357 conn->private_data, struct named_pipe_connection); 358 359 DEBUG(10,("named_pipe_recv\n")); 360 361 packet_recv(pipe_conn->packet); 162 stream_terminate_connection(conn, "named_pipe_recv: called"); 362 163 } 363 164 … … 367 168 static void named_pipe_send(struct stream_connection *conn, uint16_t flags) 368 169 { 369 struct named_pipe_connection *pipe_conn = talloc_get_type( 370 conn->private_data, struct named_pipe_connection); 371 372 packet_queue_run(pipe_conn->packet); 373 } 374 375 /* 376 handle socket recv errors 377 */ 378 static void named_pipe_recv_error(void *private_data, NTSTATUS status) 379 { 380 struct named_pipe_connection *pipe_conn = talloc_get_type( 381 private_data, struct named_pipe_connection); 382 383 stream_terminate_connection(pipe_conn->connection, nt_errstr(status)); 384 } 385 386 static NTSTATUS named_pipe_full_request(void *private_data, DATA_BLOB blob, size_t *size) 387 { 388 if (blob.length < 8) { 389 return STATUS_MORE_ENTRIES; 390 } 391 392 if (memcmp(NAMED_PIPE_AUTH_MAGIC, &blob.data[4], 4) != 0) { 393 DEBUG(0,("named_pipe_full_request: wrong protocol\n")); 394 *size = blob.length; 395 /* the error will be handled in named_pipe_recv_auth_request */ 396 return NT_STATUS_OK; 397 } 398 399 *size = 4 + RIVAL(blob.data, 0); 400 if (*size > blob.length) { 401 return STATUS_MORE_ENTRIES; 402 } 403 404 return NT_STATUS_OK; 405 } 406 407 static void named_pipe_accept(struct stream_connection *conn) 408 { 409 struct named_pipe_socket *pipe_sock = talloc_get_type( 410 conn->private_data, struct named_pipe_socket); 411 struct named_pipe_connection *pipe_conn; 412 413 DEBUG(5,("named_pipe_accept\n")); 414 415 pipe_conn = talloc_zero(conn, struct named_pipe_connection); 416 if (!pipe_conn) { 417 stream_terminate_connection(conn, "out of memory"); 418 return; 419 } 420 421 pipe_conn->packet = packet_init(pipe_conn); 422 if (!pipe_conn->packet) { 423 stream_terminate_connection(conn, "out of memory"); 424 return; 425 } 426 packet_set_private(pipe_conn->packet, pipe_conn); 427 packet_set_socket(pipe_conn->packet, conn->socket); 428 packet_set_callback(pipe_conn->packet, named_pipe_recv_auth_request); 429 packet_set_full_request(pipe_conn->packet, named_pipe_full_request); 430 packet_set_error_handler(pipe_conn->packet, named_pipe_recv_error); 431 packet_set_event_context(pipe_conn->packet, conn->event.ctx); 432 packet_set_fde(pipe_conn->packet, conn->event.fde); 433 packet_set_serialise(pipe_conn->packet); 434 packet_set_initial_read(pipe_conn->packet, 8); 435 436 pipe_conn->pipe_sock = pipe_sock; 437 438 pipe_conn->connection = conn; 439 conn->private_data = pipe_conn; 170 stream_terminate_connection(conn, "named_pipe_send: called"); 440 171 } 441 172 … … 447 178 }; 448 179 449 NTSTATUS stream_setup_named_pipe(struct tevent_context *event_context, 450 struct loadparm_context *lp_ctx, 451 const struct model_ops *model_ops, 452 const struct stream_server_ops *stream_ops, 453 const char *pipe_name, 454 void *private_data) 180 NTSTATUS tstream_setup_named_pipe(TALLOC_CTX *mem_ctx, 181 struct tevent_context *event_context, 182 struct loadparm_context *lp_ctx, 183 const struct model_ops *model_ops, 184 const struct stream_server_ops *stream_ops, 185 const char *pipe_name, 186 void *private_data) 455 187 { 456 188 char *dirname; … … 458 190 NTSTATUS status = NT_STATUS_NO_MEMORY;; 459 191 460 pipe_sock = talloc( event_context, struct named_pipe_socket);192 pipe_sock = talloc(mem_ctx, struct named_pipe_socket); 461 193 if (pipe_sock == NULL) { 462 194 goto fail; … … 469 201 } 470 202 471 dirname = talloc_asprintf(pipe_sock, "%s/np", lp_ncalrpc_dir(lp_ctx)); 203 if (!directory_create_or_exist(lpcfg_ncalrpc_dir(lp_ctx), geteuid(), 0755)) { 204 status = map_nt_error_from_unix(errno); 205 DEBUG(0,(__location__ ": Failed to create ncalrpc pipe directory '%s' - %s\n", 206 lpcfg_ncalrpc_dir(lp_ctx), nt_errstr(status))); 207 goto fail; 208 } 209 210 dirname = talloc_asprintf(pipe_sock, "%s/np", lpcfg_ncalrpc_dir(lp_ctx)); 472 211 if (dirname == NULL) { 473 212 goto fail; … … 493 232 talloc_free(dirname); 494 233 495 pipe_sock->ops = stream_ops; 496 pipe_sock->private_data = talloc_reference(pipe_sock, private_data); 497 498 status = stream_setup_socket(event_context, 234 pipe_sock->ops = stream_ops; 235 pipe_sock->private_data = private_data; 236 237 status = stream_setup_socket(pipe_sock, 238 event_context, 499 239 lp_ctx, 500 240 model_ops, -
vendor/current/source4/smbd/service_stream.c
r414 r740 27 27 #include "cluster/cluster.h" 28 28 #include "param/param.h" 29 #include "../lib/tsocket/tsocket.h" 29 30 30 31 /* the range of ports to try for dcerpc over tcp endpoints */ … … 98 99 } 99 100 100 static void stream_io_handler_fde(struct tevent_context *ev, struct tevent_fd *fde, 101 void stream_io_handler_fde(struct tevent_context *ev, struct tevent_fd *fde, 101 102 uint16_t flags, void *private_data) 102 103 { … … 121 122 struct loadparm_context *lp_ctx, 122 123 const struct model_ops *model_ops, 123 struct socket_context *sock,124 124 const struct stream_server_ops *stream_ops, 125 125 struct messaging_context *msg_ctx, … … 132 132 NT_STATUS_HAVE_NO_MEMORY(srv_conn); 133 133 134 talloc_steal(srv_conn, sock);135 136 134 srv_conn->private_data = private_data; 137 135 srv_conn->model_ops = model_ops; 138 srv_conn->socket = sock;136 srv_conn->socket = NULL; 139 137 srv_conn->server_id = cluster_id(0, 0); 140 138 srv_conn->ops = stream_ops; … … 142 140 srv_conn->event.ctx = ev; 143 141 srv_conn->lp_ctx = lp_ctx; 144 srv_conn->event.fde = tevent_add_fd(ev, srv_conn, socket_get_fd(sock), 145 TEVENT_FD_READ, 146 stream_io_handler_fde, srv_conn); 147 if (!srv_conn->event.fde) { 148 talloc_free(srv_conn); 149 return NT_STATUS_NO_MEMORY; 150 } 142 srv_conn->event.fde = NULL; 151 143 152 144 *_srv_conn = srv_conn; … … 165 157 struct stream_socket *stream_socket = talloc_get_type(private_data, struct stream_socket); 166 158 struct stream_connection *srv_conn; 167 struct socket_address *c, *s;168 159 169 160 srv_conn = talloc_zero(ev, struct stream_connection); … … 183 174 srv_conn->lp_ctx = lp_ctx; 184 175 185 if (!socket_check_access(sock, "smbd", lp _hostsallow(NULL, lp_default_service(lp_ctx)), lp_hostsdeny(NULL, lp_default_service(lp_ctx)))) {176 if (!socket_check_access(sock, "smbd", lpcfg_hostsallow(NULL, lpcfg_default_service(lp_ctx)), lpcfg_hostsdeny(NULL, lpcfg_default_service(lp_ctx)))) { 186 177 stream_terminate_connection(srv_conn, "denied by access rules"); 187 178 return; … … 197 188 /* setup to receive internal messages on this connection */ 198 189 srv_conn->msg_ctx = messaging_init(srv_conn, 199 lp_messaging_path(srv_conn, lp_ctx), 200 srv_conn->server_id, 201 lp_iconv_convenience(lp_ctx), 202 ev); 190 lpcfg_messaging_path(srv_conn, lp_ctx), 191 srv_conn->server_id, ev); 203 192 if (!srv_conn->msg_ctx) { 204 193 stream_terminate_connection(srv_conn, "messaging_init() failed"); … … 206 195 } 207 196 208 c = socket_get_peer_addr(sock, ev); 209 s = socket_get_my_addr(sock, ev); 210 if (s && c) { 197 srv_conn->remote_address = socket_get_remote_addr(srv_conn->socket, srv_conn); 198 if (!srv_conn->remote_address) { 199 stream_terminate_connection(srv_conn, "socket_get_remote_addr() failed"); 200 return; 201 } 202 203 srv_conn->local_address = socket_get_local_addr(srv_conn->socket, srv_conn); 204 if (!srv_conn->local_address) { 205 stream_terminate_connection(srv_conn, "socket_get_local_addr() failed"); 206 return; 207 } 208 209 { 210 TALLOC_CTX *tmp_ctx; 211 211 const char *title; 212 title = talloc_asprintf(s, "conn[%s] c[%s:%u] s[%s:%u] server_id[%s]", 212 213 tmp_ctx = talloc_new(srv_conn); 214 215 title = talloc_asprintf(tmp_ctx, "conn[%s] c[%s] s[%s] server_id[%s]", 213 216 stream_socket->ops->name, 214 c->addr, c->port, s->addr, s->port, 215 cluster_id_string(s, server_id)); 217 tsocket_address_string(srv_conn->remote_address, tmp_ctx), 218 tsocket_address_string(srv_conn->local_address, tmp_ctx), 219 cluster_id_string(tmp_ctx, server_id)); 216 220 if (title) { 217 221 stream_connection_set_title(srv_conn, title); 218 222 } 219 } 220 talloc_free(c); 221 talloc_free(s); 223 talloc_free(tmp_ctx); 224 } 222 225 223 226 /* we're now ready to start receiving events on this stream */ … … 240 243 connection. When done, it calls stream_new_connection() 241 244 with the newly created socket */ 242 stream_socket->model_ops->accept_connection(ev, stream_socket->lp_ctx, 245 stream_socket->model_ops->accept_connection(ev, stream_socket->lp_ctx, 243 246 stream_socket->sock, 244 247 stream_new_connection, stream_socket); … … 253 256 to the socket implementation - JRV20070903 254 257 */ 255 NTSTATUS stream_setup_socket(struct tevent_context *event_context, 258 NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx, 259 struct tevent_context *event_context, 256 260 struct loadparm_context *lp_ctx, 257 261 const struct model_ops *model_ops, … … 269 273 int i; 270 274 271 stream_socket = talloc_zero( event_context, struct stream_socket);275 stream_socket = talloc_zero(mem_ctx, struct stream_socket); 272 276 NT_STATUS_HAVE_NO_MEMORY(stream_socket); 273 277 -
vendor/current/source4/smbd/service_stream.h
r414 r740 24 24 #define __SERVICE_STREAM_H__ 25 25 26 #include "librpc/gen_ndr/server_id .h"26 #include "librpc/gen_ndr/server_id4.h" 27 27 28 28 /* modules can use the following to determine if the interface has changed … … 51 51 struct loadparm_context *lp_ctx; 52 52 53 struct tstream_context *tstream; 54 struct tsocket_address *local_address; 55 struct tsocket_address *remote_address; 56 53 57 /* 54 58 * this transport layer session info, normally NULL … … 71 75 }; 72 76 77 void stream_terminate_connection(struct stream_connection *srv_conn, const char *reason); 78 73 79 #endif /* __SERVICE_STREAM_H__ */ -
vendor/current/source4/smbd/service_task.c
r414 r740 24 24 #include "lib/messaging/irpc.h" 25 25 #include "param/param.h" 26 #include "librpc/gen_ndr/ndr_irpc .h"26 #include "librpc/gen_ndr/ndr_irpc_c.h" 27 27 28 28 /* … … 36 36 37 37 if (fatal) { 38 struct dcerpc_binding_handle *irpc_handle; 38 39 struct samba_terminate r; 39 struct server_id *sid;40 40 41 sid = irpc_servers_byname(task->msg_ctx, task, "samba");42 43 r.in.reason = reason;44 IRPC_CALL(task->msg_ctx, sid[0],45 irpc, SAMBA_TERMINATE,46 &r, NULL);41 irpc_handle = irpc_binding_handle_by_name(task, task->msg_ctx, 42 "samba", &ndr_table_irpc); 43 if (irpc_handle != NULL) { 44 r.in.reason = reason; 45 dcerpc_samba_terminate_r(irpc_handle, task, &r); 46 } 47 47 } 48 48 … … 80 80 81 81 task->msg_ctx = messaging_init(task, 82 lp _messaging_path(task, task->lp_ctx),82 lpcfg_messaging_path(task, task->lp_ctx), 83 83 task->server_id, 84 lp_iconv_convenience(task->lp_ctx),85 84 task->event_ctx); 86 85 if (!task->msg_ctx) { -
vendor/current/source4/smbd/service_task.h
r414 r740 23 23 #define __SERVICE_TASK_H__ 24 24 25 #include "librpc/gen_ndr/server_id .h"25 #include "librpc/gen_ndr/server_id4.h" 26 26 27 27 struct task_server {
Note:
See TracChangeset
for help on using the changeset viewer.