Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

Location:
vendor/current/source4/smbd
Files:
2 added
3 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/smbd/pidfile.c

    r414 r740  
    3939        char *pidFile;
    4040
    41         asprintf(&pidFile, "%s/%s.pid", piddir, name);
     41        if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) {
     42                return 0;
     43        }
    4244
    4345        fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644);
     
    8688        pid_t pid;
    8789
    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        }
    8994
    9095        pid = pidfile_pid(piddir, name);
  • vendor/current/source4/smbd/process_model.c

    r414 r740  
    2323#include "param/param.h"
    2424
    25 static const struct model_ops *process_model_byname(const char *name);
     25/* the list of currently registered process models */
     26static struct process_model {
     27        const struct model_ops *ops;
     28        bool initialised;
     29} *models = NULL;
     30static int num_models;
     31
     32
     33/*
     34  return the operations structure for a named backend of the specified type
     35*/
     36static 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
    2649
    2750/*
    2851  setup the events for the chosen process model
    2952*/
    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)
    3154{
    32         const struct model_ops *ops;
     55        struct process_model *m;
    3356
    34         ops = process_model_byname(model);
    35         if (!ops) {
     57        m = process_model_byname(model);
     58        if (m == NULL) {
    3659                DEBUG(0,("Unknown process model '%s'\n", model));
    3760                exit(-1);
    3861        }
    3962
    40         ops->model_init(ev);
     63        if (!m->initialised) {
     64                m->initialised = true;
     65                m->ops->model_init();
     66        }
    4167
    42         return ops;
     68        return m->ops;
    4369}
    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;
    5070
    5171/*
     
    5575  structure for this backend. 
    5676*/
    57 _PUBLIC_ NTSTATUS register_process_model(const void *_ops)
     77_PUBLIC_ NTSTATUS register_process_model(const struct model_ops *ops)
    5878{
    59         const struct model_ops *ops = _ops;
    60 
    6179        if (process_model_byname(ops->name) != NULL) {
    6280                /* its already registered! */
     
    6684        }
    6785
    68         models = realloc_p(models, struct process_model, num_models+1);
     86        models = talloc_realloc(NULL, models, struct process_model, num_models+1);
    6987        if (!models) {
    7088                smb_panic("out of memory in register_process_model");
    7189        }
    7290
    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;
    7593
    7694        num_models++;
    7795
    78         DEBUG(3,("PROCESS_MODEL '%s' registered\n",
    79                  ops->name));
     96        DEBUG(3,("PROCESS_MODEL '%s' registered\n", ops->name));
    8097
    8198        return NT_STATUS_OK;
     
    84101_PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
    85102{
    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;
    90105        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;
    92108
     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       
    93116        run_init_functions(static_init);
    94117        run_init_functions(shared_init);
    95118
    96119        talloc_free(shared_init);
    97        
     120
    98121        return NT_STATUS_OK;
    99 }
    100 
    101 /*
    102   return the operations structure for a named backend of the specified type
    103 */
    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;
    115122}
    116123
  • vendor/current/source4/smbd/process_model.h

    r414 r740  
    2727#include "lib/socket/socket.h"
    2828#include "smbd/service.h"
     29#include "smbd/process_model_proto.h"
    2930
    3031/* modules can use the following to determine if the interface has changed
     
    4243
    4344        /* called at startup when the model is selected */
    44         void (*model_init)(struct tevent_context *);
     45        void (*model_init)(void);
    4546
    4647        /* function to accept new connection */
     
    5657        /* function to create a task */
    5758        void (*new_task)(struct tevent_context *,
    58                          struct loadparm_context *lp_ctx, 
     59                         struct loadparm_context *lp_ctx,
    5960                         const char *service_name,
    6061                         void (*)(struct tevent_context *,
     
    6465
    6566        /* 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,
    6768                          const char *reason);
    6869
     
    7980extern const struct model_ops single_ops;
    8081
    81 const struct model_ops *process_model_startup(struct tevent_context *ev, const char *model);
    82 NTSTATUS register_process_model(const void *_ops);
     82const struct model_ops *process_model_startup(const char *model);
     83NTSTATUS register_process_model(const struct model_ops *ops);
    8384NTSTATUS process_model_init(struct loadparm_context *lp_ctx);
    8485
  • vendor/current/source4/smbd/process_prefork.c

    r414 r740  
    2626#include "includes.h"
    2727#include "lib/events/events.h"
    28 #include "../tdb/include/tdb.h"
    2928#include "lib/socket/socket.h"
    3029#include "smbd/process_model.h"
    31 #include "param/secrets.h"
    3230#include "system/filesys.h"
    3331#include "cluster/cluster.h"
    3432#include "param/param.h"
     33#include "ldb_wrap.h"
    3534
    3635#ifdef HAVE_SETPROCTITLE
     
    5049  called when the process model is selected
    5150*/
    52 static void prefork_model_init(struct tevent_context *ev)
     51static void prefork_model_init(void)
    5352{
    5453        signal(SIGCHLD, SIG_IGN);
     
    5756static void prefork_reload_after_fork(void)
    5857{
    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();
    6359
    6460        /* Ensure that the forked children do not expose identical random streams */
     
    9894                             struct loadparm_context *lp_ctx,
    9995                             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 *),
    10197                             void *private_data)
    10298{
     
    127123        talloc_free(ev);
    128124
    129         setproctitle("task %s server_id[%d]", service_name, pid);
     125        setproctitle("task %s server_id[%d]", service_name, (int)pid);
    130126
    131127        prefork_reload_after_fork();
     
    134130        new_task_fn(ev2, lp_ctx, cluster_id(pid, 0), private_data);
    135131
    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);
    137133        if (num_children == 0) {
    138134
     
    156152                } else {
    157153                        pid = getpid();
    158                         setproctitle("task %s server_id[%d]", service_name, pid);
     154                        setproctitle("task %s server_id[%d]", service_name, (int)pid);
    159155
    160156                        prefork_reload_after_fork();
     
    175171        /* But we need a events system to handle reaping children */
    176172        ev_parent = s4_event_context_init(NULL);
    177        
     173
    178174        /* TODO: Handle some events... */
    179175       
     
    190186
    191187/* called when a task goes down */
    192 _NORETURN_ static void prefork_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason)
     188static void prefork_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason)
    193189{
    194190        DEBUG(2,("prefork_terminate: reason[%s]\n",reason));
  • vendor/current/source4/smbd/process_single.c

    r414 r740  
    3030  called when the process model is selected
    3131*/
    32 static void single_model_init(struct tevent_context *ev)
     32static void single_model_init(void)
    3333{
    3434}
     
    5656
    5757                   We can only be here if woken up from select, due to
    58                    an incomming connection.
     58                   an incoming connection.
    5959
    6060                   We need to throttle things until the system clears
     
    7272        /* The cluster_id(0, fd) cannot collide with the incrementing
    7373         * 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,
    7575                 cluster_id(0, socket_get_fd(connected_socket)), private_data);
    7676}
     
    8080*/
    8181static void single_new_task(struct tevent_context *ev,
    82                             struct loadparm_context *lp_ctx, 
     82                            struct loadparm_context *lp_ctx,
    8383                            const char *service_name,
    8484                            void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *),
     
    9898
    9999/* called when a task goes down */
    100 static void single_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason) 
     100static void single_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason)
    101101{
    102         DEBUG(2,("single_terminate: reason[%s]\n",reason));
     102        DEBUG(3,("single_terminate: reason[%s]\n",reason));
    103103}
    104104
  • vendor/current/source4/smbd/process_standard.c

    r414 r740  
    2424#include "includes.h"
    2525#include "lib/events/events.h"
    26 #include "../tdb/include/tdb.h"
    2726#include "smbd/process_model.h"
    2827#include "system/filesys.h"
    2928#include "cluster/cluster.h"
    3029#include "param/param.h"
     30#include "ldb_wrap.h"
    3131
    3232#ifdef HAVE_SETPROCTITLE
     
    5151  called when the process model is selected
    5252*/
    53 static void standard_model_init(struct tevent_context *ev)
     53static void standard_model_init(void)
    5454{
    5555        pipe(child_pipe);
     
    8181        struct socket_context *sock2;
    8282        pid_t pid;
    83         struct tevent_context *ev2;
    8483        struct socket_address *c, *s;
    8584
     
    107106
    108107        /* 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        }
    116112
    117113        /* this will free all the listening sockets and all state that
    118114           is not associated with this new connection */
    119115        talloc_free(sock);
    120         talloc_free(ev);
    121116
    122117        /* we don't care if the dup fails, as its only a select()
     
    125120                       
    126121        /* 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,
    132125                      standard_pipe_handler, NULL);
    133126        close(child_pipe[1]);
     
    137130
    138131        /* setup the process title */
    139         c = socket_get_peer_addr(sock2, ev2);
    140         s = socket_get_my_addr(sock2, ev2);
     132        c = socket_get_peer_addr(sock2, ev);
     133        s = socket_get_my_addr(sock2, ev);
    141134        if (s && c) {
    142135                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);
    144137        }
    145138        talloc_free(c);
     
    147140
    148141        /* setup this new connection.  Cluster ID is PID based for this process modal */
    149         new_conn(ev2, lp_ctx, sock2, cluster_id(pid, 0), private_data);
     142        new_conn(ev, lp_ctx, sock2, cluster_id(pid, 0), private_data);
    150143
    151144        /* we can't return to the top level here, as that event context is gone,
    152145           so we now process events in the new event context until there are no
    153146           more to process */     
    154         event_loop_wait(ev2);
    155 
    156         talloc_free(ev2);
     147        event_loop_wait(ev);
     148
     149        talloc_free(ev);
    157150        exit(0);
    158151}
     
    164157                              struct loadparm_context *lp_ctx,
    165158                              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 *),
    167160                              void *private_data)
    168161{
    169162        pid_t pid;
    170         struct tevent_context *ev2;
    171163
    172164        pid = fork();
     
    179171        pid = getpid();
    180172
    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 that
    185            encapsulates the context it needs for this new connection -
    186            everything else will be freed */
    187         talloc_steal(ev2, private_data);
    188 
    189173        /* this will free all the listening sockets and all state that
    190174           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(ev2, 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,
    199183                      standard_pipe_handler, NULL);
    200184        close(child_pipe[1]);
     
    203187        set_need_random_reseed();
    204188
    205         setproctitle("task %s server_id[%d]", service_name, pid);
     189        setproctitle("task %s server_id[%d]", service_name, (int)pid);
    206190
    207191        /* setup this new task.  Cluster ID is PID based for this process modal */
    208         new_task(ev2, lp_ctx, cluster_id(pid, 0), private_data);
     192        new_task(ev, lp_ctx, cluster_id(pid, 0), private_data);
    209193
    210194        /* we can't return to the top level here, as that event context is gone,
    211195           so we now process events in the new event context until there are no
    212196           more to process */     
    213         event_loop_wait(ev2);
    214 
    215         talloc_free(ev2);
     197        event_loop_wait(ev);
     198
     199        talloc_free(ev);
    216200        exit(0);
    217201}
     
    219203
    220204/* 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,
    222206                                          const char *reason)
    223207{
    224208        DEBUG(2,("standard_terminate: reason[%s]\n",reason));
     209
     210        talloc_free(ev);
    225211
    226212        /* this reload_charcnv() has the effect of freeing the iconv context memory,
    227213           which makes leak checking easier */
    228214        reload_charcnv(lp_ctx);
    229 
    230         talloc_free(ev);
    231215
    232216        /* terminate this process */
  • vendor/current/source4/smbd/process_thread.c

    r414 r740  
    3030#include "system/wait.h"
    3131#include "system/filesys.h"
     32#include "system/time.h"
    3233#include "lib/events/events.h"
    3334#include "lib/util/dlinklist.h"
     
    6364*/
    6465static void thread_accept_connection(struct tevent_context *ev,
    65                                      struct loadparm_context *lp_ctx, 
     66                                     struct loadparm_context *lp_ctx,
    6667                                     struct socket_context *sock,
    6768                                     void (*new_conn)(struct tevent_context *,
     
    133134        struct new_task_state *new_task = talloc_get_type(thread_parm, struct new_task_state);
    134135
    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(),
    136137                           new_task->private_data);
    137138
     
    189190
    190191/* called when a task goes down */
    191 static void thread_terminate(struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, const char *reason) 
     192static void thread_terminate(struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, const char *reason)
    192193{
    193194        DEBUG(10,("thread_terminate: reason[%s]\n",reason));
     
    234235}
    235236
    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);
     237static void mutex_start_timer(struct timespec *tp1)
     238{
     239        clock_gettime_mono(tp1);
     240}
     241
     242static double mutex_end_timer(struct timespec tp1)
     243{
     244        struct timespec tp2;
     245
     246        clock_gettime_mono(&tp2);
    245247        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);
    247249}
    248250
     
    255257        int rc;
    256258        double t;
    257         struct timeval tp1;
     259        struct timespec tp1;
    258260        /* Test below is ONLY for debugging */
    259261        if ((rc = pthread_mutex_trylock(mutex))) {
     
    317319        int rc;
    318320        double t;
    319         struct timeval tp1;
     321        struct timespec tp1;
    320322        /* Test below is ONLY for debugging */
    321323        if ((rc = pthread_rwlock_tryrdlock(rwlock))) {
     
    346348        int rc;
    347349        double t;
    348         struct timeval tp1;
     350        struct timespec tp1;
    349351        /* Test below is ONLY for debugging */
    350352        if ((rc = pthread_rwlock_trywrlock(rwlock))) {
     
    460462{
    461463#ifdef SIGSEGV
    462         CatchSignal(SIGSEGV,SIGNAL_CAST thread_sig_fault);
     464        CatchSignal(SIGSEGV, thread_sig_fault);
    463465#endif
    464466#ifdef SIGBUS
    465         CatchSignal(SIGBUS,SIGNAL_CAST thread_sig_fault);
     467        CatchSignal(SIGBUS, thread_sig_fault);
    466468#endif
    467469#ifdef SIGABRT
    468         CatchSignal(SIGABRT,SIGNAL_CAST thread_sig_fault);
     470        CatchSignal(SIGABRT, thread_sig_fault);
    469471#endif
    470472}
     
    510512  called when the process model is selected
    511513*/
    512 static void thread_model_init(struct tevent_context *event_context)
     514static void thread_model_init(void)
    513515{
    514516        struct mutex_ops m_ops;
     
    519521
    520522        pthread_key_create(&title_key, NULL);
    521         pthread_setspecific(title_key, talloc_strdup(event_context, ""));
     523        pthread_setspecific(title_key, NULL);
    522524
    523525        /* register mutex/rwlock handlers */
  • vendor/current/source4/smbd/samba.8.xml

    r414 r740  
    11<?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">
    33<refentry id="samba.8">
    44
  • vendor/current/source4/smbd/server.c

    r414 r740  
    3232#include "ntptr/ntptr.h"
    3333#include "auth/gensec/gensec.h"
     34#include "libcli/auth/schannel.h"
    3435#include "smbd/process_model.h"
    3536#include "param/secrets.h"
     
    4142#include "librpc/gen_ndr/ndr_irpc.h"
    4243#include "cluster/cluster.h"
     44#include "dynconfig/dynconfig.h"
    4345
    4446/*
     
    116118#endif
    117119        DEBUG(0,("Exiting pid %d on SIGTERM\n", (int)getpid()));
    118         exit(0);
     120        exit(127);
    119121}
    120122
     
    141143
    142144        /* POSIX demands that signals are inherited. If the invoking process has
    143          * these signals masked, we will have problems, as we won't recieve them. */
     145         * these signals masked, we will have problems, as we won't receive them. */
    144146        BlockSignals(false, SIGHUP);
    145147        BlockSignals(false, SIGTERM);
     
    177179{
    178180        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        }
    180188        exit(0);
    181189}
    182190
    183191/*
    184   pre-open the sam ldb to ensure the schema has been loaded. This
    185   saves a lot of time in child processes 
     192  pre-open the key databases. This saves a lot of time in child
     193  processes
    186194 */
    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);
     195static 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() */
    193205}
    194206
     
    214226
    215227        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);
    220230        NT_STATUS_HAVE_NO_MEMORY(msg);
    221231
     
    229239
    230240
     241/*
     242  show build info
     243 */
     244static 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}
    231285
    232286/*
     
    239293        int opt;
    240294        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;
    256297        init_module_fn static_init[] = { STATIC_service_MODULES };
    257298        init_module_fn *shared_init;
     
    264305                OPT_DAEMON = 1000,
    265306                OPT_INTERACTIVE,
    266                 OPT_PROCESS_MODEL
     307                OPT_PROCESS_MODEL,
     308                OPT_SHOW_BUILD
    267309        };
    268310        struct poptOption long_options[] = {
     
    276318                {"maximum-runtime",0, POPT_ARG_INT, &max_runtime, 0,
    277319                 "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 },
    278321                POPT_COMMON_SAMBA
    279322                POPT_COMMON_VERSION
     
    293336                        model = poptGetOptArg(pc);
    294337                        break;
     338                case OPT_SHOW_BUILD:
     339                        show_build();
     340                        break;
    295341                default:
    296342                        fprintf(stderr, "\nInvalid option %s: %s\n\n",
    297343                                  poptBadOption(pc, 0), poptStrerror(opt));
    298344                        poptPrintUsage(pc, stderr, 0);
    299                         exit(1);
     345                        return 1;
    300346                }
    301347        }
     
    305351                          "Option -i|--interactive is not allowed together with -D|--daemon\n\n");
    306352                poptPrintUsage(pc, stderr, 0);
    307                 exit(1);
     353                return 1;
    308354        } else if (!opt_interactive) {
    309355                /* default is --daemon */
     
    321367
    322368        DEBUG(0,("%s version %s started.\n", binary_name, SAMBA_VERSION_STRING));
    323         DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2009\n"));
     369        DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2011\n"));
    324370
    325371        if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || sizeof(uint64_t) < 8) {
     
    327373                DEBUGADD(0,("sizeof(uint16_t) = %u, sizeof(uint32_t) %u, sizeof(uint64_t) = %u\n",
    328374                            (unsigned int)sizeof(uint16_t), (unsigned int)sizeof(uint32_t), (unsigned int)sizeof(uint64_t)));
    329                 exit(1);
     375                return 1;
    330376        }
    331377
    332378        if (opt_daemon) {
    333379                DEBUG(3,("Becoming a daemon.\n"));
    334                 become_daemon(true, false);
     380                become_daemon(true, false, false);
    335381        }
    336382
    337383        cleanup_tmp_files(cmdline_lp_ctx);
    338384
    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);
    344390
    345391        /* Do *not* remove this, until you have removed
     
    347393        /* Setup the SECRETS subsystem */
    348394        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                }
    350403        }
    351404
     
    393446
    394447        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                }
    395456                tevent_add_timer(event_ctx, event_ctx,
    396457                                 timeval_current_ofs(max_runtime, 0),
     
    399460        }
    400461
    401         prime_samdb_schema(event_ctx);
     462        prime_ldb_databases(event_ctx);
    402463
    403464        status = setup_parent_messaging(event_ctx, cmdline_lp_ctx);
     
    410471
    411472        status = server_service_startup(event_ctx, cmdline_lp_ctx, model,
    412                                         lp_server_services(cmdline_lp_ctx));
     473                                        lpcfg_server_services(cmdline_lp_ctx));
    413474        if (!NT_STATUS_IS_OK(status)) {
    414475                DEBUG(0,("Starting Services failed - %s\n", nt_errstr(status)));
  • vendor/current/source4/smbd/service.c

    r414 r740  
    8484        }
    8585
    86         model_ops = process_model_startup(event_ctx, model);
     86        model_ops = process_model_startup(model);
    8787        if (!model_ops) {
    8888                DEBUG(0,("process_model_startup('%s') failed\n", model));
  • vendor/current/source4/smbd/service_named_pipe.c

    r414 r740  
    2424#include "smbd/service.h"
    2525#include "param/param.h"
     26#include "auth/auth.h"
    2627#include "auth/session.h"
    2728#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"
    2932#include "librpc/gen_ndr/ndr_named_pipe_auth.h"
    3033#include "system/passwd.h"
     34#include "system/network.h"
    3135#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"
    3439
    3540struct named_pipe_socket {
     
    4045};
    4146
    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));
     47static void named_pipe_accept_done(struct tevent_req *subreq);
     48
     49static 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");
    6467                return;
    6568        }
    6669
    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
     84static 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        }
    76134
    77135        /*
     
    79137         * now that we have setup the transport session_info
    80138         */
     139        conn->ops = pipe_sock->ops;
     140        conn->private_data = pipe_sock->private_data;
    81141        conn->ops->accept_connection(conn);
    82142
    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
     149out:
     150        talloc_free(tmp_ctx);
     151        if (!reason) {
     152                reason = "Internal error";
     153        }
     154        stream_terminate_connection(conn, reason);
    349155}
    350156
     
    354160static void named_pipe_recv(struct stream_connection *conn, uint16_t flags)
    355161{
    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");
    362163}
    363164
     
    367168static void named_pipe_send(struct stream_connection *conn, uint16_t flags)
    368169{
    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");
    440171}
    441172
     
    447178};
    448179
    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)
     180NTSTATUS 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)
    455187{
    456188        char *dirname;
     
    458190        NTSTATUS status = NT_STATUS_NO_MEMORY;;
    459191
    460         pipe_sock = talloc(event_context, struct named_pipe_socket);
     192        pipe_sock = talloc(mem_ctx, struct named_pipe_socket);
    461193        if (pipe_sock == NULL) {
    462194                goto fail;
     
    469201        }
    470202
    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));
    472211        if (dirname == NULL) {
    473212                goto fail;
     
    493232        talloc_free(dirname);
    494233
    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,
    499239                                     lp_ctx,
    500240                                     model_ops,
  • vendor/current/source4/smbd/service_stream.c

    r414 r740  
    2727#include "cluster/cluster.h"
    2828#include "param/param.h"
     29#include "../lib/tsocket/tsocket.h"
    2930
    3031/* the range of ports to try for dcerpc over tcp endpoints */
     
    9899}
    99100
    100 static void stream_io_handler_fde(struct tevent_context *ev, struct tevent_fd *fde,
     101void stream_io_handler_fde(struct tevent_context *ev, struct tevent_fd *fde,
    101102                                  uint16_t flags, void *private_data)
    102103{
     
    121122                                     struct loadparm_context *lp_ctx,
    122123                                     const struct model_ops *model_ops,
    123                                      struct socket_context *sock,
    124124                                     const struct stream_server_ops *stream_ops,
    125125                                     struct messaging_context *msg_ctx,
     
    132132        NT_STATUS_HAVE_NO_MEMORY(srv_conn);
    133133
    134         talloc_steal(srv_conn, sock);
    135 
    136134        srv_conn->private_data  = private_data;
    137135        srv_conn->model_ops     = model_ops;
    138         srv_conn->socket        = sock;
     136        srv_conn->socket        = NULL;
    139137        srv_conn->server_id     = cluster_id(0, 0);
    140138        srv_conn->ops           = stream_ops;
     
    142140        srv_conn->event.ctx     = ev;
    143141        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;
    151143
    152144        *_srv_conn = srv_conn;
     
    165157        struct stream_socket *stream_socket = talloc_get_type(private_data, struct stream_socket);
    166158        struct stream_connection *srv_conn;
    167         struct socket_address *c, *s;
    168159
    169160        srv_conn = talloc_zero(ev, struct stream_connection);
     
    183174        srv_conn->lp_ctx        = lp_ctx;
    184175
    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)))) {
    186177                stream_terminate_connection(srv_conn, "denied by access rules");
    187178                return;
     
    197188        /* setup to receive internal messages on this connection */
    198189        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);
    203192        if (!srv_conn->msg_ctx) {
    204193                stream_terminate_connection(srv_conn, "messaging_init() failed");
     
    206195        }
    207196
    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;
    211211                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]",
    213216                                        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));
    216220                if (title) {
    217221                        stream_connection_set_title(srv_conn, title);
    218222                }
    219         }
    220         talloc_free(c);
    221         talloc_free(s);
     223                talloc_free(tmp_ctx);
     224        }
    222225
    223226        /* we're now ready to start receiving events on this stream */
     
    240243           connection.  When done, it calls stream_new_connection()
    241244           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,
    243246                                                    stream_socket->sock,
    244247                                                    stream_new_connection, stream_socket);
     
    253256         to the socket implementation - JRV20070903
    254257 */
    255 NTSTATUS stream_setup_socket(struct tevent_context *event_context,
     258NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
     259                             struct tevent_context *event_context,
    256260                             struct loadparm_context *lp_ctx,
    257261                             const struct model_ops *model_ops,
     
    269273        int i;
    270274
    271         stream_socket = talloc_zero(event_context, struct stream_socket);
     275        stream_socket = talloc_zero(mem_ctx, struct stream_socket);
    272276        NT_STATUS_HAVE_NO_MEMORY(stream_socket);
    273277
  • vendor/current/source4/smbd/service_stream.h

    r414 r740  
    2424#define __SERVICE_STREAM_H__
    2525
    26 #include "librpc/gen_ndr/server_id.h"
     26#include "librpc/gen_ndr/server_id4.h"
    2727
    2828/* modules can use the following to determine if the interface has changed
     
    5151        struct loadparm_context *lp_ctx;
    5252
     53        struct tstream_context *tstream;
     54        struct tsocket_address *local_address;
     55        struct tsocket_address *remote_address;
     56
    5357        /*
    5458         * this transport layer session info, normally NULL
     
    7175};
    7276
     77void stream_terminate_connection(struct stream_connection *srv_conn, const char *reason);
     78
    7379#endif /* __SERVICE_STREAM_H__ */
  • vendor/current/source4/smbd/service_task.c

    r414 r740  
    2424#include "lib/messaging/irpc.h"
    2525#include "param/param.h"
    26 #include "librpc/gen_ndr/ndr_irpc.h"
     26#include "librpc/gen_ndr/ndr_irpc_c.h"
    2727
    2828/*
     
    3636
    3737        if (fatal) {
     38                struct dcerpc_binding_handle *irpc_handle;
    3839                struct samba_terminate r;
    39                 struct server_id *sid;
    4040
    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                }
    4747        }
    4848
     
    8080
    8181        task->msg_ctx = messaging_init(task,
    82                                        lp_messaging_path(task, task->lp_ctx),
     82                                       lpcfg_messaging_path(task, task->lp_ctx),
    8383                                       task->server_id,
    84                                        lp_iconv_convenience(task->lp_ctx),
    8584                                       task->event_ctx);
    8685        if (!task->msg_ctx) {
  • vendor/current/source4/smbd/service_task.h

    r414 r740  
    2323#define __SERVICE_TASK_H__
    2424
    25 #include "librpc/gen_ndr/server_id.h"
     25#include "librpc/gen_ndr/server_id4.h"
    2626
    2727struct task_server {
Note: See TracChangeset for help on using the changeset viewer.