Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
143 deleted
95 edited
30 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/lib/access.c

    r599 r745  
    1212
    1313#include "includes.h"
     14#include "memcache.h"
     15#include "interfaces.h"
    1416
    1517#define NAME_INDEX 0
     
    6769        }
    6870
    69         return same_net((struct sockaddr *)&ss_host, (struct sockaddr *)&ss_tok, (struct sockaddr *)&ss_mask);
     71        return same_net((struct sockaddr *)(void *)&ss_host,
     72                        (struct sockaddr *)(void *)&ss_tok,
     73                        (struct sockaddr *)(void *)&ss_mask);
    7074}
    7175
     
    330334        ret = allow_access_internal(deny_list, allow_list, nc_cname, nc_caddr);
    331335
     336        DEBUG(ret ? 3 : 0,
     337              ("%s connection from %s (%s)\n",
     338               ret ? "Allowed" : "Denied", nc_cname, nc_caddr));
     339
    332340        SAFE_FREE(nc_cname);
    333341        SAFE_FREE(nc_caddr);
    334342        return ret;
    335343}
    336 
    337 /* return true if the char* contains ip addrs only.  Used to avoid
    338 name lookup calls */
    339 
    340 static bool only_ipaddrs_in_list(const char **list)
    341 {
    342         bool only_ip = true;
    343 
    344         if (!list) {
    345                 return true;
    346         }
    347 
    348         for (; *list ; list++) {
    349                 /* factor out the special strings */
    350                 if (strequal(*list, "ALL") || strequal(*list, "FAIL") ||
    351                     strequal(*list, "EXCEPT")) {
    352                         continue;
    353                 }
    354 
    355                 if (!is_ipaddress(*list)) {
    356                         /*
    357                          * If we failed, make sure that it was not because
    358                          * the token was a network/netmask pair. Only
    359                          * network/netmask pairs have a '/' in them.
    360                          */
    361                         if ((strchr_m(*list, '/')) == NULL) {
    362                                 only_ip = false;
    363                                 DEBUG(3,("only_ipaddrs_in_list: list has "
    364                                         "non-ip address (%s)\n",
    365                                         *list));
    366                                 break;
    367                         }
    368                 }
    369         }
    370 
    371         return only_ip;
    372 }
    373 
    374 /* return true if access should be allowed to a service for a socket */
    375 bool check_access(int sock, const char **allow_list, const char **deny_list)
    376 {
    377         bool ret = false;
    378         bool only_ip = false;
    379 
    380         if ((!deny_list || *deny_list==0) && (!allow_list || *allow_list==0))
    381                 ret = true;
    382 
    383         if (!ret) {
    384                 char addr[INET6_ADDRSTRLEN];
    385 
    386                 /* Bypass name resolution calls if the lists
    387                  * only contain IP addrs */
    388                 if (only_ipaddrs_in_list(allow_list) &&
    389                                 only_ipaddrs_in_list(deny_list)) {
    390                         only_ip = true;
    391                         DEBUG (3, ("check_access: no hostnames "
    392                                 "in host allow/deny list.\n"));
    393                         ret = allow_access(deny_list,
    394                                         allow_list,
    395                                         "",
    396                                         get_peer_addr(sock,addr,sizeof(addr)));
    397                 } else {
    398                         DEBUG (3, ("check_access: hostnames in "
    399                                 "host allow/deny list.\n"));
    400                         ret = allow_access(deny_list,
    401                                         allow_list,
    402                                         get_peer_name(sock,true),
    403                                         get_peer_addr(sock,addr,sizeof(addr)));
    404                 }
    405 
    406                 if (ret) {
    407                         DEBUG(2,("Allowed connection from %s (%s)\n",
    408                                  only_ip ? "" : get_peer_name(sock,true),
    409                                  get_peer_addr(sock,addr,sizeof(addr))));
    410                 } else {
    411                         DEBUG(0,("Denied connection from %s (%s)\n",
    412                                  only_ip ? "" : get_peer_name(sock,true),
    413                                  get_peer_addr(sock,addr,sizeof(addr))));
    414                 }
    415         }
    416 
    417         return(ret);
    418 }
  • trunk/server/source3/lib/adt_tree.c

    r414 r745  
    2121#include "adt_tree.h"
    2222
     23struct tree_node {
     24        struct tree_node        *parent;
     25        struct tree_node        **children;
     26        int                     num_children;
     27        char                    *key;
     28        void                    *data_p;
     29};
     30
     31struct sorted_tree {
     32        struct tree_node *root;
     33};
    2334
    2435/**************************************************************************
     
    2839{
    2940        char *p;
    30        
     41
    3142        *new_path = *base = NULL;
    32        
     43
    3344        if ( !path )
    3445                return False;
    35        
     46
    3647        *base = path;
    37        
    38         p = strchr( path, '/' );
    39        
     48
     49        p = strchr( path, '\\' );
     50
    4051        if ( p ) {
    4152                *p = '\0';
    4253                *new_path = p+1;
    4354        }
    44        
     55
    4556        return True;
    4657}
    4758
    48  
    49 /**************************************************************************
    50  Initialize the tree's root.  The cmp_fn is a callback function used
    51  for comparision of two children
    52  *************************************************************************/
    53 
    54  SORTED_TREE* pathtree_init( void *data_p, int (cmp_fn)(void*, void*) )
    55 {
    56         SORTED_TREE *tree = NULL;
    57        
    58         if ( !(tree = TALLOC_ZERO_P(NULL, SORTED_TREE)) )
    59                 return NULL;
    60                
    61         tree->compare = cmp_fn;
    62        
    63         if ( !(tree->root = TALLOC_ZERO_P(tree, TREE_NODE)) ) {
     59/**************************************************************************
     60 Initialize the tree's root.
     61 *************************************************************************/
     62
     63struct sorted_tree *pathtree_init(void *data_p)
     64{
     65        struct sorted_tree *tree = NULL;
     66
     67        tree = talloc_zero(NULL, struct sorted_tree);
     68        if (tree == NULL) {
     69                return NULL;
     70        }
     71
     72        tree->root = talloc_zero(tree, struct tree_node);
     73        if (tree->root == NULL) {
    6474                TALLOC_FREE( tree );
    6575                return NULL;
    6676        }
    67        
     77
    6878        tree->root->data_p = data_p;
    69        
     79
    7080        return tree;
    7181}
     
    7686 *************************************************************************/
    7787
    78 static TREE_NODE* pathtree_birth_child( TREE_NODE *node, char* key )
    79 {
    80         TREE_NODE *infant = NULL;
    81         TREE_NODE **siblings;
     88static struct tree_node *pathtree_birth_child(struct tree_node *node,
     89                                              char* key )
     90{
     91        struct tree_node *infant = NULL;
     92        struct tree_node **siblings;
    8293        int i;
    83        
    84         if ( !(infant = TALLOC_ZERO_P( node, TREE_NODE)) )
    85                 return NULL;
    86        
     94
     95        infant = talloc_zero(node, struct tree_node);
     96        if (infant == NULL) {
     97                return NULL;
     98        }
     99
    87100        infant->key = talloc_strdup( infant, key );
    88101        infant->parent = node;
    89        
    90         siblings = TALLOC_REALLOC_ARRAY( node, node->children, TREE_NODE *, node->num_children+1 );
    91        
     102
     103        siblings = talloc_realloc(node, node->children, struct tree_node *,
     104                                  node->num_children+1);
     105
    92106        if ( siblings )
    93107                node->children = siblings;
    94        
     108
    95109        node->num_children++;
    96        
     110
    97111        /* first child */
    98        
     112
    99113        if ( node->num_children == 1 ) {
    100114                DEBUG(11,("pathtree_birth_child: First child of node [%s]! [%s]\n",
     
    112126                 * from left to right
    113127                 */
    114        
     128
    115129                for ( i = node->num_children-1; i>=1; i-- )
    116130                {
    117131                        DEBUG(11,("pathtree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n",
    118132                                infant->key, node->children[i-1]->key));
    119                        
     133
    120134                        /* the strings should never match assuming that we
    121135                           have called pathtree_find_child() first */
    122                
     136
    123137                        if ( StrCaseCmp( infant->key, node->children[i-1]->key ) > 0 ) {
    124138                                DEBUG(11,("pathtree_birth_child: storing infant in i == [%d]\n",
     
    127141                                break;
    128142                        }
    129                        
     143
    130144                        /* bump everything towards the end on slot */
    131                        
     145
    132146                        node->children[i] = node->children[i-1];
    133147                }
    134148
    135149                DEBUG(11,("pathtree_birth_child: Exiting loop (i == [%d])\n", i ));
    136                
     150
    137151                /* if we haven't found the correct slot yet, the child
    138152                   will be first in the list */
    139                    
     153
    140154                if ( i == 0 )
    141155                        node->children[0] = infant;
     
    149163 *************************************************************************/
    150164
    151 static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key )
    152 {
    153         TREE_NODE *next = NULL;
     165static struct tree_node *pathtree_find_child(struct tree_node *node,
     166                                             char *key )
     167{
     168        struct tree_node *next = NULL;
    154169        int i, result;
    155        
     170
    156171        if ( !node ) {
    157172                DEBUG(0,("pathtree_find_child: NULL node passed into function!\n"));
    158173                return NULL;
    159174        }
    160        
     175
    161176        if ( !key ) {
    162177                DEBUG(0,("pathtree_find_child: NULL key string passed into function!\n"));
    163178                return NULL;
    164179        }
    165        
     180
    166181        for ( i=0; i<node->num_children; i++ )
    167182        {       
    168183                DEBUG(11,("pathtree_find_child: child key => [%s]\n",
    169184                        node->children[i]->key));
    170                        
     185
    171186                result = StrCaseCmp( node->children[i]->key, key );
    172                
     187
    173188                if ( result == 0 )
    174189                        next = node->children[i];
    175                
     190
    176191                /* if result > 0 then we've gone to far because
    177192                   the list of children is sorted by key name
    178193                   If result == 0, then we have a match         */
    179                    
     194
    180195                if ( result > 0 )
    181196                        break;
     
    184199        DEBUG(11,("pathtree_find_child: %s [%s]\n",
    185200                next ? "Found" : "Did not find", key ));       
    186        
     201
    187202        return next;
    188203}
     
    192207 *************************************************************************/
    193208
    194  WERROR pathtree_add( SORTED_TREE *tree, const char *path, void *data_p )
     209WERROR pathtree_add(struct sorted_tree *tree, const char *path, void *data_p)
    195210{
    196211        char *str, *base, *path2;
    197         TREE_NODE *current, *next;
     212        struct tree_node *current, *next;
    198213        WERROR ret = WERR_OK;
    199        
     214
    200215        DEBUG(8,("pathtree_add: Enter\n"));
    201                
    202         if ( !path || *path != '/' ) {
     216
     217        if ( !path || *path != '\\' ) {
    203218                DEBUG(0,("pathtree_add: Attempt to add a node with a bad path [%s]\n",
    204219                        path ? path : "NULL" ));
    205220                return WERR_INVALID_PARAM;
    206221        }
    207        
     222
    208223        if ( !tree ) {
    209224                DEBUG(0,("pathtree_add: Attempt to add a node to an uninitialized tree!\n"));
    210225                return WERR_INVALID_PARAM;
    211226        }
    212        
    213         /* move past the first '/' */
    214        
     227
     228        /* move past the first '\\' */
     229
    215230        path++;
    216231        path2 = SMB_STRDUP( path );
     
    219234                return WERR_NOMEM;
    220235        }
    221        
     236
    222237
    223238        /*
     
    226241         * The path should be of the form /<key1>/<key2>/...
    227242         */
    228        
     243
    229244        base = path2;
    230245        str  = path2;
    231246        current = tree->root;
    232        
     247
    233248        do {
    234249                /* break off the remaining part of the path */
    235                
    236                 str = strchr( str, '/' );
     250
     251                str = strchr( str, '\\' );
    237252                if ( str )
    238253                        *str = '\0';
    239                        
     254
    240255                /* iterate to the next child--birth it if necessary */
    241                
     256
    242257                next = pathtree_find_child( current, base );
    243258                if ( !next ) {
     
    250265                }
    251266                current = next;
    252                
     267
    253268                /* setup the next part of the path */
    254                
     269
    255270                base = str;
    256271                if ( base ) {
    257                         *base = '/';
     272                        *base = '\\';
    258273                        base++;
    259274                        str = base;
    260275                }
    261        
     276
    262277        } while ( base != NULL );
    263        
     278
    264279        current->data_p = data_p;
    265        
     280
    266281        DEBUG(10,("pathtree_add: Successfully added node [%s] to tree\n",
    267282                path ));
     
    276291
    277292/**************************************************************************
    278  Recursive routine to print out all children of a TREE_NODE
     293 Recursive routine to print out all children of a struct tree_node
    279294 *************************************************************************/
    280295
    281296static void pathtree_print_children(TALLOC_CTX *ctx,
    282                                 TREE_NODE *node,
     297                                struct tree_node *node,
    283298                                int debug,
    284299                                const char *path )
     
    320335 *************************************************************************/
    321336
    322  void pathtree_print_keys( SORTED_TREE *tree, int debug )
     337void pathtree_print_keys(struct sorted_tree *tree, int debug )
    323338{
    324339        int i;
     
    344359 *************************************************************************/
    345360
    346  void* pathtree_find( SORTED_TREE *tree, char *key )
     361void* pathtree_find(struct sorted_tree *tree, char *key )
    347362{
    348363        char *keystr, *base = NULL, *str = NULL, *p;
    349         TREE_NODE *current;
     364        struct tree_node *current;
    350365        void *result = NULL;
    351        
     366
    352367        DEBUG(10,("pathtree_find: Enter [%s]\n", key ? key : "NULL" ));
    353368
    354369        /* sanity checks first */
    355        
     370
    356371        if ( !key ) {
    357372                DEBUG(0,("pathtree_find: Attempt to search tree using NULL search string!\n"));
    358373                return NULL;
    359374        }
    360        
     375
    361376        if ( !tree ) {
    362377                DEBUG(0,("pathtree_find: Attempt to search an uninitialized tree using string [%s]!\n",
     
    364379                return NULL;
    365380        }
    366        
     381
    367382        if ( !tree->root )
    368383                return NULL;
    369        
     384
    370385        /* make a copy to play with */
    371        
    372         if ( *key == '/' )
     386
     387        if ( *key == '\\' )
    373388                keystr = SMB_STRDUP( key+1 );
    374389        else
    375390                keystr = SMB_STRDUP( key );
    376        
     391
    377392        if ( !keystr ) {
    378393                DEBUG(0,("pathtree_find: strdup() failed on string [%s]!?!?!\n", key));
     
    381396
    382397        /* start breaking the path apart */
    383        
     398
    384399        p = keystr;
    385400        current = tree->root;
    386        
     401
    387402        if ( tree->root->data_p )
    388403                result = tree->root->data_p;
    389                
     404
    390405        do
    391406        {
     
    393408
    394409                trim_tree_keypath( p, &base, &str );
    395                        
     410
    396411                DEBUG(11,("pathtree_find: [loop] base => [%s], new_path => [%s]\n",
    397412                        base ? base : "",
     
    399414
    400415                /* iterate to the next child */
    401                
     416
    402417                current = pathtree_find_child( current, base );
    403        
     418
    404419                /*
    405420                 * the idea is that the data_p for a parent should
     
    407422                 * overridden farther down
    408423                 */
    409                
     424
    410425                if ( current && current->data_p )
    411426                        result = current->data_p;
     
    414429
    415430                p = str;
    416            
     431
    417432        } while ( str && current );
    418        
     433
    419434        /* result should be the data_p from the lowest match node in the tree */
    420435        if ( result )
    421436                DEBUG(11,("pathtree_find: Found data_p!\n"));
    422        
     437
    423438        SAFE_FREE( keystr );
    424        
     439
    425440        DEBUG(10,("pathtree_find: Exit\n"));
    426        
     441
    427442        return result;
    428443}
  • trunk/server/source3/lib/afs.c

    r414 r745  
    2424#define NO_ASN1_TYPEDEFS 1
    2525
     26#include "secrets.h"
     27#include "passdb.h"
     28#include "auth.h"
     29#include "../librpc/gen_ndr/ndr_netlogon.h"
     30
    2631#include <afs/param.h>
    2732#include <afs/stds.h>
     
    220225        bool result;
    221226        char *ticket_str = NULL;
    222         const DOM_SID *user_sid;
     227        const struct dom_sid *user_sid;
    223228        TALLOC_CTX *ctx = talloc_tos();
    224229
     
    232237
    233238        afs_username = talloc_sub_advanced(ctx,
    234                                 SNUM(conn), conn->server_info->unix_name,
    235                                 conn->connectpath, conn->server_info->utok.gid,
    236                                 conn->server_info->sanitized_username,
    237                                 pdb_get_domain(conn->server_info->sam_account),
     239                                lp_servicename(SNUM(conn)),
     240                                conn->session_info->unix_name,
     241                                conn->connectpath, conn->session_info->utok.gid,
     242                                conn->session_info->sanitized_username,
     243                                conn->session_info->info3->base.domain.string,
    238244                                afs_username);
    239245        if (!afs_username) {
     
    241247        }
    242248
    243         user_sid = &conn->server_info->ptok->user_sids[0];
     249        user_sid = &conn->session_info->security_token->sids[0];
    244250        afs_username = talloc_string_sub(talloc_tos(),
    245251                                        afs_username,
  • trunk/server/source3/lib/afs_settoken.c

    r414 r745  
    2424#define NO_ASN1_TYPEDEFS 1
    2525
     26#include "system/filesys.h"
     27
    2628#include <afs/param.h>
    2729#include <afs/stds.h>
     
    237239                return False;
    238240
    239         if (geteuid() != 0)
     241        if (geteuid() != sec_initial_uid())
    240242                ct.ViceId = getuid();
    241243
  • trunk/server/source3/lib/audit.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "../librpc/gen_ndr/lsa.h"
    2122
    2223static const struct audit_category_tab {
  • trunk/server/source3/lib/bitmap.c

    r414 r745  
    2424
    2525/****************************************************************************
    26 allocate a bitmap of the specified size
    27 ****************************************************************************/
    28 struct bitmap *bitmap_allocate(int n)
    29 {
    30         struct bitmap *bm;
    31 
    32         bm = SMB_MALLOC_P(struct bitmap);
    33 
    34         if (!bm) return NULL;
    35 
    36         bm->n = n;
    37         bm->b = SMB_MALLOC_ARRAY(uint32, (n+31)/32);
    38         if (!bm->b) {
    39                 SAFE_FREE(bm);
    40                 return NULL;
    41         }
    42 
    43         memset(bm->b, 0, sizeof(uint32)*((n+31)/32));
    44 
    45         return bm;
    46 }
    47 
    48 /****************************************************************************
    49 free a bitmap.
    50 ****************************************************************************/
    51 
    52 void bitmap_free(struct bitmap *bm)
    53 {
    54         if (!bm)
    55                 return;
    56 
    57         SAFE_FREE(bm->b);
    58         SAFE_FREE(bm);
    59 }
    60 
    61 /****************************************************************************
    6226talloc a bitmap
    6327****************************************************************************/
     
    6630        struct bitmap *bm;
    6731
    68         if (!mem_ctx) return NULL;
    69 
    7032        bm = TALLOC_P(mem_ctx, struct bitmap);
    7133
     
    7335
    7436        bm->n = n;
    75         bm->b = TALLOC_ARRAY(mem_ctx, uint32, (n+31)/32);
     37        bm->b = TALLOC_ZERO_ARRAY(bm, uint32, (n+31)/32);
    7638        if (!bm->b) {
     39                TALLOC_FREE(bm);
    7740                return NULL;
    7841        }
    79 
    80         memset(bm->b, 0, sizeof(uint32)*((n+31)/32));
    81 
    8242        return bm;
    8343}
  • trunk/server/source3/lib/charcnv.c

    r599 r745  
    4646
    4747
    48 static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
    4948static bool conv_silent; /* Should we do a debug if the conversion fails ? */
    5049static bool initialized;
    5150
    52 /**
    53  * Return the name of a charset to give to iconv().
    54  **/
    55 static const char *charset_name(charset_t ch)
    56 {
    57         const char *ret;
    58 
    59         switch (ch) {
    60         case CH_UTF16LE:
    61                 ret = "UTF-16LE";
    62                 break;
    63         case CH_UTF16BE:
    64                 ret = "UTF-16BE";
    65                 break;
    66         case CH_UNIX:
    67                 ret = lp_unix_charset();
    68                 break;
    69         case CH_DOS:
    70                 ret = lp_dos_charset();
    71                 break;
    72         case CH_DISPLAY:
    73                 ret = lp_display_charset();
    74                 break;
    75         case CH_UTF8:
    76                 ret = "UTF8";
    77                 break;
    78         default:
    79                 ret = NULL;
    80         }
    81 
    82 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
    83         if (ret && !strcmp(ret, "LOCALE")) {
    84                 const char *ln = NULL;
    85 
    86 #ifdef HAVE_SETLOCALE
    87                 setlocale(LC_ALL, "");
    88 #endif
    89                 ln = nl_langinfo(CODESET);
    90                 if (ln) {
    91                         /* Check whether the charset name is supported
    92                            by iconv */
    93                         smb_iconv_t handle = smb_iconv_open(ln,"UCS-2LE");
    94                         if (handle == (smb_iconv_t) -1) {
    95                                 DEBUG(5,("Locale charset '%s' unsupported, using ASCII instead\n", ln));
    96                                 ln = NULL;
    97                         } else {
    98                                 DEBUG(5,("Substituting charset '%s' for LOCALE\n", ln));
    99                                 smb_iconv_close(handle);
    100                         }
    101                 }
    102                 ret = ln;
    103         }
    104 #endif
    105 
    106         if (!ret || !*ret) ret = "ASCII";
    107         return ret;
    108 }
    109 
    11051void lazy_initialize_conv(void)
    11152{
    11253        if (!initialized) {
    113                 load_case_tables();
     54                load_case_tables_library();
    11455                init_iconv();
    11556                initialized = true;
     
    12263void gfree_charcnv(void)
    12364{
    124         int c1, c2;
    125 
    126         for (c1=0;c1<NUM_CHARSETS;c1++) {
    127                 for (c2=0;c2<NUM_CHARSETS;c2++) {
    128                         if ( conv_handles[c1][c2] ) {
    129                                 smb_iconv_close( conv_handles[c1][c2] );
    130                                 conv_handles[c1][c2] = 0;
    131                         }
    132                 }
    133         }
     65        TALLOC_FREE(global_iconv_convenience);
    13466        initialized = false;
    13567}
     
    14476void init_iconv(void)
    14577{
    146         int c1, c2;
    147         bool did_reload = False;
    148 
    149         /* so that charset_name() works we need to get the UNIX<->UCS2 going
    150            first */
    151         if (!conv_handles[CH_UNIX][CH_UTF16LE])
    152                 conv_handles[CH_UNIX][CH_UTF16LE] = smb_iconv_open(charset_name(CH_UTF16LE), "ASCII");
    153 
    154         if (!conv_handles[CH_UTF16LE][CH_UNIX])
    155                 conv_handles[CH_UTF16LE][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UTF16LE));
    156 
    157         for (c1=0;c1<NUM_CHARSETS;c1++) {
    158                 for (c2=0;c2<NUM_CHARSETS;c2++) {
    159                         const char *n1 = charset_name((charset_t)c1);
    160                         const char *n2 = charset_name((charset_t)c2);
    161                         if (conv_handles[c1][c2] &&
    162                             strcmp(n1, conv_handles[c1][c2]->from_name) == 0 &&
    163                             strcmp(n2, conv_handles[c1][c2]->to_name) == 0)
    164                                 continue;
    165 
    166                         did_reload = True;
    167 
    168                         if (conv_handles[c1][c2])
    169                                 smb_iconv_close(conv_handles[c1][c2]);
    170 
    171                         conv_handles[c1][c2] = smb_iconv_open(n2,n1);
    172                         if (conv_handles[c1][c2] == (smb_iconv_t)-1) {
    173                                 DEBUG(0,("init_iconv: Conversion from %s to %s not supported\n",
    174                                          charset_name((charset_t)c1), charset_name((charset_t)c2)));
    175                                 if (c1 != CH_UTF16LE && c1 != CH_UTF16BE) {
    176                                         n1 = "ASCII";
    177                                 }
    178                                 if (c2 != CH_UTF16LE && c2 != CH_UTF16BE) {
    179                                         n2 = "ASCII";
    180                                 }
    181                                 DEBUG(0,("init_iconv: Attempting to replace with conversion from %s to %s\n",
    182                                         n1, n2 ));
    183                                 conv_handles[c1][c2] = smb_iconv_open(n2,n1);
    184                                 if (!conv_handles[c1][c2]) {
    185                                         DEBUG(0,("init_iconv: Conversion from %s to %s failed", n1, n2));
    186                                         smb_panic("init_iconv: conv_handle initialization failed");
    187                                 }
    188                         }
    189                 }
    190         }
    191 
    192         if (did_reload) {
    193                 /* XXX: Does this really get called every time the dos
    194                  * codepage changes? */
    195                 /* XXX: Is the did_reload test too strict? */
    196                 conv_silent = True;
    197                 init_valid_table();
    198                 conv_silent = False;
    199         }
     78        global_iconv_convenience = smb_iconv_convenience_reinit(NULL, lp_dos_charset(),
     79                                                                lp_unix_charset(), lp_display_charset(),
     80                                                                true, global_iconv_convenience);
    20081}
    20182
     
    224105        char* outbuf = (char*)dest;
    225106        smb_iconv_t descriptor;
     107        struct smb_iconv_convenience *ic;
    226108
    227109        lazy_initialize_conv();
    228 
    229         descriptor = conv_handles[from][to];
     110        ic = get_iconv_convenience();
     111        descriptor = get_conv_handle(ic, from, to);
    230112
    231113        if (srclen == (size_t)-1) {
     
    265147                                        if (from == CH_UNIX) {
    266148                                                DEBUG(3,("E2BIG: convert_string(%s,%s): srclen=%u destlen=%u - '%s'\n",
    267                                                         charset_name(from), charset_name(to),
     149                                                         charset_name(ic, from), charset_name(ic, to),
    268150                                                        (unsigned int)srclen, (unsigned int)destlen, (const char *)src));
    269151                                        } else {
    270152                                                DEBUG(3,("E2BIG: convert_string(%s,%s): srclen=%u destlen=%u\n",
    271                                                         charset_name(from), charset_name(to),
     153                                                         charset_name(ic, from), charset_name(ic, to),
    272154                                                        (unsigned int)srclen, (unsigned int)destlen));
    273155                                        }
     
    562444        smb_iconv_t descriptor;
    563445        void **dest = (void **)dst;
     446        struct smb_iconv_convenience *ic;
    564447
    565448        *dest = NULL;
     
    596479
    597480        lazy_initialize_conv();
    598 
    599         descriptor = conv_handles[from][to];
     481        ic = get_iconv_convenience();
     482        descriptor = get_conv_handle(ic, from, to);
    600483
    601484        if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
     
    18181701}
    18191702
    1820 /*
    1821   Return the unicode codepoint for the next multi-byte CH_UNIX character
    1822   in the string. The unicode codepoint (codepoint_t) is an unsinged 32 bit value.
    1823 
    1824   Also return the number of bytes consumed (which tells the caller
    1825   how many bytes to skip to get to the next CH_UNIX character).
    1826 
    1827   Return INVALID_CODEPOINT if the next character cannot be converted.
    1828 */
    1829 codepoint_t next_codepoint(const char *str, size_t *size)
    1830 {
    1831         /* It cannot occupy more than 4 bytes in UTF16 format */
    1832         uint8_t buf[4];
    1833         smb_iconv_t descriptor;
    1834         size_t ilen_orig;
    1835         size_t ilen;
    1836         size_t olen;
    1837         char *outbuf;
    1838 
    1839         if ((str[0] & 0x80) == 0) {
    1840                 *size = 1;
    1841                 return (codepoint_t)str[0];
    1842         }
    1843 
    1844         /* We assume that no multi-byte character can take
    1845            more than 5 bytes. This is OK as we only
    1846            support codepoints up to 1M */
    1847 
    1848         ilen_orig = strnlen(str, 5);
    1849         ilen = ilen_orig;
    1850 
    1851         lazy_initialize_conv();
    1852 
    1853         descriptor = conv_handles[CH_UNIX][CH_UTF16LE];
    1854         if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
    1855                 *size = 1;
    1856                 return INVALID_CODEPOINT;
    1857         }
    1858 
    1859         /* This looks a little strange, but it is needed to cope
    1860            with codepoints above 64k which are encoded as per RFC2781. */
    1861         olen = 2;
    1862         outbuf = (char *)buf;
    1863         smb_iconv(descriptor, &str, &ilen, &outbuf, &olen);
    1864         if (olen == 2) {
    1865                 /* We failed to convert to a 2 byte character.
    1866                    See if we can convert to a 4 UTF16-LE byte char encoding.
    1867                 */
    1868                 olen = 4;
    1869                 outbuf = (char *)buf;
    1870                 smb_iconv(descriptor,  &str, &ilen, &outbuf, &olen);
    1871                 if (olen == 4) {
    1872                         /* We didn't convert any bytes */
    1873                         *size = 1;
    1874                         return INVALID_CODEPOINT;
    1875                 }
    1876                 olen = 4 - olen;
    1877         } else {
    1878                 olen = 2 - olen;
    1879         }
    1880 
    1881         *size = ilen_orig - ilen;
    1882 
    1883         if (olen == 2) {
    1884                 /* 2 byte, UTF16-LE encoded value. */
    1885                 return (codepoint_t)SVAL(buf, 0);
    1886         }
    1887         if (olen == 4) {
    1888                 /* Decode a 4 byte UTF16-LE character manually.
    1889                    See RFC2871 for the encoding machanism.
    1890                 */
    1891                 codepoint_t w1 = SVAL(buf,0) & ~0xD800;
    1892                 codepoint_t w2 = SVAL(buf,2) & ~0xDC00;
    1893 
    1894                 return (codepoint_t)0x10000 +
    1895                                 (w1 << 10) + w2;
    1896         }
    1897 
    1898         /* no other length is valid */
    1899         return INVALID_CODEPOINT;
    1900 }
    1901 
    1902 /*
    1903   push a single codepoint into a CH_UNIX string the target string must
    1904   be able to hold the full character, which is guaranteed if it is at
    1905   least 5 bytes in size. The caller may pass less than 5 bytes if they
    1906   are sure the character will fit (for example, you can assume that
    1907   uppercase/lowercase of a character will not add more than 1 byte)
    1908 
    1909   return the number of bytes occupied by the CH_UNIX character, or
    1910   -1 on failure
    1911 */
    1912 _PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c)
    1913 {
    1914         smb_iconv_t descriptor;
    1915         uint8_t buf[4];
    1916         size_t ilen, olen;
    1917         const char *inbuf;
    1918        
    1919         if (c < 128) {
    1920                 *str = c;
    1921                 return 1;
    1922         }
    1923 
    1924         lazy_initialize_conv();
    1925 
    1926         descriptor = conv_handles[CH_UNIX][CH_UTF16LE];
    1927         if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
    1928                 return -1;
    1929         }
    1930 
    1931         if (c < 0x10000) {
    1932                 ilen = 2;
    1933                 olen = 5;
    1934                 inbuf = (char *)buf;
    1935                 SSVAL(buf, 0, c);
    1936                 smb_iconv(descriptor, &inbuf, &ilen, &str, &olen);
    1937                 if (ilen != 0) {
    1938                         return -1;
    1939                 }
    1940                 return 5 - olen;
    1941         }
    1942 
    1943         c -= 0x10000;
    1944 
    1945         buf[0] = (c>>10) & 0xFF;
    1946         buf[1] = (c>>18) | 0xd8;
    1947         buf[2] = c & 0xFF;
    1948         buf[3] = ((c>>8) & 0x3) | 0xdc;
    1949 
    1950         ilen = 4;
    1951         olen = 5;
    1952         inbuf = (char *)buf;
    1953 
    1954         smb_iconv(descriptor, &inbuf, &ilen, &str, &olen);
    1955         if (ilen != 0) {
    1956                 return -1;
    1957         }
    1958         return 5 - olen;
    1959 }
    1960 
    1961 
  • trunk/server/source3/lib/conn_tdb.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/globals.h"
     23#include "dbwrap.h"
    2124
    2225static struct db_context *connections_db_ctx(bool rw)
    2326{
    2427        static struct db_context *db_ctx;
     28        int open_flags;
    2529
    2630        if (db_ctx != NULL) {
     
    2832        }
    2933
    30         if (rw) {
    31                 db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
    32                                  TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
    33                                  O_RDWR | O_CREAT, 0644);
    34         }
    35         else {
    36                 db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
    37                                  TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDONLY, 0);
    38         }
     34        open_flags = rw ? (O_RDWR|O_CREAT) : O_RDONLY;
    3935
     36        db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
     37                         TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, open_flags, 0644);
    4038        return db_ctx;
    4139}
    4240
    43 struct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx,
    44                                            TDB_DATA key)
     41static struct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx,
     42                                                  TDB_DATA key)
    4543{
    4644        struct db_context *ctx = connections_db_ctx(True);
     
    6159
    6260        ZERO_STRUCT(ckey);
    63         ckey.pid = procid_self();
    64         ckey.cnum = conn ? conn->cnum : -1;
     61        ckey.pid = sconn_server_id(conn->sconn);
     62        ckey.cnum = conn->cnum;
    6563        strlcpy(ckey.name, name, sizeof(ckey.name));
    6664
     
    113111                       void *private_data)
    114112{
     113        struct db_context *ctx;
    115114        struct conn_traverse_state state;
     115
     116        ctx = connections_db_ctx(true);
     117        if (ctx == NULL) {
     118                return -1;
     119        }
    116120
    117121        state.fn = fn;
    118122        state.private_data = private_data;
    119123
    120         return connections_traverse(conn_traverse_fn, (void *)&state);
     124        return ctx->traverse(ctx, conn_traverse_fn, (void *)&state);
     125}
     126
     127struct conn_traverse_read_state {
     128        int (*fn)(const struct connections_key *key,
     129                  const struct connections_data *data,
     130                  void *private_data);
     131        void *private_data;
     132};
     133
     134static int connections_forall_read_fn(struct db_record *rec,
     135                                      void *private_data)
     136{
     137        struct conn_traverse_read_state *state =
     138                (struct conn_traverse_read_state *)private_data;
     139
     140        if ((rec->key.dsize != sizeof(struct connections_key))
     141            || (rec->value.dsize != sizeof(struct connections_data))) {
     142                return 0;
     143        }
     144        return state->fn((const struct connections_key *)rec->key.dptr,
     145                         (const struct connections_data *)rec->value.dptr,
     146                         state->private_data);
     147}
     148
     149int connections_forall_read(int (*fn)(const struct connections_key *key,
     150                                      const struct connections_data *data,
     151                                      void *private_data),
     152                            void *private_data)
     153{
     154        struct db_context *ctx;
     155        struct conn_traverse_read_state state;
     156
     157        ctx = connections_db_ctx(false);
     158        if (ctx == NULL) {
     159                return -1;
     160        }
     161
     162        state.fn = fn;
     163        state.private_data = private_data;
     164
     165        return ctx->traverse_read(ctx, connections_forall_read_fn,
     166                                  (void *)&state);
    121167}
    122168
  • trunk/server/source3/lib/ctdbd_conn.c

    r429 r745  
    2020
    2121#include "includes.h"
     22#include "util_tdb.h"
    2223
    2324#ifdef CLUSTER_SUPPORT
    2425
    25 #include "librpc/gen_ndr/messaging.h"
    26 #include "librpc/gen_ndr/ndr_messaging.h"
     26#include "ctdbd_conn.h"
     27#include "packet.h"
     28#include "messages.h"
    2729
    2830/* paths to these include files come from --with-ctdb= in configure */
     
    5860           so that someone else can take over without getting sharing
    5961           violations */
    60         _exit(0);
     62        _exit(1);
    6163}
    6264
     
    105107}
    106108
     109/*
     110 * Are we active (i.e. not banned or stopped?)
     111 */
     112static bool ctdbd_working(struct ctdbd_connection *conn, uint32_t vnn)
     113{
     114        int32_t cstatus=-1;
     115        NTSTATUS status;
     116        TDB_DATA outdata;
     117        struct ctdb_node_map *m;
     118        uint32_t failure_flags;
     119        bool ret = false;
     120        int i;
     121
     122        status = ctdbd_control(conn, CTDB_CURRENT_NODE,
     123                               CTDB_CONTROL_GET_NODEMAP, 0, 0,
     124                               tdb_null, talloc_tos(), &outdata, &cstatus);
     125        if (!NT_STATUS_IS_OK(status)) {
     126                cluster_fatal("ctdbd_control failed\n");
     127        }
     128        if ((cstatus != 0) || (outdata.dptr == NULL)) {
     129                DEBUG(2, ("Received invalid ctdb data\n"));
     130                return false;
     131        }
     132
     133        m = (struct ctdb_node_map *)outdata.dptr;
     134
     135        for (i=0; i<m->num; i++) {
     136                if (vnn == m->nodes[i].pnn) {
     137                        break;
     138                }
     139        }
     140
     141        if (i == m->num) {
     142                DEBUG(2, ("Did not find ourselves (node %d) in nodemap\n",
     143                          (int)vnn));
     144                goto fail;
     145        }
     146
     147        failure_flags = NODE_FLAGS_BANNED | NODE_FLAGS_DISCONNECTED
     148                | NODE_FLAGS_PERMANENTLY_DISABLED | NODE_FLAGS_STOPPED;
     149
     150        if ((m->nodes[i].flags & failure_flags) != 0) {
     151                DEBUG(2, ("Node has status %x, not active\n",
     152                          (int)m->nodes[i].flags));
     153                goto fail;
     154        }
     155
     156        ret = true;
     157fail:
     158        TALLOC_FREE(outdata.dptr);
     159        return ret;
     160}
     161
    107162uint32 ctdbd_vnn(const struct ctdbd_connection *conn)
    108163{
     
    136191        strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
    137192
    138         if (sys_connect(fd, (struct sockaddr *)&addr) == -1) {
     193        if (sys_connect(fd, (struct sockaddr *)(void *)&addr) == -1) {
    139194                DEBUG(1, ("connect(%s) failed: %s\n", sockname,
    140195                          strerror(errno)));
     
    258313
    259314        ndr_err = ndr_pull_struct_blob(
    260                 &blob, result, NULL, result,
     315                &blob, result, result,
    261316                (ndr_pull_flags_fn_t)ndr_pull_messaging_rec);
    262317
     
    278333static NTSTATUS ctdb_packet_fd_read_sync(struct packet_context *ctx)
    279334{
    280         struct timeval timeout;
    281         struct timeval *ptimeout;
    282 
    283         timeout = timeval_set(lp_ctdb_timeout(), 0);
    284         ptimeout = (timeout.tv_sec != 0) ? &timeout : NULL;
    285 
    286         return packet_fd_read_sync(ctx, ptimeout);
     335        int timeout = lp_ctdb_timeout();
     336
     337        if (timeout == 0) {
     338                timeout = -1;
     339        }
     340        return packet_fd_read_sync(ctx, timeout);
    287341}
    288342
     
    369423                                  ? "cluster reconfigure" : "SAMBA_NOTIFY"));
    370424
    371                         messaging_send(conn->msg_ctx, procid_self(),
     425                        messaging_send(conn->msg_ctx,
     426                                       messaging_server_id(conn->msg_ctx),
    372427                                       MSG_SMB_BRL_VALIDATE, &data_blob_null);
    373                         messaging_send(conn->msg_ctx, procid_self(),
     428                        messaging_send(conn->msg_ctx,
     429                                       messaging_server_id(conn->msg_ctx),
    374430                                       MSG_DBWRAP_G_LOCK_RETRY,
    375431                                       &data_blob_null);
     
    378434                }
    379435
    380                 if (!(msg_state = TALLOC_P(talloc_autofree_context(), struct deferred_msg_state))) {
     436                msg_state = TALLOC_P(NULL, struct deferred_msg_state);
     437                if (msg_state == NULL) {
    381438                        DEBUG(0, ("talloc failed\n"));
    382439                        TALLOC_FREE(hdr);
     
    432489 */
    433490
    434 NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
    435                                struct ctdbd_connection **pconn)
     491static NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
     492                                      struct ctdbd_connection **pconn)
    436493{
    437494        struct ctdbd_connection *conn;
     
    454511        if (!NT_STATUS_IS_OK(status)) {
    455512                DEBUG(10, ("get_cluster_vnn failed: %s\n", nt_errstr(status)));
     513                goto fail;
     514        }
     515
     516        if (!ctdbd_working(conn, conn->our_vnn)) {
     517                DEBUG(2, ("Node is not working, can not connect\n"));
     518                status = NT_STATUS_INTERNAL_DB_ERROR;
    456519                goto fail;
    457520        }
     
    565628                 * clean the brl database
    566629                 */
    567                 messaging_send(conn->msg_ctx, procid_self(),
     630                messaging_send(conn->msg_ctx,
     631                               messaging_server_id(conn->msg_ctx),
    568632                               MSG_SMB_BRL_VALIDATE, &data_blob_null);
    569633
    570                 messaging_send(conn->msg_ctx, procid_self(),
     634                messaging_send(conn->msg_ctx,
     635                               messaging_server_id(conn->msg_ctx),
    571636                               MSG_DBWRAP_G_LOCK_RETRY,
    572637                               &data_blob_null);
     
    671736
    672737        ndr_err = ndr_push_struct_blob(
    673                 &blob, mem_ctx, NULL, msg,
     738                &blob, mem_ctx, msg,
    674739                (ndr_push_flags_fn_t)ndr_push_messaging_rec);
    675740
     
    758823        req.srvid            = srvid;
    759824        req.datalen          = data.dsize;
     825        req.flags            = flags;
    760826
    761827        DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
     
    781847        if (flags & CTDB_CTRL_FLAG_NOREPLY) {
    782848                TALLOC_FREE(new_conn);
     849                if (cstatus) {
     850                        *cstatus = 0;
     851                }
    783852                return NT_STATUS_OK;
    784853        }
     
    881950                               ? CTDB_CONTROL_DB_ATTACH_PERSISTENT
    882951                               : CTDB_CONTROL_DB_ATTACH,
    883                                0, 0, data, NULL, &data, &cstatus);
     952                               tdb_flags, 0, data, NULL, &data, &cstatus);
    884953        if (!NT_STATUS_IS_OK(status)) {
    885954                DEBUG(0, (__location__ " ctdb_control for db_attach "
     
    12751344        switch (client.ss_family) {
    12761345        case AF_INET:
    1277                 p4.dest = *(struct sockaddr_in *)&server;
    1278                 p4.src = *(struct sockaddr_in *)&client;
     1346                p4.dest = *(struct sockaddr_in *)(void *)&server;
     1347                p4.src = *(struct sockaddr_in *)(void *)&client;
    12791348                data.dptr = (uint8_t *)&p4;
    12801349                data.dsize = sizeof(p4);
     
    12821351#ifdef HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR
    12831352        case AF_INET6:
    1284                 p.dest.ip6 = *(struct sockaddr_in6 *)&server;
    1285                 p.src.ip6 = *(struct sockaddr_in6 *)&client;
     1353                p.dest.ip6 = *(struct sockaddr_in6 *)(void *)&server;
     1354                p.src.ip6 = *(struct sockaddr_in6 *)(void *)&client;
    12861355                data.dptr = (uint8_t *)&p;
    12871356                data.dsize = sizeof(p);
     
    12931362
    12941363        conn->release_ip_handler = release_ip_handler;
     1364        /*
     1365         * store the IP address of the server socket for later
     1366         * comparison in release_ip()
     1367         */
     1368        conn->release_ip_priv = private_data;
    12951369
    12961370        /*
     
    13761450}
    13771451
    1378 #else
    1379 
    1380 NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
    1381                                struct ctdbd_connection **pconn)
    1382 {
    1383         return NT_STATUS_NOT_IMPLEMENTED;
    1384 }
    1385 
    13861452#endif
  • trunk/server/source3/lib/dbwrap.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "dbwrap.h"
     24#include "util_tdb.h"
    2325#ifdef CLUSTER_SUPPORT
    2426#include "ctdb_private.h"
     
    104106#ifdef CLUSTER_SUPPORT
    105107        const char *sockname = lp_ctdbd_socket();
    106 #endif
    107 
    108 #ifdef CLUSTER_SUPPORT
     108
    109109        if(!sockname || !*sockname) {
    110110                sockname = CTDB_PATH;
  • trunk/server/source3/lib/dbwrap_ctdb.c

    r429 r745  
    2020
    2121#include "includes.h"
     22#include "system/filesys.h"
     23#include "lib/util/tdb_wrap.h"
     24#include "util_tdb.h"
    2225#ifdef CLUSTER_SUPPORT
    2326#include "ctdb.h"
     
    2528#include "ctdbd_conn.h"
    2629#include "g_lock.h"
     30#include "messages.h"
    2731
    2832struct db_ctdb_transaction_handle {
     
    5155        struct db_ctdb_ctx *ctdb_ctx;
    5256        struct ctdb_ltdb_header header;
     57        struct timeval lock_time;
    5358};
    5459
     
    474479}
    475480
     481/**
     482 * Fetch a record from a persistent database
     483 * without record locking and without an active transaction.
     484 *
     485 * This just fetches from the local database copy.
     486 * Since the databases are kept in syc cluster-wide,
     487 * there is no point in doing a ctdb call to fetch the
     488 * record from the lmaster. It does even harm since migration
     489 * of records bump their RSN and hence render the persistent
     490 * database inconsistent.
     491 */
     492static int db_ctdb_fetch_persistent(struct db_ctdb_ctx *db,
     493                                    TALLOC_CTX *mem_ctx,
     494                                    TDB_DATA key, TDB_DATA *data)
     495{
     496        NTSTATUS status;
     497
     498        status = db_ctdb_ltdb_fetch(db, key, NULL, mem_ctx, data);
     499
     500        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
     501                *data = tdb_null;
     502        } else if (!NT_STATUS_IS_OK(status)) {
     503                return -1;
     504        }
     505
     506        return 0;
     507}
    476508
    477509static NTSTATUS db_ctdb_store_transaction(struct db_record *rec, TDB_DATA data, int flag);
     
    880912
    881913
     914#ifdef HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL
     915static NTSTATUS db_ctdb_send_schedule_for_deletion(struct db_record *rec)
     916{
     917        NTSTATUS status;
     918        struct ctdb_control_schedule_for_deletion *dd;
     919        TDB_DATA indata;
     920        int cstatus;
     921        struct db_ctdb_rec *crec = talloc_get_type_abort(
     922                rec->private_data, struct db_ctdb_rec);
     923
     924        indata.dsize = offsetof(struct ctdb_control_schedule_for_deletion, key) + rec->key.dsize;
     925        indata.dptr = talloc_zero_array(crec, uint8_t, indata.dsize);
     926        if (indata.dptr == NULL) {
     927                DEBUG(0, (__location__ " talloc failed!\n"));
     928                return NT_STATUS_NO_MEMORY;
     929        }
     930
     931        dd = (struct ctdb_control_schedule_for_deletion *)(void *)indata.dptr;
     932        dd->db_id = crec->ctdb_ctx->db_id;
     933        dd->hdr = crec->header;
     934        dd->keylen = rec->key.dsize;
     935        memcpy(dd->key, rec->key.dptr, rec->key.dsize);
     936
     937        status = ctdbd_control_local(messaging_ctdbd_connection(),
     938                                     CTDB_CONTROL_SCHEDULE_FOR_DELETION,
     939                                     crec->ctdb_ctx->db_id,
     940                                     CTDB_CTRL_FLAG_NOREPLY, /* flags */
     941                                     indata,
     942                                     NULL, /* outdata */
     943                                     NULL, /* errmsg */
     944                                     &cstatus);
     945        talloc_free(indata.dptr);
     946
     947        if (!NT_STATUS_IS_OK(status) || cstatus != 0) {
     948                DEBUG(1, (__location__ " Error sending local control "
     949                          "SCHEDULE_FOR_DELETION: %s, cstatus = %d\n",
     950                          nt_errstr(status), cstatus));
     951                if (NT_STATUS_IS_OK(status)) {
     952                        status = NT_STATUS_UNSUCCESSFUL;
     953                }
     954        }
     955
     956        return status;
     957}
     958#endif
     959
    882960static NTSTATUS db_ctdb_delete(struct db_record *rec)
    883961{
    884962        TDB_DATA data;
     963        NTSTATUS status;
    885964
    886965        /*
     
    891970        ZERO_STRUCT(data);
    892971
    893         return db_ctdb_store(rec, data, 0);
    894 
     972        status = db_ctdb_store(rec, data, 0);
     973        if (!NT_STATUS_IS_OK(status)) {
     974                return status;
     975        }
     976
     977#ifdef HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL
     978        status = db_ctdb_send_schedule_for_deletion(rec);
     979#endif
     980
     981        return status;
    895982}
    896983
     
    899986        struct db_ctdb_rec *crec = talloc_get_type_abort(
    900987                data->private_data, struct db_ctdb_rec);
     988        int threshold;
    901989
    902990        DEBUG(10, (DEBUGLEVEL > 10
     
    910998                DEBUG(0, ("tdb_chainunlock failed\n"));
    911999                return -1;
     1000        }
     1001
     1002        threshold = lp_ctdb_locktime_warn_threshold();
     1003        if (threshold != 0) {
     1004                double timediff = timeval_elapsed(&crec->lock_time);
     1005                if ((timediff * 1000) > threshold) {
     1006                        DEBUG(0, ("Held tdb lock %f seconds\n", timediff));
     1007                }
    9121008        }
    9131009
     
    9961092                           get_my_vnn()));
    9971093
    998                 status = ctdbd_migrate(messaging_ctdbd_connection(),ctx->db_id, key);
     1094                status = ctdbd_migrate(messaging_ctdbd_connection(), ctx->db_id,
     1095                                       key);
    9991096                if (!NT_STATUS_IS_OK(status)) {
    10001097                        DEBUG(5, ("ctdb_migrate failed: %s\n",
     
    10111108                          migrate_attempts));
    10121109        }
     1110
     1111        GetTimeOfDay(&crec->lock_time);
    10131112
    10141113        memcpy(&crec->header, ctdb_data.dptr, sizeof(crec->header));
     
    10611160        if (ctx->transaction) {
    10621161                return db_ctdb_transaction_fetch(ctx, mem_ctx, key, data);
     1162        }
     1163
     1164        if (db->persistent) {
     1165                return db_ctdb_fetch_persistent(ctx, mem_ctx, key, data);
    10631166        }
    10641167
     
    10731176        if ((ctdb_data.dptr != NULL) &&
    10741177            (ctdb_data.dsize >= sizeof(struct ctdb_ltdb_header)) &&
    1075             (db->persistent ||
    1076              ((struct ctdb_ltdb_header *)ctdb_data.dptr)->dmaster == get_my_vnn())) {
     1178            ((struct ctdb_ltdb_header *)ctdb_data.dptr)->dmaster == get_my_vnn())
     1179        {
    10771180                /* we are the dmaster - avoid the ctdb protocol op */
    10781181
     
    10991202
    11001203        /* we weren't able to get it locally - ask ctdb to fetch it for us */
    1101         status = ctdbd_fetch(messaging_ctdbd_connection(),ctx->db_id, key, mem_ctx, data);
     1204        status = ctdbd_fetch(messaging_ctdbd_connection(), ctx->db_id, key,
     1205                             mem_ctx, data);
    11021206        if (!NT_STATUS_IS_OK(status)) {
    11031207                DEBUG(5, ("ctdbd_fetch failed: %s\n", nt_errstr(status)));
     
    12781382
    12791383        conn = messaging_ctdbd_connection();
     1384        if (conn == NULL) {
     1385                DEBUG(1, ("Could not connect to ctdb\n"));
     1386                TALLOC_FREE(result);
     1387                return NULL;
     1388        }
    12801389
    12811390        if (!NT_STATUS_IS_OK(ctdbd_db_attach(conn, name, &db_ctdb->db_id, tdb_flags))) {
  • trunk/server/source3/lib/dbwrap_rbt.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "dbwrap.h"
    2122#include "../lib/util/rbtree.h"
    2223
  • trunk/server/source3/lib/dbwrap_tdb.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "dbwrap.h"
     22#include "lib/util/tdb_wrap.h"
    2123
    2224struct db_tdb_ctx {
  • trunk/server/source3/lib/dbwrap_util.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "dbwrap.h"
     24#include "util_tdb.h"
    2325
    2426int32_t dbwrap_fetch_int32(struct db_context *db, const char *keystr)
     
    118120{
    119121        struct db_record *rec;
    120         uint32 val = -1;
     122        uint32_t val = (uint32_t)-1;
    121123        uint32_t v_store;
    122124        NTSTATUS ret;
     
    416418}
    417419
     420struct dbwrap_trans_traverse_action_ctx {
     421        int (*f)(struct db_record* rec, void* private_data);
     422        void* private_data;
     423};
     424
     425
     426static NTSTATUS dbwrap_trans_traverse_action(struct db_context* db, void* private_data)
     427{
     428        struct dbwrap_trans_traverse_action_ctx* ctx =
     429                (struct dbwrap_trans_traverse_action_ctx*)private_data;
     430
     431        int ret = db->traverse(db, ctx->f, ctx->private_data);
     432
     433        return (ret == -1) ? NT_STATUS_INTERNAL_DB_CORRUPTION : NT_STATUS_OK;
     434}
     435
     436NTSTATUS dbwrap_trans_traverse(struct db_context *db,
     437                               int (*f)(struct db_record*, void*),
     438                               void *private_data)
     439{
     440        struct dbwrap_trans_traverse_action_ctx ctx = {
     441                .f = f,
     442                .private_data = private_data,
     443        };
     444        return dbwrap_trans_do(db, dbwrap_trans_traverse_action, &ctx);
     445}
     446
     447NTSTATUS dbwrap_traverse(struct db_context *db,
     448                         int (*f)(struct db_record*, void*),
     449                         void *private_data)
     450{
     451        int ret = db->traverse(db, f, private_data);
     452        return (ret == -1) ? NT_STATUS_INTERNAL_DB_CORRUPTION : NT_STATUS_OK;
     453}
     454
     455
     456
     457
    418458NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key)
    419459{
  • trunk/server/source3/lib/dmallocmsg.c

    r414 r745  
    1818
    1919#include "includes.h"
     20#include "messages.h"
    2021
    2122/**
  • trunk/server/source3/lib/dprintf.c

    r414 r745  
    3030
    3131#include "includes.h"
     32#include "intl/lang_tdb.h"
    3233
    3334 int d_vfprintf(FILE *f, const char *format, va_list ap)
  • trunk/server/source3/lib/dummysmbd.c

    r414 r745  
    2424#include "includes.h"
    2525
    26 int get_client_fd(void)
    27 {
    28         return -1;
    29 }
    30 
    31 int find_service(fstring service)
     26int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out)
    3227{
    3328        return -1;
     
    3934}
    4035
    41 void cancel_pending_lock_requests_by_fid(files_struct *fsp, struct byte_range_lock *br_lck)
     36void cancel_pending_lock_requests_by_fid(files_struct *fsp,
     37                        struct byte_range_lock *br_lck,
     38                        enum file_close_type close_type)
    4239{
    4340}
    4441
    45 void send_stat_cache_delete_message(const char *name)
     42void send_stat_cache_delete_message(struct messaging_context *msg_ctx,
     43                                    const char *name)
    4644{
    4745}
     
    5957
    6058struct event_context *smbd_event_context(void)
    61 {
    62         return NULL;
    63 }
    64 
    65 struct messaging_context *smbd_messaging_context(void)
    6659{
    6760        return NULL;
  • trunk/server/source3/lib/errmap_unix.c

    r414 r745  
    106106        { ECANCELED, ERRDOS, ERRbadfid, NT_STATUS_CANCELLED},
    107107#endif
    108 
     108#ifdef ENOTSUP
     109        { ENOTSUP, ERRSRV, ERRnosupport, NT_STATUS_NOT_SUPPORTED},
     110#endif
    109111        { 0, 0, 0, NT_STATUS_OK }
    110112};
     
    138140        /* Default return */
    139141        return NT_STATUS_ACCESS_DENIED;
     142}
     143
     144/* Convert a Unix error code to a WERROR. */
     145WERROR unix_to_werror(int unix_error)
     146{
     147        return ntstatus_to_werror(map_nt_error_from_unix(unix_error));
    140148}
    141149
  • trunk/server/source3/lib/eventlog/eventlog.c

    r414 r745  
    2222
    2323#include "includes.h"
     24#include "system/filesys.h"
     25#include "lib/eventlog/eventlog.h"
     26#include "../libcli/security/security.h"
     27#include "util_tdb.h"
    2428
    2529/* maintain a list of open eventlog tdbs with reference counts */
     
    6670char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
    6771{
    68         char *path = talloc_asprintf(ctx, "%s/%s.tdb",
    69                         state_path("eventlog"),
    70                         name);
     72        char *path;
     73        char *file;
     74        char *tdbname;
     75
     76        path = talloc_strdup(ctx, state_path("eventlog"));
    7177        if (!path) {
    7278                return NULL;
    7379        }
    74         strlower_m(path);
    75         return path;
     80
     81        file = talloc_asprintf_strlower_m(path, "%s.tdb", name);
     82        if (!file) {
     83                talloc_free(path);
     84                return NULL;
     85        }
     86
     87        tdbname = talloc_asprintf(path, "%s/%s", state_path("eventlog"), file);
     88        if (!tdbname) {
     89                talloc_free(path);
     90                return NULL;
     91        }
     92
     93        return tdbname;
    7694}
    7795
     
    677695        blob = data_blob_const(data.dptr, data.dsize);
    678696
    679         ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, r,
     697        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, r,
    680698                           (ndr_pull_flags_fn_t)ndr_pull_eventlog_Record_tdb);
    681699
     
    727745        }
    728746
    729         r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, NULL, 0);
     747        r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, 0);
    730748
    731749        return r;
     
    771789        r->record_number = tdb_fetch_int32(tdb, EVT_NEXT_RECORD);
    772790
    773         ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, r,
     791        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, r,
    774792                      (ndr_push_flags_fn_t)ndr_push_eventlog_Record_tdb);
    775793        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    941959                }
    942960                if (len > 0) {
    943                         e->UserSid = *string_sid_talloc(mem_ctx, sid_str);
     961                        string_to_sid(&e->UserSid, sid_str);
    944962                }
    945963        }
     
    9931011                }
    9941012
    995                 endoffset += ndr_size_EVENTLOGRECORD(&e, NULL, 0);
     1013                endoffset += ndr_size_EVENTLOGRECORD(&e, 0);
    9961014
    9971015                ADD_TO_ARRAY(mem_ctx, struct EVENTLOGRECORD, e, &evt.records, &num_records);
     
    10201038        }
    10211039
    1022         ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &evt,
     1040        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &evt,
    10231041                   (ndr_push_flags_fn_t)ndr_push_EVENTLOG_EVT_FILE);
    10241042        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
  • trunk/server/source3/lib/events.c

    r596 r745  
    2020
    2121#include "includes.h"
    22 #include <tevent_internal.h>
    23 
    24 void event_fd_set_writeable(struct tevent_fd *fde)
    25 {
    26         TEVENT_FD_WRITEABLE(fde);
    27 }
    28 
    29 void event_fd_set_not_writeable(struct tevent_fd *fde)
    30 {
    31         TEVENT_FD_NOT_WRITEABLE(fde);
    32 }
    33 
    34 void event_fd_set_readable(struct tevent_fd *fde)
    35 {
    36         TEVENT_FD_READABLE(fde);
    37 }
    38 
    39 void event_fd_set_not_readable(struct tevent_fd *fde)
    40 {
    41         TEVENT_FD_NOT_READABLE(fde);
    42 }
    43 
    44 /*
    45  * Return if there's something in the queue
    46  */
    47 
    48 bool event_add_to_select_args(struct tevent_context *ev,
    49                               const struct timeval *now,
    50                               fd_set *read_fds, fd_set *write_fds,
    51                               struct timeval *timeout, int *maxfd)
     22#include "lib/tevent/tevent_internal.h"
     23#include "../lib/util/select.h"
     24#include "system/select.h"
     25
     26struct tevent_poll_private {
     27        /*
     28         * Index from file descriptor into the pollfd array
     29         */
     30        int *pollfd_idx;
     31
     32        /*
     33         * Cache for s3_event_loop_once to avoid reallocs
     34         */
     35        struct pollfd *pfds;
     36};
     37
     38static struct tevent_poll_private *tevent_get_poll_private(
     39        struct tevent_context *ev)
     40{
     41        struct tevent_poll_private *state;
     42
     43        state = (struct tevent_poll_private *)ev->additional_data;
     44        if (state == NULL) {
     45                state = TALLOC_ZERO_P(ev, struct tevent_poll_private);
     46                ev->additional_data = (void *)state;
     47                if (state == NULL) {
     48                        DEBUG(10, ("talloc failed\n"));
     49                }
     50        }
     51        return state;
     52}
     53
     54static void count_fds(struct tevent_context *ev,
     55                      int *pnum_fds, int *pmax_fd)
    5256{
    5357        struct tevent_fd *fde;
    54         struct timeval diff;
    55         bool ret = false;
     58        int num_fds = 0;
     59        int max_fd = 0;
     60
     61        for (fde = ev->fd_events; fde != NULL; fde = fde->next) {
     62                if (fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) {
     63                        num_fds += 1;
     64                        if (fde->fd > max_fd) {
     65                                max_fd = fde->fd;
     66                        }
     67                }
     68        }
     69        *pnum_fds = num_fds;
     70        *pmax_fd = max_fd;
     71}
     72
     73bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
     74                            struct pollfd **pfds, int *pnum_pfds,
     75                            int *ptimeout)
     76{
     77        struct tevent_poll_private *state;
     78        struct tevent_fd *fde;
     79        int i, num_fds, max_fd, num_pollfds, idx_len;
     80        struct pollfd *fds;
     81        struct timeval now, diff;
     82        int timeout;
     83
     84        state = tevent_get_poll_private(ev);
     85        if (state == NULL) {
     86                return false;
     87        }
     88        count_fds(ev, &num_fds, &max_fd);
     89
     90        idx_len = max_fd+1;
     91
     92        if (talloc_array_length(state->pollfd_idx) < idx_len) {
     93                state->pollfd_idx = TALLOC_REALLOC_ARRAY(
     94                        state, state->pollfd_idx, int, idx_len);
     95                if (state->pollfd_idx == NULL) {
     96                        DEBUG(10, ("talloc_realloc failed\n"));
     97                        return false;
     98                }
     99        }
     100
     101        fds = *pfds;
     102        num_pollfds = *pnum_pfds;
     103
     104        /*
     105         * The +1 is for the sys_poll calling convention. It expects
     106         * an array 1 longer for the signal pipe
     107         */
     108
     109        if (talloc_array_length(fds) < num_pollfds + num_fds + 1) {
     110                fds = TALLOC_REALLOC_ARRAY(mem_ctx, fds, struct pollfd,
     111                                           num_pollfds + num_fds + 1);
     112                if (fds == NULL) {
     113                        DEBUG(10, ("talloc_realloc failed\n"));
     114                        return false;
     115                }
     116        }
     117
     118        memset(&fds[num_pollfds], 0, sizeof(struct pollfd) * num_fds);
     119
     120        /*
     121         * This needs tuning. We need to cope with multiple fde's for a file
     122         * descriptor. The problem is that we need to re-use pollfd_idx across
     123         * calls for efficiency. One way would be a direct bitmask that might
     124         * be initialized quicker, but our bitmap_init implementation is
     125         * pretty heavy-weight as well.
     126         */
     127        for (i=0; i<idx_len; i++) {
     128                state->pollfd_idx[i] = -1;
     129        }
    56130
    57131        for (fde = ev->fd_events; fde; fde = fde->next) {
    58                 if (fde->fd < 0 || fde->fd >= FD_SETSIZE) {
    59                         /* We ignore here, as it shouldn't be
    60                            possible to add an invalid fde->fd
    61                            but we don't want FD_SET to see an
    62                            invalid fd. */
     132                struct pollfd *pfd;
     133
     134                if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) == 0) {
    63135                        continue;
    64136                }
    65137
     138                if (state->pollfd_idx[fde->fd] == -1) {
     139                        /*
     140                         * We haven't seen this fd yet. Allocate a new pollfd.
     141                         */
     142                        state->pollfd_idx[fde->fd] = num_pollfds;
     143                        pfd = &fds[num_pollfds];
     144                        num_pollfds += 1;
     145                } else {
     146                        /*
     147                         * We have already seen this fd. OR in the flags.
     148                         */
     149                        pfd = &fds[state->pollfd_idx[fde->fd]];
     150                }
     151
     152                pfd->fd = fde->fd;
     153
    66154                if (fde->flags & EVENT_FD_READ) {
    67                         FD_SET(fde->fd, read_fds);
    68                         ret = true;
     155                        pfd->events |= (POLLIN|POLLHUP);
    69156                }
    70157                if (fde->flags & EVENT_FD_WRITE) {
    71                         FD_SET(fde->fd, write_fds);
    72                         ret = true;
    73                 }
    74 
    75                 if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE))
    76                     && (fde->fd > *maxfd)) {
    77                         *maxfd = fde->fd;
    78                 }
    79         }
     158                        pfd->events |= POLLOUT;
     159                }
     160        }
     161        *pfds = fds;
     162        *pnum_pfds = num_pollfds;
    80163
    81164        if (ev->immediate_events != NULL) {
    82                 *timeout = timeval_zero();
    83                 return true;
    84         }
    85 
     165                *ptimeout = 0;
     166                return true;
     167        }
    86168        if (ev->timer_events == NULL) {
    87                 return ret;
    88         }
    89 
    90         diff = timeval_until(now, &ev->timer_events->next_event);
    91         *timeout = timeval_min(timeout, &diff);
     169                *ptimeout = MIN(*ptimeout, INT_MAX);
     170                return true;
     171        }
     172
     173        now = timeval_current();
     174        diff = timeval_until(&now, &ev->timer_events->next_event);
     175        timeout = timeval_to_msec(diff);
     176
     177        if (timeout < *ptimeout) {
     178                *ptimeout = timeout;
     179        }
    92180
    93181        return true;
    94182}
    95183
    96 bool run_events(struct tevent_context *ev,
    97                 int selrtn, fd_set *read_fds, fd_set *write_fds)
    98 {
     184bool run_events_poll(struct tevent_context *ev, int pollrtn,
     185                     struct pollfd *pfds, int num_pfds)
     186{
     187        struct tevent_poll_private *state;
     188        int *pollfd_idx;
    99189        struct tevent_fd *fde;
    100190        struct timeval now;
     
    140230        }
    141231
    142         if (selrtn <= 0) {
     232        if (pollrtn <= 0) {
    143233                /*
    144234                 * No fd ready
     
    147237        }
    148238
     239        state = (struct tevent_poll_private *)ev->additional_data;
     240        pollfd_idx = state->pollfd_idx;
     241
    149242        for (fde = ev->fd_events; fde; fde = fde->next) {
     243                struct pollfd *pfd;
    150244                uint16 flags = 0;
    151245
    152                 if (FD_ISSET(fde->fd, read_fds)) flags |= EVENT_FD_READ;
    153                 if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE;
    154 
     246                if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) == 0) {
     247                        continue;
     248                }
     249
     250                if (pollfd_idx[fde->fd] >= num_pfds) {
     251                        DEBUG(1, ("internal error: pollfd_idx[fde->fd] (%d) "
     252                                  ">= num_pfds (%d)\n", pollfd_idx[fde->fd],
     253                                  num_pfds));
     254                        return false;
     255                }
     256                pfd = &pfds[pollfd_idx[fde->fd]];
     257
     258                if (pfd->fd != fde->fd) {
     259                        DEBUG(1, ("internal error: pfd->fd (%d) "
     260                                  "!= fde->fd (%d)\n", pollfd_idx[fde->fd],
     261                                  num_pfds));
     262                        return false;
     263                }
     264
     265                if (pfd->revents & (POLLHUP|POLLERR)) {
     266                        /* If we only wait for EVENT_FD_WRITE, we
     267                           should not tell the event handler about it,
     268                           and remove the writable flag, as we only
     269                           report errors when waiting for read events
     270                           to match the select behavior. */
     271                        if (!(fde->flags & EVENT_FD_READ)) {
     272                                EVENT_FD_NOT_WRITEABLE(fde);
     273                                continue;
     274                        }
     275                        flags |= EVENT_FD_READ;
     276                }
     277
     278                if (pfd->revents & POLLIN) {
     279                        flags |= EVENT_FD_READ;
     280                }
     281                if (pfd->revents & POLLOUT) {
     282                        flags |= EVENT_FD_WRITE;
     283                }
    155284                if (flags & fde->flags) {
    156                         DLIST_DEMOTE(ev->fd_events, fde, struct tevent_fd *);
     285                        DLIST_DEMOTE(ev->fd_events, fde, struct tevent_fd);
    157286                        fde->handler(ev, fde, flags, fde->private_data);
    158287                        return true;
     
    162291        return false;
    163292}
    164 
    165293
    166294struct timeval *get_timed_events_timeout(struct tevent_context *ev,
     
    188316static int s3_event_loop_once(struct tevent_context *ev, const char *location)
    189317{
    190         struct timeval now, to;
    191         fd_set r_fds, w_fds;
    192         int maxfd = 0;
     318        struct tevent_poll_private *state;
     319        int timeout;
     320        int num_pfds;
    193321        int ret;
    194322
    195         FD_ZERO(&r_fds);
    196         FD_ZERO(&w_fds);
    197 
    198         to.tv_sec = 9999;       /* Max timeout */
    199         to.tv_usec = 0;
    200 
    201         if (run_events(ev, 0, NULL, NULL)) {
     323        timeout = INT_MAX;
     324
     325        state = tevent_get_poll_private(ev);
     326        if (state == NULL) {
     327                errno = ENOMEM;
     328                return -1;
     329        }
     330
     331        if (run_events_poll(ev, 0, NULL, 0)) {
    202332                return 0;
    203333        }
    204334
    205         GetTimeOfDay(&now);
    206 
    207         if (!event_add_to_select_args(ev, &now, &r_fds, &w_fds, &to, &maxfd)) {
     335        num_pfds = 0;
     336        if (!event_add_to_poll_args(ev, state,
     337                                    &state->pfds, &num_pfds, &timeout)) {
    208338                return -1;
    209339        }
    210340
    211         ret = sys_select(maxfd+1, &r_fds, &w_fds, NULL, &to);
    212 
     341        ret = sys_poll(state->pfds, num_pfds, timeout);
    213342        if (ret == -1 && errno != EINTR) {
    214343                tevent_debug(ev, TEVENT_DEBUG_FATAL,
    215                              "sys_select() failed: %d:%s\n",
     344                             "poll() failed: %d:%s\n",
    216345                             errno, strerror(errno));
    217346                return -1;
    218347        }
    219348
    220         run_events(ev, ret, &r_fds, &w_fds);
     349        run_events_poll(ev, ret, state->pfds, num_pfds);
    221350        return 0;
    222 }
    223 
    224 void event_context_reinit(struct tevent_context *ev)
    225 {
    226         tevent_common_context_destructor(ev);
    227         return;
    228351}
    229352
  • trunk/server/source3/lib/fault.c

    r454 r745  
    2020
    2121#include "includes.h"
     22#include "system/filesys.h"
    2223
    2324#ifdef HAVE_SYS_SYSCTL_H
     
    5657#ifndef __OS2__ /* don't use the built in signal capture stuff - prefer native handling of errors */
    5758#ifdef SIGSEGV
    58                 CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL);
     59                CatchSignal(SIGSEGV, SIG_DFL);
    5960#endif
    6061#ifdef SIGBUS
    61                 CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL);
     62                CatchSignal(SIGBUS, SIG_DFL);
    6263#endif
    6364#ifdef SIGABRT
    64                 CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
     65                CatchSignal(SIGABRT, SIG_DFL);
    6566#endif
    6667#endif
     
    8788#ifndef __OS2__ /* don't use the built in signal capture stuff - prefer native handling of errors */
    8889#ifdef SIGSEGV
    89         CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault);
     90        CatchSignal(SIGSEGV, sig_fault);
    9091#endif
    9192#ifdef SIGBUS
    92         CatchSignal(SIGBUS,SIGNAL_CAST sig_fault);
     93        CatchSignal(SIGBUS, sig_fault);
    9394#endif
    9495#ifdef SIGABRT
    95         CatchSignal(SIGABRT,SIGNAL_CAST sig_fault);
     96        CatchSignal(SIGABRT, sig_fault);
    9697#endif
    9798#endif
     
    197198#endif
    198199
     200#if defined(HAVE_SYS_KERNEL_PROC_CORE_PATTERN)
     201
     202/**
     203 * Get the Linux corepath.
     204 *
     205 * On Linux the contents of /proc/sys/kernel/core_pattern indicates the
     206 * location of the core path.
     207 */
     208static char *get_linux_corepath(void)
     209{
     210        char *end;
     211        int fd;
     212        char *result;
     213
     214        fd = open("/proc/sys/kernel/core_pattern", O_RDONLY, 0);
     215        if (fd == -1) {
     216                return NULL;
     217        }
     218
     219        result = afdgets(fd, NULL, 0);
     220        close(fd);
     221
     222        if (result == NULL) {
     223                return NULL;
     224        }
     225
     226        if (result[0] != '/') {
     227                /*
     228                 * No absolute path, use the default (cwd)
     229                 */
     230                TALLOC_FREE(result);
     231                return NULL;
     232        }
     233        /* Strip off the common filename expansion */
     234
     235        end = strrchr_m(result, '/');
     236
     237        if ((end != result) /* this would be the only / */
     238            && (end != NULL)) {
     239                *end = '\0';
     240        }
     241        return result;
     242}
     243#endif
     244
     245
    199246/**
    200247 * Try getting system-specific corepath if one exists.
     
    205252{
    206253#if (defined(FREEBSD) && defined(HAVE_SYSCTLBYNAME))
    207 
    208         /* @todo: Add support for the linux corepath. */
    209 
    210254        char *tmp_corepath = NULL;
    211255        tmp_corepath = get_freebsd_corepath();
     256
     257        /* If this has been set correctly, we're done. */
     258        if (tmp_corepath) {
     259                return tmp_corepath;
     260        }
     261#endif
     262
     263#if defined(HAVE_SYS_KERNEL_PROC_CORE_PATTERN)
     264        char *tmp_corepath = NULL;
     265        tmp_corepath = get_linux_corepath();
    212266
    213267        /* If this has been set correctly, we're done. */
     
    271325#endif
    272326
    273 #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
    274         /* On Linux we lose the ability to dump core when we change our user
    275          * ID. We know how to dump core safely, so let's make sure we have our
    276          * dumpable flag set.
    277          */
    278         prctl(PR_SET_DUMPABLE, 1);
    279 #endif
    280 
    281327        /* FIXME: if we have a core-plus-pid facility, configurably set
    282328         * this up here.
     
    309355         * file to the corepath.  There must not be an unbecome_root() before
    310356         * we call abort(). */
    311         if (geteuid() != 0) {
     357        if (geteuid() != sec_initial_uid()) {
    312358                become_root();
    313359        }
     
    334380        dbgflush();
    335381
     382#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
     383        /* On Linux we lose the ability to dump core when we change our user
     384         * ID. We know how to dump core safely, so let's make sure we have our
     385         * dumpable flag set.
     386         */
     387        prctl(PR_SET_DUMPABLE, 1);
     388#endif
     389
    336390        /* Ensure we don't have a signal handler for abort. */
    337391#ifdef SIGABRT
    338         CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
     392        CatchSignal(SIGABRT, SIG_DFL);
    339393#endif
    340394
  • trunk/server/source3/lib/fncall.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "../lib/util/tevent_unix.h"
    2122
    2223#if WITH_PTHREADPOOL
    2324
    24 #include "pthreadpool.h"
     25#include "lib/pthreadpool/pthreadpool.h"
    2526
    2627struct fncall_state {
     
    8788        talloc_set_destructor(ctx, fncall_context_destructor);
    8889
    89         ctx->sig_fd = pthreadpool_sig_fd(ctx->pool);
     90        ctx->sig_fd = pthreadpool_signal_fd(ctx->pool);
    9091        if (ctx->sig_fd == -1) {
    9192                TALLOC_FREE(ctx);
  • trunk/server/source3/lib/g_lock.c

    r593 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
    2122#include "g_lock.h"
     23#include "util_tdb.h"
     24#include "ctdbd_conn.h"
     25#include "../lib/util/select.h"
     26#include "system/select.h"
     27#include "messages.h"
    2228
    2329static NTSTATUS g_lock_force_unlock(struct g_lock_ctx *ctx, const char *name,
     
    5258
    5359        result->db = db_open(result, lock_path("g_lock.tdb"), 0,
    54                              TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0700);
     60                             TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0700);
    5561        if (result->db == NULL) {
    5662                DEBUG(1, ("g_lock_init: Could not open g_lock.tdb"));
     
    206212        }
    207213
    208         self = procid_self();
     214        self = messaging_server_id(ctx->msg);
    209215        our_index = -1;
    210216
     
    333339
    334340        while (true) {
    335 #ifdef CLUSTER_SUPPORT
    336                 fd_set _r_fds;
    337 #endif
    338                 fd_set *r_fds = NULL;
    339                 int max_fd = 0;
     341                struct pollfd *pollfds;
     342                int num_pollfds;
     343                int saved_errno;
    340344                int ret;
    341345                struct timeval timeout_remaining, select_timeout;
     
    385389                 */
    386390
     391                /*
     392                 * We allocate 2 entries here. One is needed anyway for
     393                 * sys_poll and in the clustering case we might have to add
     394                 * the ctdb fd. This avoids the realloc then.
     395                 */
     396                pollfds = TALLOC_ARRAY(talloc_tos(), struct pollfd, 2);
     397                if (pollfds == NULL) {
     398                        status = NT_STATUS_NO_MEMORY;
     399                        break;
     400                }
     401                num_pollfds = 0;
     402
    387403#ifdef CLUSTER_SUPPORT
    388404                if (lp_clustering()) {
    389                         struct ctdbd_connection *conn = messaging_ctdbd_connection();
    390 
    391                         r_fds = &_r_fds;
    392                         FD_ZERO(r_fds);
    393                         max_fd = ctdbd_conn_get_fd(conn);
    394                         if (max_fd >= 0 && max_fd < FD_SETSIZE) {
    395                                 FD_SET(max_fd, r_fds);
    396                         }
     405                        struct ctdbd_connection *conn;
     406                        conn = messaging_ctdbd_connection();
     407
     408                        pollfds[0].fd = ctdbd_conn_get_fd(conn);
     409                        pollfds[0].events = POLLIN|POLLHUP;
     410
     411                        num_pollfds += 1;
    397412                }
    398413#endif
     
    405420                                             &timeout_remaining);
    406421
    407                 ret = sys_select(max_fd + 1, r_fds, NULL, NULL,
    408                                  &select_timeout);
     422                ret = sys_poll(pollfds, num_pollfds,
     423                               timeval_to_msec(select_timeout));
     424
     425                /*
     426                 * We're not *really interested in the actual flags. We just
     427                 * need to retry this whole thing.
     428                 */
     429                saved_errno = errno;
     430                TALLOC_FREE(pollfds);
     431                errno = saved_errno;
     432
    409433                if (ret == -1) {
    410434                        if (errno != EINTR) {
     
    590614        NTSTATUS status;
    591615
    592         status = g_lock_force_unlock(ctx, name, procid_self());
     616        status = g_lock_force_unlock(ctx, name, messaging_server_id(ctx->msg));
    593617
    594618#ifdef CLUSTER_SUPPORT
     
    707731                            struct tevent_context **pev,
    708732                            struct messaging_context **pmsg,
     733                            const struct server_id self,
    709734                            struct g_lock_ctx **pg_ctx)
    710735{
     
    718743                goto fail;
    719744        }
    720         msg = messaging_init(mem_ctx, procid_self(), ev);
     745        msg = messaging_init(mem_ctx, self, ev);
    721746        if (msg == NULL) {
    722747                d_fprintf(stderr, "ERROR: could not init messaging context\n");
     
    741766
    742767NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
    743                    struct timeval timeout,
     768                   struct timeval timeout, const struct server_id self,
    744769                   void (*fn)(void *private_data), void *private_data)
    745770{
     
    749774        NTSTATUS status;
    750775
    751         if (!g_lock_init_all(talloc_tos(), &ev, &msg, &g_ctx)) {
     776        if (!g_lock_init_all(talloc_tos(), &ev, &msg, self, &g_ctx)) {
    752777                status = NT_STATUS_ACCESS_DENIED;
    753778                goto done;
  • trunk/server/source3/lib/gencache.c

    r414 r745  
    2323
    2424#include "includes.h"
     25#include "system/filesys.h"
     26#include "system/glob.h"
     27#include "util_tdb.h"
    2528
    2629#undef  DBGC_CLASS
     
    6669
    6770again:
    68         cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, open_flags, 0644);
     71        cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, open_flags, 0644);
    6972        if (cache) {
    7073                int ret;
     
    8184                        DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after CLEAR_IF_FIRST\n",
    8285                                  cache_fname));
    83                         cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST, open_flags, 0644);
     86                        cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, open_flags, 0644);
    8487                        if (cache) {
    8588                                tdb_close(cache);
     
    9295        if (!cache && (errno == EACCES)) {
    9396                open_flags = O_RDONLY;
    94                 cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, open_flags,
     97                cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, open_flags,
    9598                                     0644);
    9699                if (cache) {
     
    108111        DEBUG(5, ("Opening cache file at %s\n", cache_fname));
    109112
    110         cache_notrans = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST,
     113        cache_notrans = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
    111114                                     open_flags, 0644);
    112115        if (cache_notrans == NULL) {
     
    275278        char *endptr;
    276279
     280        if (val == NULL) {
     281                return false;
     282        }
     283
    277284        res = strtol(val, &endptr, 10);
    278285
     
    288295        }
    289296        return true;
     297}
     298
     299struct gencache_parse_state {
     300        void (*parser)(time_t timeout, DATA_BLOB blob, void *private_data);
     301        void *private_data;
     302};
     303
     304static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
     305{
     306        struct gencache_parse_state *state;
     307        DATA_BLOB blob;
     308        time_t t;
     309        char *endptr;
     310        bool ret;
     311
     312        if (data.dptr == NULL) {
     313                return -1;
     314        }
     315        ret = gencache_pull_timeout((char *)data.dptr, &t, &endptr);
     316        if (!ret) {
     317                return -1;
     318        }
     319        state = (struct gencache_parse_state *)private_data;
     320        blob = data_blob_const(
     321                endptr+1, data.dsize - PTR_DIFF(endptr+1, data.dptr));
     322        state->parser(t, blob, state->private_data);
     323        return 0;
     324}
     325
     326bool gencache_parse(const char *keystr,
     327                    void (*parser)(time_t timeout, DATA_BLOB blob,
     328                                   void *private_data),
     329                    void *private_data)
     330{
     331        struct gencache_parse_state state;
     332        TDB_DATA key;
     333        int ret;
     334
     335        if (keystr == NULL) {
     336                return false;
     337        }
     338        if (tdb_data_cmp(string_term_tdb_data(keystr),
     339                         last_stabilize_key()) == 0) {
     340                return false;
     341        }
     342        if (!gencache_init()) {
     343                return false;
     344        }
     345
     346        key = string_term_tdb_data(keystr);
     347        state.parser = parser;
     348        state.private_data = private_data;
     349
     350        ret = tdb_parse_record(cache_notrans, key, gencache_parse_fn, &state);
     351        if (ret != -1) {
     352                return true;
     353        }
     354        ret = tdb_parse_record(cache, key, gencache_parse_fn, &state);
     355        return (ret != -1);
     356}
     357
     358struct gencache_get_data_blob_state {
     359        DATA_BLOB *blob;
     360        time_t timeout;
     361        bool result;
     362};
     363
     364static void gencache_get_data_blob_parser(time_t timeout, DATA_BLOB blob,
     365                                          void *private_data)
     366{
     367        struct gencache_get_data_blob_state *state =
     368                (struct gencache_get_data_blob_state *)private_data;
     369
     370        if (timeout == 0) {
     371                state->result = false;
     372                return;
     373        }
     374        state->timeout = timeout;
     375
     376        if (state->blob == NULL) {
     377                state->result = true;
     378                return;
     379        }
     380
     381        *state->blob = data_blob(blob.data, blob.length);
     382        if (state->blob->data == NULL) {
     383                state->result = false;
     384                return;
     385        }
     386        state->result = true;
    290387}
    291388
     
    305402                            time_t *timeout, bool *was_expired)
    306403{
    307         TDB_DATA databuf;
    308         time_t t;
    309         char *endptr;
     404        struct gencache_get_data_blob_state state;
    310405        bool expired = false;
    311406
    312         if (keystr == NULL) {
     407        state.result = false;
     408        state.blob = blob;
     409
     410        if (!gencache_parse(keystr, gencache_get_data_blob_parser, &state)) {
    313411                goto fail;
    314412        }
    315 
    316         if (tdb_data_cmp(string_term_tdb_data(keystr),
    317                          last_stabilize_key()) == 0) {
    318                 DEBUG(10, ("Can't get %s as a key\n", keystr));
     413        if (!state.result) {
    319414                goto fail;
    320415        }
    321 
    322         if (!gencache_init()) {
    323                 goto fail;
    324         }
    325 
    326         databuf = tdb_fetch_bystring(cache_notrans, keystr);
    327 
    328         if (databuf.dptr == NULL) {
    329                 databuf = tdb_fetch_bystring(cache, keystr);
    330         }
    331 
    332         if (databuf.dptr == NULL) {
    333                 DEBUG(10, ("Cache entry with key = %s couldn't be found \n",
    334                            keystr));
    335                 goto fail;
    336         }
    337 
    338         if (!gencache_pull_timeout((char *)databuf.dptr, &t, &endptr)) {
    339                 SAFE_FREE(databuf.dptr);
    340                 goto fail;
    341         }
    342 
    343         DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, "
    344                    "timeout = %s", t > time(NULL) ? "valid" :
    345                    "expired", keystr, endptr+1, ctime(&t)));
    346 
    347         if (t == 0) {
    348                 /* Deleted */
    349                 SAFE_FREE(databuf.dptr);
    350                 goto fail;
    351         }
    352 
    353         if (t <= time(NULL)) {
    354 
     416        if (state.timeout <= time(NULL)) {
    355417                /*
    356418                 * We're expired, delete the entry. We can't use gencache_del
     
    360422                 */
    361423                gencache_set(keystr, "", 0);
    362 
    363                 SAFE_FREE(databuf.dptr);
    364 
    365424                expired = true;
    366425                goto fail;
    367426        }
    368 
    369         if (blob != NULL) {
    370                 *blob = data_blob(
    371                         endptr+1,
    372                         databuf.dsize - PTR_DIFF(endptr+1, databuf.dptr));
    373                 if (blob->data == NULL) {
    374                         SAFE_FREE(databuf.dptr);
    375                         DEBUG(0, ("memdup failed\n"));
    376                         goto fail;
    377                 }
    378         }
    379 
    380         SAFE_FREE(databuf.dptr);
    381 
    382427        if (timeout) {
    383                 *timeout = t;
     428                *timeout = state.timeout;
    384429        }
    385430
     
    389434        if (was_expired != NULL) {
    390435                *was_expired = expired;
     436        }
     437        if (state.result && state.blob) {
     438                data_blob_free(state.blob);
    391439        }
    392440        return false;
     
    417465        }
    418466
    419         res = tdb_transaction_start(cache);
     467        res = tdb_transaction_start_nonblock(cache);
    420468        if (res == -1) {
     469
     470                if (tdb_error(cache) == TDB_ERR_NOLOCK) {
     471                        /*
     472                         * Someone else already does the stabilize,
     473                         * this does not have to be done twice
     474                         */
     475                        return true;
     476                }
     477
    421478                DEBUG(10, ("Could not start transaction on gencache.tdb: "
    422479                           "%s\n", tdb_errorstr(cache)));
     
    585642}
    586643
    587 /**
    588  * Iterate through all entries which key matches to specified pattern
    589  *
    590  * @param fn pointer to the function that will be supplied with each single
    591  *        matching cache entry (key, value and timeout) as an arguments
    592  * @param data void pointer to an arbitrary data that is passed directly to the fn
    593  *        function on each call
    594  * @param keystr_pattern pattern the existing entries' keys are matched to
    595  *
    596  **/
    597 
    598 struct gencache_iterate_state {
    599         void (*fn)(const char *key, const char *value, time_t timeout,
    600                    void *priv);
     644struct gencache_iterate_blobs_state {
     645        void (*fn)(const char *key, DATA_BLOB value,
     646                   time_t timeout, void *private_data);
    601647        const char *pattern;
    602         void *priv;
     648        void *private_data;
    603649        bool in_persistent;
    604650};
    605651
    606 static int gencache_iterate_fn(struct tdb_context *tdb, TDB_DATA key,
    607                                TDB_DATA value, void *priv)
    608 {
    609         struct gencache_iterate_state *state =
    610                 (struct gencache_iterate_state *)priv;
     652static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
     653                                     TDB_DATA data, void *priv)
     654{
     655        struct gencache_iterate_blobs_state *state =
     656                (struct gencache_iterate_blobs_state *)priv;
    611657        char *keystr;
    612658        char *free_key = NULL;
    613         char *valstr;
    614         char *free_val = NULL;
    615         unsigned long u;
    616659        time_t timeout;
    617         char *timeout_endp;
     660        char *endptr;
    618661
    619662        if (tdb_data_cmp(key, last_stabilize_key()) == 0) {
    620663                return 0;
    621664        }
    622 
    623665        if (state->in_persistent && tdb_exists(cache_notrans, key)) {
    624666                return 0;
     
    633675        }
    634676
    635         if ((value.dptr == NULL) || (value.dsize <= TIMEOUT_LEN)) {
     677        if (!gencache_pull_timeout((char *)data.dptr, &timeout, &endptr)) {
    636678                goto done;
    637679        }
     680        endptr += 1;
    638681
    639682        if (fnmatch(state->pattern, keystr, 0) != 0) {
     
    641684        }
    642685
    643         if (value.dptr[value.dsize-1] == '\0') {
    644                 valstr = (char *)value.dptr;
     686        DEBUG(10, ("Calling function with arguments (key=%s, timeout=%s)\n",
     687                   keystr, ctime(&timeout)));
     688
     689        state->fn(keystr,
     690                  data_blob_const(endptr,
     691                                  data.dsize - PTR_DIFF(endptr, data.dptr)),
     692                  timeout, state->private_data);
     693
     694 done:
     695        SAFE_FREE(free_key);
     696        return 0;
     697}
     698
     699void gencache_iterate_blobs(void (*fn)(const char *key, DATA_BLOB value,
     700                                       time_t timeout, void *private_data),
     701                            void *private_data, const char *pattern)
     702{
     703        struct gencache_iterate_blobs_state state;
     704
     705        if ((fn == NULL) || (pattern == NULL) || !gencache_init()) {
     706                return;
     707        }
     708
     709        DEBUG(5, ("Searching cache keys with pattern %s\n", pattern));
     710
     711        state.fn = fn;
     712        state.pattern = pattern;
     713        state.private_data = private_data;
     714
     715        state.in_persistent = false;
     716        tdb_traverse(cache_notrans, gencache_iterate_blobs_fn, &state);
     717
     718        state.in_persistent = true;
     719        tdb_traverse(cache, gencache_iterate_blobs_fn, &state);
     720}
     721
     722/**
     723 * Iterate through all entries which key matches to specified pattern
     724 *
     725 * @param fn pointer to the function that will be supplied with each single
     726 *        matching cache entry (key, value and timeout) as an arguments
     727 * @param data void pointer to an arbitrary data that is passed directly to the fn
     728 *        function on each call
     729 * @param keystr_pattern pattern the existing entries' keys are matched to
     730 *
     731 **/
     732
     733struct gencache_iterate_state {
     734        void (*fn)(const char *key, const char *value, time_t timeout,
     735                   void *priv);
     736        void *private_data;
     737};
     738
     739static void gencache_iterate_fn(const char *key, DATA_BLOB value,
     740                                time_t timeout, void *private_data)
     741{
     742        struct gencache_iterate_state *state =
     743                (struct gencache_iterate_state *)private_data;
     744        char *valstr;
     745        char *free_val = NULL;
     746
     747        if (value.data[value.length-1] == '\0') {
     748                valstr = (char *)value.data;
    645749        } else {
    646750                /* ensure 0-termination */
    647                 valstr = SMB_STRNDUP((char *)value.dptr, value.dsize);
     751                valstr = SMB_STRNDUP((char *)value.data, value.length);
    648752                free_val = valstr;
    649753        }
    650 
    651         u = strtoul(valstr, &timeout_endp, 10);
    652 
    653         if ((*timeout_endp != '/') || ((timeout_endp-valstr) != TIMEOUT_LEN)) {
    654                 goto done;
    655         }
    656 
    657         timeout = u;
    658         timeout_endp += 1;
    659754
    660755        DEBUG(10, ("Calling function with arguments "
    661756                   "(key = %s, value = %s, timeout = %s)\n",
    662                    keystr, timeout_endp, ctime(&timeout)));
    663         state->fn(keystr, timeout_endp, timeout, state->priv);
    664 
    665  done:
    666         SAFE_FREE(free_key);
     757                   key, valstr, ctime(&timeout)));
     758
     759        state->fn(key, valstr, timeout, state->private_data);
     760
    667761        SAFE_FREE(free_val);
    668         return 0;
    669 }
    670 
    671 void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
    672                       void* data, const char* keystr_pattern)
     762}
     763
     764void gencache_iterate(void (*fn)(const char *key, const char *value,
     765                                 time_t timeout, void *dptr),
     766                      void *private_data, const char *pattern)
    673767{
    674768        struct gencache_iterate_state state;
    675769
    676         if ((fn == NULL) || (keystr_pattern == NULL)) {
     770        if (fn == NULL) {
    677771                return;
    678772        }
    679 
    680         if (!gencache_init()) return;
    681 
    682         DEBUG(5, ("Searching cache keys with pattern %s\n", keystr_pattern));
    683 
    684773        state.fn = fn;
    685         state.pattern = keystr_pattern;
    686         state.priv = data;
    687 
    688         state.in_persistent = false;
    689         tdb_traverse(cache_notrans, gencache_iterate_fn, &state);
    690 
    691         state.in_persistent = true;
    692         tdb_traverse(cache, gencache_iterate_fn, &state);
    693 }
     774        state.private_data = private_data;
     775        gencache_iterate_blobs(gencache_iterate_fn, &state, pattern);
     776}
  • trunk/server/source3/lib/idmap_cache.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "idmap_cache.h"
     22#include "../libcli/security/security.h"
    2123
    2224/**
     
    259261        }
    260262}
     263
     264static char* key_xid2sid_str(TALLOC_CTX* mem_ctx, char t, const char* id) {
     265        return talloc_asprintf(mem_ctx, "IDMAP/%cID2SID/%s", t, id);
     266}
     267
     268static char* key_xid2sid(TALLOC_CTX* mem_ctx, char t, int id) {
     269        char str[32];
     270        snprintf(str, sizeof(str), "%d", id);
     271        return key_xid2sid_str(mem_ctx, t, str);
     272}
     273
     274static char* key_sid2xid_str(TALLOC_CTX* mem_ctx, char t, const char* sid) {
     275        return talloc_asprintf(mem_ctx, "IDMAP/SID2%cID/%s", t, sid);
     276}
     277
     278/* static char* key_sid2xid(TALLOC_CTX* mem_ctx, char t, const struct dom_sid* sid) */
     279/* { */
     280/*      char* sid_str = sid_string_talloc(mem_ctx, sid); */
     281/*      char* key = key_sid2xid_str(mem_ctx, t, sid_str); */
     282/*      talloc_free(sid_str); */
     283/*      return key; */
     284/* } */
     285
     286static bool idmap_cache_del_xid(char t, int xid)
     287{
     288        TALLOC_CTX* mem_ctx = talloc_stackframe();
     289        const char* key = key_xid2sid(mem_ctx, t, xid);
     290        char* sid_str = NULL;
     291        time_t timeout;
     292        bool ret = true;
     293
     294        if (!gencache_get(key, &sid_str, &timeout)) {
     295                DEBUG(3, ("no entry: %s\n", key));
     296                ret = false;
     297                goto done;
     298        }
     299
     300        if (sid_str[0] != '-') {
     301                const char* sid_key = key_sid2xid_str(mem_ctx, t, sid_str);
     302                if (!gencache_del(sid_key)) {
     303                        DEBUG(2, ("failed to delete: %s\n", sid_key));
     304                        ret = false;
     305                } else {
     306                        DEBUG(5, ("delete: %s\n", sid_key));
     307                }
     308
     309        }
     310
     311        if (!gencache_del(key)) {
     312                DEBUG(1, ("failed to delete: %s\n", key));
     313                ret = false;
     314        } else {
     315                DEBUG(5, ("delete: %s\n", key));
     316        }
     317
     318done:
     319        talloc_free(mem_ctx);
     320        return ret;
     321}
     322
     323bool idmap_cache_del_uid(uid_t uid) {
     324        return idmap_cache_del_xid('U', uid);
     325}
     326
     327bool idmap_cache_del_gid(gid_t gid) {
     328        return idmap_cache_del_xid('G', gid);
     329}
     330
     331static bool idmap_cache_del_sid2xid(TALLOC_CTX* mem_ctx, char t, const char* sid)
     332{
     333        const char* sid_key = key_sid2xid_str(mem_ctx, t, sid);
     334        char* xid_str;
     335        time_t timeout;
     336        bool ret = true;
     337
     338        if (!gencache_get(sid_key, &xid_str, &timeout)) {
     339                ret = false;
     340                goto done;
     341        }
     342
     343        if (atoi(xid_str) != -1) {
     344                const char* xid_key = key_xid2sid_str(mem_ctx, t, xid_str);
     345                if (!gencache_del(xid_key)) {
     346                        DEBUG(2, ("failed to delete: %s\n", xid_key));
     347                        ret = false;
     348                } else {
     349                        DEBUG(5, ("delete: %s\n", xid_key));
     350                }
     351        }
     352
     353        if (!gencache_del(sid_key)) {
     354                DEBUG(2, ("failed to delete: %s\n", sid_key));
     355                ret = false;
     356        } else {
     357                DEBUG(5, ("delete: %s\n", sid_key));
     358        }
     359done:
     360        return ret;
     361}
     362
     363bool idmap_cache_del_sid(const struct dom_sid *sid)
     364{
     365        TALLOC_CTX* mem_ctx = talloc_stackframe();
     366        const char* sid_str = sid_string_talloc(mem_ctx, sid);
     367        bool ret = true;
     368
     369        if (!idmap_cache_del_sid2xid(mem_ctx, 'U', sid_str) &&
     370            !idmap_cache_del_sid2xid(mem_ctx, 'G', sid_str))
     371        {
     372                DEBUG(3, ("no entry: %s\n", key_xid2sid_str(mem_ctx, '?', sid_str)));
     373                ret = false;
     374        }
     375
     376        talloc_free(mem_ctx);
     377        return ret;
     378}
  • trunk/server/source3/lib/interface.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "interfaces.h"
    2223
    2324static struct iface_struct *probed_ifaces;
  • trunk/server/source3/lib/interfaces.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "interfaces.h"
    2223
    2324/****************************************************************************
     
    280281
    281282        /* now we need to remove duplicates */
    282         qsort(ifaces, total, sizeof(ifaces[0]), QSORT_CAST iface_comp);
     283        TYPESAFE_QSORT(ifaces, total, iface_comp);
    283284
    284285        for (i=1;i<total;) {
  • trunk/server/source3/lib/ldap_debug_handler.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "smb_ldap.h"
    2122
    2223#if defined(HAVE_LDAP) && defined(HAVE_LBER_LOG_PRINT_FN)
  • trunk/server/source3/lib/memcache.c

    r414 r745  
    3232
    3333struct memcache {
    34         struct memcache_element *mru, *lru;
     34        struct memcache_element *mru;
    3535        struct rb_root tree;
    3636        size_t size;
     
    162162
    163163        if (cache->size != 0) {
    164                 /*
    165                  * Do LRU promotion only when we will ever shrink
    166                  */
    167                 if (e == cache->lru) {
    168                         cache->lru = e->prev;
    169                 }
    170164                DLIST_PROMOTE(cache->mru, e);
    171                 if (cache->mru == NULL) {
    172                         cache->mru = e;
    173                 }
    174165        }
    175166
     
    202193        rb_erase(&e->rb_node, &cache->tree);
    203194
    204         if (e == cache->lru) {
    205                 cache->lru = e->prev;
    206         }
    207195        DLIST_REMOVE(cache->mru, e);
    208196
     
    228216        }
    229217
    230         while ((cache->size > cache->max_size) && (cache->lru != NULL)) {
    231                 memcache_delete_element(cache, cache->lru);
     218        while ((cache->size > cache->max_size) && DLIST_TAIL(cache->mru)) {
     219                memcache_delete_element(cache, DLIST_TAIL(cache->mru));
    232220        }
    233221}
     
    332320
    333321        DLIST_ADD(cache->mru, e);
    334         if (cache->lru == NULL) {
    335                 cache->lru = e;
    336         }
    337322
    338323        cache->size += element_size;
     
    401386        }
    402387
    403         if (node == NULL) {
    404                 return;
    405         }
    406 
    407388        /*
    408389         * Then, find the leftmost element with number n
  • trunk/server/source3/lib/messages.c

    r414 r745  
    4747
    4848#include "includes.h"
    49 #include "librpc/gen_ndr/messaging.h"
    50 #include "librpc/gen_ndr/ndr_messaging.h"
     49#include "dbwrap.h"
     50#include "serverid.h"
     51#include "messages.h"
    5152
    5253struct messaging_callback {
     
    9697****************************************************************************/
    9798
    98 static int traverse_fn(struct db_record *rec,
    99                        const struct connections_key *ckey,
    100                        const struct connections_data *crec,
    101                        void *state)
     99static int traverse_fn(struct db_record *rec, const struct server_id *id,
     100                       uint32_t msg_flags, void *state)
    102101{
    103102        struct msg_all *msg_all = (struct msg_all *)state;
    104103        NTSTATUS status;
    105104
    106         if (crec->cnum != -1)
     105        /* Don't send if the receiver hasn't registered an interest. */
     106
     107        if((msg_flags & msg_all->msg_flag) == 0) {
    107108                return 0;
    108 
    109         /* Don't send if the receiver hasn't registered an interest. */
    110 
    111         if(!(crec->bcast_msg_flags & msg_all->msg_flag))
    112                 return 0;
     109        }
    113110
    114111        /* If the msg send fails because the pid was not found (i.e. smbd died),
    115112         * the msg has already been deleted from the messages.tdb.*/
    116113
    117         status = messaging_send_buf(msg_all->msg_ctx,
    118                                     crec->pid, msg_all->msg_type,
     114        status = messaging_send_buf(msg_all->msg_ctx, *id, msg_all->msg_type,
    119115                                    (uint8 *)msg_all->buf, msg_all->len);
    120116
     
    123119                /* If the pid was not found delete the entry from connections.tdb */
    124120
    125                 DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
    126                          procid_str_static(&crec->pid), crec->cnum,
    127                          crec->servicename));
     121                DEBUG(2, ("pid %s doesn't exist\n", procid_str_static(id)));
    128122
    129123                rec->delete_rec(rec);
     
    173167        msg_all.msg_ctx = msg_ctx;
    174168
    175         connections_forall(traverse_fn, &msg_all);
     169        serverid_traverse(traverse_fn, &msg_all);
    176170        if (n_sent)
    177171                *n_sent = msg_all.n_sent;
     
    201195
    202196        if (!NT_STATUS_IS_OK(status)) {
    203                 DEBUG(0, ("messaging_tdb_init failed: %s\n",
     197                DEBUG(2, ("messaging_tdb_init failed: %s\n",
    204198                          nt_errstr(status)));
    205199                TALLOC_FREE(ctx);
     
    212206
    213207                if (!NT_STATUS_IS_OK(status)) {
    214                         DEBUG(1, ("messaging_ctdb_init failed: %s\n",
     208                        DEBUG(2, ("messaging_ctdb_init failed: %s\n",
    215209                                  nt_errstr(status)));
    216210                        TALLOC_FREE(ctx);
     
    218212                }
    219213        }
     214        ctx->id.vnn = get_my_vnn();
    220215#endif
    221216
     
    231226}
    232227
     228struct server_id messaging_server_id(const struct messaging_context *msg_ctx)
     229{
     230        return msg_ctx->id;
     231}
     232
    233233/*
    234234 * re-init after a fork
    235235 */
    236 NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
     236NTSTATUS messaging_reinit(struct messaging_context *msg_ctx,
     237                          struct server_id id)
    237238{
    238239        NTSTATUS status;
    239240
    240241        TALLOC_FREE(msg_ctx->local);
     242
     243        msg_ctx->id = id;
    241244
    242245        status = messaging_tdb_init(msg_ctx, msg_ctx, &msg_ctx->local);
     
    361364
    362365/*
    363   Dispatch one messsaging_rec
     366  Dispatch one messaging_rec
    364367*/
    365368void messaging_dispatch_rec(struct messaging_context *msg_ctx,
  • trunk/server/source3/lib/messages_ctdbd.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "messages.h"
     22#include "util_tdb.h"
    2123
    2224#ifdef CLUSTER_SUPPORT
    2325
    24 #include "librpc/gen_ndr/messaging.h"
    2526#include "ctdb.h"
    2627#include "ctdb_private.h"
     
    8182        msg.msg_type    = msg_type;
    8283        msg.dest        = pid;
    83         msg.src         = procid_self();
     84        msg.src         = msg_ctx->id;
    8485        msg.buf         = *data;
    8586
  • trunk/server/source3/lib/messages_local.c

    r414 r745  
    33   Samba internal messaging functions
    44   Copyright (C) 2007 by Volker Lendecke
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2222  @{
    2323  @file messages.c
    24  
     24
    2525  @brief  Module for internal messaging between Samba daemons.
    2626
     
    4444
    4545#include "includes.h"
    46 #include "librpc/gen_ndr/messaging.h"
    47 #include "librpc/gen_ndr/ndr_messaging.h"
     46#include "system/filesys.h"
     47#include "messages.h"
     48#include "lib/util/tdb_wrap.h"
    4849
    4950struct messaging_tdb_context {
     
    104105
    105106        ctx->tdb = tdb_wrap_open(ctx, lock_path("messages.tdb"), 0,
    106                                  TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE,
     107                                 TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH,
    107108                                 O_RDWR|O_CREAT,0600);
    108109
    109110        if (!ctx->tdb) {
    110111                NTSTATUS status = map_nt_error_from_unix(errno);
    111                 DEBUG(0, ("ERROR: Failed to initialise messages database: "
     112                DEBUG(2, ("ERROR: Failed to initialise messages database: "
    112113                          "%s\n", strerror(errno)));
    113114                TALLOC_FREE(result);
     
    134135}
    135136
     137bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx)
     138{
     139        struct tdb_wrap *db;
     140
     141        /*
     142         * Open the tdb in the parent process (smbd) so that our
     143         * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
     144         * work.
     145         */
     146
     147        db = tdb_wrap_open(mem_ctx, lock_path("messages.tdb"), 0,
     148                           TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH,
     149                           O_RDWR|O_CREAT,0600);
     150        if (db == NULL) {
     151                DEBUG(1, ("could not open messaging.tdb: %s\n",
     152                          strerror(errno)));
     153                return false;
     154        }
     155        return true;
     156}
     157
    136158/*******************************************************************
    137159 Form a static tdb key from a pid.
     
    146168
    147169        SMB_ASSERT(key != NULL);
    148        
     170
    149171        kbuf.dptr = (uint8 *)key;
    150172        kbuf.dsize = strlen(key)+1;
     
    180202
    181203        ndr_err = ndr_pull_struct_blob(
    182                 &blob, result, NULL, result,
     204                &blob, result, result,
    183205                (ndr_pull_flags_fn_t)ndr_pull_messaging_array);
    184206
     
    222244        }
    223245
    224         ndr_err = ndr_push_struct_blob(
    225                 &blob, mem_ctx, NULL, array,
     246        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, array,
    226247                (ndr_push_flags_fn_t)ndr_push_messaging_array);
    227248
     
    361382        rec[msg_array->num_messages].msg_type = msg_type & MSG_TYPE_MASK;
    362383        rec[msg_array->num_messages].dest = pid;
    363         rec[msg_array->num_messages].src = procid_self();
     384        rec[msg_array->num_messages].src = msg_ctx->id;
    364385        rec[msg_array->num_messages].buf = *data;
    365386
     
    372393                goto done;
    373394        }
    374        
     395
    375396        status = message_notify(pid);
    376397
     
    388409
    389410/****************************************************************************
    390  Retrieve all messages for the current process.
     411 Retrieve all messages for a process.
    391412****************************************************************************/
    392413
    393414static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb,
     415                                      struct server_id id,
    394416                                      TALLOC_CTX *mem_ctx,
    395417                                      struct messaging_array **presult)
    396418{
    397419        struct messaging_array *result;
    398         TDB_DATA key = message_key_pid(mem_ctx, procid_self());
     420        TDB_DATA key = message_key_pid(mem_ctx, id);
    399421        NTSTATUS status;
    400422
     
    444466                   ctx->received_messages));
    445467
    446         status = retrieve_all_messages(tdb->tdb, NULL, &msg_array);
     468        status = retrieve_all_messages(tdb->tdb, msg_ctx->id, NULL, &msg_array);
    447469        if (!NT_STATUS_IS_OK(status)) {
    448470                DEBUG(0, ("message_dispatch: failed to retrieve messages: %s\n",
  • trunk/server/source3/lib/ms_fnmatch.c

    r414 r745  
    235235int gen_fnmatch(const char *pattern, const char *string)
    236236{
    237         return ms_fnmatch(pattern, string, PROTOCOL_NT1, False);
    238 }
     237        return ms_fnmatch(pattern, string, true, False);
     238}
  • trunk/server/source3/lib/netapi/cm.c

    r590 r745  
    1919
    2020#include "includes.h"
     21#include "popt_common.h"
    2122
    2223#include "lib/netapi/netapi.h"
    2324#include "lib/netapi/netapi_private.h"
     25#include "libsmb/libsmb.h"
     26#include "rpc_client/cli_pipe.h"
    2427
    2528/********************************************************************
     
    251254        return WERR_OK;
    252255}
     256
     257/********************************************************************
     258********************************************************************/
     259
     260WERROR libnetapi_get_binding_handle(struct libnetapi_ctx *ctx,
     261                                    const char *server_name,
     262                                    const struct ndr_syntax_id *interface,
     263                                    struct dcerpc_binding_handle **binding_handle)
     264{
     265        struct rpc_pipe_client *pipe_cli;
     266        WERROR result;
     267
     268        *binding_handle = NULL;
     269
     270        result = libnetapi_open_pipe(ctx, server_name, interface, &pipe_cli);
     271        if (!W_ERROR_IS_OK(result)) {
     272                return result;
     273        }
     274
     275        *binding_handle = pipe_cli->binding_handle;
     276
     277        return WERR_OK;
     278}
  • trunk/server/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c

    r480 r745  
    479479                        p = strchr(newname, '.');
    480480                        if (p) {
    481                                 *p = NULL;
     481                                *p = '\0';
    482482                        }
    483483
  • trunk/server/source3/lib/netapi/examples/netlogon/nltest.c

    r414 r745  
    3131
    3232enum {
    33         OPT_DBFLAG = 1,
     33        OPT_SERVER = 1,
     34        OPT_DBFLAG,
    3435        OPT_SC_QUERY,
    3536        OPT_SC_RESET,
    3637        OPT_SC_VERIFY,
    37         OPT_SC_CHANGE_PWD
     38        OPT_SC_CHANGE_PWD,
     39        OPT_DSGETDC,
     40        OPT_PDC,
     41        OPT_DS,
     42        OPT_DSP,
     43        OPT_GC,
     44        OPT_KDC,
     45        OPT_TIMESERV,
     46        OPT_GTIMESERV,
     47        OPT_WS,
     48        OPT_NETBIOS,
     49        OPT_DNS,
     50        OPT_IP,
     51        OPT_FORCE,
     52        OPT_WRITABLE,
     53        OPT_AVOIDSELF,
     54        OPT_LDAPONLY,
     55        OPT_BACKG,
     56        OPT_DS_6,
     57        OPT_TRY_NEXT_CLOSEST_SITE,
     58        OPT_SITE,
     59        OPT_ACCOUNT,
     60        OPT_RET_DNS,
     61        OPT_RET_NETBIOS,
     62        OPT_DSREGDNS
    3863};
    3964
     
    4166****************************************************************/
    4267
    43 static void print_result(uint32_t level,
    44                         uint8_t *buffer)
     68static void print_netlogon_info_result(uint32_t level,
     69                                      uint8_t *buffer)
    4570{
    4671        struct NETLOGON_INFO_1 *i1 = NULL;
     
    101126****************************************************************/
    102127
     128static void print_dc_info_flags(uint32_t flags)
     129{
     130        if (flags & DS_PDC_FLAG)
     131                printf("PDC ");
     132        if (flags & DS_GC_FLAG)
     133                printf("GC ");
     134        if (flags & DS_DS_FLAG)
     135                printf("DS ");
     136        if (flags & DS_LDAP_FLAG)
     137                printf("LDAP ");
     138        if (flags & DS_KDC_FLAG)
     139                printf("KDC ");
     140        if (flags & DS_TIMESERV_FLAG)
     141                printf("TIMESERV ");
     142        if (flags & DS_GOOD_TIMESERV_FLAG)
     143                printf("GTIMESERV ");
     144        if (flags & DS_WRITABLE_FLAG)
     145                printf("WRITABLE ");
     146        if (flags & DS_DNS_FOREST_FLAG)
     147                printf("DNS_FOREST ");
     148        if (flags & DS_CLOSEST_FLAG)
     149                printf("CLOSE_SITE ");
     150        if (flags & DS_FULL_SECRET_DOMAIN_6_FLAG)
     151                printf("FULL_SECRET ");
     152        /* "WS" */
     153        printf("\n");
     154}
     155
     156/****************************************************************
     157****************************************************************/
     158
     159static void print_dc_info(struct DOMAIN_CONTROLLER_INFO *dc_info)
     160{
     161        if (dc_info->flags) {
     162                printf("           DC: %s\n", dc_info->domain_controller_name);
     163                printf("      Address: %s\n", dc_info->domain_controller_address);
     164/*              printf("     Dom Guid: %s\n", X(domain_guid)); */
     165                printf("     Dom Name: %s\n", dc_info->domain_name);
     166                printf("  Forest Name: %s\n", dc_info->dns_forest_name);
     167                printf(" Dc Site Name: %s\n", dc_info->dc_site_name);
     168                printf("Our Site Name: %s\n", dc_info->client_site_name);
     169                printf("        Flags: ");
     170                print_dc_info_flags(dc_info->flags);
     171        } else {
     172                printf("           DC: %s\n", dc_info->domain_controller_name);
     173                printf("      Address: %s\n", dc_info->domain_controller_address);
     174                printf("     Dom Name: %s\n", dc_info->domain_name);
     175        }
     176}
     177
     178/****************************************************************
     179****************************************************************/
     180
    103181int main(int argc, const char **argv)
    104182{
     
    106184        NET_API_STATUS status;
    107185        struct libnetapi_ctx *ctx = NULL;
    108         const char *server_name = NULL;
     186        char *opt_server = NULL;
    109187        char *opt_domain = NULL;
    110188        int opt_dbflag = 0;
    111         uint32_t query_level;
     189        int opt_pdc = 0;
     190        int opt_ds = 0;
     191        int opt_dsp = 0;
     192        int opt_gc = 0;
     193        int opt_kdc = 0;
     194        int opt_timeserv = 0;
     195        int opt_gtimeserv = 0;
     196        int opt_ws = 0;
     197        int opt_netbios = 0;
     198        int opt_dns = 0;
     199        int opt_ip = 0;
     200        int opt_force = 0;
     201        int opt_writable = 0;
     202        int opt_avoidself = 0;
     203        int opt_ldaponly = 0;
     204        int opt_backg = 0;
     205        int opt_ds_6 = 0;
     206        int opt_try_next_closest_site = 0;
     207        char *opt_site = NULL;
     208        char *opt_account = NULL;
     209        int opt_ret_dns = 0;
     210        int opt_ret_netbios = 0;
     211        int opt_dsregdns = 0;
     212        uint32_t query_level = 0;
    112213        uint8_t *buffer = NULL;
     214        uint32_t flags = 0;
     215        struct DOMAIN_CONTROLLER_INFO *dc_info = NULL;
    113216
    114217        poptContext pc;
    115218        struct poptOption long_options[] = {
    116219                POPT_AUTOHELP
     220                {"server", 0, POPT_ARG_STRING, &opt_server, OPT_SERVER, "Servername", "SERVER"},
    117221                {"dbflag", 0, POPT_ARG_INT,   &opt_dbflag, OPT_DBFLAG, "New Debug Flag", "HEXFLAGS"},
    118222                {"sc_query", 0, POPT_ARG_STRING,   &opt_domain, OPT_SC_QUERY, "Query secure channel for domain on server", "DOMAIN"},
     
    120224                {"sc_verify", 0, POPT_ARG_STRING,   &opt_domain, OPT_SC_VERIFY, "Verify secure channel for domain on server", "DOMAIN"},
    121225                {"sc_change_pwd", 0, POPT_ARG_STRING,   &opt_domain, OPT_SC_CHANGE_PWD, "Change a secure channel password for domain on server", "DOMAIN"},
     226                {"dsgetdc", 0, POPT_ARG_STRING, &opt_domain, OPT_DSGETDC, "Call DsGetDcName", "DOMAIN"},
     227                {"pdc", 0, POPT_ARG_NONE, &opt_pdc, OPT_PDC, NULL},
     228                {"ds", 0, POPT_ARG_NONE, &opt_ds, OPT_DS, NULL},
     229                {"dsp", 0, POPT_ARG_NONE, &opt_dsp, OPT_DSP, NULL},
     230                {"gc", 0, POPT_ARG_NONE, &opt_gc, OPT_GC, NULL},
     231                {"kdc", 0, POPT_ARG_NONE, &opt_kdc, OPT_KDC, NULL},
     232                {"timeserv", 0, POPT_ARG_NONE, &opt_timeserv, OPT_TIMESERV, NULL},
     233                {"gtimeserv", 0, POPT_ARG_NONE, &opt_gtimeserv, OPT_GTIMESERV, NULL},
     234                {"ws", 0, POPT_ARG_NONE, &opt_ws, OPT_WS, NULL},
     235                {"netbios", 0, POPT_ARG_NONE, &opt_netbios, OPT_NETBIOS, NULL},
     236                {"dns", 0, POPT_ARG_NONE, &opt_dns, OPT_DNS, NULL},
     237                {"ip", 0, POPT_ARG_NONE, &opt_ip, OPT_IP, NULL},
     238                {"force", 0, POPT_ARG_NONE, &opt_force, OPT_FORCE, NULL},
     239                {"writable", 0, POPT_ARG_NONE, &opt_writable, OPT_WRITABLE, NULL},
     240                {"avoidself", 0, POPT_ARG_NONE, &opt_avoidself, OPT_AVOIDSELF, NULL},
     241                {"ldaponly", 0, POPT_ARG_NONE, &opt_ldaponly, OPT_LDAPONLY, NULL},
     242                {"backg", 0, POPT_ARG_NONE, &opt_backg, OPT_BACKG, NULL},
     243                {"ds_6", 0, POPT_ARG_NONE, &opt_ds_6, OPT_DS_6, NULL},
     244                {"try_next_closest_site", 0, POPT_ARG_NONE, &opt_try_next_closest_site, OPT_TRY_NEXT_CLOSEST_SITE, NULL},
     245                {"site", 0, POPT_ARG_STRING, &opt_site, OPT_SITE, "SITE"},
     246                {"account", 0, POPT_ARG_STRING, &opt_account, OPT_ACCOUNT, "ACCOUNT"},
     247                {"ret_dns", 0, POPT_ARG_NONE, &opt_ret_dns, OPT_RET_DNS, NULL},
     248                {"ret_netbios", 0, POPT_ARG_NONE, &opt_ret_netbios, OPT_RET_NETBIOS, NULL},
     249                {"dsregdns", 0, POPT_ARG_NONE, &opt_dsregdns, OPT_DSREGDNS, "Force registration of all DC-specific DNS records"},
    122250                POPT_COMMON_LIBNETAPI_EXAMPLES
    123251                POPT_TABLEEND
     
    131259        pc = poptGetContext("nltest", argc, argv, long_options, 0);
    132260
    133         poptSetOtherOptionHelp(pc, "server_name");
     261        poptSetOtherOptionHelp(pc, "<options>");
    134262        while((opt = poptGetNextOpt(pc)) != -1) {
    135263        }
    136 
    137         if (!poptPeekArg(pc)) {
    138                 poptPrintHelp(pc, stderr, 0);
    139                 goto done;
    140         }
    141         server_name = poptGetArg(pc);
    142264
    143265        if (argc == 1) {
     
    146268        }
    147269
    148         if (!server_name || poptGetArg(pc)) {
    149                 poptPrintHelp(pc, stderr, 0);
    150                 goto done;
    151         }
    152 
    153         if ((server_name[0] == '/' && server_name[1] == '/') ||
    154             (server_name[0] == '\\' && server_name[1] ==  '\\')) {
    155                 server_name += 2;
    156         }
    157 
    158270        poptResetContext(pc);
    159271
     
    161273                switch (opt) {
    162274
     275                case OPT_SERVER:
     276
     277                        if ((opt_server[0] == '/' && opt_server[1] == '/') ||
     278                            (opt_server[0] == '\\' && opt_server[1] ==  '\\')) {
     279                                opt_server += 2;
     280                        }
     281
     282                        break;
     283
    163284                case OPT_DBFLAG:
    164285                        query_level = 1;
    165                         status = I_NetLogonControl2(server_name,
     286                        status = I_NetLogonControl2(opt_server,
    166287                                                    NETLOGON_CONTROL_SET_DBFLAG,
    167288                                                    query_level,
     
    174295                                goto done;
    175296                        }
     297
     298                        print_netlogon_info_result(query_level, buffer);
     299
    176300                        break;
    177301                case OPT_SC_QUERY:
    178302                        query_level = 2;
    179                         status = I_NetLogonControl2(server_name,
     303                        status = I_NetLogonControl2(opt_server,
    180304                                                    NETLOGON_CONTROL_TC_QUERY,
    181305                                                    query_level,
     
    188312                                goto done;
    189313                        }
     314
     315                        print_netlogon_info_result(query_level, buffer);
     316
    190317                        break;
    191318                case OPT_SC_VERIFY:
    192319                        query_level = 2;
    193                         status = I_NetLogonControl2(server_name,
     320                        status = I_NetLogonControl2(opt_server,
    194321                                                    NETLOGON_CONTROL_TC_VERIFY,
    195322                                                    query_level,
     
    202329                                goto done;
    203330                        }
     331
     332                        print_netlogon_info_result(query_level, buffer);
     333
    204334                        break;
    205335                case OPT_SC_RESET:
    206336                        query_level = 2;
    207                         status = I_NetLogonControl2(server_name,
     337                        status = I_NetLogonControl2(opt_server,
    208338                                                    NETLOGON_CONTROL_REDISCOVER,
    209339                                                    query_level,
     
    216346                                goto done;
    217347                        }
     348
     349                        print_netlogon_info_result(query_level, buffer);
     350
    218351                        break;
    219352                case OPT_SC_CHANGE_PWD:
    220353                        query_level = 1;
    221                         status = I_NetLogonControl2(server_name,
     354                        status = I_NetLogonControl2(opt_server,
    222355                                                    NETLOGON_CONTROL_CHANGE_PASSWORD,
    223356                                                    query_level,
     
    230363                                goto done;
    231364                        }
     365
     366                        print_netlogon_info_result(query_level, buffer);
     367
     368                        break;
     369                case OPT_DSREGDNS:
     370                        query_level = 1;
     371                        status = I_NetLogonControl2(opt_server,
     372                                                    NETLOGON_CONTROL_FORCE_DNS_REG,
     373                                                    query_level,
     374                                                    NULL,
     375                                                    &buffer);
     376                        if (status != 0) {
     377                                fprintf(stderr, "I_NetlogonControl failed: Status = %d 0x%x %s\n",
     378                                        status, status,
     379                                        libnetapi_get_error_string(ctx, status));
     380                                goto done;
     381                        }
     382
     383                        print_netlogon_info_result(query_level, buffer);
     384
     385                        break;
     386                case OPT_DSGETDC:
     387                        if (opt_pdc)
     388                                flags |= DS_PDC_REQUIRED;
     389                        if (opt_ds)
     390                                flags |= DS_DIRECTORY_SERVICE_REQUIRED;
     391                        if (opt_dsp)
     392                                flags |= DS_DIRECTORY_SERVICE_PREFERRED;
     393                        if (opt_kdc)
     394                                flags |= DS_KDC_REQUIRED;
     395                        if (opt_timeserv)
     396                                flags |= DS_TIMESERV_REQUIRED;
     397                        if (opt_gtimeserv)
     398                                flags |= DS_GOOD_TIMESERV_PREFERRED;
     399                        if (opt_ws)
     400                                flags |= DS_WEB_SERVICE_REQUIRED;
     401                        if (opt_netbios)
     402                                flags |= DS_IS_FLAT_NAME;
     403                        if (opt_dns)
     404                                flags |= DS_IS_DNS_NAME;
     405                        if (opt_ip)
     406                                flags |= DS_IP_REQUIRED;
     407                        if (opt_force)
     408                                flags |= DS_FORCE_REDISCOVERY;
     409                        if (opt_writable)
     410                                flags |= DS_WRITABLE_REQUIRED;
     411                        if (opt_avoidself)
     412                                flags |= DS_AVOID_SELF;
     413                        if (opt_ldaponly)
     414                                flags |= DS_ONLY_LDAP_NEEDED;
     415                        if (opt_backg)
     416                                flags |= DS_BACKGROUND_ONLY;
     417                        if (opt_ds_6)
     418                                flags |= DS_DIRECTORY_SERVICE_6_REQUIRED;
     419                        if (opt_try_next_closest_site)
     420                                flags |= DS_TRY_NEXTCLOSEST_SITE;
     421                        if (opt_ret_dns)
     422                                flags |= DS_RETURN_DNS_NAME;
     423                        if (opt_ret_netbios)
     424                                flags |= DS_RETURN_FLAT_NAME;
     425
     426                        status = DsGetDcName(opt_server,
     427                                             opt_domain,
     428                                             NULL, /* domain_guid */
     429                                             opt_site,
     430                                             flags,
     431                                             &dc_info);
     432                        if (status != 0) {
     433                                fprintf(stderr, "DsGetDcName failed: Status = %d 0x%x %s\n",
     434                                        status, status,
     435                                        libnetapi_get_error_string(ctx, status));
     436                                goto done;
     437                        }
     438
     439                        print_dc_info(dc_info);
     440
    232441                        break;
    233442                default:
    234                         poptPrintHelp(pc, stderr, 0);
    235                         goto done;
     443                        continue;
    236444                }
    237445        }
    238 
    239         print_result(query_level, buffer);
    240446
    241447        printf("The command completed successfully\n");
  • trunk/server/source3/lib/netapi/file.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_srvsvc.h"
     26#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
    2727
    2828/****************************************************************
     
    3434        WERROR werr;
    3535        NTSTATUS status;
    36         struct rpc_pipe_client *pipe_cli = NULL;
    37 
    38         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    39                                    &ndr_table_srvsvc.syntax_id,
    40                                    &pipe_cli);
    41         if (!W_ERROR_IS_OK(werr)) {
    42                 goto done;
    43         }
    44 
    45         status = rpccli_srvsvc_NetFileClose(pipe_cli, talloc_tos(),
     36        struct dcerpc_binding_handle *b;
     37
     38        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     39                                            &ndr_table_srvsvc.syntax_id,
     40                                            &b);
     41        if (!W_ERROR_IS_OK(werr)) {
     42                goto done;
     43        }
     44
     45        status = dcerpc_srvsvc_NetFileClose(b, talloc_tos(),
    4646                                            r->in.server_name,
    4747                                            r->in.fileid,
     
    114114        WERROR werr;
    115115        NTSTATUS status;
    116         struct rpc_pipe_client *pipe_cli = NULL;
    117116        union srvsvc_NetFileInfo info;
    118117        uint32_t num_entries = 0;
     118        struct dcerpc_binding_handle *b;
    119119
    120120        if (!r->out.buffer) {
     
    130130        }
    131131
    132         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    133                                    &ndr_table_srvsvc.syntax_id,
    134                                    &pipe_cli);
    135         if (!W_ERROR_IS_OK(werr)) {
    136                 goto done;
    137         }
    138 
    139         status = rpccli_srvsvc_NetFileGetInfo(pipe_cli, talloc_tos(),
     132        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     133                                            &ndr_table_srvsvc.syntax_id,
     134                                            &b);
     135        if (!W_ERROR_IS_OK(werr)) {
     136                goto done;
     137        }
     138
     139        status = dcerpc_srvsvc_NetFileGetInfo(b, talloc_tos(),
    140140                                              r->in.server_name,
    141141                                              r->in.fileid,
     
    143143                                              &info,
    144144                                              &werr);
     145        if (!NT_STATUS_IS_OK(status)) {
     146                werr = ntstatus_to_werror(status);
     147                goto done;
     148        }
     149
    145150        if (!W_ERROR_IS_OK(werr)) {
    146151                goto done;
     
    177182        WERROR werr;
    178183        NTSTATUS status;
    179         struct rpc_pipe_client *pipe_cli = NULL;
    180184        struct srvsvc_NetFileInfoCtr info_ctr;
    181185        struct srvsvc_NetFileCtr2 ctr2;
     
    183187        uint32_t num_entries = 0;
    184188        uint32_t i;
     189        struct dcerpc_binding_handle *b;
    185190
    186191        if (!r->out.buffer) {
     
    196201        }
    197202
    198         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    199                                    &ndr_table_srvsvc.syntax_id,
    200                                    &pipe_cli);
     203        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     204                                            &ndr_table_srvsvc.syntax_id,
     205                                            &b);
    201206        if (!W_ERROR_IS_OK(werr)) {
    202207                goto done;
     
    217222        }
    218223
    219         status = rpccli_srvsvc_NetFileEnum(pipe_cli, talloc_tos(),
     224        status = dcerpc_srvsvc_NetFileEnum(b, talloc_tos(),
    220225                                           r->in.server_name,
    221226                                           r->in.base_path,
     
    226231                                           r->out.resume_handle,
    227232                                           &werr);
    228         if (NT_STATUS_IS_ERR(status)) {
     233        if (!NT_STATUS_IS_OK(status)) {
     234                werr = ntstatus_to_werror(status);
     235                goto done;
     236        }
     237
     238        if (!W_ERROR_IS_OK(werr) && !W_ERROR_EQUAL(werr, WERR_MORE_DATA)) {
    229239                goto done;
    230240        }
  • trunk/server/source3/lib/netapi/getdc.c

    r596 r745  
    2020#include "includes.h"
    2121
     22#include "../librpc/gen_ndr/ndr_netlogon_c.h"
    2223#include "librpc/gen_ndr/libnetapi.h"
    2324#include "lib/netapi/netapi.h"
    2425#include "lib/netapi/netapi_private.h"
    2526#include "lib/netapi/libnetapi.h"
    26 #include "libnet/libnet.h"
    27 #include "../librpc/gen_ndr/cli_netlogon.h"
    2827
    2928/********************************************************************
     
    4241                      struct NetGetDCName *r)
    4342{
    44         struct rpc_pipe_client *pipe_cli = NULL;
    4543        NTSTATUS status;
    4644        WERROR werr;
     45        struct dcerpc_binding_handle *b;
    4746
    48         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    49                                    &ndr_table_netlogon.syntax_id,
    50                                    &pipe_cli);
     47        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     48                                            &ndr_table_netlogon.syntax_id,
     49                                            &b);
    5150        if (!W_ERROR_IS_OK(werr)) {
    5251                goto done;
    5352        }
    5453
    55         status = rpccli_netr_GetDcName(pipe_cli, talloc_tos(),
     54        status = dcerpc_netr_GetDcName(b, talloc_tos(),
    5655                                       r->in.server_name,
    5756                                       r->in.domain_name,
     
    8281                         struct NetGetAnyDCName *r)
    8382{
    84         struct rpc_pipe_client *pipe_cli = NULL;
    8583        NTSTATUS status;
    8684        WERROR werr;
     85        struct dcerpc_binding_handle *b;
    8786
    88         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    89                                    &ndr_table_netlogon.syntax_id,
    90                                    &pipe_cli);
     87        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     88                                            &ndr_table_netlogon.syntax_id,
     89                                            &b);
    9190        if (!W_ERROR_IS_OK(werr)) {
    9291                goto done;
    9392        }
    9493
    95         status = rpccli_netr_GetAnyDCName(pipe_cli, talloc_tos(),
     94        status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
    9695                                          r->in.server_name,
    9796                                          r->in.domain_name,
     
    9998                                          &werr);
    10099        if (!NT_STATUS_IS_OK(status)) {
     100                werr = ntstatus_to_werror(status);
    101101                goto done;
    102102        }
     
    114114{
    115115        NTSTATUS status;
     116        struct libnetapi_private_ctx *priv;
     117
     118        priv = talloc_get_type_abort(ctx->private_data,
     119                struct libnetapi_private_ctx);
    116120
    117121        status = dsgetdcname(ctx,
    118                              NULL,
     122                             priv->msg_ctx,
    119123                             r->in.domain_name,
    120124                             r->in.domain_guid,
     
    139143        WERROR werr;
    140144        NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
    141         struct rpc_pipe_client *pipe_cli = NULL;
     145        struct dcerpc_binding_handle *b;
    142146
    143         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    144                                    &ndr_table_netlogon.syntax_id,
    145                                    &pipe_cli);
     147        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     148                                            &ndr_table_netlogon.syntax_id,
     149                                            &b);
    146150        if (!W_ERROR_IS_OK(werr)) {
    147151                goto done;
    148152        }
    149153
    150         status = rpccli_netr_DsRGetDCName(pipe_cli,
     154        status = dcerpc_netr_DsRGetDCNameEx(b,
     155                                            ctx,
     156                                            r->in.server_name,
     157                                            r->in.domain_name,
     158                                            r->in.domain_guid,
     159                                            r->in.site_name,
     160                                            r->in.flags,
     161                                            (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
     162                                            &werr);
     163        if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
     164                goto done;
     165        }
     166
     167        status = dcerpc_netr_DsRGetDCName(b,
    151168                                          ctx,
    152169                                          r->in.server_name,
  • trunk/server/source3/lib/netapi/group.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_samr.h"
     26#include "rpc_client/rpc_client.h"
     27#include "../librpc/gen_ndr/ndr_samr_c.h"
     28#include "rpc_client/init_lsa.h"
     29#include "../libcli/security/security.h"
    2730
    2831/****************************************************************
     
    3336{
    3437        struct rpc_pipe_client *pipe_cli = NULL;
    35         NTSTATUS status;
     38        NTSTATUS status, result;
    3639        WERROR werr;
    3740        struct policy_handle connect_handle, domain_handle, group_handle;
     
    3942        struct dom_sid2 *domain_sid = NULL;
    4043        uint32_t rid = 0;
     44        struct dcerpc_binding_handle *b = NULL;
    4145
    4246        struct GROUP_INFO_0 *info0 = NULL;
     
    7882                goto done;
    7983        }
     84
     85        b = pipe_cli->binding_handle;
    8086
    8187        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    106112        }
    107113
    108         status = rpccli_samr_CreateDomainGroup(pipe_cli, talloc_tos(),
     114        status = dcerpc_samr_CreateDomainGroup(b, talloc_tos(),
    109115                                               &domain_handle,
    110116                                               &lsa_group_name,
     
    112118                                               SAMR_GROUP_ACCESS_SET_INFO,
    113119                                               &group_handle,
    114                                                &rid);
    115 
    116         if (!NT_STATUS_IS_OK(status)) {
    117                 werr = ntstatus_to_werror(status);
     120                                               &rid,
     121                                               &result);
     122
     123        if (!NT_STATUS_IS_OK(status)) {
     124                werr = ntstatus_to_werror(status);
     125                goto done;
     126        }
     127        if (!NT_STATUS_IS_OK(result)) {
     128                werr = ntstatus_to_werror(result);
    118129                goto done;
    119130        }
     
    125136                                                info1->grpi1_comment);
    126137
    127                                 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     138                                status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    128139                                                                  &group_handle,
    129140                                                                  GROUPINFODESCRIPTION,
    130                                                                   &info);
     141                                                                  &info,
     142                                                                  &result);
    131143                        }
    132144                        break;
     
    136148                                                info2->grpi2_comment);
    137149
    138                                 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     150                                status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    139151                                                                  &group_handle,
    140152                                                                  GROUPINFODESCRIPTION,
    141                                                                   &info);
     153                                                                  &info,
     154                                                                  &result);
    142155                                if (!NT_STATUS_IS_OK(status)) {
    143156                                        werr = ntstatus_to_werror(status);
    144157                                        goto failed;
    145158                                }
     159                                if (!NT_STATUS_IS_OK(result)) {
     160                                        werr = ntstatus_to_werror(result);
     161                                        goto failed;
     162                                }
    146163                        }
    147164
    148165                        if (info2->grpi2_attributes != 0) {
    149166                                info.attributes.attributes = info2->grpi2_attributes;
    150                                 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     167                                status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    151168                                                                  &group_handle,
    152169                                                                  GROUPINFOATTRIBUTES,
    153                                                                   &info);
     170                                                                  &info,
     171                                                                  &result);
    154172
    155173                        }
     
    160178                                                info3->grpi3_comment);
    161179
    162                                 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     180                                status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    163181                                                                  &group_handle,
    164182                                                                  GROUPINFODESCRIPTION,
    165                                                                   &info);
     183                                                                  &info,
     184                                                                  &result);
    166185                                if (!NT_STATUS_IS_OK(status)) {
    167186                                        werr = ntstatus_to_werror(status);
    168187                                        goto failed;
    169188                                }
     189                                if (!NT_STATUS_IS_OK(result)) {
     190                                        werr = ntstatus_to_werror(result);
     191                                        goto failed;
     192                                }
    170193                        }
    171194
    172195                        if (info3->grpi3_attributes != 0) {
    173196                                info.attributes.attributes = info3->grpi3_attributes;
    174                                 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     197                                status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    175198                                                                  &group_handle,
    176199                                                                  GROUPINFOATTRIBUTES,
    177                                                                   &info);
     200                                                                  &info,
     201                                                                  &result);
    178202                        }
    179203                        break;
     
    184208        if (!NT_STATUS_IS_OK(status)) {
    185209                werr = ntstatus_to_werror(status);
     210                goto failed;
     211        }
     212        if (!NT_STATUS_IS_OK(result)) {
     213                werr = ntstatus_to_werror(result);
    186214                goto failed;
    187215        }
     
    191219
    192220 failed:
    193         rpccli_samr_DeleteDomainGroup(pipe_cli, talloc_tos(),
    194                                       &group_handle);
     221        dcerpc_samr_DeleteDomainGroup(b, talloc_tos(),
     222                                      &group_handle, &result);
    195223
    196224 done:
    197225        if (is_valid_policy_hnd(&group_handle)) {
    198                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     226                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    199227        }
    200228
     
    223251{
    224252        struct rpc_pipe_client *pipe_cli = NULL;
    225         NTSTATUS status;
     253        NTSTATUS status, result;
    226254        WERROR werr;
    227255        struct policy_handle connect_handle, domain_handle, group_handle;
     
    229257        struct dom_sid2 *domain_sid = NULL;
    230258        int i = 0;
     259        struct dcerpc_binding_handle *b = NULL;
    231260
    232261        struct samr_Ids rids;
    233262        struct samr_Ids types;
    234263        union samr_GroupInfo *info = NULL;
    235         struct samr_RidTypeArray *rid_array = NULL;
     264        struct samr_RidAttrArray *rid_array = NULL;
    236265
    237266        ZERO_STRUCT(connect_handle);
     
    249278                goto done;
    250279        }
     280
     281        b = pipe_cli->binding_handle;
    251282
    252283        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    263294        init_lsa_String(&lsa_group_name, r->in.group_name);
    264295
    265         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     296        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    266297                                         &domain_handle,
    267298                                         1,
    268299                                         &lsa_group_name,
    269300                                         &rids,
    270                                          &types);
    271         if (!NT_STATUS_IS_OK(status)) {
    272                 werr = ntstatus_to_werror(status);
     301                                         &types,
     302                                         &result);
     303        if (!NT_STATUS_IS_OK(status)) {
     304                werr = ntstatus_to_werror(status);
     305                goto done;
     306        }
     307        if (!NT_STATUS_IS_OK(result)) {
     308                werr = ntstatus_to_werror(result);
    273309                goto done;
    274310        }
     
    279315        }
    280316
    281         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     317        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    282318                                       &domain_handle,
    283319                                       SEC_STD_DELETE |
     
    287323                                       SAMR_GROUP_ACCESS_LOOKUP_INFO,
    288324                                       rids.ids[0],
    289                                        &group_handle);
    290         if (!NT_STATUS_IS_OK(status)) {
    291                 werr = ntstatus_to_werror(status);
    292                 goto done;
    293         }
    294 
    295         status = rpccli_samr_QueryGroupInfo(pipe_cli, talloc_tos(),
     325                                       &group_handle,
     326                                       &result);
     327        if (!NT_STATUS_IS_OK(status)) {
     328                werr = ntstatus_to_werror(status);
     329                goto done;
     330        }
     331        if (!NT_STATUS_IS_OK(result)) {
     332                werr = ntstatus_to_werror(result);
     333                goto done;
     334        }
     335
     336        status = dcerpc_samr_QueryGroupInfo(b, talloc_tos(),
    296337                                            &group_handle,
    297338                                            GROUPINFOATTRIBUTES,
    298                                             &info);
    299         if (!NT_STATUS_IS_OK(status)) {
    300                 werr = ntstatus_to_werror(status);
     339                                            &info,
     340                                            &result);
     341        if (!NT_STATUS_IS_OK(status)) {
     342                werr = ntstatus_to_werror(status);
     343                goto done;
     344        }
     345        if (!NT_STATUS_IS_OK(result)) {
     346                werr = ntstatus_to_werror(result);
    301347                goto done;
    302348        }
     
    309355        }
    310356#endif
    311         status = rpccli_samr_QueryGroupMember(pipe_cli, talloc_tos(),
     357        status = dcerpc_samr_QueryGroupMember(b, talloc_tos(),
    312358                                              &group_handle,
    313                                               &rid_array);
    314         if (!NT_STATUS_IS_OK(status)) {
    315                 werr = ntstatus_to_werror(status);
     359                                              &rid_array,
     360                                              &result);
     361        if (!NT_STATUS_IS_OK(status)) {
     362                werr = ntstatus_to_werror(status);
     363                goto done;
     364        }
     365        if (!NT_STATUS_IS_OK(result)) {
     366                werr = ntstatus_to_werror(result);
    316367                goto done;
    317368        }
     
    321372        struct samr_Ids member_types;
    322373
    323         status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),
     374        status = dcerpc_samr_LookupRids(b, talloc_tos(),
    324375                                        &domain_handle,
    325376                                        rid_array->count,
    326377                                        rid_array->rids,
    327378                                        &names,
    328                                         &member_types);
    329         if (!NT_STATUS_IS_OK(status)) {
    330                 werr = ntstatus_to_werror(status);
     379                                        &member_types,
     380                                        &result);
     381        if (!NT_STATUS_IS_OK(status)) {
     382                werr = ntstatus_to_werror(status);
     383                goto done;
     384        }
     385        if (!NT_STATUS_IS_OK(result)) {
     386                werr = ntstatus_to_werror(result);
    331387                goto done;
    332388        }
     
    335391        for (i=0; i < rid_array->count; i++) {
    336392
    337                 status = rpccli_samr_DeleteGroupMember(pipe_cli, talloc_tos(),
     393                status = dcerpc_samr_DeleteGroupMember(b, talloc_tos(),
    338394                                                       &group_handle,
    339                                                        rid_array->rids[i]);
     395                                                       rid_array->rids[i],
     396                                                       &result);
    340397                if (!NT_STATUS_IS_OK(status)) {
    341398                        werr = ntstatus_to_werror(status);
    342399                        goto done;
    343400                }
    344         }
    345 
    346         status = rpccli_samr_DeleteDomainGroup(pipe_cli, talloc_tos(),
    347                                                &group_handle);
    348         if (!NT_STATUS_IS_OK(status)) {
    349                 werr = ntstatus_to_werror(status);
     401                if (!NT_STATUS_IS_OK(result)) {
     402                        werr = ntstatus_to_werror(result);
     403                        goto done;
     404                }
     405        }
     406
     407        status = dcerpc_samr_DeleteDomainGroup(b, talloc_tos(),
     408                                               &group_handle,
     409                                               &result);
     410        if (!NT_STATUS_IS_OK(status)) {
     411                werr = ntstatus_to_werror(status);
     412                goto done;
     413        }
     414        if (!NT_STATUS_IS_OK(result)) {
     415                werr = ntstatus_to_werror(result);
    350416                goto done;
    351417        }
     
    357423 done:
    358424        if (is_valid_policy_hnd(&group_handle)) {
    359                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     425                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    360426        }
    361427
     
    384450{
    385451        struct rpc_pipe_client *pipe_cli = NULL;
    386         NTSTATUS status;
     452        NTSTATUS status, result;
    387453        WERROR werr;
    388454        struct policy_handle connect_handle, domain_handle, group_handle;
    389455        struct lsa_String lsa_group_name;
    390456        struct dom_sid2 *domain_sid = NULL;
     457        struct dcerpc_binding_handle *b = NULL;
    391458
    392459        struct samr_Ids rids;
     
    415482        }
    416483
     484        b = pipe_cli->binding_handle;
     485
    417486        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
    418487                                          SAMR_ACCESS_ENUM_DOMAINS |
     
    428497        init_lsa_String(&lsa_group_name, r->in.group_name);
    429498
    430         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     499        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    431500                                         &domain_handle,
    432501                                         1,
    433502                                         &lsa_group_name,
    434503                                         &rids,
    435                                          &types);
    436         if (!NT_STATUS_IS_OK(status)) {
    437                 werr = ntstatus_to_werror(status);
     504                                         &types,
     505                                         &result);
     506        if (!NT_STATUS_IS_OK(status)) {
     507                werr = ntstatus_to_werror(status);
     508                goto done;
     509        }
     510        if (!NT_STATUS_IS_OK(result)) {
     511                werr = ntstatus_to_werror(result);
    438512                goto done;
    439513        }
     
    444518        }
    445519
    446         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     520        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    447521                                       &domain_handle,
    448522                                       SAMR_GROUP_ACCESS_SET_INFO |
    449523                                       SAMR_GROUP_ACCESS_LOOKUP_INFO,
    450524                                       rids.ids[0],
    451                                        &group_handle);
    452         if (!NT_STATUS_IS_OK(status)) {
    453                 werr = ntstatus_to_werror(status);
     525                                       &group_handle,
     526                                       &result);
     527        if (!NT_STATUS_IS_OK(status)) {
     528                werr = ntstatus_to_werror(status);
     529                goto done;
     530        }
     531        if (!NT_STATUS_IS_OK(result)) {
     532                werr = ntstatus_to_werror(result);
    454533                goto done;
    455534        }
     
    459538                        g0 = (struct GROUP_INFO_0 *)r->in.buffer;
    460539                        init_lsa_String(&info.name, g0->grpi0_name);
    461                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     540                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    462541                                                          &group_handle,
    463542                                                          GROUPINFONAME,
    464                                                           &info);
     543                                                          &info,
     544                                                          &result);
    465545                        break;
    466546                case 1:
    467547                        g1 = (struct GROUP_INFO_1 *)r->in.buffer;
    468548                        init_lsa_String(&info.description, g1->grpi1_comment);
    469                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     549                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    470550                                                          &group_handle,
    471551                                                          GROUPINFODESCRIPTION,
    472                                                           &info);
     552                                                          &info,
     553                                                          &result);
    473554                        break;
    474555                case 2:
    475556                        g2 = (struct GROUP_INFO_2 *)r->in.buffer;
    476557                        init_lsa_String(&info.description, g2->grpi2_comment);
    477                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     558                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    478559                                                          &group_handle,
    479560                                                          GROUPINFODESCRIPTION,
    480                                                           &info);
     561                                                          &info,
     562                                                          &result);
    481563                        if (!NT_STATUS_IS_OK(status)) {
    482564                                werr = ntstatus_to_werror(status);
    483565                                goto done;
    484566                        }
     567                        if (!NT_STATUS_IS_OK(result)) {
     568                                werr = ntstatus_to_werror(result);
     569                                goto done;
     570                        }
     571
    485572                        info.attributes.attributes = g2->grpi2_attributes;
    486                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     573                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    487574                                                          &group_handle,
    488575                                                          GROUPINFOATTRIBUTES,
    489                                                           &info);
     576                                                          &info,
     577                                                          &result);
    490578                        break;
    491579                case 3:
    492580                        g3 = (struct GROUP_INFO_3 *)r->in.buffer;
    493581                        init_lsa_String(&info.description, g3->grpi3_comment);
    494                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     582                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    495583                                                          &group_handle,
    496584                                                          GROUPINFODESCRIPTION,
    497                                                           &info);
     585                                                          &info,
     586                                                          &result);
    498587                        if (!NT_STATUS_IS_OK(status)) {
    499588                                werr = ntstatus_to_werror(status);
    500589                                goto done;
    501590                        }
     591                        if (!NT_STATUS_IS_OK(result)) {
     592                                werr = ntstatus_to_werror(result);
     593                                goto done;
     594                        }
     595
    502596                        info.attributes.attributes = g3->grpi3_attributes;
    503                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     597                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    504598                                                          &group_handle,
    505599                                                          GROUPINFOATTRIBUTES,
    506                                                           &info);
     600                                                          &info,
     601                                                          &result);
    507602                        break;
    508603                case 1002:
    509604                        g1002 = (struct GROUP_INFO_1002 *)r->in.buffer;
    510605                        init_lsa_String(&info.description, g1002->grpi1002_comment);
    511                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     606                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    512607                                                          &group_handle,
    513608                                                          GROUPINFODESCRIPTION,
    514                                                           &info);
     609                                                          &info,
     610                                                          &result);
    515611                        break;
    516612                case 1005:
    517613                        g1005 = (struct GROUP_INFO_1005 *)r->in.buffer;
    518614                        info.attributes.attributes = g1005->grpi1005_attributes;
    519                         status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),
     615                        status = dcerpc_samr_SetGroupInfo(b, talloc_tos(),
    520616                                                          &group_handle,
    521617                                                          GROUPINFOATTRIBUTES,
    522                                                           &info);
     618                                                          &info,
     619                                                          &result);
    523620                        break;
    524621                default:
     
    531628                goto done;
    532629        }
     630        if (!NT_STATUS_IS_OK(result)) {
     631                werr = ntstatus_to_werror(result);
     632                goto done;
     633        }
    533634
    534635        werr = WERR_OK;
     
    536637 done:
    537638        if (is_valid_policy_hnd(&group_handle)) {
    538                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     639                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    539640        }
    540641
     
    603704                        info3.grpi3_comment     = info->description.string;
    604705                        info3.grpi3_attributes  = info->attributes;
    605                         info3.grpi3_group_sid   = (struct domsid *)sid_dup_talloc(mem_ctx, &sid);
     706                        info3.grpi3_group_sid   = (struct domsid *)dom_sid_dup(mem_ctx, &sid);
    606707
    607708                        *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, sizeof(info3));
     
    624725{
    625726        struct rpc_pipe_client *pipe_cli = NULL;
    626         NTSTATUS status;
     727        NTSTATUS status, result;
    627728        WERROR werr;
    628729        struct policy_handle connect_handle, domain_handle, group_handle;
    629730        struct lsa_String lsa_group_name;
    630731        struct dom_sid2 *domain_sid = NULL;
     732        struct dcerpc_binding_handle *b = NULL;
    631733
    632734        struct samr_Ids rids;
     
    649751                goto done;
    650752        }
     753
     754        b = pipe_cli->binding_handle;
    651755
    652756        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    663767        init_lsa_String(&lsa_group_name, r->in.group_name);
    664768
    665         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     769        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    666770                                         &domain_handle,
    667771                                         1,
    668772                                         &lsa_group_name,
    669773                                         &rids,
    670                                          &types);
    671         if (!NT_STATUS_IS_OK(status)) {
    672                 werr = ntstatus_to_werror(status);
     774                                         &types,
     775                                         &result);
     776        if (!NT_STATUS_IS_OK(status)) {
     777                werr = ntstatus_to_werror(status);
     778                goto done;
     779        }
     780        if (!NT_STATUS_IS_OK(result)) {
     781                werr = ntstatus_to_werror(result);
    673782                goto done;
    674783        }
     
    679788        }
    680789
    681         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     790        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    682791                                       &domain_handle,
    683792                                       SAMR_GROUP_ACCESS_LOOKUP_INFO,
    684793                                       rids.ids[0],
    685                                        &group_handle);
    686         if (!NT_STATUS_IS_OK(status)) {
    687                 werr = ntstatus_to_werror(status);
    688                 goto done;
    689         }
    690 
    691         status = rpccli_samr_QueryGroupInfo(pipe_cli, talloc_tos(),
     794                                       &group_handle,
     795                                       &result);
     796        if (!NT_STATUS_IS_OK(status)) {
     797                werr = ntstatus_to_werror(status);
     798                goto done;
     799        }
     800        if (!NT_STATUS_IS_OK(result)) {
     801                werr = ntstatus_to_werror(result);
     802                goto done;
     803        }
     804
     805        status = dcerpc_samr_QueryGroupInfo(b, talloc_tos(),
    692806                                            &group_handle,
    693807                                            GROUPINFOALL2,
    694                                             &info);
    695         if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
    696                 status = rpccli_samr_QueryGroupInfo(pipe_cli, talloc_tos(),
     808                                            &info,
     809                                            &result);
     810        if (!NT_STATUS_IS_OK(status)) {
     811                werr = ntstatus_to_werror(status);
     812                goto done;
     813        }
     814
     815        if (NT_STATUS_EQUAL(result, NT_STATUS_INVALID_INFO_CLASS)) {
     816                status = dcerpc_samr_QueryGroupInfo(b, talloc_tos(),
    697817                                                    &group_handle,
    698818                                                    GROUPINFOALL,
    699                                                     &info);
     819                                                    &info,
     820                                                    &result);
    700821                group_info_all = true;
    701         }
    702 
    703         if (!NT_STATUS_IS_OK(status)) {
    704                 werr = ntstatus_to_werror(status);
     822                if (!NT_STATUS_IS_OK(status)) {
     823                        werr = ntstatus_to_werror(status);
     824                        goto done;
     825                }
     826        }
     827
     828        if (!NT_STATUS_IS_OK(result)) {
     829                werr = ntstatus_to_werror(result);
    705830                goto done;
    706831        }
     
    715840 done:
    716841        if (is_valid_policy_hnd(&group_handle)) {
    717                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     842                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    718843        }
    719844
     
    742867{
    743868        struct rpc_pipe_client *pipe_cli = NULL;
    744         NTSTATUS status;
     869        NTSTATUS status, result;
    745870        WERROR werr;
    746871        struct policy_handle connect_handle, domain_handle, group_handle;
    747872        struct lsa_String lsa_group_name, lsa_user_name;
    748873        struct dom_sid2 *domain_sid = NULL;
     874        struct dcerpc_binding_handle *b = NULL;
    749875
    750876        struct samr_Ids rids;
     
    765891                goto done;
    766892        }
     893
     894        b = pipe_cli->binding_handle;
    767895
    768896        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    779907        init_lsa_String(&lsa_group_name, r->in.group_name);
    780908
    781         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     909        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    782910                                         &domain_handle,
    783911                                         1,
    784912                                         &lsa_group_name,
    785913                                         &rids,
    786                                          &types);
    787         if (!NT_STATUS_IS_OK(status)) {
     914                                         &types,
     915                                         &result);
     916        if (!NT_STATUS_IS_OK(status)) {
     917                werr = ntstatus_to_werror(status);
     918                goto done;
     919        }
     920        if (!NT_STATUS_IS_OK(result)) {
    788921                werr = WERR_GROUPNOTFOUND;
    789922                goto done;
     
    795928        }
    796929
    797         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     930        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    798931                                       &domain_handle,
    799932                                       SAMR_GROUP_ACCESS_ADD_MEMBER,
    800933                                       rids.ids[0],
    801                                        &group_handle);
    802         if (!NT_STATUS_IS_OK(status)) {
    803                 werr = ntstatus_to_werror(status);
     934                                       &group_handle,
     935                                       &result);
     936        if (!NT_STATUS_IS_OK(status)) {
     937                werr = ntstatus_to_werror(status);
     938                goto done;
     939        }
     940        if (!NT_STATUS_IS_OK(result)) {
     941                werr = ntstatus_to_werror(result);
    804942                goto done;
    805943        }
     
    807945        init_lsa_String(&lsa_user_name, r->in.user_name);
    808946
    809         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     947        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    810948                                         &domain_handle,
    811949                                         1,
    812950                                         &lsa_user_name,
    813951                                         &rids,
    814                                          &types);
    815         if (!NT_STATUS_IS_OK(status)) {
     952                                         &types,
     953                                         &result);
     954        if (!NT_STATUS_IS_OK(status)) {
     955                werr = ntstatus_to_werror(status);
     956                goto done;
     957        }
     958        if (!NT_STATUS_IS_OK(result)) {
    816959                werr = WERR_USER_NOT_FOUND;
    817960                goto done;
     
    823966        }
    824967
    825         status = rpccli_samr_AddGroupMember(pipe_cli, talloc_tos(),
     968        status = dcerpc_samr_AddGroupMember(b, talloc_tos(),
    826969                                            &group_handle,
    827970                                            rids.ids[0],
    828                                             7); /* why ? */
    829         if (!NT_STATUS_IS_OK(status)) {
    830                 werr = ntstatus_to_werror(status);
     971                                            7, /* why ? */
     972                                            &result);
     973        if (!NT_STATUS_IS_OK(status)) {
     974                werr = ntstatus_to_werror(status);
     975                goto done;
     976        }
     977        if (!NT_STATUS_IS_OK(result)) {
     978                werr = ntstatus_to_werror(result);
    831979                goto done;
    832980        }
     
    836984 done:
    837985        if (is_valid_policy_hnd(&group_handle)) {
    838                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     986                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    839987        }
    840988
     
    8631011{
    8641012        struct rpc_pipe_client *pipe_cli = NULL;
    865         NTSTATUS status;
     1013        NTSTATUS status, result;
    8661014        WERROR werr;
    8671015        struct policy_handle connect_handle, domain_handle, group_handle;
    8681016        struct lsa_String lsa_group_name, lsa_user_name;
    8691017        struct dom_sid2 *domain_sid = NULL;
     1018        struct dcerpc_binding_handle *b = NULL;
    8701019
    8711020        struct samr_Ids rids;
     
    8861035                goto done;
    8871036        }
     1037
     1038        b = pipe_cli->binding_handle;
    8881039
    8891040        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    9001051        init_lsa_String(&lsa_group_name, r->in.group_name);
    9011052
    902         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1053        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    9031054                                         &domain_handle,
    9041055                                         1,
    9051056                                         &lsa_group_name,
    9061057                                         &rids,
    907                                          &types);
    908         if (!NT_STATUS_IS_OK(status)) {
     1058                                         &types,
     1059                                         &result);
     1060        if (!NT_STATUS_IS_OK(status)) {
     1061                werr = ntstatus_to_werror(status);
     1062                goto done;
     1063        }
     1064        if (!NT_STATUS_IS_OK(result)) {
    9091065                werr = WERR_GROUPNOTFOUND;
    9101066                goto done;
     
    9161072        }
    9171073
    918         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     1074        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    9191075                                       &domain_handle,
    9201076                                       SAMR_GROUP_ACCESS_REMOVE_MEMBER,
    9211077                                       rids.ids[0],
    922                                        &group_handle);
    923         if (!NT_STATUS_IS_OK(status)) {
    924                 werr = ntstatus_to_werror(status);
     1078                                       &group_handle,
     1079                                       &result);
     1080        if (!NT_STATUS_IS_OK(status)) {
     1081                werr = ntstatus_to_werror(status);
     1082                goto done;
     1083        }
     1084        if (!NT_STATUS_IS_OK(result)) {
     1085                werr = ntstatus_to_werror(result);
    9251086                goto done;
    9261087        }
     
    9281089        init_lsa_String(&lsa_user_name, r->in.user_name);
    9291090
    930         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1091        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    9311092                                         &domain_handle,
    9321093                                         1,
    9331094                                         &lsa_user_name,
    9341095                                         &rids,
    935                                          &types);
    936         if (!NT_STATUS_IS_OK(status)) {
     1096                                         &types,
     1097                                         &result);
     1098        if (!NT_STATUS_IS_OK(status)) {
     1099                werr = ntstatus_to_werror(status);
     1100                goto done;
     1101        }
     1102
     1103        if (!NT_STATUS_IS_OK(result)) {
    9371104                werr = WERR_USER_NOT_FOUND;
    9381105                goto done;
     
    9441111        }
    9451112
    946         status = rpccli_samr_DeleteGroupMember(pipe_cli, talloc_tos(),
     1113        status = dcerpc_samr_DeleteGroupMember(b, talloc_tos(),
    9471114                                               &group_handle,
    948                                                rids.ids[0]);
    949         if (!NT_STATUS_IS_OK(status)) {
    950                 werr = ntstatus_to_werror(status);
     1115                                               rids.ids[0],
     1116                                               &result);
     1117        if (!NT_STATUS_IS_OK(status)) {
     1118                werr = ntstatus_to_werror(status);
     1119                goto done;
     1120        }
     1121        if (!NT_STATUS_IS_OK(result)) {
     1122                werr = ntstatus_to_werror(result);
    9511123                goto done;
    9521124        }
     
    9561128 done:
    9571129        if (is_valid_policy_hnd(&group_handle)) {
    958                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     1130                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    9591131        }
    9601132
     
    10861258                g3[i].grpi3_comment = talloc_strdup(mem_ctx,
    10871259                        groups->entries[i].description.string);
    1088                 g3[i].grpi3_group_sid = (struct domsid *)sid_dup_talloc(mem_ctx, &sid);
     1260                g3[i].grpi3_group_sid = (struct domsid *)dom_sid_dup(mem_ctx, &sid);
    10891261                g3[i].grpi3_attributes = groups->entries[i].acct_flags;
    10901262                W_ERROR_HAVE_NO_MEMORY(g3[i].grpi3_name);
     
    11381310        union samr_DispInfo info;
    11391311        union samr_DomainInfo *domain_info = NULL;
     1312        struct dcerpc_binding_handle *b = NULL;
    11401313
    11411314        uint32_t total_size = 0;
    11421315        uint32_t returned_size = 0;
    11431316
     1317        NTSTATUS result = NT_STATUS_OK;
    11441318        NTSTATUS status = NT_STATUS_OK;
    11451319        WERROR werr, tmp_werr;
     
    11641338                goto done;
    11651339        }
     1340
     1341        b = pipe_cli->binding_handle;
    11661342
    11671343        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    11781354        }
    11791355
    1180         status = rpccli_samr_QueryDomainInfo(pipe_cli, talloc_tos(),
     1356        status = dcerpc_samr_QueryDomainInfo(b, talloc_tos(),
    11811357                                             &domain_handle,
    11821358                                             2,
    1183                                              &domain_info);
    1184         if (!NT_STATUS_IS_OK(status)) {
    1185                 werr = ntstatus_to_werror(status);
     1359                                             &domain_info,
     1360                                             &result);
     1361        if (!NT_STATUS_IS_OK(status)) {
     1362                werr = ntstatus_to_werror(status);
     1363                goto done;
     1364        }
     1365        if (!NT_STATUS_IS_OK(result)) {
     1366                werr = ntstatus_to_werror(result);
    11861367                goto done;
    11871368        }
     
    11911372        }
    11921373
    1193         status = rpccli_samr_QueryDisplayInfo2(pipe_cli,
     1374        status = dcerpc_samr_QueryDisplayInfo2(b,
    11941375                                               ctx,
    11951376                                               &domain_handle,
     
    12011382                                               &total_size,
    12021383                                               &returned_size,
    1203                                                &info);
    1204         werr = ntstatus_to_werror(status);
    1205         if (NT_STATUS_IS_ERR(status)) {
     1384                                               &info,
     1385                                               &result);
     1386        if (!NT_STATUS_IS_OK(status)) {
     1387                werr = ntstatus_to_werror(status);
     1388                goto done;
     1389        }
     1390
     1391        werr = ntstatus_to_werror(result);
     1392        if (NT_STATUS_IS_ERR(result)) {
    12061393                goto done;
    12071394        }
     
    12251412 done:
    12261413        /* if last query */
    1227         if (NT_STATUS_IS_OK(status) ||
    1228             NT_STATUS_IS_ERR(status)) {
     1414        if (NT_STATUS_IS_OK(result) ||
     1415            NT_STATUS_IS_ERR(result)) {
    12291416
    12301417                if (ctx->disable_policy_handle_cache) {
     
    12591446        struct dom_sid2 *domain_sid = NULL;
    12601447        struct samr_Ids group_rids, name_types;
    1261         struct samr_RidTypeArray *rid_array = NULL;
     1448        struct samr_RidAttrArray *rid_array = NULL;
    12621449        struct lsa_Strings names;
    12631450        struct samr_Ids member_types;
     1451        struct dcerpc_binding_handle *b = NULL;
    12641452
    12651453        int i;
     
    12671455
    12681456        NTSTATUS status = NT_STATUS_OK;
     1457        NTSTATUS result = NT_STATUS_OK;
    12691458        WERROR werr;
    12701459
     
    12951484                goto done;
    12961485        }
     1486
     1487        b = pipe_cli->binding_handle;
    12971488
    12981489        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    13091500        init_lsa_String(&lsa_account_name, r->in.group_name);
    13101501
    1311         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1502        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    13121503                                         &domain_handle,
    13131504                                         1,
    13141505                                         &lsa_account_name,
    13151506                                         &group_rids,
    1316                                          &name_types);
    1317         if (!NT_STATUS_IS_OK(status)) {
    1318                 werr = ntstatus_to_werror(status);
    1319                 goto done;
    1320         }
    1321 
    1322         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     1507                                         &name_types,
     1508                                         &result);
     1509        if (!NT_STATUS_IS_OK(status)) {
     1510                werr = ntstatus_to_werror(status);
     1511                goto done;
     1512        }
     1513        if (!NT_STATUS_IS_OK(result)) {
     1514                werr = ntstatus_to_werror(result);
     1515                goto done;
     1516        }
     1517
     1518        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    13231519                                       &domain_handle,
    13241520                                       SAMR_GROUP_ACCESS_GET_MEMBERS,
    13251521                                       group_rids.ids[0],
    1326                                        &group_handle);
    1327         if (!NT_STATUS_IS_OK(status)) {
    1328                 werr = ntstatus_to_werror(status);
    1329                 goto done;
    1330         }
    1331 
    1332         status = rpccli_samr_QueryGroupMember(pipe_cli, talloc_tos(),
     1522                                       &group_handle,
     1523                                       &result);
     1524        if (!NT_STATUS_IS_OK(status)) {
     1525                werr = ntstatus_to_werror(status);
     1526                goto done;
     1527        }
     1528        if (!NT_STATUS_IS_OK(result)) {
     1529                werr = ntstatus_to_werror(result);
     1530                goto done;
     1531        }
     1532
     1533        status = dcerpc_samr_QueryGroupMember(b, talloc_tos(),
    13331534                                              &group_handle,
    1334                                               &rid_array);
    1335         if (!NT_STATUS_IS_OK(status)) {
    1336                 werr = ntstatus_to_werror(status);
    1337                 goto done;
    1338         }
    1339 
    1340         status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),
     1535                                              &rid_array,
     1536                                              &result);
     1537        if (!NT_STATUS_IS_OK(status)) {
     1538                werr = ntstatus_to_werror(status);
     1539                goto done;
     1540        }
     1541        if (!NT_STATUS_IS_OK(result)) {
     1542                werr = ntstatus_to_werror(result);
     1543                goto done;
     1544        }
     1545
     1546        status = dcerpc_samr_LookupRids(b, talloc_tos(),
    13411547                                        &domain_handle,
    13421548                                        rid_array->count,
    13431549                                        rid_array->rids,
    13441550                                        &names,
    1345                                         &member_types);
    1346         if (!NT_STATUS_IS_OK(status)) {
    1347                 werr = ntstatus_to_werror(status);
     1551                                        &member_types,
     1552                                        &result);
     1553        if (!NT_STATUS_IS_OK(status)) {
     1554                werr = ntstatus_to_werror(status);
     1555                goto done;
     1556        }
     1557        if (!NT_STATUS_IS_OK(result)) {
     1558                werr = ntstatus_to_werror(result);
    13481559                goto done;
    13491560        }
     
    13741585 done:
    13751586        if (is_valid_policy_hnd(&group_handle)) {
    1376                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     1587                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    13771588        }
    13781589
     
    14071618        struct samr_Ids user_rids, name_types;
    14081619        struct samr_Ids group_rids, group_types;
    1409         struct samr_RidTypeArray *rid_array = NULL;
     1620        struct samr_RidAttrArray *rid_array = NULL;
    14101621        struct lsa_String *lsa_names = NULL;
     1622        struct dcerpc_binding_handle *b = NULL;
    14111623
    14121624        uint32_t *add_rids = NULL;
     
    14161628
    14171629        uint32_t *member_rids = NULL;
    1418         size_t num_member_rids = 0;
    14191630
    14201631        struct GROUP_USERS_INFO_0 *i0 = NULL;
     
    14241635
    14251636        NTSTATUS status = NT_STATUS_OK;
     1637        NTSTATUS result = NT_STATUS_OK;
    14261638        WERROR werr;
    14271639
     
    14471659                goto done;
    14481660        }
     1661
     1662        b = pipe_cli->binding_handle;
    14491663
    14501664        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    14611675        init_lsa_String(&lsa_account_name, r->in.group_name);
    14621676
    1463         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1677        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    14641678                                         &domain_handle,
    14651679                                         1,
    14661680                                         &lsa_account_name,
    14671681                                         &group_rids,
    1468                                          &group_types);
    1469         if (!NT_STATUS_IS_OK(status)) {
    1470                 werr = ntstatus_to_werror(status);
    1471                 goto done;
    1472         }
    1473 
    1474         status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     1682                                         &group_types,
     1683                                         &result);
     1684        if (!NT_STATUS_IS_OK(status)) {
     1685                werr = ntstatus_to_werror(status);
     1686                goto done;
     1687        }
     1688        if (!NT_STATUS_IS_OK(result)) {
     1689                werr = ntstatus_to_werror(result);
     1690                goto done;
     1691        }
     1692
     1693        status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    14751694                                       &domain_handle,
    14761695                                       SAMR_GROUP_ACCESS_GET_MEMBERS |
     
    14791698                                       SAMR_GROUP_ACCESS_LOOKUP_INFO,
    14801699                                       group_rids.ids[0],
    1481                                        &group_handle);
    1482         if (!NT_STATUS_IS_OK(status)) {
    1483                 werr = ntstatus_to_werror(status);
    1484                 goto done;
    1485         }
    1486 
    1487         status = rpccli_samr_QueryGroupInfo(pipe_cli, talloc_tos(),
     1700                                       &group_handle,
     1701                                       &result);
     1702        if (!NT_STATUS_IS_OK(status)) {
     1703                werr = ntstatus_to_werror(status);
     1704                goto done;
     1705        }
     1706        if (!NT_STATUS_IS_OK(result)) {
     1707                werr = ntstatus_to_werror(result);
     1708                goto done;
     1709        }
     1710
     1711        status = dcerpc_samr_QueryGroupInfo(b, talloc_tos(),
    14881712                                            &group_handle,
    14891713                                            GROUPINFOATTRIBUTES,
    1490                                             &group_info);
    1491         if (!NT_STATUS_IS_OK(status)) {
    1492                 werr = ntstatus_to_werror(status);
     1714                                            &group_info,
     1715                                            &result);
     1716        if (!NT_STATUS_IS_OK(status)) {
     1717                werr = ntstatus_to_werror(status);
     1718                goto done;
     1719        }
     1720        if (!NT_STATUS_IS_OK(result)) {
     1721                werr = ntstatus_to_werror(result);
    14931722                goto done;
    14941723        }
     
    15231752        }
    15241753
    1525         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1754        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    15261755                                         &domain_handle,
    15271756                                         r->in.num_entries,
    15281757                                         lsa_names,
    15291758                                         &user_rids,
    1530                                          &name_types);
    1531         if (!NT_STATUS_IS_OK(status)) {
    1532                 werr = ntstatus_to_werror(status);
     1759                                         &name_types,
     1760                                         &result);
     1761        if (!NT_STATUS_IS_OK(status)) {
     1762                werr = ntstatus_to_werror(status);
     1763                goto done;
     1764        }
     1765        if (!NT_STATUS_IS_OK(result)) {
     1766                werr = ntstatus_to_werror(result);
    15331767                goto done;
    15341768        }
    15351769
    15361770        member_rids = user_rids.ids;
    1537         num_member_rids = user_rids.count;
    1538 
    1539         status = rpccli_samr_QueryGroupMember(pipe_cli, talloc_tos(),
     1771
     1772        status = dcerpc_samr_QueryGroupMember(b, talloc_tos(),
    15401773                                              &group_handle,
    1541                                               &rid_array);
    1542         if (!NT_STATUS_IS_OK(status)) {
    1543                 werr = ntstatus_to_werror(status);
     1774                                              &rid_array,
     1775                                              &result);
     1776        if (!NT_STATUS_IS_OK(status)) {
     1777                werr = ntstatus_to_werror(status);
     1778                goto done;
     1779        }
     1780        if (!NT_STATUS_IS_OK(result)) {
     1781                werr = ntstatus_to_werror(result);
    15441782                goto done;
    15451783        }
     
    15881826
    15891827        for (i=0; i < num_add_rids; i++) {
    1590                 status = rpccli_samr_AddGroupMember(pipe_cli, talloc_tos(),
     1828                status = dcerpc_samr_AddGroupMember(b, talloc_tos(),
    15911829                                                    &group_handle,
    15921830                                                    add_rids[i],
    1593                                                     7 /* ? */);
     1831                                                    7 /* ? */,
     1832                                                    &result);
    15941833                if (!NT_STATUS_IS_OK(status)) {
    15951834                        werr = ntstatus_to_werror(status);
    15961835                        goto done;
    15971836                }
     1837                if (!NT_STATUS_IS_OK(result)) {
     1838                        werr = ntstatus_to_werror(result);
     1839                        goto done;
     1840                }
    15981841        }
    15991842
     
    16011844
    16021845        for (i=0; i < num_del_rids; i++) {
    1603                 status = rpccli_samr_DeleteGroupMember(pipe_cli, talloc_tos(),
     1846                status = dcerpc_samr_DeleteGroupMember(b, talloc_tos(),
    16041847                                                       &group_handle,
    1605                                                        del_rids[i]);
     1848                                                       del_rids[i],
     1849                                                       &result);
    16061850                if (!NT_STATUS_IS_OK(status)) {
    16071851                        werr = ntstatus_to_werror(status);
    16081852                        goto done;
    16091853                }
     1854                if (!NT_STATUS_IS_OK(result)) {
     1855                        werr = ntstatus_to_werror(result);
     1856                        goto done;
     1857                }
    16101858        }
    16111859
     
    16141862 done:
    16151863        if (is_valid_policy_hnd(&group_handle)) {
    1616                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     1864                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    16171865        }
    16181866
  • trunk/server/source3/lib/netapi/joindomain.c

    r596 r745  
    1919
    2020#include "includes.h"
    21 
     21#include "ads.h"
    2222#include "librpc/gen_ndr/libnetapi.h"
     23#include "libcli/auth/libcli_auth.h"
    2324#include "lib/netapi/netapi.h"
    2425#include "lib/netapi/netapi_private.h"
    2526#include "lib/netapi/libnetapi.h"
    26 #include "libnet/libnet.h"
    27 #include "libcli/auth/libcli_auth.h"
    28 #include "../librpc/gen_ndr/cli_wkssvc.h"
     27#include "librpc/gen_ndr/libnet_join.h"
     28#include "libnet/libnet_join.h"
     29#include "../librpc/gen_ndr/ndr_wkssvc_c.h"
     30#include "rpc_client/cli_pipe.h"
     31#include "secrets.h"
    2932
    3033/****************************************************************
     
    3538{
    3639        struct libnet_JoinCtx *j = NULL;
    37         WERROR werr;
     40        struct libnetapi_private_ctx *priv;
     41        WERROR werr;
     42
     43        priv = talloc_get_type_abort(mem_ctx->private_data,
     44                struct libnetapi_private_ctx);
    3845
    3946        if (!r->in.domain) {
     
    5461                                 DS_WRITABLE_REQUIRED |
    5562                                 DS_RETURN_DNS_NAME;
    56                 status = dsgetdcname(mem_ctx, NULL, r->in.domain,
     63                status = dsgetdcname(mem_ctx, priv->msg_ctx, r->in.domain,
    5764                                     NULL, NULL, flags, &info);
    5865                if (!NT_STATUS_IS_OK(status)) {
     
    106113        WERROR werr;
    107114        unsigned int old_timeout = 0;
     115        struct dcerpc_binding_handle *b;
     116        DATA_BLOB session_key;
    108117
    109118        werr = libnetapi_open_pipe(ctx, r->in.server,
     
    114123        }
    115124
    116         if (r->in.password) {
     125        b = pipe_cli->binding_handle;
     126
     127        if (r->in.password) {
     128
     129                status = cli_get_session_key(talloc_tos(), pipe_cli, &session_key);
     130                if (!NT_STATUS_IS_OK(status)) {
     131                        werr = ntstatus_to_werror(status);
     132                        goto done;
     133                }
     134
    117135                encode_wkssvc_join_password_buffer(ctx,
    118136                                                   r->in.password,
    119                                                    &pipe_cli->auth->user_session_key,
     137                                                   &session_key,
    120138                                                   &encrypted_password);
    121139        }
     
    123141        old_timeout = rpccli_set_timeout(pipe_cli, 600000);
    124142
    125         status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, talloc_tos(),
     143        status = dcerpc_wkssvc_NetrJoinDomain2(b, talloc_tos(),
    126144                                               r->in.server,
    127145                                               r->in.domain,
     
    153171        const char *domain = NULL;
    154172        WERROR werr;
     173        struct libnetapi_private_ctx *priv;
     174
     175        priv = talloc_get_type_abort(mem_ctx->private_data,
     176                struct libnetapi_private_ctx);
    155177
    156178        if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) {
     
    177199                                 DS_WRITABLE_REQUIRED |
    178200                                 DS_RETURN_DNS_NAME;
    179                 status = dsgetdcname(mem_ctx, NULL, domain,
     201                status = dsgetdcname(mem_ctx, priv->msg_ctx, domain,
    180202                                     NULL, NULL, flags, &info);
    181203                if (!NT_STATUS_IS_OK(status)) {
     
    232254        WERROR werr;
    233255        unsigned int old_timeout = 0;
     256        struct dcerpc_binding_handle *b;
     257        DATA_BLOB session_key;
    234258
    235259        werr = libnetapi_open_pipe(ctx, r->in.server_name,
     
    240264        }
    241265
    242         if (r->in.password) {
     266        b = pipe_cli->binding_handle;
     267
     268        if (r->in.password) {
     269
     270                status = cli_get_session_key(talloc_tos(), pipe_cli, &session_key);
     271                if (!NT_STATUS_IS_OK(status)) {
     272                        werr = ntstatus_to_werror(status);
     273                        goto done;
     274                }
     275
    243276                encode_wkssvc_join_password_buffer(ctx,
    244277                                                   r->in.password,
    245                                                    &pipe_cli->auth->user_session_key,
     278                                                   &session_key,
    246279                                                   &encrypted_password);
    247280        }
     
    249282        old_timeout = rpccli_set_timeout(pipe_cli, 60000);
    250283
    251         status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, talloc_tos(),
     284        status = dcerpc_wkssvc_NetrUnjoinDomain2(b, talloc_tos(),
    252285                                                 r->in.server_name,
    253286                                                 r->in.account,
     
    278311        WERROR werr;
    279312        const char *buffer = NULL;
     313        struct dcerpc_binding_handle *b;
    280314
    281315        werr = libnetapi_open_pipe(ctx, r->in.server_name,
     
    286320        }
    287321
    288         status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, talloc_tos(),
     322        b = pipe_cli->binding_handle;
     323
     324        status = dcerpc_wkssvc_NetrGetJoinInformation(b, talloc_tos(),
    289325                                                      r->in.server_name,
    290326                                                      &buffer,
     
    293329        if (!NT_STATUS_IS_OK(status)) {
    294330                werr = ntstatus_to_werror(status);
     331                goto done;
     332        }
     333
     334        if (!W_ERROR_IS_OK(werr)) {
    295335                goto done;
    296336        }
     
    339379                           struct NetGetJoinableOUs *r)
    340380{
    341 #ifdef WITH_ADS
     381#ifdef HAVE_ADS
    342382        NTSTATUS status;
    343383        ADS_STATUS ads_status;
     
    347387        uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
    348388                         DS_RETURN_DNS_NAME;
    349 
    350         status = dsgetdcname(ctx, NULL, r->in.domain,
     389        struct libnetapi_private_ctx *priv;
     390
     391        priv = talloc_get_type_abort(ctx->private_data,
     392                struct libnetapi_private_ctx);
     393
     394        status = dsgetdcname(ctx, priv->msg_ctx, r->in.domain,
    351395                             NULL, NULL, flags, &info);
    352396        if (!NT_STATUS_IS_OK(status)) {
     
    408452        NTSTATUS status;
    409453        WERROR werr;
     454        struct dcerpc_binding_handle *b;
     455        DATA_BLOB session_key;
    410456
    411457        werr = libnetapi_open_pipe(ctx, r->in.server_name,
     
    416462        }
    417463
    418         if (r->in.password) {
     464        b = pipe_cli->binding_handle;
     465
     466        if (r->in.password) {
     467
     468                status = cli_get_session_key(talloc_tos(), pipe_cli, &session_key);
     469                if (!NT_STATUS_IS_OK(status)) {
     470                        werr = ntstatus_to_werror(status);
     471                        goto done;
     472                }
     473
    419474                encode_wkssvc_join_password_buffer(ctx,
    420475                                                   r->in.password,
    421                                                    &pipe_cli->auth->user_session_key,
     476                                                   &session_key,
    422477                                                   &encrypted_password);
    423478        }
    424479
    425         status = rpccli_wkssvc_NetrGetJoinableOus2(pipe_cli, talloc_tos(),
     480        status = dcerpc_wkssvc_NetrGetJoinableOus2(b, talloc_tos(),
    426481                                                   r->in.server_name,
    427482                                                   r->in.domain,
     
    450505        NTSTATUS status;
    451506        WERROR werr;
     507        struct dcerpc_binding_handle *b;
     508        DATA_BLOB session_key;
    452509
    453510        werr = libnetapi_open_pipe(ctx, r->in.server_name,
     
    458515        }
    459516
    460         if (r->in.password) {
     517        b = pipe_cli->binding_handle;
     518
     519        if (r->in.password) {
     520
     521                status = cli_get_session_key(talloc_tos(), pipe_cli, &session_key);
     522                if (!NT_STATUS_IS_OK(status)) {
     523                        werr = ntstatus_to_werror(status);
     524                        goto done;
     525                }
     526
    461527                encode_wkssvc_join_password_buffer(ctx,
    462528                                                   r->in.password,
    463                                                    &pipe_cli->auth->user_session_key,
     529                                                   &session_key,
    464530                                                   &encrypted_password);
    465531        }
    466532
    467         status = rpccli_wkssvc_NetrRenameMachineInDomain2(pipe_cli, talloc_tos(),
     533        status = dcerpc_wkssvc_NetrRenameMachineInDomain2(b, talloc_tos(),
    468534                                                          r->in.server_name,
    469535                                                          r->in.new_machine_name,
  • trunk/server/source3/lib/netapi/libnetapi.c

    r596 r745  
    7575
    7676        TALLOC_FREE(frame);
    77         return r.out.result;
     77        return (NET_API_STATUS)r.out.result;
    7878}
    7979
     
    124124
    125125        TALLOC_FREE(frame);
    126         return r.out.result;
     126        return (NET_API_STATUS)r.out.result;
    127127}
    128128
     
    171171
    172172        TALLOC_FREE(frame);
    173         return r.out.result;
     173        return (NET_API_STATUS)r.out.result;
    174174}
    175175
     
    224224
    225225        TALLOC_FREE(frame);
    226         return r.out.result;
     226        return (NET_API_STATUS)r.out.result;
    227227}
    228228
     
    275275
    276276        TALLOC_FREE(frame);
    277         return r.out.result;
     277        return (NET_API_STATUS)r.out.result;
    278278}
    279279
     
    322322
    323323        TALLOC_FREE(frame);
    324         return r.out.result;
     324        return (NET_API_STATUS)r.out.result;
    325325}
    326326
     
    371371
    372372        TALLOC_FREE(frame);
    373         return r.out.result;
     373        return (NET_API_STATUS)r.out.result;
    374374}
    375375
     
    418418
    419419        TALLOC_FREE(frame);
    420         return r.out.result;
     420        return (NET_API_STATUS)r.out.result;
    421421}
    422422
     
    465465
    466466        TALLOC_FREE(frame);
    467         return r.out.result;
     467        return (NET_API_STATUS)r.out.result;
    468468}
    469469
     
    518518
    519519        TALLOC_FREE(frame);
    520         return r.out.result;
     520        return (NET_API_STATUS)r.out.result;
    521521}
    522522
     
    567567
    568568        TALLOC_FREE(frame);
    569         return r.out.result;
     569        return (NET_API_STATUS)r.out.result;
    570570}
    571571
     
    612612
    613613        TALLOC_FREE(frame);
    614         return r.out.result;
     614        return (NET_API_STATUS)r.out.result;
    615615}
    616616
     
    670670
    671671        TALLOC_FREE(frame);
    672         return r.out.result;
     672        return (NET_API_STATUS)r.out.result;
    673673}
    674674
     
    719719
    720720        TALLOC_FREE(frame);
    721         return r.out.result;
     721        return (NET_API_STATUS)r.out.result;
    722722}
    723723
     
    768768
    769769        TALLOC_FREE(frame);
    770         return r.out.result;
     770        return (NET_API_STATUS)r.out.result;
    771771}
    772772
     
    819819
    820820        TALLOC_FREE(frame);
    821         return r.out.result;
     821        return (NET_API_STATUS)r.out.result;
    822822}
    823823
     
    874874
    875875        TALLOC_FREE(frame);
    876         return r.out.result;
     876        return (NET_API_STATUS)r.out.result;
    877877}
    878878
     
    925925
    926926        TALLOC_FREE(frame);
    927         return r.out.result;
     927        return (NET_API_STATUS)r.out.result;
    928928}
    929929
     
    982982
    983983        TALLOC_FREE(frame);
    984         return r.out.result;
     984        return (NET_API_STATUS)r.out.result;
    985985}
    986986
     
    10291029
    10301030        TALLOC_FREE(frame);
    1031         return r.out.result;
     1031        return (NET_API_STATUS)r.out.result;
    10321032}
    10331033
     
    10781078
    10791079        TALLOC_FREE(frame);
    1080         return r.out.result;
     1080        return (NET_API_STATUS)r.out.result;
    10811081}
    10821082
     
    11331133
    11341134        TALLOC_FREE(frame);
    1135         return r.out.result;
     1135        return (NET_API_STATUS)r.out.result;
    11361136}
    11371137
     
    11821182
    11831183        TALLOC_FREE(frame);
    1184         return r.out.result;
     1184        return (NET_API_STATUS)r.out.result;
    11851185}
    11861186
     
    12271227
    12281228        TALLOC_FREE(frame);
    1229         return r.out.result;
     1229        return (NET_API_STATUS)r.out.result;
    12301230}
    12311231
     
    12831283
    12841284        TALLOC_FREE(frame);
    1285         return r.out.result;
     1285        return (NET_API_STATUS)r.out.result;
    12861286}
    12871287
     
    13341334
    13351335        TALLOC_FREE(frame);
    1336         return r.out.result;
     1336        return (NET_API_STATUS)r.out.result;
    13371337}
    13381338
     
    13831383
    13841384        TALLOC_FREE(frame);
    1385         return r.out.result;
     1385        return (NET_API_STATUS)r.out.result;
    13861386}
    13871387
     
    14301430
    14311431        TALLOC_FREE(frame);
    1432         return r.out.result;
     1432        return (NET_API_STATUS)r.out.result;
    14331433}
    14341434
     
    14771477
    14781478        TALLOC_FREE(frame);
    1479         return r.out.result;
     1479        return (NET_API_STATUS)r.out.result;
    14801480}
    14811481
     
    15351535
    15361536        TALLOC_FREE(frame);
    1537         return r.out.result;
     1537        return (NET_API_STATUS)r.out.result;
    15381538}
    15391539
     
    15861586
    15871587        TALLOC_FREE(frame);
    1588         return r.out.result;
     1588        return (NET_API_STATUS)r.out.result;
    15891589}
    15901590
     
    16351635
    16361636        TALLOC_FREE(frame);
    1637         return r.out.result;
     1637        return (NET_API_STATUS)r.out.result;
    16381638}
    16391639
     
    16801680
    16811681        TALLOC_FREE(frame);
    1682         return r.out.result;
     1682        return (NET_API_STATUS)r.out.result;
    16831683}
    16841684
     
    17291729
    17301730        TALLOC_FREE(frame);
    1731         return r.out.result;
     1731        return (NET_API_STATUS)r.out.result;
    17321732}
    17331733
     
    17801780
    17811781        TALLOC_FREE(frame);
    1782         return r.out.result;
     1782        return (NET_API_STATUS)r.out.result;
    17831783}
    17841784
     
    18361836
    18371837        TALLOC_FREE(frame);
    1838         return r.out.result;
     1838        return (NET_API_STATUS)r.out.result;
    18391839}
    18401840
     
    18871887
    18881888        TALLOC_FREE(frame);
    1889         return r.out.result;
     1889        return (NET_API_STATUS)r.out.result;
    18901890}
    18911891
     
    19381938
    19391939        TALLOC_FREE(frame);
    1940         return r.out.result;
     1940        return (NET_API_STATUS)r.out.result;
    19411941}
    19421942
     
    19961996
    19971997        TALLOC_FREE(frame);
    1998         return r.out.result;
     1998        return (NET_API_STATUS)r.out.result;
    19991999}
    20002000
     
    20472047
    20482048        TALLOC_FREE(frame);
    2049         return r.out.result;
     2049        return (NET_API_STATUS)r.out.result;
    20502050}
    20512051
     
    20922092
    20932093        TALLOC_FREE(frame);
    2094         return r.out.result;
     2094        return (NET_API_STATUS)r.out.result;
    20952095}
    20962096
     
    21412141
    21422142        TALLOC_FREE(frame);
    2143         return r.out.result;
     2143        return (NET_API_STATUS)r.out.result;
    21442144}
    21452145
     
    21882188
    21892189        TALLOC_FREE(frame);
    2190         return r.out.result;
     2190        return (NET_API_STATUS)r.out.result;
    21912191}
    21922192
     
    22442244
    22452245        TALLOC_FREE(frame);
    2246         return r.out.result;
     2246        return (NET_API_STATUS)r.out.result;
    22472247}
    22482248
     
    22932293
    22942294        TALLOC_FREE(frame);
    2295         return r.out.result;
     2295        return (NET_API_STATUS)r.out.result;
    22962296}
    22972297
     
    23442344
    23452345        TALLOC_FREE(frame);
    2346         return r.out.result;
     2346        return (NET_API_STATUS)r.out.result;
    23472347}
    23482348
     
    23892389
    23902390        TALLOC_FREE(frame);
    2391         return r.out.result;
     2391        return (NET_API_STATUS)r.out.result;
    23922392}
    23932393
     
    24382438
    24392439        TALLOC_FREE(frame);
    2440         return r.out.result;
     2440        return (NET_API_STATUS)r.out.result;
    24412441}
    24422442
     
    24982498
    24992499        TALLOC_FREE(frame);
    2500         return r.out.result;
     2500        return (NET_API_STATUS)r.out.result;
    25012501}
    25022502
     
    25492549
    25502550        TALLOC_FREE(frame);
    2551         return r.out.result;
     2551        return (NET_API_STATUS)r.out.result;
    25522552}
    25532553
     
    25922592
    25932593        TALLOC_FREE(frame);
    2594         return r.out.result;
     2594        return (NET_API_STATUS)r.out.result;
    25952595}
    25962596
     
    26412641
    26422642        TALLOC_FREE(frame);
    2643         return r.out.result;
     2643        return (NET_API_STATUS)r.out.result;
    26442644}
    26452645
     
    26922692
    26932693        TALLOC_FREE(frame);
    2694         return r.out.result;
    2695 }
    2696 
     2694        return (NET_API_STATUS)r.out.result;
     2695}
     2696
  • trunk/server/source3/lib/netapi/libnetapi.h

    r414 r745  
     1/*
     2 *  Unix SMB/CIFS implementation.
     3 *  NetApi Support
     4 *  Copyright (C) Guenther Deschner 2007-2008
     5 *
     6 *  This program is free software; you can redistribute it and/or modify
     7 *  it under the terms of the GNU General Public License as published by
     8 *  the Free Software Foundation; either version 3 of the License, or
     9 *  (at your option) any later version.
     10 *
     11 *  This program is distributed in the hope that it will be useful,
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 *  GNU General Public License for more details.
     15 *
     16 *  You should have received a copy of the GNU General Public License
     17 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
     18 */
     19
    120#ifndef __LIBNETAPI_LIBNETAPI__
    221#define __LIBNETAPI_LIBNETAPI__
  • trunk/server/source3/lib/netapi/localgroup.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_samr.h"
    27 #include "../librpc/gen_ndr/cli_lsa.h"
     26#include "rpc_client/rpc_client.h"
     27#include "../librpc/gen_ndr/ndr_samr_c.h"
     28#include "../librpc/gen_ndr/ndr_lsa_c.h"
     29#include "rpc_client/cli_lsarpc.h"
     30#include "rpc_client/init_lsa.h"
     31#include "../libcli/security/security.h"
    2832
    2933static NTSTATUS libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx,
     
    3438                                                     struct policy_handle *alias_handle)
    3539{
    36         NTSTATUS status;
     40        NTSTATUS status, result;
    3741
    3842        struct lsa_String lsa_account_name;
    3943        struct samr_Ids user_rids, name_types;
     44        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    4045
    4146        init_lsa_String(&lsa_account_name, group_name);
    4247
    43         status = rpccli_samr_LookupNames(pipe_cli, mem_ctx,
     48        status = dcerpc_samr_LookupNames(b, mem_ctx,
    4449                                         domain_handle,
    4550                                         1,
    4651                                         &lsa_account_name,
    4752                                         &user_rids,
    48                                          &name_types);
     53                                         &name_types,
     54                                         &result);
    4955        if (!NT_STATUS_IS_OK(status)) {
    5056                return status;
     57        }
     58        if (!NT_STATUS_IS_OK(result)) {
     59                return result;
    5160        }
    5261
     
    5968        }
    6069
    61         return rpccli_samr_OpenAlias(pipe_cli, mem_ctx,
    62                                      domain_handle,
    63                                      access_rights,
    64                                      user_rids.ids[0],
    65                                      alias_handle);
     70        status = dcerpc_samr_OpenAlias(b, mem_ctx,
     71                                       domain_handle,
     72                                       access_rights,
     73                                       user_rids.ids[0],
     74                                       alias_handle,
     75                                       &result);
     76        if (!NT_STATUS_IS_OK(status)) {
     77                return status;
     78        }
     79
     80        return result;
    6681}
    6782
     
    7792                                                    union samr_AliasInfo **alias_info)
    7893{
    79         NTSTATUS status;
     94        NTSTATUS status, result;
    8095        struct policy_handle alias_handle;
    8196        union samr_AliasInfo *_alias_info = NULL;
     97        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    8298
    8399        ZERO_STRUCT(alias_handle);
    84100
    85         status = rpccli_samr_OpenAlias(pipe_cli, mem_ctx,
     101        status = dcerpc_samr_OpenAlias(b, mem_ctx,
    86102                                       handle,
    87103                                       access_rights,
    88104                                       rid,
    89                                        &alias_handle);
    90         if (!NT_STATUS_IS_OK(status)) {
    91                 goto done;
    92         }
    93 
    94         status = rpccli_samr_QueryAliasInfo(pipe_cli, mem_ctx,
     105                                       &alias_handle,
     106                                       &result);
     107        if (!NT_STATUS_IS_OK(status)) {
     108                goto done;
     109        }
     110        if (!NT_STATUS_IS_OK(result)) {
     111                status = result;
     112                goto done;
     113        }
     114
     115        status = dcerpc_samr_QueryAliasInfo(b, mem_ctx,
    95116                                            &alias_handle,
    96117                                            level,
    97                                             &_alias_info);
    98         if (!NT_STATUS_IS_OK(status)) {
     118                                            &_alias_info,
     119                                            &result);
     120        if (!NT_STATUS_IS_OK(status)) {
     121                goto done;
     122        }
     123        if (!NT_STATUS_IS_OK(result)) {
     124                status = result;
    99125                goto done;
    100126        }
     
    104130 done:
    105131        if (is_valid_policy_hnd(&alias_handle)) {
    106                 rpccli_samr_Close(pipe_cli, mem_ctx, &alias_handle);
     132                dcerpc_samr_Close(b, mem_ctx, &alias_handle, &result);
    107133        }
    108134
     
    117143{
    118144        struct rpc_pipe_client *pipe_cli = NULL;
    119         NTSTATUS status;
     145        NTSTATUS status, result;
    120146        WERROR werr;
    121147        struct lsa_String lsa_account_name;
     
    123149        struct dom_sid2 *domain_sid = NULL;
    124150        uint32_t rid;
     151        struct dcerpc_binding_handle *b = NULL;
    125152
    126153        struct LOCALGROUP_INFO_0 *info0 = NULL;
     
    158185                goto done;
    159186        }
     187
     188        b = pipe_cli->binding_handle;
    160189
    161190        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
     
    197226        init_lsa_String(&lsa_account_name, alias_name);
    198227
    199         status = rpccli_samr_CreateDomAlias(pipe_cli, talloc_tos(),
     228        status = dcerpc_samr_CreateDomAlias(b, talloc_tos(),
    200229                                            &domain_handle,
    201230                                            &lsa_account_name,
     
    203232                                            SAMR_ALIAS_ACCESS_SET_INFO,
    204233                                            &alias_handle,
    205                                             &rid);
     234                                            &rid,
     235                                            &result);
    206236        if (!NT_STATUS_IS_OK(status)) {
    207237                werr = ntstatus_to_werror(status);
    208238                goto done;
    209239        }
     240        if (!NT_STATUS_IS_OK(result)) {
     241                werr = ntstatus_to_werror(result);
     242                goto done;
     243        }
     244
    210245
    211246        if (r->in.level == 1 && info1->lgrpi1_comment) {
     
    215250                init_lsa_String(&alias_info.description, info1->lgrpi1_comment);
    216251
    217                 status = rpccli_samr_SetAliasInfo(pipe_cli, talloc_tos(),
     252                status = dcerpc_samr_SetAliasInfo(b, talloc_tos(),
    218253                                                  &alias_handle,
    219254                                                  ALIASINFODESCRIPTION,
    220                                                   &alias_info);
     255                                                  &alias_info,
     256                                                  &result);
    221257                if (!NT_STATUS_IS_OK(status)) {
    222258                        werr = ntstatus_to_werror(status);
    223259                        goto done;
    224260                }
     261                if (!NT_STATUS_IS_OK(result)) {
     262                        werr = ntstatus_to_werror(result);
     263                        goto done;
     264                }
    225265        }
    226266
     
    229269 done:
    230270        if (is_valid_policy_hnd(&alias_handle)) {
    231                 rpccli_samr_Close(pipe_cli, talloc_tos(), &alias_handle);
     271                dcerpc_samr_Close(b, talloc_tos(), &alias_handle, &result);
    232272        }
    233273
     
    258298{
    259299        struct rpc_pipe_client *pipe_cli = NULL;
    260         NTSTATUS status;
     300        NTSTATUS status, result;
    261301        WERROR werr;
    262302        struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
    263303        struct dom_sid2 *domain_sid = NULL;
     304        struct dcerpc_binding_handle *b = NULL;
    264305
    265306        if (!r->in.group_name) {
     
    278319                goto done;
    279320        }
     321
     322        b = pipe_cli->binding_handle;
    280323
    281324        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
     
    332375
    333376 delete_alias:
    334         status = rpccli_samr_DeleteDomAlias(pipe_cli, talloc_tos(),
    335                                             &alias_handle);
     377        status = dcerpc_samr_DeleteDomAlias(b, talloc_tos(),
     378                                            &alias_handle,
     379                                            &result);
    336380        if (!NT_STATUS_IS_OK(status)) {
    337381                werr = ntstatus_to_werror(status);
     382                goto done;
     383        }
     384        if (!NT_STATUS_IS_OK(result)) {
     385                werr = ntstatus_to_werror(result);
    338386                goto done;
    339387        }
     
    345393 done:
    346394        if (is_valid_policy_hnd(&alias_handle)) {
    347                 rpccli_samr_Close(pipe_cli, talloc_tos(), &alias_handle);
     395                dcerpc_samr_Close(b, talloc_tos(), &alias_handle, &result);
    348396        }
    349397
     
    419467{
    420468        struct rpc_pipe_client *pipe_cli = NULL;
    421         NTSTATUS status;
     469        NTSTATUS status, result;
    422470        WERROR werr;
    423471        struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
     
    425473        union samr_AliasInfo *alias_info = NULL;
    426474        uint32_t entries_read = 0;
     475        struct dcerpc_binding_handle *b = NULL;
    427476
    428477        if (!r->in.group_name) {
     
    450499                goto done;
    451500        }
     501
     502        b = pipe_cli->binding_handle;
    452503
    453504        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
     
    503554
    504555 query_alias:
    505         status = rpccli_samr_QueryAliasInfo(pipe_cli, talloc_tos(),
     556        status = dcerpc_samr_QueryAliasInfo(b, talloc_tos(),
    506557                                            &alias_handle,
    507558                                            ALIASINFOALL,
    508                                             &alias_info);
     559                                            &alias_info,
     560                                            &result);
    509561        if (!NT_STATUS_IS_OK(status)) {
    510562                werr = ntstatus_to_werror(status);
     563                goto done;
     564        }
     565        if (!NT_STATUS_IS_OK(result)) {
     566                werr = ntstatus_to_werror(result);
    511567                goto done;
    512568        }
     
    520576 done:
    521577        if (is_valid_policy_hnd(&alias_handle)) {
    522                 rpccli_samr_Close(pipe_cli, talloc_tos(), &alias_handle);
     578                dcerpc_samr_Close(b, talloc_tos(), &alias_handle, &result);
    523579        }
    524580
     
    589645{
    590646        struct rpc_pipe_client *pipe_cli = NULL;
    591         NTSTATUS status;
     647        NTSTATUS status, result;
    592648        WERROR werr;
    593649        struct lsa_String lsa_account_name;
     
    596652        enum samr_AliasInfoEnum alias_level = 0;
    597653        union samr_AliasInfo *alias_info = NULL;
     654        struct dcerpc_binding_handle *b = NULL;
    598655
    599656        if (!r->in.group_name) {
     
    621678                goto done;
    622679        }
     680
     681        b = pipe_cli->binding_handle;
    623682
    624683        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
     
    681740        }
    682741
    683         status = rpccli_samr_SetAliasInfo(pipe_cli, talloc_tos(),
     742        status = dcerpc_samr_SetAliasInfo(b, talloc_tos(),
    684743                                          &alias_handle,
    685744                                          alias_level,
    686                                           alias_info);
     745                                          alias_info,
     746                                          &result);
    687747        if (!NT_STATUS_IS_OK(status)) {
    688748                werr = ntstatus_to_werror(status);
     749                goto done;
     750        }
     751        if (!NT_STATUS_IS_OK(result)) {
     752                werr = ntstatus_to_werror(result);
    689753                goto done;
    690754        }
     
    694758 done:
    695759        if (is_valid_policy_hnd(&alias_handle)) {
    696                 rpccli_samr_Close(pipe_cli, talloc_tos(), &alias_handle);
     760                dcerpc_samr_Close(b, talloc_tos(), &alias_handle, &result);
    697761        }
    698762
     
    722786{
    723787        struct rpc_pipe_client *pipe_cli = NULL;
    724         NTSTATUS status;
     788        NTSTATUS status, result;
    725789        WERROR werr;
    726790        struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
     
    732796        struct samr_SamArray *builtin_sam_array = NULL;
    733797        int i;
     798        struct dcerpc_binding_handle *b = NULL;
    734799
    735800        if (!r->out.buffer) {
     
    763828                goto done;
    764829        }
     830
     831        b = pipe_cli->binding_handle;
    765832
    766833        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
     
    789856        }
    790857
    791         status = rpccli_samr_QueryDomainInfo(pipe_cli, talloc_tos(),
     858        status = dcerpc_samr_QueryDomainInfo(b, talloc_tos(),
    792859                                             &builtin_handle,
    793860                                             2,
    794                                              &builtin_info);
     861                                             &builtin_info,
     862                                             &result);
    795863        if (!NT_STATUS_IS_OK(status)) {
    796864                werr = ntstatus_to_werror(status);
     865                goto done;
     866        }
     867        if (!NT_STATUS_IS_OK(result)) {
     868                werr = ntstatus_to_werror(result);
    797869                goto done;
    798870        }
     
    802874        }
    803875
    804         status = rpccli_samr_QueryDomainInfo(pipe_cli, talloc_tos(),
     876        status = dcerpc_samr_QueryDomainInfo(b, talloc_tos(),
    805877                                             &domain_handle,
    806878                                             2,
    807                                              &domain_info);
     879                                             &domain_info,
     880                                             &result);
    808881        if (!NT_STATUS_IS_OK(status)) {
    809882                werr = ntstatus_to_werror(status);
     883                goto done;
     884        }
     885        if (!NT_STATUS_IS_OK(result)) {
     886                werr = ntstatus_to_werror(result);
    810887                goto done;
    811888        }
     
    815892        }
    816893
    817         status = rpccli_samr_EnumDomainAliases(pipe_cli, talloc_tos(),
     894        status = dcerpc_samr_EnumDomainAliases(b, talloc_tos(),
    818895                                               &builtin_handle,
    819896                                               r->in.resume_handle,
    820897                                               &builtin_sam_array,
    821898                                               r->in.prefmaxlen,
    822                                                &entries_read);
     899                                               &entries_read,
     900                                               &result);
    823901        if (!NT_STATUS_IS_OK(status)) {
    824902                werr = ntstatus_to_werror(status);
     903                goto done;
     904        }
     905        if (!NT_STATUS_IS_OK(result)) {
     906                werr = ntstatus_to_werror(result);
    825907                goto done;
    826908        }
     
    851933        }
    852934
    853         status = rpccli_samr_EnumDomainAliases(pipe_cli, talloc_tos(),
     935        status = dcerpc_samr_EnumDomainAliases(b, talloc_tos(),
    854936                                               &domain_handle,
    855937                                               r->in.resume_handle,
    856938                                               &domain_sam_array,
    857939                                               r->in.prefmaxlen,
    858                                                &entries_read);
     940                                               &entries_read,
     941                                               &result);
    859942        if (!NT_STATUS_IS_OK(status)) {
    860943                werr = ntstatus_to_werror(status);
     944                goto done;
     945        }
     946        if (!NT_STATUS_IS_OK(result)) {
     947                werr = ntstatus_to_werror(result);
    861948                goto done;
    862949        }
     
    9141001                                            struct dom_sid *sid)
    9151002{
    916         NTSTATUS status;
     1003        NTSTATUS status, result;
    9171004        struct policy_handle lsa_handle;
     1005        struct dcerpc_binding_handle *b = lsa_pipe->binding_handle;
    9181006
    9191007        struct lsa_RefDomainList *domains = NULL;
     
    9341022        status = rpccli_lsa_open_policy2(lsa_pipe, mem_ctx,
    9351023                                         false,
    936                                          STD_RIGHT_READ_CONTROL_ACCESS |
     1024                                         SEC_STD_READ_CONTROL |
    9371025                                         LSA_POLICY_VIEW_LOCAL_INFORMATION |
    9381026                                         LSA_POLICY_LOOKUP_NAMES,
     
    9401028        NT_STATUS_NOT_OK_RETURN(status);
    9411029
    942         status = rpccli_lsa_LookupNames3(lsa_pipe, mem_ctx,
     1030        status = dcerpc_lsa_LookupNames3(b, mem_ctx,
    9431031                                         &lsa_handle,
    9441032                                         num_names,
     
    9481036                                         LSA_LOOKUP_NAMES_ALL, /* sure ? */
    9491037                                         &count,
    950                                          0, 0);
     1038                                         0, 0,
     1039                                         &result);
    9511040        NT_STATUS_NOT_OK_RETURN(status);
     1041        NT_STATUS_NOT_OK_RETURN(result);
    9521042
    9531043        if (count != 1 || sids.count != 1) {
     
    9721062        struct rpc_pipe_client *pipe_cli = NULL;
    9731063        struct rpc_pipe_client *lsa_pipe = NULL;
    974         NTSTATUS status;
     1064        NTSTATUS status, result;
    9751065        WERROR werr;
    9761066        struct lsa_String lsa_account_name;
     
    9851075        struct dom_sid *add_sids = NULL;
    9861076        struct dom_sid *del_sids = NULL;
    987         size_t num_add_sids = 0;
    988         size_t num_del_sids = 0;
     1077        uint32_t num_add_sids = 0;
     1078        uint32_t num_del_sids = 0;
     1079        struct dcerpc_binding_handle *b = NULL;
    9891080
    9901081        if ((!add && !del && !set) || (add && del && set)) {
     
    10691160                goto done;
    10701161        }
     1162
     1163        b = pipe_cli->binding_handle;
    10711164
    10721165        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
     
    11571250                struct lsa_SidArray current_sids;
    11581251
    1159                 status = rpccli_samr_GetMembersInAlias(pipe_cli, talloc_tos(),
     1252                status = dcerpc_samr_GetMembersInAlias(b, talloc_tos(),
    11601253                                                       &alias_handle,
    1161                                                        &current_sids);
     1254                                                       &current_sids,
     1255                                                       &result);
    11621256                if (!NT_STATUS_IS_OK(status)) {
    11631257                        werr = ntstatus_to_werror(status);
    11641258                        goto done;
    11651259                }
     1260                if (!NT_STATUS_IS_OK(result)) {
     1261                        werr = ntstatus_to_werror(result);
     1262                        goto done;
     1263                }
    11661264
    11671265                /* add list */
     
    11701268                        bool already_member = false;
    11711269                        for (k=0; k < current_sids.num_sids; k++) {
    1172                                 if (sid_equal(&member_sids[i],
     1270                                if (dom_sid_equal(&member_sids[i],
    11731271                                              current_sids.sids[k].sid)) {
    11741272                                        already_member = true;
     
    11921290                        bool keep_member = false;
    11931291                        for (i=0; i < r->in.total_entries; i++) {
    1194                                 if (sid_equal(&member_sids[i],
     1292                                if (dom_sid_equal(&member_sids[i],
    11951293                                              current_sids.sids[k].sid)) {
    11961294                                        keep_member = true;
     
    12131311
    12141312        for (i=0; i < num_add_sids; i++) {
    1215                 status = rpccli_samr_AddAliasMember(pipe_cli, talloc_tos(),
     1313                status = dcerpc_samr_AddAliasMember(b, talloc_tos(),
    12161314                                                    &alias_handle,
    1217                                                     &add_sids[i]);
     1315                                                    &add_sids[i],
     1316                                                    &result);
    12181317                if (!NT_STATUS_IS_OK(status)) {
    12191318                        werr = ntstatus_to_werror(status);
    12201319                        goto done;
    12211320                }
     1321                if (!NT_STATUS_IS_OK(result)) {
     1322                        werr = ntstatus_to_werror(result);
     1323                        goto done;
     1324                }
    12221325        }
    12231326
     
    12251328
    12261329        for (i=0; i < num_del_sids; i++) {
    1227                 status = rpccli_samr_DeleteAliasMember(pipe_cli, talloc_tos(),
     1330                status = dcerpc_samr_DeleteAliasMember(b, talloc_tos(),
    12281331                                                       &alias_handle,
    1229                                                        &del_sids[i]);
     1332                                                       &del_sids[i],
     1333                                                       &result);
    12301334                if (!NT_STATUS_IS_OK(status)) {
    12311335                        werr = ntstatus_to_werror(status);
    12321336                        goto done;
    12331337                }
     1338                if (!NT_STATUS_IS_OK(result)) {
     1339                        werr = ntstatus_to_werror(result);
     1340                        goto done;
     1341                }
    12341342        }
    12351343
     
    12371345
    12381346 done:
    1239         if (is_valid_policy_hnd(&alias_handle)) {
    1240                 rpccli_samr_Close(pipe_cli, talloc_tos(), &alias_handle);
     1347        if (b && is_valid_policy_hnd(&alias_handle)) {
     1348                dcerpc_samr_Close(b, talloc_tos(), &alias_handle, &result);
    12411349        }
    12421350
  • trunk/server/source3/lib/netapi/netapi.c

    r414 r745  
    2121#include "lib/netapi/netapi.h"
    2222#include "lib/netapi/netapi_private.h"
    23 
    24 extern bool AllowDebugChange;
     23#include "secrets.h"
     24#include "krb5_env.h"
    2525
    2626struct libnetapi_ctx *stat_ctx = NULL;
     
    5050
    5151/****************************************************************
     52Create a libnetapi context, for use in non-Samba applications.  This
     53loads the smb.conf file and sets the debug level to 0, so that
     54applications are not flooded with debug logs at level 10, when they
     55were not expecting it.
    5256****************************************************************/
    5357
    5458NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
    5559{
    56         NET_API_STATUS status;
    57         struct libnetapi_ctx *ctx = NULL;
    58         char *krb5_cc_env = NULL;
    59 
    6060        if (stat_ctx && libnetapi_initialized) {
    6161                *context = stat_ctx;
     
    6868        frame = talloc_stackframe();
    6969
    70         ctx = talloc_zero(frame, struct libnetapi_ctx);
    71         if (!ctx) {
    72                 TALLOC_FREE(frame);
    73                 return W_ERROR_V(WERR_NOMEM);
    74         }
    75 
    76         if (!DEBUGLEVEL) {
    77                 DEBUGLEVEL = 0;
    78         }
    79 
    80         /* prevent setup_logging() from closing x_stderr... */
    81         dbf = 0;
    82         setup_logging("libnetapi", true);
    83 
    84         dbf = x_stderr;
    85         x_setbuf(x_stderr, NULL);
    86         AllowDebugChange = false;
    87 
    88         load_case_tables();
     70        /* Case tables must be loaded before any string comparisons occour */
     71        load_case_tables_library();
     72
     73        /* When libnetapi is invoked from an application, it does not
     74         * want to be swamped with level 10 debug messages, even if
     75         * this has been set for the server in smb.conf */
     76        lp_set_cmdline("log level", "0");
     77        setup_logging("libnetapi", DEBUG_STDERR);
    8978
    9079        if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) {
     
    9483        }
    9584
    96         AllowDebugChange = true;
    97 
    9885        init_names();
    9986        load_interfaces();
    10087        reopen_logs();
     88
     89        BlockSignals(True, SIGPIPE);
     90
     91        return libnetapi_net_init(context);
     92}
     93
     94/****************************************************************
     95Create a libnetapi context, for use inside the 'net' binary.
     96
     97As we know net has already loaded the smb.conf file, and set the debug
     98level etc, this avoids doing so again (which causes trouble with -d on
     99the command line).
     100****************************************************************/
     101
     102NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
     103{
     104        NET_API_STATUS status;
     105        struct libnetapi_ctx *ctx = NULL;
     106        char *krb5_cc_env = NULL;
     107
     108        frame = talloc_stackframe();
     109
     110        ctx = talloc_zero(frame, struct libnetapi_ctx);
     111        if (!ctx) {
     112                TALLOC_FREE(frame);
     113                return W_ERROR_V(WERR_NOMEM);
     114        }
    101115
    102116        BlockSignals(True, SIGPIPE);
     
    133147
    134148/****************************************************************
     149 Return the static libnetapi context
    135150****************************************************************/
    136151
     
    146161
    147162/****************************************************************
     163 Free the static libnetapi context
    148164****************************************************************/
    149165
     
    182198
    183199/****************************************************************
     200 Override the current log level for libnetapi
    184201****************************************************************/
    185202
     
    187204                                        const char *debuglevel)
    188205{
    189         AllowDebugChange = true;
    190206        ctx->debuglevel = talloc_strdup(ctx, debuglevel);
    191         if (!debug_parse_levels(debuglevel)) {
     207        if (!lp_set_cmdline("log level", debuglevel)) {
    192208                return W_ERROR_V(WERR_GENERAL_FAILURE);
    193209        }
  • trunk/server/source3/lib/netapi/netapi.h

    r414 r745  
    12851285};
    12861286
     1287#define DS_PDC_FLAG ( 0x00000001 )
     1288#define DS_GC_FLAG ( 0x00000004 )
     1289#define DS_LDAP_FLAG ( 0x00000008 )
     1290#define DS_DS_FLAG ( 0x00000010 )
     1291#define DS_KDC_FLAG ( 0x00000020 )
     1292#define DS_TIMESERV_FLAG ( 0x00000040 )
     1293#define DS_CLOSEST_FLAG ( 0x00000080 )
     1294#define DS_WRITABLE_FLAG ( 0x00000100 )
     1295#define DS_GOOD_TIMESERV_FLAG ( 0x00000200 )
     1296#define DS_NDNC_FLAG ( 0x00000400 )
     1297#define DS_SELECT_SECRET_DOMAIN_6_FLAG ( 0x00000800 )
     1298#define DS_FULL_SECRET_DOMAIN_6_FLAG ( 0x00001000 )
     1299#define DS_DNS_CONTROLLER_FLAG ( 0x20000000 )
     1300#define DS_DNS_DOMAIN_FLAG ( 0x40000000 )
     1301#define DS_DNS_FOREST_FLAG ( 0x80000000 )
     1302
    12871303#endif /* _HEADER_libnetapi */
    12881304
     
    13061322#define NETLOGON_CONTROL_BREAKPOINT ( 0x0000FFFF )
    13071323
     1324#define DS_FORCE_REDISCOVERY ( 0x00000001 )
     1325#define DS_DIRECTORY_SERVICE_REQUIRED ( 0x00000010 )
     1326#define DS_DIRECTORY_SERVICE_PREFERRED ( 0x00000020 )
     1327#define DS_GC_SERVER_REQUIRED ( 0x00000040 )
     1328#define DS_PDC_REQUIRED ( 0x00000080 )
     1329#define DS_BACKGROUND_ONLY ( 0x00000100 )
     1330#define DS_IP_REQUIRED ( 0x00000200 )
     1331#define DS_KDC_REQUIRED ( 0x00000400 )
     1332#define DS_TIMESERV_REQUIRED ( 0x00000800 )
     1333#define DS_WRITABLE_REQUIRED ( 0x00001000 )
     1334#define DS_GOOD_TIMESERV_PREFERRED ( 0x00002000 )
     1335#define DS_AVOID_SELF ( 0x00004000 )
     1336#define DS_ONLY_LDAP_NEEDED ( 0x00008000 )
     1337#define DS_IS_FLAT_NAME ( 0x00010000 )
     1338#define DS_IS_DNS_NAME ( 0x00020000 )
     1339#define DS_TRY_NEXTCLOSEST_SITE ( 0x00040000 )
     1340#define DS_DIRECTORY_SERVICE_6_REQUIRED ( 0x00080000 )
     1341#define DS_WEB_SERVICE_REQUIRED ( 0x00100000 )
     1342#define DS_RETURN_DNS_NAME ( 0x40000000 )
     1343#define DS_RETURN_FLAT_NAME ( 0x80000000 )
     1344
    13081345#endif /* _HEADER_netlogon */
    13091346
  • trunk/server/source3/lib/netapi/netapi_private.h

    r590 r745  
    2121#define __LIB_NETAPI_PRIVATE_H__
    2222
     23#include "lib/netapi/netapi_net.h"
     24
    2325#define LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, fn) \
    2426        DEBUG(10,("redirecting call %s to localhost\n", #fn)); \
     
    2729        } \
    2830        return fn ## _r(ctx, r);
     31
     32struct dcerpc_binding_handle;
    2933
    3034struct libnetapi_private_ctx {
     
    4549
    4650        struct client_ipc_connection *ipc_connections;
     51
     52        struct messaging_context *msg_ctx;
    4753};
    4854
     
    5763                           const struct ndr_syntax_id *interface,
    5864                           struct rpc_pipe_client **presult);
     65WERROR libnetapi_get_binding_handle(struct libnetapi_ctx *ctx,
     66                                    const char *server_name,
     67                                    const struct ndr_syntax_id *interface,
     68                                    struct dcerpc_binding_handle **binding_handle);
    5969WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx,
    6070                                  struct rpc_pipe_client *pipe_cli,
  • trunk/server/source3/lib/netapi/netlogon.c

    r596 r745  
    2020#include "includes.h"
    2121
     22#include "../librpc/gen_ndr/ndr_netlogon_c.h"
    2223#include "librpc/gen_ndr/libnetapi.h"
    2324#include "lib/netapi/netapi.h"
    2425#include "lib/netapi/netapi_private.h"
    2526#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_netlogon.h"
    2727
    2828static WERROR construct_data(enum netr_LogonControlCode function_code,
     
    4444                data_out->debug_level = atoi((const char *)data_in);
    4545                break;
     46        case NETLOGON_CONTROL_FORCE_DNS_REG:
     47                ZERO_STRUCTP(data_out);
     48                break;
    4649        default:
    4750                return WERR_INVALID_PARAM;
     
    127130        WERROR werr;
    128131        NTSTATUS status;
    129         struct rpc_pipe_client *pipe_cli = NULL;
    130132        union netr_CONTROL_QUERY_INFORMATION query;
    131 
    132         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    133                                    &ndr_table_netlogon.syntax_id,
    134                                    &pipe_cli);
    135         if (!W_ERROR_IS_OK(werr)) {
    136                 goto done;
    137         }
    138 
    139         status = rpccli_netr_LogonControl(pipe_cli, talloc_tos(),
     133        struct dcerpc_binding_handle *b;
     134
     135        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     136                                            &ndr_table_netlogon.syntax_id,
     137                                            &b);
     138        if (!W_ERROR_IS_OK(werr)) {
     139                goto done;
     140        }
     141
     142        status = dcerpc_netr_LogonControl(b, talloc_tos(),
    140143                                          r->in.server_name,
    141144                                          r->in.function_code,
     
    147150                goto done;
    148151        }
     152        if (!W_ERROR_IS_OK(werr)) {
     153                goto done;
     154        }
    149155
    150156        werr = construct_buffer(ctx, r->in.query_level, &query,
     
    175181        WERROR werr;
    176182        NTSTATUS status;
    177         struct rpc_pipe_client *pipe_cli = NULL;
    178183        union netr_CONTROL_DATA_INFORMATION data;
    179184        union netr_CONTROL_QUERY_INFORMATION query;
     185        struct dcerpc_binding_handle *b;
    180186
    181187        werr = construct_data(r->in.function_code, r->in.data, &data);
     
    184190        }
    185191
    186         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    187                                    &ndr_table_netlogon.syntax_id,
    188                                    &pipe_cli);
     192        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     193                                            &ndr_table_netlogon.syntax_id,
     194                                            &b);
    189195        if (!W_ERROR_IS_OK(werr)) {
    190196                goto done;
     
    194200        case NETLOGON_CONTROL_TC_VERIFY:
    195201        case NETLOGON_CONTROL_SET_DBFLAG:
    196                 status = rpccli_netr_LogonControl2Ex(pipe_cli, talloc_tos(),
     202        case NETLOGON_CONTROL_FORCE_DNS_REG:
     203                status = dcerpc_netr_LogonControl2Ex(b, talloc_tos(),
    197204                                                     r->in.server_name,
    198205                                                     r->in.function_code,
     
    203210                break;
    204211        default:
    205                 status = rpccli_netr_LogonControl2(pipe_cli, talloc_tos(),
     212                status = dcerpc_netr_LogonControl2(b, talloc_tos(),
    206213                                                   r->in.server_name,
    207214                                                   r->in.function_code,
     
    213220        }
    214221
    215         if (!W_ERROR_IS_OK(werr)) {
    216                 goto done;
    217         }
    218 
    219222        if (!NT_STATUS_IS_OK(status)) {
    220223                werr = ntstatus_to_werror(status);
     
    222225        }
    223226
     227        if (!W_ERROR_IS_OK(werr)) {
     228                goto done;
     229        }
     230
    224231        werr = construct_buffer(ctx, r->in.query_level, &query,
    225232                                r->out.buffer);
  • trunk/server/source3/lib/netapi/samr.c

    r414 r745  
    2121#include "lib/netapi/netapi.h"
    2222#include "lib/netapi/netapi_private.h"
    23 #include "../librpc/gen_ndr/cli_samr.h"
     23#include "rpc_client/rpc_client.h"
     24#include "../librpc/gen_ndr/ndr_samr_c.h"
     25#include "rpc_client/cli_samr.h"
     26#include "rpc_client/init_lsa.h"
     27#include "../libcli/security/security.h"
    2428
    2529/****************************************************************
     
    3438                                  struct dom_sid2 **domain_sid)
    3539{
    36         NTSTATUS status;
     40        NTSTATUS status, result;
    3741        WERROR werr;
    3842        struct libnetapi_private_ctx *priv;
     
    4448        bool domain_found = true;
    4549        int i;
     50        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    4651
    4752        priv = talloc_get_type_abort(mem_ctx->private_data,
     
    7883
    7984        if (!is_valid_policy_hnd(connect_handle)) {
    80                 status = rpccli_try_samr_connects(pipe_cli, mem_ctx,
     85                status = dcerpc_try_samr_connects(pipe_cli->binding_handle, mem_ctx,
     86                                                  pipe_cli->srv_name_slash,
    8187                                                  connect_mask,
    82                                                   connect_handle);
     88                                                  connect_handle,
     89                                                  &result);
    8390                if (!NT_STATUS_IS_OK(status)) {
    8491                        werr = ntstatus_to_werror(status);
    8592                        goto done;
    8693                }
    87         }
    88 
    89         status = rpccli_samr_EnumDomains(pipe_cli, mem_ctx,
     94                if (!NT_STATUS_IS_OK(result)) {
     95                        werr = ntstatus_to_werror(result);
     96                        goto done;
     97                }
     98        }
     99
     100        status = dcerpc_samr_EnumDomains(b, mem_ctx,
    90101                                         connect_handle,
    91102                                         &resume_handle,
    92103                                         &sam,
    93104                                         0xffffffff,
    94                                          &num_entries);
     105                                         &num_entries,
     106                                         &result);
    95107        if (!NT_STATUS_IS_OK(status)) {
    96108                werr = ntstatus_to_werror(status);
    97109                goto done;
    98110        }
     111        if (!NT_STATUS_IS_OK(result)) {
     112                werr = ntstatus_to_werror(result);
     113                goto done;
     114        }
    99115
    100116        for (i=0; i<num_entries; i++) {
     
    117133        init_lsa_String(&lsa_domain_name, domain_name);
    118134
    119         status = rpccli_samr_LookupDomain(pipe_cli, mem_ctx,
     135        status = dcerpc_samr_LookupDomain(b, mem_ctx,
    120136                                          connect_handle,
    121137                                          &lsa_domain_name,
    122                                           domain_sid);
     138                                          domain_sid,
     139                                          &result);
    123140        if (!NT_STATUS_IS_OK(status)) {
    124141                werr = ntstatus_to_werror(status);
    125142                goto done;
    126143        }
    127 
    128         status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx,
     144        if (!NT_STATUS_IS_OK(result)) {
     145                werr = ntstatus_to_werror(result);
     146                goto done;
     147        }
     148
     149        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    129150                                        connect_handle,
    130151                                        domain_mask,
    131152                                        *domain_sid,
    132                                         domain_handle);
     153                                        domain_handle,
     154                                        &result);
    133155        if (!NT_STATUS_IS_OK(status)) {
    134156                werr = ntstatus_to_werror(status);
     157                goto done;
     158        }
     159        if (!NT_STATUS_IS_OK(result)) {
     160                werr = ntstatus_to_werror(result);
    135161                goto done;
    136162        }
     
    163189                                          struct policy_handle *builtin_handle)
    164190{
    165         NTSTATUS status;
     191        NTSTATUS status, result;
    166192        WERROR werr;
    167193        struct libnetapi_private_ctx *priv;
     194        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    168195
    169196        priv = talloc_get_type_abort(mem_ctx->private_data,
     
    196223
    197224        if (!is_valid_policy_hnd(connect_handle)) {
    198                 status = rpccli_try_samr_connects(pipe_cli, mem_ctx,
     225                status = dcerpc_try_samr_connects(pipe_cli->binding_handle, mem_ctx,
     226                                                  pipe_cli->srv_name_slash,
    199227                                                  connect_mask,
    200                                                   connect_handle);
     228                                                  connect_handle,
     229                                                  &result);
    201230                if (!NT_STATUS_IS_OK(status)) {
    202231                        werr = ntstatus_to_werror(status);
    203232                        goto done;
    204233                }
    205         }
    206 
    207         status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx,
     234                if (!NT_STATUS_IS_OK(result)) {
     235                        werr = ntstatus_to_werror(result);
     236                        goto done;
     237                }
     238        }
     239
     240        status = dcerpc_samr_OpenDomain(b, mem_ctx,
    208241                                        connect_handle,
    209242                                        builtin_mask,
    210                                         CONST_DISCARD(DOM_SID *, &global_sid_Builtin),
    211                                         builtin_handle);
     243                                        CONST_DISCARD(struct dom_sid *, &global_sid_Builtin),
     244                                        builtin_handle,
     245                                        &result);
    212246        if (!NT_STATUS_IS_OK(status)) {
    213247                werr = ntstatus_to_werror(status);
    214248                goto done;
    215249        }
     250        if (!NT_STATUS_IS_OK(result)) {
     251                werr = ntstatus_to_werror(result);
     252                goto done;
     253        }
    216254
    217255        priv->samr.cli                  = pipe_cli;
     
    236274{
    237275        struct libnetapi_private_ctx *priv;
     276        struct dcerpc_binding_handle *b;
     277        NTSTATUS result;
    238278
    239279        if (!is_valid_policy_hnd(handle)) {
     
    244284                struct libnetapi_private_ctx);
    245285
    246         if (!policy_hnd_equal(handle, &priv->samr.domain_handle)) {
    247                 return;
    248         }
    249 
    250         rpccli_samr_Close(priv->samr.cli, ctx, handle);
     286        if (!policy_handle_equal(handle, &priv->samr.domain_handle)) {
     287                return;
     288        }
     289
     290        b = priv->samr.cli->binding_handle;
     291
     292        dcerpc_samr_Close(b, ctx, handle, &result);
    251293
    252294        ZERO_STRUCT(priv->samr.domain_handle);
     
    260302{
    261303        struct libnetapi_private_ctx *priv;
     304        struct dcerpc_binding_handle *b;
     305        NTSTATUS result;
    262306
    263307        if (!is_valid_policy_hnd(handle)) {
     
    268312                struct libnetapi_private_ctx);
    269313
    270         if (!policy_hnd_equal(handle, &priv->samr.builtin_handle)) {
    271                 return;
    272         }
    273 
    274         rpccli_samr_Close(priv->samr.cli, ctx, handle);
     314        if (!policy_handle_equal(handle, &priv->samr.builtin_handle)) {
     315                return;
     316        }
     317
     318        b = priv->samr.cli->binding_handle;
     319
     320        dcerpc_samr_Close(b, ctx, handle, &result);
    275321
    276322        ZERO_STRUCT(priv->samr.builtin_handle);
     
    284330{
    285331        struct libnetapi_private_ctx *priv;
     332        struct dcerpc_binding_handle *b;
     333        NTSTATUS result;
    286334
    287335        if (!is_valid_policy_hnd(handle)) {
     
    292340                struct libnetapi_private_ctx);
    293341
    294         if (!policy_hnd_equal(handle, &priv->samr.connect_handle)) {
    295                 return;
    296         }
    297 
    298         rpccli_samr_Close(priv->samr.cli, ctx, handle);
     342        if (!policy_handle_equal(handle, &priv->samr.connect_handle)) {
     343                return;
     344        }
     345
     346        b = priv->samr.cli->binding_handle;
     347
     348        dcerpc_samr_Close(b, ctx, handle, &result);
    299349
    300350        ZERO_STRUCT(priv->samr.connect_handle);
  • trunk/server/source3/lib/netapi/serverinfo.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "libnet/libnet.h"
    27 #include "../librpc/gen_ndr/cli_srvsvc.h"
     26#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
     27#include "lib/smbconf/smbconf.h"
     28#include "lib/smbconf/smbconf_reg.h"
    2829
    2930/****************************************************************
     
    480481                          struct NetServerGetInfo *r)
    481482{
    482         struct rpc_pipe_client *pipe_cli = NULL;
    483483        NTSTATUS status;
    484484        WERROR werr;
    485485        union srvsvc_NetSrvInfo info;
     486        struct dcerpc_binding_handle *b;
    486487
    487488        if (!r->out.buffer) {
     
    502503        }
    503504
    504         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    505                                    &ndr_table_srvsvc.syntax_id,
    506                                    &pipe_cli);
     505        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     506                                            &ndr_table_srvsvc.syntax_id,
     507                                            &b);
    507508        if (!W_ERROR_IS_OK(werr)) {
    508509                goto done;
    509510        }
    510511
    511         status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, talloc_tos(),
     512        status = dcerpc_srvsvc_NetSrvGetInfo(b, talloc_tos(),
    512513                                             r->in.server_name,
    513514                                             r->in.level,
     
    519520        }
    520521
     522        if (!W_ERROR_IS_OK(werr)) {
     523                goto done;
     524        }
     525
    521526        status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info,
    522527                                                       r->out.buffer);
     
    536541                                      struct NetServerSetInfo *r)
    537542{
    538         WERROR werr;
     543        WERROR werr = WERR_OK;
     544        sbcErr err;
    539545        struct smbconf_ctx *conf_ctx;
    540546        struct srvsvc_NetSrvInfo1005 *info1005;
     
    559565        }
    560566
    561         werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
    562         if (!W_ERROR_IS_OK(werr)) {
    563                 goto done;
    564         }
    565 
    566         werr = smbconf_set_global_parameter(conf_ctx, "server string",
     567        err = smbconf_init_reg(ctx, &conf_ctx, NULL);
     568        if (!SBC_ERROR_IS_OK(err)) {
     569                libnetapi_set_error_string(ctx,
     570                        "Could not initialize backend: %s",
     571                        sbcErrorString(err));
     572                werr = WERR_NO_SUCH_SERVICE;
     573                goto done;
     574        }
     575
     576        err = smbconf_set_global_parameter(conf_ctx, "server string",
    567577                                            info1005->comment);
     578        if (!SBC_ERROR_IS_OK(err)) {
     579                libnetapi_set_error_string(ctx,
     580                        "Could not set global parameter: %s",
     581                        sbcErrorString(err));
     582                werr = WERR_NO_SUCH_SERVICE;
     583                goto done;
     584        }
    568585
    569586 done:
     
    594611                          struct NetServerSetInfo *r)
    595612{
    596         struct rpc_pipe_client *pipe_cli = NULL;
    597613        NTSTATUS status;
    598614        WERROR werr;
    599615        union srvsvc_NetSrvInfo info;
    600 
    601         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    602                                    &ndr_table_srvsvc.syntax_id,
    603                                    &pipe_cli);
     616        struct dcerpc_binding_handle *b;
     617
     618        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     619                                            &ndr_table_srvsvc.syntax_id,
     620                                            &b);
    604621        if (!W_ERROR_IS_OK(werr)) {
    605622                goto done;
     
    615632        }
    616633
    617         status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, talloc_tos(),
     634        status = dcerpc_srvsvc_NetSrvSetInfo(b, talloc_tos(),
    618635                                             r->in.server_name,
    619636                                             r->in.level,
     
    636653                      struct NetRemoteTOD *r)
    637654{
    638         struct rpc_pipe_client *pipe_cli = NULL;
    639655        NTSTATUS status;
    640656        WERROR werr;
    641657        struct srvsvc_NetRemoteTODInfo *info = NULL;
    642 
    643         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    644                                    &ndr_table_srvsvc.syntax_id,
    645                                    &pipe_cli);
     658        struct dcerpc_binding_handle *b;
     659
     660        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     661                                            &ndr_table_srvsvc.syntax_id,
     662                                            &b);
    646663        if (!W_ERROR_IS_OK(werr)) {
    647664                goto done;
    648665        }
    649666
    650         status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, talloc_tos(),
     667        status = dcerpc_srvsvc_NetRemoteTOD(b, talloc_tos(),
    651668                                            r->in.server_name,
    652669                                            &info,
     
    657674        }
    658675
     676        if (!W_ERROR_IS_OK(werr)) {
     677                goto done;
     678        }
     679
    659680        *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
    660681                          sizeof(struct srvsvc_NetRemoteTODInfo));
  • trunk/server/source3/lib/netapi/share.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_srvsvc.h"
     26#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
    2727
    2828/****************************************************************
     
    183183        WERROR werr;
    184184        NTSTATUS status;
    185         struct rpc_pipe_client *pipe_cli = NULL;
    186185        union srvsvc_NetShareInfo info;
     186        struct dcerpc_binding_handle *b;
    187187
    188188        if (!r->in.buffer) {
     
    200200        }
    201201
    202         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    203                                    &ndr_table_srvsvc.syntax_id,
    204                                    &pipe_cli);
     202        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     203                                            &ndr_table_srvsvc.syntax_id,
     204                                            &b);
    205205        if (!W_ERROR_IS_OK(werr)) {
    206206                goto done;
     
    216216        }
    217217
    218         status = rpccli_srvsvc_NetShareAdd(pipe_cli, talloc_tos(),
     218        status = dcerpc_srvsvc_NetShareAdd(b, talloc_tos(),
    219219                                           r->in.server_name,
    220220                                           r->in.level,
     
    222222                                           r->out.parm_err,
    223223                                           &werr);
     224        if (!NT_STATUS_IS_OK(status)) {
     225                werr = ntstatus_to_werror(status);
     226                goto done;
     227        }
     228
    224229        if (!W_ERROR_IS_OK(werr)) {
    225230                goto done;
     
    247252        WERROR werr;
    248253        NTSTATUS status;
    249         struct rpc_pipe_client *pipe_cli = NULL;
     254        struct dcerpc_binding_handle *b;
    250255
    251256        if (!r->in.net_name) {
     
    253258        }
    254259
    255         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    256                                    &ndr_table_srvsvc.syntax_id,
    257                                    &pipe_cli);
    258         if (!W_ERROR_IS_OK(werr)) {
    259                 goto done;
    260         }
    261 
    262         status = rpccli_srvsvc_NetShareDel(pipe_cli, talloc_tos(),
     260        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     261                                            &ndr_table_srvsvc.syntax_id,
     262                                            &b);
     263        if (!W_ERROR_IS_OK(werr)) {
     264                goto done;
     265        }
     266
     267        status = dcerpc_srvsvc_NetShareDel(b, talloc_tos(),
    263268                                           r->in.server_name,
    264269                                           r->in.net_name,
     
    291296        WERROR werr;
    292297        NTSTATUS status;
    293         struct rpc_pipe_client *pipe_cli = NULL;
    294298        struct srvsvc_NetShareInfoCtr info_ctr;
    295299        struct srvsvc_NetShareCtr0 ctr0;
     
    297301        struct srvsvc_NetShareCtr2 ctr2;
    298302        uint32_t i;
     303        struct dcerpc_binding_handle *b;
    299304
    300305        if (!r->out.buffer) {
     
    316321        ZERO_STRUCT(info_ctr);
    317322
    318         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    319                                    &ndr_table_srvsvc.syntax_id,
    320                                    &pipe_cli);
     323        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     324                                            &ndr_table_srvsvc.syntax_id,
     325                                            &b);
    321326        if (!W_ERROR_IS_OK(werr)) {
    322327                goto done;
     
    339344        }
    340345
    341         status = rpccli_srvsvc_NetShareEnumAll(pipe_cli, talloc_tos(),
     346        status = dcerpc_srvsvc_NetShareEnumAll(b, talloc_tos(),
    342347                                               r->in.server_name,
    343348                                               &info_ctr,
     
    346351                                               r->out.resume_handle,
    347352                                               &werr);
    348         if (NT_STATUS_IS_ERR(status)) {
     353        if (!NT_STATUS_IS_OK(status)) {
     354                werr = ntstatus_to_werror(status);
     355                goto done;
     356        }
     357
     358        if (!W_ERROR_IS_OK(werr) && !W_ERROR_EQUAL(werr, WERR_MORE_DATA)) {
    349359                goto done;
    350360        }
     
    371381                if (!NT_STATUS_IS_OK(status)) {
    372382                        werr = ntstatus_to_werror(status);
     383                        goto done;
    373384                }
    374385        }
     
    395406        WERROR werr;
    396407        NTSTATUS status;
    397         struct rpc_pipe_client *pipe_cli = NULL;
    398408        union srvsvc_NetShareInfo info;
    399409        uint32_t num_entries = 0;
     410        struct dcerpc_binding_handle *b;
    400411
    401412        if (!r->in.net_name || !r->out.buffer) {
     
    417428        }
    418429
    419         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    420                                    &ndr_table_srvsvc.syntax_id,
    421                                    &pipe_cli);
    422         if (!W_ERROR_IS_OK(werr)) {
    423                 goto done;
    424         }
    425 
    426         status = rpccli_srvsvc_NetShareGetInfo(pipe_cli, talloc_tos(),
     430        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     431                                            &ndr_table_srvsvc.syntax_id,
     432                                            &b);
     433        if (!W_ERROR_IS_OK(werr)) {
     434                goto done;
     435        }
     436
     437        status = dcerpc_srvsvc_NetShareGetInfo(b, talloc_tos(),
    427438                                               r->in.server_name,
    428439                                               r->in.net_name,
     
    430441                                               &info,
    431442                                               &werr);
     443        if (!NT_STATUS_IS_OK(status)) {
     444                werr = ntstatus_to_werror(status);
     445                goto done;
     446        }
    432447
    433448        if (!W_ERROR_IS_OK(werr)) {
     
    465480        WERROR werr;
    466481        NTSTATUS status;
    467         struct rpc_pipe_client *pipe_cli = NULL;
    468482        union srvsvc_NetShareInfo info;
     483        struct dcerpc_binding_handle *b;
    469484
    470485        if (!r->in.buffer) {
     
    487502        }
    488503
    489         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    490                                    &ndr_table_srvsvc.syntax_id,
    491                                    &pipe_cli);
     504        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     505                                            &ndr_table_srvsvc.syntax_id,
     506                                            &b);
    492507        if (!W_ERROR_IS_OK(werr)) {
    493508                goto done;
     
    503518        }
    504519
    505         status = rpccli_srvsvc_NetShareSetInfo(pipe_cli, talloc_tos(),
     520        status = dcerpc_srvsvc_NetShareSetInfo(b, talloc_tos(),
    506521                                               r->in.server_name,
    507522                                               r->in.net_name,
     
    510525                                               r->out.parm_err,
    511526                                               &werr);
     527        if (!NT_STATUS_IS_OK(status)) {
     528                werr = ntstatus_to_werror(status);
     529                goto done;
     530        }
     531
    512532        if (!W_ERROR_IS_OK(werr)) {
    513533                goto done;
  • trunk/server/source3/lib/netapi/shutdown.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_initshutdown.h"
     26#include "../librpc/gen_ndr/ndr_initshutdown_c.h"
     27#include "rpc_client/init_lsa.h"
    2728
    2829/****************************************************************
     
    3435        WERROR werr;
    3536        NTSTATUS status;
    36         struct rpc_pipe_client *pipe_cli = NULL;
    3737        struct lsa_StringLarge message;
     38        struct dcerpc_binding_handle *b;
    3839
    39         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    40                                    &ndr_table_initshutdown.syntax_id,
    41                                    &pipe_cli);
     40        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     41                                            &ndr_table_initshutdown.syntax_id,
     42                                            &b);
    4243        if (!W_ERROR_IS_OK(werr)) {
    4344                goto done;
     
    4647        init_lsa_StringLarge(&message, r->in.message);
    4748
    48         status = rpccli_initshutdown_Init(pipe_cli, talloc_tos(),
     49        status = dcerpc_initshutdown_Init(b, talloc_tos(),
    4950                                          NULL,
    5051                                          &message,
     
    7980        WERROR werr;
    8081        NTSTATUS status;
    81         struct rpc_pipe_client *pipe_cli = NULL;
     82        struct dcerpc_binding_handle *b;
    8283
    83         werr = libnetapi_open_pipe(ctx, r->in.server_name,
    84                                    &ndr_table_initshutdown.syntax_id,
    85                                    &pipe_cli);
     84        werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     85                                            &ndr_table_initshutdown.syntax_id,
     86                                            &b);
    8687        if (!W_ERROR_IS_OK(werr)) {
    8788                goto done;
    8889        }
    8990
    90         status = rpccli_initshutdown_Abort(pipe_cli, talloc_tos(),
     91        status = dcerpc_initshutdown_Abort(b, talloc_tos(),
    9192                                           NULL,
    9293                                           &werr);
  • trunk/server/source3/lib/netapi/sid.c

    r414 r745  
    2121
    2222#include "lib/netapi/netapi.h"
     23#include "../libcli/security/security.h"
    2324
    2425/****************************************************************
  • trunk/server/source3/lib/netapi/user.c

    r596 r745  
    2424#include "lib/netapi/netapi_private.h"
    2525#include "lib/netapi/libnetapi.h"
    26 #include "../librpc/gen_ndr/cli_samr.h"
     26#include "../librpc/gen_ndr/ndr_samr_c.h"
     27#include "rpc_client/init_samr.h"
     28#include "../libds/common/flags.h"
     29#include "rpc_client/init_lsa.h"
     30#include "../libcli/security/security.h"
     31#include "../libds/common/flag_mapping.h"
     32#include "rpc_client/cli_pipe.h"
    2733
    2834/****************************************************************
     
    109115        info21->lm_owf_password         = zero_parameters;
    110116        info21->nt_owf_password         = zero_parameters;
    111         info21->unknown3.string         = NULL;
     117        info21->private_data.string     = NULL;
    112118        info21->buf_count               = 0;
    113119        info21->buffer                  = NULL;
     
    124130        info21->nt_password_set         = 0;
    125131        info21->password_expired        = infoX->usriX_password_expired;
    126         info21->unknown4                = 0;
     132        info21->private_data_sensitive  = 0;
    127133}
    128134
     
    293299        union samr_UserInfo user_info;
    294300        struct samr_UserInfo21 info21;
    295         NTSTATUS status;
     301        NTSTATUS status, result;
     302        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    296303
    297304        if (!uX) {
     
    311318                                          &user_info.info25.password);
    312319
    313                 status = rpccli_samr_SetUserInfo2(pipe_cli, talloc_tos(),
     320                status = dcerpc_samr_SetUserInfo2(b, talloc_tos(),
    314321                                                  user_handle,
    315322                                                  25,
    316                                                   &user_info);
    317 
    318                 if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) {
     323                                                  &user_info,
     324                                                  &result);
     325                if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE)) {
    319326
    320327                        user_info.info23.info = info21;
     
    324331                                                &user_info.info23.password);
    325332
    326                         status = rpccli_samr_SetUserInfo2(pipe_cli, talloc_tos(),
     333                        status = dcerpc_samr_SetUserInfo2(b, talloc_tos(),
    327334                                                          user_handle,
    328335                                                          23,
    329                                                           &user_info);
     336                                                          &user_info,
     337                                                          &result);
     338                        if (!NT_STATUS_IS_OK(status)) {
     339                                return status;
     340                        }
     341                }
     342
     343                if (!NT_STATUS_IS_OK(status)) {
     344                        return status;
    330345                }
    331346        } else {
     
    333348                user_info.info21 = info21;
    334349
    335                 status = rpccli_samr_SetUserInfo(pipe_cli, talloc_tos(),
     350                status = dcerpc_samr_SetUserInfo(b, talloc_tos(),
    336351                                                 user_handle,
    337352                                                 21,
    338                                                  &user_info);
    339         }
    340 
    341         return status;
     353                                                 &user_info,
     354                                                 &result);
     355                if (!NT_STATUS_IS_OK(status)) {
     356                        return status;
     357                }
     358        }
     359
     360        return result;
    342361}
    343362
     
    349368{
    350369        struct rpc_pipe_client *pipe_cli = NULL;
    351         NTSTATUS status;
     370        NTSTATUS status, result;
    352371        WERROR werr;
    353372        struct policy_handle connect_handle, domain_handle, user_handle;
     
    359378        uint32_t rid = 0;
    360379        struct USER_INFO_X uX;
     380        struct dcerpc_binding_handle *b = NULL;
     381        DATA_BLOB session_key;
    361382
    362383        ZERO_STRUCT(connect_handle);
     
    385406                goto done;
    386407        }
     408
     409        b = pipe_cli->binding_handle;
    387410
    388411        status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX);
     
    407430        init_lsa_String(&lsa_account_name, uX.usriX_name);
    408431
    409         status = rpccli_samr_CreateUser2(pipe_cli, talloc_tos(),
     432        status = dcerpc_samr_CreateUser2(b, talloc_tos(),
    410433                                         &domain_handle,
    411434                                         &lsa_account_name,
     
    418441                                         &user_handle,
    419442                                         &access_granted,
    420                                          &rid);
     443                                         &rid,
     444                                         &result);
    421445        if (!NT_STATUS_IS_OK(status)) {
    422446                werr = ntstatus_to_werror(status);
    423447                goto done;
    424448        }
    425 
    426         status = rpccli_samr_QueryUserInfo(pipe_cli, talloc_tos(),
     449        if (!NT_STATUS_IS_OK(result)) {
     450                werr = ntstatus_to_werror(result);
     451                goto done;
     452        }
     453
     454        status = dcerpc_samr_QueryUserInfo(b, talloc_tos(),
    427455                                           &user_handle,
    428456                                           16,
    429                                            &user_info);
     457                                           &user_info,
     458                                           &result);
    430459        if (!NT_STATUS_IS_OK(status)) {
    431460                werr = ntstatus_to_werror(status);
     461                goto done;
     462        }
     463        if (!NT_STATUS_IS_OK(result)) {
     464                werr = ntstatus_to_werror(result);
    432465                goto done;
    433466        }
     
    438471        }
    439472
    440         status = rpccli_samr_GetUserPwInfo(pipe_cli, talloc_tos(),
     473        status = dcerpc_samr_GetUserPwInfo(b, talloc_tos(),
    441474                                           &user_handle,
    442                                            &pw_info);
     475                                           &pw_info,
     476                                           &result);
    443477        if (!NT_STATUS_IS_OK(status)) {
    444478                werr = ntstatus_to_werror(status);
    445479                goto done;
    446480        }
     481        if (!NT_STATUS_IS_OK(result)) {
     482                werr = ntstatus_to_werror(result);
     483                goto done;
     484        }
     485
     486        status = cli_get_session_key(talloc_tos(), pipe_cli, &session_key);
     487        if (!NT_STATUS_IS_OK(status)) {
     488                werr = ntstatus_to_werror(status);
     489                goto done;
     490        }
    447491
    448492        uX.usriX_flags |= ACB_NORMAL;
    449493
    450494        status = set_user_info_USER_INFO_X(ctx, pipe_cli,
    451                                            &pipe_cli->auth->user_session_key,
     495                                           &session_key,
    452496                                           &user_handle,
    453497                                           &uX);
     
    461505
    462506 failed:
    463         rpccli_samr_DeleteUser(pipe_cli, talloc_tos(),
    464                                &user_handle);
     507        dcerpc_samr_DeleteUser(b, talloc_tos(),
     508                               &user_handle,
     509                               &result);
    465510
    466511 done:
    467         if (is_valid_policy_hnd(&user_handle) && pipe_cli) {
    468                 rpccli_samr_Close(pipe_cli, talloc_tos(), &user_handle);
     512        if (is_valid_policy_hnd(&user_handle) && b) {
     513                dcerpc_samr_Close(b, talloc_tos(), &user_handle, &result);
    469514        }
    470515
     
    493538{
    494539        struct rpc_pipe_client *pipe_cli = NULL;
    495         NTSTATUS status;
     540        NTSTATUS status, result;
    496541        WERROR werr;
    497542        struct policy_handle connect_handle, builtin_handle, domain_handle, user_handle;
     
    500545        struct dom_sid2 *domain_sid = NULL;
    501546        struct dom_sid2 user_sid;
     547        struct dcerpc_binding_handle *b = NULL;
    502548
    503549        ZERO_STRUCT(connect_handle);
     
    513559                goto done;
    514560        }
     561
     562        b = pipe_cli->binding_handle;
    515563
    516564        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    525573        }
    526574
    527         status = rpccli_samr_OpenDomain(pipe_cli, talloc_tos(),
     575        status = dcerpc_samr_OpenDomain(b, talloc_tos(),
    528576                                        &connect_handle,
    529577                                        SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
    530                                         CONST_DISCARD(DOM_SID *, &global_sid_Builtin),
    531                                         &builtin_handle);
     578                                        CONST_DISCARD(struct dom_sid *, &global_sid_Builtin),
     579                                        &builtin_handle,
     580                                        &result);
    532581        if (!NT_STATUS_IS_OK(status)) {
    533582                werr = ntstatus_to_werror(status);
    534583                goto done;
    535584        }
     585        if (!NT_STATUS_IS_OK(result)) {
     586                werr = ntstatus_to_werror(result);
     587                goto done;
     588        }
    536589
    537590        init_lsa_String(&lsa_account_name, r->in.user_name);
    538591
    539         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     592        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    540593                                         &domain_handle,
    541594                                         1,
    542595                                         &lsa_account_name,
    543596                                         &user_rids,
    544                                          &name_types);
     597                                         &name_types,
     598                                         &result);
    545599        if (!NT_STATUS_IS_OK(status)) {
    546600                werr = ntstatus_to_werror(status);
    547601                goto done;
    548602        }
    549 
    550         status = rpccli_samr_OpenUser(pipe_cli, talloc_tos(),
     603        if (!NT_STATUS_IS_OK(result)) {
     604                werr = ntstatus_to_werror(result);
     605                goto done;
     606        }
     607
     608        status = dcerpc_samr_OpenUser(b, talloc_tos(),
    551609                                      &domain_handle,
    552610                                      SEC_STD_DELETE,
    553611                                      user_rids.ids[0],
    554                                       &user_handle);
     612                                      &user_handle,
     613                                      &result);
    555614        if (!NT_STATUS_IS_OK(status)) {
    556615                werr = ntstatus_to_werror(status);
    557616                goto done;
    558617        }
     618        if (!NT_STATUS_IS_OK(result)) {
     619                werr = ntstatus_to_werror(result);
     620                goto done;
     621        }
    559622
    560623        sid_compose(&user_sid, domain_sid, user_rids.ids[0]);
    561624
    562         status = rpccli_samr_RemoveMemberFromForeignDomain(pipe_cli, talloc_tos(),
     625        status = dcerpc_samr_RemoveMemberFromForeignDomain(b, talloc_tos(),
    563626                                                           &builtin_handle,
    564                                                            &user_sid);
     627                                                           &user_sid,
     628                                                           &result);
    565629        if (!NT_STATUS_IS_OK(status)) {
    566630                werr = ntstatus_to_werror(status);
    567631                goto done;
    568632        }
    569 
    570         status = rpccli_samr_DeleteUser(pipe_cli, talloc_tos(),
    571                                         &user_handle);
     633        if (!NT_STATUS_IS_OK(result)) {
     634                werr = ntstatus_to_werror(result);
     635                goto done;
     636        }
     637
     638        status = dcerpc_samr_DeleteUser(b, talloc_tos(),
     639                                        &user_handle,
     640                                        &result);
    572641        if (!NT_STATUS_IS_OK(status)) {
    573642                werr = ntstatus_to_werror(status);
     643                goto done;
     644        }
     645        if (!NT_STATUS_IS_OK(result)) {
     646                werr = ntstatus_to_werror(result);
    574647                goto done;
    575648        }
     
    579652 done:
    580653        if (is_valid_policy_hnd(&user_handle)) {
    581                 rpccli_samr_Close(pipe_cli, talloc_tos(), &user_handle);
     654                dcerpc_samr_Close(b, talloc_tos(), &user_handle, &result);
    582655        }
    583656
     
    615688                                           uint32_t *auth_flag_p)
    616689{
    617         NTSTATUS status;
     690        NTSTATUS status, result;
    618691
    619692        struct policy_handle user_handle;
     
    623696                               SAMR_USER_ACCESS_GET_ATTRIBUTES |
    624697                               SAMR_USER_ACCESS_GET_NAME_ETC;
     698        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    625699
    626700        ZERO_STRUCT(user_handle);
     
    653727        }
    654728
    655         status = rpccli_samr_OpenUser(pipe_cli, mem_ctx,
     729        status = dcerpc_samr_OpenUser(b, mem_ctx,
    656730                                      domain_handle,
    657731                                      access_mask,
    658732                                      rid,
    659                                       &user_handle);
    660         if (!NT_STATUS_IS_OK(status)) {
    661                 goto done;
    662         }
    663 
    664         status = rpccli_samr_QueryUserInfo(pipe_cli, mem_ctx,
     733                                      &user_handle,
     734                                      &result);
     735        if (!NT_STATUS_IS_OK(status)) {
     736                goto done;
     737        }
     738        if (!NT_STATUS_IS_OK(result)) {
     739                status = result;
     740                goto done;
     741        }
     742
     743        status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
    665744                                           &user_handle,
    666745                                           21,
    667                                            &user_info);
    668         if (!NT_STATUS_IS_OK(status)) {
    669                 goto done;
    670         }
    671 
    672         status = rpccli_samr_QuerySecurity(pipe_cli, mem_ctx,
     746                                           &user_info,
     747                                           &result);
     748        if (!NT_STATUS_IS_OK(status)) {
     749                goto done;
     750        }
     751        if (!NT_STATUS_IS_OK(result)) {
     752                status = result;
     753                goto done;
     754        }
     755
     756        status = dcerpc_samr_QuerySecurity(b, mem_ctx,
    673757                                           &user_handle,
    674758                                           SECINFO_DACL,
    675                                            sec_desc);
    676         if (!NT_STATUS_IS_OK(status)) {
     759                                           sec_desc,
     760                                           &result);
     761        if (!NT_STATUS_IS_OK(status)) {
     762                goto done;
     763        }
     764        if (!NT_STATUS_IS_OK(result)) {
     765                status = result;
    677766                goto done;
    678767        }
     
    686775                struct dom_sid sid;
    687776
    688                 status = rpccli_samr_GetGroupsForUser(pipe_cli, mem_ctx,
     777                status = dcerpc_samr_GetGroupsForUser(b, mem_ctx,
    689778                                                      &user_handle,
    690                                                       &rid_array);
     779                                                      &rid_array,
     780                                                      &result);
    691781                if (!NT_STATUS_IS_OK(status)) {
     782                        goto done;
     783                }
     784                if (!NT_STATUS_IS_OK(result)) {
     785                        status = result;
    692786                        goto done;
    693787                }
     
    700794                for (i=0; i<rid_array->count; i++) {
    701795                        sid_compose(&sid, domain_sid, rid_array->rids[i].rid);
    702                         sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sid);
     796                        sid_array.sids[i].sid = dom_sid_dup(mem_ctx, &sid);
    703797                        NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid);
    704798                }
    705799
    706800                sid_compose(&sid, domain_sid, rid);
    707                 sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sid);
     801                sid_array.sids[i].sid = dom_sid_dup(mem_ctx, &sid);
    708802                NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid);
    709803
    710                 status = rpccli_samr_GetAliasMembership(pipe_cli, mem_ctx,
     804                status = dcerpc_samr_GetAliasMembership(b, mem_ctx,
    711805                                                        builtin_handle,
    712806                                                        &sid_array,
    713                                                         &alias_rids);
     807                                                        &alias_rids,
     808                                                        &result);
    714809                if (!NT_STATUS_IS_OK(status)) {
     810                        goto done;
     811                }
     812                if (!NT_STATUS_IS_OK(result)) {
     813                        status = result;
    715814                        goto done;
    716815                }
     
    741840 done:
    742841        if (is_valid_policy_hnd(&user_handle)) {
    743                 rpccli_samr_Close(pipe_cli, mem_ctx, &user_handle);
     842                dcerpc_samr_Close(b, mem_ctx, &user_handle, &result);
    744843        }
    745844
     
    9181017                return NT_STATUS_NO_MEMORY;
    9191018        }
    920         i->usri4_user_sid       = (struct domsid *)sid_dup_talloc(mem_ctx, &sid);
     1019        i->usri4_user_sid       = (struct domsid *)dom_sid_dup(mem_ctx, &sid);
    9211020        i->usri4_primary_group_id = i21->primary_gid;
    9221021        i->usri4_profile        = talloc_strdup(mem_ctx, i21->profile_path.string);
     
    10191118                return NT_STATUS_NO_MEMORY;
    10201119        }
    1021         i->usri23_user_sid      = (struct domsid *)sid_dup_talloc(mem_ctx, &sid);
     1120        i->usri23_user_sid      = (struct domsid *)dom_sid_dup(mem_ctx, &sid);
    10221121
    10231122        return NT_STATUS_OK;
     
    11851284
    11861285        NTSTATUS status = NT_STATUS_OK;
     1286        NTSTATUS result = NT_STATUS_OK;
    11871287        WERROR werr;
     1288        struct dcerpc_binding_handle *b = NULL;
    11881289
    11891290        ZERO_STRUCT(connect_handle);
     
    12201321        }
    12211322
     1323        b = pipe_cli->binding_handle;
     1324
    12221325        werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
    12231326                                                  SAMR_ACCESS_ENUM_DOMAINS |
     
    12641367        }
    12651368
    1266         status = rpccli_samr_EnumDomainUsers(pipe_cli,
     1369        status = dcerpc_samr_EnumDomainUsers(b,
    12671370                                             ctx,
    12681371                                             &domain_handle,
     
    12711374                                             &sam,
    12721375                                             r->in.prefmaxlen,
    1273                                              &entries_read);
    1274         werr = ntstatus_to_werror(status);
    1275         if (NT_STATUS_IS_ERR(status)) {
     1376                                             &entries_read,
     1377                                             &result);
     1378        if (!NT_STATUS_IS_OK(status)) {
     1379                werr = ntstatus_to_werror(status);
     1380                goto done;
     1381        }
     1382        werr = ntstatus_to_werror(result);
     1383        if (NT_STATUS_IS_ERR(result)) {
    12761384                goto done;
    12771385        }
     
    12961404 done:
    12971405        /* if last query */
    1298         if (NT_STATUS_IS_OK(status) ||
    1299             NT_STATUS_IS_ERR(status)) {
     1406        if (NT_STATUS_IS_OK(result) ||
     1407            NT_STATUS_IS_ERR(result)) {
    13001408
    13011409                if (ctx->disable_policy_handle_cache) {
     
    14901598        struct policy_handle domain_handle;
    14911599        union samr_DispInfo info;
     1600        struct dcerpc_binding_handle *b = NULL;
    14921601
    14931602        uint32_t total_size = 0;
     
    14951604
    14961605        NTSTATUS status = NT_STATUS_OK;
     1606        NTSTATUS result = NT_STATUS_OK;
    14971607        WERROR werr;
    14981608        WERROR werr_tmp;
     
    15181628                goto done;
    15191629        }
     1630
     1631        b = pipe_cli->binding_handle;
    15201632
    15211633        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    15321644        }
    15331645
    1534         status = rpccli_samr_QueryDisplayInfo2(pipe_cli,
     1646        status = dcerpc_samr_QueryDisplayInfo2(b,
    15351647                                               ctx,
    15361648                                               &domain_handle,
     
    15411653                                               &total_size,
    15421654                                               &returned_size,
    1543                                                &info);
    1544         werr = ntstatus_to_werror(status);
    1545         if (NT_STATUS_IS_ERR(status)) {
     1655                                               &info,
     1656                                               &result);
     1657        if (!NT_STATUS_IS_OK(status)) {
     1658                werr = ntstatus_to_werror(status);
     1659                goto done;
     1660        }
     1661        werr = ntstatus_to_werror(result);
     1662        if (NT_STATUS_IS_ERR(result)) {
    15461663                goto done;
    15471664        }
     
    15561673 done:
    15571674        /* if last query */
    1558         if (NT_STATUS_IS_OK(status) ||
    1559             NT_STATUS_IS_ERR(status)) {
     1675        if (NT_STATUS_IS_OK(result) ||
     1676            NT_STATUS_IS_ERR(result)) {
    15601677
    15611678                if (ctx->disable_policy_handle_cache) {
     
    16041721{
    16051722        struct rpc_pipe_client *pipe_cli = NULL;
    1606         NTSTATUS status;
     1723        NTSTATUS status, result;
    16071724        WERROR werr;
    16081725
     
    16121729        struct samr_Ids user_rids, name_types;
    16131730        uint32_t num_entries = 0;
     1731        struct dcerpc_binding_handle *b = NULL;
    16141732
    16151733        ZERO_STRUCT(connect_handle);
     
    16451763        }
    16461764
     1765        b = pipe_cli->binding_handle;
     1766
    16471767        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
    16481768                                          SAMR_ACCESS_ENUM_DOMAINS |
     
    16691789        init_lsa_String(&lsa_account_name, r->in.user_name);
    16701790
    1671         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1791        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    16721792                                         &domain_handle,
    16731793                                         1,
    16741794                                         &lsa_account_name,
    16751795                                         &user_rids,
    1676                                          &name_types);
     1796                                         &name_types,
     1797                                         &result);
    16771798        if (!NT_STATUS_IS_OK(status)) {
    16781799                werr = ntstatus_to_werror(status);
     1800                goto done;
     1801        }
     1802        if (!NT_STATUS_IS_OK(result)) {
     1803                werr = ntstatus_to_werror(result);
    16791804                goto done;
    16801805        }
     
    16951820
    16961821 done:
    1697         if (is_valid_policy_hnd(&user_handle) && pipe_cli) {
    1698                 rpccli_samr_Close(pipe_cli, talloc_tos(), &user_handle);
     1822        if (is_valid_policy_hnd(&user_handle) && b) {
     1823                dcerpc_samr_Close(b, talloc_tos(), &user_handle, &result);
    16991824        }
    17001825
     
    17231848{
    17241849        struct rpc_pipe_client *pipe_cli = NULL;
    1725         NTSTATUS status;
     1850        NTSTATUS status, result;
    17261851        WERROR werr;
    17271852
     
    17331858
    17341859        struct USER_INFO_X uX;
     1860        struct dcerpc_binding_handle *b = NULL;
     1861        DATA_BLOB session_key;
    17351862
    17361863        ZERO_STRUCT(connect_handle);
     
    17671894                        break;
    17681895                case 3:
    1769                         user_mask = STD_RIGHT_READ_CONTROL_ACCESS |
    1770                                     STD_RIGHT_WRITE_DAC_ACCESS |
     1896                        user_mask = SEC_STD_READ_CONTROL |
     1897                                    SEC_STD_WRITE_DAC |
    17711898                                    SAMR_USER_ACCESS_GET_GROUPS |
    17721899                                    SAMR_USER_ACCESS_SET_PASSWORD |
     
    17991926        }
    18001927
     1928        b = pipe_cli->binding_handle;
     1929
    18011930        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
    18021931                                          SAMR_ACCESS_ENUM_DOMAINS |
     
    18241953        init_lsa_String(&lsa_account_name, r->in.user_name);
    18251954
    1826         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     1955        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    18271956                                         &domain_handle,
    18281957                                         1,
    18291958                                         &lsa_account_name,
    18301959                                         &user_rids,
    1831                                          &name_types);
     1960                                         &name_types,
     1961                                         &result);
    18321962        if (!NT_STATUS_IS_OK(status)) {
    18331963                werr = ntstatus_to_werror(status);
    18341964                goto done;
    18351965        }
    1836 
    1837         status = rpccli_samr_OpenUser(pipe_cli, talloc_tos(),
     1966        if (!NT_STATUS_IS_OK(result)) {
     1967                werr = ntstatus_to_werror(result);
     1968                goto done;
     1969        }
     1970
     1971        status = dcerpc_samr_OpenUser(b, talloc_tos(),
    18381972                                      &domain_handle,
    18391973                                      user_mask,
    18401974                                      user_rids.ids[0],
    1841                                       &user_handle);
     1975                                      &user_handle,
     1976                                      &result);
    18421977        if (!NT_STATUS_IS_OK(status)) {
    18431978                werr = ntstatus_to_werror(status);
    18441979                goto done;
    18451980        }
     1981        if (!NT_STATUS_IS_OK(result)) {
     1982                werr = ntstatus_to_werror(result);
     1983                goto done;
     1984        }
    18461985
    18471986        status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX);
     
    18511990        }
    18521991
     1992        status = cli_get_session_key(talloc_tos(), pipe_cli, &session_key);
     1993        if (!NT_STATUS_IS_OK(status)) {
     1994                werr = ntstatus_to_werror(status);
     1995                goto done;
     1996        }
     1997
    18531998        status = set_user_info_USER_INFO_X(ctx, pipe_cli,
    1854                                            &pipe_cli->auth->user_session_key,
     1999                                           &session_key,
    18552000                                           &user_handle,
    18562001                                           &uX);
     
    18632008
    18642009 done:
    1865         if (is_valid_policy_hnd(&user_handle) && pipe_cli) {
    1866                 rpccli_samr_Close(pipe_cli, talloc_tos(), &user_handle);
     2010        if (is_valid_policy_hnd(&user_handle) && b) {
     2011                dcerpc_samr_Close(b, talloc_tos(), &user_handle, &result);
    18672012        }
    18682013
     
    18982043                                           struct samr_DomInfo12 *info12)
    18992044{
    1900         NTSTATUS status;
     2045        NTSTATUS status, result;
    19012046        union samr_DomainInfo *dom_info = NULL;
     2047        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    19022048
    19032049        if (info1) {
    1904                 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
     2050                status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    19052051                                                     domain_handle,
    19062052                                                     1,
    1907                                                      &dom_info);
     2053                                                     &dom_info,
     2054                                                     &result);
    19082055                NT_STATUS_NOT_OK_RETURN(status);
     2056                NT_STATUS_NOT_OK_RETURN(result);
    19092057
    19102058                *info1 = dom_info->info1;
     
    19122060
    19132061        if (info3) {
    1914                 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
     2062                status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    19152063                                                     domain_handle,
    19162064                                                     3,
    1917                                                      &dom_info);
     2065                                                     &dom_info,
     2066                                                     &result);
    19182067                NT_STATUS_NOT_OK_RETURN(status);
     2068                NT_STATUS_NOT_OK_RETURN(result);
    19192069
    19202070                *info3 = dom_info->info3;
     
    19222072
    19232073        if (info5) {
    1924                 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
     2074                status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    19252075                                                     domain_handle,
    19262076                                                     5,
    1927                                                      &dom_info);
     2077                                                     &dom_info,
     2078                                                     &result);
    19282079                NT_STATUS_NOT_OK_RETURN(status);
     2080                NT_STATUS_NOT_OK_RETURN(result);
    19292081
    19302082                *info5 = dom_info->info5;
     
    19322084
    19332085        if (info6) {
    1934                 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
     2086                status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    19352087                                                     domain_handle,
    19362088                                                     6,
    1937                                                      &dom_info);
     2089                                                     &dom_info,
     2090                                                     &result);
    19382091                NT_STATUS_NOT_OK_RETURN(status);
     2092                NT_STATUS_NOT_OK_RETURN(result);
    19392093
    19402094                *info6 = dom_info->info6;
     
    19422096
    19432097        if (info7) {
    1944                 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
     2098                status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
    19452099                                                     domain_handle,
    19462100                                                     7,
    1947                                                      &dom_info);
     2101                                                     &dom_info,
     2102                                                     &result);
    19482103                NT_STATUS_NOT_OK_RETURN(status);
     2104                NT_STATUS_NOT_OK_RETURN(result);
    19492105
    19502106                *info7 = dom_info->info7;
     
    19522108
    19532109        if (info12) {
    1954                 status = rpccli_samr_QueryDomainInfo2(pipe_cli, mem_ctx,
     2110                status = dcerpc_samr_QueryDomainInfo2(b, mem_ctx,
    19552111                                                      domain_handle,
    19562112                                                      12,
    1957                                                       &dom_info);
     2113                                                      &dom_info,
     2114                                                      &result);
    19582115                NT_STATUS_NOT_OK_RETURN(status);
     2116                NT_STATUS_NOT_OK_RETURN(result);
    19592117
    19602118                *info12 = dom_info->info12;
     
    20612219                talloc_strdup(mem_ctx, dom_info5.domain_name.string);
    20622220        info2->usrmod2_domain_id =
    2063                 (struct domsid *)sid_dup_talloc(mem_ctx, domain_sid);
     2221                (struct domsid *)dom_sid_dup(mem_ctx, domain_sid);
    20642222
    20652223        NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_name);
     
    22742432                                         struct samr_DomInfo12 *info12)
    22752433{
    2276         NTSTATUS status;
     2434        NTSTATUS status, result;
    22772435        union samr_DomainInfo dom_info;
     2436        struct dcerpc_binding_handle *b = pipe_cli->binding_handle;
    22782437
    22792438        if (info1) {
     
    22832442                dom_info.info1 = *info1;
    22842443
    2285                 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,
     2444                status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
    22862445                                                   domain_handle,
    22872446                                                   1,
    2288                                                    &dom_info);
     2447                                                   &dom_info,
     2448                                                   &result);
    22892449                NT_STATUS_NOT_OK_RETURN(status);
     2450                NT_STATUS_NOT_OK_RETURN(result);
    22902451        }
    22912452
     
    22962457                dom_info.info3 = *info3;
    22972458
    2298                 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,
     2459                status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
    22992460                                                   domain_handle,
    23002461                                                   3,
    2301                                                    &dom_info);
     2462                                                   &dom_info,
     2463                                                   &result);
    23022464
    23032465                NT_STATUS_NOT_OK_RETURN(status);
     2466                NT_STATUS_NOT_OK_RETURN(result);
    23042467        }
    23052468
     
    23102473                dom_info.info12 = *info12;
    23112474
    2312                 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,
     2475                status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
    23132476                                                   domain_handle,
    23142477                                                   12,
    2315                                                    &dom_info);
     2478                                                   &dom_info,
     2479                                                   &result);
    23162480
    23172481                NT_STATUS_NOT_OK_RETURN(status);
     2482                NT_STATUS_NOT_OK_RETURN(result);
    23182483        }
    23192484
     
    28022967
    28032968        NTSTATUS status = NT_STATUS_OK;
     2969        NTSTATUS result = NT_STATUS_OK;
    28042970        WERROR werr;
     2971        struct dcerpc_binding_handle *b = NULL;
    28052972
    28062973        ZERO_STRUCT(connect_handle);
     
    28292996                goto done;
    28302997        }
     2998
     2999        b = pipe_cli->binding_handle;
    28313000
    28323001        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    28433012        init_lsa_String(&lsa_account_name, r->in.user_name);
    28443013
    2845         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     3014        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    28463015                                         &domain_handle,
    28473016                                         1,
    28483017                                         &lsa_account_name,
    28493018                                         &user_rids,
    2850                                          &name_types);
     3019                                         &name_types,
     3020                                         &result);
    28513021        if (!NT_STATUS_IS_OK(status)) {
    28523022                werr = ntstatus_to_werror(status);
    28533023                goto done;
    28543024        }
    2855 
    2856         status = rpccli_samr_OpenUser(pipe_cli, talloc_tos(),
     3025        if (!NT_STATUS_IS_OK(result)) {
     3026                werr = ntstatus_to_werror(result);
     3027                goto done;
     3028        }
     3029
     3030        status = dcerpc_samr_OpenUser(b, talloc_tos(),
    28573031                                      &domain_handle,
    28583032                                      SAMR_USER_ACCESS_GET_GROUPS,
    28593033                                      user_rids.ids[0],
    2860                                       &user_handle);
     3034                                      &user_handle,
     3035                                      &result);
    28613036        if (!NT_STATUS_IS_OK(status)) {
    28623037                werr = ntstatus_to_werror(status);
    28633038                goto done;
    28643039        }
    2865 
    2866         status = rpccli_samr_GetGroupsForUser(pipe_cli, talloc_tos(),
     3040        if (!NT_STATUS_IS_OK(result)) {
     3041                werr = ntstatus_to_werror(result);
     3042                goto done;
     3043        }
     3044
     3045        status = dcerpc_samr_GetGroupsForUser(b, talloc_tos(),
    28673046                                              &user_handle,
    2868                                               &rid_array);
     3047                                              &rid_array,
     3048                                              &result);
    28693049        if (!NT_STATUS_IS_OK(status)) {
    28703050                werr = ntstatus_to_werror(status);
     3051                goto done;
     3052        }
     3053        if (!NT_STATUS_IS_OK(result)) {
     3054                werr = ntstatus_to_werror(result);
    28713055                goto done;
    28723056        }
     
    28823066        }
    28833067
    2884         status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),
     3068        status = dcerpc_samr_LookupRids(b, talloc_tos(),
    28853069                                        &domain_handle,
    28863070                                        rid_array->count,
    28873071                                        rids,
    28883072                                        &names,
    2889                                         &types);
    2890         if (!NT_STATUS_IS_OK(status) &&
    2891             !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
     3073                                        &types,
     3074                                        &result);
     3075        if (!NT_STATUS_IS_OK(status)) {
    28923076                werr = ntstatus_to_werror(status);
     3077                goto done;
     3078        }
     3079        if (!NT_STATUS_IS_OK(result) &&
     3080            !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
     3081                werr = ntstatus_to_werror(result);
    28933082                goto done;
    28943083        }
     
    29573146
    29583147        NTSTATUS status = NT_STATUS_OK;
     3148        NTSTATUS result = NT_STATUS_OK;
    29593149        WERROR werr;
     3150        struct dcerpc_binding_handle *b = NULL;
    29603151
    29613152        ZERO_STRUCT(connect_handle);
     
    29803171                goto done;
    29813172        }
     3173
     3174        b = pipe_cli->binding_handle;
    29823175
    29833176        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    29943187        init_lsa_String(&lsa_account_name, r->in.user_name);
    29953188
    2996         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     3189        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    29973190                                         &domain_handle,
    29983191                                         1,
    29993192                                         &lsa_account_name,
    30003193                                         &user_rids,
    3001                                          &name_types);
     3194                                         &name_types,
     3195                                         &result);
    30023196        if (!NT_STATUS_IS_OK(status)) {
    30033197                werr = ntstatus_to_werror(status);
    30043198                goto done;
    30053199        }
    3006 
    3007         status = rpccli_samr_OpenUser(pipe_cli, talloc_tos(),
     3200        if (!NT_STATUS_IS_OK(result)) {
     3201                werr = ntstatus_to_werror(result);
     3202                goto done;
     3203        }
     3204
     3205        status = dcerpc_samr_OpenUser(b, talloc_tos(),
    30083206                                      &domain_handle,
    30093207                                      SAMR_USER_ACCESS_GET_GROUPS,
    30103208                                      user_rids.ids[0],
    3011                                       &user_handle);
     3209                                      &user_handle,
     3210                                      &result);
    30123211        if (!NT_STATUS_IS_OK(status)) {
    30133212                werr = ntstatus_to_werror(status);
     3213                goto done;
     3214        }
     3215        if (!NT_STATUS_IS_OK(result)) {
     3216                werr = ntstatus_to_werror(result);
    30143217                goto done;
    30153218        }
     
    30443247        }
    30453248
    3046         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     3249        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    30473250                                         &domain_handle,
    30483251                                         r->in.num_entries,
    30493252                                         lsa_names,
    30503253                                         &group_rids,
    3051                                          &name_types);
     3254                                         &name_types,
     3255                                         &result);
    30523256        if (!NT_STATUS_IS_OK(status)) {
    30533257                werr = ntstatus_to_werror(status);
     3258                goto done;
     3259        }
     3260        if (!NT_STATUS_IS_OK(result)) {
     3261                werr = ntstatus_to_werror(result);
    30543262                goto done;
    30553263        }
     
    30583266        num_member_rids = group_rids.count;
    30593267
    3060         status = rpccli_samr_GetGroupsForUser(pipe_cli, talloc_tos(),
     3268        status = dcerpc_samr_GetGroupsForUser(b, talloc_tos(),
    30613269                                              &user_handle,
    3062                                               &rid_array);
     3270                                              &rid_array,
     3271                                              &result);
    30633272        if (!NT_STATUS_IS_OK(status)) {
    30643273                werr = ntstatus_to_werror(status);
     3274                goto done;
     3275        }
     3276        if (!NT_STATUS_IS_OK(result)) {
     3277                werr = ntstatus_to_werror(result);
    30653278                goto done;
    30663279        }
     
    31093322
    31103323        for (i=0; i < num_add_rids; i++) {
    3111                 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     3324                status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    31123325                                               &domain_handle,
    31133326                                               SAMR_GROUP_ACCESS_ADD_MEMBER,
    31143327                                               add_rids[i],
    3115                                                &group_handle);
     3328                                               &group_handle,
     3329                                               &result);
    31163330                if (!NT_STATUS_IS_OK(status)) {
    31173331                        werr = ntstatus_to_werror(status);
    31183332                        goto done;
    31193333                }
    3120 
    3121                 status = rpccli_samr_AddGroupMember(pipe_cli, talloc_tos(),
     3334                if (!NT_STATUS_IS_OK(result)) {
     3335                        werr = ntstatus_to_werror(result);
     3336                        goto done;
     3337                }
     3338
     3339                status = dcerpc_samr_AddGroupMember(b, talloc_tos(),
    31223340                                                    &group_handle,
    31233341                                                    user_rids.ids[0],
    3124                                                     7 /* ? */);
     3342                                                    7 /* ? */,
     3343                                                    &result);
    31253344                if (!NT_STATUS_IS_OK(status)) {
    31263345                        werr = ntstatus_to_werror(status);
    31273346                        goto done;
    31283347                }
     3348                if (!NT_STATUS_IS_OK(result)) {
     3349                        werr = ntstatus_to_werror(result);
     3350                        goto done;
     3351                }
    31293352
    31303353                if (is_valid_policy_hnd(&group_handle)) {
    3131                         rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     3354                        dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    31323355                }
    31333356        }
     
    31363359
    31373360        for (i=0; i < num_del_rids; i++) {
    3138                 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),
     3361                status = dcerpc_samr_OpenGroup(b, talloc_tos(),
    31393362                                               &domain_handle,
    31403363                                               SAMR_GROUP_ACCESS_REMOVE_MEMBER,
    31413364                                               del_rids[i],
    3142                                                &group_handle);
     3365                                               &group_handle,
     3366                                               &result);
    31433367                if (!NT_STATUS_IS_OK(status)) {
    31443368                        werr = ntstatus_to_werror(status);
    31453369                        goto done;
    31463370                }
    3147 
    3148                 status = rpccli_samr_DeleteGroupMember(pipe_cli, talloc_tos(),
     3371                if (!NT_STATUS_IS_OK(result)) {
     3372                        werr = ntstatus_to_werror(result);
     3373                        goto done;
     3374                }
     3375
     3376                status = dcerpc_samr_DeleteGroupMember(b, talloc_tos(),
    31493377                                                       &group_handle,
    3150                                                        user_rids.ids[0]);
     3378                                                       user_rids.ids[0],
     3379                                                       &result);
    31513380                if (!NT_STATUS_IS_OK(status)) {
    31523381                        werr = ntstatus_to_werror(status);
    31533382                        goto done;
    31543383                }
     3384                if (!NT_STATUS_IS_OK(result)) {
     3385                        werr = ntstatus_to_werror(result);
     3386                        goto done;
     3387                }
    31553388
    31563389                if (is_valid_policy_hnd(&group_handle)) {
    3157                         rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     3390                        dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    31583391                }
    31593392        }
     
    31633396 done:
    31643397        if (is_valid_policy_hnd(&group_handle)) {
    3165                 rpccli_samr_Close(pipe_cli, talloc_tos(), &group_handle);
     3398                dcerpc_samr_Close(b, talloc_tos(), &group_handle, &result);
    31663399        }
    31673400
     
    32353468
    32363469        NTSTATUS status = NT_STATUS_OK;
     3470        NTSTATUS result = NT_STATUS_OK;
    32373471        WERROR werr;
     3472        struct dcerpc_binding_handle *b = NULL;
    32383473
    32393474        ZERO_STRUCT(connect_handle);
     
    32623497                goto done;
    32633498        }
     3499
     3500        b = pipe_cli->binding_handle;
    32643501
    32653502        werr = libnetapi_samr_open_domain(ctx, pipe_cli,
     
    32883525        init_lsa_String(&lsa_account_name, r->in.user_name);
    32893526
    3290         status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),
     3527        status = dcerpc_samr_LookupNames(b, talloc_tos(),
    32913528                                         &domain_handle,
    32923529                                         1,
    32933530                                         &lsa_account_name,
    32943531                                         &user_rids,
    3295                                          &name_types);
     3532                                         &name_types,
     3533                                         &result);
    32963534        if (!NT_STATUS_IS_OK(status)) {
    32973535                werr = ntstatus_to_werror(status);
    32983536                goto done;
    32993537        }
    3300 
    3301         status = rpccli_samr_OpenUser(pipe_cli, talloc_tos(),
     3538        if (!NT_STATUS_IS_OK(result)) {
     3539                werr = ntstatus_to_werror(result);
     3540                goto done;
     3541        }
     3542
     3543        status = dcerpc_samr_OpenUser(b, talloc_tos(),
    33023544                                      &domain_handle,
    33033545                                      SAMR_USER_ACCESS_GET_GROUPS,
    33043546                                      user_rids.ids[0],
    3305                                       &user_handle);
     3547                                      &user_handle,
     3548                                      &result);
    33063549        if (!NT_STATUS_IS_OK(status)) {
    33073550                werr = ntstatus_to_werror(status);
    33083551                goto done;
    33093552        }
    3310 
    3311         status = rpccli_samr_GetGroupsForUser(pipe_cli, talloc_tos(),
     3553        if (!NT_STATUS_IS_OK(result)) {
     3554                werr = ntstatus_to_werror(result);
     3555                goto done;
     3556        }
     3557
     3558        status = dcerpc_samr_GetGroupsForUser(b, talloc_tos(),
    33123559                                              &user_handle,
    3313                                               &rid_array);
     3560                                              &rid_array,
     3561                                              &result);
    33143562        if (!NT_STATUS_IS_OK(status)) {
    33153563                werr = ntstatus_to_werror(status);
     3564                goto done;
     3565        }
     3566        if (!NT_STATUS_IS_OK(result)) {
     3567                werr = ntstatus_to_werror(result);
    33163568                goto done;
    33173569        }
     
    33293581        }
    33303582
    3331         sid_array.sids[0].sid = sid_dup_talloc(ctx, &user_sid);
     3583        sid_array.sids[0].sid = dom_sid_dup(ctx, &user_sid);
    33323584        if (!sid_array.sids[0].sid) {
    33333585                werr = WERR_NOMEM;
     
    33433595                }
    33443596
    3345                 sid_array.sids[i+1].sid = sid_dup_talloc(ctx, &sid);
     3597                sid_array.sids[i+1].sid = dom_sid_dup(ctx, &sid);
    33463598                if (!sid_array.sids[i+1].sid) {
    33473599                        werr = WERR_NOMEM;
     
    33503602        }
    33513603
    3352         status = rpccli_samr_GetAliasMembership(pipe_cli, talloc_tos(),
     3604        status = dcerpc_samr_GetAliasMembership(b, talloc_tos(),
    33533605                                                &domain_handle,
    33543606                                                &sid_array,
    3355                                                 &domain_rids);
     3607                                                &domain_rids,
     3608                                                &result);
    33563609        if (!NT_STATUS_IS_OK(status)) {
    33573610                werr = ntstatus_to_werror(status);
     3611                goto done;
     3612        }
     3613        if (!NT_STATUS_IS_OK(result)) {
     3614                werr = ntstatus_to_werror(result);
    33583615                goto done;
    33593616        }
     
    33673624        }
    33683625
    3369         status = rpccli_samr_GetAliasMembership(pipe_cli, talloc_tos(),
     3626        status = dcerpc_samr_GetAliasMembership(b, talloc_tos(),
    33703627                                                &builtin_handle,
    33713628                                                &sid_array,
    3372                                                 &builtin_rids);
     3629                                                &builtin_rids,
     3630                                                &result);
    33733631        if (!NT_STATUS_IS_OK(status)) {
    33743632                werr = ntstatus_to_werror(status);
     3633                goto done;
     3634        }
     3635        if (!NT_STATUS_IS_OK(result)) {
     3636                werr = ntstatus_to_werror(result);
    33753637                goto done;
    33763638        }
     
    33843646        }
    33853647
    3386         status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),
     3648        status = dcerpc_samr_LookupRids(b, talloc_tos(),
    33873649                                        &builtin_handle,
    33883650                                        num_rids,
    33893651                                        rids,
    33903652                                        &names,
    3391                                         &types);
     3653                                        &types,
     3654                                        &result);
    33923655        if (!NT_STATUS_IS_OK(status)) {
    33933656                werr = ntstatus_to_werror(status);
     3657                goto done;
     3658        }
     3659        if (!NT_STATUS_IS_OK(result)) {
     3660                werr = ntstatus_to_werror(result);
    33943661                goto done;
    33953662        }
  • trunk/server/source3/lib/os2helper.c

    r698 r745  
    6060#include "../lib/util/attr.h"
    6161#include "../lib/util/xfile.h"
    62 #include "debug.h"
     62#include "../lib/util/debug.h"
    6363#else
    6464
  • trunk/server/source3/lib/packet.c

    r593 r745  
    33   Packet handling
    44   Copyright (C) Volker Lendecke 2007
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    1919
    2020#include "includes.h"
     21#include "../lib/util/select.h"
     22#include "system/filesys.h"
     23#include "system/select.h"
     24#include "packet.h"
    2125
    2226struct packet_context {
     
    102106}
    103107
    104 NTSTATUS packet_fd_read_sync(struct packet_context *ctx,
    105                              struct timeval *timeout)
    106 {
    107         int res;
    108         fd_set r_fds;
    109 
    110         if (ctx->fd < 0 || ctx->fd >= FD_SETSIZE) {
    111                 errno = EBADF;
    112                 return map_nt_error_from_unix(errno);
    113         }
    114 
    115         FD_ZERO(&r_fds);
    116         FD_SET(ctx->fd, &r_fds);
    117 
    118         res = sys_select(ctx->fd+1, &r_fds, NULL, NULL, timeout);
    119 
     108NTSTATUS packet_fd_read_sync(struct packet_context *ctx, int timeout)
     109{
     110        int res, revents;
     111
     112        res = poll_one_fd(ctx->fd, POLLIN|POLLHUP, timeout, &revents);
    120113        if (res == 0) {
    121                 DEBUG(10, ("select timed out\n"));
     114                DEBUG(10, ("poll timed out\n"));
    122115                return NT_STATUS_IO_TIMEOUT;
    123116        }
    124117
    125118        if (res == -1) {
    126                 DEBUG(10, ("select returned %s\n", strerror(errno)));
    127                 return map_nt_error_from_unix(errno);
     119                DEBUG(10, ("poll returned %s\n", strerror(errno)));
     120                return map_nt_error_from_unix(errno);
     121        }
     122        if ((revents & (POLLIN|POLLHUP|POLLERR)) == 0) {
     123                DEBUG(10, ("socket not readable\n"));
     124                return NT_STATUS_IO_TIMEOUT;
    128125        }
    129126
  • trunk/server/source3/lib/pidfile.c

    r454 r745  
    2121
    2222#include "includes.h"
     23#include "system/filesys.h"
    2324
    2425#ifndef O_NONBLOCK
     
    9798        /* Add a suffix to the program name if this is a process with a
    9899         * none default configuration file name. */
    99 
    100100        /* On OS/2, CONFIGFILE will always be different to dyn_CONFIGFILE
    101101           as dyn_CONFIGFILE dynamically looks up the system ETC directory */   
    102102#ifndef __OS2__
    103 
    104103        if (strcmp( CONFIGFILE, get_dyn_CONFIGFILE()) == 0) {
    105104                name = SMB_STRDUP(program_name);
     
    154153                exit(1);
    155154        }
    156 
    157155        /* Leave pid file open & locked for the duration... */
    158156        SAFE_FREE(name);
     157
    159158#ifdef __OS2__ // If we leave the file open & locked on OS/2 - we can't read it, so close the fd
    160159        close(fd);
     160#else
     161        /* set the close on exec so that we don't leak the fd */
     162        fcntl(fd, F_SETFD, FD_CLOEXEC);
    161163#endif
    162164}
  • trunk/server/source3/lib/popt_common.c

    r414 r745  
    2222
    2323#include "includes.h"
     24#include "system/filesys.h"
     25#include "popt_common.h"
    2426
    2527/* Handle command line options:
     
    3436 */
    3537
    36 extern bool AllowDebugChange;
     38enum {OPT_OPTION=1};
     39
    3740extern bool override_logfile;
    3841
     
    9699
    97100        switch(opt->val) {
     101        case OPT_OPTION:
     102                if (!lp_set_option(arg)) {
     103                        fprintf(stderr, "Error setting option '%s'\n", arg);
     104                        exit(1);
     105                }
     106                break;
     107
    98108        case 'd':
    99109                if (arg) {
    100                         debug_parse_levels(arg);
    101                         AllowDebugChange = False;
     110                        lp_set_cmdline("log level", arg);
    102111                }
    103112                break;
     
    164173        { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" },
    165174        { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
     175        { "option",         0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" },
    166176        POPT_TABLEEND
    167177};
     
    185195};
    186196
     197struct poptOption popt_common_option[] = {
     198        { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_POST, (void *)popt_common_callback },
     199        { "option",         0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" },
     200        POPT_TABLEEND
     201};
    187202
    188203/* Handle command line options:
  • trunk/server/source3/lib/privileges.c

    r414 r745  
    2323
    2424#include "includes.h"
     25#include "lib/privileges.h"
     26#include "dbwrap.h"
     27#include "libcli/security/privileges_private.h"
     28#include "../libcli/security/security.h"
     29#include "passdb.h"
    2530
    2631#define PRIVPREFIX              "PRIV_"
    2732
    2833typedef struct {
    29         size_t count;
    30         DOM_SID *list;
     34        uint32_t count;
     35        struct dom_sid *list;
    3136} SID_LIST;
    3237
    3338typedef struct {
    3439        TALLOC_CTX *mem_ctx;
    35         SE_PRIV privilege;
     40        uint64_t privilege;
    3641        SID_LIST sids;
    3742} PRIV_SID_LIST;
    3843
    39 
    40 static bool get_privileges( const DOM_SID *sid, SE_PRIV *mask )
     44/*
     45  interpret an old style SE_PRIV structure
     46 */
     47static uint64_t map_old_SE_PRIV(unsigned char *dptr)
     48{
     49        uint32_t *old_masks = (uint32_t *)dptr;
     50        /*
     51         * the old privileges code only ever used up to 0x800, except
     52         * for a special case of 'SE_ALL_PRIVS' which was 0xFFFFFFFF
     53         */
     54        if (old_masks[0] == 0xFFFFFFFF) {
     55                /* they set all privileges */
     56                return SE_ALL_PRIVS;
     57        }
     58
     59        /* the old code used the machine byte order, but we don't know
     60         * the byte order of the machine that wrote it. However we can
     61         * tell what byte order it was by taking advantage of the fact
     62         * that it only ever use up to 0x800
     63         */
     64        if (dptr[0] || dptr[1]) {
     65                /* it was little endian */
     66                return IVAL(dptr, 0);
     67        }
     68
     69        /* it was either zero or big-endian */
     70        return RIVAL(dptr, 0);
     71}
     72
     73
     74static bool get_privileges( const struct dom_sid *sid, uint64_t *mask )
    4175{
    4276        struct db_context *db = get_account_pol_db();
     
    6094
    6195        if ( !data.dptr ) {
    62                 DEBUG(3, ("get_privileges: No privileges assigned to SID "
     96                DEBUG(4, ("get_privileges: No privileges assigned to SID "
    6397                          "[%s]\n", sid_string_dbg(sid)));
    6498                return False;
    6599        }
    66100
    67         SMB_ASSERT( data.dsize == sizeof( SE_PRIV ) );
    68 
    69         se_priv_copy( mask, (SE_PRIV*)data.dptr );
     101        if (data.dsize == 4*4) {
     102                /* it's an old style SE_PRIV structure. */
     103                *mask = map_old_SE_PRIV(data.dptr);
     104        } else {
     105                if (data.dsize != sizeof( uint64_t ) ) {
     106                        DEBUG(3, ("get_privileges: Invalid privileges record assigned to SID "
     107                                  "[%s]\n", sid_string_dbg(sid)));
     108                        return False;
     109                }
     110
     111                *mask = BVAL(data.dptr, 0);
     112        }
     113
    70114        TALLOC_FREE(data.dptr);
    71115
     
    77121****************************************************************************/
    78122
    79 static bool set_privileges( const DOM_SID *sid, SE_PRIV *mask )
     123static bool set_privileges( const struct dom_sid *sid, uint64_t mask )
    80124{
    81125        struct db_context *db = get_account_pol_db();
     126        uint8_t privbuf[8];
    82127        fstring tmp, keystr;
    83128        TDB_DATA data;
     
    98143        fstr_sprintf(keystr, "%s%s", PRIVPREFIX, sid_to_fstring(tmp, sid));
    99144
    100         /* no packing.  static size structure, just write it out */
    101 
    102         data.dptr  = (uint8 *)mask;
    103         data.dsize = sizeof(SE_PRIV);
     145        /* This writes the 64 bit bitmask out in little endian format */
     146        SBVAL(privbuf,0,mask);
     147
     148        data.dptr  = privbuf;
     149        data.dsize = sizeof(privbuf);
    104150
    105151        return NT_STATUS_IS_OK(dbwrap_store_bystring(db, keystr, data,
     
    111157*********************************************************************/
    112158
    113 bool get_privileges_for_sids(SE_PRIV *privileges, DOM_SID *slist, int scount)
    114 {
    115         SE_PRIV mask;
     159bool get_privileges_for_sids(uint64_t *privileges, struct dom_sid *slist, int scount)
     160{
     161        uint64_t mask;
    116162        int i;
    117163        bool found = False;
    118164
    119         se_priv_copy( privileges, &se_priv_none );
     165        *privileges = 0;
    120166
    121167        for ( i=0; i<scount; i++ ) {
     
    126172
    127173                DEBUG(5,("get_privileges_for_sids: sid = %s\nPrivilege "
    128                          "set:\n", sid_string_dbg(&slist[i])));
    129                 dump_se_priv( DBGC_ALL, 5, &mask );
    130 
    131                 se_priv_add( privileges, &mask );
     174                         "set: 0x%llx\n", sid_string_dbg(&slist[i]),
     175                         (unsigned long long)mask));
     176
     177                *privileges |= mask;
    132178                found = True;
    133179        }
     
    136182}
    137183
     184NTSTATUS get_privileges_for_sid_as_set(TALLOC_CTX *mem_ctx, PRIVILEGE_SET **privileges, struct dom_sid *sid)
     185{
     186        uint64_t mask;
     187        if (!get_privileges(sid, &mask)) {
     188                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
     189        }
     190
     191        *privileges = talloc_zero(mem_ctx, PRIVILEGE_SET);
     192        if (!*privileges) {
     193                return NT_STATUS_NO_MEMORY;
     194        }
     195
     196        if (!se_priv_to_privilege_set(*privileges, mask)) {
     197                return NT_STATUS_NO_MEMORY;
     198        }
     199        return NT_STATUS_OK;
     200}
    138201
    139202/*********************************************************************
     
    145208        PRIV_SID_LIST *priv = (PRIV_SID_LIST *)state;
    146209        int  prefixlen = strlen(PRIVPREFIX);
    147         DOM_SID sid;
     210        struct dom_sid sid;
    148211        fstring sid_string;
    149 
    150         /* easy check first */
    151 
    152         if (rec->value.dsize != sizeof(SE_PRIV) )
    153                 return 0;
    154212
    155213        /* check we have a PRIV_+SID entry */
     
    160218        /* check to see if we are looking for a particular privilege */
    161219
    162         if ( !se_priv_equal(&priv->privilege, &se_priv_none) ) {
    163                 SE_PRIV mask;
    164 
    165                 se_priv_copy( &mask, (SE_PRIV*)rec->value.dptr );
     220        fstrcpy( sid_string, (char *)&(rec->key.dptr[strlen(PRIVPREFIX)]) );
     221
     222        if (priv->privilege != 0) {
     223                uint64_t mask;
     224
     225                if (rec->value.dsize == 4*4) {
     226                        mask = map_old_SE_PRIV(rec->value.dptr);
     227                } else {
     228                        if (rec->value.dsize != sizeof( uint64_t ) ) {
     229                                DEBUG(3, ("get_privileges: Invalid privileges record assigned to SID "
     230                                          "[%s]\n", sid_string));
     231                                return 0;
     232                        }
     233                        mask = BVAL(rec->value.dptr, 0);
     234                }
    166235
    167236                /* if the SID does not have the specified privilege
    168237                   then just return */
    169238
    170                 if ( !is_privilege_assigned( &mask, &priv->privilege) )
     239                if ((mask & priv->privilege) == 0) {
    171240                        return 0;
    172         }
    173 
    174         fstrcpy( sid_string, (char *)&(rec->key.dptr[strlen(PRIVPREFIX)]) );
     241                }
     242        }
    175243
    176244        /* this is a last ditch safety check to preventing returning
     
    200268*********************************************************************/
    201269
    202 NTSTATUS privilege_enumerate_accounts(DOM_SID **sids, int *num_sids)
     270NTSTATUS privilege_enumerate_accounts(struct dom_sid **sids, int *num_sids)
    203271{
    204272        struct db_context *db = get_account_pol_db();
     
    211279        ZERO_STRUCT(priv);
    212280
    213         se_priv_copy( &priv.privilege, &se_priv_none );
    214 
    215281        db->traverse_read(db, priv_traverse_fn, &priv);
    216282
     
    227293*********************************************************************/
    228294
    229 NTSTATUS privilege_enum_sids(const SE_PRIV *mask, TALLOC_CTX *mem_ctx,
    230                              DOM_SID **sids, int *num_sids)
     295NTSTATUS privilege_enum_sids(enum sec_privilege privilege, TALLOC_CTX *mem_ctx,
     296                             struct dom_sid **sids, int *num_sids)
    231297{
    232298        struct db_context *db = get_account_pol_db();
     
    239305        ZERO_STRUCT(priv);
    240306
    241         se_priv_copy(&priv.privilege, mask);
     307        priv.privilege = sec_privilege_mask(privilege);
    242308        priv.mem_ctx = mem_ctx;
    243309
     
    256322****************************************************************************/
    257323
    258 bool grant_privilege(const DOM_SID *sid, const SE_PRIV *priv_mask)
    259 {
    260         SE_PRIV old_mask, new_mask;
     324static bool grant_privilege_bitmap(const struct dom_sid *sid, const uint64_t priv_mask)
     325{
     326        uint64_t old_mask, new_mask;
    261327
    262328        ZERO_STRUCT( old_mask );
     
    264330
    265331        if ( get_privileges( sid, &old_mask ) )
    266                 se_priv_copy( &new_mask, &old_mask );
     332                new_mask = old_mask;
    267333        else
    268                 se_priv_copy( &new_mask, &se_priv_none );
    269 
    270         se_priv_add( &new_mask, priv_mask );
     334                new_mask = 0;
     335
     336        new_mask |= priv_mask;
    271337
    272338        DEBUG(10,("grant_privilege: %s\n", sid_string_dbg(sid)));
    273339
    274         DEBUGADD( 10, ("original privilege mask:\n"));
    275         dump_se_priv( DBGC_ALL, 10, &old_mask );
    276 
    277         DEBUGADD( 10, ("new privilege mask:\n"));
    278         dump_se_priv( DBGC_ALL, 10, &new_mask );
    279 
    280         return set_privileges( sid, &new_mask );
     340        DEBUGADD( 10, ("original privilege mask: 0x%llx\n", (unsigned long long)new_mask));
     341
     342        DEBUGADD( 10, ("new privilege mask:      0x%llx\n", (unsigned long long)new_mask));
     343
     344        return set_privileges( sid, new_mask );
    281345}
    282346
     
    285349*********************************************************************/
    286350
    287 bool grant_privilege_by_name(DOM_SID *sid, const char *name)
    288 {
    289         SE_PRIV mask;
     351bool grant_privilege_by_name(const struct dom_sid *sid, const char *name)
     352{
     353        uint64_t mask;
    290354
    291355        if (! se_priv_from_name(name, &mask)) {
     
    295359        }
    296360
    297         return grant_privilege( sid, &mask );
     361        return grant_privilege_bitmap( sid, mask );
     362}
     363
     364/***************************************************************************
     365 Grant a privilege set (list of LUID values) from a sid
     366****************************************************************************/
     367
     368bool grant_privilege_set(const struct dom_sid *sid, struct lsa_PrivilegeSet *set)
     369{
     370        uint64_t privilege_mask;
     371        if (!privilege_set_to_se_priv(&privilege_mask, set)) {
     372                return false;
     373        }
     374        return grant_privilege_bitmap(sid, privilege_mask);
    298375}
    299376
     
    302379****************************************************************************/
    303380
    304 bool revoke_privilege(const DOM_SID *sid, const SE_PRIV *priv_mask)
    305 {
    306         SE_PRIV mask;
     381static bool revoke_privilege_bitmap(const struct dom_sid *sid, const uint64_t priv_mask)
     382{
     383        uint64_t mask;
    307384
    308385        /* if the user has no privileges, then we can't revoke any */
     
    313390        DEBUG(10,("revoke_privilege: %s\n", sid_string_dbg(sid)));
    314391
    315         DEBUGADD( 10, ("original privilege mask:\n"));
    316         dump_se_priv( DBGC_ALL, 10, &mask );
    317 
    318         se_priv_remove( &mask, priv_mask );
    319 
    320         DEBUGADD( 10, ("new privilege mask:\n"));
    321         dump_se_priv( DBGC_ALL, 10, &mask );
    322 
    323         return set_privileges( sid, &mask );
     392        DEBUGADD( 10, ("original privilege mask: 0x%llx\n", (unsigned long long)mask));
     393
     394        mask &= ~priv_mask;
     395
     396        DEBUGADD( 10, ("new privilege mask:      0x%llx\n", (unsigned long long)mask));
     397
     398        return set_privileges( sid, mask );
     399}
     400
     401/***************************************************************************
     402 Remove a privilege set (list of LUID values) from a sid
     403****************************************************************************/
     404
     405bool revoke_privilege_set(const struct dom_sid *sid, struct lsa_PrivilegeSet *set)
     406{
     407        uint64_t privilege_mask;
     408        if (!privilege_set_to_se_priv(&privilege_mask, set)) {
     409                return false;
     410        }
     411        return revoke_privilege_bitmap(sid, privilege_mask);
    324412}
    325413
     
    328416*********************************************************************/
    329417
    330 bool revoke_all_privileges( DOM_SID *sid )
    331 {
    332         return revoke_privilege( sid, &se_priv_all );
     418bool revoke_all_privileges( const struct dom_sid *sid )
     419{
     420        return revoke_privilege_bitmap( sid, SE_ALL_PRIVS);
    333421}
    334422
     
    337425*********************************************************************/
    338426
    339 bool revoke_privilege_by_name(DOM_SID *sid, const char *name)
    340 {
    341         SE_PRIV mask;
     427bool revoke_privilege_by_name(const struct dom_sid *sid, const char *name)
     428{
     429        uint64_t mask;
    342430
    343431        if (! se_priv_from_name(name, &mask)) {
     
    347435        }
    348436
    349         return revoke_privilege(sid, &mask);
     437        return revoke_privilege_bitmap(sid, mask);
    350438
    351439}
     
    355443****************************************************************************/
    356444
    357 NTSTATUS privilege_create_account(const DOM_SID *sid )
    358 {
    359         return ( grant_privilege(sid, &se_priv_none) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL);
     445NTSTATUS privilege_create_account(const struct dom_sid *sid )
     446{
     447        return ( grant_privilege_bitmap(sid, 0) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL);
    360448}
    361449
     
    388476}
    389477
    390 /****************************************************************************
    391  initialise a privilege list and set the talloc context
    392  ****************************************************************************/
    393 
    394 NTSTATUS privilege_set_init(PRIVILEGE_SET *priv_set)
    395 {
    396         TALLOC_CTX *mem_ctx;
    397 
    398         ZERO_STRUCTP( priv_set );
    399 
    400         mem_ctx = talloc_init("privilege set");
    401         if ( !mem_ctx ) {
    402                 DEBUG(0,("privilege_set_init: failed to initialize talloc ctx!\n"));
    403                 return NT_STATUS_NO_MEMORY;
    404         }
    405 
    406         priv_set->mem_ctx = mem_ctx;
    407 
    408         return NT_STATUS_OK;
    409 }
    410 
    411 /****************************************************************************
    412   initialise a privilege list and with someone else's talloc context
    413 ****************************************************************************/
    414 
    415 NTSTATUS privilege_set_init_by_ctx(TALLOC_CTX *mem_ctx, PRIVILEGE_SET *priv_set)
    416 {
    417         ZERO_STRUCTP( priv_set );
    418 
    419         priv_set->mem_ctx = mem_ctx;
    420         priv_set->ext_ctx = True;
    421 
    422         return NT_STATUS_OK;
    423 }
    424 
    425 /****************************************************************************
    426  Free all memory used by a PRIVILEGE_SET
    427 ****************************************************************************/
    428 
    429 void privilege_set_free(PRIVILEGE_SET *priv_set)
    430 {
    431         if ( !priv_set )
    432                 return;
    433 
    434         if ( !( priv_set->ext_ctx ) )
    435                 talloc_destroy( priv_set->mem_ctx );
    436 
    437         ZERO_STRUCTP( priv_set );
    438 }
    439 
    440 /****************************************************************************
    441  duplicate alloc luid_attr
    442  ****************************************************************************/
    443 
    444 NTSTATUS dup_luid_attr(TALLOC_CTX *mem_ctx, LUID_ATTR **new_la, LUID_ATTR *old_la, int count)
    445 {
    446         int i;
    447 
    448         if ( !old_la )
    449                 return NT_STATUS_OK;
    450 
    451         if (count) {
    452                 *new_la = TALLOC_ARRAY(mem_ctx, LUID_ATTR, count);
    453                 if ( !*new_la ) {
    454                         DEBUG(0,("dup_luid_attr: failed to alloc new LUID_ATTR array [%d]\n", count));
    455                         return NT_STATUS_NO_MEMORY;
    456                 }
    457         } else {
    458                 *new_la = NULL;
    459         }
    460 
    461         for (i=0; i<count; i++) {
    462                 (*new_la)[i].luid.high = old_la[i].luid.high;
    463                 (*new_la)[i].luid.low = old_la[i].luid.low;
    464                 (*new_la)[i].attr = old_la[i].attr;
    465         }
    466 
    467         return NT_STATUS_OK;
    468 }
    469 
    470478/*******************************************************************
    471479*******************************************************************/
    472480
    473 bool is_privileged_sid( const DOM_SID *sid )
    474 {
    475         SE_PRIV mask;
     481bool is_privileged_sid( const struct dom_sid *sid )
     482{
     483        uint64_t mask;
    476484
    477485        return get_privileges( sid, &mask );
     
    481489*******************************************************************/
    482490
    483 bool grant_all_privileges( const DOM_SID *sid )
    484 {
    485         SE_PRIV mask;
    486 
    487         if (!se_priv_put_all_privileges(&mask)) {
    488                 return False;
    489         }
    490 
    491         return grant_privilege( sid, &mask );
    492 }
     491bool grant_all_privileges( const struct dom_sid *sid )
     492{
     493        uint64_t mask;
     494
     495        se_priv_put_all_privileges(&mask);
     496
     497        return grant_privilege_bitmap( sid, mask );
     498}
  • trunk/server/source3/lib/pthreadpool/pthreadpool.c

    r741 r745  
    3131#include "pthreadpool.h"
    3232#include "lib/util/dlinklist.h"
     33#ifdef __OS2__
     34#define pipe(A) os2_pipe(A)
     35#endif
    3336
    3437struct pthreadpool_job {
  • trunk/server/source3/lib/recvfile.c

    r664 r745  
    2525
    2626#include "includes.h"
     27#include "system/filesys.h"
    2728#ifdef __OS2__
    2829#define pipe(A) os2_pipe(A)
  • trunk/server/source3/lib/secdesc.c

    r414 r745  
    2222
    2323#include "includes.h"
     24#include "../librpc/gen_ndr/ndr_security.h"
     25#include "../libcli/security/security.h"
     26
     27#define ALL_SECURITY_INFORMATION (SECINFO_OWNER|SECINFO_GROUP|\
     28                                        SECINFO_DACL|SECINFO_SACL|\
     29                                        SECINFO_UNPROTECTED_SACL|\
     30                                        SECINFO_UNPROTECTED_DACL|\
     31                                        SECINFO_PROTECTED_SACL|\
     32                                        SECINFO_PROTECTED_DACL)
    2433
    2534/* Map generic permissions to file object specific permissions */
     
    3645********************************************************************/
    3746
    38 uint32_t get_sec_info(const SEC_DESC *sd)
     47uint32_t get_sec_info(const struct security_descriptor *sd)
    3948{
    4049        uint32_t sec_info = ALL_SECURITY_INFORMATION;
     
    4352
    4453        if (sd->owner_sid == NULL) {
    45                 sec_info &= ~OWNER_SECURITY_INFORMATION;
     54                sec_info &= ~SECINFO_OWNER;
    4655        }
    4756        if (sd->group_sid == NULL) {
    48                 sec_info &= ~GROUP_SECURITY_INFORMATION;
     57                sec_info &= ~SECINFO_GROUP;
    4958        }
    5059        if (sd->sacl == NULL) {
    51                 sec_info &= ~SACL_SECURITY_INFORMATION;
     60                sec_info &= ~SECINFO_SACL;
    5261        }
    5362        if (sd->dacl == NULL) {
    54                 sec_info &= ~DACL_SECURITY_INFORMATION;
     63                sec_info &= ~SECINFO_DACL;
    5564        }
    5665
     
    6473********************************************************************/
    6574
    66 SEC_DESC_BUF *sec_desc_merge(TALLOC_CTX *ctx, SEC_DESC_BUF *new_sdb, SEC_DESC_BUF *old_sdb)
    67 {
    68         DOM_SID *owner_sid, *group_sid;
    69         SEC_DESC_BUF *return_sdb;
    70         SEC_ACL *dacl, *sacl;
    71         SEC_DESC *psd = NULL;
     75struct sec_desc_buf *sec_desc_merge_buf(TALLOC_CTX *ctx, struct sec_desc_buf *new_sdb, struct sec_desc_buf *old_sdb)
     76{
     77        struct dom_sid *owner_sid, *group_sid;
     78        struct sec_desc_buf *return_sdb;
     79        struct security_acl *dacl, *sacl;
     80        struct security_descriptor *psd = NULL;
    7281        uint16 secdesc_type;
    7382        size_t secdesc_size;
     
    109118}
    110119
    111 /*******************************************************************
    112  Creates a SEC_DESC structure
    113 ********************************************************************/
    114 
    115 SEC_DESC *make_sec_desc(TALLOC_CTX *ctx,
     120struct security_descriptor *sec_desc_merge(TALLOC_CTX *ctx, struct security_descriptor *new_sdb, struct security_descriptor *old_sdb)
     121{
     122        struct dom_sid *owner_sid, *group_sid;
     123        struct security_acl *dacl, *sacl;
     124        struct security_descriptor *psd = NULL;
     125        uint16 secdesc_type;
     126        size_t secdesc_size;
     127
     128        /* Copy over owner and group sids.  There seems to be no flag for
     129           this so just check the pointer values. */
     130
     131        owner_sid = new_sdb->owner_sid ? new_sdb->owner_sid :
     132                old_sdb->owner_sid;
     133
     134        group_sid = new_sdb->group_sid ? new_sdb->group_sid :
     135                old_sdb->group_sid;
     136
     137        secdesc_type = new_sdb->type;
     138
     139        /* Ignore changes to the system ACL.  This has the effect of making
     140           changes through the security tab audit button not sticking.
     141           Perhaps in future Samba could implement these settings somehow. */
     142
     143        sacl = NULL;
     144        secdesc_type &= ~SEC_DESC_SACL_PRESENT;
     145
     146        /* Copy across discretionary ACL */
     147
     148        if (secdesc_type & SEC_DESC_DACL_PRESENT) {
     149                dacl = new_sdb->dacl;
     150        } else {
     151                dacl = old_sdb->dacl;
     152        }
     153
     154        /* Create new security descriptor from bits */
     155        psd = make_sec_desc(ctx, new_sdb->revision, secdesc_type,
     156                            owner_sid, group_sid, sacl, dacl, &secdesc_size);
     157
     158        return psd;
     159}
     160
     161/*******************************************************************
     162 Creates a struct security_descriptor structure
     163********************************************************************/
     164
     165#define  SEC_DESC_HEADER_SIZE (2 * sizeof(uint16) + 4 * sizeof(uint32))
     166
     167struct security_descriptor *make_sec_desc(TALLOC_CTX *ctx,
    116168                        enum security_descriptor_revision revision,
    117169                        uint16 type,
    118                         const DOM_SID *owner_sid, const DOM_SID *grp_sid,
    119                         SEC_ACL *sacl, SEC_ACL *dacl, size_t *sd_size)
    120 {
    121         SEC_DESC *dst;
     170                        const struct dom_sid *owner_sid, const struct dom_sid *grp_sid,
     171                        struct security_acl *sacl, struct security_acl *dacl, size_t *sd_size)
     172{
     173        struct security_descriptor *dst;
    122174        uint32 offset     = 0;
    123175
    124176        *sd_size = 0;
    125177
    126         if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)
     178        if(( dst = TALLOC_ZERO_P(ctx, struct security_descriptor)) == NULL)
    127179                return NULL;
    128180
     
    140192        dst->dacl      = NULL;
    141193
    142         if(owner_sid && ((dst->owner_sid = sid_dup_talloc(dst,owner_sid)) == NULL))
     194        if(owner_sid && ((dst->owner_sid = dom_sid_dup(dst,owner_sid)) == NULL))
    143195                goto error_exit;
    144196
    145         if(grp_sid && ((dst->group_sid = sid_dup_talloc(dst,grp_sid)) == NULL))
     197        if(grp_sid && ((dst->group_sid = dom_sid_dup(dst,grp_sid)) == NULL))
    146198                goto error_exit;
    147199
     
    166218
    167219        if (dst->owner_sid != NULL) {
    168                 offset += ndr_size_dom_sid(dst->owner_sid, NULL, 0);
     220                offset += ndr_size_dom_sid(dst->owner_sid, 0);
    169221        }
    170222
    171223        if (dst->group_sid != NULL) {
    172                 offset += ndr_size_dom_sid(dst->group_sid, NULL, 0);
     224                offset += ndr_size_dom_sid(dst->group_sid, 0);
    173225        }
    174226
     
    183235
    184236/*******************************************************************
    185  Duplicate a SEC_DESC structure. 
    186 ********************************************************************/
    187 
    188 SEC_DESC *dup_sec_desc(TALLOC_CTX *ctx, const SEC_DESC *src)
     237 Duplicate a struct security_descriptor structure.
     238********************************************************************/
     239
     240struct security_descriptor *dup_sec_desc(TALLOC_CTX *ctx, const struct security_descriptor *src)
    189241{
    190242        size_t dummy;
     
    209261
    210262        ndr_err = ndr_push_struct_blob(
    211                 &blob, mem_ctx, NULL, secdesc,
     263                &blob, mem_ctx, secdesc,
    212264                (ndr_push_flags_fn_t)ndr_push_security_descriptor);
    213265
     
    215267                DEBUG(0, ("ndr_push_security_descriptor failed: %s\n",
    216268                          ndr_errstr(ndr_err)));
    217                 return ndr_map_error2ntstatus(ndr_err);;
     269                return ndr_map_error2ntstatus(ndr_err);
    218270        }
    219271
     
    235287
    236288        ndr_err = ndr_push_struct_blob(
    237                 &blob, mem_ctx, NULL, secdesc_buf,
     289                &blob, mem_ctx, secdesc_buf,
    238290                (ndr_push_flags_fn_t)ndr_push_sec_desc_buf);
    239291
     
    241293                DEBUG(0, ("ndr_push_sec_desc_buf failed: %s\n",
    242294                          ndr_errstr(ndr_err)));
    243                 return ndr_map_error2ntstatus(ndr_err);;
     295                return ndr_map_error2ntstatus(ndr_err);
    244296        }
    245297
     
    270322        blob = data_blob_const(data, len);
    271323
    272         ndr_err = ndr_pull_struct_blob(
    273                 &blob, result, NULL, result,
     324        ndr_err = ndr_pull_struct_blob(&blob, result, result,
    274325                (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
    275326
     
    278329                          ndr_errstr(ndr_err)));
    279330                TALLOC_FREE(result);
    280                 return ndr_map_error2ntstatus(ndr_err);;
     331                return ndr_map_error2ntstatus(ndr_err);
    281332        }
    282333
     
    307358        blob = data_blob_const(data, len);
    308359
    309         ndr_err = ndr_pull_struct_blob(
    310                 &blob, result, NULL, result,
     360        ndr_err = ndr_pull_struct_blob(&blob, result, result,
    311361                (ndr_pull_flags_fn_t)ndr_pull_sec_desc_buf);
    312362
     
    315365                          ndr_errstr(ndr_err)));
    316366                TALLOC_FREE(result);
    317                 return ndr_map_error2ntstatus(ndr_err);;
     367                return ndr_map_error2ntstatus(ndr_err);
    318368        }
    319369
     
    323373
    324374/*******************************************************************
    325  Creates a SEC_DESC structure with typical defaults.
    326 ********************************************************************/
    327 
    328 SEC_DESC *make_standard_sec_desc(TALLOC_CTX *ctx, const DOM_SID *owner_sid, const DOM_SID *grp_sid,
    329                                  SEC_ACL *dacl, size_t *sd_size)
     375 Creates a struct security_descriptor structure with typical defaults.
     376********************************************************************/
     377
     378struct security_descriptor *make_standard_sec_desc(TALLOC_CTX *ctx, const struct dom_sid *owner_sid, const struct dom_sid *grp_sid,
     379                                 struct security_acl *dacl, size_t *sd_size)
    330380{
    331381        return make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
     
    335385
    336386/*******************************************************************
    337  Creates a SEC_DESC_BUF structure.
    338 ********************************************************************/
    339 
    340 SEC_DESC_BUF *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, SEC_DESC *sec_desc)
    341 {
    342         SEC_DESC_BUF *dst;
    343 
    344         if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL)
     387 Creates a struct sec_desc_buf structure.
     388********************************************************************/
     389
     390struct sec_desc_buf *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, struct security_descriptor *sec_desc)
     391{
     392        struct sec_desc_buf *dst;
     393
     394        if((dst = TALLOC_ZERO_P(ctx, struct sec_desc_buf)) == NULL)
    345395                return NULL;
    346396
     
    356406
    357407/*******************************************************************
    358  Duplicates a SEC_DESC_BUF structure.
    359 ********************************************************************/
    360 
    361 SEC_DESC_BUF *dup_sec_desc_buf(TALLOC_CTX *ctx, SEC_DESC_BUF *src)
     408 Duplicates a struct sec_desc_buf structure.
     409********************************************************************/
     410
     411struct sec_desc_buf *dup_sec_desc_buf(TALLOC_CTX *ctx, struct sec_desc_buf *src)
    362412{
    363413        if(src == NULL)
     
    368418
    369419/*******************************************************************
    370  Add a new SID with its permissions to SEC_DESC.
    371 ********************************************************************/
    372 
    373 NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, SEC_DESC **psd, DOM_SID *sid, uint32 mask, size_t *sd_size)
    374 {
    375         SEC_DESC *sd   = 0;
    376         SEC_ACL  *dacl = 0;
    377         SEC_ACE  *ace  = 0;
     420 Add a new SID with its permissions to struct security_descriptor.
     421********************************************************************/
     422
     423NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, struct security_descriptor **psd, const struct dom_sid *sid, uint32 mask, size_t *sd_size)
     424{
     425        struct security_descriptor *sd   = 0;
     426        struct security_acl  *dacl = 0;
     427        struct security_ace  *ace  = 0;
    378428        NTSTATUS  status;
    379429
     
    401451
    402452/*******************************************************************
    403  Modify a SID's permissions in a SEC_DESC.
    404 ********************************************************************/
    405 
    406 NTSTATUS sec_desc_mod_sid(SEC_DESC *sd, DOM_SID *sid, uint32 mask)
     453 Modify a SID's permissions in a struct security_descriptor.
     454********************************************************************/
     455
     456NTSTATUS sec_desc_mod_sid(struct security_descriptor *sd, struct dom_sid *sid, uint32 mask)
    407457{
    408458        NTSTATUS status;
     
    420470
    421471/*******************************************************************
    422  Delete a SID from a SEC_DESC.
    423 ********************************************************************/
    424 
    425 NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, SEC_DESC **psd, DOM_SID *sid, size_t *sd_size)
    426 {
    427         SEC_DESC *sd   = 0;
    428         SEC_ACL  *dacl = 0;
    429         SEC_ACE  *ace  = 0;
     472 Delete a SID from a struct security_descriptor.
     473********************************************************************/
     474
     475NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, struct security_descriptor **psd, struct dom_sid *sid, size_t *sd_size)
     476{
     477        struct security_descriptor *sd   = 0;
     478        struct security_acl  *dacl = 0;
     479        struct security_ace  *ace  = 0;
    430480        NTSTATUS  status;
    431481
     
    453503
    454504/*
    455  * Determine if an ACE is inheritable
     505 * Determine if an struct security_ace is inheritable
    456506 */
    457507
    458 static bool is_inheritable_ace(const SEC_ACE *ace,
     508static bool is_inheritable_ace(const struct security_ace *ace,
    459509                                bool container)
    460510{
     
    480530 */
    481531
    482 bool sd_has_inheritable_components(const SEC_DESC *parent_ctr, bool container)
     532bool sd_has_inheritable_components(const struct security_descriptor *parent_ctr, bool container)
    483533{
    484534        unsigned int i;
    485         const SEC_ACL *the_acl = parent_ctr->dacl;
     535        const struct security_acl *the_acl = parent_ctr->dacl;
    486536
    487537        for (i = 0; i < the_acl->num_aces; i++) {
    488                 const SEC_ACE *ace = &the_acl->aces[i];
     538                const struct security_ace *ace = &the_acl->aces[i];
    489539
    490540                if (is_inheritable_ace(ace, container)) {
     
    500550
    501551NTSTATUS se_create_child_secdesc(TALLOC_CTX *ctx,
    502                                         SEC_DESC **ppsd,
     552                                        struct security_descriptor **ppsd,
    503553                                        size_t *psize,
    504                                         const SEC_DESC *parent_ctr,
    505                                         const DOM_SID *owner_sid,
    506                                         const DOM_SID *group_sid,
     554                                        const struct security_descriptor *parent_ctr,
     555                                        const struct dom_sid *owner_sid,
     556                                        const struct dom_sid *group_sid,
    507557                                        bool container)
    508558{
    509         SEC_ACL *new_dacl = NULL, *the_acl = NULL;
    510         SEC_ACE *new_ace_list = NULL;
     559        struct security_acl *new_dacl = NULL, *the_acl = NULL;
     560        struct security_ace *new_ace_list = NULL;
    511561        unsigned int new_ace_list_ndx = 0, i;
    512562
     
    525575                }
    526576
    527                 if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE,
     577                if (!(new_ace_list = TALLOC_ARRAY(ctx, struct security_ace,
    528578                                                2*the_acl->num_aces))) {
    529579                        return NT_STATUS_NO_MEMORY;
     
    534584
    535585        for (i = 0; i < the_acl->num_aces; i++) {
    536                 const SEC_ACE *ace = &the_acl->aces[i];
    537                 SEC_ACE *new_ace = &new_ace_list[new_ace_list_ndx];
    538                 const DOM_SID *ptrustee = &ace->trustee;
    539                 const DOM_SID *creator = NULL;
     586                const struct security_ace *ace = &the_acl->aces[i];
     587                struct security_ace *new_ace = &new_ace_list[new_ace_list_ndx];
     588                const struct dom_sid *ptrustee = &ace->trustee;
     589                const struct dom_sid *creator = NULL;
    540590                uint8 new_flags = ace->flags;
    541591
     
    559609
    560610                /* The CREATOR sids are special when inherited */
    561                 if (sid_equal(ptrustee, &global_sid_Creator_Owner)) {
     611                if (dom_sid_equal(ptrustee, &global_sid_Creator_Owner)) {
    562612                        creator = &global_sid_Creator_Owner;
    563613                        ptrustee = owner_sid;
    564                 } else if (sid_equal(ptrustee, &global_sid_Creator_Group)) {
     614                } else if (dom_sid_equal(ptrustee, &global_sid_Creator_Group)) {
    565615                        creator = &global_sid_Creator_Group;
    566616                        ptrustee = group_sid;
     
    635685
    636686NTSTATUS se_create_child_secdesc_buf(TALLOC_CTX *ctx,
    637                                         SEC_DESC_BUF **ppsdb,
    638                                         const SEC_DESC *parent_ctr,
     687                                        struct sec_desc_buf **ppsdb,
     688                                        const struct security_descriptor *parent_ctr,
    639689                                        bool container)
    640690{
    641691        NTSTATUS status;
    642692        size_t size = 0;
    643         SEC_DESC *sd = NULL;
     693        struct security_descriptor *sd = NULL;
    644694
    645695        *ppsdb = NULL;
  • trunk/server/source3/lib/sendfile.c

    r414 r745  
    6464                        nwritten = sendfile(tofd, fromfd, &offset, total);
    6565#endif
    66                 } while (nwritten == -1 && errno == EINTR);
     66#if defined(EWOULDBLOCK)
     67                } while (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     68#else
     69                } while (nwritten == -1 && (errno == EINTR || errno == EAGAIN));
     70#endif
    6771                if (nwritten == -1) {
    6872                        if (errno == ENOSYS || errno == EINVAL) {
     
    146150                do {
    147151                        nwritten = sendfile(tofd, fromfd, &small_offset, small_total);
    148                 } while (nwritten == -1 && errno == EINTR);
     152#if defined(EWOULDBLOCK)
     153                } while (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     154#else
     155                } while (nwritten == -1 && (errno == EINTR || errno == EAGAIN));
     156#endif
    149157                if (nwritten == -1) {
    150158                        if (errno == ENOSYS || errno == EINVAL) {
     
    227235                        nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
    228236#endif
    229                 if (nwritten == -1 && errno == EINTR) {
     237#if defined(EWOULDBLOCK)
     238                if  (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) {
     239#else
     240                if (nwritten == -1 && (errno == EINTR || errno == EAGAIN)) {
     241#endif
    230242                        if (xferred == 0)
    231243                                continue; /* Nothing written yet. */
     
    301313                        nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
    302314#endif
    303                 } while (nwritten == -1 && errno == EINTR);
     315#if defined(EWOULDBLOCK)
     316                } while (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     317#else
     318                } while (nwritten == -1 && (errno == EINTR || errno == EAGAIN));
     319#endif
    304320                if (nwritten == -1)
    305321                        return -1;
     
    372388                do {
    373389                        ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0);
    374                 } while (ret == -1 && errno == EINTR);
     390#if defined(EWOULDBLOCK)
     391                } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     392#else
     393                } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     394#endif
    375395                if (ret == -1)
    376396                        return -1;
     
    450470                do {
    451471                        ret = send_file(&tofd, &hdtrl, 0);
    452                 } while ( (ret == 1) || (ret == -1 && errno == EINTR) );
     472#if defined(EWOULDBLOCK)
     473                } while ((ret == 1) || (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)));
     474#else
     475                } while ((ret == 1) || (ret == -1 && (errno == EINTR || errno == EAGAIN)));
     476#endif
    453477                if ( ret == -1 )
    454478                        return -1;
  • trunk/server/source3/lib/server_mutex.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "system/filesys.h"
     23#include "lib/util/tdb_wrap.h"
     24#include "util_tdb.h"
    2225
    2326/* For reasons known only to MS, many of their NT/Win2k versions
  • trunk/server/source3/lib/sharesec.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "../libcli/security/security.h"
     23#include "../librpc/gen_ndr/ndr_security.h"
     24#include "dbwrap.h"
     25#include "util_tdb.h"
    2126
    2227/*******************************************************************
     
    2732#define SHARE_DATABASE_VERSION_V1 1
    2833#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
    29 
     34#define SHARE_DATABASE_VERSION_V3 3 /* canonicalized sharenames as lower case */
     35
     36#define SHARE_SECURITY_DB_KEY_PREFIX_STR "SECDESC/"
    3037/* Map generic permissions to file object specific permissions */
    3138
     
    3845}
    3946
     47/*****************************************************
     48 Looking for keys of the form: SHARE_SECURITY_DB_KEY_PREFIX_STR + "non lower case str".
     49 If we find one re-write it into a canonical case form.
     50*****************************************************/
     51
     52static int upgrade_v2_to_v3(struct db_record *rec, void *priv)
     53{
     54        size_t prefix_len = strlen(SHARE_SECURITY_DB_KEY_PREFIX_STR);
     55        const char *servicename = NULL;
     56        char *c_servicename = NULL;
     57        char *newkey = NULL;
     58        bool *p_upgrade_ok = (bool *)priv;
     59        NTSTATUS status;
     60
     61        /* Is there space for a one character sharename ? */
     62        if (rec->key.dsize <= prefix_len+2) {
     63                return 0;
     64        }
     65
     66        /* Does it start with the share key prefix ? */
     67        if (memcmp(rec->key.dptr, SHARE_SECURITY_DB_KEY_PREFIX_STR,
     68                        prefix_len) != 0) {
     69                return 0;
     70        }
     71
     72        /* Is it a null terminated string as a key ? */
     73        if (rec->key.dptr[rec->key.dsize-1] != '\0') {
     74                return 0;
     75        }
     76
     77        /* Bytes after the prefix are the sharename string. */
     78        servicename = (char *)&rec->key.dptr[prefix_len];
     79        c_servicename = canonicalize_servicename(talloc_tos(), servicename);
     80        if (!c_servicename) {
     81                smb_panic("out of memory upgrading share security db from v2 -> v3");
     82        }
     83
     84        if (strcmp(servicename, c_servicename) == 0) {
     85                /* Old and new names match. No canonicalization needed. */
     86                TALLOC_FREE(c_servicename);
     87                return 0;
     88        }
     89
     90        /* Oops. Need to canonicalize name, delete old then store new. */
     91        status = rec->delete_rec(rec);
     92        if (!NT_STATUS_IS_OK(status)) {
     93                DEBUG(1, ("upgrade_v2_to_v3: Failed to delete secdesc for "
     94                          "%s: %s\n", rec->key.dptr, nt_errstr(status)));
     95                TALLOC_FREE(c_servicename);
     96                *p_upgrade_ok = false;
     97                return -1;
     98        } else {
     99                DEBUG(10, ("upgrade_v2_to_v3: deleted secdesc for "
     100                          "%s\n", rec->key.dptr ));
     101        }
     102
     103        if (!(newkey = talloc_asprintf(talloc_tos(),
     104                        SHARE_SECURITY_DB_KEY_PREFIX_STR "%s",
     105                        c_servicename))) {
     106                smb_panic("out of memory upgrading share security db from v2 -> v3");
     107        }
     108
     109        status = dbwrap_store(share_db,
     110                                string_term_tdb_data(newkey),
     111                                rec->value,
     112                                TDB_REPLACE);
     113
     114        if (!NT_STATUS_IS_OK(status)) {
     115                DEBUG(1, ("upgrade_v2_to_v3: Failed to store secdesc for "
     116                          "%s: %s\n", c_servicename, nt_errstr(status)));
     117                TALLOC_FREE(c_servicename);
     118                TALLOC_FREE(newkey);
     119                *p_upgrade_ok = false;
     120                return -1;
     121        } else {
     122                DEBUG(10, ("upgrade_v2_to_v3: stored secdesc for "
     123                          "%s\n", newkey ));
     124        }
     125
     126        TALLOC_FREE(newkey);
     127        TALLOC_FREE(c_servicename);
     128
     129        return 0;
     130}
     131
    40132bool share_info_db_init(void)
    41133{
    42134        const char *vstring = "INFO/version";
    43135        int32 vers_id;
     136        int ret;
     137        bool upgrade_ok = true;
    44138
    45139        if (share_db != NULL) {
     
    56150
    57151        vers_id = dbwrap_fetch_int32(share_db, vstring);
    58         if (vers_id == SHARE_DATABASE_VERSION_V2) {
     152        if (vers_id == SHARE_DATABASE_VERSION_V3) {
    59153                return true;
    60154        }
     
    67161
    68162        vers_id = dbwrap_fetch_int32(share_db, vstring);
    69         if (vers_id == SHARE_DATABASE_VERSION_V2) {
     163        if (vers_id == SHARE_DATABASE_VERSION_V3) {
    70164                /*
    71165                 * Race condition
     
    77171        }
    78172
     173        /* Move to at least V2. */
     174
    79175        /* Cope with byte-reversed older versions of the db. */
    80176        if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
     
    90186
    91187        if (vers_id != SHARE_DATABASE_VERSION_V2) {
    92                 int ret;
    93188                ret = share_db->traverse(share_db, delete_fn, NULL);
    94189                if (ret < 0) {
     
    103198        }
    104199
     200        /* Finally upgrade to version 3, with canonicalized sharenames. */
     201
     202        ret = share_db->traverse(share_db, upgrade_v2_to_v3, &upgrade_ok);
     203        if (ret < 0 || upgrade_ok == false) {
     204                DEBUG(0, ("traverse failed\n"));
     205                goto cancel;
     206        }
     207        if (dbwrap_store_int32(share_db, vstring,
     208                               SHARE_DATABASE_VERSION_V3) != 0) {
     209                DEBUG(0, ("dbwrap_store_int32 failed\n"));
     210                goto cancel;
     211        }
     212
    105213        if (share_db->transaction_commit(share_db) != 0) {
    106214                DEBUG(0, ("transaction_commit failed\n"));
     
    123231 ********************************************************************/
    124232
    125 SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)
     233struct security_descriptor *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)
    126234{
    127235        uint32_t sa;
    128         SEC_ACE ace;
    129         SEC_ACL *psa = NULL;
    130         SEC_DESC *psd = NULL;
     236        struct security_ace ace;
     237        struct security_acl *psa = NULL;
     238        struct security_descriptor *psd = NULL;
    131239        uint32 spec_access = def_access;
    132240
     
    154262 ********************************************************************/
    155263
    156 SEC_DESC *get_share_security( TALLOC_CTX *ctx, const char *servicename,
     264struct security_descriptor *get_share_security( TALLOC_CTX *ctx, const char *servicename,
    157265                              size_t *psize)
    158266{
    159267        char *key;
    160         SEC_DESC *psd = NULL;
     268        struct security_descriptor *psd = NULL;
    161269        TDB_DATA data;
     270        char *c_servicename = canonicalize_servicename(talloc_tos(), servicename);
    162271        NTSTATUS status;
    163272
     273        if (!c_servicename) {
     274                return NULL;
     275        }
     276
    164277        if (!share_info_db_init()) {
     278                TALLOC_FREE(c_servicename);
    165279                return NULL;
    166280        }
    167281
    168         if (!(key = talloc_asprintf(ctx, "SECDESC/%s", servicename))) {
     282        if (!(key = talloc_asprintf(ctx, SHARE_SECURITY_DB_KEY_PREFIX_STR "%s", c_servicename))) {
     283                TALLOC_FREE(c_servicename);
    169284                DEBUG(0, ("talloc_asprintf failed\n"));
    170285                return NULL;
    171286        }
     287
     288        TALLOC_FREE(c_servicename);
    172289
    173290        data = dbwrap_fetch_bystring(share_db, talloc_tos(), key);
     
    187304                DEBUG(0, ("unmarshall_sec_desc failed: %s\n",
    188305                          nt_errstr(status)));
    189                 return NULL;
    190         }
    191 
    192         if (psd)
    193                 *psize = ndr_size_security_descriptor(psd, NULL, 0);
     306                return get_share_security_default(ctx, psize,
     307                                                  GENERIC_ALL_ACCESS);
     308        }
     309
     310        if (psd) {
     311                *psize = ndr_size_security_descriptor(psd, 0);
     312        } else {
     313                return get_share_security_default(ctx, psize,
     314                                                  GENERIC_ALL_ACCESS);
     315        }
    194316
    195317        return psd;
     
    200322 ********************************************************************/
    201323
    202 bool set_share_security(const char *share_name, SEC_DESC *psd)
    203 {
    204         TALLOC_CTX *frame;
     324bool set_share_security(const char *share_name, struct security_descriptor *psd)
     325{
     326        TALLOC_CTX *frame = talloc_stackframe();
    205327        char *key;
    206328        bool ret = False;
    207329        TDB_DATA blob;
    208330        NTSTATUS status;
     331        char *c_share_name = canonicalize_servicename(frame, share_name);
     332
     333        if (!c_share_name) {
     334                goto out;
     335        }
    209336
    210337        if (!share_info_db_init()) {
    211                 return False;
    212         }
    213 
    214         frame = talloc_stackframe();
     338                goto out;
     339        }
    215340
    216341        status = marshall_sec_desc(frame, psd, &blob.dptr, &blob.dsize);
     
    222347        }
    223348
    224         if (!(key = talloc_asprintf(frame, "SECDESC/%s", share_name))) {
     349        if (!(key = talloc_asprintf(frame, SHARE_SECURITY_DB_KEY_PREFIX_STR "%s", c_share_name))) {
    225350                DEBUG(0, ("talloc_asprintf failed\n"));
    226351                goto out;
     
    252377        char *key;
    253378        NTSTATUS status;
     379        char *c_servicename = canonicalize_servicename(talloc_tos(), servicename);
     380
     381        if (!c_servicename) {
     382                return NULL;
     383        }
    254384
    255385        if (!share_info_db_init()) {
     386                TALLOC_FREE(c_servicename);
    256387                return False;
    257388        }
    258389
    259         if (!(key = talloc_asprintf(talloc_tos(), "SECDESC/%s",
    260                                     servicename))) {
     390        if (!(key = talloc_asprintf(talloc_tos(), SHARE_SECURITY_DB_KEY_PREFIX_STR "%s",
     391                                    c_servicename))) {
     392                TALLOC_FREE(c_servicename);
    261393                return False;
    262394        }
     
    266398        if (!NT_STATUS_IS_OK(status)) {
    267399                DEBUG(0, ("delete_share_security: Failed to delete entry for "
    268                           "share %s: %s\n", servicename, nt_errstr(status)));
     400                          "share %s: %s\n", c_servicename, nt_errstr(status)));
     401                TALLOC_FREE(c_servicename);
    269402                return False;
    270403        }
    271404
     405        TALLOC_FREE(c_servicename);
    272406        return True;
    273407}
     
    277411********************************************************************/
    278412
    279 bool share_access_check(const NT_USER_TOKEN *token, const char *sharename,
    280                         uint32 desired_access)
     413bool share_access_check(const struct security_token *token,
     414                        const char *sharename,
     415                        uint32 desired_access,
     416                        uint32_t *pgranted)
    281417{
    282418        uint32 granted;
    283419        NTSTATUS status;
    284         SEC_DESC *psd = NULL;
     420        struct security_descriptor *psd = NULL;
    285421        size_t sd_size;
    286422
     
    294430
    295431        TALLOC_FREE(psd);
     432
     433        if (pgranted != NULL) {
     434                *pgranted = granted;
     435        }
    296436
    297437        return NT_STATUS_IS_OK(status);
     
    302442***************************************************************************/
    303443
    304 bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, SEC_DESC **ppsd)
     444bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, struct security_descriptor **ppsd)
    305445{
    306446        size_t s_size = 0;
    307447        const char *pacl = acl_str;
    308448        int num_aces = 0;
    309         SEC_ACE *ace_list = NULL;
    310         SEC_ACL *psa = NULL;
    311         SEC_DESC *psd = NULL;
     449        struct security_ace *ace_list = NULL;
     450        struct security_acl *psa = NULL;
     451        struct security_descriptor *psd = NULL;
    312452        size_t sd_size = 0;
    313453        int i;
     
    317457        /* If the acl string is blank return "Everyone:R" */
    318458        if (!*acl_str) {
    319                 SEC_DESC *default_psd = get_share_security_default(ctx, &s_size, GENERIC_READ_ACCESS);
     459                struct security_descriptor *default_psd = get_share_security_default(ctx, &s_size, GENERIC_READ_ACCESS);
    320460                if (!default_psd) {
    321461                        return False;
     
    330470        num_aces += count_chars(pacl,',');
    331471
    332         ace_list = TALLOC_ARRAY(ctx, SEC_ACE, num_aces);
     472        ace_list = TALLOC_ARRAY(ctx, struct security_ace, num_aces);
    333473        if (!ace_list) {
    334474                return False;
     
    339479                uint32 g_access;
    340480                uint32 s_access;
    341                 DOM_SID sid;
     481                struct dom_sid sid;
    342482                char *sidstr;
    343483                enum security_ace_type type = SEC_ACE_TYPE_ACCESS_ALLOWED;
  • trunk/server/source3/lib/smbconf/smbconf_init.c

    r414 r745  
    2222#include "lib/smbconf/smbconf_txt.h"
    2323#include "lib/smbconf/smbconf_reg.h"
     24#include "lib/smbconf/smbconf_init.h"
    2425
    2526/**
     
    3435 * -  "txt" or "file"
    3536 */
    36 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
     37sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
    3738                    const char *source)
    3839{
    39         WERROR werr;
     40        sbcErr err;
    4041        char *backend = NULL;
    4142        char *path = NULL;
     
    4445
    4546        if (conf_ctx == NULL) {
    46                 werr = WERR_INVALID_PARAM;
     47                err = SBC_ERR_INVALID_PARAM;
    4748                goto done;
    4849        }
    4950
    5051        if ((source == NULL) || (*source == '\0')) {
    51                 werr = WERR_INVALID_PARAM;
     52                err = SBC_ERR_INVALID_PARAM;
    5253                goto done;
    5354        }
     
    5556        backend = talloc_strdup(tmp_ctx, source);
    5657        if (backend == NULL) {
    57                 werr = WERR_NOMEM;
     58                err = SBC_ERR_NOMEM;
    5859                goto done;
    5960        }
     
    6970
    7071        if (strequal(backend, "registry") || strequal(backend, "reg")) {
    71                 werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
     72                err = smbconf_init_reg(mem_ctx, conf_ctx, path);
    7273        } else if (strequal(backend, "file") || strequal(backend, "txt")) {
    73                 werr = smbconf_init_txt(mem_ctx, conf_ctx, path);
     74                err = smbconf_init_txt(mem_ctx, conf_ctx, path);
    7475        } else if (sep == NULL) {
    7576                /*
     
    7879                 * string as a path argument.
    7980                 */
    80                 werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);
     81                err = smbconf_init_txt(mem_ctx, conf_ctx, backend);
    8182        } else {
    8283                /*
     
    8788                 * 'include = /path/to/file.%T'
    8889                 */
    89                 werr = smbconf_init_txt(mem_ctx, conf_ctx, source);
     90                err = smbconf_init_txt(mem_ctx, conf_ctx, source);
    9091        }
    9192
    9293done:
    9394        talloc_free(tmp_ctx);
    94         return werr;
     95        return err;
    9596}
  • trunk/server/source3/lib/smbconf/smbconf_init.h

    r414 r745  
    2727 * takes source string in the form of "backend:path"
    2828 */
    29 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
     29sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
    3030                    const char *source);
    3131
  • trunk/server/source3/lib/smbconf/smbconf_reg.c

    r414 r745  
    2020#include "includes.h"
    2121#include "lib/smbconf/smbconf_private.h"
     22#include "registry.h"
     23#include "registry/reg_api.h"
     24#include "registry/reg_backend_db.h"
     25#include "registry/reg_util_token.h"
     26#include "registry/reg_api_util.h"
     27#include "registry/reg_init_smbconf.h"
     28#include "lib/smbconf/smbconf_init.h"
     29#include "lib/smbconf/smbconf_reg.h"
     30#include "../libcli/registry/util_reg.h"
    2231
    2332#define INCLUDES_VALNAME "includes"
     
    7584 * Open a subkey of the base key (i.e a service)
    7685 */
    77 static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
     86static sbcErr smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
    7887                                           struct smbconf_ctx *ctx,
    7988                                           const char *servicename,
     
    8594        if (servicename == NULL) {
    8695                *key = rpd(ctx)->base_key;
    87                 return WERR_OK;
     96                return SBC_ERR_OK;
    8897        }
    8998        werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename,
    9099                           desired_access, key);
    91 
    92100        if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
    93                 werr = WERR_NO_SUCH_SERVICE;
    94         }
    95 
    96         return werr;
     101                return SBC_ERR_NO_SUCH_SERVICE;
     102        }
     103        if (!W_ERROR_IS_OK(werr)) {
     104                return SBC_ERR_NOMEM;
     105        }
     106
     107        return SBC_ERR_OK;
    97108}
    98109
     
    119130 * create a subkey of the base key (i.e. a service...)
    120131 */
    121 static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
     132static sbcErr smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
    122133                                             struct smbconf_ctx *ctx,
    123134                                             const char * subkeyname,
    124135                                             struct registry_key **newkey)
    125136{
    126         WERROR werr = WERR_OK;
     137        WERROR werr;
     138        sbcErr err = SBC_ERR_OK;
    127139        TALLOC_CTX *create_ctx;
    128140        enum winreg_CreateAction action = REG_ACTION_NONE;
     
    137149        if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
    138150                DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
    139                 werr = WERR_FILE_EXISTS;
     151                err = SBC_ERR_FILE_EXISTS;
    140152        }
    141153        if (!W_ERROR_IS_OK(werr)) {
    142154                DEBUG(5, ("Error creating key %s: %s\n",
    143155                         subkeyname, win_errstr(werr)));
     156                err = SBC_ERR_UNKNOWN_FAILURE;
    144157        }
    145158
    146159        talloc_free(create_ctx);
    147         return werr;
     160        return err;
    148161}
    149162
     
    151164 * add a value to a key.
    152165 */
    153 static WERROR smbconf_reg_set_value(struct registry_key *key,
     166static sbcErr smbconf_reg_set_value(struct registry_key *key,
    154167                                    const char *valname,
    155168                                    const char *valstr)
     
    157170        struct registry_value val;
    158171        WERROR werr = WERR_OK;
     172        sbcErr err;
    159173        char *subkeyname;
    160174        const char *canon_valname;
     
    172186                                  "parameter '%s'\n", valstr, valname));
    173187                }
    174                 werr = WERR_INVALID_PARAM;
     188                err = SBC_ERR_INVALID_PARAM;
    175189                goto done;
    176190        }
     
    179193                DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
    180194                          canon_valname));
    181                 werr = WERR_INVALID_PARAM;
     195                err = SBC_ERR_INVALID_PARAM;
    182196                goto done;
    183197        }
     
    187201                DEBUG(5, ("Invalid registry key '%s' given as "
    188202                          "smbconf section.\n", key->key->name));
    189                 werr = WERR_INVALID_PARAM;
     203                err = SBC_ERR_INVALID_PARAM;
    190204                goto done;
    191205        }
     
    197211                          "service definition ('%s').\n", canon_valname,
    198212                          subkeyname));
    199                 werr = WERR_INVALID_PARAM;
     213                err = SBC_ERR_INVALID_PARAM;
    200214                goto done;
    201215        }
     
    204218
    205219        val.type = REG_SZ;
    206         val.v.sz.str = CONST_DISCARD(char *, canon_valstr);
    207         val.v.sz.len = strlen(canon_valstr) + 1;
     220        if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) {
     221                err = SBC_ERR_NOMEM;
     222                goto done;
     223        }
    208224
    209225        werr = reg_setvalue(key, canon_valname, &val);
     
    212228                          "key '%s': %s\n",
    213229                          canon_valname, key->key->name, win_errstr(werr)));
    214         }
    215 
    216 done:
    217         return werr;
    218 }
    219 
    220 static WERROR smbconf_reg_set_multi_sz_value(struct registry_key *key,
     230                err = SBC_ERR_NOMEM;
     231                goto done;
     232        }
     233
     234        err = SBC_ERR_OK;
     235done:
     236        return err;
     237}
     238
     239static sbcErr smbconf_reg_set_multi_sz_value(struct registry_key *key,
    221240                                             const char *valname,
    222241                                             const uint32_t num_strings,
     
    224243{
    225244        WERROR werr;
     245        sbcErr err = SBC_ERR_OK;
    226246        struct registry_value *value;
    227247        uint32_t count;
    228248        TALLOC_CTX *tmp_ctx = talloc_stackframe();
     249        const char **array;
    229250
    230251        if (strings == NULL) {
    231                 werr = WERR_INVALID_PARAM;
     252                err = SBC_ERR_INVALID_PARAM;
     253                goto done;
     254        }
     255
     256        array = talloc_zero_array(tmp_ctx, const char *, num_strings + 1);
     257        if (array == NULL) {
     258                err = SBC_ERR_NOMEM;
    232259                goto done;
    233260        }
    234261
    235262        value = TALLOC_ZERO_P(tmp_ctx, struct registry_value);
     263        if (value == NULL) {
     264                err = SBC_ERR_NOMEM;
     265                goto done;
     266        }
    236267
    237268        value->type = REG_MULTI_SZ;
    238         value->v.multi_sz.num_strings = num_strings;
    239         value->v.multi_sz.strings = TALLOC_ARRAY(tmp_ctx, char *, num_strings);
    240         if (value->v.multi_sz.strings == NULL) {
    241                 werr = WERR_NOMEM;
    242                 goto done;
    243         }
     269
    244270        for (count = 0; count < num_strings; count++) {
    245                 value->v.multi_sz.strings[count] =
    246                         talloc_strdup(value->v.multi_sz.strings,
    247                                       strings[count]);
    248                 if (value->v.multi_sz.strings[count] == NULL) {
    249                         werr = WERR_NOMEM;
    250                         goto done;
    251                 }
     271                array[count] = talloc_strdup(value, strings[count]);
     272                if (array[count] == NULL) {
     273                        err = SBC_ERR_NOMEM;
     274                        goto done;
     275                }
     276        }
     277
     278        if (!push_reg_multi_sz(value, &value->data, array)) {
     279                err = SBC_ERR_NOMEM;
     280                goto done;
    252281        }
    253282
     
    256285                DEBUG(5, ("Error adding value '%s' to key '%s': %s\n",
    257286                          valname, key->key->name, win_errstr(werr)));
     287                err = SBC_ERR_ACCESS_DENIED;
    258288        }
    259289
    260290done:
    261291        talloc_free(tmp_ctx);
    262         return werr;
     292        return err;
    263293}
    264294
     
    282312        switch (value->type) {
    283313        case REG_DWORD:
    284                 result = talloc_asprintf(mem_ctx, "%d", value->v.dword);
     314                if (value->data.length >= 4) {
     315                        uint32_t v = IVAL(value->data.data, 0);
     316                        result = talloc_asprintf(mem_ctx, "%d", v);
     317                }
    285318                break;
    286319        case REG_SZ:
    287         case REG_EXPAND_SZ:
    288                 result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str);
     320        case REG_EXPAND_SZ: {
     321                const char *s;
     322                if (!pull_reg_sz(mem_ctx, &value->data, &s)) {
     323                        break;
     324                }
     325                result = talloc_strdup(mem_ctx, s);
    289326                break;
     327        }
    290328        case REG_MULTI_SZ: {
    291329                uint32 j;
    292                 for (j = 0; j < value->v.multi_sz.num_strings; j++) {
     330                const char **a = NULL;
     331                if (!pull_reg_multi_sz(mem_ctx, &value->data, &a)) {
     332                        break;
     333                }
     334                for (j = 0; a[j] != NULL; j++) {
    293335                        result = talloc_asprintf(mem_ctx, "%s\"%s\" ",
    294336                                                 result ? result : "" ,
    295                                                  value->v.multi_sz.strings[j]);
     337                                                 a[j]);
    296338                        if (result == NULL) {
    297339                                break;
     
    302344        case REG_BINARY:
    303345                result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
    304                                          (int)value->v.binary.length);
     346                                         (int)value->data.length);
    305347                break;
    306348        default:
     
    311353}
    312354
    313 static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
     355static sbcErr smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
    314356                                                struct registry_key *key,
    315357                                                uint32_t *num_includes,
     
    317359{
    318360        WERROR werr;
     361        sbcErr err;
    319362        uint32_t count;
    320363        struct registry_value *value = NULL;
    321364        char **tmp_includes = NULL;
     365        const char **array = NULL;
    322366        TALLOC_CTX *tmp_ctx = talloc_stackframe();
    323367
     
    326370                *num_includes = 0;
    327371                *includes = NULL;
    328                 werr = WERR_OK;
     372                err = SBC_ERR_OK;
    329373                goto done;
    330374        }
     
    332376        werr = reg_queryvalue(tmp_ctx, key, INCLUDES_VALNAME, &value);
    333377        if (!W_ERROR_IS_OK(werr)) {
     378                err = SBC_ERR_ACCESS_DENIED;
    334379                goto done;
    335380        }
     
    337382        if (value->type != REG_MULTI_SZ) {
    338383                /* wrong type -- ignore */
    339                 goto done;
    340         }
    341 
    342         for (count = 0; count < value->v.multi_sz.num_strings; count++)
    343         {
    344                 werr = smbconf_add_string_to_array(tmp_ctx,
     384                err = SBC_ERR_OK;
     385                goto done;
     386        }
     387
     388        if (!pull_reg_multi_sz(tmp_ctx, &value->data, &array)) {
     389                err = SBC_ERR_NOMEM;
     390                goto done;
     391        }
     392
     393        for (count = 0; array[count] != NULL; count++) {
     394                err = smbconf_add_string_to_array(tmp_ctx,
    345395                                        &tmp_includes,
    346396                                        count,
    347                                         value->v.multi_sz.strings[count]);
    348                 if (!W_ERROR_IS_OK(werr)) {
     397                                        array[count]);
     398                if (!SBC_ERROR_IS_OK(err)) {
    349399                        goto done;
    350400                }
     
    354404                *includes = talloc_move(mem_ctx, &tmp_includes);
    355405                if (*includes == NULL) {
    356                         werr = WERR_NOMEM;
     406                        err = SBC_ERR_NOMEM;
    357407                        goto done;
    358408                }
     
    363413        }
    364414
     415        err = SBC_ERR_OK;
    365416done:
    366417        talloc_free(tmp_ctx);
    367         return werr;
     418        return err;
    368419}
    369420
     
    372423 * and a list of value strings (ordered)
    373424 */
    374 static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
     425static sbcErr smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
    375426                                     struct registry_key *key,
    376427                                     uint32_t *num_values,
     
    380431        TALLOC_CTX *tmp_ctx = NULL;
    381432        WERROR werr = WERR_OK;
     433        sbcErr err;
    382434        uint32_t count;
    383435        struct registry_value *valvalue = NULL;
     
    392444            (value_strings == NULL))
    393445        {
    394                 werr = WERR_INVALID_PARAM;
     446                err = SBC_ERR_INVALID_PARAM;
    395447                goto done;
    396448        }
     
    409461                }
    410462
    411                 werr = smbconf_add_string_to_array(tmp_ctx,
    412                                                    &tmp_valnames,
    413                                                    tmp_num_values, valname);
    414                 if (!W_ERROR_IS_OK(werr)) {
     463                err = smbconf_add_string_to_array(tmp_ctx,
     464                                                  &tmp_valnames,
     465                                                  tmp_num_values, valname);
     466                if (!SBC_ERROR_IS_OK(err)) {
    415467                        goto done;
    416468                }
    417469
    418470                valstring = smbconf_format_registry_value(tmp_ctx, valvalue);
    419                 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
    420                                                    tmp_num_values, valstring);
    421                 if (!W_ERROR_IS_OK(werr)) {
     471                err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
     472                                                  tmp_num_values, valstring);
     473                if (!SBC_ERROR_IS_OK(err)) {
    422474                        goto done;
    423475                }
     
    425477        }
    426478        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
     479                err = SBC_ERR_NOMEM;
    427480                goto done;
    428481        }
    429482
    430483        /* now add the includes at the end */
    431         werr = smbconf_reg_get_includes_internal(tmp_ctx, key, &num_includes,
     484        err = smbconf_reg_get_includes_internal(tmp_ctx, key, &num_includes,
    432485                                                 &includes);
    433         if (!W_ERROR_IS_OK(werr)) {
    434                 goto done;
    435         }
     486        if (!SBC_ERROR_IS_OK(err)) {
     487                goto done;
     488        }
     489
    436490        for (count = 0; count < num_includes; count++) {
    437                 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,
    438                                                    tmp_num_values, "include");
    439                 if (!W_ERROR_IS_OK(werr)) {
    440                         goto done;
    441                 }
    442 
    443                 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
    444                                                    tmp_num_values,
    445                                                    includes[count]);
    446                 if (!W_ERROR_IS_OK(werr)) {
     491                err = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,
     492                                                  tmp_num_values, "include");
     493                if (!SBC_ERROR_IS_OK(err)) {
     494                        goto done;
     495                }
     496
     497                err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
     498                                                  tmp_num_values,
     499                                                  includes[count]);
     500                if (!SBC_ERROR_IS_OK(err)) {
    447501                        goto done;
    448502                }
     
    462516done:
    463517        talloc_free(tmp_ctx);
    464         return werr;
     518        return err;
    465519}
    466520
     
    491545 * delete all values from a key
    492546 */
    493 static WERROR smbconf_reg_delete_values(struct registry_key *key)
    494 {
    495         WERROR werr;
     547static sbcErr smbconf_reg_delete_values(struct registry_key *key)
     548{
     549        WERROR werr;
     550        sbcErr err;
    496551        char *valname;
    497552        struct registry_value *valvalue;
     
    506561                werr = reg_deletevalue(key, valname);
    507562                if (!W_ERROR_IS_OK(werr)) {
     563                        err = SBC_ERR_ACCESS_DENIED;
    508564                        goto done;
    509565                }
     
    514570                          key->key->name,
    515571                          win_errstr(werr)));
    516                 goto done;
    517         }
    518 
    519         werr = WERR_OK;
     572                err = SBC_ERR_ACCESS_DENIED;
     573                goto done;
     574        }
     575
     576        err = SBC_ERR_OK;
    520577
    521578done:
    522579        talloc_free(mem_ctx);
    523         return werr;
     580        return err;
    524581}
    525582
     
    533590 * initialize the registry smbconf backend
    534591 */
    535 static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
     592static sbcErr smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
    536593{
    537594        WERROR werr = WERR_OK;
    538         struct nt_user_token *token;
     595        sbcErr err;
     596        struct security_token *token;
    539597
    540598        if (path == NULL) {
     
    543601        ctx->path = talloc_strdup(ctx, path);
    544602        if (ctx->path == NULL) {
    545                 werr = WERR_NOMEM;
     603                err = SBC_ERR_NOMEM;
    546604                goto done;
    547605        }
     
    552610        if (!W_ERROR_IS_OK(werr)) {
    553611                DEBUG(1, ("Error creating admin token\n"));
     612                err = SBC_ERR_UNKNOWN_FAILURE;
    554613                goto done;
    555614        }
     
    558617        werr = registry_init_smbconf(path);
    559618        if (!W_ERROR_IS_OK(werr)) {
    560                 goto done;
    561         }
    562 
    563         werr = ctx->ops->open_conf(ctx);
    564         if (!W_ERROR_IS_OK(werr)) {
     619                err = SBC_ERR_BADFILE;
     620                goto done;
     621        }
     622
     623        err = ctx->ops->open_conf(ctx);
     624        if (!SBC_ERROR_IS_OK(err)) {
    565625                DEBUG(1, ("Error opening the registry.\n"));
    566626                goto done;
     
    571631                             token, &rpd(ctx)->base_key);
    572632        if (!W_ERROR_IS_OK(werr)) {
    573                 goto done;
    574         }
    575 
    576 done:
    577         return werr;
     633                err = SBC_ERR_UNKNOWN_FAILURE;
     634                goto done;
     635        }
     636
     637done:
     638        return err;
    578639}
    579640
     
    604665}
    605666
    606 static WERROR smbconf_reg_open(struct smbconf_ctx *ctx)
     667static sbcErr smbconf_reg_open(struct smbconf_ctx *ctx)
    607668{
    608669        WERROR werr;
    609670
    610671        if (rpd(ctx)->open) {
    611                 return WERR_OK;
     672                return SBC_ERR_OK;
    612673        }
    613674
    614675        werr = regdb_open();
    615         if (W_ERROR_IS_OK(werr)) {
    616                 rpd(ctx)->open = true;
    617         }
    618         return werr;
     676        if (!W_ERROR_IS_OK(werr)) {
     677                return SBC_ERR_BADFILE;
     678        }
     679
     680        rpd(ctx)->open = true;
     681        return SBC_ERR_OK;
    619682}
    620683
     
    646709        }
    647710
    648         if (!W_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {
     711        if (!SBC_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {
    649712                return;
    650713        }
     
    656719 * Drop the whole configuration (restarting empty) - registry version
    657720 */
    658 static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx)
     721static sbcErr smbconf_reg_drop(struct smbconf_ctx *ctx)
    659722{
    660723        char *path, *p;
    661724        WERROR werr = WERR_OK;
     725        sbcErr err = SBC_ERR_OK;
    662726        struct registry_key *parent_key = NULL;
    663727        struct registry_key *new_key = NULL;
    664728        TALLOC_CTX* mem_ctx = talloc_stackframe();
    665729        enum winreg_CreateAction action;
    666         struct nt_user_token *token;
     730        struct security_token *token;
    667731
    668732        werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
    669733        if (!W_ERROR_IS_OK(werr)) {
    670734                DEBUG(1, ("Error creating admin token\n"));
     735                err = SBC_ERR_UNKNOWN_FAILURE;
    671736                goto done;
    672737        }
     
    674739        path = talloc_strdup(mem_ctx, ctx->path);
    675740        if (path == NULL) {
    676                 werr = WERR_NOMEM;
     741                err = SBC_ERR_NOMEM;
    677742                goto done;
    678743        }
    679744        p = strrchr(path, '\\');
     745        if (p == NULL) {
     746                err = SBC_ERR_INVALID_PARAM;
     747                goto done;
     748        }
    680749        *p = '\0';
    681750        werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token,
    682751                             &parent_key);
    683 
    684         if (!W_ERROR_IS_OK(werr)) {
    685                 goto done;
    686         }
    687 
    688         werr = reg_deletekey_recursive(mem_ctx, parent_key, p+1);
    689 
    690         if (!W_ERROR_IS_OK(werr)) {
     752        if (!W_ERROR_IS_OK(werr)) {
     753                err = SBC_ERR_IO_FAILURE;
     754                goto done;
     755        }
     756
     757        werr = reg_deletekey_recursive(parent_key, p+1);
     758        if (!W_ERROR_IS_OK(werr)) {
     759                err = SBC_ERR_IO_FAILURE;
    691760                goto done;
    692761        }
     
    694763        werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE,
    695764                             &new_key, &action);
     765        if (!W_ERROR_IS_OK(werr)) {
     766                err = SBC_ERR_IO_FAILURE;
     767                goto done;
     768        }
    696769
    697770done:
    698771        talloc_free(mem_ctx);
    699         return werr;
     772        return err;
    700773}
    701774
     
    704777 * registry version.
    705778 */
    706 static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
     779static sbcErr smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
    707780                                          TALLOC_CTX *mem_ctx,
    708781                                          uint32_t *num_shares,
     
    712785        uint32_t added_count = 0;
    713786        TALLOC_CTX *tmp_ctx = NULL;
    714         WERROR werr = WERR_OK;
     787        WERROR werr;
     788        sbcErr err = SBC_ERR_OK;
    715789        char *subkey_name = NULL;
    716790        char **tmp_share_names = NULL;
    717791
    718792        if ((num_shares == NULL) || (share_names == NULL)) {
    719                 werr = WERR_INVALID_PARAM;
    720                 goto done;
     793                return SBC_ERR_INVALID_PARAM;
    721794        }
    722795
     
    726799
    727800        if (smbconf_reg_key_has_values(rpd(ctx)->base_key)) {
    728                 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
     801                err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
    729802                                                   0, NULL);
    730                 if (!W_ERROR_IS_OK(werr)) {
     803                if (!SBC_ERROR_IS_OK(err)) {
    731804                        goto done;
    732805                }
     
    736809        /* make sure "global" is always listed first */
    737810        if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
    738                 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
    739                                                    added_count, GLOBAL_NAME);
    740                 if (!W_ERROR_IS_OK(werr)) {
     811                err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
     812                                                  added_count, GLOBAL_NAME);
     813                if (!SBC_ERROR_IS_OK(err)) {
    741814                        goto done;
    742815                }
     
    754827                }
    755828
    756                 werr = smbconf_add_string_to_array(tmp_ctx,
     829                err = smbconf_add_string_to_array(tmp_ctx,
    757830                                                   &tmp_share_names,
    758831                                                   added_count,
    759832                                                   subkey_name);
    760                 if (!W_ERROR_IS_OK(werr)) {
     833                if (!SBC_ERROR_IS_OK(err)) {
    761834                        goto done;
    762835                }
     
    764837        }
    765838        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
    766                 goto done;
    767         }
    768         werr = WERR_OK;
     839                err = SBC_ERR_NO_MORE_ITEMS;
     840                goto done;
     841        }
     842        err = SBC_ERR_OK;
    769843
    770844        *num_shares = added_count;
     
    777851done:
    778852        talloc_free(tmp_ctx);
    779         return werr;
     853        return err;
    780854}
    781855
     
    787861{
    788862        bool ret = false;
    789         WERROR werr = WERR_OK;
     863        sbcErr err;
    790864        TALLOC_CTX *mem_ctx = talloc_stackframe();
    791865        struct registry_key *key = NULL;
    792866
    793         werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
    794                                             REG_KEY_READ, &key);
    795         if (W_ERROR_IS_OK(werr)) {
     867        err = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
     868                                           REG_KEY_READ, &key);
     869        if (SBC_ERROR_IS_OK(err)) {
    796870                ret = true;
    797871        }
     
    804878 * Add a service if it does not already exist - registry version
    805879 */
    806 static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
     880static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx,
    807881                                       const char *servicename)
    808882{
    809         WERROR werr;
     883        sbcErr err;
    810884        struct registry_key *key = NULL;
    811885
    812886        if (servicename == NULL) {
    813                 return WERR_OK;
    814         }
    815 
    816         werr = smbconf_reg_create_service_key(talloc_tos(), ctx,
    817                                               servicename, &key);
     887                return SBC_ERR_OK;
     888        }
     889
     890        err = smbconf_reg_create_service_key(talloc_tos(), ctx,
     891                                             servicename, &key);
    818892
    819893        talloc_free(key);
    820         return werr;
     894        return err;
    821895}
    822896
     
    824898 * get a definition of a share (service) from configuration.
    825899 */
    826 static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx,
     900static sbcErr smbconf_reg_get_share(struct smbconf_ctx *ctx,
    827901                                    TALLOC_CTX *mem_ctx,
    828902                                    const char *servicename,
    829903                                    struct smbconf_service **service)
    830904{
    831         WERROR werr = WERR_OK;
     905        sbcErr err;
    832906        struct registry_key *key = NULL;
    833907        struct smbconf_service *tmp_service = NULL;
    834908        TALLOC_CTX *tmp_ctx = talloc_stackframe();
    835909
    836         werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
    837                                             REG_KEY_READ, &key);
    838         if (!W_ERROR_IS_OK(werr)) {
     910        err = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
     911                                           REG_KEY_READ, &key);
     912        if (!SBC_ERROR_IS_OK(err)) {
    839913                goto done;
    840914        }
     
    842916        tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
    843917        if (tmp_service == NULL) {
    844                 werr =  WERR_NOMEM;
     918                err = SBC_ERR_NOMEM;
    845919                goto done;
    846920        }
     
    849923                tmp_service->name = talloc_strdup(tmp_service, servicename);
    850924                if (tmp_service->name == NULL) {
    851                         werr = WERR_NOMEM;
    852                         goto done;
    853                 }
    854         }
    855 
    856         werr = smbconf_reg_get_values(tmp_service, key,
    857                                       &(tmp_service->num_params),
    858                                       &(tmp_service->param_names),
    859                                       &(tmp_service->param_values));
    860 
    861         if (W_ERROR_IS_OK(werr)) {
     925                        err = SBC_ERR_NOMEM;
     926                        goto done;
     927                }
     928        }
     929
     930        err = smbconf_reg_get_values(tmp_service, key,
     931                                     &(tmp_service->num_params),
     932                                     &(tmp_service->param_names),
     933                                     &(tmp_service->param_values));
     934        if (SBC_ERROR_IS_OK(err)) {
    862935                *service = talloc_move(mem_ctx, &tmp_service);
    863936        }
     
    865938done:
    866939        talloc_free(tmp_ctx);
    867         return werr;
     940        return err;
    868941}
    869942
     
    871944 * delete a service from configuration
    872945 */
    873 static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx,
     946static sbcErr smbconf_reg_delete_share(struct smbconf_ctx *ctx,
    874947                                       const char *servicename)
    875948{
    876         WERROR werr = WERR_OK;
     949        WERROR werr;
     950        sbcErr err = SBC_ERR_OK;
    877951        TALLOC_CTX *mem_ctx = talloc_stackframe();
    878952
    879953        if (servicename != NULL) {
    880                 werr = reg_deletekey_recursive(mem_ctx, rpd(ctx)->base_key,
    881                                                servicename);
     954                werr = reg_deletekey_recursive(rpd(ctx)->base_key, servicename);
     955                if (!W_ERROR_IS_OK(werr)) {
     956                        err = SBC_ERR_ACCESS_DENIED;
     957                }
    882958        } else {
    883                 werr = smbconf_reg_delete_values(rpd(ctx)->base_key);
     959                err = smbconf_reg_delete_values(rpd(ctx)->base_key);
    884960        }
    885961
    886962        talloc_free(mem_ctx);
    887         return werr;
     963        return err;
    888964}
    889965
     
    891967 * set a configuration parameter to the value provided.
    892968 */
    893 static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
     969static sbcErr smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
    894970                                        const char *service,
    895971                                        const char *param,
    896972                                        const char *valstr)
    897973{
    898         WERROR werr;
     974        sbcErr err;
    899975        struct registry_key *key = NULL;
    900976        TALLOC_CTX *mem_ctx = talloc_stackframe();
    901977
    902         werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
    903                                             REG_KEY_WRITE, &key);
    904         if (!W_ERROR_IS_OK(werr)) {
    905                 goto done;
    906         }
    907 
    908         werr = smbconf_reg_set_value(key, param, valstr);
     978        err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
     979                                           REG_KEY_WRITE, &key);
     980        if (!SBC_ERROR_IS_OK(err)) {
     981                goto done;
     982        }
     983
     984        err = smbconf_reg_set_value(key, param, valstr);
    909985
    910986done:
    911987        talloc_free(mem_ctx);
    912         return werr;
     988        return err;
    913989}
    914990
     
    916992 * get the value of a configuration parameter as a string
    917993 */
    918 static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
     994static sbcErr smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
    919995                                        TALLOC_CTX *mem_ctx,
    920996                                        const char *service,
     
    923999{
    9241000        WERROR werr = WERR_OK;
     1001        sbcErr err;
    9251002        struct registry_key *key = NULL;
    9261003        struct registry_value *value = NULL;
    9271004
    928         werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
    929                                             REG_KEY_READ, &key);
    930         if (!W_ERROR_IS_OK(werr)) {
     1005        err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
     1006                                           REG_KEY_READ, &key);
     1007        if (!SBC_ERROR_IS_OK(err)) {
    9311008                goto done;
    9321009        }
    9331010
    9341011        if (!smbconf_reg_valname_valid(param)) {
    935                 werr = WERR_INVALID_PARAM;
     1012                err = SBC_ERR_INVALID_PARAM;
    9361013                goto done;
    9371014        }
    9381015
    9391016        if (!smbconf_value_exists(key, param)) {
    940                 werr = WERR_INVALID_PARAM;
     1017                err = SBC_ERR_INVALID_PARAM;
    9411018                goto done;
    9421019        }
     
    9441021        werr = reg_queryvalue(mem_ctx, key, param, &value);
    9451022        if (!W_ERROR_IS_OK(werr)) {
     1023                err = SBC_ERR_NOMEM;
    9461024                goto done;
    9471025        }
    9481026
    9491027        *valstr = smbconf_format_registry_value(mem_ctx, value);
    950 
    9511028        if (*valstr == NULL) {
    952                 werr = WERR_NOMEM;
     1029                err = SBC_ERR_NOMEM;
    9531030        }
    9541031
     
    9561033        talloc_free(key);
    9571034        talloc_free(value);
    958         return werr;
     1035        return err;
    9591036}
    9601037
     
    9621039 * delete a parameter from configuration
    9631040 */
    964 static WERROR smbconf_reg_delete_parameter(struct smbconf_ctx *ctx,
     1041static sbcErr smbconf_reg_delete_parameter(struct smbconf_ctx *ctx,
    9651042                                           const char *service,
    9661043                                           const char *param)
    9671044{
    9681045        struct registry_key *key = NULL;
    969         WERROR werr = WERR_OK;
     1046        WERROR werr;
     1047        sbcErr err;
    9701048        TALLOC_CTX *mem_ctx = talloc_stackframe();
    9711049
    972         werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
    973                                             REG_KEY_ALL, &key);
    974         if (!W_ERROR_IS_OK(werr)) {
     1050        err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
     1051                                           REG_KEY_ALL, &key);
     1052        if (!SBC_ERROR_IS_OK(err)) {
    9751053                goto done;
    9761054        }
    9771055
    9781056        if (!smbconf_reg_valname_valid(param)) {
    979                 werr = WERR_INVALID_PARAM;
     1057                err = SBC_ERR_INVALID_PARAM;
    9801058                goto done;
    9811059        }
    9821060
    9831061        if (!smbconf_value_exists(key, param)) {
    984                 werr = WERR_INVALID_PARAM;
     1062                err = SBC_ERR_OK;
    9851063                goto done;
    9861064        }
    9871065
    9881066        werr = reg_deletevalue(key, param);
     1067        if (!W_ERROR_IS_OK(werr)) {
     1068                err = SBC_ERR_ACCESS_DENIED;
     1069        }
    9891070
    9901071done:
    9911072        talloc_free(mem_ctx);
    992         return werr;
    993 }
    994 
    995 static WERROR smbconf_reg_get_includes(struct smbconf_ctx *ctx,
     1073        return err;
     1074}
     1075
     1076static sbcErr smbconf_reg_get_includes(struct smbconf_ctx *ctx,
    9961077                                       TALLOC_CTX *mem_ctx,
    9971078                                       const char *service,
     
    9991080                                       char ***includes)
    10001081{
    1001         WERROR werr;
     1082        sbcErr err;
    10021083        struct registry_key *key = NULL;
    10031084        TALLOC_CTX *tmp_ctx = talloc_stackframe();
    10041085
    1005         werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
    1006                                             REG_KEY_READ, &key);
    1007         if (!W_ERROR_IS_OK(werr)) {
    1008                 goto done;
    1009         }
    1010 
    1011         werr = smbconf_reg_get_includes_internal(mem_ctx, key, num_includes,
     1086        err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
     1087                                           REG_KEY_READ, &key);
     1088        if (!SBC_ERROR_IS_OK(err)) {
     1089                goto done;
     1090        }
     1091
     1092        err = smbconf_reg_get_includes_internal(mem_ctx, key, num_includes,
    10121093                                                 includes);
     1094        if (!SBC_ERROR_IS_OK(err)) {
     1095                goto done;
     1096        }
    10131097
    10141098done:
    10151099        talloc_free(tmp_ctx);
    1016         return werr;
    1017 }
    1018 
    1019 static WERROR smbconf_reg_set_includes(struct smbconf_ctx *ctx,
     1100        return err;
     1101}
     1102
     1103static sbcErr smbconf_reg_set_includes(struct smbconf_ctx *ctx,
    10201104                                       const char *service,
    10211105                                       uint32_t num_includes,
     
    10231107{
    10241108        WERROR werr = WERR_OK;
     1109        sbcErr err;
    10251110        struct registry_key *key = NULL;
    10261111        TALLOC_CTX *tmp_ctx = talloc_stackframe();
    10271112
    1028         werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
    1029                                             REG_KEY_ALL, &key);
    1030         if (!W_ERROR_IS_OK(werr)) {
     1113        err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
     1114                                           REG_KEY_ALL, &key);
     1115        if (!SBC_ERROR_IS_OK(err)) {
    10311116                goto done;
    10321117        }
     
    10341119        if (num_includes == 0) {
    10351120                if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
     1121                        err = SBC_ERR_OK;
    10361122                        goto done;
    10371123                }
    10381124                werr = reg_deletevalue(key, INCLUDES_VALNAME);
     1125                if (!W_ERROR_IS_OK(werr)) {
     1126                        err = SBC_ERR_ACCESS_DENIED;
     1127                        goto done;
     1128                }
    10391129        } else {
    1040                 werr = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME,
     1130                err = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME,
    10411131                                                      num_includes, includes);
    10421132        }
     
    10441134done:
    10451135        talloc_free(tmp_ctx);
    1046         return werr;
    1047 }
    1048 
    1049 static WERROR smbconf_reg_delete_includes(struct smbconf_ctx *ctx,
     1136        return err;
     1137}
     1138
     1139static sbcErr smbconf_reg_delete_includes(struct smbconf_ctx *ctx,
    10501140                                          const char *service)
    10511141{
    1052         WERROR werr = WERR_OK;
     1142        WERROR werr;
     1143        sbcErr err;
    10531144        struct registry_key *key = NULL;
    10541145        TALLOC_CTX *tmp_ctx = talloc_stackframe();
    10551146
    1056         werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
    1057                                             REG_KEY_ALL, &key);
    1058         if (!W_ERROR_IS_OK(werr)) {
     1147        err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
     1148                                           REG_KEY_ALL, &key);
     1149        if (!SBC_ERROR_IS_OK(err)) {
    10591150                goto done;
    10601151        }
    10611152
    10621153        if (!smbconf_value_exists(key, INCLUDES_VALNAME)) {
     1154                err = SBC_ERR_OK;
    10631155                goto done;
    10641156        }
    10651157
    10661158        werr = reg_deletevalue(key, INCLUDES_VALNAME);
    1067 
    1068 
     1159        if (!W_ERROR_IS_OK(werr)) {
     1160                err = SBC_ERR_ACCESS_DENIED;
     1161                goto done;
     1162        }
     1163
     1164        err = SBC_ERR_OK;
    10691165done:
    10701166        talloc_free(tmp_ctx);
    1071         return werr;
    1072 }
    1073 
    1074 static WERROR smbconf_reg_transaction_start(struct smbconf_ctx *ctx)
    1075 {
    1076         return regdb_transaction_start();
    1077 }
    1078 
    1079 static WERROR smbconf_reg_transaction_commit(struct smbconf_ctx *ctx)
    1080 {
    1081         return regdb_transaction_commit();
    1082 }
    1083 
    1084 static WERROR smbconf_reg_transaction_cancel(struct smbconf_ctx *ctx)
    1085 {
    1086         return regdb_transaction_cancel();
     1167        return err;
     1168}
     1169
     1170static sbcErr smbconf_reg_transaction_start(struct smbconf_ctx *ctx)
     1171{
     1172        WERROR werr;
     1173
     1174        werr = regdb_transaction_start();
     1175        if (!W_ERROR_IS_OK(werr)) {
     1176                return SBC_ERR_IO_FAILURE;
     1177        }
     1178
     1179        return SBC_ERR_OK;
     1180}
     1181
     1182static sbcErr smbconf_reg_transaction_commit(struct smbconf_ctx *ctx)
     1183{
     1184        WERROR werr;
     1185
     1186        werr = regdb_transaction_commit();
     1187        if (!W_ERROR_IS_OK(werr)) {
     1188                return SBC_ERR_IO_FAILURE;
     1189        }
     1190
     1191        return SBC_ERR_OK;
     1192}
     1193
     1194static sbcErr smbconf_reg_transaction_cancel(struct smbconf_ctx *ctx)
     1195{
     1196        WERROR werr;
     1197
     1198        werr = regdb_transaction_cancel();
     1199        if (!W_ERROR_IS_OK(werr)) {
     1200                return SBC_ERR_IO_FAILURE;
     1201        }
     1202
     1203        return SBC_ERR_OK;
    10871204}
    10881205
     
    11171234 * the only function that is exported from this module
    11181235 */
    1119 WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
     1236sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
    11201237                        const char *path)
    11211238{
  • trunk/server/source3/lib/smbconf/smbconf_reg.h

    r414 r745  
    2727 */
    2828
    29 WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
     29sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
    3030                        const char *path);
    3131
  • trunk/server/source3/lib/smbconf/testsuite.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "popt_common.h"
     22#include "lib/smbconf/smbconf.h"
     23#include "lib/smbconf/smbconf_init.h"
     24#include "lib/smbconf/smbconf_reg.h"
     25#include "lib/smbconf/smbconf_txt.h"
    2126
    2227static void print_strings(const char *prefix,
     
    3641static bool test_get_includes(struct smbconf_ctx *ctx)
    3742{
    38         WERROR werr;
     43        sbcErr err;
    3944        bool ret = false;
    4045        uint32_t num_includes = 0;
     
    4348
    4449        printf("TEST: get_includes\n");
    45         werr = smbconf_get_global_includes(ctx, mem_ctx,
    46                                            &num_includes, &includes);
    47         if (!W_ERROR_IS_OK(werr)) {
    48                 printf("FAIL: get_includes - %s\n", win_errstr(werr));
     50        err = smbconf_get_global_includes(ctx, mem_ctx,
     51                                          &num_includes, &includes);
     52        if (!SBC_ERROR_IS_OK(err)) {
     53                printf("FAIL: get_includes - %s\n", sbcErrorString(err));
    4954                goto done;
    5055        }
     
    6469static bool test_set_get_includes(struct smbconf_ctx *ctx)
    6570{
    66         WERROR werr;
     71        sbcErr err;
    6772        uint32_t count;
    6873        bool ret = false;
     
    7883        printf("TEST: set_get_includes\n");
    7984
    80         werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
    81         if (!W_ERROR_IS_OK(werr)) {
     85        err = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
     86        if (!SBC_ERROR_IS_OK(err)) {
    8287                printf("FAIL: get_set_includes (setting includes) - %s\n",
    83                        win_errstr(werr));
    84                 goto done;
    85         }
    86 
    87         werr = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
    88                                            &get_includes);
    89         if (!W_ERROR_IS_OK(werr)) {
     88                       sbcErrorString(err));
     89                goto done;
     90        }
     91
     92        err = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
     93                                          &get_includes);
     94        if (!SBC_ERROR_IS_OK(err)) {
    9095                printf("FAIL: get_set_includes (getting includes) - %s\n",
    91                        win_errstr(werr));
     96                       sbcErrorString(err));
    9297                goto done;
    9398        }
     
    121126static bool test_delete_includes(struct smbconf_ctx *ctx)
    122127{
    123         WERROR werr;
     128        sbcErr err;
    124129        bool ret = false;
    125130        const char *set_includes[] = {
     
    133138        printf("TEST: delete_includes\n");
    134139
    135         werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
    136         if (!W_ERROR_IS_OK(werr)) {
     140        err = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
     141        if (!SBC_ERROR_IS_OK(err)) {
    137142                printf("FAIL: delete_includes (setting includes) - %s\n",
    138                        win_errstr(werr));
    139                 goto done;
    140         }
    141 
    142         werr = smbconf_delete_global_includes(ctx);
    143         if (!W_ERROR_IS_OK(werr)) {
     143                       sbcErrorString(err));
     144                goto done;
     145        }
     146
     147        err = smbconf_delete_global_includes(ctx);
     148        if (!SBC_ERROR_IS_OK(err)) {
    144149                printf("FAIL: delete_includes (deleting includes) - %s\n",
    145                        win_errstr(werr));
    146                 goto done;
    147         }
    148 
    149         werr = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
    150                                            &get_includes);
    151         if (!W_ERROR_IS_OK(werr)) {
     150                       sbcErrorString(err));
     151                goto done;
     152        }
     153
     154        err = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
     155                                          &get_includes);
     156        if (!SBC_ERROR_IS_OK(err)) {
    152157                printf("FAIL: delete_includes (getting includes) - %s\n",
    153                        win_errstr(werr));
     158                       sbcErrorString(err));
    154159                goto done;
    155160        }
     
    160165        }
    161166
    162         werr = smbconf_delete_global_includes(ctx);
    163         if (!W_ERROR_IS_OK(werr)) {
     167        err = smbconf_delete_global_includes(ctx);
     168        if (!SBC_ERROR_IS_OK(err)) {
    164169                printf("FAIL: delete_includes (delete empty includes) - "
    165                        "%s\n", win_errstr(werr));
     170                       "%s\n", sbcErrorString(err));
    166171                goto done;
    167172        }
     
    199204static bool torture_smbconf_txt(void)
    200205{
    201         WERROR werr;
     206        sbcErr err;
    202207        bool ret = true;
    203208        const char *filename = "/tmp/smb.conf.smbconf_testsuite";
     
    213218
    214219        printf("TEST: init\n");
    215         werr = smbconf_init_txt(mem_ctx, &conf_ctx, filename);
    216         if (!W_ERROR_IS_OK(werr)) {
    217                 printf("FAIL: text backend failed: %s\n", win_errstr(werr));
     220        err = smbconf_init_txt(mem_ctx, &conf_ctx, filename);
     221        if (!SBC_ERROR_IS_OK(err)) {
     222                printf("FAIL: text backend failed: %s\n", sbcErrorString(err));
    218223                ret = false;
    219224                goto done;
     
    241246static bool torture_smbconf_reg(void)
    242247{
    243         WERROR werr;
     248        sbcErr err;
    244249        bool ret = true;
    245250        struct smbconf_ctx *conf_ctx = NULL;
     
    249254
    250255        printf("TEST: init\n");
    251         werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
    252         if (!W_ERROR_IS_OK(werr)) {
    253                 printf("FAIL: init failed: %s\n", win_errstr(werr));
     256        err = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
     257        if (!SBC_ERROR_IS_OK(err)) {
     258                printf("FAIL: init failed: %s\n", sbcErrorString(err));
    254259                ret = false;
    255260                goto done;
     
    290295
    291296        load_case_tables();
    292         dbf = x_stderr;
     297        setup_logging(argv[0], DEBUG_STDERR);
    293298
    294299        /* parse options */
  • trunk/server/source3/lib/smbldap.c

    r620 r745  
    2525#include "includes.h"
    2626#include "smbldap.h"
    27 
    28 #ifndef LDAP_OPT_SUCCESS
    29 #define LDAP_OPT_SUCCESS 0
    30 #endif
     27#include "secrets.h"
     28#include "../libcli/security/security.h"
    3129
    3230/* Try not to hit the up or down server forever */
     
    508506 ***********************************************************************/
    509507
    510  void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value)
     508static void smbldap_set_mod_internal(LDAPMod *** modlist, int modop, const char *attribute, const char *value, const DATA_BLOB *blob)
    511509{
    512510        LDAPMod **mods;
     
    559557        }
    560558
    561         if (value != NULL) {
     559        if (blob && (modop & LDAP_MOD_BVALUES)) {
     560                j = 0;
     561                if (mods[i]->mod_bvalues != NULL) {
     562                        for (; mods[i]->mod_bvalues[j] != NULL; j++);
     563                }
     564                mods[i]->mod_bvalues = SMB_REALLOC_ARRAY(mods[i]->mod_bvalues, struct berval *, j + 2);
     565
     566                if (mods[i]->mod_bvalues == NULL) {
     567                        smb_panic("smbldap_set_mod: out of memory!");
     568                        /* notreached. */
     569                }
     570
     571                mods[i]->mod_bvalues[j] = SMB_MALLOC_P(struct berval);
     572                SMB_ASSERT(mods[i]->mod_bvalues[j] != NULL);
     573
     574                mods[i]->mod_bvalues[j]->bv_val = (char *)memdup(blob->data, blob->length);
     575                SMB_ASSERT(mods[i]->mod_bvalues[j]->bv_val != NULL);
     576                mods[i]->mod_bvalues[j]->bv_len = blob->length;
     577
     578                mods[i]->mod_bvalues[j + 1] = NULL;
     579        } else if (value != NULL) {
    562580                char *utf8_value = NULL;
    563581                size_t converted_size;
     
    586604        }
    587605        *modlist = mods;
     606}
     607
     608 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value)
     609{
     610        smbldap_set_mod_internal(modlist, modop, attribute, value, NULL);
     611}
     612
     613 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *value)
     614{
     615        smbldap_set_mod_internal(modlist, modop | LDAP_MOD_BVALUES, attribute, NULL, value);
    588616}
    589617
     
    593621*********************************************************************/
    594622
    595  void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
    596                       LDAPMod ***mods,
    597                       const char *attribute, const char *newval)
     623static void smbldap_make_mod_internal(LDAP *ldap_struct, LDAPMessage *existing,
     624                                      LDAPMod ***mods,
     625                                      const char *attribute, int op,
     626                                      const char *newval,
     627                                      const DATA_BLOB *newblob)
    598628{
    599629        char oldval[2048]; /* current largest allowed value is mungeddial */
    600630        bool existed;
     631        DATA_BLOB oldblob = data_blob_null;
    601632
    602633        if (attribute == NULL) {
     
    607638
    608639        if (existing != NULL) {
    609                 existed = smbldap_get_single_attribute(ldap_struct, existing, attribute, oldval, sizeof(oldval));
     640                if (op & LDAP_MOD_BVALUES) {
     641                        existed = smbldap_talloc_single_blob(talloc_tos(), ldap_struct, existing, attribute, &oldblob);
     642                } else {
     643                        existed = smbldap_get_single_attribute(ldap_struct, existing, attribute, oldval, sizeof(oldval));
     644                }
    610645        } else {
    611646                existed = False;
     
    613648        }
    614649
    615         /* all of our string attributes are case insensitive */
    616 
    617         if (existed && newval && (StrCaseCmp(oldval, newval) == 0)) {
    618 
    619                 /* Believe it or not, but LDAP will deny a delete and
    620                    an add at the same time if the values are the
    621                    same... */
    622                 DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute));
    623                 return;
    624         }
    625 
    626650        if (existed) {
     651                bool equal = false;
     652                if (op & LDAP_MOD_BVALUES) {
     653                        equal = (newblob && (data_blob_cmp(&oldblob, newblob) == 0));
     654                } else {
     655                        /* all of our string attributes are case insensitive */
     656                        equal = (newval && (StrCaseCmp(oldval, newval) == 0));
     657                }
     658
     659                if (equal) {
     660                        /* Believe it or not, but LDAP will deny a delete and
     661                           an add at the same time if the values are the
     662                           same... */
     663                        DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute));
     664                        return;
     665                }
     666
    627667                /* There has been no value before, so don't delete it.
    628668                 * Here's a possible race: We might end up with
     
    636676                 * you could add new value */
    637677
    638                 DEBUG(10,("smbldap_make_mod: deleting attribute |%s| values |%s|\n", attribute, oldval));
    639                 smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, oldval);
     678                if (op & LDAP_MOD_BVALUES) {
     679                        DEBUG(10,("smbldap_make_mod: deleting attribute |%s| blob\n", attribute));
     680                        smbldap_set_mod_blob(mods, LDAP_MOD_DELETE, attribute, &oldblob);
     681                } else {
     682                        DEBUG(10,("smbldap_make_mod: deleting attribute |%s| values |%s|\n", attribute, oldval));
     683                        smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, oldval);
     684                }
    640685        }
    641686
     
    644689           the old value, should it exist. */
    645690
    646         if ((newval != NULL) && (strlen(newval) > 0)) {
    647                 DEBUG(10,("smbldap_make_mod: adding attribute |%s| value |%s|\n", attribute, newval));
    648                 smbldap_set_mod(mods, LDAP_MOD_ADD, attribute, newval);
    649         }
     691        if (op & LDAP_MOD_BVALUES) {
     692                if (newblob && newblob->length) {
     693                        DEBUG(10,("smbldap_make_mod: adding attribute |%s| blob\n", attribute));
     694                        smbldap_set_mod_blob(mods, LDAP_MOD_ADD, attribute, newblob);
     695                }
     696        } else {
     697                if ((newval != NULL) && (strlen(newval) > 0)) {
     698                        DEBUG(10,("smbldap_make_mod: adding attribute |%s| value |%s|\n", attribute, newval));
     699                        smbldap_set_mod(mods, LDAP_MOD_ADD, attribute, newval);
     700                }
     701        }
     702}
     703
     704 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
     705                      LDAPMod ***mods,
     706                      const char *attribute, const char *newval)
     707{
     708        smbldap_make_mod_internal(ldap_struct, existing, mods, attribute,
     709                                  0, newval, NULL);
     710}
     711
     712 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
     713                            LDAPMod ***mods,
     714                            const char *attribute, const DATA_BLOB *newblob)
     715{
     716        smbldap_make_mod_internal(ldap_struct, existing, mods, attribute,
     717                                  LDAP_MOD_BVALUES, NULL, newblob);
    650718}
    651719
     
    745813*******************************************************************/
    746814
    747 int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri)
     815static int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri)
    748816{
    749817        int rc;
     
    849917 *******************************************************************/
    850918
    851 int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version)
     919static int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version)
    852920{
    853921        int version;
     
    9621030{
    9631031        struct smbldap_state *ldap_state = arg;
     1032        struct timespec ts;
    9641033
    9651034        /** @TODO Should we be doing something to check what servers we rebind to?
     
    9941063        }
    9951064
    996         GetTimeOfDay(&ldap_state->last_rebind);
     1065        clock_gettime_mono(&ts);
     1066        ldap_state->last_rebind = convert_timespec_to_timeval(ts);
    9971067
    9981068        return 0;
     
    10141084                (struct smbldap_state *)arg;
    10151085        int rc;
     1086        struct timespec ts;
    10161087        int version;
    10171088
     
    10461117                                "setting last_rebind timestamp "
    10471118                                "(req: 0x%02x)\n", (unsigned int)request));
    1048                         GetTimeOfDay(&ldap_state->last_rebind);
     1119                        clock_gettime_mono(&ts);
     1120                        ldap_state->last_rebind = convert_timespec_to_timeval(ts);
    10491121                        break;
    10501122                default:
     
    11791251static void smbldap_idle_fn(struct event_context *event_ctx,
    11801252                            struct timed_event *te,
    1181                             struct timeval now,
     1253                            struct timeval now_abs,
    11821254                            void *private_data);
    11831255
     
    11911263        SMB_ASSERT(ldap_state);
    11921264
    1193         if ((ldap_state->ldap_struct != NULL) && ((ldap_state->last_ping + SMBLDAP_DONT_PING_TIME) < time(NULL))) {
     1265        if ((ldap_state->ldap_struct != NULL) && ((ldap_state->last_ping + SMBLDAP_DONT_PING_TIME) < time_mono(NULL))) {
    11941266
    11951267#ifdef HAVE_UNIXSOCKET
     
    12151287                        ldap_state->last_ping = (time_t)0;
    12161288                } else {
    1217                         ldap_state->last_ping = time(NULL);
     1289                        ldap_state->last_ping = time_mono(NULL);
    12181290                }
    12191291        }
     
    12331305
    12341306
    1235         ldap_state->last_ping = time(NULL);
     1307        ldap_state->last_ping = time_mono(NULL);
    12361308        ldap_state->pid = sys_getpid();
    12371309
     
    12851357                            int *attempts, time_t endtime)
    12861358{
    1287         time_t now = time(NULL);
     1359        time_t now = time_mono(NULL);
    12881360        int open_rc = LDAP_SERVER_DOWN;
    12891361
     
    13581430        int             attempts = 0;
    13591431        char           *utf8_filter;
    1360         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1432        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    13611433        struct          timeval timeout;
    13621434        size_t          converted_size;
     
    13691441        if (ldap_state->last_rebind.tv_sec > 0) {
    13701442                struct timeval  tval;
     1443                struct timespec ts;
    13711444                int64_t tdiff = 0;
    13721445                int             sleep_time = 0;
    13731446
    1374                 ZERO_STRUCT(tval);
    1375                 GetTimeOfDay(&tval);
     1447                clock_gettime_mono(&ts);
     1448                tval = convert_timespec_to_timeval(ts);
    13761449
    13771450                tdiff = usec_time_diff(&tval, &ldap_state->last_rebind);
     
    14071480
    14081481        got_alarm = 0;
    1409         CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
     1482        CatchSignal(SIGALRM, gotalarm_sig);
    14101483        alarm(lp_ldap_timeout());
    14111484        /* End setup timeout. */
     
    14421515
    14431516        /* Teardown timeout. */
    1444         CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
     1517        CatchSignal(SIGALRM, SIG_IGN);
    14451518        alarm(0);
    14461519
     
    15561629        int             attempts = 0;
    15571630        char           *utf8_dn;
    1558         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1631        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    15591632        size_t          converted_size;
    15601633
     
    16001673        int             attempts = 0;
    16011674        char           *utf8_dn;
    1602         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1675        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    16031676        size_t          converted_size;
    16041677
     
    16441717        int             attempts = 0;
    16451718        char           *utf8_dn;
    1646         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1719        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    16471720        size_t          converted_size;
    16481721
     
    16901763        int             rc = LDAP_SERVER_DOWN;
    16911764        int             attempts = 0;
    1692         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1765        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    16931766
    16941767        if (!ldap_state)
     
    17371810static void smbldap_idle_fn(struct event_context *event_ctx,
    17381811                            struct timed_event *te,
    1739                             struct timeval now,
     1812                            struct timeval now_abs,
    17401813                            void *private_data)
    17411814{
     
    17491822        }
    17501823
    1751         if ((state->last_use+SMBLDAP_IDLE_TIME) > now.tv_sec) {
     1824        if ((state->last_use+SMBLDAP_IDLE_TIME) > time_mono(NULL)) {
    17521825                DEBUG(10,("ldap connection not idle...\n"));
    17531826
     1827                /* this needs to be made monotonic clock aware inside tevent: */
    17541828                state->idle_event = event_add_timed(
    17551829                        event_ctx, state,
    1756                         timeval_add(&now, SMBLDAP_IDLE_TIME, 0),
     1830                        timeval_add(&now_abs, SMBLDAP_IDLE_TIME, 0),
    17571831                        smbldap_idle_fn,
    17581832                        private_data);
  • trunk/server/source3/lib/smbldap_util.c

    r414 r745  
    2525#include "includes.h"
    2626#include "smbldap.h"
     27#include "passdb.h"
    2728
    2829/**********************************************************************
  • trunk/server/source3/lib/substitute.c

    r414 r745  
    44   Copyright (C) Andrew Tridgell 1992-2000
    55   Copyright (C) Gerald Carter   2006
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2121
    2222#include "includes.h"
     23#include "system/passwd.h"
     24#include "secrets.h"
     25#include "auth.h"
     26
     27static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
     28                             const char *str);
    2329
    2430userdom_struct current_user_info;
     
    4248        static bool already_perm = false;
    4349        char *tmp_local_machine = NULL;
    44         char addr[INET6_ADDRSTRLEN];
    4550        size_t len;
     51
     52        if (already_perm) {
     53                return true;
     54        }
    4655
    4756        tmp_local_machine = SMB_STRDUP(local_name);
     
    5059        }
    5160        trim_char(tmp_local_machine,' ',' ');
    52 
    53         /*
    54          * Windows NT/2k uses "*SMBSERVER" and XP uses "*SMBSERV"
    55          * arrggg!!!
    56          */
    57 
    58         if (strequal(tmp_local_machine, "*SMBSERVER") ||
    59                         strequal(tmp_local_machine, "*SMBSERV") )  {
    60                 SAFE_FREE(local_machine);
    61                 local_machine = SMB_STRDUP(client_socket_addr(get_client_fd(),
    62                                         addr, sizeof(addr)) );
    63                 SAFE_FREE(tmp_local_machine);
    64                 return local_machine ? true : false;
    65         }
    66 
    67         if (already_perm) {
    68                 return true;
    69         }
    7061
    7162        SAFE_FREE(local_machine);
     
    202193                smb_user_name[len-1] = '$';
    203194        }
     195}
     196
     197static char sub_peeraddr[INET6_ADDRSTRLEN];
     198static const char *sub_peername = "";
     199static char sub_sockaddr[INET6_ADDRSTRLEN];
     200
     201void sub_set_socket_ids(const char *peeraddr, const char *peername,
     202                        const char *sockaddr)
     203{
     204        const char *addr = peeraddr;
     205
     206        if (strnequal(addr, "::ffff:", 7)) {
     207                addr += 7;
     208        }
     209        strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr));
     210
     211        sub_peername = SMB_STRDUP(peername);
     212        if (sub_peername == NULL) {
     213                sub_peername = sub_peeraddr;
     214        }
     215
     216        /*
     217         * Shouldn't we do the ::ffff: cancellation here as well? The
     218         * original code in alloc_sub_basic() did not do it, so I'm
     219         * leaving it out here as well for compatibility.
     220         */
     221        strlcpy(sub_sockaddr, sockaddr, sizeof(sub_sockaddr));
    204222}
    205223
     
    277295        r = p + 3;
    278296        copylen = q - r;
    279        
     297
    280298        /* reserve space for use later add %$() chars */
    281299        if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
    282300                return NULL;
    283301        }
    284        
     302
    285303        strncpy(envname,r,copylen);
    286304        envname[copylen] = '\0';
     
    302320        r = realloc_string_sub(str, envname, envval);
    303321        SAFE_FREE(envname);
    304                
     322
    305323        return r;
    306324}
     
    311329static char *longvar_domainsid( void )
    312330{
    313         DOM_SID sid;
     331        struct dom_sid sid;
    314332        fstring tmp;
    315333        char *sid_string;
    316        
     334
    317335        if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
    318336                return NULL;
    319337        }
    320        
     338
    321339        sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) );
    322        
     340
    323341        if ( !sid_string ) {
    324342                DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
    325343        }
    326        
     344
    327345        return sid_string;
    328346}
     
    344362{
    345363        int i;
    346        
     364
    347365        DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname));
    348        
     366
    349367        for ( i=0; longvar_table[i].name; i++ ) {
    350368                if ( strequal( longvar_table[i].name, varname ) ) {
     
    352370                }
    353371        }
    354        
     372
    355373        return NULL;
    356374}
     
    516534{
    517535        char *s;
    518        
     536
    519537        if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) {
    520538                strncpy( str, s, len );
    521539        }
    522        
     540
    523541        SAFE_FREE( s );
    524        
    525542}
    526543
     
    534551{
    535552        char *a, *t;
    536        
     553
    537554        if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) {
    538555                return NULL;
     
    546563****************************************************************************/
    547564
    548 char *alloc_sub_basic(const char *smb_name, const char *domain_name,
    549                       const char *str)
     565static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
     566                             const char *str)
    550567{
    551568        char *b, *p, *s, *r, *a_string;
    552569        fstring pidstr, vnnstr;
    553         char addr[INET6_ADDRSTRLEN];
    554570        const char *local_machine_name = get_local_machine_name();
    555571        TALLOC_CTX *tmp_ctx = NULL;
    556572
    557573        /* workaround to prevent a crash while looking at bug #687 */
    558        
     574
    559575        if (!str) {
    560576                DEBUG(0,("alloc_sub_basic: NULL source string!  This should not happen\n"));
    561577                return NULL;
    562578        }
    563        
     579
    564580        a_string = SMB_STRDUP(str);
    565581        if (a_string == NULL) {
     
    606622                        break;
    607623                case 'I' : {
    608                         int offset = 0;
    609                         client_addr(get_client_fd(), addr, sizeof(addr));
    610                         if (strnequal(addr,"::ffff:",7)) {
    611                                 offset = 7;
    612                         }
    613                         a_string = realloc_string_sub(a_string, "%I",
    614                                                       addr + offset);
     624                        a_string = realloc_string_sub(
     625                                a_string, "%I",
     626                                sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0");
    615627                        break;
    616628                }
    617629                case 'i':
    618                         a_string = realloc_string_sub( a_string, "%i",
    619                                         client_socket_addr(get_client_fd(), addr, sizeof(addr)) );
     630                        a_string = realloc_string_sub(
     631                                a_string, "%i",
     632                                sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0");
    620633                        break;
    621634                case 'L' :
     
    633646                        break;
    634647                case 'M' :
    635                         a_string = realloc_string_sub(a_string, "%M", client_name(get_client_fd()));
     648                        a_string = realloc_string_sub(a_string, "%M",
     649                                                      sub_peername);
    636650                        break;
    637651                case 'R' :
     
    723737                goto done;
    724738        }
    725        
     739
    726740        for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
    727                
     741
    728742                b = a_string;
    729                
     743
    730744                switch (*(p+1)) {
    731745                case 'U' :
     
    803817                return NULL;
    804818        }
    805        
     819
    806820        for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
    807                
     821
    808822                b = a_string;
    809                
     823
    810824                switch (*(p+1)) {
    811825                case 'N' :
     
    831845                        a_string = realloc_string_sub(a_string, "%u", user);
    832846                        break;
    833                        
     847
    834848                        /* Patch from jkf@soton.ac.uk Left the %N (NIS
    835849                         * server name) in standard_sub_basic as it is
     
    843857                                                      automount_path(servicename));
    844858                        break;
    845                        
     859
    846860                default:
    847861                        break;
     
    906920        return talloc_sub_advanced(ctx,
    907921                                lp_servicename(SNUM(conn)),
    908                                 conn->server_info->unix_name,
     922                                conn->session_info->unix_name,
    909923                                conn->connectpath,
    910                                 conn->server_info->utok.gid,
     924                                conn->session_info->utok.gid,
    911925                                get_smb_user_name(),
    912926                                "",
  • trunk/server/source3/lib/sysacls.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "system/passwd.h"
     24
     25#if defined(HAVE_POSIX_ACLS)
     26#include "modules/vfs_posixacl.h"
     27#endif
     28
     29#if defined(HAVE_TRU64_ACLS)
     30#include "modules/vfs_tru64acl.h"
     31#endif
     32
     33#if defined(HAVE_SOLARIS_ACLS) || defined(HAVE_UNIXWARE_ACLS)
     34#include "modules/vfs_solarisacl.h"
     35#endif
     36
     37#if defined(HAVE_HPUX_ACLS)
     38#include "modules/vfs_hpuxacl.h"
     39#endif
     40
     41#if defined(HAVE_IRIX_ACLS)
     42#include "modules/vfs_irixacl.h"
     43#endif
    2344
    2445#undef  DBGC_CLASS
  • trunk/server/source3/lib/sysquotas.c

    r414 r745  
    178178        {"xfs", sys_get_xfs_quota,      sys_set_xfs_quota},
    179179#endif /* HAVE_XFS_QUOTAS */
     180#ifdef HAVE_NFS_QUOTAS
     181        {"nfs", sys_get_nfs_quota,      sys_set_nfs_quota},
     182#endif /* HAVE_NFS_QUOTAS */
    180183        {NULL,  NULL,                   NULL}
    181184};
     
    301304                        DEBUG (3, ("Parsed output of get_quota, ...\n"));
    302305
    303 #ifdef LARGE_SMB_OFF_T
    304306                        DEBUGADD (5,(
    305307                                "qflags:%u curblocks:%llu softlimit:%llu hardlimit:%llu\n"
     
    310312                                (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
    311313                                (long long unsigned)dp->bsize));
    312 #else /* LARGE_SMB_OFF_T */
    313                         DEBUGADD (5,(
    314                                 "qflags:%u curblocks:%lu softlimit:%lu hardlimit:%lu\n"
    315                                 "curinodes:%lu isoftlimit:%lu ihardlimit:%lu bsize:%lu\n",
    316                                 dp->qflags,(long unsigned)dp->curblocks,
    317                                 (long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
    318                                 (long unsigned)dp->curinodes,
    319                                 (long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
    320                                 (long unsigned)dp->bsize));
    321 #endif /* LARGE_SMB_OFF_T */
    322314                        return 0;
    323315                }
     
    360352                }
    361353
    362 #ifdef LARGE_SMB_OFF_T
    363354                if (asprintf(&syscmd,
    364355                        "%s \"%s\" %d %d "
     
    371362                        return -1;
    372363                }
    373 #else /* LARGE_SMB_OFF_T */
    374                 if (asprintf(&syscmd,
    375                         "%s \"%s\" %d %d "
    376                         "%u %lu %lu "
    377                         "%lu %lu %lu ",
    378                         set_quota_command, path, qtype, _id, dp->qflags,
    379                         (long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
    380                         (long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
    381                         (long unsigned)dp->bsize) < 0) {
    382                         return -1;
    383                 }
    384 #endif /* LARGE_SMB_OFF_T */
    385364
    386365                DEBUG (3, ("get_quota: Running command %s\n", syscmd));
  • trunk/server/source3/lib/system.c

    r590 r745  
    2222
    2323#include "includes.h"
     24#include "system/syslog.h"
     25#include "system/capability.h"
     26#include "system/passwd.h"
     27#include "system/filesys.h"
    2428
    2529#ifdef HAVE_SYS_PRCTL_H
    2630#include <sys/prctl.h>
     31#endif
     32#ifdef __OS2__
     33#define pipe(A) os2_pipe(A)
    2734#endif
    2835
     
    124131        do {
    125132                ret = read(fd, buf, count);
    126         } while (ret == -1 && errno == EINTR);
     133#if defined(EWOULDBLOCK)
     134        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     135#else
     136        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     137#endif
    127138        return ret;
    128139}
     
    138149        do {
    139150                ret = write(fd, buf, count);
    140         } while (ret == -1 && errno == EINTR);
     151#if defined(EWOULDBLOCK)
     152        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     153#else
     154        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     155#endif
    141156        return ret;
    142157}
     
    163178        do {
    164179                ret = writev(fd, iov, iovcnt);
    165         } while (ret == -1 && errno == EINTR);
     180#if defined(EWOULDBLOCK)
     181        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     182#else
     183        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     184#endif
    166185        return ret;
    167186}
     
    208227
    209228/*******************************************************************
    210 A send wrapper that will deal with EINTR.
     229A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
    211230********************************************************************/
    212231
     
    217236        do {
    218237                ret = send(s, msg, len, flags);
    219         } while (ret == -1 && errno == EINTR);
    220         return ret;
    221 }
    222 
    223 /*******************************************************************
    224 A sendto wrapper that will deal with EINTR.
     238#if defined(EWOULDBLOCK)
     239        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     240#else
     241        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     242#endif
     243        return ret;
     244}
     245
     246/*******************************************************************
     247A sendto wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
    225248********************************************************************/
    226249
     
    231254        do {
    232255                ret = sendto(s, msg, len, flags, to, tolen);
    233         } while (ret == -1 && errno == EINTR);
    234         return ret;
    235 }
    236 
    237 /*******************************************************************
    238 A recv wrapper that will deal with EINTR.
     256#if defined(EWOULDBLOCK)
     257        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     258#else
     259        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     260#endif
     261        return ret;
     262}
     263
     264/*******************************************************************
     265A recv wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
    239266********************************************************************/
    240267
     
    245272        do {
    246273                ret = recv(fd, buf, count, flags);
    247         } while (ret == -1 && errno == EINTR);
     274#if defined(EWOULDBLOCK)
     275        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     276#else
     277        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     278#endif
    248279        return ret;
    249280}
     
    259290        do {
    260291                ret = recvfrom(s, buf, len, flags, from, fromlen);
    261         } while (ret == -1 && errno == EINTR);
     292#if defined(EWOULDBLOCK)
     293        } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     294#else
     295        } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     296#endif
    262297        return ret;
    263298}
     
    637672#elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
    638673        return posix_fallocate(fd, offset, len);
     674#elif defined(F_RESVSP64)
     675        /* this handles XFS on IRIX */
     676        struct flock64 fl;
     677        SMB_OFF_T new_len = offset + len;
     678        int ret;
     679        struct stat64 sbuf;
     680
     681        /* unlikely to get a too large file on a 64bit system but ... */
     682        if (new_len < 0)
     683                return EFBIG;
     684
     685        fl.l_whence = SEEK_SET;
     686        fl.l_start = offset;
     687        fl.l_len = len;
     688
     689        ret=fcntl(fd, F_RESVSP64, &fl);
     690
     691        if (ret != 0)
     692                return errno;
     693
     694        /* Make sure the file gets enlarged after we allocated space: */
     695        fstat64(fd, &sbuf);
     696        if (new_len > sbuf.st_size)
     697                ftruncate64(fd, new_len);
     698        return 0;
    639699#else
    640700        return ENOSYS;
     701#endif
     702}
     703
     704/*******************************************************************
     705 An fallocate() function that matches the semantics of the Linux one.
     706********************************************************************/
     707
     708#ifdef HAVE_LINUX_FALLOC_H
     709#include <linux/falloc.h>
     710#endif
     711
     712int sys_fallocate(int fd, enum vfs_fallocate_mode mode, SMB_OFF_T offset, SMB_OFF_T len)
     713{
     714#if defined(HAVE_LINUX_FALLOCATE64) || defined(HAVE_LINUX_FALLOCATE)
     715        int lmode;
     716        switch (mode) {
     717        case VFS_FALLOCATE_EXTEND_SIZE:
     718                lmode = 0;
     719                break;
     720        case VFS_FALLOCATE_KEEP_SIZE:
     721                lmode = FALLOC_FL_KEEP_SIZE;
     722                break;
     723        default:
     724                errno = EINVAL;
     725                return -1;
     726        }
     727#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LINUX_FALLOCATE64)
     728        return fallocate64(fd, lmode, offset, len);
     729#elif defined(HAVE_LINUX_FALLOCATE)
     730        return fallocate(fd, lmode, offset, len);
     731#endif
     732#else
     733        /* TODO - plumb in fallocate from other filesysetms like VXFS etc. JRA. */
     734        errno = ENOSYS;
     735        return -1;
    641736#endif
    642737}
     
    743838}
    744839
     840
     841#if HAVE_KERNEL_SHARE_MODES
     842#ifndef LOCK_MAND
     843#define LOCK_MAND       32      /* This is a mandatory flock */
     844#define LOCK_READ       64      /* ... Which allows concurrent read operations */
     845#define LOCK_WRITE      128     /* ... Which allows concurrent write operations */
     846#define LOCK_RW         192     /* ... Which allows concurrent read & write ops */
     847#endif
     848#endif
    745849
    746850/*******************************************************************
     
    778882#else
    779883        return opendir(name);
     884#endif
     885}
     886
     887/*******************************************************************
     888 An fdopendir wrapper that will deal with 64 bit filesizes.
     889 Ugly hack - we need dirfd for this to work correctly in the
     890 calling code.. JRA.
     891********************************************************************/
     892
     893SMB_STRUCT_DIR *sys_fdopendir(int fd)
     894{
     895#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FDOPENDIR64) && defined(HAVE_DIRFD)
     896        return fdopendir64(fd);
     897#elif defined(HAVE_FDOPENDIR) && defined(HAVE_DIRFD)
     898        return fdopendir(fd);
     899#else
     900        errno = ENOSYS;
     901        return NULL;
    780902#endif
    781903}
     
    10331155}
    10341156
     1157#ifndef NGROUPS_MAX
     1158#define NGROUPS_MAX 32 /* Guess... */
     1159#endif
     1160
    10351161/**************************************************************************
    10361162 Returns equivalent to NGROUPS_MAX - using sysconf if needed.
     
    10531179
    10541180#if defined(HAVE_BROKEN_GETGROUPS)
     1181
     1182#ifdef HAVE_BROKEN_GETGROUPS
     1183#define GID_T int
     1184#else
     1185#define GID_T gid_t
     1186#endif
     1187
    10551188static int sys_broken_getgroups(int setlen, gid_t *gidset)
    10561189{
     
    12321365
    12331366/**************************************************************************
    1234  Wrappers for setpwent(), getpwent() and endpwent()
    1235 ****************************************************************************/
    1236 
    1237 void sys_setpwent(void)
    1238 {
    1239         setpwent();
    1240 }
    1241 
    1242 struct passwd *sys_getpwent(void)
    1243 {
    1244         return getpwent();
    1245 }
    1246 
    1247 void sys_endpwent(void)
    1248 {
    1249         endpwent();
    1250 }
    1251 
    1252 /**************************************************************************
    1253  Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid()
    1254 ****************************************************************************/
    1255 
    1256 
    1257 struct passwd *sys_getpwnam(const char *name)
    1258 {
    1259         return getpwnam(name);
    1260 }
    1261 
    1262 struct passwd *sys_getpwuid(uid_t uid)
    1263 {
    1264         return getpwuid(uid);
    1265 }
    1266 
    1267 struct group *sys_getgrnam(const char *name)
    1268 {
    1269         return getgrnam(name);
    1270 }
    1271 
    1272 struct group *sys_getgrgid(gid_t gid)
    1273 {
    1274         return getgrgid(gid);
    1275 }
    1276 
    1277 /**************************************************************************
    12781367 Extract a command into an arg list.
    12791368****************************************************************************/
     
    14421531
    14431532        SAFE_FREE(entry);
    1444         SAFE_FREE(argl);
     1533        TALLOC_FREE(argl);
    14451534        close(pipe_fds[0]);
    14461535        close(pipe_fds[1]);
     
    17741863                }
    17751864                /* Shift results back, so we can prepend prefixes */
    1776                 buf = memmove(list + len, list, list_size);
     1865                buf = (char *)memmove(list + len, list, list_size);
    17771866
    17781867                for(i = 0; i < list_size; i += len + 1) {
     
    25832672}
    25842673#endif /* WITH_AIO */
    2585 
    2586 int sys_getpeereid( int s, uid_t *uid)
    2587 {
    2588 #if defined(HAVE_PEERCRED)
    2589         struct ucred cred;
    2590         socklen_t cred_len = sizeof(struct ucred);
    2591         int ret;
    2592 
    2593         ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &cred_len);
    2594         if (ret != 0) {
    2595                 return -1;
    2596         }
    2597 
    2598         if (cred_len != sizeof(struct ucred)) {
    2599                 errno = EINVAL;
    2600                 return -1;
    2601         }
    2602 
    2603         *uid = cred.uid;
    2604         return 0;
    2605 #else
    2606         errno = ENOSYS;
    2607         return -1;
    2608 #endif
    2609 }
    2610 
    2611 int sys_getnameinfo(const struct sockaddr *psa,
    2612                         socklen_t salen,
    2613                         char *host,
    2614                         size_t hostlen,
    2615                         char *service,
    2616                         size_t servlen,
    2617                         int flags)
    2618 {
    2619         /*
    2620          * For Solaris we must make sure salen is the
    2621          * correct length for the incoming sa_family.
    2622          */
    2623 
    2624         if (salen == sizeof(struct sockaddr_storage)) {
    2625                 salen = sizeof(struct sockaddr_in);
    2626 #if defined(HAVE_IPV6)
    2627                 if (psa->sa_family == AF_INET6) {
    2628                         salen = sizeof(struct sockaddr_in6);
    2629                 }
    2630 #endif
    2631         }
    2632         return getnameinfo(psa, salen, host, hostlen, service, servlen, flags);
    2633 }
    2634 
    2635 int sys_connect(int fd, const struct sockaddr * addr)
    2636 {
    2637         socklen_t salen = -1;
    2638 
    2639         if (addr->sa_family == AF_INET) {
    2640             salen = sizeof(struct sockaddr_in);
    2641         } else if (addr->sa_family == AF_UNIX) {
    2642             salen = sizeof(struct sockaddr_un);
    2643         }
    2644 #if defined(HAVE_IPV6)
    2645         else if (addr->sa_family == AF_INET6) {
    2646             salen = sizeof(struct sockaddr_in6);
    2647         }
    2648 #endif
    2649 
    2650         return connect(fd, addr, salen);
    2651 }
  • trunk/server/source3/lib/system_smbd.c

    r599 r745  
    2525
    2626#include "includes.h"
     27#include "system/passwd.h"
     28#include "nsswitch/winbind_client.h"
    2729
    2830#ifndef HAVE_GETGROUPLIST
     
    120122        }
    121123
    122         if (initgroups(user, gid) != 0) {
     124        if (initgroups(user, gid) == -1) {
    123125                DEBUG(0, ("getgrouplist_internals: initgroups() failed!\n"));
    124126                SAFE_FREE(gids_saved);
     
    206208bool getgroups_unix_user(TALLOC_CTX *mem_ctx, const char *user,
    207209                         gid_t primary_gid,
    208                          gid_t **ret_groups, size_t *p_ngroups)
    209 {
    210         size_t ngrp;
     210                         gid_t **ret_groups, uint32_t *p_ngroups)
     211{
     212        uint32_t ngrp;
    211213        int max_grp;
    212214        gid_t *temp_groups;
  • trunk/server/source3/lib/talloc_dict.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "dbwrap.h"
     22#include "talloc_dict.h"
     23#include "util_tdb.h"
    2124
    2225struct talloc_dict {
  • trunk/server/source3/lib/tallocmsg.c

    r414 r745  
    22   samba -- Unix SMB/CIFS implementation.
    33   Copyright (C) 2001, 2002 by Martin Pool
    4    
     4
    55   This program is free software; you can redistribute it and/or modify
    66   it under the terms of the GNU General Public License as published by
    77   the Free Software Foundation; either version 3 of the License, or
    88   (at your option) any later version.
    9    
     9
    1010   This program is distributed in the hope that it will be useful,
    1111   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1212   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1313   GNU General Public License for more details.
    14    
     14
    1515   You should have received a copy of the GNU General Public License
    1616   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    1818
    1919#include "includes.h"
     20#include "messages.h"
    2021
    2122/**
     
    5253        }
    5354
     55        if (strcmp(name, "char") == 0) {
     56                /*
     57                 * Print out the first 50 bytes of the string
     58                 */
     59                sprintf_append(state->mem_ctx, &state->s, &state->len,
     60                               &state->buflen,
     61                               "%*s%-30s contains %6lu bytes in %3lu blocks "
     62                               "(ref %d): %*s\n", depth*4, "",
     63                               name,
     64                               (unsigned long)talloc_total_size(ptr),
     65                               (unsigned long)talloc_total_blocks(ptr),
     66                               talloc_reference_count(ptr),
     67                               MIN(50, talloc_get_size(ptr)),
     68                               (char *)ptr);
     69                return;
     70        }
     71
    5472        sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
    5573                       "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n",
     
    7492
    7593        SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
    76        
     94
    7795        DEBUG(2,("Got POOL_USAGE\n"));
    7896
     
    91109                return;
    92110        }
    93        
     111
    94112        messaging_send_buf(msg_ctx, src, MSG_POOL_USAGE,
    95113                           (uint8 *)state.s, strlen(state.s)+1);
  • trunk/server/source3/lib/tdb_validate.c

    r590 r745  
    2020 */
    2121
     22#include "includes.h"
     23#include "system/filesys.h"
     24#include "util_tdb.h"
    2225#include "tdb_validate.h"
    23 #include "includes.h"
    2426
    2527/*
     
    282284
    283285        tmp_path = talloc_asprintf(ctx, "%s%s", dst_path, ".tmp");
     286        if (!tmp_path) {
     287                DEBUG(3, ("talloc fail\n"));
     288                goto done;
     289        }
     290
    284291        unlink(tmp_path);
    285292        dst_tdb = tdb_open_log(tmp_path,
     
    356363
    357364        dst_path = talloc_asprintf(ctx, "%s%s", path, suffix);
     365        if (dst_path == NULL) {
     366                DEBUG(3, ("error out of memory\n"));
     367                return ret;
     368        }
    358369
    359370        ret = (rename(path, dst_path) != 0);
     
    395406                char *rotate_path = talloc_asprintf(ctx, "%s%s", dst_path,
    396407                                                    rotate_suffix);
     408                if (rotate_path == NULL) {
     409                        DEBUG(10, ("talloc fail\n"));
     410                        return -1;
     411                }
    397412                DEBUG(10, ("backup of %s failed due to lack of space\n",
    398413                           src_path));
     
    451466
    452467        tdb_path_backup = talloc_asprintf(ctx, "%s%s", tdb_path, backup_suffix);
     468        if (!tdb_path_backup) {
     469                DEBUG(0, ("tdb_validate_and_backup: out of memory\n"));
     470                goto done;
     471        }
    453472
    454473        ret = tdb_validate_open(tdb_path, validate_fn);
  • trunk/server/source3/lib/tdb_validate.h

    r414 r745  
    2424
    2525#include "lib/replace/replace.h"
    26 #include "tdb.h"
     26#include <tdb.h>
    2727
    2828/**
  • trunk/server/source3/lib/time.c

    r480 r745  
    3737#endif
    3838
    39 /*******************************************************************
    40   create a 16 bit dos packed date
    41 ********************************************************************/
    42 static uint16_t make_dos_date1(struct tm *t)
    43 {
    44         uint16_t ret=0;
    45         ret = (((unsigned int)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1);
    46         ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5));
    47         return ret;
    48 }
    49 
    50 /*******************************************************************
    51   create a 16 bit dos packed time
    52 ********************************************************************/
    53 static uint16_t make_dos_time1(struct tm *t)
    54 {
    55         uint16_t ret=0;
    56         ret = ((((unsigned int)t->tm_min >> 3)&0x7) | (((unsigned int)t->tm_hour) << 3));
    57         ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5));
    58         return ret;
    59 }
    60 
    61 /*******************************************************************
    62   create a 32 bit dos packed date/time from some parameters
    63   This takes a GMT time and returns a packed localtime structure
    64 ********************************************************************/
    65 static uint32_t make_dos_date(time_t unixdate, int zone_offset)
    66 {
    67         struct tm *t;
    68         uint32_t ret=0;
    69 
    70         if (unixdate == 0) {
    71                 return 0;
    72         }
    73 
    74         unixdate -= zone_offset;
    75 
    76         t = gmtime(&unixdate);
    77         if (!t) {
    78                 return 0xFFFFFFFF;
    79         }
    80 
    81         ret = make_dos_date1(t);
    82         ret = ((ret&0xFFFF)<<16) | make_dos_time1(t);
    83 
    84         return ret;
    85 }
    8639
    8740/**
     
    9851**************************************************************/
    9952
    100 uint32_t convert_time_t_to_uint32(time_t t)
     53uint32_t convert_time_t_to_uint32_t(time_t t)
    10154{
    10255#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8))
     
    11164}
    11265
    113 time_t convert_uint32_to_time_t(uint32_t u)
     66time_t convert_uint32_t_to_time_t(uint32_t u)
    11467{
    11568#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8))
     
    177130}
    178131
    179 /****************************************************************************
    180  Return the date and time as a string
    181 ****************************************************************************/
    182 
    183 char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires)
    184 {
    185         fstring TimeBuf;
    186         time_t t;
    187         struct tm *tm;
    188 
    189         t = (time_t)tp->tv_sec;
    190         tm = localtime(&t);
    191         if (!tm) {
    192                 if (hires) {
    193                         slprintf(TimeBuf,
    194                                  sizeof(TimeBuf)-1,
    195                                  "%ld.%06ld seconds since the Epoch",
    196                                  (long)tp->tv_sec,
    197                                  (long)tp->tv_usec);
    198                 } else {
    199                         slprintf(TimeBuf,
    200                                  sizeof(TimeBuf)-1,
    201                                  "%ld seconds since the Epoch",
    202                                  (long)t);
    203                 }
    204         } else {
    205 #ifdef HAVE_STRFTIME
    206                 if (hires) {
    207                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
    208                         slprintf(TimeBuf+strlen(TimeBuf),
    209                                  sizeof(TimeBuf)-1 - strlen(TimeBuf),
    210                                  ".%06ld",
    211                                  (long)tp->tv_usec);
    212                 } else {
    213                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
    214                 }
    215 #else
    216                 if (hires) {
    217                         const char *asct = asctime(tm);
    218                         slprintf(TimeBuf,
    219                                  sizeof(TimeBuf)-1,
    220                                  "%s.%06ld",
    221                                  asct ? asct : "unknown",
    222                                  (long)tp->tv_usec);
    223                 } else {
    224                         const char *asct = asctime(tm);
    225                         fstrcpy(TimeBuf, asct ? asct : "unknown");
    226                 }
    227 #endif
    228         }
    229         return talloc_strdup(ctx, TimeBuf);
    230 }
    231 
    232 char *current_timestring(TALLOC_CTX *ctx, bool hires)
    233 {
    234         struct timeval tv;
    235 
    236         GetTimeOfDay(&tv);
    237         return timeval_string(ctx, &tv, hires);
    238 }
    239 
    240 /*******************************************************************
    241  Put a dos date into a buffer (time/date format).
    242  This takes GMT time and puts local time in the buffer.
    243 ********************************************************************/
    244 
    245 static void put_dos_date(char *buf,int offset,time_t unixdate, int zone_offset)
    246 {
    247         uint32_t x = make_dos_date(unixdate, zone_offset);
    248         SIVAL(buf,offset,x);
    249 }
    250 
    251 /*******************************************************************
    252  Put a dos date into a buffer (date/time format).
    253  This takes GMT time and puts local time in the buffer.
    254 ********************************************************************/
    255 
    256 static void put_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset)
    257 {
    258         uint32_t x = make_dos_date(unixdate, zone_offset);
    259         x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
    260         SIVAL(buf,offset,x);
    261 }
    262 
    263 /*******************************************************************
    264  Put a dos 32 bit "unix like" date into a buffer. This routine takes
    265  GMT and converts it to LOCAL time before putting it (most SMBs assume
    266  localtime for this sort of date)
    267 ********************************************************************/
    268 
    269 static void put_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset)
    270 {
    271         if (!null_mtime(unixdate)) {
    272                 unixdate -= zone_offset;
    273         }
    274         SIVAL(buf,offset,unixdate);
    275 }
    276 
    277 
    278132/***************************************************************************
    279133 Server versions of the above functions.
     
    282136void srv_put_dos_date(char *buf,int offset,time_t unixdate)
    283137{
    284         put_dos_date(buf, offset, unixdate, server_zone_offset);
     138        push_dos_date((uint8_t *)buf, offset, unixdate, server_zone_offset);
    285139}
    286140
    287141void srv_put_dos_date2(char *buf,int offset, time_t unixdate)
    288142{
    289         put_dos_date2(buf, offset, unixdate, server_zone_offset);
     143        push_dos_date2((uint8_t *)buf, offset, unixdate, server_zone_offset);
    290144}
    291145
    292146void srv_put_dos_date3(char *buf,int offset,time_t unixdate)
    293147{
    294         put_dos_date3(buf, offset, unixdate, server_zone_offset);
     148        push_dos_date3((uint8_t *)buf, offset, unixdate, server_zone_offset);
    295149}
    296150
     
    343197********************************************************************/
    344198
    345 static time_t make_unix_date(const void *date_ptr, int zone_offset)
     199time_t make_unix_date(const void *date_ptr, int zone_offset)
    346200{
    347201        uint32_t dos_date=0;
     
    389243{
    390244        time_t t = (time_t)IVAL(date_ptr,0);
    391         if (!null_mtime(t)) {
     245        if (!null_time(t)) {
    392246                t += zone_offset;
    393247        }
     
    440294struct timespec timespec_current(void)
    441295{
    442         struct timeval tv;
    443296        struct timespec ts;
    444         GetTimeOfDay(&tv);
    445         ts.tv_sec = tv.tv_sec;
    446         ts.tv_nsec = tv.tv_usec * 1000;
     297        clock_gettime(CLOCK_REALTIME, &ts);
    447298        return ts;
    448299}
     
    496347        struct timeval tv = convert_timespec_to_timeval(*ts);
    497348        *ts = convert_timeval_to_timespec(tv);
     349        while (ts->tv_nsec > 1000000000) {
     350                ts->tv_sec += 1;
     351                ts->tv_nsec -= 1000000000;
     352        }
    498353}
    499354
     
    517372}
    518373
    519 /***************************************************************************
    520  Client versions of the above functions.
    521 ***************************************************************************/
    522 
    523 void cli_put_dos_date(struct cli_state *cli, char *buf, int offset, time_t unixdate)
    524 {
    525         put_dos_date(buf, offset, unixdate, cli->serverzone);
    526 }
    527 
    528 void cli_put_dos_date2(struct cli_state *cli, char *buf, int offset, time_t unixdate)
    529 {
    530         put_dos_date2(buf, offset, unixdate, cli->serverzone);
    531 }
    532 
    533 void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unixdate)
    534 {
    535         put_dos_date3(buf, offset, unixdate, cli->serverzone);
    536 }
    537 
    538 time_t cli_make_unix_date(struct cli_state *cli, const void *date_ptr)
    539 {
    540         return make_unix_date(date_ptr, cli->serverzone);
    541 }
    542 
    543 time_t cli_make_unix_date2(struct cli_state *cli, const void *date_ptr)
    544 {
    545         return make_unix_date2(date_ptr, cli->serverzone);
    546 }
    547 
    548 time_t cli_make_unix_date3(struct cli_state *cli, const void *date_ptr)
    549 {
    550         return make_unix_date3(date_ptr, cli->serverzone);
    551 }
    552 
    553 /****************************************************************************
    554  Check if two NTTIMEs are the same.
    555 ****************************************************************************/
    556 
    557 bool nt_time_equals(const NTTIME *nt1, const NTTIME *nt2)
    558 {
    559         return (*nt1 == *nt2);
    560 }
    561 
    562374/*******************************************************************
    563375 Re-read the smb serverzone value.
     
    598410}
    599411
     412/**
     413 * @brief Get the startup time of the server.
     414 *
     415 * @param[out] ret_time A pointer to a timveal structure to set the startup
     416 *                      time.
     417 */
     418void get_startup_time(struct timeval *ret_time)
     419{
     420        ret_time->tv_sec = start_time_hires.tv_sec;
     421        ret_time->tv_usec = start_time_hires.tv_usec;
     422}
     423
     424
    600425/****************************************************************************
    601426 Convert a NTTIME structure to a time_t.
     
    740565
    741566/****************************************************************************
    742  Check if it's a null mtime.
    743 ****************************************************************************/
    744 
    745 bool null_mtime(time_t mtime)
    746 {
    747         if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1)
    748                 return true;
    749         return false;
    750 }
    751 
    752 /****************************************************************************
    753567 Utility function that always returns a const string even if localtime
    754568 and asctime fail.
  • trunk/server/source3/lib/tldap.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "tldap.h"
     22#include "../lib/util/asn1.h"
     23#include "../lib/tsocket/tsocket.h"
     24#include "../lib/util/tevent_unix.h"
     25
     26static int tldap_simple_recv(struct tevent_req *req);
    2127
    2228bool tevent_req_is_ldap_error(struct tevent_req *req, int *perr)
     
    419425        }
    420426
    421         state->iov.iov_base = blob.data;
     427        state->iov.iov_base = (void *)blob.data;
    422428        state->iov.iov_len = blob.length;
    423429
     
    506512
    507513        /*
    508          * We're the first ones, add the read_ldap request that waits for the
     514         * We're the first one, add the read_ldap request that waits for the
    509515         * answer from the server
    510516         */
     
    555561        struct tevent_req *req;
    556562        struct tldap_msg_state *state;
    557         struct tevent_context *ev;
    558563        struct asn1_data *data;
    559564        uint8_t *inbuf;
     
    614619        state->data = talloc_move(state, &data);
    615620
    616         ev = state->ev;
    617 
    618621        talloc_set_destructor(req, NULL);
    619622        tldap_msg_unset_pending(req);
     
    734737{
    735738        char *result = talloc_array(mem_ctx, char, blob.length+1);
     739
     740        if (result == NULL) {
     741                return NULL;
     742        }
     743
    736744        memcpy(result, blob.data, blob.length);
    737745        result[blob.length] = '\0';
     
    741749static bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx,
    742750                                         struct asn1_data *data,
    743                                          char **result)
     751                                         char **presult)
    744752{
    745753        DATA_BLOB string;
     754        char *result;
    746755        if (!asn1_read_OctetString(data, mem_ctx, &string))
    747756                return false;
    748         *result = blob2string_talloc(mem_ctx, string);
     757
     758        result = blob2string_talloc(mem_ctx, string);
     759
    749760        data_blob_free(&string);
     761
     762        if (result == NULL) {
     763                return false;
     764        }
     765        *presult = result;
    750766        return true;
    751767}
     
    869885int tldap_sasl_bind_recv(struct tevent_req *req)
    870886{
    871         int err;
    872 
    873         if (tevent_req_is_ldap_error(req, &err)) {
    874                 return err;
    875         }
    876         return TLDAP_SUCCESS;
     887        return tldap_simple_recv(req);
    877888}
    878889
     
    957968/*****************************************************************************/
    958969
    959 /*
    960  * This piece has a dependency on ldb, the ldb_parse_tree() function is used.
    961  * In case we want to separate out tldap, we need to copy or rewrite it.
     970/* can't use isalpha() as only a strict set is valid for LDAP */
     971
     972static bool tldap_is_alpha(char c)
     973{
     974        return (((c >= 'a') && (c <= 'z')) || \
     975                ((c >= 'A') && (c <= 'Z')));
     976}
     977
     978static bool tldap_is_adh(char c)
     979{
     980        return tldap_is_alpha(c) || isdigit(c) || (c == '-');
     981}
     982
     983#define TLDAP_FILTER_AND  ASN1_CONTEXT(0)
     984#define TLDAP_FILTER_OR   ASN1_CONTEXT(1)
     985#define TLDAP_FILTER_NOT  ASN1_CONTEXT(2)
     986#define TLDAP_FILTER_EQ   ASN1_CONTEXT(3)
     987#define TLDAP_FILTER_SUB  ASN1_CONTEXT(4)
     988#define TLDAP_FILTER_LE   ASN1_CONTEXT(5)
     989#define TLDAP_FILTER_GE   ASN1_CONTEXT(6)
     990#define TLDAP_FILTER_PRES ASN1_CONTEXT_SIMPLE(7)
     991#define TLDAP_FILTER_APX  ASN1_CONTEXT(8)
     992#define TLDAP_FILTER_EXT  ASN1_CONTEXT(9)
     993
     994#define TLDAP_SUB_INI ASN1_CONTEXT_SIMPLE(0)
     995#define TLDAP_SUB_ANY ASN1_CONTEXT_SIMPLE(1)
     996#define TLDAP_SUB_FIN ASN1_CONTEXT_SIMPLE(2)
     997
     998
     999/* oid's should be numerical only in theory,
     1000 * but apparently some broken servers may have alphanum aliases instead.
     1001 * Do like openldap libraries and allow alphanum aliases for oids, but
     1002 * do not allow Tagging options in that case.
    9621003 */
    963 
    964 #include "lib/ldb/include/ldb.h"
    965 #include "lib/ldb/include/ldb_errors.h"
    966 
    967 static bool ldap_push_filter(struct asn1_data *data,
    968                              struct ldb_parse_tree *tree)
    969 {
     1004static bool tldap_is_attrdesc(const char *s, int len, bool no_tagopts)
     1005{
     1006        bool is_oid = false;
     1007        bool dot = false;
    9701008        int i;
    9711009
    972         switch (tree->operation) {
    973         case LDB_OP_AND:
    974         case LDB_OP_OR:
    975                 asn1_push_tag(data,
    976                               ASN1_CONTEXT(tree->operation==LDB_OP_AND?0:1));
    977                 for (i=0; i<tree->u.list.num_elements; i++) {
    978                         if (!ldap_push_filter(data,
    979                                               tree->u.list.elements[i])) {
     1010        /* first char has stricter rules */
     1011        if (isdigit(*s)) {
     1012                is_oid = true;
     1013        } else if (!tldap_is_alpha(*s)) {
     1014                /* bad first char */
     1015                return false;
     1016        }
     1017
     1018        for (i = 1; i < len; i++) {
     1019
     1020                if (is_oid) {
     1021                        if (isdigit(s[i])) {
     1022                                dot = false;
     1023                                continue;
     1024                        }
     1025                        if (s[i] == '.') {
     1026                                if (dot) {
     1027                                        /* malformed */
     1028                                        return false;
     1029                                }
     1030                                dot = true;
     1031                                continue;
     1032                        }
     1033                } else {
     1034                        if (tldap_is_adh(s[i])) {
     1035                                continue;
     1036                        }
     1037                }
     1038
     1039                if (s[i] == ';') {
     1040                        if (no_tagopts) {
     1041                                /* no tagging options */
    9801042                                return false;
    9811043                        }
     1044                        if (dot) {
     1045                                /* malformed */
     1046                                return false;
     1047                        }
     1048                        if ((i + 1) == len) {
     1049                                /* malformed */
     1050                                return false;
     1051                        }
     1052
     1053                        is_oid = false;
     1054                        continue;
     1055                }
     1056        }
     1057
     1058        if (dot) {
     1059                /* malformed */
     1060                return false;
     1061        }
     1062
     1063        return true;
     1064}
     1065
     1066/* this function copies the value until the closing parenthesis is found. */
     1067static char *tldap_get_val(TALLOC_CTX *memctx,
     1068                           const char *value, const char **_s)
     1069{
     1070        const char *s = value;
     1071
     1072        /* find terminator */
     1073        while (*s) {
     1074                s = strchr(s, ')');
     1075                if (s && (*(s - 1) == '\\')) {
     1076                        continue;
     1077                }
     1078                break;
     1079        }
     1080        if (!s || !(*s == ')')) {
     1081                /* malformed filter */
     1082                return NULL;
     1083        }
     1084
     1085        *_s = s;
     1086
     1087        return talloc_strndup(memctx, value, s - value);
     1088}
     1089
     1090static int tldap_hex2char(const char *x)
     1091{
     1092        if (isxdigit(x[0]) && isxdigit(x[1])) {
     1093                const char h1 = x[0], h2 = x[1];
     1094                int c = 0;
     1095
     1096                if (h1 >= 'a') c = h1 - (int)'a' + 10;
     1097                else if (h1 >= 'A') c = h1 - (int)'A' + 10;
     1098                else if (h1 >= '0') c = h1 - (int)'0';
     1099                c = c << 4;
     1100                if (h2 >= 'a') c += h2 - (int)'a' + 10;
     1101                else if (h2 >= 'A') c += h2 - (int)'A' + 10;
     1102                else if (h2 >= '0') c += h2 - (int)'0';
     1103
     1104                return c;
     1105        }
     1106
     1107        return -1;
     1108}
     1109
     1110static bool tldap_find_first_star(const char *val, const char **star)
     1111{
     1112        const char *s;
     1113
     1114        for (s = val; *s; s++) {
     1115                switch (*s) {
     1116                case '\\':
     1117                        if (isxdigit(s[1]) && isxdigit(s[2])) {
     1118                                s += 2;
     1119                                break;
     1120                        }
     1121                        /* not hex based escape, check older syntax */
     1122                        switch (s[1]) {
     1123                        case '(':
     1124                        case ')':
     1125                        case '*':
     1126                        case '\\':
     1127                                s++;
     1128                                break;
     1129                        default:
     1130                                /* invalid escape sequence */
     1131                                return false;
     1132                        }
     1133                        break;
     1134                case ')':
     1135                        /* end of val, nothing found */
     1136                        *star = s;
     1137                        return true;
     1138
     1139                case '*':
     1140                        *star = s;
     1141                        return true;
     1142                }
     1143        }
     1144
     1145        /* string ended without closing parenthesis, filter is malformed */
     1146        return false;
     1147}
     1148
     1149static bool tldap_unescape_inplace(char *value, size_t *val_len)
     1150{
     1151        int c, i, p;
     1152
     1153        for (i = 0,p = 0; i < *val_len; i++) {
     1154
     1155                switch (value[i]) {
     1156                case '(':
     1157                case ')':
     1158                case '*':
     1159                        /* these must be escaped */
     1160                        return false;
     1161
     1162                case '\\':
     1163                        if (!value[i + 1]) {
     1164                                /* invalid EOL */
     1165                                return false;
     1166                        }
     1167                        i++;
     1168
     1169                        c = tldap_hex2char(&value[i]);
     1170                        if (c >= 0 && c < 256) {
     1171                                value[p] = c;
     1172                                i++;
     1173                                p++;
     1174                                break;
     1175                        }
     1176
     1177                        switch (value[i]) {
     1178                        case '(':
     1179                        case ')':
     1180                        case '*':
     1181                        case '\\':
     1182                                value[p] = value[i];
     1183                                p++;
     1184                        default:
     1185                                /* invalid */
     1186                                return false;
     1187                        }
     1188                        break;
     1189
     1190                default:
     1191                        value[p] = value[i];
     1192                        p++;
     1193                }
     1194        }
     1195        value[p] = '\0';
     1196        *val_len = p;
     1197        return true;
     1198}
     1199
     1200static bool tldap_push_filter_basic(struct tldap_context *ld,
     1201                                    struct asn1_data *data,
     1202                                    const char **_s);
     1203static bool tldap_push_filter_substring(struct tldap_context *ld,
     1204                                        struct asn1_data *data,
     1205                                        const char *val,
     1206                                        const char **_s);
     1207static bool tldap_push_filter_int(struct tldap_context *ld,
     1208                                  struct asn1_data *data,
     1209                                  const char **_s)
     1210{
     1211        const char *s = *_s;
     1212        bool ret;
     1213
     1214        if (*s != '(') {
     1215                tldap_debug(ld, TLDAP_DEBUG_ERROR,
     1216                            "Incomplete or malformed filter\n");
     1217                return false;
     1218        }
     1219        s++;
     1220
     1221        /* we are right after a parenthesis,
     1222         * find out what op we have at hand */
     1223        switch (*s) {
     1224        case '&':
     1225                tldap_debug(ld, TLDAP_DEBUG_TRACE, "Filter op: AND\n");
     1226                asn1_push_tag(data, TLDAP_FILTER_AND);
     1227                s++;
     1228                break;
     1229
     1230        case '|':
     1231                tldap_debug(ld, TLDAP_DEBUG_TRACE, "Filter op: OR\n");
     1232                asn1_push_tag(data, TLDAP_FILTER_OR);
     1233                s++;
     1234                break;
     1235
     1236        case '!':
     1237                tldap_debug(ld, TLDAP_DEBUG_TRACE, "Filter op: NOT\n");
     1238                asn1_push_tag(data, TLDAP_FILTER_NOT);
     1239                s++;
     1240                ret = tldap_push_filter_int(ld, data, &s);
     1241                if (!ret) {
     1242                        return false;
    9821243                }
    9831244                asn1_pop_tag(data);
    984                 break;
    985 
    986         case LDB_OP_NOT:
    987                 asn1_push_tag(data, ASN1_CONTEXT(2));
    988                 if (!ldap_push_filter(data, tree->u.isnot.child)) {
     1245                goto done;
     1246
     1247        case '(':
     1248        case ')':
     1249                tldap_debug(ld, TLDAP_DEBUG_ERROR,
     1250                            "Invalid parenthesis '%c'\n", *s);
     1251                return false;
     1252
     1253        case '\0':
     1254                tldap_debug(ld, TLDAP_DEBUG_ERROR,
     1255                            "Invalid filter termination\n");
     1256                return false;
     1257
     1258        default:
     1259                ret = tldap_push_filter_basic(ld, data, &s);
     1260                if (!ret) {
    9891261                        return false;
    9901262                }
     1263                goto done;
     1264        }
     1265
     1266        /* only and/or filters get here.
     1267         * go through the list of filters */
     1268
     1269        if (*s == ')') {
     1270                /* RFC 4526: empty and/or */
    9911271                asn1_pop_tag(data);
    992                 break;
    993 
    994         case LDB_OP_EQUALITY:
    995                 /* equality test */
    996                 asn1_push_tag(data, ASN1_CONTEXT(3));
    997                 asn1_write_OctetString(data, tree->u.equality.attr,
    998                                       strlen(tree->u.equality.attr));
    999                 asn1_write_OctetString(data, tree->u.equality.value.data,
    1000                                       tree->u.equality.value.length);
    1001                 asn1_pop_tag(data);
    1002                 break;
    1003 
    1004         case LDB_OP_SUBSTRING:
    1005                 /*
    1006                   SubstringFilter ::= SEQUENCE {
    1007                           type            AttributeDescription,
    1008                           -- at least one must be present
    1009                           substrings      SEQUENCE OF CHOICE {
    1010                                   initial [0] LDAPString,
    1011                                   any     [1] LDAPString,
    1012                                   final   [2] LDAPString } }
    1013                 */
    1014                 asn1_push_tag(data, ASN1_CONTEXT(4));
    1015                 asn1_write_OctetString(data, tree->u.substring.attr,
    1016                                        strlen(tree->u.substring.attr));
    1017                 asn1_push_tag(data, ASN1_SEQUENCE(0));
    1018                 i = 0;
    1019                 if (!tree->u.substring.start_with_wildcard) {
    1020                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(0));
    1021                         asn1_write_DATA_BLOB_LDAPString(
    1022                                 data, tree->u.substring.chunks[i]);
     1272                goto done;
     1273        }
     1274
     1275        while (*s) {
     1276                ret = tldap_push_filter_int(ld, data, &s);
     1277                if (!ret) {
     1278                        return false;
     1279                }
     1280
     1281                if (*s == ')') {
     1282                        /* end of list, return */
    10231283                        asn1_pop_tag(data);
    1024                         i++;
    1025                 }
    1026                 while (tree->u.substring.chunks[i]) {
    1027                         int ctx;
    1028 
    1029                         if ((!tree->u.substring.chunks[i + 1]) &&
    1030                             (tree->u.substring.end_with_wildcard == 0)) {
    1031                                 ctx = 2;
     1284                        break;
     1285                }
     1286        }
     1287
     1288done:
     1289        if (*s != ')') {
     1290                tldap_debug(ld, TLDAP_DEBUG_ERROR,
     1291                            "Incomplete or malformed filter\n");
     1292                return false;
     1293        }
     1294        s++;
     1295
     1296        if (data->has_error) {
     1297                return false;
     1298        }
     1299
     1300        *_s = s;
     1301        return true;
     1302}
     1303
     1304
     1305static bool tldap_push_filter_basic(struct tldap_context *ld,
     1306                                    struct asn1_data *data,
     1307                                    const char **_s)
     1308{
     1309        TALLOC_CTX *tmpctx = talloc_tos();
     1310        const char *s = *_s;
     1311        const char *e;
     1312        const char *eq;
     1313        const char *val;
     1314        const char *type;
     1315        const char *dn;
     1316        const char *rule;
     1317        const char *star;
     1318        size_t type_len = 0;
     1319        char *uval;
     1320        size_t uval_len;
     1321        bool write_octect = true;
     1322        bool ret;
     1323
     1324        eq = strchr(s, '=');
     1325        if (!eq) {
     1326                tldap_debug(ld, TLDAP_DEBUG_ERROR,
     1327                            "Invalid filter, missing equal sign\n");
     1328                return false;
     1329        }
     1330
     1331        val = eq + 1;
     1332        e = eq - 1;
     1333
     1334        switch (*e) {
     1335        case '<':
     1336                asn1_push_tag(data, TLDAP_FILTER_LE);
     1337                break;
     1338
     1339        case '>':
     1340                asn1_push_tag(data, TLDAP_FILTER_GE);
     1341                break;
     1342
     1343        case '~':
     1344                asn1_push_tag(data, TLDAP_FILTER_APX);
     1345                break;
     1346
     1347        case ':':
     1348                asn1_push_tag(data, TLDAP_FILTER_EXT);
     1349                write_octect = false;
     1350
     1351                type = NULL;
     1352                dn = NULL;
     1353                rule = NULL;
     1354
     1355                if (*s == ':') { /* [:dn]:rule:= value */
     1356                        if (s == e) {
     1357                                /* malformed filter */
     1358                                return false;
     1359                        }
     1360                        dn = s;
     1361                } else { /* type[:dn][:rule]:= value */
     1362                        type = s;
     1363                        dn = strchr(s, ':');
     1364                        type_len = dn - type;
     1365                        if (dn == e) { /* type:= value */
     1366                                dn = NULL;
     1367                        }
     1368                }
     1369                if (dn) {
     1370                        dn++;
     1371
     1372                        rule = strchr(dn, ':');
     1373                        if ((rule == dn + 1) || rule + 1 == e) {
     1374                                /* malformed filter, contains "::" */
     1375                                return false;
     1376                        }
     1377
     1378                        if (StrnCaseCmp(dn, "dn:", 3) != 0) {
     1379                                if (rule == e) {
     1380                                        rule = dn;
     1381                                        dn = NULL;
     1382                                } else {
     1383                                        /* malformed filter. With two
     1384                                         * optionals, the first must be "dn"
     1385                                         */
     1386                                        return false;
     1387                                }
    10321388                        } else {
    1033                                 ctx = 1;
     1389                                if (rule == e) {
     1390                                        rule = NULL;
     1391                                } else {
     1392                                        rule++;
     1393                                }
    10341394                        }
    1035                         asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(ctx));
    1036                         asn1_write_DATA_BLOB_LDAPString(
    1037                                 data, tree->u.substring.chunks[i]);
    1038                         asn1_pop_tag(data);
    1039                         i++;
    1040                 }
    1041                 asn1_pop_tag(data);
    1042                 asn1_pop_tag(data);
    1043                 break;
    1044 
    1045         case LDB_OP_GREATER:
    1046                 /* greaterOrEqual test */
    1047                 asn1_push_tag(data, ASN1_CONTEXT(5));
    1048                 asn1_write_OctetString(data, tree->u.comparison.attr,
    1049                                       strlen(tree->u.comparison.attr));
    1050                 asn1_write_OctetString(data, tree->u.comparison.value.data,
    1051                                       tree->u.comparison.value.length);
    1052                 asn1_pop_tag(data);
    1053                 break;
    1054 
    1055         case LDB_OP_LESS:
    1056                 /* lessOrEqual test */
    1057                 asn1_push_tag(data, ASN1_CONTEXT(6));
    1058                 asn1_write_OctetString(data, tree->u.comparison.attr,
    1059                                       strlen(tree->u.comparison.attr));
    1060                 asn1_write_OctetString(data, tree->u.comparison.value.data,
    1061                                       tree->u.comparison.value.length);
    1062                 asn1_pop_tag(data);
    1063                 break;
    1064 
    1065         case LDB_OP_PRESENT:
    1066                 /* present test */
    1067                 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(7));
    1068                 asn1_write_LDAPString(data, tree->u.present.attr);
    1069                 asn1_pop_tag(data);
    1070                 return !data->has_error;
    1071 
    1072         case LDB_OP_APPROX:
    1073                 /* approx test */
    1074                 asn1_push_tag(data, ASN1_CONTEXT(8));
    1075                 asn1_write_OctetString(data, tree->u.comparison.attr,
    1076                                       strlen(tree->u.comparison.attr));
    1077                 asn1_write_OctetString(data, tree->u.comparison.value.data,
    1078                                       tree->u.comparison.value.length);
    1079                 asn1_pop_tag(data);
    1080                 break;
    1081 
    1082         case LDB_OP_EXTENDED:
     1395                }
     1396
     1397                if (!type && !dn && !rule) {
     1398                        /* malformed filter, there must be at least one */
     1399                        return false;
     1400                }
     1401
    10831402                /*
    10841403                  MatchingRuleAssertion ::= SEQUENCE {
    10851404                  matchingRule    [1] MatchingRuleID OPTIONAL,
    1086                   type            [2] AttributeDescription OPTIONAL,
     1405                  type      [2] AttributeDescription OPTIONAL,
    10871406                  matchValue      [3] AssertionValue,
    10881407                  dnAttributes    [4] BOOLEAN DEFAULT FALSE
    10891408                  }
    10901409                */
    1091                 asn1_push_tag(data, ASN1_CONTEXT(9));
    1092                 if (tree->u.extended.rule_id) {
     1410
     1411                /* check and add rule */
     1412                if (rule) {
     1413                        ret = tldap_is_attrdesc(rule, e - rule, true);
     1414                        if (!ret) {
     1415                                return false;
     1416                        }
    10931417                        asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(1));
    1094                         asn1_write_LDAPString(data, tree->u.extended.rule_id);
     1418                        asn1_write(data, rule, e - rule);
    10951419                        asn1_pop_tag(data);
    10961420                }
    1097                 if (tree->u.extended.attr) {
     1421
     1422                /* check and add type */
     1423                if (type) {
     1424                        ret = tldap_is_attrdesc(type, type_len, false);
     1425                        if (!ret) {
     1426                                return false;
     1427                        }
    10981428                        asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(2));
    1099                         asn1_write_LDAPString(data, tree->u.extended.attr);
     1429                        asn1_write(data, type, type_len);
    11001430                        asn1_pop_tag(data);
    11011431                }
     1432
     1433                uval = tldap_get_val(tmpctx, val, _s);
     1434                if (!uval) {
     1435                        return false;
     1436                }
     1437                uval_len = *_s - val;
     1438                ret = tldap_unescape_inplace(uval, &uval_len);
     1439                if (!ret) {
     1440                        return false;
     1441                }
     1442
    11021443                asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(3));
    1103                 asn1_write_DATA_BLOB_LDAPString(data, &tree->u.extended.value);
     1444                asn1_write(data, uval, uval_len);
    11041445                asn1_pop_tag(data);
     1446
    11051447                asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(4));
    1106                 asn1_write_uint8(data, tree->u.extended.dnAttributes);
     1448                asn1_write_uint8(data, dn?1:0);
    11071449                asn1_pop_tag(data);
     1450                break;
     1451
     1452        default:
     1453                e = eq;
     1454
     1455                ret = tldap_is_attrdesc(s, e - s, false);
     1456                if (!ret) {
     1457                        return false;
     1458                }
     1459
     1460                if (strncmp(val, "*)", 2) == 0) {
     1461                        /* presence */
     1462                        asn1_push_tag(data, TLDAP_FILTER_PRES);
     1463                        asn1_write(data, s, e - s);
     1464                        *_s = val + 1;
     1465                        write_octect = false;
     1466                        break;
     1467                }
     1468
     1469                ret = tldap_find_first_star(val, &star);
     1470                if (!ret) {
     1471                        return false;
     1472                }
     1473                if (*star == '*') {
     1474                        /* substring */
     1475                        asn1_push_tag(data, TLDAP_FILTER_SUB);
     1476                        asn1_write_OctetString(data, s, e - s);
     1477                        ret = tldap_push_filter_substring(ld, data, val, &s);
     1478                        if (!ret) {
     1479                                return false;
     1480                        }
     1481                        *_s = s;
     1482                        write_octect = false;
     1483                        break;
     1484                }
     1485
     1486                /* if nothing else, then it is just equality */
     1487                asn1_push_tag(data, TLDAP_FILTER_EQ);
     1488                write_octect = true;
     1489                break;
     1490        }
     1491
     1492        if (write_octect) {
     1493                uval = tldap_get_val(tmpctx, val, _s);
     1494                if (!uval) {
     1495                        return false;
     1496                }
     1497                uval_len = *_s - val;
     1498                ret = tldap_unescape_inplace(uval, &uval_len);
     1499                if (!ret) {
     1500                        return false;
     1501                }
     1502
     1503                asn1_write_OctetString(data, s, e - s);
     1504                asn1_write_OctetString(data, uval, uval_len);
     1505        }
     1506
     1507        if (data->has_error) {
     1508                return false;
     1509        }
     1510        asn1_pop_tag(data);
     1511        return true;
     1512}
     1513
     1514static bool tldap_push_filter_substring(struct tldap_context *ld,
     1515                                        struct asn1_data *data,
     1516                                        const char *val,
     1517                                        const char **_s)
     1518{
     1519        TALLOC_CTX *tmpctx = talloc_tos();
     1520        bool initial = true;
     1521        const char *star;
     1522        char *chunk;
     1523        size_t chunk_len;
     1524        bool ret;
     1525
     1526        /*
     1527          SubstringFilter ::= SEQUENCE {
     1528                  type      AttributeDescription,
     1529                  -- at least one must be present
     1530                  substrings      SEQUENCE OF CHOICE {
     1531                          initial [0] LDAPString,
     1532                          any     [1] LDAPString,
     1533                          final   [2] LDAPString } }
     1534        */
     1535        asn1_push_tag(data, ASN1_SEQUENCE(0));
     1536
     1537        do {
     1538                ret = tldap_find_first_star(val, &star);
     1539                if (!ret) {
     1540                        return false;
     1541                }
     1542                chunk_len = star - val;
     1543
     1544                switch (*star) {
     1545                case '*':
     1546                        if (!initial && chunk_len == 0) {
     1547                                /* found '**', which is illegal */
     1548                                return false;
     1549                        }
     1550                        break;
     1551                case ')':
     1552                        if (initial) {
     1553                                /* no stars ?? */
     1554                                return false;
     1555                        }
     1556                        /* we are done */
     1557                        break;
     1558                default:
     1559                        /* ?? */
     1560                        return false;
     1561                }
     1562
     1563                if (initial && chunk_len == 0) {
     1564                        val = star + 1;
     1565                        initial = false;
     1566                        continue;
     1567                }
     1568
     1569                chunk = talloc_strndup(tmpctx, val, chunk_len);
     1570                if (!chunk) {
     1571                        return false;
     1572                }
     1573                ret = tldap_unescape_inplace(chunk, &chunk_len);
     1574                if (!ret) {
     1575                        return false;
     1576                }
     1577                switch (*star) {
     1578                case '*':
     1579                        if (initial) {
     1580                                asn1_push_tag(data, TLDAP_SUB_INI);
     1581                                initial = false;
     1582                        } else {
     1583                                asn1_push_tag(data, TLDAP_SUB_ANY);
     1584                        }
     1585                        break;
     1586                case ')':
     1587                        asn1_push_tag(data, TLDAP_SUB_FIN);
     1588                        break;
     1589                default:
     1590                        /* ?? */
     1591                        return false;
     1592                }
     1593                asn1_write(data, chunk, chunk_len);
    11081594                asn1_pop_tag(data);
    1109                 break;
    1110 
    1111         default:
     1595
     1596                val = star + 1;
     1597
     1598        } while (*star == '*');
     1599
     1600        *_s = star;
     1601
     1602        /* end of sequence */
     1603        asn1_pop_tag(data);
     1604        return true;
     1605}
     1606
     1607/* NOTE: although openldap libraries allow for spaces in some places, mosly
     1608 * around parenthesis, we do not allow any spaces (except in values of
     1609 * course) as I couldn't fine any place in RFC 4512 or RFC 4515 where
     1610 * leading or trailing spaces where allowed.
     1611 */
     1612static bool tldap_push_filter(struct tldap_context *ld,
     1613                              struct asn1_data *data,
     1614                              const char *filter)
     1615{
     1616        const char *s = filter;
     1617        bool ret;
     1618
     1619        ret = tldap_push_filter_int(ld, data, &s);
     1620        if (ret && *s) {
     1621                tldap_debug(ld, TLDAP_DEBUG_ERROR,
     1622                            "Incomplete or malformed filter\n");
    11121623                return false;
    11131624        }
    1114         return !data->has_error;
    1115 }
    1116 
    1117 static bool tldap_push_filter(struct asn1_data *data, const char *filter)
    1118 {
    1119         struct ldb_parse_tree *tree;
    1120         bool ret;
    1121 
    1122         tree = ldb_parse_tree(talloc_tos(), filter);
    1123         if (tree == NULL) {
    1124                 return false;
    1125         }
    1126         ret = ldap_push_filter(data, tree);
    1127         TALLOC_FREE(tree);
    11281625        return ret;
    11291626}
     
    11661663        asn1_write_BOOLEAN(state->out, attrsonly);
    11671664
    1168         if (!tldap_push_filter(state->out, filter)) {
     1665        if (!tldap_push_filter(ld, state->out, filter)) {
    11691666                goto encoding_error;
    11701667        }
     
    13451842        tevent_req_set_callback(req, tldap_search_cb, &state);
    13461843
     1844        if (!tevent_req_is_in_progress(req)) {
     1845                /* an error happend before sending */
     1846                if (tevent_req_is_ldap_error(req, &state.rc)) {
     1847                        goto fail;
     1848                }
     1849        }
     1850
    13471851        while (tevent_req_is_in_progress(req)
    13481852               && (state.rc == TLDAP_SUCCESS)) {
     
    14551959}
    14561960
    1457 bool tldap_entry_attributes(struct tldap_message *msg, int *num_attributes,
    1458                             struct tldap_attribute **attributes)
     1961bool tldap_entry_attributes(struct tldap_message *msg,
     1962                            struct tldap_attribute **attributes,
     1963                            int *num_attributes)
    14591964{
    14601965        if ((msg->dn == NULL) && (!tldap_parse_search_entry(msg))) {
     
    16282133
    16292134int tldap_add(struct tldap_context *ld, const char *dn,
    1630               int num_attributes, struct tldap_mod *attributes,
     2135              struct tldap_mod *attributes, int num_attributes,
    16312136              struct tldap_control *sctrls, int num_sctrls,
    16322137              struct tldap_control *cctrls, int num_cctrls)
     
    16682173                                     struct tldap_context *ld,
    16692174                                     const char *dn,
    1670                                      int num_mods, struct tldap_mod *mods,
     2175                                     struct tldap_mod *mods, int num_mods,
    16712176                                     struct tldap_control *sctrls,
    16722177                                     int num_sctrls,
     
    17282233
    17292234int tldap_modify(struct tldap_context *ld, const char *dn,
    1730                  int num_mods, struct tldap_mod *mods,
     2235                 struct tldap_mod *mods, int num_mods,
    17312236                 struct tldap_control *sctrls, int num_sctrls,
    17322237                 struct tldap_control *cctrls, int num_cctrls)
     
    17432248        }
    17442249
    1745         req = tldap_modify_send(frame, ev, ld, dn, num_mods, mods,
     2250        req = tldap_modify_send(frame, ev, ld, dn, mods, num_mods,
    17462251                                sctrls, num_sctrls, cctrls, num_cctrls);
    17472252        if (req == NULL) {
     
    18782383                *sctrls = NULL;
    18792384                *num_sctrls = 0;
     2385                return;
    18802386        }
    18812387        *sctrls = msg->res_sctrls;
  • trunk/server/source3/lib/tldap_util.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "tldap.h"
     22#include "tldap_util.h"
     23#include "../libcli/security/security.h"
     24#include "../lib/util/asn1.h"
     25#include "../librpc/ndr/libndr.h"
    2126
    2227bool tldap_entry_values(struct tldap_message *msg, const char *attribute,
    23                         int *num_values, DATA_BLOB **values)
     28                        DATA_BLOB **values, int *num_values)
    2429{
    2530        struct tldap_attribute *attributes;
    2631        int i, num_attributes;
    2732
    28         if (!tldap_entry_attributes(msg, &num_attributes, &attributes)) {
     33        if (!tldap_entry_attributes(msg, &attributes, &num_attributes)) {
    2934                return false;
    3035        }
     
    5257                return NULL;
    5358        }
    54         if (!tldap_entry_values(msg, attribute, &num_values, &values)) {
     59        if (!tldap_entry_values(msg, attribute, &values, &num_values)) {
    5560                return NULL;
    5661        }
     
    104109
    105110static bool tldap_add_blob_vals(TALLOC_CTX *mem_ctx, struct tldap_mod *mod,
    106                                 int num_newvals, DATA_BLOB *newvals)
     111                                DATA_BLOB *newvals, int num_newvals)
    107112{
    108113        int num_values = talloc_array_length(mod->values);
     
    129134}
    130135
    131 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
     136bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
     137                         struct tldap_mod **pmods, int *pnum_mods,
    132138                         int mod_op, const char *attrib,
    133                          int num_newvals, DATA_BLOB *newvals)
     139                         DATA_BLOB *newvals, int num_newvals)
    134140{
    135141        struct tldap_mod new_mod;
     
    145151        }
    146152
    147         num_mods = talloc_array_length(mods);
     153        num_mods = *pnum_mods;
    148154
    149155        for (i=0; i<num_mods; i++) {
     
    167173
    168174        if ((num_newvals != 0)
    169             && !tldap_add_blob_vals(mods, mod, num_newvals, newvals)) {
    170                 return false;
    171         }
    172 
    173         if (i == num_mods) {
     175            && !tldap_add_blob_vals(mods, mod, newvals, num_newvals)) {
     176                return false;
     177        }
     178
     179        if ((i == num_mods) && (talloc_array_length(mods) < num_mods + 1)) {
    174180                mods = talloc_realloc(talloc_tos(), mods, struct tldap_mod,
    175181                                      num_mods+1);
     
    181187
    182188        *pmods = mods;
     189        *pnum_mods += 1;
    183190        return true;
    184191}
    185192
    186 bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
     193bool tldap_add_mod_str(TALLOC_CTX *mem_ctx,
     194                       struct tldap_mod **pmods, int *pnum_mods,
    187195                       int mod_op, const char *attrib, const char *str)
    188196{
     
    196204        }
    197205
    198         ret = tldap_add_mod_blobs(mem_ctx, pmods, mod_op, attrib, 1, &utf8);
     206        ret = tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods, mod_op, attrib,
     207                                  &utf8, 1);
    199208        TALLOC_FREE(utf8.data);
    200209        return ret;
     
    203212static bool tldap_make_mod_blob_int(struct tldap_message *existing,
    204213                                    TALLOC_CTX *mem_ctx,
    205                                     int *pnum_mods, struct tldap_mod **pmods,
     214                                    struct tldap_mod **pmods, int *pnum_mods,
    206215                                    const char *attrib, DATA_BLOB newval,
    207216                                    int (*comparison)(const DATA_BLOB *d1,
     
    213222
    214223        if ((existing != NULL)
    215             && tldap_entry_values(existing, attrib, &num_values, &values)) {
     224            && tldap_entry_values(existing, attrib, &values, &num_values)) {
    216225
    217226                if (num_values > 1) {
     
    229238                   an add at the same time if the values are the
    230239                   same... */
    231                 DEBUG(10,("smbldap_make_mod_blob: attribute |%s| not "
     240                DEBUG(10,("tldap_make_mod_blob_int: attribute |%s| not "
    232241                          "changed.\n", attrib));
    233242                return true;
     
    243252                 * then you could add new value */
    244253
    245                 DEBUG(10, ("smbldap_make_mod_blob: deleting attribute |%s|\n",
     254                DEBUG(10, ("tldap_make_mod_blob_int: deleting attribute |%s|\n",
    246255                           attrib));
    247                 if (!tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_DELETE,
    248                                          attrib, 1, &oldval)) {
     256                if (!tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods,
     257                                         TLDAP_MOD_DELETE,
     258                                         attrib, &oldval, 1)) {
    249259                        return false;
    250260                }
     
    256266
    257267        if (newval.data != NULL) {
    258                 DEBUG(10, ("smbldap_make_mod: adding attribute |%s| value len "
     268                DEBUG(10, ("tldap_make_mod_blob_int: adding attribute |%s| value len "
    259269                           "%d\n", attrib, (int)newval.length));
    260                 if (!tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_ADD,
    261                                          attrib, 1, &newval)) {
     270                if (!tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods,
     271                                         TLDAP_MOD_ADD,
     272                                         attrib, &newval, 1)) {
    262273                        return false;
    263274                }
    264275        }
    265         *pnum_mods = talloc_array_length(*pmods);
    266276        return true;
    267277}
    268278
    269279bool tldap_make_mod_blob(struct tldap_message *existing, TALLOC_CTX *mem_ctx,
    270                          int *pnum_mods, struct tldap_mod **pmods,
     280                         struct tldap_mod **pmods, int *pnum_mods,
    271281                         const char *attrib, DATA_BLOB newval)
    272282{
    273         return tldap_make_mod_blob_int(existing, mem_ctx, pnum_mods, pmods,
     283        return tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods,
    274284                                       attrib, newval, data_blob_cmp);
    275285}
     
    299309
    300310bool tldap_make_mod_fmt(struct tldap_message *existing, TALLOC_CTX *mem_ctx,
    301                         int *pnum_mods, struct tldap_mod **pmods,
     311                        struct tldap_mod **pmods, int *pnum_mods,
    302312                        const char *attrib, const char *fmt, ...)
    303313{
     
    319329                blob.data = CONST_DISCARD(uint8_t *, newval);
    320330        }
    321         ret = tldap_make_mod_blob_int(existing, mem_ctx, pnum_mods, pmods,
     331        ret = tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods,
    322332                                      attrib, blob, compare_utf8_blobs);
    323333        TALLOC_FREE(newval);
     
    330340        char *res;
    331341
    332         ld_error = tldap_msg_diagnosticmessage(tldap_ctx_lastmsg(ld));
     342        if (ld != NULL) {
     343                ld_error = tldap_msg_diagnosticmessage(tldap_ctx_lastmsg(ld));
     344        }
    333345        res = talloc_asprintf(mem_ctx, "LDAP error %d (%s), %s", rc,
    334346                              tldap_err2string(rc),
     
    540552        DATA_BLOB *values;
    541553
    542         if (!tldap_entry_values(msg, attribute, &num_values, &values)) {
     554        if (!tldap_entry_values(msg, attribute, &values, &num_values)) {
    543555                return false;
    544556        }
  • trunk/server/source3/lib/username.c

    r414 r745  
    44   Copyright (C) Andrew Tridgell 1992-1998
    55   Copyright (C) Jeremy Allison 1997-2001.
    6    
     6   Copyright (C) Andrew Bartlett 2002
     7
    78   This program is free software; you can redistribute it and/or modify
    89   it under the terms of the GNU General Public License as published by
    910   the Free Software Foundation; either version 3 of the License, or
    1011   (at your option) any later version.
    11    
     12
    1213   This program is distributed in the hope that it will be useful,
    1314   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1415   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1516   GNU General Public License for more details.
    16    
     17
    1718   You should have received a copy of the GNU General Public License
    1819   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2021
    2122#include "includes.h"
     23#include "system/passwd.h"
     24#include "memcache.h"
     25#include "../lib/util/util_pw.h"
    2226
    2327/* internal functions */
     
    2933                                                 int N);
    3034
     35static struct passwd *getpwnam_alloc_cached(TALLOC_CTX *mem_ctx, const char *name)
     36{
     37        struct passwd *pw, *for_cache;
     38
     39        pw = (struct passwd *)memcache_lookup_talloc(
     40                NULL, GETPWNAM_CACHE, data_blob_string_const_null(name));
     41        if (pw != NULL) {
     42                return tcopy_passwd(mem_ctx, pw);
     43        }
     44
     45        pw = sys_getpwnam(name);
     46        if (pw == NULL) {
     47                return NULL;
     48        }
     49
     50        for_cache = tcopy_passwd(talloc_tos(), pw);
     51        if (for_cache == NULL) {
     52                return NULL;
     53        }
     54
     55        memcache_add_talloc(NULL, GETPWNAM_CACHE,
     56                        data_blob_string_const_null(name), &for_cache);
     57
     58        return tcopy_passwd(mem_ctx, pw);
     59}
     60
     61/****************************************************************************
     62 Flush all cached passwd structs.
     63****************************************************************************/
     64
     65void flush_pwnam_cache(void)
     66{
     67        memcache_flush(NULL, GETPWNAM_CACHE);
     68}
     69
    3170/****************************************************************************
    3271 Get a users home directory.
     
    76115        strlower_m(user2);
    77116        DEBUG(5,("Trying _Get_Pwnam(), username as lowercase is %s\n",user2));
    78         ret = getpwnam_alloc(mem_ctx, user2);
     117        ret = getpwnam_alloc_cached(mem_ctx, user2);
    79118        if(ret)
    80119                goto done;
     
    84123                DEBUG(5,("Trying _Get_Pwnam(), username as given is %s\n",
    85124                         user));
    86                 ret = getpwnam_alloc(mem_ctx, user);
     125                ret = getpwnam_alloc_cached(mem_ctx, user);
    87126                if(ret)
    88127                        goto done;
     
    94133                DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n",
    95134                         user2));
    96                 ret = getpwnam_alloc(mem_ctx, user2);
     135                ret = getpwnam_alloc_cached(mem_ctx, user2);
    97136                if(ret)
    98137                        goto done;
     
    103142        DEBUG(5,("Checking combinations of %d uppercase letters in %s\n",
    104143                 lp_usernamelevel(), user2));
    105         ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc,
     144        ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc_cached,
    106145                                        lp_usernamelevel());
    107146
     
    122161{
    123162        fstring user2;
    124         struct passwd *ret;
    125163
    126164        if ( *user == '\0' ) {
     
    133171        DEBUG(5,("Finding user %s\n", user));
    134172
    135         ret = Get_Pwnam_internals(mem_ctx, user, user2);
    136        
    137         return ret; 
     173        return Get_Pwnam_internals(mem_ctx, user, user2);
    138174}
    139175
     
    161197        for (i=offset;i<(len-(N-1));i++) {
    162198                char c = s[i];
    163                 if (!islower_ascii((int)c))
     199                if (!islower_m((int)c))
    164200                        continue;
    165                 s[i] = toupper_ascii(c);
     201                s[i] = toupper_m(c);
    166202                ret = uname_string_combinations2(s, mem_ctx, i+1, fn, N-1);
    167203                if(ret)
  • trunk/server/source3/lib/util.c

    r599 r745  
    1212   the Free Software Foundation; either version 3 of the License, or
    1313   (at your option) any later version.
    14    
     14
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    19    
     19
    2020   You should have received a copy of the GNU General Public License
    2121   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323
    2424#include "includes.h"
     25#include "system/passwd.h"
     26#include "system/filesys.h"
     27#include "util_tdb.h"
     28#include "ctdbd_conn.h"
     29#include "../lib/util/util_pw.h"
     30#include "messages.h"
    2531
    2632extern char *global_clobber_region_function;
     
    7480***********************************************************************/
    7581
    76 static char *smb_myname;
    77 static char *smb_myworkgroup;
    7882static char *smb_scope;
    7983static int smb_num_netbios_names;
    8084static char **smb_my_netbios_names;
    81 
    82 /***********************************************************************
    83  Allocate and set myname. Ensure upper case.
    84 ***********************************************************************/
    85 
    86 bool set_global_myname(const char *myname)
    87 {
    88         SAFE_FREE(smb_myname);
    89         smb_myname = SMB_STRDUP(myname);
    90         if (!smb_myname)
    91                 return False;
    92         strupper_m(smb_myname);
    93         return True;
    94 }
    95 
    96 const char *global_myname(void)
    97 {
    98         return smb_myname;
    99 }
    100 
    101 /***********************************************************************
    102  Allocate and set myworkgroup. Ensure upper case.
    103 ***********************************************************************/
    104 
    105 bool set_global_myworkgroup(const char *myworkgroup)
    106 {
    107         SAFE_FREE(smb_myworkgroup);
    108         smb_myworkgroup = SMB_STRDUP(myworkgroup);
    109         if (!smb_myworkgroup)
    110                 return False;
    111         strupper_m(smb_myworkgroup);
    112         return True;
    113 }
    114 
    115 const char *lp_workgroup(void)
    116 {
    117         return smb_myworkgroup;
    118 }
    11985
    12086/***********************************************************************
     
    185151void gfree_names(void)
    186152{
    187         SAFE_FREE( smb_myname );
    188         SAFE_FREE( smb_myworkgroup );
     153        gfree_netbios_names();
    189154        SAFE_FREE( smb_scope );
    190155        free_netbios_names_array();
     
    262227        if (global_myname() == NULL || *global_myname() == '\0') {
    263228                if (!set_global_myname(myhostname())) {
    264                         DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
     229                        DEBUG( 0, ( "init_names: malloc fail.\n" ) );
    265230                        return False;
    266231                }
     
    268233
    269234        if (!set_netbios_aliases(lp_netbios_aliases())) {
    270                 DEBUG( 0, ( "init_structs: malloc fail.\n" ) );
     235                DEBUG( 0, ( "init_names: malloc fail.\n" ) );
    271236                return False;
    272237        }
     
    281246
    282247        return( True );
    283 }
    284 
    285 /**************************************************************************n
    286   Code to cope with username/password auth options from the commandline.
    287   Used mainly in client tools.
    288 ****************************************************************************/
    289 
    290 struct user_auth_info *user_auth_info_init(TALLOC_CTX *mem_ctx)
    291 {
    292         struct user_auth_info *result;
    293 
    294         result = TALLOC_ZERO_P(mem_ctx, struct user_auth_info);
    295         if (result == NULL) {
    296                 return NULL;
    297         }
    298 
    299         result->signing_state = Undefined;
    300         return result;
    301 }
    302 
    303 const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info)
    304 {
    305         if (!auth_info->username) {
    306                 return "";
    307         }
    308         return auth_info->username;
    309 }
    310 
    311 void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
    312                                     const char *username)
    313 {
    314         TALLOC_FREE(auth_info->username);
    315         auth_info->username = talloc_strdup(auth_info, username);
    316         if (!auth_info->username) {
    317                 exit(ENOMEM);
    318         }
    319 }
    320 
    321 const char *get_cmdline_auth_info_domain(const struct user_auth_info *auth_info)
    322 {
    323         if (!auth_info->domain) {
    324                 return "";
    325         }
    326         return auth_info->domain;
    327 }
    328 
    329 void set_cmdline_auth_info_domain(struct user_auth_info *auth_info,
    330                                   const char *domain)
    331 {
    332         TALLOC_FREE(auth_info->domain);
    333         auth_info->domain = talloc_strdup(auth_info, domain);
    334         if (!auth_info->domain) {
    335                 exit(ENOMEM);
    336         }
    337 }
    338 
    339 const char *get_cmdline_auth_info_password(const struct user_auth_info *auth_info)
    340 {
    341         if (!auth_info->password) {
    342                 return "";
    343         }
    344         return auth_info->password;
    345 }
    346 
    347 void set_cmdline_auth_info_password(struct user_auth_info *auth_info,
    348                                     const char *password)
    349 {
    350         TALLOC_FREE(auth_info->password);
    351         if (password == NULL) {
    352                 password = "";
    353         }
    354         auth_info->password = talloc_strdup(auth_info, password);
    355         if (!auth_info->password) {
    356                 exit(ENOMEM);
    357         }
    358         auth_info->got_pass = true;
    359 }
    360 
    361 bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info,
    362                                          const char *arg)
    363 {
    364         auth_info->signing_state = -1;
    365         if (strequal(arg, "off") || strequal(arg, "no") ||
    366                         strequal(arg, "false")) {
    367                 auth_info->signing_state = false;
    368         } else if (strequal(arg, "on") || strequal(arg, "yes") ||
    369                         strequal(arg, "true") || strequal(arg, "auto")) {
    370                 auth_info->signing_state = true;
    371         } else if (strequal(arg, "force") || strequal(arg, "required") ||
    372                         strequal(arg, "forced")) {
    373                 auth_info->signing_state = Required;
    374         } else {
    375                 return false;
    376         }
    377         return true;
    378 }
    379 
    380 int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
    381 {
    382         return auth_info->signing_state;
    383 }
    384 
    385 void set_cmdline_auth_info_use_ccache(struct user_auth_info *auth_info, bool b)
    386 {
    387         auth_info->use_ccache = b;
    388 }
    389 
    390 bool get_cmdline_auth_info_use_ccache(const struct user_auth_info *auth_info)
    391 {
    392         return auth_info->use_ccache;
    393 }
    394 
    395 void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info,
    396                                         bool b)
    397 {
    398         auth_info->use_kerberos = b;
    399 }
    400 
    401 bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info)
    402 {
    403         return auth_info->use_kerberos;
    404 }
    405 
    406 void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info,
    407                                         bool b)
    408 {
    409         auth_info->fallback_after_kerberos = b;
    410 }
    411 
    412 bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info)
    413 {
    414         return auth_info->fallback_after_kerberos;
    415 }
    416 
    417 /* This should only be used by lib/popt_common.c JRA */
    418 void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info)
    419 {
    420         auth_info->use_kerberos = true;
    421         auth_info->got_pass = true;
    422 }
    423 
    424 /* This should only be used by lib/popt_common.c JRA */
    425 void set_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info)
    426 {
    427         auth_info->smb_encrypt = true;
    428 }
    429 
    430 void set_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info)
    431 {
    432         auth_info->use_machine_account = true;
    433 }
    434 
    435 bool get_cmdline_auth_info_got_pass(const struct user_auth_info *auth_info)
    436 {
    437         return auth_info->got_pass;
    438 }
    439 
    440 bool get_cmdline_auth_info_smb_encrypt(const struct user_auth_info *auth_info)
    441 {
    442         return auth_info->smb_encrypt;
    443 }
    444 
    445 bool get_cmdline_auth_info_use_machine_account(const struct user_auth_info *auth_info)
    446 {
    447         return auth_info->use_machine_account;
    448 }
    449 
    450 struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx,
    451                                                   const struct user_auth_info *src)
    452 {
    453         struct user_auth_info *result;
    454 
    455         result = user_auth_info_init(mem_ctx);
    456         if (result == NULL) {
    457                 return NULL;
    458         }
    459 
    460         *result = *src;
    461 
    462         result->username = talloc_strdup(
    463                 result, get_cmdline_auth_info_username(src));
    464         result->password = talloc_strdup(
    465                 result, get_cmdline_auth_info_password(src));
    466         if ((result->username == NULL) || (result->password == NULL)) {
    467                 TALLOC_FREE(result);
    468                 return NULL;
    469         }
    470 
    471         return result;
    472 }
    473 
    474 bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info)
    475 {
    476         char *pass = NULL;
    477         char *account = NULL;
    478 
    479         if (!get_cmdline_auth_info_use_machine_account(auth_info)) {
    480                 return false;
    481         }
    482 
    483         if (!secrets_init()) {
    484                 d_printf("ERROR: Unable to open secrets database\n");
    485                 return false;
    486         }
    487 
    488         if (asprintf(&account, "%s$@%s", global_myname(), lp_realm()) < 0) {
    489                 return false;
    490         }
    491 
    492         pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
    493         if (!pass) {
    494                 d_printf("ERROR: Unable to fetch machine password for "
    495                         "%s in domain %s\n",
    496                         account, lp_workgroup());
    497                 SAFE_FREE(account);
    498                 return false;
    499         }
    500 
    501         set_cmdline_auth_info_username(auth_info, account);
    502         set_cmdline_auth_info_password(auth_info, pass);
    503 
    504         SAFE_FREE(account);
    505         SAFE_FREE(pass);
    506 
    507         return true;
    508 }
    509 
    510 /****************************************************************************
    511  Ensure we have a password if one not given.
    512 ****************************************************************************/
    513 
    514 void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info)
    515 {
    516         char *label = NULL;
    517         char *pass;
    518         TALLOC_CTX *frame;
    519 
    520         if (get_cmdline_auth_info_got_pass(auth_info) ||
    521                         get_cmdline_auth_info_use_kerberos(auth_info)) {
    522                 /* Already got one... */
    523                 return;
    524         }
    525 
    526         frame = talloc_stackframe();
    527         label = talloc_asprintf(frame, "Enter %s's password: ",
    528                         get_cmdline_auth_info_username(auth_info));
    529         pass = getpass(label);
    530         if (pass) {
    531                 set_cmdline_auth_info_password(auth_info, pass);
    532         }
    533         TALLOC_FREE(frame);
    534248}
    535249
     
    596310        attrstr[0] = 0;
    597311
    598         if (mode & aVOLID) fstrcat(attrstr,"V");
    599         if (mode & aDIR) fstrcat(attrstr,"D");
    600         if (mode & aARCH) fstrcat(attrstr,"A");
    601         if (mode & aHIDDEN) fstrcat(attrstr,"H");
    602         if (mode & aSYSTEM) fstrcat(attrstr,"S");
    603         if (mode & aRONLY) fstrcat(attrstr,"R");         
     312        if (mode & FILE_ATTRIBUTE_VOLUME) fstrcat(attrstr,"V");
     313        if (mode & FILE_ATTRIBUTE_DIRECTORY) fstrcat(attrstr,"D");
     314        if (mode & FILE_ATTRIBUTE_ARCHIVE) fstrcat(attrstr,"A");
     315        if (mode & FILE_ATTRIBUTE_HIDDEN) fstrcat(attrstr,"H");
     316        if (mode & FILE_ATTRIBUTE_SYSTEM) fstrcat(attrstr,"S");
     317        if (mode & FILE_ATTRIBUTE_READONLY) fstrcat(attrstr,"R");
    604318
    605319        return talloc_strdup(talloc_tos(), attrstr);
     
    617331        if (!DEBUGLVL(5))
    618332                return;
    619        
     333
    620334        DEBUG(5,("size=%d\nsmb_com=0x%x\nsmb_rcls=%d\nsmb_reh=%d\nsmb_err=%d\nsmb_flg=%d\nsmb_flg2=%d\n",
    621335                        smb_len(buf),
     
    636350                DEBUGADD(5,("smb_vwv[%2d]=%5d (0x%X)\n",i,
    637351                        SVAL(buf,smb_vwv+2*i),SVAL(buf,smb_vwv+2*i)));
    638        
     352
    639353        bcc = (int)SVAL(buf,smb_vwv+2*(CVAL(buf,smb_wct)));
    640354
     
    863577}
    864578
    865 /*******************************************************************
    866  Sleep for a specified number of milliseconds.
    867 ********************************************************************/
    868 
    869 void smb_msleep(unsigned int t)
    870 {
    871 #if defined(HAVE_NANOSLEEP)
    872         struct timespec tval;
    873         int ret;
    874 
    875         tval.tv_sec = t/1000;
    876         tval.tv_nsec = 1000000*(t%1000);
    877 
    878         do {
    879                 errno = 0;
    880                 ret = nanosleep(&tval, &tval);
    881         } while (ret < 0 && errno == EINTR && (tval.tv_sec > 0 || tval.tv_nsec > 0));
    882 #else
    883         unsigned int tdiff=0;
    884         struct timeval tval,t1,t2; 
    885         fd_set fds;
    886 
    887         GetTimeOfDay(&t1);
    888         t2 = t1;
    889  
    890         while (tdiff < t) {
    891                 tval.tv_sec = (t-tdiff)/1000;
    892                 tval.tv_usec = 1000*((t-tdiff)%1000);
    893 
    894                 /* Never wait for more than 1 sec. */
    895                 if (tval.tv_sec > 1) {
    896                         tval.tv_sec = 1;
    897                         tval.tv_usec = 0;
    898                 }
    899 
    900                 FD_ZERO(&fds);
    901                 errno = 0;
    902                 sys_select_intr(0,&fds,NULL,NULL,&tval);
    903 
    904                 GetTimeOfDay(&t2);
    905                 if (t2.tv_sec < t1.tv_sec) {
    906                         /* Someone adjusted time... */
    907                         t1 = t2;
    908                 }
    909 
    910                 tdiff = TvalDiff(&t1,&t2);
    911         }
    912 #endif
    913 }
    914579
    915580NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
    916                        struct event_context *ev_ctx,
    917                        bool parent_longlived)
     581                           struct event_context *ev_ctx,
     582                           struct server_id id,
     583                           bool parent_longlived)
    918584{
    919585        NTSTATUS status = NT_STATUS_OK;
     
    932598        }
    933599
    934         if (ev_ctx) {
    935                 event_context_reinit(ev_ctx);
     600        if (ev_ctx && tevent_re_initialise(ev_ctx) != 0) {
     601                smb_panic(__location__ ": Failed to re-initialise event context");
    936602        }
    937603
     
    941607                 * fork
    942608                 */
    943                 status = messaging_reinit(msg_ctx);
     609                status = messaging_reinit(msg_ctx, id);
    944610                if (!NT_STATUS_IS_OK(status)) {
    945611                        DEBUG(0,("messaging_reinit() failed: %s\n",
     
    949615 done:
    950616        return status;
    951 }
    952 
    953 /****************************************************************************
    954  Put up a yes/no prompt.
    955 ****************************************************************************/
    956 
    957 bool yesno(const char *p)
    958 {
    959         char ans[20];
    960         printf("%s",p);
    961 
    962         if (!fgets(ans,sizeof(ans)-1,stdin))
    963                 return(False);
    964 
    965         if (*ans == 'y' || *ans == 'Y')
    966                 return(True);
    967 
    968         return(False);
    969617}
    970618
     
    1208856        if (strequal(str,"CORE+"))
    1209857                return(PROTOCOL_COREPLUS);
    1210  
     858
    1211859        DEBUG(0,("Unrecognised protocol level %s\n",str));
    1212  
     860
    1213861        return(def);
    1214862}
     
    13531001
    13541002#ifdef CLUSTER_SUPPORT
    1355         return ctdbd_process_exists(messaging_ctdbd_connection(), pid.vnn,
    1356                                     pid.pid);
     1003        return ctdbd_process_exists(messaging_ctdbd_connection(),
     1004                                    pid.vnn, pid.pid);
    13571005#else
    13581006        return False;
     
    14111059        uid_t u;
    14121060
    1413         pass = Get_Pwnam_alloc(talloc_autofree_context(), name);
     1061        pass = Get_Pwnam_alloc(talloc_tos(), name);
    14141062        if (pass) {
    14151063                u = pass->pw_uid;
     
    15711219        DEBUG(0, ("BACKTRACE: %lu stack frames:\n",
    15721220                  (unsigned long)backtrace_size));
    1573        
     1221
    15741222        if (backtrace_strings) {
    15751223                int i;
     
    16351283        if (!p)
    16361284                return(NULL);
    1637  
     1285
    16381286        ptr = (SMB_STRUCT_DIRENT *)sys_readdir(p);
    16391287        if (!ptr)
     
    17091357 if possible.
    17101358********************************************************************/
    1711  
     1359
    17121360void set_namearray(name_compare_entry **ppname_array, const char *namelist)
    17131361{
     
    17851433                i++;
    17861434        }
    1787  
     1435
    17881436        (*ppname_array)[i].name = NULL;
    17891437
     
    18451493        *pcount = lock.l_len;
    18461494        *ppid = lock.l_pid;
    1847        
     1495
    18481496        DEBUG(3,("fcntl_getlock: fd %d is returned info %d pid %u\n",
    18491497                        fd, (int)lock.l_type, (unsigned int)lock.l_pid));
     
    19631611                remote_arch_str = "CIFSFS";
    19641612                break;
     1613        case RA_OSX:
     1614                remote_arch_str = "OSX";
     1615                break;
    19651616        default:
    19661617                ra_type = RA_UNKNOWN;
     
    20021653{
    20031654        TDB_DATA key = string_tdb_data(s);
    2004         return jenkins_hash(&key);
     1655        return tdb_jenkins_hash(&key);
    20051656}
    20061657
     
    21461797        static char *ret;
    21471798        if (ret == NULL) {
    2148                 /* This is cached forever so
    2149                  * use talloc_autofree_context() ctx. */
    2150                 ret = get_myname(talloc_autofree_context());
     1799                ret = get_myname(NULL);
    21511800        }
    21521801        return ret;
     
    22951944        char *p;
    22961945        ptrdiff_t len;
    2297  
     1946
    22981947        p = strrchr_m(dir, '/'); /* Find final '/', if any */
    22991948
     
    23712020bool mask_match(const char *string, const char *pattern, bool is_case_sensitive)
    23722021{
    2373         if (strcmp(string,"..") == 0)
     2022        if (ISDOTDOT(string))
    23742023                string = ".";
    2375         if (strcmp(pattern,".") == 0)
     2024        if (ISDOT(pattern))
    23762025                return False;
    2377        
     2026
    23782027        return ms_fnmatch(pattern, string, Protocol <= PROTOCOL_LANMAN2, is_case_sensitive) == 0;
    23792028}
     
    23872036bool mask_match_search(const char *string, const char *pattern, bool is_case_sensitive)
    23882037{
    2389         if (strcmp(string,"..") == 0)
     2038        if (ISDOTDOT(string))
    23902039                string = ".";
    2391         if (strcmp(pattern,".") == 0)
     2040        if (ISDOT(pattern))
    23922041                return False;
    2393        
     2042
    23942043        return ms_fnmatch(pattern, string, True, is_case_sensitive) == 0;
    23952044}
     
    26602309}
    26612310
     2311static uint64_t my_unique_id = 0;
     2312
     2313void set_my_unique_id(uint64_t unique_id)
     2314{
     2315        my_unique_id = unique_id;
     2316}
     2317
    26622318struct server_id pid_to_procid(pid_t pid)
    26632319{
    26642320        struct server_id result;
    26652321        result.pid = pid;
    2666 #ifdef CLUSTER_SUPPORT
     2322        result.unique_id = my_unique_id;
    26672323        result.vnn = my_vnn;
    2668 #endif
    26692324        return result;
    26702325}
     
    26732328{
    26742329        return pid_to_procid(sys_getpid());
    2675 }
    2676 
    2677 struct server_id server_id_self(void)
    2678 {
    2679         return procid_self();
    26802330}
    26812331
     
    26842334        if (p1->pid != p2->pid)
    26852335                return False;
    2686 #ifdef CLUSTER_SUPPORT
    26872336        if (p1->vnn != p2->vnn)
    26882337                return False;
    2689 #endif
    26902338        return True;
    26912339}
     
    27012349        if (pid->pid != sys_getpid())
    27022350                return False;
    2703 #ifdef CLUSTER_SUPPORT
    27042351        if (pid->vnn != my_vnn)
    27052352                return False;
    2706 #endif
    27072353        return True;
    27082354}
     
    27122358        struct server_id result;
    27132359        int pid;
    2714 #ifdef CLUSTER_SUPPORT
    27152360        unsigned int vnn;
    27162361        if (sscanf(pid_string, "%u:%d", &vnn, &pid) == 2) {
     
    27262371                result.pid = -1;
    27272372        }
    2728 #else
    2729         if (sscanf(pid_string, "%d", &pid) != 1) {
    2730                 result.pid = -1;
    2731         } else {
    2732                 result.pid = pid;
    2733         }
    2734 #endif
    27352373        /* Assigning to result.pid may have overflowed
    27362374           Map negative pid to -1: i.e. error */
     
    27382376                result.pid = -1;
    27392377        }
     2378        result.unique_id = 0;
    27402379        return result;
    27412380}
     
    27432382char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
    27442383{
    2745 #ifdef CLUSTER_SUPPORT
    27462384        if (pid->vnn == NONCLUSTER_VNN) {
    27472385                return talloc_asprintf(mem_ctx,
     
    27552393                                        (int)pid->pid);
    27562394        }
    2757 #else
    2758         return talloc_asprintf(mem_ctx,
    2759                         "%d",
    2760                         (int)pid->pid);
    2761 #endif
    27622395}
    27632396
     
    27742407bool procid_is_local(const struct server_id *pid)
    27752408{
    2776 #ifdef CLUSTER_SUPPORT
    27772409        return pid->vnn == my_vnn;
    2778 #else
    2779         return True;
    2780 #endif
    2781 }
    2782 
    2783 int this_is_smp(void)
    2784 {
    2785 #if defined(HAVE_SYSCONF)
    2786 
    2787 #if defined(SYSCONF_SC_NPROC_ONLN)
    2788         return (sysconf(_SC_NPROC_ONLN) > 1) ? 1 : 0;
    2789 #elif defined(SYSCONF_SC_NPROCESSORS_ONLN)
    2790         return (sysconf(_SC_NPROCESSORS_ONLN) > 1) ? 1 : 0;
    2791 #else
    2792         return 0;
    2793 #endif
    2794 
    2795 #else
    2796         return 0;
    2797 #endif
    27982410}
    27992411
     
    30292641#endif
    30302642
    3031 bool is_valid_policy_hnd(const struct policy_handle *hnd)
    3032 {
    3033         struct policy_handle tmp;
    3034         ZERO_STRUCT(tmp);
    3035         return (memcmp(&tmp, hnd, sizeof(tmp)) != 0);
    3036 }
    3037 
    3038 bool policy_hnd_equal(const struct policy_handle *hnd1,
    3039                       const struct policy_handle *hnd2)
    3040 {
    3041         if (!hnd1 || !hnd2) {
    3042                 return false;
    3043         }
    3044 
    3045         return (memcmp(hnd1, hnd2, sizeof(*hnd1)) == 0);
    3046 }
    3047 
    30482643/****************************************************************
    30492644 strip off leading '\\' from a hostname
     
    30762671        return ret;
    30772672}
     2673
     2674bool any_nt_status_not_ok(NTSTATUS err1, NTSTATUS err2, NTSTATUS *result)
     2675{
     2676        if (!NT_STATUS_IS_OK(err1)) {
     2677                *result = err1;
     2678                return true;
     2679        }
     2680        if (!NT_STATUS_IS_OK(err2)) {
     2681                *result = err2;
     2682                return true;
     2683        }
     2684        return false;
     2685}
     2686
     2687int timeval_to_msec(struct timeval t)
     2688{
     2689        return t.tv_sec * 1000 + (t.tv_usec+999) / 1000;
     2690}
     2691
     2692/*******************************************************************
     2693 Check a given DOS pathname is valid for a share.
     2694********************************************************************/
     2695
     2696char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname)
     2697{
     2698        char *ptr = NULL;
     2699
     2700        if (!dos_pathname) {
     2701                return NULL;
     2702        }
     2703
     2704        ptr = talloc_strdup(ctx, dos_pathname);
     2705        if (!ptr) {
     2706                return NULL;
     2707        }
     2708        /* Convert any '\' paths to '/' */
     2709        unix_format(ptr);
     2710        ptr = unix_clean_name(ctx, ptr);
     2711        if (!ptr) {
     2712                return NULL;
     2713        }
     2714
     2715        /* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
     2716        if (strlen(ptr) > 2 && ptr[1] == ':' && ptr[0] != '/')
     2717                ptr += 2;
     2718
     2719        /* Only absolute paths allowed. */
     2720        if (*ptr != '/')
     2721                return NULL;
     2722
     2723        return ptr;
     2724}
  • trunk/server/source3/lib/util_nscd.c

    r414 r745  
    2020#include "includes.h"
    2121
     22#ifdef HAVE_LIBNSCD
     23#include <libnscd.h>
     24#endif
     25
    2226static void smb_nscd_flush_cache(const char *service)
    2327{
  • trunk/server/source3/lib/util_nttoken.c

    r414 r745  
    2727
    2828#include "includes.h"
     29#include "../libcli/security/security.h"
    2930
    3031/****************************************************************************
     
    3233****************************************************************************/
    3334
    34 NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN *ptoken)
     35struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken)
    3536{
    36         NT_USER_TOKEN *token;
     37        struct security_token *token;
    3738
    3839        if (!ptoken)
    3940                return NULL;
    4041
    41         token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
     42        token = TALLOC_ZERO_P(mem_ctx, struct security_token);
    4243        if (token == NULL) {
    4344                DEBUG(0, ("talloc failed\n"));
     
    4546        }
    4647
    47         if (ptoken->user_sids && ptoken->num_sids) {
    48                 token->user_sids = (DOM_SID *)talloc_memdup(
    49                         token, ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids );
     48        if (ptoken->sids && ptoken->num_sids) {
     49                token->sids = (struct dom_sid *)talloc_memdup(
     50                        token, ptoken->sids, sizeof(struct dom_sid) * ptoken->num_sids );
    5051
    51                 if (token->user_sids == NULL) {
     52                if (token->sids == NULL) {
    5253                        DEBUG(0, ("talloc_memdup failed\n"));
    5354                        TALLOC_FREE(token);
     
    5758        }
    5859       
    59         /* copy the privileges; don't consider failure to be critical here */
    60        
    61         if ( !se_priv_copy( &token->privileges, &ptoken->privileges ) ) {
    62                 DEBUG(0,("dup_nt_token: Failure to copy SE_PRIV!.  "
    63                          "Continuing with 0 privileges assigned.\n"));
    64         }
     60        token->privilege_mask = ptoken->privilege_mask;
     61        token->rights_mask = ptoken->rights_mask;
    6562
    6663        return token;
     
    7269
    7370NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx,
    74                         const struct nt_user_token *token_1,
    75                         const struct nt_user_token *token_2,
    76                         struct nt_user_token **token_out)
     71                        const struct security_token *token_1,
     72                        const struct security_token *token_2,
     73                        struct security_token **token_out)
    7774{
    78         struct nt_user_token *token = NULL;
     75        struct security_token *token = NULL;
    7976        NTSTATUS status;
    8077        int i;
     
    8481        }
    8582
    86         token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token);
     83        token = TALLOC_ZERO_P(mem_ctx, struct security_token);
    8784        NT_STATUS_HAVE_NO_MEMORY(token);
    8885
    8986        for (i=0; i < token_1->num_sids; i++) {
    9087                status = add_sid_to_array_unique(mem_ctx,
    91                                                  &token_1->user_sids[i],
    92                                                  &token->user_sids,
     88                                                 &token_1->sids[i],
     89                                                 &token->sids,
    9390                                                 &token->num_sids);
    9491                if (!NT_STATUS_IS_OK(status)) {
     
    10097        for (i=0; i < token_2->num_sids; i++) {
    10198                status = add_sid_to_array_unique(mem_ctx,
    102                                                  &token_2->user_sids[i],
    103                                                  &token->user_sids,
     99                                                 &token_2->sids[i],
     100                                                 &token->sids,
    104101                                                 &token->num_sids);
    105102                if (!NT_STATUS_IS_OK(status)) {
     
    109106        }
    110107
    111         se_priv_add(&token->privileges, &token_1->privileges);
    112         se_priv_add(&token->privileges, &token_2->privileges);
     108        token->privilege_mask |= token_1->privilege_mask;
     109        token->privilege_mask |= token_2->privilege_mask;
     110
     111        token->rights_mask |= token_1->rights_mask;
     112        token->rights_mask |= token_2->rights_mask;
    113113
    114114        *token_out = token;
     
    118118
    119119/*******************************************************************
    120  Check if this ACE has a SID in common with the token.
     120 Check if this struct security_ace has a SID in common with the token.
    121121********************************************************************/
    122122
    123 bool token_sid_in_ace(const NT_USER_TOKEN *token, const struct security_ace *ace)
     123bool token_sid_in_ace(const struct security_token *token, const struct security_ace *ace)
    124124{
    125125        size_t i;
    126126
    127127        for (i = 0; i < token->num_sids; i++) {
    128                 if (sid_equal(&ace->trustee, &token->user_sids[i]))
     128                if (dom_sid_equal(&ace->trustee, &token->sids[i]))
    129129                        return true;
    130130        }
  • trunk/server/source3/lib/util_sid.c

    r583 r745  
    88   Copyright (C) Simo Sorce                     2002
    99   Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005
    10      
     10
    1111   This program is free software; you can redistribute it and/or modify
    1212   it under the terms of the GNU General Public License as published by
    1313   the Free Software Foundation; either version 3 of the License, or
    1414   (at your option) any later version.
    15    
     15
    1616   This program is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    20    
     20
    2121   You should have received a copy of the GNU General Public License
    2222   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2424
    2525#include "includes.h"
    26 
    27 /*
    28  * Some useful sids, more well known sids can be found at
    29  * http://support.microsoft.com/kb/243330/EN-US/
    30  */
    31 
    32 
    33 const DOM_SID global_sid_World_Domain =               /* Everyone domain */
    34 { 1, 0, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    35 const DOM_SID global_sid_World =                      /* Everyone */
    36 { 1, 1, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    37 const DOM_SID global_sid_Creator_Owner_Domain =       /* Creator Owner domain */
    38 { 1, 0, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    39 const DOM_SID global_sid_NT_Authority =                 /* NT Authority */
    40 { 1, 0, {0,0,0,0,0,5}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    41 const DOM_SID global_sid_System =                       /* System */
    42 { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    43 const DOM_SID global_sid_NULL =                         /* NULL sid */
    44 { 1, 1, {0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    45 const DOM_SID global_sid_Authenticated_Users =  /* All authenticated rids */
    46 { 1, 1, {0,0,0,0,0,5}, {11,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    47 #if 0
    48 /* for documentation */
    49 const DOM_SID global_sid_Restriced =                    /* Restriced Code */
    50 { 1, 1, {0,0,0,0,0,5}, {12,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    51 #endif
    52 const DOM_SID global_sid_Network =                      /* Network rids */
    53 { 1, 1, {0,0,0,0,0,5}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    54 
    55 const DOM_SID global_sid_Creator_Owner =                /* Creator Owner */
    56 { 1, 1, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    57 const DOM_SID global_sid_Creator_Group =                /* Creator Group */
    58 { 1, 1, {0,0,0,0,0,3}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    59 const DOM_SID global_sid_Anonymous =                    /* Anonymous login */
    60 { 1, 1, {0,0,0,0,0,5}, {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    61 
    62 const DOM_SID global_sid_Builtin =                      /* Local well-known domain */
    63 { 1, 1, {0,0,0,0,0,5}, {32,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    64 const DOM_SID global_sid_Builtin_Administrators =       /* Builtin administrators */
    65 { 1, 2, {0,0,0,0,0,5}, {32,544,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    66 const DOM_SID global_sid_Builtin_Users =                /* Builtin users */
    67 { 1, 2, {0,0,0,0,0,5}, {32,545,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    68 const DOM_SID global_sid_Builtin_Guests =               /* Builtin guest users */
    69 { 1, 2, {0,0,0,0,0,5}, {32,546,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    70 const DOM_SID global_sid_Builtin_Power_Users =  /* Builtin power users */
    71 { 1, 2, {0,0,0,0,0,5}, {32,547,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    72 const DOM_SID global_sid_Builtin_Account_Operators =    /* Builtin account operators */
    73 { 1, 2, {0,0,0,0,0,5}, {32,548,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    74 const DOM_SID global_sid_Builtin_Server_Operators =     /* Builtin server operators */
    75 { 1, 2, {0,0,0,0,0,5}, {32,549,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    76 const DOM_SID global_sid_Builtin_Print_Operators =      /* Builtin print operators */
    77 { 1, 2, {0,0,0,0,0,5}, {32,550,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    78 const DOM_SID global_sid_Builtin_Backup_Operators =     /* Builtin backup operators */
    79 { 1, 2, {0,0,0,0,0,5}, {32,551,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    80 const DOM_SID global_sid_Builtin_Replicator =           /* Builtin replicator */
    81 { 1, 2, {0,0,0,0,0,5}, {32,552,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    82 const DOM_SID global_sid_Builtin_PreWin2kAccess =       /* Builtin pre win2k access */
    83 { 1, 2, {0,0,0,0,0,5}, {32,554,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    84 
    85 const DOM_SID global_sid_Unix_Users =                   /* Unmapped Unix users */
    86 { 1, 1, {0,0,0,0,0,22}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    87 const DOM_SID global_sid_Unix_Groups =                  /* Unmapped Unix groups */
    88 { 1, 1, {0,0,0,0,0,22}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    89 
    90 /* Unused, left here for documentary purposes */
    91 #if 0
    92 #define SECURITY_NULL_SID_AUTHORITY    0
    93 #define SECURITY_WORLD_SID_AUTHORITY   1
    94 #define SECURITY_LOCAL_SID_AUTHORITY   2
    95 #define SECURITY_CREATOR_SID_AUTHORITY 3
    96 #define SECURITY_NT_AUTHORITY          5
    97 #endif
    98 
    99 /*
    100  * An NT compatible anonymous token.
    101  */
    102 
    103 static DOM_SID anon_sid_array[3] =
    104 { { 1, 1, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
    105   { 1, 1, {0,0,0,0,0,5}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
    106   { 1, 1, {0,0,0,0,0,5}, {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} };
    107 NT_USER_TOKEN anonymous_token = { 3, anon_sid_array, SE_NONE };
    108 
    109 static DOM_SID system_sid_array[1] =
    110 { { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} };
    111 NT_USER_TOKEN system_token = { 1, system_sid_array, SE_ALL_PRIVS };
    112 
    113 /****************************************************************************
    114  Lookup string names for SID types.
    115 ****************************************************************************/
    116 
    117 static const struct {
    118         enum lsa_SidType sid_type;
    119         const char *string;
    120 } sid_name_type[] = {
    121         {SID_NAME_USER, "User"},
    122         {SID_NAME_DOM_GRP, "Domain Group"},
    123         {SID_NAME_DOMAIN, "Domain"},
    124         {SID_NAME_ALIAS, "Local Group"},
    125         {SID_NAME_WKN_GRP, "Well-known Group"},
    126         {SID_NAME_DELETED, "Deleted Account"},
    127         {SID_NAME_INVALID, "Invalid Account"},
    128         {SID_NAME_UNKNOWN, "UNKNOWN"},
    129         {SID_NAME_COMPUTER, "Computer"},
    130 
    131         {(enum lsa_SidType)0, NULL}
    132 };
    133 
    134 const char *sid_type_lookup(uint32 sid_type)
    135 {
    136         int i = 0;
    137 
    138         /* Look through list */
    139         while(sid_name_type[i].sid_type != 0) {
    140                 if (sid_name_type[i].sid_type == sid_type)
    141                         return sid_name_type[i].string;
    142                 i++;
    143         }
    144 
    145         /* Default return */
    146         return "SID *TYPE* is INVALID";
    147 }
    148 
    149 /**************************************************************************
    150  Create the SYSTEM token.
    151 ***************************************************************************/
    152 
    153 NT_USER_TOKEN *get_system_token(void)
    154 {
    155         return &system_token;
    156 }
    157 
    158 /******************************************************************
    159  get the default domain/netbios name to be used when dealing
    160  with our passdb list of accounts
    161 ******************************************************************/
    162 
    163 const char *get_global_sam_name(void)
    164 {
    165         if ((lp_server_role() == ROLE_DOMAIN_PDC) || (lp_server_role() == ROLE_DOMAIN_BDC)) {
    166                 return lp_workgroup();
    167         }
    168         return global_myname();
    169 }
     26#include "../librpc/gen_ndr/ndr_security.h"
     27#include "../librpc/gen_ndr/netlogon.h"
     28#include "../libcli/security/security.h"
     29
    17030
    17131/*****************************************************************
     
    17333*****************************************************************/
    17434
    175 char *sid_to_fstring(fstring sidstr_out, const DOM_SID *sid)
    176 {
    177         char *str = sid_string_talloc(talloc_tos(), sid);
    178         fstrcpy(sidstr_out, str);
    179         TALLOC_FREE(str);
     35char *sid_to_fstring(fstring sidstr_out, const struct dom_sid *sid)
     36{
     37        dom_sid_string_buf(sid, sidstr_out, sizeof(fstring));
    18038        return sidstr_out;
    18139}
    18240
    18341/*****************************************************************
    184  Essentially a renamed dom_sid_string from librpc/ndr with a
    185  panic if it didn't work
    186 
    187  This introduces a dependency on librpc/ndr/sid.o which can easily
    188  be turned around if necessary
    189 *****************************************************************/
    190 
    191 char *sid_string_talloc(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
     42 Essentially a renamed dom_sid_string from
     43 ../libcli/security/dom_sid.c with a panic if it didn't work.
     44*****************************************************************/
     45
     46char *sid_string_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
    19247{
    19348        char *result = dom_sid_string(mem_ctx, sid);
     
    20055*****************************************************************/
    20156
    202 char *sid_string_dbg(const DOM_SID *sid)
     57char *sid_string_dbg(const struct dom_sid *sid)
    20358{
    20459        return sid_string_talloc(talloc_tos(), sid);
     
    20964*****************************************************************/
    21065
    211 char *sid_string_tos(const DOM_SID *sid)
     66char *sid_string_tos(const struct dom_sid *sid)
    21267{
    21368        return sid_string_talloc(talloc_tos(), sid);
    214 }
    215 
    216 /*****************************************************************
    217  Convert a string to a SID. Returns True on success, False on fail.
    218 *****************************************************************/ 
    219    
    220 bool string_to_sid(DOM_SID *sidout, const char *sidstr)
    221 {
    222         const char *p;
    223         char *q;
    224         /* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 */
    225         uint32 conv;
    226  
    227         if ((sidstr[0] != 'S' && sidstr[0] != 's') || sidstr[1] != '-') {
    228                 DEBUG(3,("string_to_sid: Sid %s does not start with 'S-'.\n", sidstr));
    229                 return False;
    230         }
    231 
    232         ZERO_STRUCTP(sidout);
    233 
    234         /* Get the revision number. */
    235         p = sidstr + 2;
    236         conv = (uint32) strtoul(p, &q, 10);
    237         if (!q || (*q != '-')) {
    238                 DEBUG(3,("string_to_sid: Sid %s is not in a valid format.\n", sidstr));
    239                 return False;
    240         }
    241         sidout->sid_rev_num = (uint8) conv;
    242         q++;
    243 
    244         /* get identauth */
    245         conv = (uint32) strtoul(q, &q, 10);
    246         if (!q || (*q != '-')) {
    247                 DEBUG(0,("string_to_sid: Sid %s is not in a valid format.\n", sidstr));
    248                 return False;
    249         }
    250         /* identauth in decimal should be <  2^32 */
    251         /* NOTE - the conv value is in big-endian format. */
    252         sidout->id_auth[0] = 0;
    253         sidout->id_auth[1] = 0;
    254         sidout->id_auth[2] = (conv & 0xff000000) >> 24;
    255         sidout->id_auth[3] = (conv & 0x00ff0000) >> 16;
    256         sidout->id_auth[4] = (conv & 0x0000ff00) >> 8;
    257         sidout->id_auth[5] = (conv & 0x000000ff);
    258 
    259         q++;
    260         sidout->num_auths = 0;
    261 
    262         for(conv = (uint32) strtoul(q, &q, 10);
    263             q && (*q =='-' || *q =='\0') && (sidout->num_auths < MAXSUBAUTHS);
    264             conv = (uint32) strtoul(q, &q, 10)) {
    265                 sid_append_rid(sidout, conv);
    266                 if (*q == '\0')
    267                         break;
    268                 q++;
    269         }
    270                
    271         return True;
    272 }
    273 
    274 DOM_SID *string_sid_talloc(TALLOC_CTX *mem_ctx, const char *sidstr)
    275 {
    276         DOM_SID *result = TALLOC_P(mem_ctx, DOM_SID);
    277 
    278         if (result == NULL)
    279                 return NULL;
    280 
    281         if (!string_to_sid(result, sidstr))
    282                 return NULL;
    283 
    284         return result;
    285 }
    286 
    287 /*****************************************************************
    288  Add a rid to the end of a sid
    289 *****************************************************************/ 
    290 
    291 bool sid_append_rid(DOM_SID *sid, uint32 rid)
    292 {
    293         if (sid->num_auths < MAXSUBAUTHS) {
    294                 sid->sub_auths[sid->num_auths++] = rid;
    295                 return True;
    296         }
    297         return False;
    298 }
    299 
    300 bool sid_compose(DOM_SID *dst, const DOM_SID *domain_sid, uint32 rid)
    301 {
    302         sid_copy(dst, domain_sid);
    303         return sid_append_rid(dst, rid);
    304 }
    305 
    306 /*****************************************************************
    307  Removes the last rid from the end of a sid
    308 *****************************************************************/ 
    309 
    310 bool sid_split_rid(DOM_SID *sid, uint32 *rid)
    311 {
    312         if (sid->num_auths > 0) {
    313                 sid->num_auths--;
    314                 *rid = sid->sub_auths[sid->num_auths];
    315                 return True;
    316         }
    317         return False;
    318 }
    319 
    320 /*****************************************************************
    321  Return the last rid from the end of a sid
    322 *****************************************************************/ 
    323 
    324 bool sid_peek_rid(const DOM_SID *sid, uint32 *rid)
    325 {
    326         if (!sid || !rid)
    327                 return False;           
    328        
    329         if (sid->num_auths > 0) {
    330                 *rid = sid->sub_auths[sid->num_auths - 1];
    331                 return True;
    332         }
    333         return False;
    334 }
    335 
    336 /*****************************************************************
    337  Return the last rid from the end of a sid
    338  and check the sid against the exp_dom_sid 
    339 *****************************************************************/ 
    340 
    341 bool sid_peek_check_rid(const DOM_SID *exp_dom_sid, const DOM_SID *sid, uint32 *rid)
    342 {
    343         if (!exp_dom_sid || !sid || !rid)
    344                 return False;
    345                        
    346         if (sid->num_auths != (exp_dom_sid->num_auths+1)) {
    347                 return False;
    348         }
    349 
    350         if (sid_compare_domain(exp_dom_sid, sid)!=0){
    351                 *rid=(-1);
    352                 return False;
    353         }
    354        
    355         return sid_peek_rid(sid, rid);
    356 }
    357 
    358 /*****************************************************************
    359  Copies a sid
    360 *****************************************************************/ 
    361 
    362 void sid_copy(DOM_SID *dst, const DOM_SID *src)
    363 {
    364         int i;
    365 
    366         ZERO_STRUCTP(dst);
    367 
    368         dst->sid_rev_num = src->sid_rev_num;
    369         dst->num_auths = src->num_auths;
    370 
    371         memcpy(&dst->id_auth[0], &src->id_auth[0], sizeof(src->id_auth));
    372 
    373         for (i = 0; i < src->num_auths; i++)
    374                 dst->sub_auths[i] = src->sub_auths[i];
    37569}
    37670
     
    37973*****************************************************************/ 
    38074
    381 bool sid_linearize(char *outbuf, size_t len, const DOM_SID *sid)
     75bool sid_linearize(char *outbuf, size_t len, const struct dom_sid *sid)
    38276{
    38377        size_t i;
    38478
    385         if (len < ndr_size_dom_sid(sid, NULL, 0))
     79        if (len < ndr_size_dom_sid(sid, 0))
    38680                return False;
    38781
     
    39690
    39791/*****************************************************************
    398  Parse a on-the-wire SID to a DOM_SID.
    399 *****************************************************************/ 
    400 
    401 bool sid_parse(const char *inbuf, size_t len, DOM_SID *sid)
    402 {
    403         int i;
    404         if (len < 8)
    405                 return False;
    406 
    407         ZERO_STRUCTP(sid);
    408 
    409         sid->sid_rev_num = CVAL(inbuf, 0);
    410         sid->num_auths = CVAL(inbuf, 1);
    411         if (sid->num_auths > MAXSUBAUTHS) {
    412                 return false;
    413         }
    414         memcpy(sid->id_auth, inbuf+2, 6);
    415         if (len < 8 + sid->num_auths*4)
    416                 return False;
    417         for (i=0;i<sid->num_auths;i++)
    418                 sid->sub_auths[i] = IVAL(inbuf, 8+i*4);
    419         return True;
    420 }
    421 
    422 /*****************************************************************
    423  Compare the auth portion of two sids.
    424 *****************************************************************/ 
    425 
    426 static int sid_compare_auth(const DOM_SID *sid1, const DOM_SID *sid2)
    427 {
    428         int i;
    429 
    430         if (sid1 == sid2)
    431                 return 0;
    432         if (!sid1)
    433                 return -1;
    434         if (!sid2)
    435                 return 1;
    436 
    437         if (sid1->sid_rev_num != sid2->sid_rev_num)
    438                 return sid1->sid_rev_num - sid2->sid_rev_num;
    439 
    440         for (i = 0; i < 6; i++)
    441                 if (sid1->id_auth[i] != sid2->id_auth[i])
    442                         return sid1->id_auth[i] - sid2->id_auth[i];
    443 
    444         return 0;
    445 }
    446 
    447 /*****************************************************************
    448  Compare two sids.
    449 *****************************************************************/ 
    450 
    451 int sid_compare(const DOM_SID *sid1, const DOM_SID *sid2)
    452 {
    453         int i;
    454 
    455         if (sid1 == sid2)
    456                 return 0;
    457         if (!sid1)
    458                 return -1;
    459         if (!sid2)
    460                 return 1;
    461 
    462         /* Compare most likely different rids, first: i.e start at end */
    463         if (sid1->num_auths != sid2->num_auths)
    464                 return sid1->num_auths - sid2->num_auths;
    465 
    466         for (i = sid1->num_auths-1; i >= 0; --i)
    467                 if (sid1->sub_auths[i] != sid2->sub_auths[i])
    468                         return sid1->sub_auths[i] - sid2->sub_auths[i];
    469 
    470         return sid_compare_auth(sid1, sid2);
    471 }
    472 
    473 /*****************************************************************
    474  See if 2 SIDs are in the same domain
    475  this just compares the leading sub-auths
    476 *****************************************************************/ 
    477 
    478 int sid_compare_domain(const DOM_SID *sid1, const DOM_SID *sid2)
    479 {
    480         int n, i;
    481 
    482         n = MIN(sid1->num_auths, sid2->num_auths);
    483 
    484         for (i = n-1; i >= 0; --i)
    485                 if (sid1->sub_auths[i] != sid2->sub_auths[i])
    486                         return sid1->sub_auths[i] - sid2->sub_auths[i];
    487 
    488         return sid_compare_auth(sid1, sid2);
    489 }
    490 
    491 /*****************************************************************
    492  Compare two sids.
    493 *****************************************************************/ 
    494 
    495 bool sid_equal(const DOM_SID *sid1, const DOM_SID *sid2)
    496 {
    497         return sid_compare(sid1, sid2) == 0;
    498 }
    499 
    500 /*****************************************************************
    50192 Returns true if SID is internal (and non-mappable).
    50293*****************************************************************/
    50394
    504 bool non_mappable_sid(DOM_SID *sid)
    505 {
    506         DOM_SID dom;
    507         uint32 rid;
     95bool non_mappable_sid(struct dom_sid *sid)
     96{
     97        struct dom_sid dom;
    50898
    50999        sid_copy(&dom, sid);
    510         sid_split_rid(&dom, &rid);
    511 
    512         if (sid_equal(&dom, &global_sid_Builtin))
     100        sid_split_rid(&dom, NULL);
     101
     102        if (dom_sid_equal(&dom, &global_sid_Builtin))
    513103                return True;
    514104
    515         if (sid_equal(&dom, &global_sid_NT_Authority))
     105        if (dom_sid_equal(&dom, &global_sid_NT_Authority))
    516106                return True;
    517107
     
    520110
    521111/*****************************************************************
    522  Return the binary string representation of a DOM_SID.
     112 Return the binary string representation of a struct dom_sid.
    523113 Caller must free.
    524114*****************************************************************/
    525115
    526 char *sid_binstring(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
    527 {
    528         uint8_t *buf;
    529         char *s;
    530         int len = ndr_size_dom_sid(sid, NULL, 0);
    531         buf = talloc_array(mem_ctx, uint8_t, len);
    532         if (!buf) {
    533                 return NULL;
    534         }
    535         sid_linearize((char *)buf, len, sid);
    536         s = binary_string_rfc2254(mem_ctx, buf, len);
    537         TALLOC_FREE(buf);
    538         return s;
    539 }
    540 
    541 /*****************************************************************
    542  Return the binary string representation of a DOM_SID.
    543  Caller must free.
    544 *****************************************************************/
    545 
    546 char *sid_binstring_hex(const DOM_SID *sid)
     116char *sid_binstring_hex(const struct dom_sid *sid)
    547117{
    548118        char *buf, *s;
    549         int len = ndr_size_dom_sid(sid, NULL, 0);
     119        int len = ndr_size_dom_sid(sid, 0);
    550120        buf = (char *)SMB_MALLOC(len);
    551121        if (!buf)
    552122                return NULL;
    553123        sid_linearize(buf, len, sid);
    554         s = binary_string(buf, len);
     124        hex_encode((const unsigned char *)buf, len, &s);
    555125        free(buf);
    556126        return s;
    557127}
    558128
    559 /*******************************************************************
    560  Tallocs a duplicate SID.
    561 ********************************************************************/
    562 
    563 DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src)
    564 {
    565         DOM_SID *dst;
    566        
    567         if(!src)
    568                 return NULL;
    569        
    570         if((dst = TALLOC_ZERO_P(ctx, DOM_SID)) != NULL) {
    571                 sid_copy( dst, src);
    572         }
    573        
    574         return dst;
    575 }
    576 
    577 /********************************************************************
    578  Add SID to an array SIDs
    579 ********************************************************************/
    580 
    581 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
    582                           DOM_SID **sids, size_t *num)
    583 {
    584         *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID,
    585                                              (*num)+1);
    586         if (*sids == NULL) {
    587                 *num = 0;
    588                 return NT_STATUS_NO_MEMORY;
    589         }
    590 
    591         sid_copy(&((*sids)[*num]), sid);
    592         *num += 1;
    593 
    594         return NT_STATUS_OK;
    595 }
    596 
    597 
    598 /********************************************************************
    599  Add SID to an array SIDs ensuring that it is not already there
    600 ********************************************************************/
    601 
    602 NTSTATUS add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
    603                                  DOM_SID **sids, size_t *num_sids)
    604 {
    605         size_t i;
    606 
    607         for (i=0; i<(*num_sids); i++) {
    608                 if (sid_compare(sid, &(*sids)[i]) == 0)
    609                         return NT_STATUS_OK;
    610         }
    611 
    612         return add_sid_to_array(mem_ctx, sid, sids, num_sids);
    613 }
    614 
    615 /********************************************************************
    616  Remove SID from an array
    617 ********************************************************************/
    618 
    619 void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, size_t *num)
    620 {
    621         DOM_SID *sid_list = *sids;
    622         size_t i;
    623 
    624         for ( i=0; i<*num; i++ ) {
    625 
    626                 /* if we find the SID, then decrement the count
    627                    and break out of the loop */
    628 
    629                 if ( sid_equal(sid, &sid_list[i]) ) {
    630                         *num -= 1;
    631                         break;
    632                 }
    633         }
    634 
    635         /* This loop will copy the remainder of the array
    636            if i < num of sids ni the array */
    637 
    638         for ( ; i<*num; i++ )
    639                 sid_copy( &sid_list[i], &sid_list[i+1] );
    640        
    641         return;
    642 }
    643 
    644 bool add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
    645                                     uint32 rid, uint32 **pp_rids, size_t *p_num)
    646 {
    647         size_t i;
    648 
    649         for (i=0; i<*p_num; i++) {
    650                 if ((*pp_rids)[i] == rid)
    651                         return True;
    652         }
    653        
    654         *pp_rids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_rids, uint32, *p_num+1);
    655 
    656         if (*pp_rids == NULL) {
    657                 *p_num = 0;
    658                 return False;
    659         }
    660 
    661         (*pp_rids)[*p_num] = rid;
    662         *p_num += 1;
    663         return True;
    664 }
    665 
    666 bool is_null_sid(const DOM_SID *sid)
    667 {
    668         static const DOM_SID null_sid = {0};
    669         return sid_equal(sid, &null_sid);
    670 }
    671 
    672 bool is_sid_in_token(const NT_USER_TOKEN *token, const DOM_SID *sid)
    673 {
    674         int i;
    675 
    676         for (i=0; i<token->num_sids; i++) {
    677                 if (sid_compare(sid, &token->user_sids[i]) == 0)
    678                         return true;
    679         }
    680         return false;
    681 }
    682 
    683129NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
    684130                              const struct netr_SamInfo3 *info3,
    685                               DOM_SID **user_sids,
    686                               size_t *num_user_sids,
     131                              struct dom_sid **user_sids,
     132                              uint32_t *num_user_sids,
    687133                              bool include_user_group_rid,
    688134                              bool skip_ressource_groups)
    689135{
    690136        NTSTATUS status;
    691         DOM_SID sid;
    692         DOM_SID *sid_array = NULL;
    693         size_t num_sids = 0;
     137        struct dom_sid sid;
     138        struct dom_sid *sid_array = NULL;
     139        uint32_t num_sids = 0;
    694140        int i;
    695141
  • trunk/server/source3/lib/util_sock.c

    r599 r745  
    2121
    2222#include "includes.h"
    23 
    24 /****************************************************************************
    25  Get a port number in host byte order from a sockaddr_storage.
    26 ****************************************************************************/
    27 
    28 uint16_t get_sockaddr_port(const struct sockaddr_storage *pss)
    29 {
    30         uint16_t port = 0;
    31 
    32         if (pss->ss_family != AF_INET) {
    33 #if defined(HAVE_IPV6)
    34                 /* IPv6 */
    35                 const struct sockaddr_in6 *sa6 =
    36                         (const struct sockaddr_in6 *)pss;
    37                 port = ntohs(sa6->sin6_port);
    38 #endif
    39         } else {
    40                 const struct sockaddr_in *sa =
    41                         (const struct sockaddr_in *)pss;
    42                 port = ntohs(sa->sin_port);
    43         }
    44         return port;
    45 }
    46 
    47 /****************************************************************************
    48  Print out an IPv4 or IPv6 address from a struct sockaddr_storage.
    49 ****************************************************************************/
    50 
    51 static char *print_sockaddr_len(char *dest,
    52                         size_t destlen,
    53                         const struct sockaddr *psa,
    54                         socklen_t psalen)
    55 {
    56         if (destlen > 0) {
    57                 dest[0] = '\0';
    58         }
    59         (void)sys_getnameinfo(psa,
    60                         psalen,
    61                         dest, destlen,
    62                         NULL, 0,
    63                         NI_NUMERICHOST);
    64         return dest;
    65 }
    66 
    67 /****************************************************************************
    68  Print out an IPv4 or IPv6 address from a struct sockaddr_storage.
    69 ****************************************************************************/
    70 
    71 char *print_sockaddr(char *dest,
    72                         size_t destlen,
    73                         const struct sockaddr_storage *psa)
    74 {
    75         return print_sockaddr_len(dest, destlen, (struct sockaddr *)psa,
    76                         sizeof(struct sockaddr_storage));
    77 }
    78 
    79 /****************************************************************************
    80  Print out a canonical IPv4 or IPv6 address from a struct sockaddr_storage.
    81 ****************************************************************************/
    82 
    83 char *print_canonical_sockaddr(TALLOC_CTX *ctx,
    84                         const struct sockaddr_storage *pss)
    85 {
    86         char addr[INET6_ADDRSTRLEN];
    87         char *dest = NULL;
    88         int ret;
    89 
    90         /* Linux getnameinfo() man pages says port is unitialized if
    91            service name is NULL. */
    92 
    93         ret = sys_getnameinfo((const struct sockaddr *)pss,
    94                         sizeof(struct sockaddr_storage),
    95                         addr, sizeof(addr),
    96                         NULL, 0,
    97                         NI_NUMERICHOST);
    98         if (ret != 0) {
    99                 return NULL;
    100         }
    101 
    102         if (pss->ss_family != AF_INET) {
    103 #if defined(HAVE_IPV6)
    104                 dest = talloc_asprintf(ctx, "[%s]", addr);
    105 #else
    106                 return NULL;
    107 #endif
    108         } else {
    109                 dest = talloc_asprintf(ctx, "%s", addr);
    110         }
    111        
    112         return dest;
    113 }
    114 
    115 /****************************************************************************
    116  Return the string of an IP address (IPv4 or IPv6).
    117 ****************************************************************************/
    118 
    119 static const char *get_socket_addr(int fd, char *addr_buf, size_t addr_len)
    120 {
    121         struct sockaddr_storage sa;
    122         socklen_t length = sizeof(sa);
    123 
    124         /* Ok, returning a hard coded IPv4 address
    125          * is bogus, but it's just as bogus as a
    126          * zero IPv6 address. No good choice here.
    127          */
    128 
    129         strlcpy(addr_buf, "0.0.0.0", addr_len);
    130 
    131         if (fd == -1) {
    132                 return addr_buf;
    133         }
    134 
    135         if (getsockname(fd, (struct sockaddr *)&sa, &length) < 0) {
    136                 DEBUG(0,("getsockname failed. Error was %s\n",
    137                         strerror(errno) ));
    138                 return addr_buf;
    139         }
    140 
    141         return print_sockaddr_len(addr_buf, addr_len, (struct sockaddr *)&sa, length);
    142 }
    143 
    144 /****************************************************************************
    145  Return the port number we've bound to on a socket.
    146 ****************************************************************************/
    147 
    148 int get_socket_port(int fd)
    149 {
    150         struct sockaddr_storage sa;
    151         socklen_t length = sizeof(sa);
    152 
    153         if (fd == -1) {
    154                 return -1;
    155         }
    156 
    157         if (getsockname(fd, (struct sockaddr *)&sa, &length) < 0) {
    158                 DEBUG(0,("getpeername failed. Error was %s\n",
    159                         strerror(errno) ));
    160                 return -1;
    161         }
    162 
    163 #if defined(HAVE_IPV6)
    164         if (sa.ss_family == AF_INET6) {
    165                 return ntohs(((struct sockaddr_in6 *)&sa)->sin6_port);
    166         }
    167 #endif
    168         if (sa.ss_family == AF_INET) {
    169                 return ntohs(((struct sockaddr_in *)&sa)->sin_port);
    170         }
    171         return -1;
    172 }
     23#include "system/filesys.h"
     24#include "memcache.h"
     25#include "../lib/async_req/async_sock.h"
     26#include "../lib/util/select.h"
     27#include "interfaces.h"
     28#include "../lib/util/tevent_unix.h"
     29#include "../lib/util/tevent_ntstatus.h"
    17330
    17431const char *client_name(int fd)
     
    18037{
    18138        return get_peer_addr(fd,addr,addrlen);
    182 }
    183 
    184 const char *client_socket_addr(int fd, char *addr, size_t addr_len)
    185 {
    186         return get_socket_addr(fd, addr, addr_len);
    18739}
    18840
     
    285137#ifdef TCP_QUICKACK
    286138  {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL},
     139#endif
     140#ifdef TCP_KEEPALIVE_THRESHOLD
     141  {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT},
     142#endif
     143#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD
     144  {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT},
    287145#endif
    288146  {NULL,0,0,0,0}};
     
    437295                                  size_t *size_ret)
    438296{
    439         fd_set fds;
    440         int selrtn;
     297        int pollrtn;
    441298        ssize_t readret;
    442299        size_t nread = 0;
    443         struct timeval timeout;
    444         char addr[INET6_ADDRSTRLEN];
    445         int save_errno;
    446300
    447301        /* just checking .... */
     
    465319
    466320                        if (readret == -1) {
    467                                 save_errno = errno;
    468                                 if (fd == get_client_fd()) {
    469                                         /* Try and give an error message
    470                                          * saying what client failed. */
    471                                         DEBUG(0,("read_fd_with_timeout: "
    472                                                 "client %s read error = %s.\n",
    473                                                 get_peer_addr(fd,addr,sizeof(addr)),
    474                                                 strerror(save_errno) ));
    475                                 } else {
    476                                         DEBUG(0,("read_fd_with_timeout: "
    477                                                 "read error = %s.\n",
    478                                                 strerror(save_errno) ));
    479                                 }
    480                                 return map_nt_error_from_unix(save_errno);
     321                                return map_nt_error_from_unix(errno);
    481322                        }
    482323                        nread += readret;
     
    491332           select always returns true on disk files */
    492333
    493         /* Set initial timeout */
    494         timeout.tv_sec = (time_t)(time_out / 1000);
    495         timeout.tv_usec = (long)(1000 * (time_out % 1000));
    496 
    497334        for (nread=0; nread < mincnt; ) {
    498                 if (fd < 0 || fd >= FD_SETSIZE) {
    499                         errno = EBADF;
    500                         return map_nt_error_from_unix(EBADF);
    501                 }
    502 
    503                 FD_ZERO(&fds);
    504                 FD_SET(fd,&fds);
    505 
    506                 selrtn = sys_select_intr(fd+1,&fds,NULL,NULL,&timeout);
     335                int revents;
     336
     337                pollrtn = poll_intr_one_fd(fd, POLLIN|POLLHUP, time_out,
     338                                           &revents);
    507339
    508340                /* Check if error */
    509                 if (selrtn == -1) {
    510                         save_errno = errno;
    511                         /* something is wrong. Maybe the socket is dead? */
    512                         if (fd == get_client_fd()) {
    513                                 /* Try and give an error message saying
    514                                  * what client failed. */
    515                                 DEBUG(0,("read_fd_with_timeout: timeout "
    516                                 "read for client %s. select error = %s.\n",
    517                                 get_peer_addr(fd,addr,sizeof(addr)),
    518                                 strerror(save_errno) ));
    519                         } else {
    520                                 DEBUG(0,("read_fd_with_timeout: timeout "
    521                                 "read. select error = %s.\n",
    522                                 strerror(save_errno) ));
    523                         }
    524                         return map_nt_error_from_unix(save_errno);
     341                if (pollrtn == -1) {
     342                        return map_nt_error_from_unix(errno);
    525343                }
    526344
    527345                /* Did we timeout ? */
    528                 if (selrtn == 0) {
     346                if ((pollrtn == 0) ||
     347                    ((revents & (POLLIN|POLLHUP|POLLERR)) == 0)) {
    529348                        DEBUG(10,("read_fd_with_timeout: timeout read. "
    530349                                "select timed out.\n"));
     
    542361
    543362                if (readret == -1) {
    544                         save_errno = errno;
    545                         /* the descriptor is probably dead */
    546                         if (fd == get_client_fd()) {
    547                                 /* Try and give an error message
    548                                  * saying what client failed. */
    549                                 DEBUG(0,("read_fd_with_timeout: timeout "
    550                                         "read to client %s. read error = %s.\n",
    551                                         get_peer_addr(fd,addr,sizeof(addr)),
    552                                         strerror(save_errno) ));
    553                         } else {
    554                                 DEBUG(0,("read_fd_with_timeout: timeout "
    555                                         "read. read error = %s.\n",
    556                                         strerror(save_errno) ));
    557                         }
    558363                        return map_nt_error_from_unix(errno);
    559364                }
     
    660465ssize_t write_data(int fd, const char *buffer, size_t N)
    661466{
    662         ssize_t ret;
    663467        struct iovec iov;
    664468
    665469        iov.iov_base = CONST_DISCARD(void *, buffer);
    666470        iov.iov_len = N;
    667 
    668         ret = write_data_iov(fd, &iov, 1);
    669         if (ret >= 0) {
    670                 return ret;
    671         }
    672 
    673         if (fd == get_client_fd()) {
    674                 char addr[INET6_ADDRSTRLEN];
    675                 /*
    676                  * Try and give an error message saying what client failed.
    677                  */
    678                 DEBUG(0, ("write_data: write failure in writing to client %s. "
    679                           "Error %s\n", get_peer_addr(fd,addr,sizeof(addr)),
    680                           strerror(errno)));
    681         } else {
    682                 DEBUG(0,("write_data: write failure. Error = %s\n",
    683                          strerror(errno) ));
    684         }
    685 
    686         return -1;
     471        return write_data_iov(fd, &iov, 1);
    687472}
    688473
     
    730515
    731516        DEBUG(10,("got smb length of %lu\n",(unsigned long)(*len)));
    732 
    733         return NT_STATUS_OK;
    734 }
    735 
    736 /****************************************************************************
    737  Read 4 bytes of a smb packet and return the smb length of the packet.
    738  Store the result in the buffer. This version of the function will
    739  never return a session keepalive (length of zero).
    740  Timeout is in milliseconds.
    741 ****************************************************************************/
    742 
    743 NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout,
    744                          size_t *len)
    745 {
    746         uint8_t msgtype = SMBkeepalive;
    747 
    748         while (msgtype == SMBkeepalive) {
    749                 NTSTATUS status;
    750 
    751                 status = read_smb_length_return_keepalive(fd, inbuf, timeout,
    752                                                           len);
    753                 if (!NT_STATUS_IS_OK(status)) {
    754                         return status;
    755                 }
    756 
    757                 msgtype = CVAL(inbuf, 0);
    758         }
    759 
    760         DEBUG(10,("read_smb_length: got smb length of %lu\n",
    761                   (unsigned long)len));
    762517
    763518        return NT_STATUS_OK;
     
    782537
    783538        if (!NT_STATUS_IS_OK(status)) {
    784                 DEBUG(10, ("receive_smb_raw: %s!\n", nt_errstr(status)));
     539                DEBUG(0, ("read_fd_with_timeout failed, read "
     540                          "error = %s.\n", nt_errstr(status)));
    785541                return status;
    786542        }
     
    801557
    802558                if (!NT_STATUS_IS_OK(status)) {
     559                        DEBUG(0, ("read_fd_with_timeout failed, read error = "
     560                                  "%s.\n", nt_errstr(status)));
    803561                        return status;
    804562                }
     
    876634        }
    877635
     636#ifdef HAVE_IPV6
     637        /*
     638         * As IPV6_V6ONLY is the default on some systems,
     639         * we better try to be consistent and always use it.
     640         *
     641         * This also avoids using IPv4 via AF_INET6 sockets
     642         * and makes sure %I never resolves to a '::ffff:192.168.0.1'
     643         * string.
     644         */
     645        if (sock.ss_family == AF_INET6) {
     646                int val = 1;
     647                int ret;
     648
     649                ret = setsockopt(res, IPPROTO_IPV6, IPV6_V6ONLY,
     650                                 (const void *)&val, sizeof(val));
     651                if (ret == -1) {
     652                        if(DEBUGLVL(0)) {
     653                                dbgtext("open_socket_in(): IPV6_ONLY failed: ");
     654                                dbgtext("%s\n", strerror(errno));
     655                        }
     656                        close(res);
     657                        return -1;
     658                }
     659        }
     660#endif
     661
    878662        /* now we've got a socket - we need to bind it */
    879663        if (bind(res, (struct sockaddr *)&sock, slen) == -1 ) {
     
    1072856}
    1073857
     858/**
     859* @brief open a socket
     860*
     861* @param pss a struct sockaddr_storage defining the address to connect to
     862* @param port to connect to
     863* @param timeout in MILLISECONDS
     864* @param pfd file descriptor returned
     865*
     866* @return NTSTATUS code
     867*/
    1074868NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port,
    1075869                         int timeout, int *pfd)
     
    1197991}
    1198992
    1199 /*******************************************************************
    1200  Create an outgoing TCP socket to the first addr that connects.
    1201 
    1202  This is for simultaneous connection attempts to port 445 and 139 of a host
    1203  or for simultatneous connection attempts to multiple DCs at once.  We return
    1204  a socket fd of the first successful connection.
    1205 
    1206  @param[in] addrs list of Internet addresses and ports to connect to
    1207  @param[in] num_addrs number of address/port pairs in the addrs list
    1208  @param[in] timeout time after which we stop waiting for a socket connection
    1209             to succeed, given in milliseconds
    1210  @param[out] fd_index the entry in addrs which we successfully connected to
    1211  @param[out] fd fd of the open and connected socket
    1212  @return true on a successful connection, false if all connection attempts
    1213          failed or we timed out
    1214 *******************************************************************/
    1215 
    1216 bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
    1217                          int timeout, int *fd_index, int *fd)
    1218 {
    1219         int i, resulting_index, res;
    1220         int *sockets;
    1221         bool good_connect;
    1222 
    1223         fd_set r_fds, wr_fds;
    1224         struct timeval tv;
    1225         int maxfd;
    1226 
    1227         int connect_loop = 10000; /* 10 milliseconds */
    1228 
    1229         timeout *= 1000;        /* convert to microseconds */
    1230 
    1231         sockets = SMB_MALLOC_ARRAY(int, num_addrs);
    1232 
    1233         if (sockets == NULL)
    1234                 return false;
    1235 
    1236         resulting_index = -1;
    1237 
    1238         for (i=0; i<num_addrs; i++)
    1239                 sockets[i] = -1;
    1240 
    1241         for (i=0; i<num_addrs; i++) {
    1242                 sockets[i] = socket(addrs[i].ss_family, SOCK_STREAM, 0);
    1243                 if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE)
    1244                         goto done;
    1245                 set_blocking(sockets[i], false);
    1246         }
    1247 
    1248  connect_again:
    1249         good_connect = false;
    1250 
    1251         for (i=0; i<num_addrs; i++) {
    1252                 const struct sockaddr * a =
    1253                     (const struct sockaddr *)&(addrs[i]);
    1254 
    1255                 if (sockets[i] == -1)
    1256                         continue;
    1257 
    1258                 if (sys_connect(sockets[i], a) == 0) {
    1259                         /* Rather unlikely as we are non-blocking, but it
    1260                          * might actually happen. */
    1261                         resulting_index = i;
    1262                         goto done;
    1263                 }
    1264 
    1265                 if (errno == EINPROGRESS || errno == EALREADY ||
    1266 #ifdef EISCONN
    1267                         errno == EISCONN ||
    1268 #endif
    1269                     errno == EAGAIN || errno == EINTR) {
    1270                         /* These are the error messages that something is
    1271                            progressing. */
    1272                         good_connect = true;
    1273                 } else if (errno != 0) {
    1274                         /* There was a direct error */
    1275                         close(sockets[i]);
    1276                         sockets[i] = -1;
    1277                 }
    1278         }
    1279 
    1280         if (!good_connect) {
    1281                 /* All of the connect's resulted in real error conditions */
    1282                 goto done;
    1283         }
    1284 
    1285         /* Lets see if any of the connect attempts succeeded */
    1286 
    1287         maxfd = 0;
    1288         FD_ZERO(&wr_fds);
    1289         FD_ZERO(&r_fds);
    1290 
    1291         for (i=0; i<num_addrs; i++) {
    1292                 if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE) {
    1293                         /* This cannot happen - ignore if so. */
    1294                         continue;
    1295                 }
    1296                 FD_SET(sockets[i], &wr_fds);
    1297                 FD_SET(sockets[i], &r_fds);
    1298                 if (sockets[i]>maxfd)
    1299                         maxfd = sockets[i];
    1300         }
    1301 
    1302         tv.tv_sec = 0;
    1303         tv.tv_usec = connect_loop;
    1304 
    1305         res = sys_select_intr(maxfd+1, &r_fds, &wr_fds, NULL, &tv);
    1306 
    1307         if (res < 0)
    1308                 goto done;
    1309 
    1310         if (res == 0)
    1311                 goto next_round;
    1312 
    1313         for (i=0; i<num_addrs; i++) {
    1314 
    1315                 if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE) {
    1316                         /* This cannot happen - ignore if so. */
    1317                         continue;
    1318                 }
    1319 
    1320                 /* Stevens, Network Programming says that if there's a
    1321                  * successful connect, the socket is only writable. Upon an
    1322                  * error, it's both readable and writable. */
    1323 
    1324                 if (FD_ISSET(sockets[i], &r_fds) &&
    1325                     FD_ISSET(sockets[i], &wr_fds)) {
    1326                         /* readable and writable, so it's an error */
    1327                         close(sockets[i]);
    1328                         sockets[i] = -1;
    1329                         continue;
    1330                 }
    1331 
    1332                 if (!FD_ISSET(sockets[i], &r_fds) &&
    1333                     FD_ISSET(sockets[i], &wr_fds)) {
    1334                         /* Only writable, so it's connected */
    1335                         resulting_index = i;
    1336                         goto done;
    1337                 }
    1338         }
    1339 
    1340  next_round:
    1341 
    1342         timeout -= connect_loop;
    1343         if (timeout <= 0)
    1344                 goto done;
    1345         connect_loop *= 1.5;
    1346         if (connect_loop > timeout)
    1347                 connect_loop = timeout;
    1348         goto connect_again;
    1349 
    1350  done:
    1351         for (i=0; i<num_addrs; i++) {
    1352                 if (i == resulting_index)
    1353                         continue;
    1354                 if (sockets[i] >= 0)
    1355                         close(sockets[i]);
    1356         }
    1357 
    1358         if (resulting_index >= 0) {
    1359                 *fd_index = resulting_index;
    1360                 *fd = sockets[*fd_index];
    1361                 set_blocking(*fd, true);
    1362         }
    1363 
    1364         free(sockets);
    1365 
    1366         return (resulting_index >= 0);
    1367 }
    1368993/****************************************************************************
    1369994 Open a connected UDP socket to host on port
     
    14381063
    14391064        if (getpeername(fd, (struct sockaddr *)pss, plength) < 0) {
    1440                 DEBUG(0,("getpeername failed. Error was %s\n",
    1441                                         strerror(errno) ));
     1065                int level = (errno == ENOTCONN) ? 2 : 0;
     1066                DEBUG(level, ("getpeername failed. Error was %s\n",
     1067                               strerror(errno)));
    14421068                return addr_buf;
    14431069        }
     
    17311357#ifdef __OS2__
    17321358        if (asprintf(&path, "\\socket\\samba\\%s\\%s", socket_dir, socket_name) == -1) {
    1733 #else       
     1359#else
    17341360        if (asprintf(&path, "%s/%s", socket_dir, socket_name) == -1) {
    17351361#endif
     
    18631489        }
    18641490
    1865         if (is_zero_addr((struct sockaddr *)&ss) ||
     1491        if (is_zero_addr(&ss) ||
    18661492                is_loopback_addr((struct sockaddr *)&ss)) {
    18671493                return false;
     
    19331559        }
    19341560
     1561        /* Maybe its an IP address? */
     1562        if (is_ipaddress(servername)) {
     1563                return is_my_ipaddr(servername);
     1564        }
     1565
    19351566        /* Handle possible CNAME records - convert to an IP addr. list. */
    1936         if (!is_ipaddress(servername)) {
     1567        {
    19371568                /* Use DNS to resolve the name, check all addresses. */
    19381569                struct addrinfo *p = NULL;
     
    19621593        }
    19631594
    1964         /* Maybe its an IP address? */
    1965         if (is_ipaddress(servername)) {
    1966                 return is_my_ipaddr(servername);
    1967         }
    1968 
    19691595        /* No match */
    19701596        return false;
     
    20521678        return state->ret;
    20531679}
     1680
     1681int poll_one_fd(int fd, int events, int timeout, int *revents)
     1682{
     1683        struct pollfd *fds;
     1684        int ret;
     1685        int saved_errno;
     1686
     1687        fds = TALLOC_ZERO_ARRAY(talloc_tos(), struct pollfd, 2);
     1688        if (fds == NULL) {
     1689                errno = ENOMEM;
     1690                return -1;
     1691        }
     1692        fds[0].fd = fd;
     1693        fds[0].events = events;
     1694
     1695        ret = sys_poll(fds, 1, timeout);
     1696
     1697        /*
     1698         * Assign whatever poll did, even in the ret<=0 case.
     1699         */
     1700        *revents = fds[0].revents;
     1701        saved_errno = errno;
     1702        TALLOC_FREE(fds);
     1703        errno = saved_errno;
     1704
     1705        return ret;
     1706}
     1707
     1708int poll_intr_one_fd(int fd, int events, int timeout, int *revents)
     1709{
     1710        struct pollfd pfd;
     1711        int ret;
     1712
     1713        pfd.fd = fd;
     1714        pfd.events = events;
     1715
     1716        ret = sys_poll_intr(&pfd, 1, timeout);
     1717        if (ret <= 0) {
     1718                *revents = 0;
     1719                return ret;
     1720        }
     1721        *revents = pfd.revents;
     1722        return 1;
     1723}
  • trunk/server/source3/lib/util_str.c

    r599 r745  
    244244                while (isspace((int)*psz2))
    245245                        psz2++;
    246                 if (toupper_ascii(*psz1) != toupper_ascii(*psz2) ||
     246                if (toupper_m(*psz1) != toupper_m(*psz2) ||
    247247                                *psz1 == '\0' || *psz2 == '\0')
    248248                        break;
     
    827827                for (i=0;i<li;i++) {
    828828                        switch (insert[i]) {
    829                         case '`':
    830                         case '"':
    831                         case '\'':
    832                         case ';':
    833829                        case '$':
    834830                                /* allow a trailing $
     
    838834                                        break;
    839835                                }
     836                        case '`':
     837                        case '"':
     838                        case '\'':
     839                        case ';':
    840840                        case '%':
    841841                        case '\r':
     
    909909        for (i=0;i<li;i++) {
    910910                switch (in[i]) {
    911                         case '`':
    912                         case '"':
    913                         case '\'':
    914                         case ';':
    915911                        case '$':
    916912                                /* allow a trailing $
     
    919915                                        break;
    920916                                }
     917                        case '`':
     918                        case '"':
     919                        case '\'':
     920                        case ';':
    921921                        case '%':
    922922                        case '\r':
     
    10041004        for (i=0;i<li;i++) {
    10051005                switch (in[i]) {
    1006                         case '`':
    1007                         case '"':
    1008                         case '\'':
    1009                         case ';':
    10101006                        case '$':
    10111007                                /* allow a trailing $
     
    10141010                                        break;
    10151011                                }
     1012                        case '`':
     1013                        case '"':
     1014                        case '\'':
     1015                        case ';':
    10161016                        case '%':
    10171017                        case '\r':
     
    14071407
    14081408        while (*s && !(((unsigned char)s[0]) & 0x80)) {
    1409                 *s = tolower_ascii((unsigned char)*s);
     1409                *s = tolower_m((unsigned char)*s);
    14101410                s++;
    14111411        }
     
    14631463 * Calculate the number of units (8 or 16-bit, depending on the
    14641464 * destination charset), that would be needed to convert the input
    1465  * string which is expected to be in in CH_UNIX encoding to the
     1465 * string which is expected to be in in src_charset encoding to the
    14661466 * destination charset (which should be a unicode charset).
    14671467 */
    1468 size_t strlen_m_ext(const char *s, const charset_t dst_charset)
     1468
     1469size_t strlen_m_ext(const char *s, const charset_t src_charset,
     1470                    const charset_t dst_charset)
    14691471{
    14701472        size_t count = 0;
     
    14851487        while (*s) {
    14861488                size_t c_size;
    1487                 codepoint_t c = next_codepoint(s, &c_size);
     1489                codepoint_t c = next_codepoint_ext(s, src_charset, &c_size);
    14881490                s += c_size;
    14891491
    1490                 switch(dst_charset) {
     1492                switch (dst_charset) {
    14911493                case CH_UTF16LE:
    14921494                case CH_UTF16BE:
     
    15281530}
    15291531
    1530 size_t strlen_m_ext_term(const char *s, const charset_t dst_charset)
     1532size_t strlen_m_ext_term(const char *s, const charset_t src_charset,
     1533                         const charset_t dst_charset)
    15311534{
    15321535        if (!s) {
    15331536                return 0;
    15341537        }
    1535         return strlen_m_ext(s, dst_charset) + 1;
    1536 }
    1537 
    1538 /**
    1539  Count the number of UCS2 characters in a string. Normally this will
    1540  be the same as the number of bytes in a string for single byte strings,
    1541  but will be different for multibyte.
    1542 **/
     1538        return strlen_m_ext(s, src_charset, dst_charset) + 1;
     1539}
     1540
     1541/**
     1542 * Calculate the number of 16-bit units that would bee needed to convert
     1543 * the input string which is expected to be in CH_UNIX encoding to UTF16.
     1544 *
     1545 * This will be the same as the number of bytes in a string for single
     1546 * byte strings, but will be different for multibyte.
     1547 */
    15431548
    15441549size_t strlen_m(const char *s)
    15451550{
    1546         return strlen_m_ext(s, CH_UTF16LE);
     1551        return strlen_m_ext(s, CH_UNIX, CH_UTF16LE);
    15471552}
    15481553
     
    15771582
    15781583        return len+1;
    1579 }
    1580 /**
    1581  Return a RFC2254 binary string representation of a buffer.
    1582  Used in LDAP filters.
    1583  Caller must free.
    1584 **/
    1585 
    1586 char *binary_string_rfc2254(TALLOC_CTX *mem_ctx, const uint8_t *buf, int len)
    1587 {
    1588         char *s;
    1589         int i, j;
    1590         const char *hex = "0123456789ABCDEF";
    1591         s = talloc_array(mem_ctx, char, len * 3 + 1);
    1592         if (s == NULL) {
    1593                 return NULL;
    1594         }
    1595         for (j=i=0;i<len;i++) {
    1596                 s[j] = '\\';
    1597                 s[j+1] = hex[((unsigned char)buf[i]) >> 4];
    1598                 s[j+2] = hex[((unsigned char)buf[i]) & 0xF];
    1599                 j += 3;
    1600         }
    1601         s[j] = 0;
    1602         return s;
    1603 }
    1604 
    1605 char *binary_string(char *buf, int len)
    1606 {
    1607         char *s;
    1608         int i, j;
    1609         const char *hex = "0123456789ABCDEF";
    1610         s = (char *)SMB_MALLOC(len * 2 + 1);
    1611         if (!s)
    1612                 return NULL;
    1613         for (j=i=0;i<len;i++) {
    1614                 s[j]   = hex[((unsigned char)buf[i]) >> 4];
    1615                 s[j+1] = hex[((unsigned char)buf[i]) & 0xF];
    1616                 j += 2;
    1617         }
    1618         s[j] = 0;
    1619         return s;
    16201584}
    16211585
     
    20221986{
    20231987
    2024         uint64_t val = -1;
     1988        uint64_t val = (uint64_t)-1;
    20251989        const char *p = nptr;
    20261990
     
    20582022SMB_OFF_T conv_str_size(const char * str)
    20592023{
     2024        SMB_OFF_T lval_orig;
    20602025        SMB_OFF_T lval;
    20612026        char * end;
     
    20672032#ifdef HAVE_STRTOULL
    20682033        if (sizeof(SMB_OFF_T) == 8) {
    2069             lval = strtoull(str, &end, 10 /* base */);
     2034                lval = strtoull(str, &end, 10 /* base */);
    20702035        } else {
    2071             lval = strtoul(str, &end, 10 /* base */);
     2036                lval = strtoul(str, &end, 10 /* base */);
    20722037        }
    20732038#else
     
    20792044        }
    20802045
    2081         if (*end) {
    2082                 SMB_OFF_T lval_orig = lval;
    2083 
    2084                 if (strwicmp(end, "K") == 0) {
    2085                         lval *= (SMB_OFF_T)1024;
    2086                 } else if (strwicmp(end, "M") == 0) {
    2087                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024);
    2088                 } else if (strwicmp(end, "G") == 0) {
    2089                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
    2090                                 (SMB_OFF_T)1024);
    2091                 } else if (strwicmp(end, "T") == 0) {
    2092                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
    2093                                 (SMB_OFF_T)1024 * (SMB_OFF_T)1024);
    2094                 } else if (strwicmp(end, "P") == 0) {
    2095                         lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
    2096                                 (SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
    2097                                 (SMB_OFF_T)1024);
    2098                 } else {
    2099                         return 0;
    2100                 }
    2101 
    2102                 /* Primitive attempt to detect wrapping on platforms with
    2103                  * 4-byte SMB_OFF_T. It's better to let the caller handle
    2104                  * a failure than some random number.
    2105                  */
    2106                 if (lval_orig <= lval) {
    2107                         return 0;
    2108                 }
    2109         }
     2046        if (*end == '\0') {
     2047                return lval;
     2048        }
     2049
     2050        lval_orig = lval;
     2051
     2052        if (strwicmp(end, "K") == 0) {
     2053                lval *= (SMB_OFF_T)1024;
     2054        } else if (strwicmp(end, "M") == 0) {
     2055                lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024);
     2056        } else if (strwicmp(end, "G") == 0) {
     2057                lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
     2058                         (SMB_OFF_T)1024);
     2059        } else if (strwicmp(end, "T") == 0) {
     2060                lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
     2061                         (SMB_OFF_T)1024 * (SMB_OFF_T)1024);
     2062        } else if (strwicmp(end, "P") == 0) {
     2063                lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
     2064                         (SMB_OFF_T)1024 * (SMB_OFF_T)1024 *
     2065                         (SMB_OFF_T)1024);
     2066        } else {
     2067                return 0;
     2068        }
     2069
     2070        /*
     2071         * Primitive attempt to detect wrapping on platforms with
     2072         * 4-byte SMB_OFF_T. It's better to let the caller handle a
     2073         * failure than some random number.
     2074         */
     2075        if (lval_orig <= lval) {
     2076                return 0;
     2077        }
    21102078
    21112079        return lval;
     
    21182086        if (*left == NULL) {
    21192087                *left = (char *)SMB_MALLOC(new_len);
     2088                if (*left == NULL) {
     2089                        return;
     2090                }
    21202091                *left[0] = '\0';
    21212092        } else {
     
    23012272{
    23022273        int i;
     2274
     2275        if (!name) {
     2276                return false;
     2277        }
    23032278
    23042279        for ( i=0; i<max_len && name[i]; i++ ) {
     
    25482523        return list;
    25492524}
     2525
     2526char *sanitize_username(TALLOC_CTX *mem_ctx, const char *username)
     2527{
     2528        fstring tmp;
     2529
     2530        alpha_strcpy(tmp, username, ". _-$", sizeof(tmp));
     2531        return talloc_strdup(mem_ctx, tmp);
     2532}
  • trunk/server/source3/lib/util_tdb.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "system/filesys.h"
     24#include "util_tdb.h"
     25
    2326#undef malloc
    2427#undef realloc
     
    3538****************************************************************/
    3639
    37 static void gotalarm_sig(void)
     40static void gotalarm_sig(int signum)
    3841{
    3942        gotalarm = 1;
     
    5154
    5255        if (timeout) {
    53                 CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
     56                CatchSignal(SIGALRM, gotalarm_sig);
    5457                tdb_setalarm_sigptr(tdb, &gotalarm);
    5558                alarm(timeout);
     
    6467                alarm(0);
    6568                tdb_setalarm_sigptr(tdb, NULL);
    66                 CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
     69                CatchSignal(SIGALRM, SIG_IGN);
    6770                if (gotalarm && (ret == -1)) {
    6871                        DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
     
    482485}
    483486
    484 /*
    485  Log tdb messages via DEBUG().
    486 */
    487 static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
    488                          const char *format, ...) PRINTF_ATTRIBUTE(3,4);
    489 
    490 static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
    491                          const char *format, ...)
    492 {
    493         va_list ap;
    494         char *ptr = NULL;
    495         int debuglevel = 0;
    496         int ret;
    497 
    498         switch (level) {
    499         case TDB_DEBUG_FATAL:
    500                 debuglevel = 0;
    501                 break;
    502         case TDB_DEBUG_ERROR:
    503                 debuglevel = 1;
    504                 break;
    505         case TDB_DEBUG_WARNING:
    506                 debuglevel = 2;
    507                 break;
    508         case TDB_DEBUG_TRACE:
    509                 debuglevel = 5;
    510                 break;
    511         default:
    512                 debuglevel = 0;
    513         }               
    514 
    515         va_start(ap, format);
    516         ret = vasprintf(&ptr, format, ap);
    517         va_end(ap);
    518 
    519         if (ret != -1) {
    520                 const char *name = tdb_name(tdb);
    521                 DEBUG(debuglevel, ("tdb(%s): %s", name ? name : "unnamed", ptr));
    522                 free(ptr);
    523         }
    524 }
    525 
    526 static struct tdb_wrap *tdb_list;
    527 
    528 /* destroy the last connection to a tdb */
    529 static int tdb_wrap_destructor(struct tdb_wrap *w)
    530 {
    531         tdb_close(w->tdb);
    532         DLIST_REMOVE(tdb_list, w);
    533         return 0;
    534 }                               
    535 
    536 /*
    537   wrapped connection to a tdb database
    538   to close just talloc_free() the tdb_wrap pointer
    539  */
    540 struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
    541                                const char *name, int hash_size, int tdb_flags,
    542                                int open_flags, mode_t mode)
    543 {
    544         struct tdb_wrap *w;
    545         struct tdb_logging_context log_ctx;
    546         log_ctx.log_fn = tdb_wrap_log;
    547 
    548         if (!lp_use_mmap())
    549                 tdb_flags |= TDB_NOMMAP;
    550 
    551         for (w=tdb_list;w;w=w->next) {
    552                 if (strcmp(name, w->name) == 0) {
    553                         /*
    554                          * Yes, talloc_reference is exactly what we want
    555                          * here. Otherwise we would have to implement our own
    556                          * reference counting.
    557                          */
    558                         return talloc_reference(mem_ctx, w);
    559                 }
    560         }
    561 
    562         w = talloc(mem_ctx, struct tdb_wrap);
    563         if (w == NULL) {
    564                 return NULL;
    565         }
    566 
    567         if (!(w->name = talloc_strdup(w, name))) {
    568                 talloc_free(w);
    569                 return NULL;
    570         }
    571 
    572         if ((hash_size == 0) && (name != NULL)) {
    573                 const char *base = strrchr_m(name, '/');
    574                 if (base != NULL) {
    575                         base += 1;
    576                 }
    577                 else {
    578                         base = name;
    579                 }
    580                 hash_size = lp_parm_int(-1, "tdb_hashsize", base, 0);
    581         }
    582 
    583         w->tdb = tdb_open_ex(name, hash_size, tdb_flags,
    584                              open_flags, mode, &log_ctx, NULL);
    585         if (w->tdb == NULL) {
    586                 talloc_free(w);
    587                 return NULL;
    588         }
    589 
    590         talloc_set_destructor(w, tdb_wrap_destructor);
    591 
    592         DLIST_ADD(tdb_list, w);
    593 
    594         return w;
    595 }
    596 
    597487NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err)
    598488{
    599         struct { enum TDB_ERROR err; NTSTATUS status; } map[] =
    600                 { { TDB_SUCCESS,        NT_STATUS_OK },
    601                   { TDB_ERR_CORRUPT,    NT_STATUS_INTERNAL_DB_CORRUPTION },
    602                   { TDB_ERR_IO,         NT_STATUS_UNEXPECTED_IO_ERROR },
    603                   { TDB_ERR_OOM,        NT_STATUS_NO_MEMORY },
    604                   { TDB_ERR_EXISTS,     NT_STATUS_OBJECT_NAME_COLLISION },
    605 
    606                   /*
    607                    * TDB_ERR_LOCK is very broad, we could for example
    608                    * distinguish between fcntl locks and invalid lock
    609                    * sequences. So NT_STATUS_FILE_LOCK_CONFLICT is a
    610                    * compromise.
    611                    */
    612                   { TDB_ERR_LOCK,       NT_STATUS_FILE_LOCK_CONFLICT },
    613                   /*
    614                    * The next two ones in the enum are not actually used
    615                    */
    616                   { TDB_ERR_NOLOCK,     NT_STATUS_FILE_LOCK_CONFLICT },
    617                   { TDB_ERR_LOCK_TIMEOUT, NT_STATUS_FILE_LOCK_CONFLICT },
    618                   { TDB_ERR_NOEXIST,    NT_STATUS_NOT_FOUND },
    619                   { TDB_ERR_EINVAL,     NT_STATUS_INVALID_PARAMETER },
    620                   { TDB_ERR_RDONLY,     NT_STATUS_ACCESS_DENIED }
    621                 };
    622 
    623         int i;
    624 
    625         for (i=0; i < sizeof(map) / sizeof(map[0]); i++) {
    626                 if (err == map[i].err) {
    627                         return map[i].status;
    628                 }
    629         }
    630 
    631         return NT_STATUS_INTERNAL_ERROR;
     489        NTSTATUS result = NT_STATUS_INTERNAL_ERROR;
     490
     491        switch (err) {
     492        case TDB_SUCCESS:
     493                result = NT_STATUS_OK;
     494                break;
     495        case TDB_ERR_CORRUPT:
     496                result = NT_STATUS_INTERNAL_DB_CORRUPTION;
     497                break;
     498        case TDB_ERR_IO:
     499                result = NT_STATUS_UNEXPECTED_IO_ERROR;
     500                break;
     501        case TDB_ERR_OOM:
     502                result = NT_STATUS_NO_MEMORY;
     503                break;
     504        case TDB_ERR_EXISTS:
     505                result = NT_STATUS_OBJECT_NAME_COLLISION;
     506                break;
     507
     508        case TDB_ERR_LOCK:
     509                /*
     510                 * TDB_ERR_LOCK is very broad, we could for example
     511                 * distinguish between fcntl locks and invalid lock
     512                 * sequences. So NT_STATUS_FILE_LOCK_CONFLICT is a
     513                 * compromise.
     514                 */
     515                result = NT_STATUS_FILE_LOCK_CONFLICT;
     516                break;
     517
     518        case TDB_ERR_NOLOCK:
     519        case TDB_ERR_LOCK_TIMEOUT:
     520                /*
     521                 * These two ones in the enum are not actually used
     522                 */
     523                result = NT_STATUS_FILE_LOCK_CONFLICT;
     524                break;
     525        case TDB_ERR_NOEXIST:
     526                result = NT_STATUS_NOT_FOUND;
     527                break;
     528        case TDB_ERR_EINVAL:
     529                result = NT_STATUS_INVALID_PARAMETER;
     530                break;
     531        case TDB_ERR_RDONLY:
     532                result = NT_STATUS_ACCESS_DENIED;
     533                break;
     534        case TDB_ERR_NESTING:
     535                result = NT_STATUS_INTERNAL_ERROR;
     536                break;
     537        };
     538        return result;
    632539}
    633540
  • trunk/server/source3/lib/util_transfer_file.c

    r414 r745  
    2222
    2323#include <includes.h>
     24#include "transfer_file.h"
    2425
    2526/****************************************************************************
  • trunk/server/source3/lib/util_tsock.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "../lib/tsocket/tsocket.h"
     22#include "../lib/util/tevent_unix.h"
    2123
    2224struct tstream_read_packet_state {
     
    5254                return tevent_req_post(req, ev);
    5355        }
    54         state->iov.iov_base = state->buf;
     56        state->iov.iov_base = (void *)state->buf;
    5557        state->iov.iov_len = initial;
    5658
     
    115117        state->buf = tmp;
    116118
    117         state->iov.iov_base = state->buf + total;
     119        state->iov.iov_base = (void *)(state->buf + total);
    118120        state->iov.iov_len = more;
    119121
  • trunk/server/source3/lib/util_unistr.c

    r414 r745  
    2222#include "includes.h"
    2323
    24 #ifndef MAXUNI
    25 #define MAXUNI 1024
    26 #endif
    27 
    2824/* these 3 tables define the unicode case handling.  They are loaded
    2925   at startup either via mmap() or read() from the lib directory */
    30 static smb_ucs2_t *upcase_table;
    31 static smb_ucs2_t *lowcase_table;
    3226static uint8 *valid_table;
    33 static bool upcase_table_use_unmap;
    34 static bool lowcase_table_use_unmap;
    35 static bool valid_table_use_unmap;
    3627static bool initialized;
    3728
     
    4132void gfree_case_tables(void)
    4233{
    43         if ( upcase_table ) {
    44                 if ( upcase_table_use_unmap )
    45                         unmap_file(upcase_table, 0x20000);
    46                 else
    47                         SAFE_FREE(upcase_table);
    48         }
    49 
    50         if ( lowcase_table ) {
    51                 if ( lowcase_table_use_unmap )
    52                         unmap_file(lowcase_table, 0x20000);
    53                 else
    54                         SAFE_FREE(lowcase_table);
    55         }
    56 
    5734        if ( valid_table ) {
    58                 if ( valid_table_use_unmap )
    59                         unmap_file(valid_table, 0x10000);
    60                 else
    61                         SAFE_FREE(valid_table);
     35                unmap_file(valid_table, 0x10000);
     36                valid_table = NULL;
    6237        }
    6338        initialized = false;
    64 }
    65 
    66 /**
    67  * Load or generate the case handling tables.
    68  *
    69  * The case tables are defined in UCS2 and don't depend on any
    70  * configured parameters, so they never need to be reloaded.
    71  **/
    72 
    73 void load_case_tables(void)
    74 {
    75         char *old_locale = NULL, *saved_locale = NULL;
    76         int i;
    77         TALLOC_CTX *frame = NULL;
    78 
    79         if (initialized) {
    80                 return;
    81         }
    82         initialized = true;
    83 
    84         frame = talloc_stackframe();
    85 
    86         upcase_table = (smb_ucs2_t *)map_file(data_path("upcase.dat"),
    87                                               0x20000);
    88         upcase_table_use_unmap = ( upcase_table != NULL );
    89 
    90         lowcase_table = (smb_ucs2_t *)map_file(data_path("lowcase.dat"),
    91                                                0x20000);
    92         lowcase_table_use_unmap = ( lowcase_table != NULL );
    93 
    94 #ifdef HAVE_SETLOCALE
    95         /* Get the name of the current locale.  */
    96         old_locale = setlocale(LC_ALL, NULL);
    97 
    98         if (old_locale) {
    99                 /* Save it as it is in static storage. */
    100                 saved_locale = SMB_STRDUP(old_locale);
    101         }
    102 
    103         /* We set back the locale to C to get ASCII-compatible toupper/lower functions. */
    104         setlocale(LC_ALL, "C");
    105 #endif
    106 
    107         /* we would like Samba to limp along even if these tables are
    108            not available */
    109         if (!upcase_table) {
    110                 DEBUG(1,("creating lame upcase table\n"));
    111                 upcase_table = (smb_ucs2_t *)SMB_MALLOC(0x20000);
    112                 for (i=0;i<0x10000;i++) {
    113                         smb_ucs2_t v;
    114                         SSVAL(&v, 0, i);
    115                         upcase_table[v] = i;
    116                 }
    117                 for (i=0;i<256;i++) {
    118                         smb_ucs2_t v;
    119                         SSVAL(&v, 0, UCS2_CHAR(i));
    120                         upcase_table[v] = UCS2_CHAR(islower(i)?toupper(i):i);
    121                 }
    122         }
    123 
    124         if (!lowcase_table) {
    125                 DEBUG(1,("creating lame lowcase table\n"));
    126                 lowcase_table = (smb_ucs2_t *)SMB_MALLOC(0x20000);
    127                 for (i=0;i<0x10000;i++) {
    128                         smb_ucs2_t v;
    129                         SSVAL(&v, 0, i);
    130                         lowcase_table[v] = i;
    131                 }
    132                 for (i=0;i<256;i++) {
    133                         smb_ucs2_t v;
    134                         SSVAL(&v, 0, UCS2_CHAR(i));
    135                         lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i);
    136                 }
    137         }
    138 
    139 #ifdef HAVE_SETLOCALE
    140         /* Restore the old locale. */
    141         if (saved_locale) {
    142                 setlocale (LC_ALL, saved_locale);
    143                 SAFE_FREE(saved_locale);
    144         }
    145 #endif
    146         TALLOC_FREE(frame);
    147 }
    148 
    149 static int check_dos_char_slowly(smb_ucs2_t c)
    150 {
    151         char buf[10];
    152         smb_ucs2_t c2 = 0;
    153         int len1, len2;
    154 
    155         len1 = convert_string(CH_UTF16LE, CH_DOS, &c, 2, buf, sizeof(buf),False);
    156         if (len1 == 0) {
    157                 return 0;
    158         }
    159         len2 = convert_string(CH_DOS, CH_UTF16LE, buf, len1, &c2, 2,False);
    160         if (len2 != 2) {
    161                 return 0;
    162         }
    163         return (c == c2);
    16439}
    16540
     
    17348 **/
    17449
    175 void init_valid_table(void)
    176 {
    177         static int mapped_file;
    178         int i;
    179         const char *allowed = ".!#$%&'()_-@^`~";
    180         uint8 *valid_file;
    181 
    182         if (mapped_file) {
    183                 /* Can't unmap files, so stick with what we have */
     50static void init_valid_table(void)
     51{
     52        if (valid_table) {
    18453                return;
    18554        }
    18655
    187         valid_file = (uint8 *)map_file(data_path("valid.dat"), 0x10000);
    188         if (valid_file) {
    189                 valid_table = valid_file;
    190                 mapped_file = 1;
    191                 valid_table_use_unmap = True;
     56        valid_table = (uint8 *)map_file(data_path("valid.dat"), 0x10000);
     57        if (!valid_table) {
     58                smb_panic("Could not load valid.dat file required for mangle method=hash");
    19259                return;
    193         }
    194 
    195         /* Otherwise, we're using a dynamically created valid_table.
    196          * It might need to be regenerated if the code page changed.
    197          * We know that we're not using a mapped file, so we can
    198          * free() the old one. */
    199         SAFE_FREE(valid_table);
    200 
    201         /* use free rather than unmap */
    202         valid_table_use_unmap = False;
    203 
    204         DEBUG(2,("creating default valid table\n"));
    205         valid_table = (uint8 *)SMB_MALLOC(0x10000);
    206         SMB_ASSERT(valid_table != NULL);
    207         for (i=0;i<128;i++) {
    208                 valid_table[i] = isalnum(i) || strchr(allowed,i);
    209         }
    210 
    211         lazy_initialize_conv();
    212 
    213         for (;i<0x10000;i++) {
    214                 smb_ucs2_t c;
    215                 SSVAL(&c, 0, i);
    216                 valid_table[i] = check_dos_char_slowly(c);
    21760        }
    21861}
     
    23679}
    23780
    238 
    239 /*******************************************************************
    240  Skip past a unicode string, but not more than len. Always move
    241  past a terminating zero if found.
    242 ********************************************************************/
    243 
    244 char *skip_unibuf(char *src, size_t len)
    245 {
    246         char *srcend = src + len;
    247 
    248         while (src < srcend && SVAL(src,0)) {
    249                 src += 2;
    250         }
    251 
    252         if(!SVAL(src,0)) {
    253                 src += 2;
    254         }
    255 
    256         return src;
    257 }
    25881
    25982/* Converts a string from internal samba format to unicode
     
    279102
    280103/*******************************************************************
    281  Convert a wchar to upper case.
    282 ********************************************************************/
    283 
    284 smb_ucs2_t toupper_w(smb_ucs2_t val)
    285 {
    286         return upcase_table[SVAL(&val,0)];
    287 }
    288 
    289 /*******************************************************************
    290  Convert a wchar to lower case.
    291 ********************************************************************/
    292 
    293 smb_ucs2_t tolower_w( smb_ucs2_t val )
    294 {
    295         return lowcase_table[SVAL(&val,0)];
    296 }
    297 
    298 /*******************************************************************
    299  Determine if a character is lowercase.
    300 ********************************************************************/
    301 
    302 bool islower_w(smb_ucs2_t c)
    303 {
    304         return upcase_table[SVAL(&c,0)] != c;
    305 }
    306 
    307 /*******************************************************************
    308  Determine if a character is uppercase.
    309 ********************************************************************/
    310 
    311 bool isupper_w(smb_ucs2_t c)
    312 {
    313         return lowcase_table[SVAL(&c,0)] != c;
    314 }
    315 
    316 /*******************************************************************
    317104 Determine if a character is valid in a 8.3 name.
    318105********************************************************************/
     
    320107bool isvalid83_w(smb_ucs2_t c)
    321108{
     109        init_valid_table();
    322110        return valid_table[SVAL(&c,0)] != 0;
    323111}
     
    457245 Convert a string to lower case.
    458246 return True if any char is converted
     247
     248 This is unsafe for any string involving a UTF16 character
    459249********************************************************************/
    460250
     
    478268 Convert a string to upper case.
    479269 return True if any char is converted
     270
     271 This is unsafe for any string involving a UTF16 character
    480272********************************************************************/
    481273
     
    816608}
    817609
    818 /*************************************************************
    819  ascii only toupper - saves the need for smbd to be in C locale.
    820 *************************************************************/
    821 
    822 int toupper_ascii(int c)
    823 {
    824         smb_ucs2_t uc = toupper_w(UCS2_CHAR(c));
    825         return UCS2_TO_CHAR(uc);
    826 }
    827 
    828 /*************************************************************
    829  ascii only tolower - saves the need for smbd to be in C locale.
    830 *************************************************************/
    831 
    832 int tolower_ascii(int c)
    833 {
    834         smb_ucs2_t uc = tolower_w(UCS2_CHAR(c));
    835         return UCS2_TO_CHAR(uc);
    836 }
    837 
    838 /*************************************************************
    839  ascii only isupper - saves the need for smbd to be in C locale.
    840 *************************************************************/
    841 
    842 int isupper_ascii(int c)
    843 {
    844         return isupper_w(UCS2_CHAR(c));
    845 }
    846 
    847 /*************************************************************
    848  ascii only islower - saves the need for smbd to be in C locale.
    849 *************************************************************/
    850 
    851 int islower_ascii(int c)
    852 {
    853         return islower_w(UCS2_CHAR(c));
    854 }
     610smb_ucs2_t toupper_w(smb_ucs2_t v)
     611{
     612        smb_ucs2_t ret;
     613        /* LE to native. */
     614        codepoint_t cp = SVAL(&v,0);
     615        cp = toupper_m(cp);
     616        /* native to LE. */
     617        SSVAL(&ret,0,cp);
     618        return ret;
     619}
     620
     621bool isupper_w(smb_ucs2_t v)
     622{
     623        codepoint_t cp = SVAL(&v,0);
     624        return isupper_m(cp);
     625}
     626
     627smb_ucs2_t tolower_w(smb_ucs2_t v)
     628{
     629        smb_ucs2_t ret;
     630        /* LE to native. */
     631        codepoint_t cp = SVAL(&v,0);
     632        cp = tolower_m(cp);
     633        /* native to LE. */
     634        SSVAL(&ret,0,cp);
     635        return ret;
     636}
     637
     638bool islower_w(smb_ucs2_t v)
     639{
     640        codepoint_t cp = SVAL(&v,0);
     641        return islower_m(cp);
     642}
  • trunk/server/source3/lib/winbind_util.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "../libcli/security/security.h"
     23#include "../lib/util/util_pw.h"
     24#include "nsswitch/libwbclient/wbclient.h"
    2225
    2326#if defined(WITH_WINBIND)
    2427
    25 #include "nsswitch/libwbclient/wbclient.h"
     28#include "lib/winbind_util.h"
    2629
    2730struct passwd * winbind_getpwnam(const char * name)
     
    4245}
    4346
    44 struct passwd * winbind_getpwsid(const DOM_SID *sid)
     47struct passwd * winbind_getpwsid(const struct dom_sid *sid)
    4548{
    4649        wbcErr result;
     
    6467/* Call winbindd to convert a name to a sid */
    6568
    66 bool winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid,
     69bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid *sid,
    6770                         enum lsa_SidType *name_type)
    6871{
     
    7578                return false;
    7679
    77         memcpy(sid, &dom_sid, sizeof(DOM_SID));
     80        memcpy(sid, &dom_sid, sizeof(struct dom_sid));
    7881        *name_type = (enum lsa_SidType)type;   
    7982
     
    8386/* Call winbindd to convert sid to name */
    8487
    85 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
     88bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
    8689                        const char **domain, const char **name,
    8790                        enum lsa_SidType *name_type)
     
    135138/* Call winbindd to convert SID to uid */
    136139
    137 bool winbind_sid_to_uid(uid_t *puid, const DOM_SID *sid)
     140bool winbind_sid_to_uid(uid_t *puid, const struct dom_sid *sid)
    138141{
    139142        struct wbcDomainSid dom_sid;
     
    149152/* Call winbindd to convert uid to sid */
    150153
    151 bool winbind_uid_to_sid(DOM_SID *sid, uid_t uid)
     154bool winbind_uid_to_sid(struct dom_sid *sid, uid_t uid)
    152155{
    153156        struct wbcDomainSid dom_sid;
     
    156159        result = wbcUidToSid(uid, &dom_sid);
    157160        if (result == WBC_ERR_SUCCESS) {
    158                 memcpy(sid, &dom_sid, sizeof(DOM_SID));
     161                memcpy(sid, &dom_sid, sizeof(struct dom_sid));
    159162        } else {
    160163                sid_copy(sid, &global_sid_NULL);
     
    166169/* Call winbindd to convert SID to gid */
    167170
    168 bool winbind_sid_to_gid(gid_t *pgid, const DOM_SID *sid)
     171bool winbind_sid_to_gid(gid_t *pgid, const struct dom_sid *sid)
    169172{
    170173        struct wbcDomainSid dom_sid;
     
    180183/* Call winbindd to convert gid to sid */
    181184
    182 bool winbind_gid_to_sid(DOM_SID *sid, gid_t gid)
     185bool winbind_gid_to_sid(struct dom_sid *sid, gid_t gid)
    183186{
    184187        struct wbcDomainSid dom_sid;
     
    187190        result = wbcGidToSid(gid, &dom_sid);
    188191        if (result == WBC_ERR_SUCCESS) {
    189                 memcpy(sid, &dom_sid, sizeof(DOM_SID));
     192                memcpy(sid, &dom_sid, sizeof(struct dom_sid));
    190193        } else {
    191194                sid_copy(sid, &global_sid_NULL);
     
    214217
    215218bool winbind_lookup_rids(TALLOC_CTX *mem_ctx,
    216                          const DOM_SID *domain_sid,
     219                         const struct dom_sid *domain_sid,
    217220                         int num_rids, uint32 *rids,
    218221                         const char **domain_name,
     
    296299
    297300bool winbind_get_sid_aliases(TALLOC_CTX *mem_ctx,
    298                              const DOM_SID *dom_sid,
    299                              const DOM_SID *members,
     301                             const struct dom_sid *dom_sid,
     302                             const struct dom_sid *members,
    300303                             size_t num_members,
    301304                             uint32_t **pp_alias_rids,
     
    347350}
    348351
    349 struct passwd * winbind_getpwsid(const DOM_SID *sid)
     352struct passwd * winbind_getpwsid(const struct dom_sid *sid)
    350353{
    351354        return NULL;
    352355}
    353356
    354 bool winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid,
     357bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid *sid,
    355358                         enum lsa_SidType *name_type)
    356359{
     
    360363/* Call winbindd to convert sid to name */
    361364
    362 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
     365bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
    363366                        const char **domain, const char **name,
    364367                        enum lsa_SidType *name_type)
     
    376379/* Call winbindd to convert SID to uid */
    377380
    378 bool winbind_sid_to_uid(uid_t *puid, const DOM_SID *sid)
     381bool winbind_sid_to_uid(uid_t *puid, const struct dom_sid *sid)
    379382{
    380383        return false;
     
    383386/* Call winbindd to convert uid to sid */
    384387
    385 bool winbind_uid_to_sid(DOM_SID *sid, uid_t uid)
     388bool winbind_uid_to_sid(struct dom_sid *sid, uid_t uid)
    386389{
    387390        return false;
     
    390393/* Call winbindd to convert SID to gid */
    391394
    392 bool winbind_sid_to_gid(gid_t *pgid, const DOM_SID *sid)
     395bool winbind_sid_to_gid(gid_t *pgid, const struct dom_sid *sid)
    393396{
    394397        return false;   
     
    397400/* Call winbindd to convert gid to sid */
    398401
    399 bool winbind_gid_to_sid(DOM_SID *sid, gid_t gid)
     402bool winbind_gid_to_sid(struct dom_sid *sid, gid_t gid)
    400403{
    401404        return false;
     
    412415
    413416bool winbind_lookup_rids(TALLOC_CTX *mem_ctx,
    414                          const DOM_SID *domain_sid,
     417                         const struct dom_sid *domain_sid,
    415418                         int num_rids, uint32 *rids,
    416419                         const char **domain_name,
     
    440443
    441444bool winbind_get_sid_aliases(TALLOC_CTX *mem_ctx,
    442                              const DOM_SID *dom_sid,
    443                              const DOM_SID *members,
     445                             const struct dom_sid *dom_sid,
     446                             const struct dom_sid *members,
    444447                             size_t num_members,
    445448                             uint32_t **pp_alias_rids,
Note: See TracChangeset for help on using the changeset viewer.