Changeset 745 for trunk/server/source3/lib
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 143 deleted
- 95 edited
- 30 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/lib/access.c
r599 r745 12 12 13 13 #include "includes.h" 14 #include "memcache.h" 15 #include "interfaces.h" 14 16 15 17 #define NAME_INDEX 0 … … 67 69 } 68 70 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); 70 74 } 71 75 … … 330 334 ret = allow_access_internal(deny_list, allow_list, nc_cname, nc_caddr); 331 335 336 DEBUG(ret ? 3 : 0, 337 ("%s connection from %s (%s)\n", 338 ret ? "Allowed" : "Denied", nc_cname, nc_caddr)); 339 332 340 SAFE_FREE(nc_cname); 333 341 SAFE_FREE(nc_caddr); 334 342 return ret; 335 343 } 336 337 /* return true if the char* contains ip addrs only. Used to avoid338 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 because358 * the token was a network/netmask pair. Only359 * 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 lists387 * 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 21 21 #include "adt_tree.h" 22 22 23 struct 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 31 struct sorted_tree { 32 struct tree_node *root; 33 }; 23 34 24 35 /************************************************************************** … … 28 39 { 29 40 char *p; 30 41 31 42 *new_path = *base = NULL; 32 43 33 44 if ( !path ) 34 45 return False; 35 46 36 47 *base = path; 37 38 p = strchr( path, ' /' );39 48 49 p = strchr( path, '\\' ); 50 40 51 if ( p ) { 41 52 *p = '\0'; 42 53 *new_path = p+1; 43 54 } 44 55 45 56 return True; 46 57 } 47 58 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 63 struct 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) { 64 74 TALLOC_FREE( tree ); 65 75 return NULL; 66 76 } 67 77 68 78 tree->root->data_p = data_p; 69 79 70 80 return tree; 71 81 } … … 76 86 *************************************************************************/ 77 87 78 static TREE_NODE* pathtree_birth_child( TREE_NODE *node, char* key ) 79 { 80 TREE_NODE *infant = NULL; 81 TREE_NODE **siblings; 88 static 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; 82 93 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 87 100 infant->key = talloc_strdup( infant, key ); 88 101 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 92 106 if ( siblings ) 93 107 node->children = siblings; 94 108 95 109 node->num_children++; 96 110 97 111 /* first child */ 98 112 99 113 if ( node->num_children == 1 ) { 100 114 DEBUG(11,("pathtree_birth_child: First child of node [%s]! [%s]\n", … … 112 126 * from left to right 113 127 */ 114 128 115 129 for ( i = node->num_children-1; i>=1; i-- ) 116 130 { 117 131 DEBUG(11,("pathtree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n", 118 132 infant->key, node->children[i-1]->key)); 119 133 120 134 /* the strings should never match assuming that we 121 135 have called pathtree_find_child() first */ 122 136 123 137 if ( StrCaseCmp( infant->key, node->children[i-1]->key ) > 0 ) { 124 138 DEBUG(11,("pathtree_birth_child: storing infant in i == [%d]\n", … … 127 141 break; 128 142 } 129 143 130 144 /* bump everything towards the end on slot */ 131 145 132 146 node->children[i] = node->children[i-1]; 133 147 } 134 148 135 149 DEBUG(11,("pathtree_birth_child: Exiting loop (i == [%d])\n", i )); 136 150 137 151 /* if we haven't found the correct slot yet, the child 138 152 will be first in the list */ 139 153 140 154 if ( i == 0 ) 141 155 node->children[0] = infant; … … 149 163 *************************************************************************/ 150 164 151 static TREE_NODE* pathtree_find_child( TREE_NODE *node, char* key ) 152 { 153 TREE_NODE *next = NULL; 165 static struct tree_node *pathtree_find_child(struct tree_node *node, 166 char *key ) 167 { 168 struct tree_node *next = NULL; 154 169 int i, result; 155 170 156 171 if ( !node ) { 157 172 DEBUG(0,("pathtree_find_child: NULL node passed into function!\n")); 158 173 return NULL; 159 174 } 160 175 161 176 if ( !key ) { 162 177 DEBUG(0,("pathtree_find_child: NULL key string passed into function!\n")); 163 178 return NULL; 164 179 } 165 180 166 181 for ( i=0; i<node->num_children; i++ ) 167 182 { 168 183 DEBUG(11,("pathtree_find_child: child key => [%s]\n", 169 184 node->children[i]->key)); 170 185 171 186 result = StrCaseCmp( node->children[i]->key, key ); 172 187 173 188 if ( result == 0 ) 174 189 next = node->children[i]; 175 190 176 191 /* if result > 0 then we've gone to far because 177 192 the list of children is sorted by key name 178 193 If result == 0, then we have a match */ 179 194 180 195 if ( result > 0 ) 181 196 break; … … 184 199 DEBUG(11,("pathtree_find_child: %s [%s]\n", 185 200 next ? "Found" : "Did not find", key )); 186 201 187 202 return next; 188 203 } … … 192 207 *************************************************************************/ 193 208 194 WERROR pathtree_add( SORTED_TREE *tree, const char *path, void *data_p)209 WERROR pathtree_add(struct sorted_tree *tree, const char *path, void *data_p) 195 210 { 196 211 char *str, *base, *path2; 197 TREE_NODE*current, *next;212 struct tree_node *current, *next; 198 213 WERROR ret = WERR_OK; 199 214 200 215 DEBUG(8,("pathtree_add: Enter\n")); 201 202 if ( !path || *path != ' /' ) {216 217 if ( !path || *path != '\\' ) { 203 218 DEBUG(0,("pathtree_add: Attempt to add a node with a bad path [%s]\n", 204 219 path ? path : "NULL" )); 205 220 return WERR_INVALID_PARAM; 206 221 } 207 222 208 223 if ( !tree ) { 209 224 DEBUG(0,("pathtree_add: Attempt to add a node to an uninitialized tree!\n")); 210 225 return WERR_INVALID_PARAM; 211 226 } 212 213 /* move past the first ' /' */214 227 228 /* move past the first '\\' */ 229 215 230 path++; 216 231 path2 = SMB_STRDUP( path ); … … 219 234 return WERR_NOMEM; 220 235 } 221 236 222 237 223 238 /* … … 226 241 * The path should be of the form /<key1>/<key2>/... 227 242 */ 228 243 229 244 base = path2; 230 245 str = path2; 231 246 current = tree->root; 232 247 233 248 do { 234 249 /* break off the remaining part of the path */ 235 236 str = strchr( str, ' /' );250 251 str = strchr( str, '\\' ); 237 252 if ( str ) 238 253 *str = '\0'; 239 254 240 255 /* iterate to the next child--birth it if necessary */ 241 256 242 257 next = pathtree_find_child( current, base ); 243 258 if ( !next ) { … … 250 265 } 251 266 current = next; 252 267 253 268 /* setup the next part of the path */ 254 269 255 270 base = str; 256 271 if ( base ) { 257 *base = ' /';272 *base = '\\'; 258 273 base++; 259 274 str = base; 260 275 } 261 276 262 277 } while ( base != NULL ); 263 278 264 279 current->data_p = data_p; 265 280 266 281 DEBUG(10,("pathtree_add: Successfully added node [%s] to tree\n", 267 282 path )); … … 276 291 277 292 /************************************************************************** 278 Recursive routine to print out all children of a TREE_NODE293 Recursive routine to print out all children of a struct tree_node 279 294 *************************************************************************/ 280 295 281 296 static void pathtree_print_children(TALLOC_CTX *ctx, 282 TREE_NODE*node,297 struct tree_node *node, 283 298 int debug, 284 299 const char *path ) … … 320 335 *************************************************************************/ 321 336 322 void pathtree_print_keys( SORTED_TREE*tree, int debug )337 void pathtree_print_keys(struct sorted_tree *tree, int debug ) 323 338 { 324 339 int i; … … 344 359 *************************************************************************/ 345 360 346 void* pathtree_find( SORTED_TREE*tree, char *key )361 void* pathtree_find(struct sorted_tree *tree, char *key ) 347 362 { 348 363 char *keystr, *base = NULL, *str = NULL, *p; 349 TREE_NODE*current;364 struct tree_node *current; 350 365 void *result = NULL; 351 366 352 367 DEBUG(10,("pathtree_find: Enter [%s]\n", key ? key : "NULL" )); 353 368 354 369 /* sanity checks first */ 355 370 356 371 if ( !key ) { 357 372 DEBUG(0,("pathtree_find: Attempt to search tree using NULL search string!\n")); 358 373 return NULL; 359 374 } 360 375 361 376 if ( !tree ) { 362 377 DEBUG(0,("pathtree_find: Attempt to search an uninitialized tree using string [%s]!\n", … … 364 379 return NULL; 365 380 } 366 381 367 382 if ( !tree->root ) 368 383 return NULL; 369 384 370 385 /* make a copy to play with */ 371 372 if ( *key == ' /' )386 387 if ( *key == '\\' ) 373 388 keystr = SMB_STRDUP( key+1 ); 374 389 else 375 390 keystr = SMB_STRDUP( key ); 376 391 377 392 if ( !keystr ) { 378 393 DEBUG(0,("pathtree_find: strdup() failed on string [%s]!?!?!\n", key)); … … 381 396 382 397 /* start breaking the path apart */ 383 398 384 399 p = keystr; 385 400 current = tree->root; 386 401 387 402 if ( tree->root->data_p ) 388 403 result = tree->root->data_p; 389 404 390 405 do 391 406 { … … 393 408 394 409 trim_tree_keypath( p, &base, &str ); 395 410 396 411 DEBUG(11,("pathtree_find: [loop] base => [%s], new_path => [%s]\n", 397 412 base ? base : "", … … 399 414 400 415 /* iterate to the next child */ 401 416 402 417 current = pathtree_find_child( current, base ); 403 418 404 419 /* 405 420 * the idea is that the data_p for a parent should … … 407 422 * overridden farther down 408 423 */ 409 424 410 425 if ( current && current->data_p ) 411 426 result = current->data_p; … … 414 429 415 430 p = str; 416 431 417 432 } while ( str && current ); 418 433 419 434 /* result should be the data_p from the lowest match node in the tree */ 420 435 if ( result ) 421 436 DEBUG(11,("pathtree_find: Found data_p!\n")); 422 437 423 438 SAFE_FREE( keystr ); 424 439 425 440 DEBUG(10,("pathtree_find: Exit\n")); 426 441 427 442 return result; 428 443 } -
trunk/server/source3/lib/afs.c
r414 r745 24 24 #define NO_ASN1_TYPEDEFS 1 25 25 26 #include "secrets.h" 27 #include "passdb.h" 28 #include "auth.h" 29 #include "../librpc/gen_ndr/ndr_netlogon.h" 30 26 31 #include <afs/param.h> 27 32 #include <afs/stds.h> … … 220 225 bool result; 221 226 char *ticket_str = NULL; 222 const DOM_SID*user_sid;227 const struct dom_sid *user_sid; 223 228 TALLOC_CTX *ctx = talloc_tos(); 224 229 … … 232 237 233 238 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, 238 244 afs_username); 239 245 if (!afs_username) { … … 241 247 } 242 248 243 user_sid = &conn->se rver_info->ptok->user_sids[0];249 user_sid = &conn->session_info->security_token->sids[0]; 244 250 afs_username = talloc_string_sub(talloc_tos(), 245 251 afs_username, -
trunk/server/source3/lib/afs_settoken.c
r414 r745 24 24 #define NO_ASN1_TYPEDEFS 1 25 25 26 #include "system/filesys.h" 27 26 28 #include <afs/param.h> 27 29 #include <afs/stds.h> … … 237 239 return False; 238 240 239 if (geteuid() != 0)241 if (geteuid() != sec_initial_uid()) 240 242 ct.ViceId = getuid(); 241 243 -
trunk/server/source3/lib/audit.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "../librpc/gen_ndr/lsa.h" 21 22 22 23 static const struct audit_category_tab { -
trunk/server/source3/lib/bitmap.c
r414 r745 24 24 25 25 /**************************************************************************** 26 allocate a bitmap of the specified size27 ****************************************************************************/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 /****************************************************************************62 26 talloc a bitmap 63 27 ****************************************************************************/ … … 66 30 struct bitmap *bm; 67 31 68 if (!mem_ctx) return NULL;69 70 32 bm = TALLOC_P(mem_ctx, struct bitmap); 71 33 … … 73 35 74 36 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); 76 38 if (!bm->b) { 39 TALLOC_FREE(bm); 77 40 return NULL; 78 41 } 79 80 memset(bm->b, 0, sizeof(uint32)*((n+31)/32));81 82 42 return bm; 83 43 } -
trunk/server/source3/lib/charcnv.c
r599 r745 46 46 47 47 48 static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];49 48 static bool conv_silent; /* Should we do a debug if the conversion fails ? */ 50 49 static bool initialized; 51 50 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_SETLOCALE87 setlocale(LC_ALL, "");88 #endif89 ln = nl_langinfo(CODESET);90 if (ln) {91 /* Check whether the charset name is supported92 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 #endif105 106 if (!ret || !*ret) ret = "ASCII";107 return ret;108 }109 110 51 void lazy_initialize_conv(void) 111 52 { 112 53 if (!initialized) { 113 load_case_tables ();54 load_case_tables_library(); 114 55 init_iconv(); 115 56 initialized = true; … … 122 63 void gfree_charcnv(void) 123 64 { 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); 134 66 initialized = false; 135 67 } … … 144 76 void init_iconv(void) 145 77 { 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); 200 81 } 201 82 … … 224 105 char* outbuf = (char*)dest; 225 106 smb_iconv_t descriptor; 107 struct smb_iconv_convenience *ic; 226 108 227 109 lazy_initialize_conv(); 228 229 descriptor = conv_handles[from][to];110 ic = get_iconv_convenience(); 111 descriptor = get_conv_handle(ic, from, to); 230 112 231 113 if (srclen == (size_t)-1) { … … 265 147 if (from == CH_UNIX) { 266 148 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), 268 150 (unsigned int)srclen, (unsigned int)destlen, (const char *)src)); 269 151 } else { 270 152 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), 272 154 (unsigned int)srclen, (unsigned int)destlen)); 273 155 } … … 562 444 smb_iconv_t descriptor; 563 445 void **dest = (void **)dst; 446 struct smb_iconv_convenience *ic; 564 447 565 448 *dest = NULL; … … 596 479 597 480 lazy_initialize_conv(); 598 599 descriptor = conv_handles[from][to];481 ic = get_iconv_convenience(); 482 descriptor = get_conv_handle(ic, from, to); 600 483 601 484 if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { … … 1818 1701 } 1819 1702 1820 /*1821 Return the unicode codepoint for the next multi-byte CH_UNIX character1822 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 caller1825 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 take1845 more than 5 bytes. This is OK as we only1846 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 cope1860 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 must1904 be able to hold the full character, which is guaranteed if it is at1905 least 5 bytes in size. The caller may pass less than 5 bytes if they1906 are sure the character will fit (for example, you can assume that1907 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, or1910 -1 on failure1911 */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 19 19 20 20 #include "includes.h" 21 #include "system/filesys.h" 22 #include "smbd/globals.h" 23 #include "dbwrap.h" 21 24 22 25 static struct db_context *connections_db_ctx(bool rw) 23 26 { 24 27 static struct db_context *db_ctx; 28 int open_flags; 25 29 26 30 if (db_ctx != NULL) { … … 28 32 } 29 33 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; 39 35 36 db_ctx = db_open(NULL, lock_path("connections.tdb"), 0, 37 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, open_flags, 0644); 40 38 return db_ctx; 41 39 } 42 40 43 st ruct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx,44 41 static struct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx, 42 TDB_DATA key) 45 43 { 46 44 struct db_context *ctx = connections_db_ctx(True); … … 61 59 62 60 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; 65 63 strlcpy(ckey.name, name, sizeof(ckey.name)); 66 64 … … 113 111 void *private_data) 114 112 { 113 struct db_context *ctx; 115 114 struct conn_traverse_state state; 115 116 ctx = connections_db_ctx(true); 117 if (ctx == NULL) { 118 return -1; 119 } 116 120 117 121 state.fn = fn; 118 122 state.private_data = private_data; 119 123 120 return connections_traverse(conn_traverse_fn, (void *)&state); 124 return ctx->traverse(ctx, conn_traverse_fn, (void *)&state); 125 } 126 127 struct 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 134 static 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 149 int 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); 121 167 } 122 168 -
trunk/server/source3/lib/ctdbd_conn.c
r429 r745 20 20 21 21 #include "includes.h" 22 #include "util_tdb.h" 22 23 23 24 #ifdef CLUSTER_SUPPORT 24 25 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" 27 29 28 30 /* paths to these include files come from --with-ctdb= in configure */ … … 58 60 so that someone else can take over without getting sharing 59 61 violations */ 60 _exit( 0);62 _exit(1); 61 63 } 62 64 … … 105 107 } 106 108 109 /* 110 * Are we active (i.e. not banned or stopped?) 111 */ 112 static 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; 157 fail: 158 TALLOC_FREE(outdata.dptr); 159 return ret; 160 } 161 107 162 uint32 ctdbd_vnn(const struct ctdbd_connection *conn) 108 163 { … … 136 191 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)); 137 192 138 if (sys_connect(fd, (struct sockaddr *) &addr) == -1) {193 if (sys_connect(fd, (struct sockaddr *)(void *)&addr) == -1) { 139 194 DEBUG(1, ("connect(%s) failed: %s\n", sockname, 140 195 strerror(errno))); … … 258 313 259 314 ndr_err = ndr_pull_struct_blob( 260 &blob, result, NULL,result,315 &blob, result, result, 261 316 (ndr_pull_flags_fn_t)ndr_pull_messaging_rec); 262 317 … … 278 333 static NTSTATUS ctdb_packet_fd_read_sync(struct packet_context *ctx) 279 334 { 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); 287 341 } 288 342 … … 369 423 ? "cluster reconfigure" : "SAMBA_NOTIFY")); 370 424 371 messaging_send(conn->msg_ctx, procid_self(), 425 messaging_send(conn->msg_ctx, 426 messaging_server_id(conn->msg_ctx), 372 427 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), 374 430 MSG_DBWRAP_G_LOCK_RETRY, 375 431 &data_blob_null); … … 378 434 } 379 435 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) { 381 438 DEBUG(0, ("talloc failed\n")); 382 439 TALLOC_FREE(hdr); … … 432 489 */ 433 490 434 NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,435 491 static NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx, 492 struct ctdbd_connection **pconn) 436 493 { 437 494 struct ctdbd_connection *conn; … … 454 511 if (!NT_STATUS_IS_OK(status)) { 455 512 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; 456 519 goto fail; 457 520 } … … 565 628 * clean the brl database 566 629 */ 567 messaging_send(conn->msg_ctx, procid_self(), 630 messaging_send(conn->msg_ctx, 631 messaging_server_id(conn->msg_ctx), 568 632 MSG_SMB_BRL_VALIDATE, &data_blob_null); 569 633 570 messaging_send(conn->msg_ctx, procid_self(), 634 messaging_send(conn->msg_ctx, 635 messaging_server_id(conn->msg_ctx), 571 636 MSG_DBWRAP_G_LOCK_RETRY, 572 637 &data_blob_null); … … 671 736 672 737 ndr_err = ndr_push_struct_blob( 673 &blob, mem_ctx, NULL,msg,738 &blob, mem_ctx, msg, 674 739 (ndr_push_flags_fn_t)ndr_push_messaging_rec); 675 740 … … 758 823 req.srvid = srvid; 759 824 req.datalen = data.dsize; 825 req.flags = flags; 760 826 761 827 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n")); … … 781 847 if (flags & CTDB_CTRL_FLAG_NOREPLY) { 782 848 TALLOC_FREE(new_conn); 849 if (cstatus) { 850 *cstatus = 0; 851 } 783 852 return NT_STATUS_OK; 784 853 } … … 881 950 ? CTDB_CONTROL_DB_ATTACH_PERSISTENT 882 951 : CTDB_CONTROL_DB_ATTACH, 883 0, 0, data, NULL, &data, &cstatus);952 tdb_flags, 0, data, NULL, &data, &cstatus); 884 953 if (!NT_STATUS_IS_OK(status)) { 885 954 DEBUG(0, (__location__ " ctdb_control for db_attach " … … 1275 1344 switch (client.ss_family) { 1276 1345 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; 1279 1348 data.dptr = (uint8_t *)&p4; 1280 1349 data.dsize = sizeof(p4); … … 1282 1351 #ifdef HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR 1283 1352 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; 1286 1355 data.dptr = (uint8_t *)&p; 1287 1356 data.dsize = sizeof(p); … … 1293 1362 1294 1363 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; 1295 1369 1296 1370 /* … … 1376 1450 } 1377 1451 1378 #else1379 1380 NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,1381 struct ctdbd_connection **pconn)1382 {1383 return NT_STATUS_NOT_IMPLEMENTED;1384 }1385 1386 1452 #endif -
trunk/server/source3/lib/dbwrap.c
r414 r745 21 21 22 22 #include "includes.h" 23 #include "dbwrap.h" 24 #include "util_tdb.h" 23 25 #ifdef CLUSTER_SUPPORT 24 26 #include "ctdb_private.h" … … 104 106 #ifdef CLUSTER_SUPPORT 105 107 const char *sockname = lp_ctdbd_socket(); 106 #endif 107 108 #ifdef CLUSTER_SUPPORT 108 109 109 if(!sockname || !*sockname) { 110 110 sockname = CTDB_PATH; -
trunk/server/source3/lib/dbwrap_ctdb.c
r429 r745 20 20 21 21 #include "includes.h" 22 #include "system/filesys.h" 23 #include "lib/util/tdb_wrap.h" 24 #include "util_tdb.h" 22 25 #ifdef CLUSTER_SUPPORT 23 26 #include "ctdb.h" … … 25 28 #include "ctdbd_conn.h" 26 29 #include "g_lock.h" 30 #include "messages.h" 27 31 28 32 struct db_ctdb_transaction_handle { … … 51 55 struct db_ctdb_ctx *ctdb_ctx; 52 56 struct ctdb_ltdb_header header; 57 struct timeval lock_time; 53 58 }; 54 59 … … 474 479 } 475 480 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 */ 492 static 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 } 476 508 477 509 static NTSTATUS db_ctdb_store_transaction(struct db_record *rec, TDB_DATA data, int flag); … … 880 912 881 913 914 #ifdef HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL 915 static 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 882 960 static NTSTATUS db_ctdb_delete(struct db_record *rec) 883 961 { 884 962 TDB_DATA data; 963 NTSTATUS status; 885 964 886 965 /* … … 891 970 ZERO_STRUCT(data); 892 971 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; 895 982 } 896 983 … … 899 986 struct db_ctdb_rec *crec = talloc_get_type_abort( 900 987 data->private_data, struct db_ctdb_rec); 988 int threshold; 901 989 902 990 DEBUG(10, (DEBUGLEVEL > 10 … … 910 998 DEBUG(0, ("tdb_chainunlock failed\n")); 911 999 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 } 912 1008 } 913 1009 … … 996 1092 get_my_vnn())); 997 1093 998 status = ctdbd_migrate(messaging_ctdbd_connection(),ctx->db_id, key); 1094 status = ctdbd_migrate(messaging_ctdbd_connection(), ctx->db_id, 1095 key); 999 1096 if (!NT_STATUS_IS_OK(status)) { 1000 1097 DEBUG(5, ("ctdb_migrate failed: %s\n", … … 1011 1108 migrate_attempts)); 1012 1109 } 1110 1111 GetTimeOfDay(&crec->lock_time); 1013 1112 1014 1113 memcpy(&crec->header, ctdb_data.dptr, sizeof(crec->header)); … … 1061 1160 if (ctx->transaction) { 1062 1161 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); 1063 1166 } 1064 1167 … … 1073 1176 if ((ctdb_data.dptr != NULL) && 1074 1177 (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 { 1077 1180 /* we are the dmaster - avoid the ctdb protocol op */ 1078 1181 … … 1099 1202 1100 1203 /* 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); 1102 1206 if (!NT_STATUS_IS_OK(status)) { 1103 1207 DEBUG(5, ("ctdbd_fetch failed: %s\n", nt_errstr(status))); … … 1278 1382 1279 1383 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 } 1280 1389 1281 1390 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 19 19 20 20 #include "includes.h" 21 #include "dbwrap.h" 21 22 #include "../lib/util/rbtree.h" 22 23 -
trunk/server/source3/lib/dbwrap_tdb.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "dbwrap.h" 22 #include "lib/util/tdb_wrap.h" 21 23 22 24 struct db_tdb_ctx { -
trunk/server/source3/lib/dbwrap_util.c
r414 r745 21 21 22 22 #include "includes.h" 23 #include "dbwrap.h" 24 #include "util_tdb.h" 23 25 24 26 int32_t dbwrap_fetch_int32(struct db_context *db, const char *keystr) … … 118 120 { 119 121 struct db_record *rec; 120 uint32 val =-1;122 uint32_t val = (uint32_t)-1; 121 123 uint32_t v_store; 122 124 NTSTATUS ret; … … 416 418 } 417 419 420 struct dbwrap_trans_traverse_action_ctx { 421 int (*f)(struct db_record* rec, void* private_data); 422 void* private_data; 423 }; 424 425 426 static 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 436 NTSTATUS 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 447 NTSTATUS 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 418 458 NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key) 419 459 { -
trunk/server/source3/lib/dmallocmsg.c
r414 r745 18 18 19 19 #include "includes.h" 20 #include "messages.h" 20 21 21 22 /** -
trunk/server/source3/lib/dprintf.c
r414 r745 30 30 31 31 #include "includes.h" 32 #include "intl/lang_tdb.h" 32 33 33 34 int d_vfprintf(FILE *f, const char *format, va_list ap) -
trunk/server/source3/lib/dummysmbd.c
r414 r745 24 24 #include "includes.h" 25 25 26 int get_client_fd(void) 27 { 28 return -1; 29 } 30 31 int find_service(fstring service) 26 int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out) 32 27 { 33 28 return -1; … … 39 34 } 40 35 41 void cancel_pending_lock_requests_by_fid(files_struct *fsp, struct byte_range_lock *br_lck) 36 void cancel_pending_lock_requests_by_fid(files_struct *fsp, 37 struct byte_range_lock *br_lck, 38 enum file_close_type close_type) 42 39 { 43 40 } 44 41 45 void send_stat_cache_delete_message(const char *name) 42 void send_stat_cache_delete_message(struct messaging_context *msg_ctx, 43 const char *name) 46 44 { 47 45 } … … 59 57 60 58 struct event_context *smbd_event_context(void) 61 {62 return NULL;63 }64 65 struct messaging_context *smbd_messaging_context(void)66 59 { 67 60 return NULL; -
trunk/server/source3/lib/errmap_unix.c
r414 r745 106 106 { ECANCELED, ERRDOS, ERRbadfid, NT_STATUS_CANCELLED}, 107 107 #endif 108 108 #ifdef ENOTSUP 109 { ENOTSUP, ERRSRV, ERRnosupport, NT_STATUS_NOT_SUPPORTED}, 110 #endif 109 111 { 0, 0, 0, NT_STATUS_OK } 110 112 }; … … 138 140 /* Default return */ 139 141 return NT_STATUS_ACCESS_DENIED; 142 } 143 144 /* Convert a Unix error code to a WERROR. */ 145 WERROR unix_to_werror(int unix_error) 146 { 147 return ntstatus_to_werror(map_nt_error_from_unix(unix_error)); 140 148 } 141 149 -
trunk/server/source3/lib/eventlog/eventlog.c
r414 r745 22 22 23 23 #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" 24 28 25 29 /* maintain a list of open eventlog tdbs with reference counts */ … … 66 70 char *elog_tdbname(TALLOC_CTX *ctx, const char *name ) 67 71 { 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")); 71 77 if (!path) { 72 78 return NULL; 73 79 } 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; 76 94 } 77 95 … … 677 695 blob = data_blob_const(data.dptr, data.dsize); 678 696 679 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL,r,697 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, r, 680 698 (ndr_pull_flags_fn_t)ndr_pull_eventlog_Record_tdb); 681 699 … … 727 745 } 728 746 729 r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, NULL,0);747 r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, 0); 730 748 731 749 return r; … … 771 789 r->record_number = tdb_fetch_int32(tdb, EVT_NEXT_RECORD); 772 790 773 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL,r,791 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, r, 774 792 (ndr_push_flags_fn_t)ndr_push_eventlog_Record_tdb); 775 793 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { … … 941 959 } 942 960 if (len > 0) { 943 e->UserSid = *string_sid_talloc(mem_ctx, sid_str);961 string_to_sid(&e->UserSid, sid_str); 944 962 } 945 963 } … … 993 1011 } 994 1012 995 endoffset += ndr_size_EVENTLOGRECORD(&e, NULL,0);1013 endoffset += ndr_size_EVENTLOGRECORD(&e, 0); 996 1014 997 1015 ADD_TO_ARRAY(mem_ctx, struct EVENTLOGRECORD, e, &evt.records, &num_records); … … 1020 1038 } 1021 1039 1022 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL,&evt,1040 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &evt, 1023 1041 (ndr_push_flags_fn_t)ndr_push_EVENTLOG_EVT_FILE); 1024 1042 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { -
trunk/server/source3/lib/events.c
r596 r745 20 20 21 21 #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 26 struct 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 38 static 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 54 static void count_fds(struct tevent_context *ev, 55 int *pnum_fds, int *pmax_fd) 52 56 { 53 57 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 73 bool 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 } 56 130 57 131 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) { 63 135 continue; 64 136 } 65 137 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 66 154 if (fde->flags & EVENT_FD_READ) { 67 FD_SET(fde->fd, read_fds); 68 ret = true; 155 pfd->events |= (POLLIN|POLLHUP); 69 156 } 70 157 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; 80 163 81 164 if (ev->immediate_events != NULL) { 82 *timeout = timeval_zero(); 83 return true; 84 } 85 165 *ptimeout = 0; 166 return true; 167 } 86 168 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 } 92 180 93 181 return true; 94 182 } 95 183 96 bool run_events(struct tevent_context *ev, 97 int selrtn, fd_set *read_fds, fd_set *write_fds) 98 { 184 bool 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; 99 189 struct tevent_fd *fde; 100 190 struct timeval now; … … 140 230 } 141 231 142 if ( selrtn <= 0) {232 if (pollrtn <= 0) { 143 233 /* 144 234 * No fd ready … … 147 237 } 148 238 239 state = (struct tevent_poll_private *)ev->additional_data; 240 pollfd_idx = state->pollfd_idx; 241 149 242 for (fde = ev->fd_events; fde; fde = fde->next) { 243 struct pollfd *pfd; 150 244 uint16 flags = 0; 151 245 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 } 155 284 if (flags & fde->flags) { 156 DLIST_DEMOTE(ev->fd_events, fde, struct tevent_fd *);285 DLIST_DEMOTE(ev->fd_events, fde, struct tevent_fd); 157 286 fde->handler(ev, fde, flags, fde->private_data); 158 287 return true; … … 162 291 return false; 163 292 } 164 165 293 166 294 struct timeval *get_timed_events_timeout(struct tevent_context *ev, … … 188 316 static int s3_event_loop_once(struct tevent_context *ev, const char *location) 189 317 { 190 struct t imeval 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; 193 321 int ret; 194 322 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)) { 202 332 return 0; 203 333 } 204 334 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)) { 208 338 return -1; 209 339 } 210 340 211 ret = sys_select(maxfd+1, &r_fds, &w_fds, NULL, &to); 212 341 ret = sys_poll(state->pfds, num_pfds, timeout); 213 342 if (ret == -1 && errno != EINTR) { 214 343 tevent_debug(ev, TEVENT_DEBUG_FATAL, 215 " sys_select() failed: %d:%s\n",344 "poll() failed: %d:%s\n", 216 345 errno, strerror(errno)); 217 346 return -1; 218 347 } 219 348 220 run_events (ev, ret, &r_fds, &w_fds);349 run_events_poll(ev, ret, state->pfds, num_pfds); 221 350 return 0; 222 }223 224 void event_context_reinit(struct tevent_context *ev)225 {226 tevent_common_context_destructor(ev);227 return;228 351 } 229 352 -
trunk/server/source3/lib/fault.c
r454 r745 20 20 21 21 #include "includes.h" 22 #include "system/filesys.h" 22 23 23 24 #ifdef HAVE_SYS_SYSCTL_H … … 56 57 #ifndef __OS2__ /* don't use the built in signal capture stuff - prefer native handling of errors */ 57 58 #ifdef SIGSEGV 58 CatchSignal(SIGSEGV, SIGNAL_CASTSIG_DFL);59 CatchSignal(SIGSEGV, SIG_DFL); 59 60 #endif 60 61 #ifdef SIGBUS 61 CatchSignal(SIGBUS, SIGNAL_CASTSIG_DFL);62 CatchSignal(SIGBUS, SIG_DFL); 62 63 #endif 63 64 #ifdef SIGABRT 64 CatchSignal(SIGABRT, SIGNAL_CASTSIG_DFL);65 CatchSignal(SIGABRT, SIG_DFL); 65 66 #endif 66 67 #endif … … 87 88 #ifndef __OS2__ /* don't use the built in signal capture stuff - prefer native handling of errors */ 88 89 #ifdef SIGSEGV 89 CatchSignal(SIGSEGV, SIGNAL_CASTsig_fault);90 CatchSignal(SIGSEGV, sig_fault); 90 91 #endif 91 92 #ifdef SIGBUS 92 CatchSignal(SIGBUS, SIGNAL_CASTsig_fault);93 CatchSignal(SIGBUS, sig_fault); 93 94 #endif 94 95 #ifdef SIGABRT 95 CatchSignal(SIGABRT, SIGNAL_CASTsig_fault);96 CatchSignal(SIGABRT, sig_fault); 96 97 #endif 97 98 #endif … … 197 198 #endif 198 199 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 */ 208 static 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 199 246 /** 200 247 * Try getting system-specific corepath if one exists. … … 205 252 { 206 253 #if (defined(FREEBSD) && defined(HAVE_SYSCTLBYNAME)) 207 208 /* @todo: Add support for the linux corepath. */209 210 254 char *tmp_corepath = NULL; 211 255 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(); 212 266 213 267 /* If this has been set correctly, we're done. */ … … 271 325 #endif 272 326 273 #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)274 /* On Linux we lose the ability to dump core when we change our user275 * ID. We know how to dump core safely, so let's make sure we have our276 * dumpable flag set.277 */278 prctl(PR_SET_DUMPABLE, 1);279 #endif280 281 327 /* FIXME: if we have a core-plus-pid facility, configurably set 282 328 * this up here. … … 309 355 * file to the corepath. There must not be an unbecome_root() before 310 356 * we call abort(). */ 311 if (geteuid() != 0) {357 if (geteuid() != sec_initial_uid()) { 312 358 become_root(); 313 359 } … … 334 380 dbgflush(); 335 381 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 336 390 /* Ensure we don't have a signal handler for abort. */ 337 391 #ifdef SIGABRT 338 CatchSignal(SIGABRT, SIGNAL_CASTSIG_DFL);392 CatchSignal(SIGABRT, SIG_DFL); 339 393 #endif 340 394 -
trunk/server/source3/lib/fncall.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "../lib/util/tevent_unix.h" 21 22 22 23 #if WITH_PTHREADPOOL 23 24 24 #include " pthreadpool.h"25 #include "lib/pthreadpool/pthreadpool.h" 25 26 26 27 struct fncall_state { … … 87 88 talloc_set_destructor(ctx, fncall_context_destructor); 88 89 89 ctx->sig_fd = pthreadpool_sig _fd(ctx->pool);90 ctx->sig_fd = pthreadpool_signal_fd(ctx->pool); 90 91 if (ctx->sig_fd == -1) { 91 92 TALLOC_FREE(ctx); -
trunk/server/source3/lib/g_lock.c
r593 r745 19 19 20 20 #include "includes.h" 21 #include "system/filesys.h" 21 22 #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" 22 28 23 29 static NTSTATUS g_lock_force_unlock(struct g_lock_ctx *ctx, const char *name, … … 52 58 53 59 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); 55 61 if (result->db == NULL) { 56 62 DEBUG(1, ("g_lock_init: Could not open g_lock.tdb")); … … 206 212 } 207 213 208 self = procid_self();214 self = messaging_server_id(ctx->msg); 209 215 our_index = -1; 210 216 … … 333 339 334 340 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; 340 344 int ret; 341 345 struct timeval timeout_remaining, select_timeout; … … 385 389 */ 386 390 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 387 403 #ifdef CLUSTER_SUPPORT 388 404 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; 397 412 } 398 413 #endif … … 405 420 &timeout_remaining); 406 421 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 409 433 if (ret == -1) { 410 434 if (errno != EINTR) { … … 590 614 NTSTATUS status; 591 615 592 status = g_lock_force_unlock(ctx, name, procid_self());616 status = g_lock_force_unlock(ctx, name, messaging_server_id(ctx->msg)); 593 617 594 618 #ifdef CLUSTER_SUPPORT … … 707 731 struct tevent_context **pev, 708 732 struct messaging_context **pmsg, 733 const struct server_id self, 709 734 struct g_lock_ctx **pg_ctx) 710 735 { … … 718 743 goto fail; 719 744 } 720 msg = messaging_init(mem_ctx, procid_self(), ev);745 msg = messaging_init(mem_ctx, self, ev); 721 746 if (msg == NULL) { 722 747 d_fprintf(stderr, "ERROR: could not init messaging context\n"); … … 741 766 742 767 NTSTATUS 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, 744 769 void (*fn)(void *private_data), void *private_data) 745 770 { … … 749 774 NTSTATUS status; 750 775 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)) { 752 777 status = NT_STATUS_ACCESS_DENIED; 753 778 goto done; -
trunk/server/source3/lib/gencache.c
r414 r745 23 23 24 24 #include "includes.h" 25 #include "system/filesys.h" 26 #include "system/glob.h" 27 #include "util_tdb.h" 25 28 26 29 #undef DBGC_CLASS … … 66 69 67 70 again: 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); 69 72 if (cache) { 70 73 int ret; … … 81 84 DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after CLEAR_IF_FIRST\n", 82 85 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); 84 87 if (cache) { 85 88 tdb_close(cache); … … 92 95 if (!cache && (errno == EACCES)) { 93 96 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, 95 98 0644); 96 99 if (cache) { … … 108 111 DEBUG(5, ("Opening cache file at %s\n", cache_fname)); 109 112 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, 111 114 open_flags, 0644); 112 115 if (cache_notrans == NULL) { … … 275 278 char *endptr; 276 279 280 if (val == NULL) { 281 return false; 282 } 283 277 284 res = strtol(val, &endptr, 10); 278 285 … … 288 295 } 289 296 return true; 297 } 298 299 struct gencache_parse_state { 300 void (*parser)(time_t timeout, DATA_BLOB blob, void *private_data); 301 void *private_data; 302 }; 303 304 static 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 326 bool 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 358 struct gencache_get_data_blob_state { 359 DATA_BLOB *blob; 360 time_t timeout; 361 bool result; 362 }; 363 364 static 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; 290 387 } 291 388 … … 305 402 time_t *timeout, bool *was_expired) 306 403 { 307 TDB_DATA databuf; 308 time_t t; 309 char *endptr; 404 struct gencache_get_data_blob_state state; 310 405 bool expired = false; 311 406 312 if (keystr == NULL) { 407 state.result = false; 408 state.blob = blob; 409 410 if (!gencache_parse(keystr, gencache_get_data_blob_parser, &state)) { 313 411 goto fail; 314 412 } 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) { 319 414 goto fail; 320 415 } 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)) { 355 417 /* 356 418 * We're expired, delete the entry. We can't use gencache_del … … 360 422 */ 361 423 gencache_set(keystr, "", 0); 362 363 SAFE_FREE(databuf.dptr);364 365 424 expired = true; 366 425 goto fail; 367 426 } 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 382 427 if (timeout) { 383 *timeout = t;428 *timeout = state.timeout; 384 429 } 385 430 … … 389 434 if (was_expired != NULL) { 390 435 *was_expired = expired; 436 } 437 if (state.result && state.blob) { 438 data_blob_free(state.blob); 391 439 } 392 440 return false; … … 417 465 } 418 466 419 res = tdb_transaction_start (cache);467 res = tdb_transaction_start_nonblock(cache); 420 468 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 421 478 DEBUG(10, ("Could not start transaction on gencache.tdb: " 422 479 "%s\n", tdb_errorstr(cache))); … … 585 642 } 586 643 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); 644 struct gencache_iterate_blobs_state { 645 void (*fn)(const char *key, DATA_BLOB value, 646 time_t timeout, void *private_data); 601 647 const char *pattern; 602 void *priv ;648 void *private_data; 603 649 bool in_persistent; 604 650 }; 605 651 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;652 static 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; 611 657 char *keystr; 612 658 char *free_key = NULL; 613 char *valstr;614 char *free_val = NULL;615 unsigned long u;616 659 time_t timeout; 617 char * timeout_endp;660 char *endptr; 618 661 619 662 if (tdb_data_cmp(key, last_stabilize_key()) == 0) { 620 663 return 0; 621 664 } 622 623 665 if (state->in_persistent && tdb_exists(cache_notrans, key)) { 624 666 return 0; … … 633 675 } 634 676 635 if ( (value.dptr == NULL) || (value.dsize <= TIMEOUT_LEN)) {677 if (!gencache_pull_timeout((char *)data.dptr, &timeout, &endptr)) { 636 678 goto done; 637 679 } 680 endptr += 1; 638 681 639 682 if (fnmatch(state->pattern, keystr, 0) != 0) { … … 641 684 } 642 685 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 699 void 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 733 struct gencache_iterate_state { 734 void (*fn)(const char *key, const char *value, time_t timeout, 735 void *priv); 736 void *private_data; 737 }; 738 739 static 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; 645 749 } else { 646 750 /* ensure 0-termination */ 647 valstr = SMB_STRNDUP((char *)value.d ptr, value.dsize);751 valstr = SMB_STRNDUP((char *)value.data, value.length); 648 752 free_val = valstr; 649 753 } 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;659 754 660 755 DEBUG(10, ("Calling function with arguments " 661 756 "(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 667 761 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 764 void gencache_iterate(void (*fn)(const char *key, const char *value, 765 time_t timeout, void *dptr), 766 void *private_data, const char *pattern) 673 767 { 674 768 struct gencache_iterate_state state; 675 769 676 if ( (fn == NULL) || (keystr_pattern == NULL)) {770 if (fn == NULL) { 677 771 return; 678 772 } 679 680 if (!gencache_init()) return;681 682 DEBUG(5, ("Searching cache keys with pattern %s\n", keystr_pattern));683 684 773 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 19 19 20 20 #include "includes.h" 21 #include "idmap_cache.h" 22 #include "../libcli/security/security.h" 21 23 22 24 /** … … 259 261 } 260 262 } 263 264 static 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 268 static 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 274 static 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 286 static 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 318 done: 319 talloc_free(mem_ctx); 320 return ret; 321 } 322 323 bool idmap_cache_del_uid(uid_t uid) { 324 return idmap_cache_del_xid('U', uid); 325 } 326 327 bool idmap_cache_del_gid(gid_t gid) { 328 return idmap_cache_del_xid('G', gid); 329 } 330 331 static 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 } 359 done: 360 return ret; 361 } 362 363 bool 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 20 20 21 21 #include "includes.h" 22 #include "interfaces.h" 22 23 23 24 static struct iface_struct *probed_ifaces; -
trunk/server/source3/lib/interfaces.c
r414 r745 20 20 21 21 #include "includes.h" 22 #include "interfaces.h" 22 23 23 24 /**************************************************************************** … … 280 281 281 282 /* now we need to remove duplicates */ 282 qsort(ifaces, total, sizeof(ifaces[0]), QSORT_CASTiface_comp);283 TYPESAFE_QSORT(ifaces, total, iface_comp); 283 284 284 285 for (i=1;i<total;) { -
trunk/server/source3/lib/ldap_debug_handler.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "smb_ldap.h" 21 22 22 23 #if defined(HAVE_LDAP) && defined(HAVE_LBER_LOG_PRINT_FN) -
trunk/server/source3/lib/memcache.c
r414 r745 32 32 33 33 struct memcache { 34 struct memcache_element *mru , *lru;34 struct memcache_element *mru; 35 35 struct rb_root tree; 36 36 size_t size; … … 162 162 163 163 if (cache->size != 0) { 164 /*165 * Do LRU promotion only when we will ever shrink166 */167 if (e == cache->lru) {168 cache->lru = e->prev;169 }170 164 DLIST_PROMOTE(cache->mru, e); 171 if (cache->mru == NULL) {172 cache->mru = e;173 }174 165 } 175 166 … … 202 193 rb_erase(&e->rb_node, &cache->tree); 203 194 204 if (e == cache->lru) {205 cache->lru = e->prev;206 }207 195 DLIST_REMOVE(cache->mru, e); 208 196 … … 228 216 } 229 217 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)); 232 220 } 233 221 } … … 332 320 333 321 DLIST_ADD(cache->mru, e); 334 if (cache->lru == NULL) {335 cache->lru = e;336 }337 322 338 323 cache->size += element_size; … … 401 386 } 402 387 403 if (node == NULL) {404 return;405 }406 407 388 /* 408 389 * Then, find the leftmost element with number n -
trunk/server/source3/lib/messages.c
r414 r745 47 47 48 48 #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" 51 52 52 53 struct messaging_callback { … … 96 97 ****************************************************************************/ 97 98 98 static int traverse_fn(struct db_record *rec, 99 const struct connections_key *ckey, 100 const struct connections_data *crec, 101 void *state) 99 static int traverse_fn(struct db_record *rec, const struct server_id *id, 100 uint32_t msg_flags, void *state) 102 101 { 103 102 struct msg_all *msg_all = (struct msg_all *)state; 104 103 NTSTATUS status; 105 104 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) { 107 108 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 } 113 110 114 111 /* If the msg send fails because the pid was not found (i.e. smbd died), 115 112 * the msg has already been deleted from the messages.tdb.*/ 116 113 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, 119 115 (uint8 *)msg_all->buf, msg_all->len); 120 116 … … 123 119 /* If the pid was not found delete the entry from connections.tdb */ 124 120 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))); 128 122 129 123 rec->delete_rec(rec); … … 173 167 msg_all.msg_ctx = msg_ctx; 174 168 175 connections_forall(traverse_fn, &msg_all);169 serverid_traverse(traverse_fn, &msg_all); 176 170 if (n_sent) 177 171 *n_sent = msg_all.n_sent; … … 201 195 202 196 if (!NT_STATUS_IS_OK(status)) { 203 DEBUG( 0, ("messaging_tdb_init failed: %s\n",197 DEBUG(2, ("messaging_tdb_init failed: %s\n", 204 198 nt_errstr(status))); 205 199 TALLOC_FREE(ctx); … … 212 206 213 207 if (!NT_STATUS_IS_OK(status)) { 214 DEBUG( 1, ("messaging_ctdb_init failed: %s\n",208 DEBUG(2, ("messaging_ctdb_init failed: %s\n", 215 209 nt_errstr(status))); 216 210 TALLOC_FREE(ctx); … … 218 212 } 219 213 } 214 ctx->id.vnn = get_my_vnn(); 220 215 #endif 221 216 … … 231 226 } 232 227 228 struct server_id messaging_server_id(const struct messaging_context *msg_ctx) 229 { 230 return msg_ctx->id; 231 } 232 233 233 /* 234 234 * re-init after a fork 235 235 */ 236 NTSTATUS messaging_reinit(struct messaging_context *msg_ctx) 236 NTSTATUS messaging_reinit(struct messaging_context *msg_ctx, 237 struct server_id id) 237 238 { 238 239 NTSTATUS status; 239 240 240 241 TALLOC_FREE(msg_ctx->local); 242 243 msg_ctx->id = id; 241 244 242 245 status = messaging_tdb_init(msg_ctx, msg_ctx, &msg_ctx->local); … … 361 364 362 365 /* 363 Dispatch one mess saging_rec366 Dispatch one messaging_rec 364 367 */ 365 368 void messaging_dispatch_rec(struct messaging_context *msg_ctx, -
trunk/server/source3/lib/messages_ctdbd.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "messages.h" 22 #include "util_tdb.h" 21 23 22 24 #ifdef CLUSTER_SUPPORT 23 25 24 #include "librpc/gen_ndr/messaging.h"25 26 #include "ctdb.h" 26 27 #include "ctdb_private.h" … … 81 82 msg.msg_type = msg_type; 82 83 msg.dest = pid; 83 msg.src = procid_self();84 msg.src = msg_ctx->id; 84 85 msg.buf = *data; 85 86 -
trunk/server/source3/lib/messages_local.c
r414 r745 3 3 Samba internal messaging functions 4 4 Copyright (C) 2007 by Volker Lendecke 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 22 22 @{ 23 23 @file messages.c 24 24 25 25 @brief Module for internal messaging between Samba daemons. 26 26 … … 44 44 45 45 #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" 48 49 49 50 struct messaging_tdb_context { … … 104 105 105 106 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, 107 108 O_RDWR|O_CREAT,0600); 108 109 109 110 if (!ctx->tdb) { 110 111 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: " 112 113 "%s\n", strerror(errno))); 113 114 TALLOC_FREE(result); … … 134 135 } 135 136 137 bool 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 136 158 /******************************************************************* 137 159 Form a static tdb key from a pid. … … 146 168 147 169 SMB_ASSERT(key != NULL); 148 170 149 171 kbuf.dptr = (uint8 *)key; 150 172 kbuf.dsize = strlen(key)+1; … … 180 202 181 203 ndr_err = ndr_pull_struct_blob( 182 &blob, result, NULL,result,204 &blob, result, result, 183 205 (ndr_pull_flags_fn_t)ndr_pull_messaging_array); 184 206 … … 222 244 } 223 245 224 ndr_err = ndr_push_struct_blob( 225 &blob, mem_ctx, NULL, array, 246 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, array, 226 247 (ndr_push_flags_fn_t)ndr_push_messaging_array); 227 248 … … 361 382 rec[msg_array->num_messages].msg_type = msg_type & MSG_TYPE_MASK; 362 383 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; 364 385 rec[msg_array->num_messages].buf = *data; 365 386 … … 372 393 goto done; 373 394 } 374 395 375 396 status = message_notify(pid); 376 397 … … 388 409 389 410 /**************************************************************************** 390 Retrieve all messages for the currentprocess.411 Retrieve all messages for a process. 391 412 ****************************************************************************/ 392 413 393 414 static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, 415 struct server_id id, 394 416 TALLOC_CTX *mem_ctx, 395 417 struct messaging_array **presult) 396 418 { 397 419 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); 399 421 NTSTATUS status; 400 422 … … 444 466 ctx->received_messages)); 445 467 446 status = retrieve_all_messages(tdb->tdb, NULL, &msg_array);468 status = retrieve_all_messages(tdb->tdb, msg_ctx->id, NULL, &msg_array); 447 469 if (!NT_STATUS_IS_OK(status)) { 448 470 DEBUG(0, ("message_dispatch: failed to retrieve messages: %s\n", -
trunk/server/source3/lib/ms_fnmatch.c
r414 r745 235 235 int gen_fnmatch(const char *pattern, const char *string) 236 236 { 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 19 19 20 20 #include "includes.h" 21 #include "popt_common.h" 21 22 22 23 #include "lib/netapi/netapi.h" 23 24 #include "lib/netapi/netapi_private.h" 25 #include "libsmb/libsmb.h" 26 #include "rpc_client/cli_pipe.h" 24 27 25 28 /******************************************************************** … … 251 254 return WERR_OK; 252 255 } 256 257 /******************************************************************** 258 ********************************************************************/ 259 260 WERROR 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 479 479 p = strchr(newname, '.'); 480 480 if (p) { 481 *p = NULL;481 *p = '\0'; 482 482 } 483 483 -
trunk/server/source3/lib/netapi/examples/netlogon/nltest.c
r414 r745 31 31 32 32 enum { 33 OPT_DBFLAG = 1, 33 OPT_SERVER = 1, 34 OPT_DBFLAG, 34 35 OPT_SC_QUERY, 35 36 OPT_SC_RESET, 36 37 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 38 63 }; 39 64 … … 41 66 ****************************************************************/ 42 67 43 static void print_ result(uint32_t level,44 uint8_t *buffer)68 static void print_netlogon_info_result(uint32_t level, 69 uint8_t *buffer) 45 70 { 46 71 struct NETLOGON_INFO_1 *i1 = NULL; … … 101 126 ****************************************************************/ 102 127 128 static 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 159 static 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 103 181 int main(int argc, const char **argv) 104 182 { … … 106 184 NET_API_STATUS status; 107 185 struct libnetapi_ctx *ctx = NULL; 108 c onst char *server_name= NULL;186 char *opt_server = NULL; 109 187 char *opt_domain = NULL; 110 188 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; 112 213 uint8_t *buffer = NULL; 214 uint32_t flags = 0; 215 struct DOMAIN_CONTROLLER_INFO *dc_info = NULL; 113 216 114 217 poptContext pc; 115 218 struct poptOption long_options[] = { 116 219 POPT_AUTOHELP 220 {"server", 0, POPT_ARG_STRING, &opt_server, OPT_SERVER, "Servername", "SERVER"}, 117 221 {"dbflag", 0, POPT_ARG_INT, &opt_dbflag, OPT_DBFLAG, "New Debug Flag", "HEXFLAGS"}, 118 222 {"sc_query", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_QUERY, "Query secure channel for domain on server", "DOMAIN"}, … … 120 224 {"sc_verify", 0, POPT_ARG_STRING, &opt_domain, OPT_SC_VERIFY, "Verify secure channel for domain on server", "DOMAIN"}, 121 225 {"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"}, 122 250 POPT_COMMON_LIBNETAPI_EXAMPLES 123 251 POPT_TABLEEND … … 131 259 pc = poptGetContext("nltest", argc, argv, long_options, 0); 132 260 133 poptSetOtherOptionHelp(pc, " server_name");261 poptSetOtherOptionHelp(pc, "<options>"); 134 262 while((opt = poptGetNextOpt(pc)) != -1) { 135 263 } 136 137 if (!poptPeekArg(pc)) {138 poptPrintHelp(pc, stderr, 0);139 goto done;140 }141 server_name = poptGetArg(pc);142 264 143 265 if (argc == 1) { … … 146 268 } 147 269 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 158 270 poptResetContext(pc); 159 271 … … 161 273 switch (opt) { 162 274 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 163 284 case OPT_DBFLAG: 164 285 query_level = 1; 165 status = I_NetLogonControl2( server_name,286 status = I_NetLogonControl2(opt_server, 166 287 NETLOGON_CONTROL_SET_DBFLAG, 167 288 query_level, … … 174 295 goto done; 175 296 } 297 298 print_netlogon_info_result(query_level, buffer); 299 176 300 break; 177 301 case OPT_SC_QUERY: 178 302 query_level = 2; 179 status = I_NetLogonControl2( server_name,303 status = I_NetLogonControl2(opt_server, 180 304 NETLOGON_CONTROL_TC_QUERY, 181 305 query_level, … … 188 312 goto done; 189 313 } 314 315 print_netlogon_info_result(query_level, buffer); 316 190 317 break; 191 318 case OPT_SC_VERIFY: 192 319 query_level = 2; 193 status = I_NetLogonControl2( server_name,320 status = I_NetLogonControl2(opt_server, 194 321 NETLOGON_CONTROL_TC_VERIFY, 195 322 query_level, … … 202 329 goto done; 203 330 } 331 332 print_netlogon_info_result(query_level, buffer); 333 204 334 break; 205 335 case OPT_SC_RESET: 206 336 query_level = 2; 207 status = I_NetLogonControl2( server_name,337 status = I_NetLogonControl2(opt_server, 208 338 NETLOGON_CONTROL_REDISCOVER, 209 339 query_level, … … 216 346 goto done; 217 347 } 348 349 print_netlogon_info_result(query_level, buffer); 350 218 351 break; 219 352 case OPT_SC_CHANGE_PWD: 220 353 query_level = 1; 221 status = I_NetLogonControl2( server_name,354 status = I_NetLogonControl2(opt_server, 222 355 NETLOGON_CONTROL_CHANGE_PASSWORD, 223 356 query_level, … … 230 363 goto done; 231 364 } 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 232 441 break; 233 442 default: 234 poptPrintHelp(pc, stderr, 0); 235 goto done; 443 continue; 236 444 } 237 445 } 238 239 print_result(query_level, buffer);240 446 241 447 printf("The command completed successfully\n"); -
trunk/server/source3/lib/netapi/file.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #include "lib/netapi/libnetapi.h" 26 #include "../librpc/gen_ndr/ cli_srvsvc.h"26 #include "../librpc/gen_ndr/ndr_srvsvc_c.h" 27 27 28 28 /**************************************************************** … … 34 34 WERROR werr; 35 35 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(), 46 46 r->in.server_name, 47 47 r->in.fileid, … … 114 114 WERROR werr; 115 115 NTSTATUS status; 116 struct rpc_pipe_client *pipe_cli = NULL;117 116 union srvsvc_NetFileInfo info; 118 117 uint32_t num_entries = 0; 118 struct dcerpc_binding_handle *b; 119 119 120 120 if (!r->out.buffer) { … … 130 130 } 131 131 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(), 140 140 r->in.server_name, 141 141 r->in.fileid, … … 143 143 &info, 144 144 &werr); 145 if (!NT_STATUS_IS_OK(status)) { 146 werr = ntstatus_to_werror(status); 147 goto done; 148 } 149 145 150 if (!W_ERROR_IS_OK(werr)) { 146 151 goto done; … … 177 182 WERROR werr; 178 183 NTSTATUS status; 179 struct rpc_pipe_client *pipe_cli = NULL;180 184 struct srvsvc_NetFileInfoCtr info_ctr; 181 185 struct srvsvc_NetFileCtr2 ctr2; … … 183 187 uint32_t num_entries = 0; 184 188 uint32_t i; 189 struct dcerpc_binding_handle *b; 185 190 186 191 if (!r->out.buffer) { … … 196 201 } 197 202 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); 201 206 if (!W_ERROR_IS_OK(werr)) { 202 207 goto done; … … 217 222 } 218 223 219 status = rpccli_srvsvc_NetFileEnum(pipe_cli, talloc_tos(),224 status = dcerpc_srvsvc_NetFileEnum(b, talloc_tos(), 220 225 r->in.server_name, 221 226 r->in.base_path, … … 226 231 r->out.resume_handle, 227 232 &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)) { 229 239 goto done; 230 240 } -
trunk/server/source3/lib/netapi/getdc.c
r596 r745 20 20 #include "includes.h" 21 21 22 #include "../librpc/gen_ndr/ndr_netlogon_c.h" 22 23 #include "librpc/gen_ndr/libnetapi.h" 23 24 #include "lib/netapi/netapi.h" 24 25 #include "lib/netapi/netapi_private.h" 25 26 #include "lib/netapi/libnetapi.h" 26 #include "libnet/libnet.h"27 #include "../librpc/gen_ndr/cli_netlogon.h"28 27 29 28 /******************************************************************** … … 42 41 struct NetGetDCName *r) 43 42 { 44 struct rpc_pipe_client *pipe_cli = NULL;45 43 NTSTATUS status; 46 44 WERROR werr; 45 struct dcerpc_binding_handle *b; 47 46 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); 51 50 if (!W_ERROR_IS_OK(werr)) { 52 51 goto done; 53 52 } 54 53 55 status = rpccli_netr_GetDcName(pipe_cli, talloc_tos(),54 status = dcerpc_netr_GetDcName(b, talloc_tos(), 56 55 r->in.server_name, 57 56 r->in.domain_name, … … 82 81 struct NetGetAnyDCName *r) 83 82 { 84 struct rpc_pipe_client *pipe_cli = NULL;85 83 NTSTATUS status; 86 84 WERROR werr; 85 struct dcerpc_binding_handle *b; 87 86 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); 91 90 if (!W_ERROR_IS_OK(werr)) { 92 91 goto done; 93 92 } 94 93 95 status = rpccli_netr_GetAnyDCName(pipe_cli, talloc_tos(),94 status = dcerpc_netr_GetAnyDCName(b, talloc_tos(), 96 95 r->in.server_name, 97 96 r->in.domain_name, … … 99 98 &werr); 100 99 if (!NT_STATUS_IS_OK(status)) { 100 werr = ntstatus_to_werror(status); 101 101 goto done; 102 102 } … … 114 114 { 115 115 NTSTATUS status; 116 struct libnetapi_private_ctx *priv; 117 118 priv = talloc_get_type_abort(ctx->private_data, 119 struct libnetapi_private_ctx); 116 120 117 121 status = dsgetdcname(ctx, 118 NULL,122 priv->msg_ctx, 119 123 r->in.domain_name, 120 124 r->in.domain_guid, … … 139 143 WERROR werr; 140 144 NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND; 141 struct rpc_pipe_client *pipe_cli = NULL;145 struct dcerpc_binding_handle *b; 142 146 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); 146 150 if (!W_ERROR_IS_OK(werr)) { 147 151 goto done; 148 152 } 149 153 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, 151 168 ctx, 152 169 r->in.server_name, -
trunk/server/source3/lib/netapi/group.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #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" 27 30 28 31 /**************************************************************** … … 33 36 { 34 37 struct rpc_pipe_client *pipe_cli = NULL; 35 NTSTATUS status ;38 NTSTATUS status, result; 36 39 WERROR werr; 37 40 struct policy_handle connect_handle, domain_handle, group_handle; … … 39 42 struct dom_sid2 *domain_sid = NULL; 40 43 uint32_t rid = 0; 44 struct dcerpc_binding_handle *b = NULL; 41 45 42 46 struct GROUP_INFO_0 *info0 = NULL; … … 78 82 goto done; 79 83 } 84 85 b = pipe_cli->binding_handle; 80 86 81 87 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 106 112 } 107 113 108 status = rpccli_samr_CreateDomainGroup(pipe_cli, talloc_tos(),114 status = dcerpc_samr_CreateDomainGroup(b, talloc_tos(), 109 115 &domain_handle, 110 116 &lsa_group_name, … … 112 118 SAMR_GROUP_ACCESS_SET_INFO, 113 119 &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); 118 129 goto done; 119 130 } … … 125 136 info1->grpi1_comment); 126 137 127 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),138 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 128 139 &group_handle, 129 140 GROUPINFODESCRIPTION, 130 &info); 141 &info, 142 &result); 131 143 } 132 144 break; … … 136 148 info2->grpi2_comment); 137 149 138 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),150 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 139 151 &group_handle, 140 152 GROUPINFODESCRIPTION, 141 &info); 153 &info, 154 &result); 142 155 if (!NT_STATUS_IS_OK(status)) { 143 156 werr = ntstatus_to_werror(status); 144 157 goto failed; 145 158 } 159 if (!NT_STATUS_IS_OK(result)) { 160 werr = ntstatus_to_werror(result); 161 goto failed; 162 } 146 163 } 147 164 148 165 if (info2->grpi2_attributes != 0) { 149 166 info.attributes.attributes = info2->grpi2_attributes; 150 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),167 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 151 168 &group_handle, 152 169 GROUPINFOATTRIBUTES, 153 &info); 170 &info, 171 &result); 154 172 155 173 } … … 160 178 info3->grpi3_comment); 161 179 162 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),180 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 163 181 &group_handle, 164 182 GROUPINFODESCRIPTION, 165 &info); 183 &info, 184 &result); 166 185 if (!NT_STATUS_IS_OK(status)) { 167 186 werr = ntstatus_to_werror(status); 168 187 goto failed; 169 188 } 189 if (!NT_STATUS_IS_OK(result)) { 190 werr = ntstatus_to_werror(result); 191 goto failed; 192 } 170 193 } 171 194 172 195 if (info3->grpi3_attributes != 0) { 173 196 info.attributes.attributes = info3->grpi3_attributes; 174 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),197 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 175 198 &group_handle, 176 199 GROUPINFOATTRIBUTES, 177 &info); 200 &info, 201 &result); 178 202 } 179 203 break; … … 184 208 if (!NT_STATUS_IS_OK(status)) { 185 209 werr = ntstatus_to_werror(status); 210 goto failed; 211 } 212 if (!NT_STATUS_IS_OK(result)) { 213 werr = ntstatus_to_werror(result); 186 214 goto failed; 187 215 } … … 191 219 192 220 failed: 193 rpccli_samr_DeleteDomainGroup(pipe_cli, talloc_tos(),194 &group_handle );221 dcerpc_samr_DeleteDomainGroup(b, talloc_tos(), 222 &group_handle, &result); 195 223 196 224 done: 197 225 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); 199 227 } 200 228 … … 223 251 { 224 252 struct rpc_pipe_client *pipe_cli = NULL; 225 NTSTATUS status ;253 NTSTATUS status, result; 226 254 WERROR werr; 227 255 struct policy_handle connect_handle, domain_handle, group_handle; … … 229 257 struct dom_sid2 *domain_sid = NULL; 230 258 int i = 0; 259 struct dcerpc_binding_handle *b = NULL; 231 260 232 261 struct samr_Ids rids; 233 262 struct samr_Ids types; 234 263 union samr_GroupInfo *info = NULL; 235 struct samr_Rid TypeArray *rid_array = NULL;264 struct samr_RidAttrArray *rid_array = NULL; 236 265 237 266 ZERO_STRUCT(connect_handle); … … 249 278 goto done; 250 279 } 280 281 b = pipe_cli->binding_handle; 251 282 252 283 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 263 294 init_lsa_String(&lsa_group_name, r->in.group_name); 264 295 265 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),296 status = dcerpc_samr_LookupNames(b, talloc_tos(), 266 297 &domain_handle, 267 298 1, 268 299 &lsa_group_name, 269 300 &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); 273 309 goto done; 274 310 } … … 279 315 } 280 316 281 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),317 status = dcerpc_samr_OpenGroup(b, talloc_tos(), 282 318 &domain_handle, 283 319 SEC_STD_DELETE | … … 287 323 SAMR_GROUP_ACCESS_LOOKUP_INFO, 288 324 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(), 296 337 &group_handle, 297 338 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); 301 347 goto done; 302 348 } … … 309 355 } 310 356 #endif 311 status = rpccli_samr_QueryGroupMember(pipe_cli, talloc_tos(),357 status = dcerpc_samr_QueryGroupMember(b, talloc_tos(), 312 358 &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); 316 367 goto done; 317 368 } … … 321 372 struct samr_Ids member_types; 322 373 323 status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),374 status = dcerpc_samr_LookupRids(b, talloc_tos(), 324 375 &domain_handle, 325 376 rid_array->count, 326 377 rid_array->rids, 327 378 &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); 331 387 goto done; 332 388 } … … 335 391 for (i=0; i < rid_array->count; i++) { 336 392 337 status = rpccli_samr_DeleteGroupMember(pipe_cli, talloc_tos(),393 status = dcerpc_samr_DeleteGroupMember(b, talloc_tos(), 338 394 &group_handle, 339 rid_array->rids[i]); 395 rid_array->rids[i], 396 &result); 340 397 if (!NT_STATUS_IS_OK(status)) { 341 398 werr = ntstatus_to_werror(status); 342 399 goto done; 343 400 } 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); 350 416 goto done; 351 417 } … … 357 423 done: 358 424 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); 360 426 } 361 427 … … 384 450 { 385 451 struct rpc_pipe_client *pipe_cli = NULL; 386 NTSTATUS status ;452 NTSTATUS status, result; 387 453 WERROR werr; 388 454 struct policy_handle connect_handle, domain_handle, group_handle; 389 455 struct lsa_String lsa_group_name; 390 456 struct dom_sid2 *domain_sid = NULL; 457 struct dcerpc_binding_handle *b = NULL; 391 458 392 459 struct samr_Ids rids; … … 415 482 } 416 483 484 b = pipe_cli->binding_handle; 485 417 486 werr = libnetapi_samr_open_domain(ctx, pipe_cli, 418 487 SAMR_ACCESS_ENUM_DOMAINS | … … 428 497 init_lsa_String(&lsa_group_name, r->in.group_name); 429 498 430 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),499 status = dcerpc_samr_LookupNames(b, talloc_tos(), 431 500 &domain_handle, 432 501 1, 433 502 &lsa_group_name, 434 503 &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); 438 512 goto done; 439 513 } … … 444 518 } 445 519 446 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),520 status = dcerpc_samr_OpenGroup(b, talloc_tos(), 447 521 &domain_handle, 448 522 SAMR_GROUP_ACCESS_SET_INFO | 449 523 SAMR_GROUP_ACCESS_LOOKUP_INFO, 450 524 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); 454 533 goto done; 455 534 } … … 459 538 g0 = (struct GROUP_INFO_0 *)r->in.buffer; 460 539 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(), 462 541 &group_handle, 463 542 GROUPINFONAME, 464 &info); 543 &info, 544 &result); 465 545 break; 466 546 case 1: 467 547 g1 = (struct GROUP_INFO_1 *)r->in.buffer; 468 548 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(), 470 550 &group_handle, 471 551 GROUPINFODESCRIPTION, 472 &info); 552 &info, 553 &result); 473 554 break; 474 555 case 2: 475 556 g2 = (struct GROUP_INFO_2 *)r->in.buffer; 476 557 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(), 478 559 &group_handle, 479 560 GROUPINFODESCRIPTION, 480 &info); 561 &info, 562 &result); 481 563 if (!NT_STATUS_IS_OK(status)) { 482 564 werr = ntstatus_to_werror(status); 483 565 goto done; 484 566 } 567 if (!NT_STATUS_IS_OK(result)) { 568 werr = ntstatus_to_werror(result); 569 goto done; 570 } 571 485 572 info.attributes.attributes = g2->grpi2_attributes; 486 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),573 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 487 574 &group_handle, 488 575 GROUPINFOATTRIBUTES, 489 &info); 576 &info, 577 &result); 490 578 break; 491 579 case 3: 492 580 g3 = (struct GROUP_INFO_3 *)r->in.buffer; 493 581 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(), 495 583 &group_handle, 496 584 GROUPINFODESCRIPTION, 497 &info); 585 &info, 586 &result); 498 587 if (!NT_STATUS_IS_OK(status)) { 499 588 werr = ntstatus_to_werror(status); 500 589 goto done; 501 590 } 591 if (!NT_STATUS_IS_OK(result)) { 592 werr = ntstatus_to_werror(result); 593 goto done; 594 } 595 502 596 info.attributes.attributes = g3->grpi3_attributes; 503 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),597 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 504 598 &group_handle, 505 599 GROUPINFOATTRIBUTES, 506 &info); 600 &info, 601 &result); 507 602 break; 508 603 case 1002: 509 604 g1002 = (struct GROUP_INFO_1002 *)r->in.buffer; 510 605 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(), 512 607 &group_handle, 513 608 GROUPINFODESCRIPTION, 514 &info); 609 &info, 610 &result); 515 611 break; 516 612 case 1005: 517 613 g1005 = (struct GROUP_INFO_1005 *)r->in.buffer; 518 614 info.attributes.attributes = g1005->grpi1005_attributes; 519 status = rpccli_samr_SetGroupInfo(pipe_cli, talloc_tos(),615 status = dcerpc_samr_SetGroupInfo(b, talloc_tos(), 520 616 &group_handle, 521 617 GROUPINFOATTRIBUTES, 522 &info); 618 &info, 619 &result); 523 620 break; 524 621 default: … … 531 628 goto done; 532 629 } 630 if (!NT_STATUS_IS_OK(result)) { 631 werr = ntstatus_to_werror(result); 632 goto done; 633 } 533 634 534 635 werr = WERR_OK; … … 536 637 done: 537 638 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); 539 640 } 540 641 … … 603 704 info3.grpi3_comment = info->description.string; 604 705 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); 606 707 607 708 *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3, sizeof(info3)); … … 624 725 { 625 726 struct rpc_pipe_client *pipe_cli = NULL; 626 NTSTATUS status ;727 NTSTATUS status, result; 627 728 WERROR werr; 628 729 struct policy_handle connect_handle, domain_handle, group_handle; 629 730 struct lsa_String lsa_group_name; 630 731 struct dom_sid2 *domain_sid = NULL; 732 struct dcerpc_binding_handle *b = NULL; 631 733 632 734 struct samr_Ids rids; … … 649 751 goto done; 650 752 } 753 754 b = pipe_cli->binding_handle; 651 755 652 756 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 663 767 init_lsa_String(&lsa_group_name, r->in.group_name); 664 768 665 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),769 status = dcerpc_samr_LookupNames(b, talloc_tos(), 666 770 &domain_handle, 667 771 1, 668 772 &lsa_group_name, 669 773 &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); 673 782 goto done; 674 783 } … … 679 788 } 680 789 681 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),790 status = dcerpc_samr_OpenGroup(b, talloc_tos(), 682 791 &domain_handle, 683 792 SAMR_GROUP_ACCESS_LOOKUP_INFO, 684 793 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(), 692 806 &group_handle, 693 807 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(), 697 817 &group_handle, 698 818 GROUPINFOALL, 699 &info); 819 &info, 820 &result); 700 821 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); 705 830 goto done; 706 831 } … … 715 840 done: 716 841 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); 718 843 } 719 844 … … 742 867 { 743 868 struct rpc_pipe_client *pipe_cli = NULL; 744 NTSTATUS status ;869 NTSTATUS status, result; 745 870 WERROR werr; 746 871 struct policy_handle connect_handle, domain_handle, group_handle; 747 872 struct lsa_String lsa_group_name, lsa_user_name; 748 873 struct dom_sid2 *domain_sid = NULL; 874 struct dcerpc_binding_handle *b = NULL; 749 875 750 876 struct samr_Ids rids; … … 765 891 goto done; 766 892 } 893 894 b = pipe_cli->binding_handle; 767 895 768 896 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 779 907 init_lsa_String(&lsa_group_name, r->in.group_name); 780 908 781 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),909 status = dcerpc_samr_LookupNames(b, talloc_tos(), 782 910 &domain_handle, 783 911 1, 784 912 &lsa_group_name, 785 913 &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)) { 788 921 werr = WERR_GROUPNOTFOUND; 789 922 goto done; … … 795 928 } 796 929 797 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),930 status = dcerpc_samr_OpenGroup(b, talloc_tos(), 798 931 &domain_handle, 799 932 SAMR_GROUP_ACCESS_ADD_MEMBER, 800 933 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); 804 942 goto done; 805 943 } … … 807 945 init_lsa_String(&lsa_user_name, r->in.user_name); 808 946 809 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),947 status = dcerpc_samr_LookupNames(b, talloc_tos(), 810 948 &domain_handle, 811 949 1, 812 950 &lsa_user_name, 813 951 &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)) { 816 959 werr = WERR_USER_NOT_FOUND; 817 960 goto done; … … 823 966 } 824 967 825 status = rpccli_samr_AddGroupMember(pipe_cli, talloc_tos(),968 status = dcerpc_samr_AddGroupMember(b, talloc_tos(), 826 969 &group_handle, 827 970 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); 831 979 goto done; 832 980 } … … 836 984 done: 837 985 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); 839 987 } 840 988 … … 863 1011 { 864 1012 struct rpc_pipe_client *pipe_cli = NULL; 865 NTSTATUS status ;1013 NTSTATUS status, result; 866 1014 WERROR werr; 867 1015 struct policy_handle connect_handle, domain_handle, group_handle; 868 1016 struct lsa_String lsa_group_name, lsa_user_name; 869 1017 struct dom_sid2 *domain_sid = NULL; 1018 struct dcerpc_binding_handle *b = NULL; 870 1019 871 1020 struct samr_Ids rids; … … 886 1035 goto done; 887 1036 } 1037 1038 b = pipe_cli->binding_handle; 888 1039 889 1040 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 900 1051 init_lsa_String(&lsa_group_name, r->in.group_name); 901 1052 902 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1053 status = dcerpc_samr_LookupNames(b, talloc_tos(), 903 1054 &domain_handle, 904 1055 1, 905 1056 &lsa_group_name, 906 1057 &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)) { 909 1065 werr = WERR_GROUPNOTFOUND; 910 1066 goto done; … … 916 1072 } 917 1073 918 status = rpccli_samr_OpenGroup(pipe_cli, talloc_tos(),1074 status = dcerpc_samr_OpenGroup(b, talloc_tos(), 919 1075 &domain_handle, 920 1076 SAMR_GROUP_ACCESS_REMOVE_MEMBER, 921 1077 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); 925 1086 goto done; 926 1087 } … … 928 1089 init_lsa_String(&lsa_user_name, r->in.user_name); 929 1090 930 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1091 status = dcerpc_samr_LookupNames(b, talloc_tos(), 931 1092 &domain_handle, 932 1093 1, 933 1094 &lsa_user_name, 934 1095 &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)) { 937 1104 werr = WERR_USER_NOT_FOUND; 938 1105 goto done; … … 944 1111 } 945 1112 946 status = rpccli_samr_DeleteGroupMember(pipe_cli, talloc_tos(),1113 status = dcerpc_samr_DeleteGroupMember(b, talloc_tos(), 947 1114 &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); 951 1123 goto done; 952 1124 } … … 956 1128 done: 957 1129 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); 959 1131 } 960 1132 … … 1086 1258 g3[i].grpi3_comment = talloc_strdup(mem_ctx, 1087 1259 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); 1089 1261 g3[i].grpi3_attributes = groups->entries[i].acct_flags; 1090 1262 W_ERROR_HAVE_NO_MEMORY(g3[i].grpi3_name); … … 1138 1310 union samr_DispInfo info; 1139 1311 union samr_DomainInfo *domain_info = NULL; 1312 struct dcerpc_binding_handle *b = NULL; 1140 1313 1141 1314 uint32_t total_size = 0; 1142 1315 uint32_t returned_size = 0; 1143 1316 1317 NTSTATUS result = NT_STATUS_OK; 1144 1318 NTSTATUS status = NT_STATUS_OK; 1145 1319 WERROR werr, tmp_werr; … … 1164 1338 goto done; 1165 1339 } 1340 1341 b = pipe_cli->binding_handle; 1166 1342 1167 1343 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 1178 1354 } 1179 1355 1180 status = rpccli_samr_QueryDomainInfo(pipe_cli, talloc_tos(),1356 status = dcerpc_samr_QueryDomainInfo(b, talloc_tos(), 1181 1357 &domain_handle, 1182 1358 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); 1186 1367 goto done; 1187 1368 } … … 1191 1372 } 1192 1373 1193 status = rpccli_samr_QueryDisplayInfo2(pipe_cli,1374 status = dcerpc_samr_QueryDisplayInfo2(b, 1194 1375 ctx, 1195 1376 &domain_handle, … … 1201 1382 &total_size, 1202 1383 &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)) { 1206 1393 goto done; 1207 1394 } … … 1225 1412 done: 1226 1413 /* 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)) { 1229 1416 1230 1417 if (ctx->disable_policy_handle_cache) { … … 1259 1446 struct dom_sid2 *domain_sid = NULL; 1260 1447 struct samr_Ids group_rids, name_types; 1261 struct samr_Rid TypeArray *rid_array = NULL;1448 struct samr_RidAttrArray *rid_array = NULL; 1262 1449 struct lsa_Strings names; 1263 1450 struct samr_Ids member_types; 1451 struct dcerpc_binding_handle *b = NULL; 1264 1452 1265 1453 int i; … … 1267 1455 1268 1456 NTSTATUS status = NT_STATUS_OK; 1457 NTSTATUS result = NT_STATUS_OK; 1269 1458 WERROR werr; 1270 1459 … … 1295 1484 goto done; 1296 1485 } 1486 1487 b = pipe_cli->binding_handle; 1297 1488 1298 1489 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 1309 1500 init_lsa_String(&lsa_account_name, r->in.group_name); 1310 1501 1311 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1502 status = dcerpc_samr_LookupNames(b, talloc_tos(), 1312 1503 &domain_handle, 1313 1504 1, 1314 1505 &lsa_account_name, 1315 1506 &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(), 1323 1519 &domain_handle, 1324 1520 SAMR_GROUP_ACCESS_GET_MEMBERS, 1325 1521 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(), 1333 1534 &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(), 1341 1547 &domain_handle, 1342 1548 rid_array->count, 1343 1549 rid_array->rids, 1344 1550 &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); 1348 1559 goto done; 1349 1560 } … … 1374 1585 done: 1375 1586 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); 1377 1588 } 1378 1589 … … 1407 1618 struct samr_Ids user_rids, name_types; 1408 1619 struct samr_Ids group_rids, group_types; 1409 struct samr_Rid TypeArray *rid_array = NULL;1620 struct samr_RidAttrArray *rid_array = NULL; 1410 1621 struct lsa_String *lsa_names = NULL; 1622 struct dcerpc_binding_handle *b = NULL; 1411 1623 1412 1624 uint32_t *add_rids = NULL; … … 1416 1628 1417 1629 uint32_t *member_rids = NULL; 1418 size_t num_member_rids = 0;1419 1630 1420 1631 struct GROUP_USERS_INFO_0 *i0 = NULL; … … 1424 1635 1425 1636 NTSTATUS status = NT_STATUS_OK; 1637 NTSTATUS result = NT_STATUS_OK; 1426 1638 WERROR werr; 1427 1639 … … 1447 1659 goto done; 1448 1660 } 1661 1662 b = pipe_cli->binding_handle; 1449 1663 1450 1664 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 1461 1675 init_lsa_String(&lsa_account_name, r->in.group_name); 1462 1676 1463 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1677 status = dcerpc_samr_LookupNames(b, talloc_tos(), 1464 1678 &domain_handle, 1465 1679 1, 1466 1680 &lsa_account_name, 1467 1681 &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(), 1475 1694 &domain_handle, 1476 1695 SAMR_GROUP_ACCESS_GET_MEMBERS | … … 1479 1698 SAMR_GROUP_ACCESS_LOOKUP_INFO, 1480 1699 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(), 1488 1712 &group_handle, 1489 1713 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); 1493 1722 goto done; 1494 1723 } … … 1523 1752 } 1524 1753 1525 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1754 status = dcerpc_samr_LookupNames(b, talloc_tos(), 1526 1755 &domain_handle, 1527 1756 r->in.num_entries, 1528 1757 lsa_names, 1529 1758 &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); 1533 1767 goto done; 1534 1768 } 1535 1769 1536 1770 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(), 1540 1773 &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); 1544 1782 goto done; 1545 1783 } … … 1588 1826 1589 1827 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(), 1591 1829 &group_handle, 1592 1830 add_rids[i], 1593 7 /* ? */); 1831 7 /* ? */, 1832 &result); 1594 1833 if (!NT_STATUS_IS_OK(status)) { 1595 1834 werr = ntstatus_to_werror(status); 1596 1835 goto done; 1597 1836 } 1837 if (!NT_STATUS_IS_OK(result)) { 1838 werr = ntstatus_to_werror(result); 1839 goto done; 1840 } 1598 1841 } 1599 1842 … … 1601 1844 1602 1845 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(), 1604 1847 &group_handle, 1605 del_rids[i]); 1848 del_rids[i], 1849 &result); 1606 1850 if (!NT_STATUS_IS_OK(status)) { 1607 1851 werr = ntstatus_to_werror(status); 1608 1852 goto done; 1609 1853 } 1854 if (!NT_STATUS_IS_OK(result)) { 1855 werr = ntstatus_to_werror(result); 1856 goto done; 1857 } 1610 1858 } 1611 1859 … … 1614 1862 done: 1615 1863 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); 1617 1865 } 1618 1866 -
trunk/server/source3/lib/netapi/joindomain.c
r596 r745 19 19 20 20 #include "includes.h" 21 21 #include "ads.h" 22 22 #include "librpc/gen_ndr/libnetapi.h" 23 #include "libcli/auth/libcli_auth.h" 23 24 #include "lib/netapi/netapi.h" 24 25 #include "lib/netapi/netapi_private.h" 25 26 #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" 29 32 30 33 /**************************************************************** … … 35 38 { 36 39 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); 38 45 39 46 if (!r->in.domain) { … … 54 61 DS_WRITABLE_REQUIRED | 55 62 DS_RETURN_DNS_NAME; 56 status = dsgetdcname(mem_ctx, NULL, r->in.domain,63 status = dsgetdcname(mem_ctx, priv->msg_ctx, r->in.domain, 57 64 NULL, NULL, flags, &info); 58 65 if (!NT_STATUS_IS_OK(status)) { … … 106 113 WERROR werr; 107 114 unsigned int old_timeout = 0; 115 struct dcerpc_binding_handle *b; 116 DATA_BLOB session_key; 108 117 109 118 werr = libnetapi_open_pipe(ctx, r->in.server, … … 114 123 } 115 124 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 117 135 encode_wkssvc_join_password_buffer(ctx, 118 136 r->in.password, 119 & pipe_cli->auth->user_session_key,137 &session_key, 120 138 &encrypted_password); 121 139 } … … 123 141 old_timeout = rpccli_set_timeout(pipe_cli, 600000); 124 142 125 status = rpccli_wkssvc_NetrJoinDomain2(pipe_cli, talloc_tos(),143 status = dcerpc_wkssvc_NetrJoinDomain2(b, talloc_tos(), 126 144 r->in.server, 127 145 r->in.domain, … … 153 171 const char *domain = NULL; 154 172 WERROR werr; 173 struct libnetapi_private_ctx *priv; 174 175 priv = talloc_get_type_abort(mem_ctx->private_data, 176 struct libnetapi_private_ctx); 155 177 156 178 if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) { … … 177 199 DS_WRITABLE_REQUIRED | 178 200 DS_RETURN_DNS_NAME; 179 status = dsgetdcname(mem_ctx, NULL, domain,201 status = dsgetdcname(mem_ctx, priv->msg_ctx, domain, 180 202 NULL, NULL, flags, &info); 181 203 if (!NT_STATUS_IS_OK(status)) { … … 232 254 WERROR werr; 233 255 unsigned int old_timeout = 0; 256 struct dcerpc_binding_handle *b; 257 DATA_BLOB session_key; 234 258 235 259 werr = libnetapi_open_pipe(ctx, r->in.server_name, … … 240 264 } 241 265 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 243 276 encode_wkssvc_join_password_buffer(ctx, 244 277 r->in.password, 245 & pipe_cli->auth->user_session_key,278 &session_key, 246 279 &encrypted_password); 247 280 } … … 249 282 old_timeout = rpccli_set_timeout(pipe_cli, 60000); 250 283 251 status = rpccli_wkssvc_NetrUnjoinDomain2(pipe_cli, talloc_tos(),284 status = dcerpc_wkssvc_NetrUnjoinDomain2(b, talloc_tos(), 252 285 r->in.server_name, 253 286 r->in.account, … … 278 311 WERROR werr; 279 312 const char *buffer = NULL; 313 struct dcerpc_binding_handle *b; 280 314 281 315 werr = libnetapi_open_pipe(ctx, r->in.server_name, … … 286 320 } 287 321 288 status = rpccli_wkssvc_NetrGetJoinInformation(pipe_cli, talloc_tos(), 322 b = pipe_cli->binding_handle; 323 324 status = dcerpc_wkssvc_NetrGetJoinInformation(b, talloc_tos(), 289 325 r->in.server_name, 290 326 &buffer, … … 293 329 if (!NT_STATUS_IS_OK(status)) { 294 330 werr = ntstatus_to_werror(status); 331 goto done; 332 } 333 334 if (!W_ERROR_IS_OK(werr)) { 295 335 goto done; 296 336 } … … 339 379 struct NetGetJoinableOUs *r) 340 380 { 341 #ifdef WITH_ADS381 #ifdef HAVE_ADS 342 382 NTSTATUS status; 343 383 ADS_STATUS ads_status; … … 347 387 uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | 348 388 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, 351 395 NULL, NULL, flags, &info); 352 396 if (!NT_STATUS_IS_OK(status)) { … … 408 452 NTSTATUS status; 409 453 WERROR werr; 454 struct dcerpc_binding_handle *b; 455 DATA_BLOB session_key; 410 456 411 457 werr = libnetapi_open_pipe(ctx, r->in.server_name, … … 416 462 } 417 463 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 419 474 encode_wkssvc_join_password_buffer(ctx, 420 475 r->in.password, 421 & pipe_cli->auth->user_session_key,476 &session_key, 422 477 &encrypted_password); 423 478 } 424 479 425 status = rpccli_wkssvc_NetrGetJoinableOus2(pipe_cli, talloc_tos(),480 status = dcerpc_wkssvc_NetrGetJoinableOus2(b, talloc_tos(), 426 481 r->in.server_name, 427 482 r->in.domain, … … 450 505 NTSTATUS status; 451 506 WERROR werr; 507 struct dcerpc_binding_handle *b; 508 DATA_BLOB session_key; 452 509 453 510 werr = libnetapi_open_pipe(ctx, r->in.server_name, … … 458 515 } 459 516 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 461 527 encode_wkssvc_join_password_buffer(ctx, 462 528 r->in.password, 463 & pipe_cli->auth->user_session_key,529 &session_key, 464 530 &encrypted_password); 465 531 } 466 532 467 status = rpccli_wkssvc_NetrRenameMachineInDomain2(pipe_cli, talloc_tos(),533 status = dcerpc_wkssvc_NetrRenameMachineInDomain2(b, talloc_tos(), 468 534 r->in.server_name, 469 535 r->in.new_machine_name, -
trunk/server/source3/lib/netapi/libnetapi.c
r596 r745 75 75 76 76 TALLOC_FREE(frame); 77 return r.out.result;77 return (NET_API_STATUS)r.out.result; 78 78 } 79 79 … … 124 124 125 125 TALLOC_FREE(frame); 126 return r.out.result;126 return (NET_API_STATUS)r.out.result; 127 127 } 128 128 … … 171 171 172 172 TALLOC_FREE(frame); 173 return r.out.result;173 return (NET_API_STATUS)r.out.result; 174 174 } 175 175 … … 224 224 225 225 TALLOC_FREE(frame); 226 return r.out.result;226 return (NET_API_STATUS)r.out.result; 227 227 } 228 228 … … 275 275 276 276 TALLOC_FREE(frame); 277 return r.out.result;277 return (NET_API_STATUS)r.out.result; 278 278 } 279 279 … … 322 322 323 323 TALLOC_FREE(frame); 324 return r.out.result;324 return (NET_API_STATUS)r.out.result; 325 325 } 326 326 … … 371 371 372 372 TALLOC_FREE(frame); 373 return r.out.result;373 return (NET_API_STATUS)r.out.result; 374 374 } 375 375 … … 418 418 419 419 TALLOC_FREE(frame); 420 return r.out.result;420 return (NET_API_STATUS)r.out.result; 421 421 } 422 422 … … 465 465 466 466 TALLOC_FREE(frame); 467 return r.out.result;467 return (NET_API_STATUS)r.out.result; 468 468 } 469 469 … … 518 518 519 519 TALLOC_FREE(frame); 520 return r.out.result;520 return (NET_API_STATUS)r.out.result; 521 521 } 522 522 … … 567 567 568 568 TALLOC_FREE(frame); 569 return r.out.result;569 return (NET_API_STATUS)r.out.result; 570 570 } 571 571 … … 612 612 613 613 TALLOC_FREE(frame); 614 return r.out.result;614 return (NET_API_STATUS)r.out.result; 615 615 } 616 616 … … 670 670 671 671 TALLOC_FREE(frame); 672 return r.out.result;672 return (NET_API_STATUS)r.out.result; 673 673 } 674 674 … … 719 719 720 720 TALLOC_FREE(frame); 721 return r.out.result;721 return (NET_API_STATUS)r.out.result; 722 722 } 723 723 … … 768 768 769 769 TALLOC_FREE(frame); 770 return r.out.result;770 return (NET_API_STATUS)r.out.result; 771 771 } 772 772 … … 819 819 820 820 TALLOC_FREE(frame); 821 return r.out.result;821 return (NET_API_STATUS)r.out.result; 822 822 } 823 823 … … 874 874 875 875 TALLOC_FREE(frame); 876 return r.out.result;876 return (NET_API_STATUS)r.out.result; 877 877 } 878 878 … … 925 925 926 926 TALLOC_FREE(frame); 927 return r.out.result;927 return (NET_API_STATUS)r.out.result; 928 928 } 929 929 … … 982 982 983 983 TALLOC_FREE(frame); 984 return r.out.result;984 return (NET_API_STATUS)r.out.result; 985 985 } 986 986 … … 1029 1029 1030 1030 TALLOC_FREE(frame); 1031 return r.out.result;1031 return (NET_API_STATUS)r.out.result; 1032 1032 } 1033 1033 … … 1078 1078 1079 1079 TALLOC_FREE(frame); 1080 return r.out.result;1080 return (NET_API_STATUS)r.out.result; 1081 1081 } 1082 1082 … … 1133 1133 1134 1134 TALLOC_FREE(frame); 1135 return r.out.result;1135 return (NET_API_STATUS)r.out.result; 1136 1136 } 1137 1137 … … 1182 1182 1183 1183 TALLOC_FREE(frame); 1184 return r.out.result;1184 return (NET_API_STATUS)r.out.result; 1185 1185 } 1186 1186 … … 1227 1227 1228 1228 TALLOC_FREE(frame); 1229 return r.out.result;1229 return (NET_API_STATUS)r.out.result; 1230 1230 } 1231 1231 … … 1283 1283 1284 1284 TALLOC_FREE(frame); 1285 return r.out.result;1285 return (NET_API_STATUS)r.out.result; 1286 1286 } 1287 1287 … … 1334 1334 1335 1335 TALLOC_FREE(frame); 1336 return r.out.result;1336 return (NET_API_STATUS)r.out.result; 1337 1337 } 1338 1338 … … 1383 1383 1384 1384 TALLOC_FREE(frame); 1385 return r.out.result;1385 return (NET_API_STATUS)r.out.result; 1386 1386 } 1387 1387 … … 1430 1430 1431 1431 TALLOC_FREE(frame); 1432 return r.out.result;1432 return (NET_API_STATUS)r.out.result; 1433 1433 } 1434 1434 … … 1477 1477 1478 1478 TALLOC_FREE(frame); 1479 return r.out.result;1479 return (NET_API_STATUS)r.out.result; 1480 1480 } 1481 1481 … … 1535 1535 1536 1536 TALLOC_FREE(frame); 1537 return r.out.result;1537 return (NET_API_STATUS)r.out.result; 1538 1538 } 1539 1539 … … 1586 1586 1587 1587 TALLOC_FREE(frame); 1588 return r.out.result;1588 return (NET_API_STATUS)r.out.result; 1589 1589 } 1590 1590 … … 1635 1635 1636 1636 TALLOC_FREE(frame); 1637 return r.out.result;1637 return (NET_API_STATUS)r.out.result; 1638 1638 } 1639 1639 … … 1680 1680 1681 1681 TALLOC_FREE(frame); 1682 return r.out.result;1682 return (NET_API_STATUS)r.out.result; 1683 1683 } 1684 1684 … … 1729 1729 1730 1730 TALLOC_FREE(frame); 1731 return r.out.result;1731 return (NET_API_STATUS)r.out.result; 1732 1732 } 1733 1733 … … 1780 1780 1781 1781 TALLOC_FREE(frame); 1782 return r.out.result;1782 return (NET_API_STATUS)r.out.result; 1783 1783 } 1784 1784 … … 1836 1836 1837 1837 TALLOC_FREE(frame); 1838 return r.out.result;1838 return (NET_API_STATUS)r.out.result; 1839 1839 } 1840 1840 … … 1887 1887 1888 1888 TALLOC_FREE(frame); 1889 return r.out.result;1889 return (NET_API_STATUS)r.out.result; 1890 1890 } 1891 1891 … … 1938 1938 1939 1939 TALLOC_FREE(frame); 1940 return r.out.result;1940 return (NET_API_STATUS)r.out.result; 1941 1941 } 1942 1942 … … 1996 1996 1997 1997 TALLOC_FREE(frame); 1998 return r.out.result;1998 return (NET_API_STATUS)r.out.result; 1999 1999 } 2000 2000 … … 2047 2047 2048 2048 TALLOC_FREE(frame); 2049 return r.out.result;2049 return (NET_API_STATUS)r.out.result; 2050 2050 } 2051 2051 … … 2092 2092 2093 2093 TALLOC_FREE(frame); 2094 return r.out.result;2094 return (NET_API_STATUS)r.out.result; 2095 2095 } 2096 2096 … … 2141 2141 2142 2142 TALLOC_FREE(frame); 2143 return r.out.result;2143 return (NET_API_STATUS)r.out.result; 2144 2144 } 2145 2145 … … 2188 2188 2189 2189 TALLOC_FREE(frame); 2190 return r.out.result;2190 return (NET_API_STATUS)r.out.result; 2191 2191 } 2192 2192 … … 2244 2244 2245 2245 TALLOC_FREE(frame); 2246 return r.out.result;2246 return (NET_API_STATUS)r.out.result; 2247 2247 } 2248 2248 … … 2293 2293 2294 2294 TALLOC_FREE(frame); 2295 return r.out.result;2295 return (NET_API_STATUS)r.out.result; 2296 2296 } 2297 2297 … … 2344 2344 2345 2345 TALLOC_FREE(frame); 2346 return r.out.result;2346 return (NET_API_STATUS)r.out.result; 2347 2347 } 2348 2348 … … 2389 2389 2390 2390 TALLOC_FREE(frame); 2391 return r.out.result;2391 return (NET_API_STATUS)r.out.result; 2392 2392 } 2393 2393 … … 2438 2438 2439 2439 TALLOC_FREE(frame); 2440 return r.out.result;2440 return (NET_API_STATUS)r.out.result; 2441 2441 } 2442 2442 … … 2498 2498 2499 2499 TALLOC_FREE(frame); 2500 return r.out.result;2500 return (NET_API_STATUS)r.out.result; 2501 2501 } 2502 2502 … … 2549 2549 2550 2550 TALLOC_FREE(frame); 2551 return r.out.result;2551 return (NET_API_STATUS)r.out.result; 2552 2552 } 2553 2553 … … 2592 2592 2593 2593 TALLOC_FREE(frame); 2594 return r.out.result;2594 return (NET_API_STATUS)r.out.result; 2595 2595 } 2596 2596 … … 2641 2641 2642 2642 TALLOC_FREE(frame); 2643 return r.out.result;2643 return (NET_API_STATUS)r.out.result; 2644 2644 } 2645 2645 … … 2692 2692 2693 2693 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 1 20 #ifndef __LIBNETAPI_LIBNETAPI__ 2 21 #define __LIBNETAPI_LIBNETAPI__ -
trunk/server/source3/lib/netapi/localgroup.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #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" 28 32 29 33 static NTSTATUS libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx, … … 34 38 struct policy_handle *alias_handle) 35 39 { 36 NTSTATUS status ;40 NTSTATUS status, result; 37 41 38 42 struct lsa_String lsa_account_name; 39 43 struct samr_Ids user_rids, name_types; 44 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 40 45 41 46 init_lsa_String(&lsa_account_name, group_name); 42 47 43 status = rpccli_samr_LookupNames(pipe_cli, mem_ctx,48 status = dcerpc_samr_LookupNames(b, mem_ctx, 44 49 domain_handle, 45 50 1, 46 51 &lsa_account_name, 47 52 &user_rids, 48 &name_types); 53 &name_types, 54 &result); 49 55 if (!NT_STATUS_IS_OK(status)) { 50 56 return status; 57 } 58 if (!NT_STATUS_IS_OK(result)) { 59 return result; 51 60 } 52 61 … … 59 68 } 60 69 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; 66 81 } 67 82 … … 77 92 union samr_AliasInfo **alias_info) 78 93 { 79 NTSTATUS status ;94 NTSTATUS status, result; 80 95 struct policy_handle alias_handle; 81 96 union samr_AliasInfo *_alias_info = NULL; 97 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 82 98 83 99 ZERO_STRUCT(alias_handle); 84 100 85 status = rpccli_samr_OpenAlias(pipe_cli, mem_ctx,101 status = dcerpc_samr_OpenAlias(b, mem_ctx, 86 102 handle, 87 103 access_rights, 88 104 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, 95 116 &alias_handle, 96 117 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; 99 125 goto done; 100 126 } … … 104 130 done: 105 131 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); 107 133 } 108 134 … … 117 143 { 118 144 struct rpc_pipe_client *pipe_cli = NULL; 119 NTSTATUS status ;145 NTSTATUS status, result; 120 146 WERROR werr; 121 147 struct lsa_String lsa_account_name; … … 123 149 struct dom_sid2 *domain_sid = NULL; 124 150 uint32_t rid; 151 struct dcerpc_binding_handle *b = NULL; 125 152 126 153 struct LOCALGROUP_INFO_0 *info0 = NULL; … … 158 185 goto done; 159 186 } 187 188 b = pipe_cli->binding_handle; 160 189 161 190 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, … … 197 226 init_lsa_String(&lsa_account_name, alias_name); 198 227 199 status = rpccli_samr_CreateDomAlias(pipe_cli, talloc_tos(),228 status = dcerpc_samr_CreateDomAlias(b, talloc_tos(), 200 229 &domain_handle, 201 230 &lsa_account_name, … … 203 232 SAMR_ALIAS_ACCESS_SET_INFO, 204 233 &alias_handle, 205 &rid); 234 &rid, 235 &result); 206 236 if (!NT_STATUS_IS_OK(status)) { 207 237 werr = ntstatus_to_werror(status); 208 238 goto done; 209 239 } 240 if (!NT_STATUS_IS_OK(result)) { 241 werr = ntstatus_to_werror(result); 242 goto done; 243 } 244 210 245 211 246 if (r->in.level == 1 && info1->lgrpi1_comment) { … … 215 250 init_lsa_String(&alias_info.description, info1->lgrpi1_comment); 216 251 217 status = rpccli_samr_SetAliasInfo(pipe_cli, talloc_tos(),252 status = dcerpc_samr_SetAliasInfo(b, talloc_tos(), 218 253 &alias_handle, 219 254 ALIASINFODESCRIPTION, 220 &alias_info); 255 &alias_info, 256 &result); 221 257 if (!NT_STATUS_IS_OK(status)) { 222 258 werr = ntstatus_to_werror(status); 223 259 goto done; 224 260 } 261 if (!NT_STATUS_IS_OK(result)) { 262 werr = ntstatus_to_werror(result); 263 goto done; 264 } 225 265 } 226 266 … … 229 269 done: 230 270 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); 232 272 } 233 273 … … 258 298 { 259 299 struct rpc_pipe_client *pipe_cli = NULL; 260 NTSTATUS status ;300 NTSTATUS status, result; 261 301 WERROR werr; 262 302 struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; 263 303 struct dom_sid2 *domain_sid = NULL; 304 struct dcerpc_binding_handle *b = NULL; 264 305 265 306 if (!r->in.group_name) { … … 278 319 goto done; 279 320 } 321 322 b = pipe_cli->binding_handle; 280 323 281 324 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, … … 332 375 333 376 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); 336 380 if (!NT_STATUS_IS_OK(status)) { 337 381 werr = ntstatus_to_werror(status); 382 goto done; 383 } 384 if (!NT_STATUS_IS_OK(result)) { 385 werr = ntstatus_to_werror(result); 338 386 goto done; 339 387 } … … 345 393 done: 346 394 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); 348 396 } 349 397 … … 419 467 { 420 468 struct rpc_pipe_client *pipe_cli = NULL; 421 NTSTATUS status ;469 NTSTATUS status, result; 422 470 WERROR werr; 423 471 struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; … … 425 473 union samr_AliasInfo *alias_info = NULL; 426 474 uint32_t entries_read = 0; 475 struct dcerpc_binding_handle *b = NULL; 427 476 428 477 if (!r->in.group_name) { … … 450 499 goto done; 451 500 } 501 502 b = pipe_cli->binding_handle; 452 503 453 504 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, … … 503 554 504 555 query_alias: 505 status = rpccli_samr_QueryAliasInfo(pipe_cli, talloc_tos(),556 status = dcerpc_samr_QueryAliasInfo(b, talloc_tos(), 506 557 &alias_handle, 507 558 ALIASINFOALL, 508 &alias_info); 559 &alias_info, 560 &result); 509 561 if (!NT_STATUS_IS_OK(status)) { 510 562 werr = ntstatus_to_werror(status); 563 goto done; 564 } 565 if (!NT_STATUS_IS_OK(result)) { 566 werr = ntstatus_to_werror(result); 511 567 goto done; 512 568 } … … 520 576 done: 521 577 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); 523 579 } 524 580 … … 589 645 { 590 646 struct rpc_pipe_client *pipe_cli = NULL; 591 NTSTATUS status ;647 NTSTATUS status, result; 592 648 WERROR werr; 593 649 struct lsa_String lsa_account_name; … … 596 652 enum samr_AliasInfoEnum alias_level = 0; 597 653 union samr_AliasInfo *alias_info = NULL; 654 struct dcerpc_binding_handle *b = NULL; 598 655 599 656 if (!r->in.group_name) { … … 621 678 goto done; 622 679 } 680 681 b = pipe_cli->binding_handle; 623 682 624 683 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, … … 681 740 } 682 741 683 status = rpccli_samr_SetAliasInfo(pipe_cli, talloc_tos(),742 status = dcerpc_samr_SetAliasInfo(b, talloc_tos(), 684 743 &alias_handle, 685 744 alias_level, 686 alias_info); 745 alias_info, 746 &result); 687 747 if (!NT_STATUS_IS_OK(status)) { 688 748 werr = ntstatus_to_werror(status); 749 goto done; 750 } 751 if (!NT_STATUS_IS_OK(result)) { 752 werr = ntstatus_to_werror(result); 689 753 goto done; 690 754 } … … 694 758 done: 695 759 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); 697 761 } 698 762 … … 722 786 { 723 787 struct rpc_pipe_client *pipe_cli = NULL; 724 NTSTATUS status ;788 NTSTATUS status, result; 725 789 WERROR werr; 726 790 struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle; … … 732 796 struct samr_SamArray *builtin_sam_array = NULL; 733 797 int i; 798 struct dcerpc_binding_handle *b = NULL; 734 799 735 800 if (!r->out.buffer) { … … 763 828 goto done; 764 829 } 830 831 b = pipe_cli->binding_handle; 765 832 766 833 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, … … 789 856 } 790 857 791 status = rpccli_samr_QueryDomainInfo(pipe_cli, talloc_tos(),858 status = dcerpc_samr_QueryDomainInfo(b, talloc_tos(), 792 859 &builtin_handle, 793 860 2, 794 &builtin_info); 861 &builtin_info, 862 &result); 795 863 if (!NT_STATUS_IS_OK(status)) { 796 864 werr = ntstatus_to_werror(status); 865 goto done; 866 } 867 if (!NT_STATUS_IS_OK(result)) { 868 werr = ntstatus_to_werror(result); 797 869 goto done; 798 870 } … … 802 874 } 803 875 804 status = rpccli_samr_QueryDomainInfo(pipe_cli, talloc_tos(),876 status = dcerpc_samr_QueryDomainInfo(b, talloc_tos(), 805 877 &domain_handle, 806 878 2, 807 &domain_info); 879 &domain_info, 880 &result); 808 881 if (!NT_STATUS_IS_OK(status)) { 809 882 werr = ntstatus_to_werror(status); 883 goto done; 884 } 885 if (!NT_STATUS_IS_OK(result)) { 886 werr = ntstatus_to_werror(result); 810 887 goto done; 811 888 } … … 815 892 } 816 893 817 status = rpccli_samr_EnumDomainAliases(pipe_cli, talloc_tos(),894 status = dcerpc_samr_EnumDomainAliases(b, talloc_tos(), 818 895 &builtin_handle, 819 896 r->in.resume_handle, 820 897 &builtin_sam_array, 821 898 r->in.prefmaxlen, 822 &entries_read); 899 &entries_read, 900 &result); 823 901 if (!NT_STATUS_IS_OK(status)) { 824 902 werr = ntstatus_to_werror(status); 903 goto done; 904 } 905 if (!NT_STATUS_IS_OK(result)) { 906 werr = ntstatus_to_werror(result); 825 907 goto done; 826 908 } … … 851 933 } 852 934 853 status = rpccli_samr_EnumDomainAliases(pipe_cli, talloc_tos(),935 status = dcerpc_samr_EnumDomainAliases(b, talloc_tos(), 854 936 &domain_handle, 855 937 r->in.resume_handle, 856 938 &domain_sam_array, 857 939 r->in.prefmaxlen, 858 &entries_read); 940 &entries_read, 941 &result); 859 942 if (!NT_STATUS_IS_OK(status)) { 860 943 werr = ntstatus_to_werror(status); 944 goto done; 945 } 946 if (!NT_STATUS_IS_OK(result)) { 947 werr = ntstatus_to_werror(result); 861 948 goto done; 862 949 } … … 914 1001 struct dom_sid *sid) 915 1002 { 916 NTSTATUS status ;1003 NTSTATUS status, result; 917 1004 struct policy_handle lsa_handle; 1005 struct dcerpc_binding_handle *b = lsa_pipe->binding_handle; 918 1006 919 1007 struct lsa_RefDomainList *domains = NULL; … … 934 1022 status = rpccli_lsa_open_policy2(lsa_pipe, mem_ctx, 935 1023 false, 936 S TD_RIGHT_READ_CONTROL_ACCESS|1024 SEC_STD_READ_CONTROL | 937 1025 LSA_POLICY_VIEW_LOCAL_INFORMATION | 938 1026 LSA_POLICY_LOOKUP_NAMES, … … 940 1028 NT_STATUS_NOT_OK_RETURN(status); 941 1029 942 status = rpccli_lsa_LookupNames3(lsa_pipe, mem_ctx,1030 status = dcerpc_lsa_LookupNames3(b, mem_ctx, 943 1031 &lsa_handle, 944 1032 num_names, … … 948 1036 LSA_LOOKUP_NAMES_ALL, /* sure ? */ 949 1037 &count, 950 0, 0); 1038 0, 0, 1039 &result); 951 1040 NT_STATUS_NOT_OK_RETURN(status); 1041 NT_STATUS_NOT_OK_RETURN(result); 952 1042 953 1043 if (count != 1 || sids.count != 1) { … … 972 1062 struct rpc_pipe_client *pipe_cli = NULL; 973 1063 struct rpc_pipe_client *lsa_pipe = NULL; 974 NTSTATUS status ;1064 NTSTATUS status, result; 975 1065 WERROR werr; 976 1066 struct lsa_String lsa_account_name; … … 985 1075 struct dom_sid *add_sids = NULL; 986 1076 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; 989 1080 990 1081 if ((!add && !del && !set) || (add && del && set)) { … … 1069 1160 goto done; 1070 1161 } 1162 1163 b = pipe_cli->binding_handle; 1071 1164 1072 1165 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, … … 1157 1250 struct lsa_SidArray current_sids; 1158 1251 1159 status = rpccli_samr_GetMembersInAlias(pipe_cli, talloc_tos(),1252 status = dcerpc_samr_GetMembersInAlias(b, talloc_tos(), 1160 1253 &alias_handle, 1161 ¤t_sids); 1254 ¤t_sids, 1255 &result); 1162 1256 if (!NT_STATUS_IS_OK(status)) { 1163 1257 werr = ntstatus_to_werror(status); 1164 1258 goto done; 1165 1259 } 1260 if (!NT_STATUS_IS_OK(result)) { 1261 werr = ntstatus_to_werror(result); 1262 goto done; 1263 } 1166 1264 1167 1265 /* add list */ … … 1170 1268 bool already_member = false; 1171 1269 for (k=0; k < current_sids.num_sids; k++) { 1172 if ( sid_equal(&member_sids[i],1270 if (dom_sid_equal(&member_sids[i], 1173 1271 current_sids.sids[k].sid)) { 1174 1272 already_member = true; … … 1192 1290 bool keep_member = false; 1193 1291 for (i=0; i < r->in.total_entries; i++) { 1194 if ( sid_equal(&member_sids[i],1292 if (dom_sid_equal(&member_sids[i], 1195 1293 current_sids.sids[k].sid)) { 1196 1294 keep_member = true; … … 1213 1311 1214 1312 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(), 1216 1314 &alias_handle, 1217 &add_sids[i]); 1315 &add_sids[i], 1316 &result); 1218 1317 if (!NT_STATUS_IS_OK(status)) { 1219 1318 werr = ntstatus_to_werror(status); 1220 1319 goto done; 1221 1320 } 1321 if (!NT_STATUS_IS_OK(result)) { 1322 werr = ntstatus_to_werror(result); 1323 goto done; 1324 } 1222 1325 } 1223 1326 … … 1225 1328 1226 1329 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(), 1228 1331 &alias_handle, 1229 &del_sids[i]); 1332 &del_sids[i], 1333 &result); 1230 1334 if (!NT_STATUS_IS_OK(status)) { 1231 1335 werr = ntstatus_to_werror(status); 1232 1336 goto done; 1233 1337 } 1338 if (!NT_STATUS_IS_OK(result)) { 1339 werr = ntstatus_to_werror(result); 1340 goto done; 1341 } 1234 1342 } 1235 1343 … … 1237 1345 1238 1346 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); 1241 1349 } 1242 1350 -
trunk/server/source3/lib/netapi/netapi.c
r414 r745 21 21 #include "lib/netapi/netapi.h" 22 22 #include "lib/netapi/netapi_private.h" 23 24 extern bool AllowDebugChange; 23 #include "secrets.h" 24 #include "krb5_env.h" 25 25 26 26 struct libnetapi_ctx *stat_ctx = NULL; … … 50 50 51 51 /**************************************************************** 52 Create a libnetapi context, for use in non-Samba applications. This 53 loads the smb.conf file and sets the debug level to 0, so that 54 applications are not flooded with debug logs at level 10, when they 55 were not expecting it. 52 56 ****************************************************************/ 53 57 54 58 NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) 55 59 { 56 NET_API_STATUS status;57 struct libnetapi_ctx *ctx = NULL;58 char *krb5_cc_env = NULL;59 60 60 if (stat_ctx && libnetapi_initialized) { 61 61 *context = stat_ctx; … … 68 68 frame = talloc_stackframe(); 69 69 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); 89 78 90 79 if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { … … 94 83 } 95 84 96 AllowDebugChange = true;97 98 85 init_names(); 99 86 load_interfaces(); 100 87 reopen_logs(); 88 89 BlockSignals(True, SIGPIPE); 90 91 return libnetapi_net_init(context); 92 } 93 94 /**************************************************************** 95 Create a libnetapi context, for use inside the 'net' binary. 96 97 As we know net has already loaded the smb.conf file, and set the debug 98 level etc, this avoids doing so again (which causes trouble with -d on 99 the command line). 100 ****************************************************************/ 101 102 NET_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 } 101 115 102 116 BlockSignals(True, SIGPIPE); … … 133 147 134 148 /**************************************************************** 149 Return the static libnetapi context 135 150 ****************************************************************/ 136 151 … … 146 161 147 162 /**************************************************************** 163 Free the static libnetapi context 148 164 ****************************************************************/ 149 165 … … 182 198 183 199 /**************************************************************** 200 Override the current log level for libnetapi 184 201 ****************************************************************/ 185 202 … … 187 204 const char *debuglevel) 188 205 { 189 AllowDebugChange = true;190 206 ctx->debuglevel = talloc_strdup(ctx, debuglevel); 191 if (! debug_parse_levels(debuglevel)) {207 if (!lp_set_cmdline("log level", debuglevel)) { 192 208 return W_ERROR_V(WERR_GENERAL_FAILURE); 193 209 } -
trunk/server/source3/lib/netapi/netapi.h
r414 r745 1285 1285 }; 1286 1286 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 1287 1303 #endif /* _HEADER_libnetapi */ 1288 1304 … … 1306 1322 #define NETLOGON_CONTROL_BREAKPOINT ( 0x0000FFFF ) 1307 1323 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 1308 1345 #endif /* _HEADER_netlogon */ 1309 1346 -
trunk/server/source3/lib/netapi/netapi_private.h
r590 r745 21 21 #define __LIB_NETAPI_PRIVATE_H__ 22 22 23 #include "lib/netapi/netapi_net.h" 24 23 25 #define LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, fn) \ 24 26 DEBUG(10,("redirecting call %s to localhost\n", #fn)); \ … … 27 29 } \ 28 30 return fn ## _r(ctx, r); 31 32 struct dcerpc_binding_handle; 29 33 30 34 struct libnetapi_private_ctx { … … 45 49 46 50 struct client_ipc_connection *ipc_connections; 51 52 struct messaging_context *msg_ctx; 47 53 }; 48 54 … … 57 63 const struct ndr_syntax_id *interface, 58 64 struct rpc_pipe_client **presult); 65 WERROR 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); 59 69 WERROR libnetapi_samr_open_domain(struct libnetapi_ctx *mem_ctx, 60 70 struct rpc_pipe_client *pipe_cli, -
trunk/server/source3/lib/netapi/netlogon.c
r596 r745 20 20 #include "includes.h" 21 21 22 #include "../librpc/gen_ndr/ndr_netlogon_c.h" 22 23 #include "librpc/gen_ndr/libnetapi.h" 23 24 #include "lib/netapi/netapi.h" 24 25 #include "lib/netapi/netapi_private.h" 25 26 #include "lib/netapi/libnetapi.h" 26 #include "../librpc/gen_ndr/cli_netlogon.h"27 27 28 28 static WERROR construct_data(enum netr_LogonControlCode function_code, … … 44 44 data_out->debug_level = atoi((const char *)data_in); 45 45 break; 46 case NETLOGON_CONTROL_FORCE_DNS_REG: 47 ZERO_STRUCTP(data_out); 48 break; 46 49 default: 47 50 return WERR_INVALID_PARAM; … … 127 130 WERROR werr; 128 131 NTSTATUS status; 129 struct rpc_pipe_client *pipe_cli = NULL;130 132 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(), 140 143 r->in.server_name, 141 144 r->in.function_code, … … 147 150 goto done; 148 151 } 152 if (!W_ERROR_IS_OK(werr)) { 153 goto done; 154 } 149 155 150 156 werr = construct_buffer(ctx, r->in.query_level, &query, … … 175 181 WERROR werr; 176 182 NTSTATUS status; 177 struct rpc_pipe_client *pipe_cli = NULL;178 183 union netr_CONTROL_DATA_INFORMATION data; 179 184 union netr_CONTROL_QUERY_INFORMATION query; 185 struct dcerpc_binding_handle *b; 180 186 181 187 werr = construct_data(r->in.function_code, r->in.data, &data); … … 184 190 } 185 191 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); 189 195 if (!W_ERROR_IS_OK(werr)) { 190 196 goto done; … … 194 200 case NETLOGON_CONTROL_TC_VERIFY: 195 201 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(), 197 204 r->in.server_name, 198 205 r->in.function_code, … … 203 210 break; 204 211 default: 205 status = rpccli_netr_LogonControl2(pipe_cli, talloc_tos(),212 status = dcerpc_netr_LogonControl2(b, talloc_tos(), 206 213 r->in.server_name, 207 214 r->in.function_code, … … 213 220 } 214 221 215 if (!W_ERROR_IS_OK(werr)) {216 goto done;217 }218 219 222 if (!NT_STATUS_IS_OK(status)) { 220 223 werr = ntstatus_to_werror(status); … … 222 225 } 223 226 227 if (!W_ERROR_IS_OK(werr)) { 228 goto done; 229 } 230 224 231 werr = construct_buffer(ctx, r->in.query_level, &query, 225 232 r->out.buffer); -
trunk/server/source3/lib/netapi/samr.c
r414 r745 21 21 #include "lib/netapi/netapi.h" 22 22 #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" 24 28 25 29 /**************************************************************** … … 34 38 struct dom_sid2 **domain_sid) 35 39 { 36 NTSTATUS status ;40 NTSTATUS status, result; 37 41 WERROR werr; 38 42 struct libnetapi_private_ctx *priv; … … 44 48 bool domain_found = true; 45 49 int i; 50 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 46 51 47 52 priv = talloc_get_type_abort(mem_ctx->private_data, … … 78 83 79 84 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, 81 87 connect_mask, 82 connect_handle); 88 connect_handle, 89 &result); 83 90 if (!NT_STATUS_IS_OK(status)) { 84 91 werr = ntstatus_to_werror(status); 85 92 goto done; 86 93 } 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, 90 101 connect_handle, 91 102 &resume_handle, 92 103 &sam, 93 104 0xffffffff, 94 &num_entries); 105 &num_entries, 106 &result); 95 107 if (!NT_STATUS_IS_OK(status)) { 96 108 werr = ntstatus_to_werror(status); 97 109 goto done; 98 110 } 111 if (!NT_STATUS_IS_OK(result)) { 112 werr = ntstatus_to_werror(result); 113 goto done; 114 } 99 115 100 116 for (i=0; i<num_entries; i++) { … … 117 133 init_lsa_String(&lsa_domain_name, domain_name); 118 134 119 status = rpccli_samr_LookupDomain(pipe_cli, mem_ctx,135 status = dcerpc_samr_LookupDomain(b, mem_ctx, 120 136 connect_handle, 121 137 &lsa_domain_name, 122 domain_sid); 138 domain_sid, 139 &result); 123 140 if (!NT_STATUS_IS_OK(status)) { 124 141 werr = ntstatus_to_werror(status); 125 142 goto done; 126 143 } 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, 129 150 connect_handle, 130 151 domain_mask, 131 152 *domain_sid, 132 domain_handle); 153 domain_handle, 154 &result); 133 155 if (!NT_STATUS_IS_OK(status)) { 134 156 werr = ntstatus_to_werror(status); 157 goto done; 158 } 159 if (!NT_STATUS_IS_OK(result)) { 160 werr = ntstatus_to_werror(result); 135 161 goto done; 136 162 } … … 163 189 struct policy_handle *builtin_handle) 164 190 { 165 NTSTATUS status ;191 NTSTATUS status, result; 166 192 WERROR werr; 167 193 struct libnetapi_private_ctx *priv; 194 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 168 195 169 196 priv = talloc_get_type_abort(mem_ctx->private_data, … … 196 223 197 224 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, 199 227 connect_mask, 200 connect_handle); 228 connect_handle, 229 &result); 201 230 if (!NT_STATUS_IS_OK(status)) { 202 231 werr = ntstatus_to_werror(status); 203 232 goto done; 204 233 } 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, 208 241 connect_handle, 209 242 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); 212 246 if (!NT_STATUS_IS_OK(status)) { 213 247 werr = ntstatus_to_werror(status); 214 248 goto done; 215 249 } 250 if (!NT_STATUS_IS_OK(result)) { 251 werr = ntstatus_to_werror(result); 252 goto done; 253 } 216 254 217 255 priv->samr.cli = pipe_cli; … … 236 274 { 237 275 struct libnetapi_private_ctx *priv; 276 struct dcerpc_binding_handle *b; 277 NTSTATUS result; 238 278 239 279 if (!is_valid_policy_hnd(handle)) { … … 244 284 struct libnetapi_private_ctx); 245 285 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); 251 293 252 294 ZERO_STRUCT(priv->samr.domain_handle); … … 260 302 { 261 303 struct libnetapi_private_ctx *priv; 304 struct dcerpc_binding_handle *b; 305 NTSTATUS result; 262 306 263 307 if (!is_valid_policy_hnd(handle)) { … … 268 312 struct libnetapi_private_ctx); 269 313 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); 275 321 276 322 ZERO_STRUCT(priv->samr.builtin_handle); … … 284 330 { 285 331 struct libnetapi_private_ctx *priv; 332 struct dcerpc_binding_handle *b; 333 NTSTATUS result; 286 334 287 335 if (!is_valid_policy_hnd(handle)) { … … 292 340 struct libnetapi_private_ctx); 293 341 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); 299 349 300 350 ZERO_STRUCT(priv->samr.connect_handle); -
trunk/server/source3/lib/netapi/serverinfo.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #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" 28 29 29 30 /**************************************************************** … … 480 481 struct NetServerGetInfo *r) 481 482 { 482 struct rpc_pipe_client *pipe_cli = NULL;483 483 NTSTATUS status; 484 484 WERROR werr; 485 485 union srvsvc_NetSrvInfo info; 486 struct dcerpc_binding_handle *b; 486 487 487 488 if (!r->out.buffer) { … … 502 503 } 503 504 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); 507 508 if (!W_ERROR_IS_OK(werr)) { 508 509 goto done; 509 510 } 510 511 511 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, talloc_tos(),512 status = dcerpc_srvsvc_NetSrvGetInfo(b, talloc_tos(), 512 513 r->in.server_name, 513 514 r->in.level, … … 519 520 } 520 521 522 if (!W_ERROR_IS_OK(werr)) { 523 goto done; 524 } 525 521 526 status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info, 522 527 r->out.buffer); … … 536 541 struct NetServerSetInfo *r) 537 542 { 538 WERROR werr; 543 WERROR werr = WERR_OK; 544 sbcErr err; 539 545 struct smbconf_ctx *conf_ctx; 540 546 struct srvsvc_NetSrvInfo1005 *info1005; … … 559 565 } 560 566 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", 567 577 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 } 568 585 569 586 done: … … 594 611 struct NetServerSetInfo *r) 595 612 { 596 struct rpc_pipe_client *pipe_cli = NULL;597 613 NTSTATUS status; 598 614 WERROR werr; 599 615 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); 604 621 if (!W_ERROR_IS_OK(werr)) { 605 622 goto done; … … 615 632 } 616 633 617 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, talloc_tos(),634 status = dcerpc_srvsvc_NetSrvSetInfo(b, talloc_tos(), 618 635 r->in.server_name, 619 636 r->in.level, … … 636 653 struct NetRemoteTOD *r) 637 654 { 638 struct rpc_pipe_client *pipe_cli = NULL;639 655 NTSTATUS status; 640 656 WERROR werr; 641 657 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); 646 663 if (!W_ERROR_IS_OK(werr)) { 647 664 goto done; 648 665 } 649 666 650 status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, talloc_tos(),667 status = dcerpc_srvsvc_NetRemoteTOD(b, talloc_tos(), 651 668 r->in.server_name, 652 669 &info, … … 657 674 } 658 675 676 if (!W_ERROR_IS_OK(werr)) { 677 goto done; 678 } 679 659 680 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info, 660 681 sizeof(struct srvsvc_NetRemoteTODInfo)); -
trunk/server/source3/lib/netapi/share.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #include "lib/netapi/libnetapi.h" 26 #include "../librpc/gen_ndr/ cli_srvsvc.h"26 #include "../librpc/gen_ndr/ndr_srvsvc_c.h" 27 27 28 28 /**************************************************************** … … 183 183 WERROR werr; 184 184 NTSTATUS status; 185 struct rpc_pipe_client *pipe_cli = NULL;186 185 union srvsvc_NetShareInfo info; 186 struct dcerpc_binding_handle *b; 187 187 188 188 if (!r->in.buffer) { … … 200 200 } 201 201 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); 205 205 if (!W_ERROR_IS_OK(werr)) { 206 206 goto done; … … 216 216 } 217 217 218 status = rpccli_srvsvc_NetShareAdd(pipe_cli, talloc_tos(),218 status = dcerpc_srvsvc_NetShareAdd(b, talloc_tos(), 219 219 r->in.server_name, 220 220 r->in.level, … … 222 222 r->out.parm_err, 223 223 &werr); 224 if (!NT_STATUS_IS_OK(status)) { 225 werr = ntstatus_to_werror(status); 226 goto done; 227 } 228 224 229 if (!W_ERROR_IS_OK(werr)) { 225 230 goto done; … … 247 252 WERROR werr; 248 253 NTSTATUS status; 249 struct rpc_pipe_client *pipe_cli = NULL;254 struct dcerpc_binding_handle *b; 250 255 251 256 if (!r->in.net_name) { … … 253 258 } 254 259 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(), 263 268 r->in.server_name, 264 269 r->in.net_name, … … 291 296 WERROR werr; 292 297 NTSTATUS status; 293 struct rpc_pipe_client *pipe_cli = NULL;294 298 struct srvsvc_NetShareInfoCtr info_ctr; 295 299 struct srvsvc_NetShareCtr0 ctr0; … … 297 301 struct srvsvc_NetShareCtr2 ctr2; 298 302 uint32_t i; 303 struct dcerpc_binding_handle *b; 299 304 300 305 if (!r->out.buffer) { … … 316 321 ZERO_STRUCT(info_ctr); 317 322 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); 321 326 if (!W_ERROR_IS_OK(werr)) { 322 327 goto done; … … 339 344 } 340 345 341 status = rpccli_srvsvc_NetShareEnumAll(pipe_cli, talloc_tos(),346 status = dcerpc_srvsvc_NetShareEnumAll(b, talloc_tos(), 342 347 r->in.server_name, 343 348 &info_ctr, … … 346 351 r->out.resume_handle, 347 352 &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)) { 349 359 goto done; 350 360 } … … 371 381 if (!NT_STATUS_IS_OK(status)) { 372 382 werr = ntstatus_to_werror(status); 383 goto done; 373 384 } 374 385 } … … 395 406 WERROR werr; 396 407 NTSTATUS status; 397 struct rpc_pipe_client *pipe_cli = NULL;398 408 union srvsvc_NetShareInfo info; 399 409 uint32_t num_entries = 0; 410 struct dcerpc_binding_handle *b; 400 411 401 412 if (!r->in.net_name || !r->out.buffer) { … … 417 428 } 418 429 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(), 427 438 r->in.server_name, 428 439 r->in.net_name, … … 430 441 &info, 431 442 &werr); 443 if (!NT_STATUS_IS_OK(status)) { 444 werr = ntstatus_to_werror(status); 445 goto done; 446 } 432 447 433 448 if (!W_ERROR_IS_OK(werr)) { … … 465 480 WERROR werr; 466 481 NTSTATUS status; 467 struct rpc_pipe_client *pipe_cli = NULL;468 482 union srvsvc_NetShareInfo info; 483 struct dcerpc_binding_handle *b; 469 484 470 485 if (!r->in.buffer) { … … 487 502 } 488 503 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); 492 507 if (!W_ERROR_IS_OK(werr)) { 493 508 goto done; … … 503 518 } 504 519 505 status = rpccli_srvsvc_NetShareSetInfo(pipe_cli, talloc_tos(),520 status = dcerpc_srvsvc_NetShareSetInfo(b, talloc_tos(), 506 521 r->in.server_name, 507 522 r->in.net_name, … … 510 525 r->out.parm_err, 511 526 &werr); 527 if (!NT_STATUS_IS_OK(status)) { 528 werr = ntstatus_to_werror(status); 529 goto done; 530 } 531 512 532 if (!W_ERROR_IS_OK(werr)) { 513 533 goto done; -
trunk/server/source3/lib/netapi/shutdown.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #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" 27 28 28 29 /**************************************************************** … … 34 35 WERROR werr; 35 36 NTSTATUS status; 36 struct rpc_pipe_client *pipe_cli = NULL;37 37 struct lsa_StringLarge message; 38 struct dcerpc_binding_handle *b; 38 39 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); 42 43 if (!W_ERROR_IS_OK(werr)) { 43 44 goto done; … … 46 47 init_lsa_StringLarge(&message, r->in.message); 47 48 48 status = rpccli_initshutdown_Init(pipe_cli, talloc_tos(),49 status = dcerpc_initshutdown_Init(b, talloc_tos(), 49 50 NULL, 50 51 &message, … … 79 80 WERROR werr; 80 81 NTSTATUS status; 81 struct rpc_pipe_client *pipe_cli = NULL;82 struct dcerpc_binding_handle *b; 82 83 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); 86 87 if (!W_ERROR_IS_OK(werr)) { 87 88 goto done; 88 89 } 89 90 90 status = rpccli_initshutdown_Abort(pipe_cli, talloc_tos(),91 status = dcerpc_initshutdown_Abort(b, talloc_tos(), 91 92 NULL, 92 93 &werr); -
trunk/server/source3/lib/netapi/sid.c
r414 r745 21 21 22 22 #include "lib/netapi/netapi.h" 23 #include "../libcli/security/security.h" 23 24 24 25 /**************************************************************** -
trunk/server/source3/lib/netapi/user.c
r596 r745 24 24 #include "lib/netapi/netapi_private.h" 25 25 #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" 27 33 28 34 /**************************************************************** … … 109 115 info21->lm_owf_password = zero_parameters; 110 116 info21->nt_owf_password = zero_parameters; 111 info21-> unknown3.string= NULL;117 info21->private_data.string = NULL; 112 118 info21->buf_count = 0; 113 119 info21->buffer = NULL; … … 124 130 info21->nt_password_set = 0; 125 131 info21->password_expired = infoX->usriX_password_expired; 126 info21-> unknown4= 0;132 info21->private_data_sensitive = 0; 127 133 } 128 134 … … 293 299 union samr_UserInfo user_info; 294 300 struct samr_UserInfo21 info21; 295 NTSTATUS status; 301 NTSTATUS status, result; 302 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 296 303 297 304 if (!uX) { … … 311 318 &user_info.info25.password); 312 319 313 status = rpccli_samr_SetUserInfo2(pipe_cli, talloc_tos(),320 status = dcerpc_samr_SetUserInfo2(b, talloc_tos(), 314 321 user_handle, 315 322 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)) { 319 326 320 327 user_info.info23.info = info21; … … 324 331 &user_info.info23.password); 325 332 326 status = rpccli_samr_SetUserInfo2(pipe_cli, talloc_tos(),333 status = dcerpc_samr_SetUserInfo2(b, talloc_tos(), 327 334 user_handle, 328 335 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; 330 345 } 331 346 } else { … … 333 348 user_info.info21 = info21; 334 349 335 status = rpccli_samr_SetUserInfo(pipe_cli, talloc_tos(),350 status = dcerpc_samr_SetUserInfo(b, talloc_tos(), 336 351 user_handle, 337 352 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; 342 361 } 343 362 … … 349 368 { 350 369 struct rpc_pipe_client *pipe_cli = NULL; 351 NTSTATUS status ;370 NTSTATUS status, result; 352 371 WERROR werr; 353 372 struct policy_handle connect_handle, domain_handle, user_handle; … … 359 378 uint32_t rid = 0; 360 379 struct USER_INFO_X uX; 380 struct dcerpc_binding_handle *b = NULL; 381 DATA_BLOB session_key; 361 382 362 383 ZERO_STRUCT(connect_handle); … … 385 406 goto done; 386 407 } 408 409 b = pipe_cli->binding_handle; 387 410 388 411 status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX); … … 407 430 init_lsa_String(&lsa_account_name, uX.usriX_name); 408 431 409 status = rpccli_samr_CreateUser2(pipe_cli, talloc_tos(),432 status = dcerpc_samr_CreateUser2(b, talloc_tos(), 410 433 &domain_handle, 411 434 &lsa_account_name, … … 418 441 &user_handle, 419 442 &access_granted, 420 &rid); 443 &rid, 444 &result); 421 445 if (!NT_STATUS_IS_OK(status)) { 422 446 werr = ntstatus_to_werror(status); 423 447 goto done; 424 448 } 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(), 427 455 &user_handle, 428 456 16, 429 &user_info); 457 &user_info, 458 &result); 430 459 if (!NT_STATUS_IS_OK(status)) { 431 460 werr = ntstatus_to_werror(status); 461 goto done; 462 } 463 if (!NT_STATUS_IS_OK(result)) { 464 werr = ntstatus_to_werror(result); 432 465 goto done; 433 466 } … … 438 471 } 439 472 440 status = rpccli_samr_GetUserPwInfo(pipe_cli, talloc_tos(),473 status = dcerpc_samr_GetUserPwInfo(b, talloc_tos(), 441 474 &user_handle, 442 &pw_info); 475 &pw_info, 476 &result); 443 477 if (!NT_STATUS_IS_OK(status)) { 444 478 werr = ntstatus_to_werror(status); 445 479 goto done; 446 480 } 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 } 447 491 448 492 uX.usriX_flags |= ACB_NORMAL; 449 493 450 494 status = set_user_info_USER_INFO_X(ctx, pipe_cli, 451 & pipe_cli->auth->user_session_key,495 &session_key, 452 496 &user_handle, 453 497 &uX); … … 461 505 462 506 failed: 463 rpccli_samr_DeleteUser(pipe_cli, talloc_tos(), 464 &user_handle); 507 dcerpc_samr_DeleteUser(b, talloc_tos(), 508 &user_handle, 509 &result); 465 510 466 511 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); 469 514 } 470 515 … … 493 538 { 494 539 struct rpc_pipe_client *pipe_cli = NULL; 495 NTSTATUS status ;540 NTSTATUS status, result; 496 541 WERROR werr; 497 542 struct policy_handle connect_handle, builtin_handle, domain_handle, user_handle; … … 500 545 struct dom_sid2 *domain_sid = NULL; 501 546 struct dom_sid2 user_sid; 547 struct dcerpc_binding_handle *b = NULL; 502 548 503 549 ZERO_STRUCT(connect_handle); … … 513 559 goto done; 514 560 } 561 562 b = pipe_cli->binding_handle; 515 563 516 564 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 525 573 } 526 574 527 status = rpccli_samr_OpenDomain(pipe_cli, talloc_tos(),575 status = dcerpc_samr_OpenDomain(b, talloc_tos(), 528 576 &connect_handle, 529 577 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); 532 581 if (!NT_STATUS_IS_OK(status)) { 533 582 werr = ntstatus_to_werror(status); 534 583 goto done; 535 584 } 585 if (!NT_STATUS_IS_OK(result)) { 586 werr = ntstatus_to_werror(result); 587 goto done; 588 } 536 589 537 590 init_lsa_String(&lsa_account_name, r->in.user_name); 538 591 539 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),592 status = dcerpc_samr_LookupNames(b, talloc_tos(), 540 593 &domain_handle, 541 594 1, 542 595 &lsa_account_name, 543 596 &user_rids, 544 &name_types); 597 &name_types, 598 &result); 545 599 if (!NT_STATUS_IS_OK(status)) { 546 600 werr = ntstatus_to_werror(status); 547 601 goto done; 548 602 } 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(), 551 609 &domain_handle, 552 610 SEC_STD_DELETE, 553 611 user_rids.ids[0], 554 &user_handle); 612 &user_handle, 613 &result); 555 614 if (!NT_STATUS_IS_OK(status)) { 556 615 werr = ntstatus_to_werror(status); 557 616 goto done; 558 617 } 618 if (!NT_STATUS_IS_OK(result)) { 619 werr = ntstatus_to_werror(result); 620 goto done; 621 } 559 622 560 623 sid_compose(&user_sid, domain_sid, user_rids.ids[0]); 561 624 562 status = rpccli_samr_RemoveMemberFromForeignDomain(pipe_cli, talloc_tos(),625 status = dcerpc_samr_RemoveMemberFromForeignDomain(b, talloc_tos(), 563 626 &builtin_handle, 564 &user_sid); 627 &user_sid, 628 &result); 565 629 if (!NT_STATUS_IS_OK(status)) { 566 630 werr = ntstatus_to_werror(status); 567 631 goto done; 568 632 } 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); 572 641 if (!NT_STATUS_IS_OK(status)) { 573 642 werr = ntstatus_to_werror(status); 643 goto done; 644 } 645 if (!NT_STATUS_IS_OK(result)) { 646 werr = ntstatus_to_werror(result); 574 647 goto done; 575 648 } … … 579 652 done: 580 653 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); 582 655 } 583 656 … … 615 688 uint32_t *auth_flag_p) 616 689 { 617 NTSTATUS status ;690 NTSTATUS status, result; 618 691 619 692 struct policy_handle user_handle; … … 623 696 SAMR_USER_ACCESS_GET_ATTRIBUTES | 624 697 SAMR_USER_ACCESS_GET_NAME_ETC; 698 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 625 699 626 700 ZERO_STRUCT(user_handle); … … 653 727 } 654 728 655 status = rpccli_samr_OpenUser(pipe_cli, mem_ctx,729 status = dcerpc_samr_OpenUser(b, mem_ctx, 656 730 domain_handle, 657 731 access_mask, 658 732 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, 665 744 &user_handle, 666 745 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, 673 757 &user_handle, 674 758 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; 677 766 goto done; 678 767 } … … 686 775 struct dom_sid sid; 687 776 688 status = rpccli_samr_GetGroupsForUser(pipe_cli, mem_ctx,777 status = dcerpc_samr_GetGroupsForUser(b, mem_ctx, 689 778 &user_handle, 690 &rid_array); 779 &rid_array, 780 &result); 691 781 if (!NT_STATUS_IS_OK(status)) { 782 goto done; 783 } 784 if (!NT_STATUS_IS_OK(result)) { 785 status = result; 692 786 goto done; 693 787 } … … 700 794 for (i=0; i<rid_array->count; i++) { 701 795 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); 703 797 NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid); 704 798 } 705 799 706 800 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); 708 802 NT_STATUS_HAVE_NO_MEMORY(sid_array.sids[i].sid); 709 803 710 status = rpccli_samr_GetAliasMembership(pipe_cli, mem_ctx,804 status = dcerpc_samr_GetAliasMembership(b, mem_ctx, 711 805 builtin_handle, 712 806 &sid_array, 713 &alias_rids); 807 &alias_rids, 808 &result); 714 809 if (!NT_STATUS_IS_OK(status)) { 810 goto done; 811 } 812 if (!NT_STATUS_IS_OK(result)) { 813 status = result; 715 814 goto done; 716 815 } … … 741 840 done: 742 841 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); 744 843 } 745 844 … … 918 1017 return NT_STATUS_NO_MEMORY; 919 1018 } 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); 921 1020 i->usri4_primary_group_id = i21->primary_gid; 922 1021 i->usri4_profile = talloc_strdup(mem_ctx, i21->profile_path.string); … … 1019 1118 return NT_STATUS_NO_MEMORY; 1020 1119 } 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); 1022 1121 1023 1122 return NT_STATUS_OK; … … 1185 1284 1186 1285 NTSTATUS status = NT_STATUS_OK; 1286 NTSTATUS result = NT_STATUS_OK; 1187 1287 WERROR werr; 1288 struct dcerpc_binding_handle *b = NULL; 1188 1289 1189 1290 ZERO_STRUCT(connect_handle); … … 1220 1321 } 1221 1322 1323 b = pipe_cli->binding_handle; 1324 1222 1325 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli, 1223 1326 SAMR_ACCESS_ENUM_DOMAINS | … … 1264 1367 } 1265 1368 1266 status = rpccli_samr_EnumDomainUsers(pipe_cli,1369 status = dcerpc_samr_EnumDomainUsers(b, 1267 1370 ctx, 1268 1371 &domain_handle, … … 1271 1374 &sam, 1272 1375 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)) { 1276 1384 goto done; 1277 1385 } … … 1296 1404 done: 1297 1405 /* 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)) { 1300 1408 1301 1409 if (ctx->disable_policy_handle_cache) { … … 1490 1598 struct policy_handle domain_handle; 1491 1599 union samr_DispInfo info; 1600 struct dcerpc_binding_handle *b = NULL; 1492 1601 1493 1602 uint32_t total_size = 0; … … 1495 1604 1496 1605 NTSTATUS status = NT_STATUS_OK; 1606 NTSTATUS result = NT_STATUS_OK; 1497 1607 WERROR werr; 1498 1608 WERROR werr_tmp; … … 1518 1628 goto done; 1519 1629 } 1630 1631 b = pipe_cli->binding_handle; 1520 1632 1521 1633 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 1532 1644 } 1533 1645 1534 status = rpccli_samr_QueryDisplayInfo2(pipe_cli,1646 status = dcerpc_samr_QueryDisplayInfo2(b, 1535 1647 ctx, 1536 1648 &domain_handle, … … 1541 1653 &total_size, 1542 1654 &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)) { 1546 1663 goto done; 1547 1664 } … … 1556 1673 done: 1557 1674 /* 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)) { 1560 1677 1561 1678 if (ctx->disable_policy_handle_cache) { … … 1604 1721 { 1605 1722 struct rpc_pipe_client *pipe_cli = NULL; 1606 NTSTATUS status ;1723 NTSTATUS status, result; 1607 1724 WERROR werr; 1608 1725 … … 1612 1729 struct samr_Ids user_rids, name_types; 1613 1730 uint32_t num_entries = 0; 1731 struct dcerpc_binding_handle *b = NULL; 1614 1732 1615 1733 ZERO_STRUCT(connect_handle); … … 1645 1763 } 1646 1764 1765 b = pipe_cli->binding_handle; 1766 1647 1767 werr = libnetapi_samr_open_domain(ctx, pipe_cli, 1648 1768 SAMR_ACCESS_ENUM_DOMAINS | … … 1669 1789 init_lsa_String(&lsa_account_name, r->in.user_name); 1670 1790 1671 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1791 status = dcerpc_samr_LookupNames(b, talloc_tos(), 1672 1792 &domain_handle, 1673 1793 1, 1674 1794 &lsa_account_name, 1675 1795 &user_rids, 1676 &name_types); 1796 &name_types, 1797 &result); 1677 1798 if (!NT_STATUS_IS_OK(status)) { 1678 1799 werr = ntstatus_to_werror(status); 1800 goto done; 1801 } 1802 if (!NT_STATUS_IS_OK(result)) { 1803 werr = ntstatus_to_werror(result); 1679 1804 goto done; 1680 1805 } … … 1695 1820 1696 1821 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); 1699 1824 } 1700 1825 … … 1723 1848 { 1724 1849 struct rpc_pipe_client *pipe_cli = NULL; 1725 NTSTATUS status ;1850 NTSTATUS status, result; 1726 1851 WERROR werr; 1727 1852 … … 1733 1858 1734 1859 struct USER_INFO_X uX; 1860 struct dcerpc_binding_handle *b = NULL; 1861 DATA_BLOB session_key; 1735 1862 1736 1863 ZERO_STRUCT(connect_handle); … … 1767 1894 break; 1768 1895 case 3: 1769 user_mask = S TD_RIGHT_READ_CONTROL_ACCESS|1770 S TD_RIGHT_WRITE_DAC_ACCESS|1896 user_mask = SEC_STD_READ_CONTROL | 1897 SEC_STD_WRITE_DAC | 1771 1898 SAMR_USER_ACCESS_GET_GROUPS | 1772 1899 SAMR_USER_ACCESS_SET_PASSWORD | … … 1799 1926 } 1800 1927 1928 b = pipe_cli->binding_handle; 1929 1801 1930 werr = libnetapi_samr_open_domain(ctx, pipe_cli, 1802 1931 SAMR_ACCESS_ENUM_DOMAINS | … … 1824 1953 init_lsa_String(&lsa_account_name, r->in.user_name); 1825 1954 1826 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),1955 status = dcerpc_samr_LookupNames(b, talloc_tos(), 1827 1956 &domain_handle, 1828 1957 1, 1829 1958 &lsa_account_name, 1830 1959 &user_rids, 1831 &name_types); 1960 &name_types, 1961 &result); 1832 1962 if (!NT_STATUS_IS_OK(status)) { 1833 1963 werr = ntstatus_to_werror(status); 1834 1964 goto done; 1835 1965 } 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(), 1838 1972 &domain_handle, 1839 1973 user_mask, 1840 1974 user_rids.ids[0], 1841 &user_handle); 1975 &user_handle, 1976 &result); 1842 1977 if (!NT_STATUS_IS_OK(status)) { 1843 1978 werr = ntstatus_to_werror(status); 1844 1979 goto done; 1845 1980 } 1981 if (!NT_STATUS_IS_OK(result)) { 1982 werr = ntstatus_to_werror(result); 1983 goto done; 1984 } 1846 1985 1847 1986 status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX); … … 1851 1990 } 1852 1991 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 1853 1998 status = set_user_info_USER_INFO_X(ctx, pipe_cli, 1854 & pipe_cli->auth->user_session_key,1999 &session_key, 1855 2000 &user_handle, 1856 2001 &uX); … … 1863 2008 1864 2009 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); 1867 2012 } 1868 2013 … … 1898 2043 struct samr_DomInfo12 *info12) 1899 2044 { 1900 NTSTATUS status ;2045 NTSTATUS status, result; 1901 2046 union samr_DomainInfo *dom_info = NULL; 2047 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 1902 2048 1903 2049 if (info1) { 1904 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,2050 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 1905 2051 domain_handle, 1906 2052 1, 1907 &dom_info); 2053 &dom_info, 2054 &result); 1908 2055 NT_STATUS_NOT_OK_RETURN(status); 2056 NT_STATUS_NOT_OK_RETURN(result); 1909 2057 1910 2058 *info1 = dom_info->info1; … … 1912 2060 1913 2061 if (info3) { 1914 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,2062 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 1915 2063 domain_handle, 1916 2064 3, 1917 &dom_info); 2065 &dom_info, 2066 &result); 1918 2067 NT_STATUS_NOT_OK_RETURN(status); 2068 NT_STATUS_NOT_OK_RETURN(result); 1919 2069 1920 2070 *info3 = dom_info->info3; … … 1922 2072 1923 2073 if (info5) { 1924 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,2074 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 1925 2075 domain_handle, 1926 2076 5, 1927 &dom_info); 2077 &dom_info, 2078 &result); 1928 2079 NT_STATUS_NOT_OK_RETURN(status); 2080 NT_STATUS_NOT_OK_RETURN(result); 1929 2081 1930 2082 *info5 = dom_info->info5; … … 1932 2084 1933 2085 if (info6) { 1934 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,2086 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 1935 2087 domain_handle, 1936 2088 6, 1937 &dom_info); 2089 &dom_info, 2090 &result); 1938 2091 NT_STATUS_NOT_OK_RETURN(status); 2092 NT_STATUS_NOT_OK_RETURN(result); 1939 2093 1940 2094 *info6 = dom_info->info6; … … 1942 2096 1943 2097 if (info7) { 1944 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,2098 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx, 1945 2099 domain_handle, 1946 2100 7, 1947 &dom_info); 2101 &dom_info, 2102 &result); 1948 2103 NT_STATUS_NOT_OK_RETURN(status); 2104 NT_STATUS_NOT_OK_RETURN(result); 1949 2105 1950 2106 *info7 = dom_info->info7; … … 1952 2108 1953 2109 if (info12) { 1954 status = rpccli_samr_QueryDomainInfo2(pipe_cli, mem_ctx,2110 status = dcerpc_samr_QueryDomainInfo2(b, mem_ctx, 1955 2111 domain_handle, 1956 2112 12, 1957 &dom_info); 2113 &dom_info, 2114 &result); 1958 2115 NT_STATUS_NOT_OK_RETURN(status); 2116 NT_STATUS_NOT_OK_RETURN(result); 1959 2117 1960 2118 *info12 = dom_info->info12; … … 2061 2219 talloc_strdup(mem_ctx, dom_info5.domain_name.string); 2062 2220 info2->usrmod2_domain_id = 2063 (struct domsid *) sid_dup_talloc(mem_ctx, domain_sid);2221 (struct domsid *)dom_sid_dup(mem_ctx, domain_sid); 2064 2222 2065 2223 NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_name); … … 2274 2432 struct samr_DomInfo12 *info12) 2275 2433 { 2276 NTSTATUS status ;2434 NTSTATUS status, result; 2277 2435 union samr_DomainInfo dom_info; 2436 struct dcerpc_binding_handle *b = pipe_cli->binding_handle; 2278 2437 2279 2438 if (info1) { … … 2283 2442 dom_info.info1 = *info1; 2284 2443 2285 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,2444 status = dcerpc_samr_SetDomainInfo(b, mem_ctx, 2286 2445 domain_handle, 2287 2446 1, 2288 &dom_info); 2447 &dom_info, 2448 &result); 2289 2449 NT_STATUS_NOT_OK_RETURN(status); 2450 NT_STATUS_NOT_OK_RETURN(result); 2290 2451 } 2291 2452 … … 2296 2457 dom_info.info3 = *info3; 2297 2458 2298 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,2459 status = dcerpc_samr_SetDomainInfo(b, mem_ctx, 2299 2460 domain_handle, 2300 2461 3, 2301 &dom_info); 2462 &dom_info, 2463 &result); 2302 2464 2303 2465 NT_STATUS_NOT_OK_RETURN(status); 2466 NT_STATUS_NOT_OK_RETURN(result); 2304 2467 } 2305 2468 … … 2310 2473 dom_info.info12 = *info12; 2311 2474 2312 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,2475 status = dcerpc_samr_SetDomainInfo(b, mem_ctx, 2313 2476 domain_handle, 2314 2477 12, 2315 &dom_info); 2478 &dom_info, 2479 &result); 2316 2480 2317 2481 NT_STATUS_NOT_OK_RETURN(status); 2482 NT_STATUS_NOT_OK_RETURN(result); 2318 2483 } 2319 2484 … … 2802 2967 2803 2968 NTSTATUS status = NT_STATUS_OK; 2969 NTSTATUS result = NT_STATUS_OK; 2804 2970 WERROR werr; 2971 struct dcerpc_binding_handle *b = NULL; 2805 2972 2806 2973 ZERO_STRUCT(connect_handle); … … 2829 2996 goto done; 2830 2997 } 2998 2999 b = pipe_cli->binding_handle; 2831 3000 2832 3001 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 2843 3012 init_lsa_String(&lsa_account_name, r->in.user_name); 2844 3013 2845 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),3014 status = dcerpc_samr_LookupNames(b, talloc_tos(), 2846 3015 &domain_handle, 2847 3016 1, 2848 3017 &lsa_account_name, 2849 3018 &user_rids, 2850 &name_types); 3019 &name_types, 3020 &result); 2851 3021 if (!NT_STATUS_IS_OK(status)) { 2852 3022 werr = ntstatus_to_werror(status); 2853 3023 goto done; 2854 3024 } 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(), 2857 3031 &domain_handle, 2858 3032 SAMR_USER_ACCESS_GET_GROUPS, 2859 3033 user_rids.ids[0], 2860 &user_handle); 3034 &user_handle, 3035 &result); 2861 3036 if (!NT_STATUS_IS_OK(status)) { 2862 3037 werr = ntstatus_to_werror(status); 2863 3038 goto done; 2864 3039 } 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(), 2867 3046 &user_handle, 2868 &rid_array); 3047 &rid_array, 3048 &result); 2869 3049 if (!NT_STATUS_IS_OK(status)) { 2870 3050 werr = ntstatus_to_werror(status); 3051 goto done; 3052 } 3053 if (!NT_STATUS_IS_OK(result)) { 3054 werr = ntstatus_to_werror(result); 2871 3055 goto done; 2872 3056 } … … 2882 3066 } 2883 3067 2884 status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),3068 status = dcerpc_samr_LookupRids(b, talloc_tos(), 2885 3069 &domain_handle, 2886 3070 rid_array->count, 2887 3071 rids, 2888 3072 &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)) { 2892 3076 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); 2893 3082 goto done; 2894 3083 } … … 2957 3146 2958 3147 NTSTATUS status = NT_STATUS_OK; 3148 NTSTATUS result = NT_STATUS_OK; 2959 3149 WERROR werr; 3150 struct dcerpc_binding_handle *b = NULL; 2960 3151 2961 3152 ZERO_STRUCT(connect_handle); … … 2980 3171 goto done; 2981 3172 } 3173 3174 b = pipe_cli->binding_handle; 2982 3175 2983 3176 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 2994 3187 init_lsa_String(&lsa_account_name, r->in.user_name); 2995 3188 2996 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),3189 status = dcerpc_samr_LookupNames(b, talloc_tos(), 2997 3190 &domain_handle, 2998 3191 1, 2999 3192 &lsa_account_name, 3000 3193 &user_rids, 3001 &name_types); 3194 &name_types, 3195 &result); 3002 3196 if (!NT_STATUS_IS_OK(status)) { 3003 3197 werr = ntstatus_to_werror(status); 3004 3198 goto done; 3005 3199 } 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(), 3008 3206 &domain_handle, 3009 3207 SAMR_USER_ACCESS_GET_GROUPS, 3010 3208 user_rids.ids[0], 3011 &user_handle); 3209 &user_handle, 3210 &result); 3012 3211 if (!NT_STATUS_IS_OK(status)) { 3013 3212 werr = ntstatus_to_werror(status); 3213 goto done; 3214 } 3215 if (!NT_STATUS_IS_OK(result)) { 3216 werr = ntstatus_to_werror(result); 3014 3217 goto done; 3015 3218 } … … 3044 3247 } 3045 3248 3046 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),3249 status = dcerpc_samr_LookupNames(b, talloc_tos(), 3047 3250 &domain_handle, 3048 3251 r->in.num_entries, 3049 3252 lsa_names, 3050 3253 &group_rids, 3051 &name_types); 3254 &name_types, 3255 &result); 3052 3256 if (!NT_STATUS_IS_OK(status)) { 3053 3257 werr = ntstatus_to_werror(status); 3258 goto done; 3259 } 3260 if (!NT_STATUS_IS_OK(result)) { 3261 werr = ntstatus_to_werror(result); 3054 3262 goto done; 3055 3263 } … … 3058 3266 num_member_rids = group_rids.count; 3059 3267 3060 status = rpccli_samr_GetGroupsForUser(pipe_cli, talloc_tos(),3268 status = dcerpc_samr_GetGroupsForUser(b, talloc_tos(), 3061 3269 &user_handle, 3062 &rid_array); 3270 &rid_array, 3271 &result); 3063 3272 if (!NT_STATUS_IS_OK(status)) { 3064 3273 werr = ntstatus_to_werror(status); 3274 goto done; 3275 } 3276 if (!NT_STATUS_IS_OK(result)) { 3277 werr = ntstatus_to_werror(result); 3065 3278 goto done; 3066 3279 } … … 3109 3322 3110 3323 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(), 3112 3325 &domain_handle, 3113 3326 SAMR_GROUP_ACCESS_ADD_MEMBER, 3114 3327 add_rids[i], 3115 &group_handle); 3328 &group_handle, 3329 &result); 3116 3330 if (!NT_STATUS_IS_OK(status)) { 3117 3331 werr = ntstatus_to_werror(status); 3118 3332 goto done; 3119 3333 } 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(), 3122 3340 &group_handle, 3123 3341 user_rids.ids[0], 3124 7 /* ? */); 3342 7 /* ? */, 3343 &result); 3125 3344 if (!NT_STATUS_IS_OK(status)) { 3126 3345 werr = ntstatus_to_werror(status); 3127 3346 goto done; 3128 3347 } 3348 if (!NT_STATUS_IS_OK(result)) { 3349 werr = ntstatus_to_werror(result); 3350 goto done; 3351 } 3129 3352 3130 3353 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); 3132 3355 } 3133 3356 } … … 3136 3359 3137 3360 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(), 3139 3362 &domain_handle, 3140 3363 SAMR_GROUP_ACCESS_REMOVE_MEMBER, 3141 3364 del_rids[i], 3142 &group_handle); 3365 &group_handle, 3366 &result); 3143 3367 if (!NT_STATUS_IS_OK(status)) { 3144 3368 werr = ntstatus_to_werror(status); 3145 3369 goto done; 3146 3370 } 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(), 3149 3377 &group_handle, 3150 user_rids.ids[0]); 3378 user_rids.ids[0], 3379 &result); 3151 3380 if (!NT_STATUS_IS_OK(status)) { 3152 3381 werr = ntstatus_to_werror(status); 3153 3382 goto done; 3154 3383 } 3384 if (!NT_STATUS_IS_OK(result)) { 3385 werr = ntstatus_to_werror(result); 3386 goto done; 3387 } 3155 3388 3156 3389 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); 3158 3391 } 3159 3392 } … … 3163 3396 done: 3164 3397 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); 3166 3399 } 3167 3400 … … 3235 3468 3236 3469 NTSTATUS status = NT_STATUS_OK; 3470 NTSTATUS result = NT_STATUS_OK; 3237 3471 WERROR werr; 3472 struct dcerpc_binding_handle *b = NULL; 3238 3473 3239 3474 ZERO_STRUCT(connect_handle); … … 3262 3497 goto done; 3263 3498 } 3499 3500 b = pipe_cli->binding_handle; 3264 3501 3265 3502 werr = libnetapi_samr_open_domain(ctx, pipe_cli, … … 3288 3525 init_lsa_String(&lsa_account_name, r->in.user_name); 3289 3526 3290 status = rpccli_samr_LookupNames(pipe_cli, talloc_tos(),3527 status = dcerpc_samr_LookupNames(b, talloc_tos(), 3291 3528 &domain_handle, 3292 3529 1, 3293 3530 &lsa_account_name, 3294 3531 &user_rids, 3295 &name_types); 3532 &name_types, 3533 &result); 3296 3534 if (!NT_STATUS_IS_OK(status)) { 3297 3535 werr = ntstatus_to_werror(status); 3298 3536 goto done; 3299 3537 } 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(), 3302 3544 &domain_handle, 3303 3545 SAMR_USER_ACCESS_GET_GROUPS, 3304 3546 user_rids.ids[0], 3305 &user_handle); 3547 &user_handle, 3548 &result); 3306 3549 if (!NT_STATUS_IS_OK(status)) { 3307 3550 werr = ntstatus_to_werror(status); 3308 3551 goto done; 3309 3552 } 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(), 3312 3559 &user_handle, 3313 &rid_array); 3560 &rid_array, 3561 &result); 3314 3562 if (!NT_STATUS_IS_OK(status)) { 3315 3563 werr = ntstatus_to_werror(status); 3564 goto done; 3565 } 3566 if (!NT_STATUS_IS_OK(result)) { 3567 werr = ntstatus_to_werror(result); 3316 3568 goto done; 3317 3569 } … … 3329 3581 } 3330 3582 3331 sid_array.sids[0].sid = sid_dup_talloc(ctx, &user_sid);3583 sid_array.sids[0].sid = dom_sid_dup(ctx, &user_sid); 3332 3584 if (!sid_array.sids[0].sid) { 3333 3585 werr = WERR_NOMEM; … … 3343 3595 } 3344 3596 3345 sid_array.sids[i+1].sid = sid_dup_talloc(ctx, &sid);3597 sid_array.sids[i+1].sid = dom_sid_dup(ctx, &sid); 3346 3598 if (!sid_array.sids[i+1].sid) { 3347 3599 werr = WERR_NOMEM; … … 3350 3602 } 3351 3603 3352 status = rpccli_samr_GetAliasMembership(pipe_cli, talloc_tos(),3604 status = dcerpc_samr_GetAliasMembership(b, talloc_tos(), 3353 3605 &domain_handle, 3354 3606 &sid_array, 3355 &domain_rids); 3607 &domain_rids, 3608 &result); 3356 3609 if (!NT_STATUS_IS_OK(status)) { 3357 3610 werr = ntstatus_to_werror(status); 3611 goto done; 3612 } 3613 if (!NT_STATUS_IS_OK(result)) { 3614 werr = ntstatus_to_werror(result); 3358 3615 goto done; 3359 3616 } … … 3367 3624 } 3368 3625 3369 status = rpccli_samr_GetAliasMembership(pipe_cli, talloc_tos(),3626 status = dcerpc_samr_GetAliasMembership(b, talloc_tos(), 3370 3627 &builtin_handle, 3371 3628 &sid_array, 3372 &builtin_rids); 3629 &builtin_rids, 3630 &result); 3373 3631 if (!NT_STATUS_IS_OK(status)) { 3374 3632 werr = ntstatus_to_werror(status); 3633 goto done; 3634 } 3635 if (!NT_STATUS_IS_OK(result)) { 3636 werr = ntstatus_to_werror(result); 3375 3637 goto done; 3376 3638 } … … 3384 3646 } 3385 3647 3386 status = rpccli_samr_LookupRids(pipe_cli, talloc_tos(),3648 status = dcerpc_samr_LookupRids(b, talloc_tos(), 3387 3649 &builtin_handle, 3388 3650 num_rids, 3389 3651 rids, 3390 3652 &names, 3391 &types); 3653 &types, 3654 &result); 3392 3655 if (!NT_STATUS_IS_OK(status)) { 3393 3656 werr = ntstatus_to_werror(status); 3657 goto done; 3658 } 3659 if (!NT_STATUS_IS_OK(result)) { 3660 werr = ntstatus_to_werror(result); 3394 3661 goto done; 3395 3662 } -
trunk/server/source3/lib/os2helper.c
r698 r745 60 60 #include "../lib/util/attr.h" 61 61 #include "../lib/util/xfile.h" 62 #include " debug.h"62 #include "../lib/util/debug.h" 63 63 #else 64 64 -
trunk/server/source3/lib/packet.c
r593 r745 3 3 Packet handling 4 4 Copyright (C) Volker Lendecke 2007 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 19 19 20 20 #include "includes.h" 21 #include "../lib/util/select.h" 22 #include "system/filesys.h" 23 #include "system/select.h" 24 #include "packet.h" 21 25 22 26 struct packet_context { … … 102 106 } 103 107 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 108 NTSTATUS 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); 120 113 if (res == 0) { 121 DEBUG(10, (" selecttimed out\n"));114 DEBUG(10, ("poll timed out\n")); 122 115 return NT_STATUS_IO_TIMEOUT; 123 116 } 124 117 125 118 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; 128 125 } 129 126 -
trunk/server/source3/lib/pidfile.c
r454 r745 21 21 22 22 #include "includes.h" 23 #include "system/filesys.h" 23 24 24 25 #ifndef O_NONBLOCK … … 97 98 /* Add a suffix to the program name if this is a process with a 98 99 * none default configuration file name. */ 99 100 100 /* On OS/2, CONFIGFILE will always be different to dyn_CONFIGFILE 101 101 as dyn_CONFIGFILE dynamically looks up the system ETC directory */ 102 102 #ifndef __OS2__ 103 104 103 if (strcmp( CONFIGFILE, get_dyn_CONFIGFILE()) == 0) { 105 104 name = SMB_STRDUP(program_name); … … 154 153 exit(1); 155 154 } 156 157 155 /* Leave pid file open & locked for the duration... */ 158 156 SAFE_FREE(name); 157 159 158 #ifdef __OS2__ // If we leave the file open & locked on OS/2 - we can't read it, so close the fd 160 159 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); 161 163 #endif 162 164 } -
trunk/server/source3/lib/popt_common.c
r414 r745 22 22 23 23 #include "includes.h" 24 #include "system/filesys.h" 25 #include "popt_common.h" 24 26 25 27 /* Handle command line options: … … 34 36 */ 35 37 36 extern bool AllowDebugChange; 38 enum {OPT_OPTION=1}; 39 37 40 extern bool override_logfile; 38 41 … … 96 99 97 100 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 98 108 case 'd': 99 109 if (arg) { 100 debug_parse_levels(arg); 101 AllowDebugChange = False; 110 lp_set_cmdline("log level", arg); 102 111 } 103 112 break; … … 164 173 { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" }, 165 174 { "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" }, 166 176 POPT_TABLEEND 167 177 }; … … 185 195 }; 186 196 197 struct 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 }; 187 202 188 203 /* Handle command line options: -
trunk/server/source3/lib/privileges.c
r414 r745 23 23 24 24 #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" 25 30 26 31 #define PRIVPREFIX "PRIV_" 27 32 28 33 typedef struct { 29 size_t count;30 DOM_SID*list;34 uint32_t count; 35 struct dom_sid *list; 31 36 } SID_LIST; 32 37 33 38 typedef struct { 34 39 TALLOC_CTX *mem_ctx; 35 SE_PRIVprivilege;40 uint64_t privilege; 36 41 SID_LIST sids; 37 42 } PRIV_SID_LIST; 38 43 39 40 static bool get_privileges( const DOM_SID *sid, SE_PRIV *mask ) 44 /* 45 interpret an old style SE_PRIV structure 46 */ 47 static 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 74 static bool get_privileges( const struct dom_sid *sid, uint64_t *mask ) 41 75 { 42 76 struct db_context *db = get_account_pol_db(); … … 60 94 61 95 if ( !data.dptr ) { 62 DEBUG( 3, ("get_privileges: No privileges assigned to SID "96 DEBUG(4, ("get_privileges: No privileges assigned to SID " 63 97 "[%s]\n", sid_string_dbg(sid))); 64 98 return False; 65 99 } 66 100 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 70 114 TALLOC_FREE(data.dptr); 71 115 … … 77 121 ****************************************************************************/ 78 122 79 static bool set_privileges( const DOM_SID *sid, SE_PRIV *mask )123 static bool set_privileges( const struct dom_sid *sid, uint64_t mask ) 80 124 { 81 125 struct db_context *db = get_account_pol_db(); 126 uint8_t privbuf[8]; 82 127 fstring tmp, keystr; 83 128 TDB_DATA data; … … 98 143 fstr_sprintf(keystr, "%s%s", PRIVPREFIX, sid_to_fstring(tmp, sid)); 99 144 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); 104 150 105 151 return NT_STATUS_IS_OK(dbwrap_store_bystring(db, keystr, data, … … 111 157 *********************************************************************/ 112 158 113 bool get_privileges_for_sids( SE_PRIV *privileges, DOM_SID*slist, int scount)114 { 115 SE_PRIVmask;159 bool get_privileges_for_sids(uint64_t *privileges, struct dom_sid *slist, int scount) 160 { 161 uint64_t mask; 116 162 int i; 117 163 bool found = False; 118 164 119 se_priv_copy( privileges, &se_priv_none );165 *privileges = 0; 120 166 121 167 for ( i=0; i<scount; i++ ) { … … 126 172 127 173 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; 132 178 found = True; 133 179 } … … 136 182 } 137 183 184 NTSTATUS 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 } 138 201 139 202 /********************************************************************* … … 145 208 PRIV_SID_LIST *priv = (PRIV_SID_LIST *)state; 146 209 int prefixlen = strlen(PRIVPREFIX); 147 DOM_SIDsid;210 struct dom_sid sid; 148 211 fstring sid_string; 149 150 /* easy check first */151 152 if (rec->value.dsize != sizeof(SE_PRIV) )153 return 0;154 212 155 213 /* check we have a PRIV_+SID entry */ … … 160 218 /* check to see if we are looking for a particular privilege */ 161 219 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 } 166 235 167 236 /* if the SID does not have the specified privilege 168 237 then just return */ 169 238 170 if ( !is_privilege_assigned( &mask, &priv->privilege) )239 if ((mask & priv->privilege) == 0) { 171 240 return 0; 172 } 173 174 fstrcpy( sid_string, (char *)&(rec->key.dptr[strlen(PRIVPREFIX)]) ); 241 } 242 } 175 243 176 244 /* this is a last ditch safety check to preventing returning … … 200 268 *********************************************************************/ 201 269 202 NTSTATUS privilege_enumerate_accounts( DOM_SID**sids, int *num_sids)270 NTSTATUS privilege_enumerate_accounts(struct dom_sid **sids, int *num_sids) 203 271 { 204 272 struct db_context *db = get_account_pol_db(); … … 211 279 ZERO_STRUCT(priv); 212 280 213 se_priv_copy( &priv.privilege, &se_priv_none );214 215 281 db->traverse_read(db, priv_traverse_fn, &priv); 216 282 … … 227 293 *********************************************************************/ 228 294 229 NTSTATUS privilege_enum_sids( const SE_PRIV *mask, TALLOC_CTX *mem_ctx,230 DOM_SID**sids, int *num_sids)295 NTSTATUS privilege_enum_sids(enum sec_privilege privilege, TALLOC_CTX *mem_ctx, 296 struct dom_sid **sids, int *num_sids) 231 297 { 232 298 struct db_context *db = get_account_pol_db(); … … 239 305 ZERO_STRUCT(priv); 240 306 241 se_priv_copy(&priv.privilege, mask);307 priv.privilege = sec_privilege_mask(privilege); 242 308 priv.mem_ctx = mem_ctx; 243 309 … … 256 322 ****************************************************************************/ 257 323 258 bool grant_privilege(const DOM_SID *sid, const SE_PRIV *priv_mask)259 { 260 SE_PRIVold_mask, new_mask;324 static bool grant_privilege_bitmap(const struct dom_sid *sid, const uint64_t priv_mask) 325 { 326 uint64_t old_mask, new_mask; 261 327 262 328 ZERO_STRUCT( old_mask ); … … 264 330 265 331 if ( get_privileges( sid, &old_mask ) ) 266 se_priv_copy( &new_mask, &old_mask );332 new_mask = old_mask; 267 333 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; 271 337 272 338 DEBUG(10,("grant_privilege: %s\n", sid_string_dbg(sid))); 273 339 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 ); 281 345 } 282 346 … … 285 349 *********************************************************************/ 286 350 287 bool grant_privilege_by_name( DOM_SID*sid, const char *name)288 { 289 SE_PRIVmask;351 bool grant_privilege_by_name(const struct dom_sid *sid, const char *name) 352 { 353 uint64_t mask; 290 354 291 355 if (! se_priv_from_name(name, &mask)) { … … 295 359 } 296 360 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 368 bool 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); 298 375 } 299 376 … … 302 379 ****************************************************************************/ 303 380 304 bool revoke_privilege(const DOM_SID *sid, const SE_PRIV *priv_mask)305 { 306 SE_PRIVmask;381 static bool revoke_privilege_bitmap(const struct dom_sid *sid, const uint64_t priv_mask) 382 { 383 uint64_t mask; 307 384 308 385 /* if the user has no privileges, then we can't revoke any */ … … 313 390 DEBUG(10,("revoke_privilege: %s\n", sid_string_dbg(sid))); 314 391 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 405 bool 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); 324 412 } 325 413 … … 328 416 *********************************************************************/ 329 417 330 bool revoke_all_privileges( DOM_SID*sid )331 { 332 return revoke_privilege ( sid, &se_priv_all);418 bool revoke_all_privileges( const struct dom_sid *sid ) 419 { 420 return revoke_privilege_bitmap( sid, SE_ALL_PRIVS); 333 421 } 334 422 … … 337 425 *********************************************************************/ 338 426 339 bool revoke_privilege_by_name( DOM_SID*sid, const char *name)340 { 341 SE_PRIVmask;427 bool revoke_privilege_by_name(const struct dom_sid *sid, const char *name) 428 { 429 uint64_t mask; 342 430 343 431 if (! se_priv_from_name(name, &mask)) { … … 347 435 } 348 436 349 return revoke_privilege (sid, &mask);437 return revoke_privilege_bitmap(sid, mask); 350 438 351 439 } … … 355 443 ****************************************************************************/ 356 444 357 NTSTATUS privilege_create_account(const DOM_SID*sid )358 { 359 return ( grant_privilege (sid, &se_priv_none) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL);445 NTSTATUS privilege_create_account(const struct dom_sid *sid ) 446 { 447 return ( grant_privilege_bitmap(sid, 0) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL); 360 448 } 361 449 … … 388 476 } 389 477 390 /****************************************************************************391 initialise a privilege list and set the talloc context392 ****************************************************************************/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 context413 ****************************************************************************/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_SET427 ****************************************************************************/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_attr442 ****************************************************************************/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 470 478 /******************************************************************* 471 479 *******************************************************************/ 472 480 473 bool is_privileged_sid( const DOM_SID*sid )474 { 475 SE_PRIVmask;481 bool is_privileged_sid( const struct dom_sid *sid ) 482 { 483 uint64_t mask; 476 484 477 485 return get_privileges( sid, &mask ); … … 481 489 *******************************************************************/ 482 490 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 } 491 bool 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 31 31 #include "pthreadpool.h" 32 32 #include "lib/util/dlinklist.h" 33 #ifdef __OS2__ 34 #define pipe(A) os2_pipe(A) 35 #endif 33 36 34 37 struct pthreadpool_job { -
trunk/server/source3/lib/recvfile.c
r664 r745 25 25 26 26 #include "includes.h" 27 #include "system/filesys.h" 27 28 #ifdef __OS2__ 28 29 #define pipe(A) os2_pipe(A) -
trunk/server/source3/lib/secdesc.c
r414 r745 22 22 23 23 #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) 24 33 25 34 /* Map generic permissions to file object specific permissions */ … … 36 45 ********************************************************************/ 37 46 38 uint32_t get_sec_info(const SEC_DESC*sd)47 uint32_t get_sec_info(const struct security_descriptor *sd) 39 48 { 40 49 uint32_t sec_info = ALL_SECURITY_INFORMATION; … … 43 52 44 53 if (sd->owner_sid == NULL) { 45 sec_info &= ~ OWNER_SECURITY_INFORMATION;54 sec_info &= ~SECINFO_OWNER; 46 55 } 47 56 if (sd->group_sid == NULL) { 48 sec_info &= ~ GROUP_SECURITY_INFORMATION;57 sec_info &= ~SECINFO_GROUP; 49 58 } 50 59 if (sd->sacl == NULL) { 51 sec_info &= ~S ACL_SECURITY_INFORMATION;60 sec_info &= ~SECINFO_SACL; 52 61 } 53 62 if (sd->dacl == NULL) { 54 sec_info &= ~ DACL_SECURITY_INFORMATION;63 sec_info &= ~SECINFO_DACL; 55 64 } 56 65 … … 64 73 ********************************************************************/ 65 74 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;75 struct 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; 72 81 uint16 secdesc_type; 73 82 size_t secdesc_size; … … 109 118 } 110 119 111 /******************************************************************* 112 Creates a SEC_DESC structure 113 ********************************************************************/ 114 115 SEC_DESC *make_sec_desc(TALLOC_CTX *ctx, 120 struct 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 167 struct security_descriptor *make_sec_desc(TALLOC_CTX *ctx, 116 168 enum security_descriptor_revision revision, 117 169 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; 122 174 uint32 offset = 0; 123 175 124 176 *sd_size = 0; 125 177 126 if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)178 if(( dst = TALLOC_ZERO_P(ctx, struct security_descriptor)) == NULL) 127 179 return NULL; 128 180 … … 140 192 dst->dacl = NULL; 141 193 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)) 143 195 goto error_exit; 144 196 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)) 146 198 goto error_exit; 147 199 … … 166 218 167 219 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); 169 221 } 170 222 171 223 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); 173 225 } 174 226 … … 183 235 184 236 /******************************************************************* 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 240 struct security_descriptor *dup_sec_desc(TALLOC_CTX *ctx, const struct security_descriptor *src) 189 241 { 190 242 size_t dummy; … … 209 261 210 262 ndr_err = ndr_push_struct_blob( 211 &blob, mem_ctx, NULL,secdesc,263 &blob, mem_ctx, secdesc, 212 264 (ndr_push_flags_fn_t)ndr_push_security_descriptor); 213 265 … … 215 267 DEBUG(0, ("ndr_push_security_descriptor failed: %s\n", 216 268 ndr_errstr(ndr_err))); 217 return ndr_map_error2ntstatus(ndr_err); ;269 return ndr_map_error2ntstatus(ndr_err); 218 270 } 219 271 … … 235 287 236 288 ndr_err = ndr_push_struct_blob( 237 &blob, mem_ctx, NULL,secdesc_buf,289 &blob, mem_ctx, secdesc_buf, 238 290 (ndr_push_flags_fn_t)ndr_push_sec_desc_buf); 239 291 … … 241 293 DEBUG(0, ("ndr_push_sec_desc_buf failed: %s\n", 242 294 ndr_errstr(ndr_err))); 243 return ndr_map_error2ntstatus(ndr_err); ;295 return ndr_map_error2ntstatus(ndr_err); 244 296 } 245 297 … … 270 322 blob = data_blob_const(data, len); 271 323 272 ndr_err = ndr_pull_struct_blob( 273 &blob, result, NULL, result, 324 ndr_err = ndr_pull_struct_blob(&blob, result, result, 274 325 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); 275 326 … … 278 329 ndr_errstr(ndr_err))); 279 330 TALLOC_FREE(result); 280 return ndr_map_error2ntstatus(ndr_err); ;331 return ndr_map_error2ntstatus(ndr_err); 281 332 } 282 333 … … 307 358 blob = data_blob_const(data, len); 308 359 309 ndr_err = ndr_pull_struct_blob( 310 &blob, result, NULL, result, 360 ndr_err = ndr_pull_struct_blob(&blob, result, result, 311 361 (ndr_pull_flags_fn_t)ndr_pull_sec_desc_buf); 312 362 … … 315 365 ndr_errstr(ndr_err))); 316 366 TALLOC_FREE(result); 317 return ndr_map_error2ntstatus(ndr_err); ;367 return ndr_map_error2ntstatus(ndr_err); 318 368 } 319 369 … … 323 373 324 374 /******************************************************************* 325 Creates a SEC_DESCstructure 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 378 struct 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) 330 380 { 331 381 return make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1, … … 335 385 336 386 /******************************************************************* 337 Creates a SEC_DESC_BUFstructure.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 390 struct 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) 345 395 return NULL; 346 396 … … 356 406 357 407 /******************************************************************* 358 Duplicates a SEC_DESC_BUFstructure.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 411 struct sec_desc_buf *dup_sec_desc_buf(TALLOC_CTX *ctx, struct sec_desc_buf *src) 362 412 { 363 413 if(src == NULL) … … 368 418 369 419 /******************************************************************* 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 423 NTSTATUS 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; 378 428 NTSTATUS status; 379 429 … … 401 451 402 452 /******************************************************************* 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 456 NTSTATUS sec_desc_mod_sid(struct security_descriptor *sd, struct dom_sid *sid, uint32 mask) 407 457 { 408 458 NTSTATUS status; … … 420 470 421 471 /******************************************************************* 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 475 NTSTATUS 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; 430 480 NTSTATUS status; 431 481 … … 453 503 454 504 /* 455 * Determine if an ACEis inheritable505 * Determine if an struct security_ace is inheritable 456 506 */ 457 507 458 static bool is_inheritable_ace(const SEC_ACE*ace,508 static bool is_inheritable_ace(const struct security_ace *ace, 459 509 bool container) 460 510 { … … 480 530 */ 481 531 482 bool sd_has_inheritable_components(const SEC_DESC*parent_ctr, bool container)532 bool sd_has_inheritable_components(const struct security_descriptor *parent_ctr, bool container) 483 533 { 484 534 unsigned int i; 485 const SEC_ACL*the_acl = parent_ctr->dacl;535 const struct security_acl *the_acl = parent_ctr->dacl; 486 536 487 537 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]; 489 539 490 540 if (is_inheritable_ace(ace, container)) { … … 500 550 501 551 NTSTATUS se_create_child_secdesc(TALLOC_CTX *ctx, 502 SEC_DESC**ppsd,552 struct security_descriptor **ppsd, 503 553 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, 507 557 bool container) 508 558 { 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; 511 561 unsigned int new_ace_list_ndx = 0, i; 512 562 … … 525 575 } 526 576 527 if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE,577 if (!(new_ace_list = TALLOC_ARRAY(ctx, struct security_ace, 528 578 2*the_acl->num_aces))) { 529 579 return NT_STATUS_NO_MEMORY; … … 534 584 535 585 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; 540 590 uint8 new_flags = ace->flags; 541 591 … … 559 609 560 610 /* 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)) { 562 612 creator = &global_sid_Creator_Owner; 563 613 ptrustee = owner_sid; 564 } else if ( sid_equal(ptrustee, &global_sid_Creator_Group)) {614 } else if (dom_sid_equal(ptrustee, &global_sid_Creator_Group)) { 565 615 creator = &global_sid_Creator_Group; 566 616 ptrustee = group_sid; … … 635 685 636 686 NTSTATUS 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, 639 689 bool container) 640 690 { 641 691 NTSTATUS status; 642 692 size_t size = 0; 643 SEC_DESC*sd = NULL;693 struct security_descriptor *sd = NULL; 644 694 645 695 *ppsdb = NULL; -
trunk/server/source3/lib/sendfile.c
r414 r745 64 64 nwritten = sendfile(tofd, fromfd, &offset, total); 65 65 #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 67 71 if (nwritten == -1) { 68 72 if (errno == ENOSYS || errno == EINVAL) { … … 146 150 do { 147 151 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 149 157 if (nwritten == -1) { 150 158 if (errno == ENOSYS || errno == EINVAL) { … … 227 235 nwritten = sendfilev(tofd, vec, sfvcnt, &xferred); 228 236 #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 230 242 if (xferred == 0) 231 243 continue; /* Nothing written yet. */ … … 301 313 nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0); 302 314 #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 304 320 if (nwritten == -1) 305 321 return -1; … … 372 388 do { 373 389 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 375 395 if (ret == -1) 376 396 return -1; … … 450 470 do { 451 471 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 453 477 if ( ret == -1 ) 454 478 return -1; -
trunk/server/source3/lib/server_mutex.c
r414 r745 20 20 21 21 #include "includes.h" 22 #include "system/filesys.h" 23 #include "lib/util/tdb_wrap.h" 24 #include "util_tdb.h" 22 25 23 26 /* For reasons known only to MS, many of their NT/Win2k versions -
trunk/server/source3/lib/sharesec.c
r414 r745 19 19 20 20 #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" 21 26 22 27 /******************************************************************* … … 27 32 #define SHARE_DATABASE_VERSION_V1 1 28 33 #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/" 30 37 /* Map generic permissions to file object specific permissions */ 31 38 … … 38 45 } 39 46 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 52 static 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 40 132 bool share_info_db_init(void) 41 133 { 42 134 const char *vstring = "INFO/version"; 43 135 int32 vers_id; 136 int ret; 137 bool upgrade_ok = true; 44 138 45 139 if (share_db != NULL) { … … 56 150 57 151 vers_id = dbwrap_fetch_int32(share_db, vstring); 58 if (vers_id == SHARE_DATABASE_VERSION_V 2) {152 if (vers_id == SHARE_DATABASE_VERSION_V3) { 59 153 return true; 60 154 } … … 67 161 68 162 vers_id = dbwrap_fetch_int32(share_db, vstring); 69 if (vers_id == SHARE_DATABASE_VERSION_V 2) {163 if (vers_id == SHARE_DATABASE_VERSION_V3) { 70 164 /* 71 165 * Race condition … … 77 171 } 78 172 173 /* Move to at least V2. */ 174 79 175 /* Cope with byte-reversed older versions of the db. */ 80 176 if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) { … … 90 186 91 187 if (vers_id != SHARE_DATABASE_VERSION_V2) { 92 int ret;93 188 ret = share_db->traverse(share_db, delete_fn, NULL); 94 189 if (ret < 0) { … … 103 198 } 104 199 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 105 213 if (share_db->transaction_commit(share_db) != 0) { 106 214 DEBUG(0, ("transaction_commit failed\n")); … … 123 231 ********************************************************************/ 124 232 125 SEC_DESC*get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)233 struct security_descriptor *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access) 126 234 { 127 235 uint32_t sa; 128 SEC_ACEace;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; 131 239 uint32 spec_access = def_access; 132 240 … … 154 262 ********************************************************************/ 155 263 156 SEC_DESC*get_share_security( TALLOC_CTX *ctx, const char *servicename,264 struct security_descriptor *get_share_security( TALLOC_CTX *ctx, const char *servicename, 157 265 size_t *psize) 158 266 { 159 267 char *key; 160 SEC_DESC*psd = NULL;268 struct security_descriptor *psd = NULL; 161 269 TDB_DATA data; 270 char *c_servicename = canonicalize_servicename(talloc_tos(), servicename); 162 271 NTSTATUS status; 163 272 273 if (!c_servicename) { 274 return NULL; 275 } 276 164 277 if (!share_info_db_init()) { 278 TALLOC_FREE(c_servicename); 165 279 return NULL; 166 280 } 167 281 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); 169 284 DEBUG(0, ("talloc_asprintf failed\n")); 170 285 return NULL; 171 286 } 287 288 TALLOC_FREE(c_servicename); 172 289 173 290 data = dbwrap_fetch_bystring(share_db, talloc_tos(), key); … … 187 304 DEBUG(0, ("unmarshall_sec_desc failed: %s\n", 188 305 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 } 194 316 195 317 return psd; … … 200 322 ********************************************************************/ 201 323 202 bool set_share_security(const char *share_name, SEC_DESC*psd)203 { 204 TALLOC_CTX *frame ;324 bool set_share_security(const char *share_name, struct security_descriptor *psd) 325 { 326 TALLOC_CTX *frame = talloc_stackframe(); 205 327 char *key; 206 328 bool ret = False; 207 329 TDB_DATA blob; 208 330 NTSTATUS status; 331 char *c_share_name = canonicalize_servicename(frame, share_name); 332 333 if (!c_share_name) { 334 goto out; 335 } 209 336 210 337 if (!share_info_db_init()) { 211 return False; 212 } 213 214 frame = talloc_stackframe(); 338 goto out; 339 } 215 340 216 341 status = marshall_sec_desc(frame, psd, &blob.dptr, &blob.dsize); … … 222 347 } 223 348 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))) { 225 350 DEBUG(0, ("talloc_asprintf failed\n")); 226 351 goto out; … … 252 377 char *key; 253 378 NTSTATUS status; 379 char *c_servicename = canonicalize_servicename(talloc_tos(), servicename); 380 381 if (!c_servicename) { 382 return NULL; 383 } 254 384 255 385 if (!share_info_db_init()) { 386 TALLOC_FREE(c_servicename); 256 387 return False; 257 388 } 258 389 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); 261 393 return False; 262 394 } … … 266 398 if (!NT_STATUS_IS_OK(status)) { 267 399 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); 269 402 return False; 270 403 } 271 404 405 TALLOC_FREE(c_servicename); 272 406 return True; 273 407 } … … 277 411 ********************************************************************/ 278 412 279 bool share_access_check(const NT_USER_TOKEN *token, const char *sharename, 280 uint32 desired_access) 413 bool share_access_check(const struct security_token *token, 414 const char *sharename, 415 uint32 desired_access, 416 uint32_t *pgranted) 281 417 { 282 418 uint32 granted; 283 419 NTSTATUS status; 284 SEC_DESC*psd = NULL;420 struct security_descriptor *psd = NULL; 285 421 size_t sd_size; 286 422 … … 294 430 295 431 TALLOC_FREE(psd); 432 433 if (pgranted != NULL) { 434 *pgranted = granted; 435 } 296 436 297 437 return NT_STATUS_IS_OK(status); … … 302 442 ***************************************************************************/ 303 443 304 bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, SEC_DESC**ppsd)444 bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, struct security_descriptor **ppsd) 305 445 { 306 446 size_t s_size = 0; 307 447 const char *pacl = acl_str; 308 448 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; 312 452 size_t sd_size = 0; 313 453 int i; … … 317 457 /* If the acl string is blank return "Everyone:R" */ 318 458 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); 320 460 if (!default_psd) { 321 461 return False; … … 330 470 num_aces += count_chars(pacl,','); 331 471 332 ace_list = TALLOC_ARRAY(ctx, SEC_ACE, num_aces);472 ace_list = TALLOC_ARRAY(ctx, struct security_ace, num_aces); 333 473 if (!ace_list) { 334 474 return False; … … 339 479 uint32 g_access; 340 480 uint32 s_access; 341 DOM_SIDsid;481 struct dom_sid sid; 342 482 char *sidstr; 343 483 enum security_ace_type type = SEC_ACE_TYPE_ACCESS_ALLOWED; -
trunk/server/source3/lib/smbconf/smbconf_init.c
r414 r745 22 22 #include "lib/smbconf/smbconf_txt.h" 23 23 #include "lib/smbconf/smbconf_reg.h" 24 #include "lib/smbconf/smbconf_init.h" 24 25 25 26 /** … … 34 35 * - "txt" or "file" 35 36 */ 36 WERRORsmbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,37 sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, 37 38 const char *source) 38 39 { 39 WERROR werr;40 sbcErr err; 40 41 char *backend = NULL; 41 42 char *path = NULL; … … 44 45 45 46 if (conf_ctx == NULL) { 46 werr = WERR_INVALID_PARAM;47 err = SBC_ERR_INVALID_PARAM; 47 48 goto done; 48 49 } 49 50 50 51 if ((source == NULL) || (*source == '\0')) { 51 werr = WERR_INVALID_PARAM;52 err = SBC_ERR_INVALID_PARAM; 52 53 goto done; 53 54 } … … 55 56 backend = talloc_strdup(tmp_ctx, source); 56 57 if (backend == NULL) { 57 werr = WERR_NOMEM;58 err = SBC_ERR_NOMEM; 58 59 goto done; 59 60 } … … 69 70 70 71 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); 72 73 } 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); 74 75 } else if (sep == NULL) { 75 76 /* … … 78 79 * string as a path argument. 79 80 */ 80 werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);81 err = smbconf_init_txt(mem_ctx, conf_ctx, backend); 81 82 } else { 82 83 /* … … 87 88 * 'include = /path/to/file.%T' 88 89 */ 89 werr = smbconf_init_txt(mem_ctx, conf_ctx, source);90 err = smbconf_init_txt(mem_ctx, conf_ctx, source); 90 91 } 91 92 92 93 done: 93 94 talloc_free(tmp_ctx); 94 return werr;95 return err; 95 96 } -
trunk/server/source3/lib/smbconf/smbconf_init.h
r414 r745 27 27 * takes source string in the form of "backend:path" 28 28 */ 29 WERRORsmbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,29 sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, 30 30 const char *source); 31 31 -
trunk/server/source3/lib/smbconf/smbconf_reg.c
r414 r745 20 20 #include "includes.h" 21 21 #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" 22 31 23 32 #define INCLUDES_VALNAME "includes" … … 75 84 * Open a subkey of the base key (i.e a service) 76 85 */ 77 static WERRORsmbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,86 static sbcErr smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx, 78 87 struct smbconf_ctx *ctx, 79 88 const char *servicename, … … 85 94 if (servicename == NULL) { 86 95 *key = rpd(ctx)->base_key; 87 return WERR_OK;96 return SBC_ERR_OK; 88 97 } 89 98 werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename, 90 99 desired_access, key); 91 92 100 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; 97 108 } 98 109 … … 119 130 * create a subkey of the base key (i.e. a service...) 120 131 */ 121 static WERRORsmbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,132 static sbcErr smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx, 122 133 struct smbconf_ctx *ctx, 123 134 const char * subkeyname, 124 135 struct registry_key **newkey) 125 136 { 126 WERROR werr = WERR_OK; 137 WERROR werr; 138 sbcErr err = SBC_ERR_OK; 127 139 TALLOC_CTX *create_ctx; 128 140 enum winreg_CreateAction action = REG_ACTION_NONE; … … 137 149 if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) { 138 150 DEBUG(10, ("Key '%s' already exists.\n", subkeyname)); 139 werr = WERR_FILE_EXISTS;151 err = SBC_ERR_FILE_EXISTS; 140 152 } 141 153 if (!W_ERROR_IS_OK(werr)) { 142 154 DEBUG(5, ("Error creating key %s: %s\n", 143 155 subkeyname, win_errstr(werr))); 156 err = SBC_ERR_UNKNOWN_FAILURE; 144 157 } 145 158 146 159 talloc_free(create_ctx); 147 return werr;160 return err; 148 161 } 149 162 … … 151 164 * add a value to a key. 152 165 */ 153 static WERRORsmbconf_reg_set_value(struct registry_key *key,166 static sbcErr smbconf_reg_set_value(struct registry_key *key, 154 167 const char *valname, 155 168 const char *valstr) … … 157 170 struct registry_value val; 158 171 WERROR werr = WERR_OK; 172 sbcErr err; 159 173 char *subkeyname; 160 174 const char *canon_valname; … … 172 186 "parameter '%s'\n", valstr, valname)); 173 187 } 174 werr = WERR_INVALID_PARAM;188 err = SBC_ERR_INVALID_PARAM; 175 189 goto done; 176 190 } … … 179 193 DEBUG(5, ("Parameter '%s' not allowed in registry.\n", 180 194 canon_valname)); 181 werr = WERR_INVALID_PARAM;195 err = SBC_ERR_INVALID_PARAM; 182 196 goto done; 183 197 } … … 187 201 DEBUG(5, ("Invalid registry key '%s' given as " 188 202 "smbconf section.\n", key->key->name)); 189 werr = WERR_INVALID_PARAM;203 err = SBC_ERR_INVALID_PARAM; 190 204 goto done; 191 205 } … … 197 211 "service definition ('%s').\n", canon_valname, 198 212 subkeyname)); 199 werr = WERR_INVALID_PARAM;213 err = SBC_ERR_INVALID_PARAM; 200 214 goto done; 201 215 } … … 204 218 205 219 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 } 208 224 209 225 werr = reg_setvalue(key, canon_valname, &val); … … 212 228 "key '%s': %s\n", 213 229 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; 235 done: 236 return err; 237 } 238 239 static sbcErr smbconf_reg_set_multi_sz_value(struct registry_key *key, 221 240 const char *valname, 222 241 const uint32_t num_strings, … … 224 243 { 225 244 WERROR werr; 245 sbcErr err = SBC_ERR_OK; 226 246 struct registry_value *value; 227 247 uint32_t count; 228 248 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 249 const char **array; 229 250 230 251 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; 232 259 goto done; 233 260 } 234 261 235 262 value = TALLOC_ZERO_P(tmp_ctx, struct registry_value); 263 if (value == NULL) { 264 err = SBC_ERR_NOMEM; 265 goto done; 266 } 236 267 237 268 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 244 270 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; 252 281 } 253 282 … … 256 285 DEBUG(5, ("Error adding value '%s' to key '%s': %s\n", 257 286 valname, key->key->name, win_errstr(werr))); 287 err = SBC_ERR_ACCESS_DENIED; 258 288 } 259 289 260 290 done: 261 291 talloc_free(tmp_ctx); 262 return werr;292 return err; 263 293 } 264 294 … … 282 312 switch (value->type) { 283 313 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 } 285 318 break; 286 319 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); 289 326 break; 327 } 290 328 case REG_MULTI_SZ: { 291 329 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++) { 293 335 result = talloc_asprintf(mem_ctx, "%s\"%s\" ", 294 336 result ? result : "" , 295 value->v.multi_sz.strings[j]);337 a[j]); 296 338 if (result == NULL) { 297 339 break; … … 302 344 case REG_BINARY: 303 345 result = talloc_asprintf(mem_ctx, "binary (%d bytes)", 304 (int)value-> v.binary.length);346 (int)value->data.length); 305 347 break; 306 348 default: … … 311 353 } 312 354 313 static WERRORsmbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,355 static sbcErr smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx, 314 356 struct registry_key *key, 315 357 uint32_t *num_includes, … … 317 359 { 318 360 WERROR werr; 361 sbcErr err; 319 362 uint32_t count; 320 363 struct registry_value *value = NULL; 321 364 char **tmp_includes = NULL; 365 const char **array = NULL; 322 366 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 323 367 … … 326 370 *num_includes = 0; 327 371 *includes = NULL; 328 werr = WERR_OK;372 err = SBC_ERR_OK; 329 373 goto done; 330 374 } … … 332 376 werr = reg_queryvalue(tmp_ctx, key, INCLUDES_VALNAME, &value); 333 377 if (!W_ERROR_IS_OK(werr)) { 378 err = SBC_ERR_ACCESS_DENIED; 334 379 goto done; 335 380 } … … 337 382 if (value->type != REG_MULTI_SZ) { 338 383 /* 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, 345 395 &tmp_includes, 346 396 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)) { 349 399 goto done; 350 400 } … … 354 404 *includes = talloc_move(mem_ctx, &tmp_includes); 355 405 if (*includes == NULL) { 356 werr = WERR_NOMEM;406 err = SBC_ERR_NOMEM; 357 407 goto done; 358 408 } … … 363 413 } 364 414 415 err = SBC_ERR_OK; 365 416 done: 366 417 talloc_free(tmp_ctx); 367 return werr;418 return err; 368 419 } 369 420 … … 372 423 * and a list of value strings (ordered) 373 424 */ 374 static WERRORsmbconf_reg_get_values(TALLOC_CTX *mem_ctx,425 static sbcErr smbconf_reg_get_values(TALLOC_CTX *mem_ctx, 375 426 struct registry_key *key, 376 427 uint32_t *num_values, … … 380 431 TALLOC_CTX *tmp_ctx = NULL; 381 432 WERROR werr = WERR_OK; 433 sbcErr err; 382 434 uint32_t count; 383 435 struct registry_value *valvalue = NULL; … … 392 444 (value_strings == NULL)) 393 445 { 394 werr = WERR_INVALID_PARAM;446 err = SBC_ERR_INVALID_PARAM; 395 447 goto done; 396 448 } … … 409 461 } 410 462 411 werr = smbconf_add_string_to_array(tmp_ctx,412 413 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)) { 415 467 goto done; 416 468 } 417 469 418 470 valstring = smbconf_format_registry_value(tmp_ctx, valvalue); 419 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,420 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)) { 422 474 goto done; 423 475 } … … 425 477 } 426 478 if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { 479 err = SBC_ERR_NOMEM; 427 480 goto done; 428 481 } 429 482 430 483 /* 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, 432 485 &includes); 433 if (!W_ERROR_IS_OK(werr)) { 434 goto done; 435 } 486 if (!SBC_ERROR_IS_OK(err)) { 487 goto done; 488 } 489 436 490 for (count = 0; count < num_includes; count++) { 437 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,438 439 if (! W_ERROR_IS_OK(werr)) {440 goto done; 441 } 442 443 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,444 445 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)) { 447 501 goto done; 448 502 } … … 462 516 done: 463 517 talloc_free(tmp_ctx); 464 return werr;518 return err; 465 519 } 466 520 … … 491 545 * delete all values from a key 492 546 */ 493 static WERROR smbconf_reg_delete_values(struct registry_key *key) 494 { 495 WERROR werr; 547 static sbcErr smbconf_reg_delete_values(struct registry_key *key) 548 { 549 WERROR werr; 550 sbcErr err; 496 551 char *valname; 497 552 struct registry_value *valvalue; … … 506 561 werr = reg_deletevalue(key, valname); 507 562 if (!W_ERROR_IS_OK(werr)) { 563 err = SBC_ERR_ACCESS_DENIED; 508 564 goto done; 509 565 } … … 514 570 key->key->name, 515 571 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; 520 577 521 578 done: 522 579 talloc_free(mem_ctx); 523 return werr;580 return err; 524 581 } 525 582 … … 533 590 * initialize the registry smbconf backend 534 591 */ 535 static WERRORsmbconf_reg_init(struct smbconf_ctx *ctx, const char *path)592 static sbcErr smbconf_reg_init(struct smbconf_ctx *ctx, const char *path) 536 593 { 537 594 WERROR werr = WERR_OK; 538 struct nt_user_token *token; 595 sbcErr err; 596 struct security_token *token; 539 597 540 598 if (path == NULL) { … … 543 601 ctx->path = talloc_strdup(ctx, path); 544 602 if (ctx->path == NULL) { 545 werr = WERR_NOMEM;603 err = SBC_ERR_NOMEM; 546 604 goto done; 547 605 } … … 552 610 if (!W_ERROR_IS_OK(werr)) { 553 611 DEBUG(1, ("Error creating admin token\n")); 612 err = SBC_ERR_UNKNOWN_FAILURE; 554 613 goto done; 555 614 } … … 558 617 werr = registry_init_smbconf(path); 559 618 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)) { 565 625 DEBUG(1, ("Error opening the registry.\n")); 566 626 goto done; … … 571 631 token, &rpd(ctx)->base_key); 572 632 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 637 done: 638 return err; 578 639 } 579 640 … … 604 665 } 605 666 606 static WERRORsmbconf_reg_open(struct smbconf_ctx *ctx)667 static sbcErr smbconf_reg_open(struct smbconf_ctx *ctx) 607 668 { 608 669 WERROR werr; 609 670 610 671 if (rpd(ctx)->open) { 611 return WERR_OK;672 return SBC_ERR_OK; 612 673 } 613 674 614 675 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; 619 682 } 620 683 … … 646 709 } 647 710 648 if (! W_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {711 if (!SBC_ERROR_IS_OK(ctx->ops->open_conf(ctx))) { 649 712 return; 650 713 } … … 656 719 * Drop the whole configuration (restarting empty) - registry version 657 720 */ 658 static WERRORsmbconf_reg_drop(struct smbconf_ctx *ctx)721 static sbcErr smbconf_reg_drop(struct smbconf_ctx *ctx) 659 722 { 660 723 char *path, *p; 661 724 WERROR werr = WERR_OK; 725 sbcErr err = SBC_ERR_OK; 662 726 struct registry_key *parent_key = NULL; 663 727 struct registry_key *new_key = NULL; 664 728 TALLOC_CTX* mem_ctx = talloc_stackframe(); 665 729 enum winreg_CreateAction action; 666 struct nt_user_token *token;730 struct security_token *token; 667 731 668 732 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); 669 733 if (!W_ERROR_IS_OK(werr)) { 670 734 DEBUG(1, ("Error creating admin token\n")); 735 err = SBC_ERR_UNKNOWN_FAILURE; 671 736 goto done; 672 737 } … … 674 739 path = talloc_strdup(mem_ctx, ctx->path); 675 740 if (path == NULL) { 676 werr = WERR_NOMEM;741 err = SBC_ERR_NOMEM; 677 742 goto done; 678 743 } 679 744 p = strrchr(path, '\\'); 745 if (p == NULL) { 746 err = SBC_ERR_INVALID_PARAM; 747 goto done; 748 } 680 749 *p = '\0'; 681 750 werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token, 682 751 &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; 691 760 goto done; 692 761 } … … 694 763 werr = reg_createkey(mem_ctx, parent_key, p+1, REG_KEY_WRITE, 695 764 &new_key, &action); 765 if (!W_ERROR_IS_OK(werr)) { 766 err = SBC_ERR_IO_FAILURE; 767 goto done; 768 } 696 769 697 770 done: 698 771 talloc_free(mem_ctx); 699 return werr;772 return err; 700 773 } 701 774 … … 704 777 * registry version. 705 778 */ 706 static WERRORsmbconf_reg_get_share_names(struct smbconf_ctx *ctx,779 static sbcErr smbconf_reg_get_share_names(struct smbconf_ctx *ctx, 707 780 TALLOC_CTX *mem_ctx, 708 781 uint32_t *num_shares, … … 712 785 uint32_t added_count = 0; 713 786 TALLOC_CTX *tmp_ctx = NULL; 714 WERROR werr = WERR_OK; 787 WERROR werr; 788 sbcErr err = SBC_ERR_OK; 715 789 char *subkey_name = NULL; 716 790 char **tmp_share_names = NULL; 717 791 718 792 if ((num_shares == NULL) || (share_names == NULL)) { 719 werr = WERR_INVALID_PARAM; 720 goto done; 793 return SBC_ERR_INVALID_PARAM; 721 794 } 722 795 … … 726 799 727 800 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, 729 802 0, NULL); 730 if (! W_ERROR_IS_OK(werr)) {803 if (!SBC_ERROR_IS_OK(err)) { 731 804 goto done; 732 805 } … … 736 809 /* make sure "global" is always listed first */ 737 810 if (smbconf_share_exists(ctx, GLOBAL_NAME)) { 738 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,739 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)) { 741 814 goto done; 742 815 } … … 754 827 } 755 828 756 werr = smbconf_add_string_to_array(tmp_ctx,829 err = smbconf_add_string_to_array(tmp_ctx, 757 830 &tmp_share_names, 758 831 added_count, 759 832 subkey_name); 760 if (! W_ERROR_IS_OK(werr)) {833 if (!SBC_ERROR_IS_OK(err)) { 761 834 goto done; 762 835 } … … 764 837 } 765 838 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; 769 843 770 844 *num_shares = added_count; … … 777 851 done: 778 852 talloc_free(tmp_ctx); 779 return werr;853 return err; 780 854 } 781 855 … … 787 861 { 788 862 bool ret = false; 789 WERROR werr = WERR_OK;863 sbcErr err; 790 864 TALLOC_CTX *mem_ctx = talloc_stackframe(); 791 865 struct registry_key *key = NULL; 792 866 793 werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,794 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)) { 796 870 ret = true; 797 871 } … … 804 878 * Add a service if it does not already exist - registry version 805 879 */ 806 static WERRORsmbconf_reg_create_share(struct smbconf_ctx *ctx,880 static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx, 807 881 const char *servicename) 808 882 { 809 WERROR werr;883 sbcErr err; 810 884 struct registry_key *key = NULL; 811 885 812 886 if (servicename == NULL) { 813 return WERR_OK;814 } 815 816 werr = smbconf_reg_create_service_key(talloc_tos(), ctx,817 887 return SBC_ERR_OK; 888 } 889 890 err = smbconf_reg_create_service_key(talloc_tos(), ctx, 891 servicename, &key); 818 892 819 893 talloc_free(key); 820 return werr;894 return err; 821 895 } 822 896 … … 824 898 * get a definition of a share (service) from configuration. 825 899 */ 826 static WERRORsmbconf_reg_get_share(struct smbconf_ctx *ctx,900 static sbcErr smbconf_reg_get_share(struct smbconf_ctx *ctx, 827 901 TALLOC_CTX *mem_ctx, 828 902 const char *servicename, 829 903 struct smbconf_service **service) 830 904 { 831 WERROR werr = WERR_OK;905 sbcErr err; 832 906 struct registry_key *key = NULL; 833 907 struct smbconf_service *tmp_service = NULL; 834 908 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 835 909 836 werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,837 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)) { 839 913 goto done; 840 914 } … … 842 916 tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service); 843 917 if (tmp_service == NULL) { 844 werr = WERR_NOMEM;918 err = SBC_ERR_NOMEM; 845 919 goto done; 846 920 } … … 849 923 tmp_service->name = talloc_strdup(tmp_service, servicename); 850 924 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)) { 862 935 *service = talloc_move(mem_ctx, &tmp_service); 863 936 } … … 865 938 done: 866 939 talloc_free(tmp_ctx); 867 return werr;940 return err; 868 941 } 869 942 … … 871 944 * delete a service from configuration 872 945 */ 873 static WERRORsmbconf_reg_delete_share(struct smbconf_ctx *ctx,946 static sbcErr smbconf_reg_delete_share(struct smbconf_ctx *ctx, 874 947 const char *servicename) 875 948 { 876 WERROR werr = WERR_OK; 949 WERROR werr; 950 sbcErr err = SBC_ERR_OK; 877 951 TALLOC_CTX *mem_ctx = talloc_stackframe(); 878 952 879 953 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 } 882 958 } else { 883 werr = smbconf_reg_delete_values(rpd(ctx)->base_key);959 err = smbconf_reg_delete_values(rpd(ctx)->base_key); 884 960 } 885 961 886 962 talloc_free(mem_ctx); 887 return werr;963 return err; 888 964 } 889 965 … … 891 967 * set a configuration parameter to the value provided. 892 968 */ 893 static WERRORsmbconf_reg_set_parameter(struct smbconf_ctx *ctx,969 static sbcErr smbconf_reg_set_parameter(struct smbconf_ctx *ctx, 894 970 const char *service, 895 971 const char *param, 896 972 const char *valstr) 897 973 { 898 WERROR werr;974 sbcErr err; 899 975 struct registry_key *key = NULL; 900 976 TALLOC_CTX *mem_ctx = talloc_stackframe(); 901 977 902 werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,903 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); 909 985 910 986 done: 911 987 talloc_free(mem_ctx); 912 return werr;988 return err; 913 989 } 914 990 … … 916 992 * get the value of a configuration parameter as a string 917 993 */ 918 static WERRORsmbconf_reg_get_parameter(struct smbconf_ctx *ctx,994 static sbcErr smbconf_reg_get_parameter(struct smbconf_ctx *ctx, 919 995 TALLOC_CTX *mem_ctx, 920 996 const char *service, … … 923 999 { 924 1000 WERROR werr = WERR_OK; 1001 sbcErr err; 925 1002 struct registry_key *key = NULL; 926 1003 struct registry_value *value = NULL; 927 1004 928 werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,929 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)) { 931 1008 goto done; 932 1009 } 933 1010 934 1011 if (!smbconf_reg_valname_valid(param)) { 935 werr = WERR_INVALID_PARAM;1012 err = SBC_ERR_INVALID_PARAM; 936 1013 goto done; 937 1014 } 938 1015 939 1016 if (!smbconf_value_exists(key, param)) { 940 werr = WERR_INVALID_PARAM;1017 err = SBC_ERR_INVALID_PARAM; 941 1018 goto done; 942 1019 } … … 944 1021 werr = reg_queryvalue(mem_ctx, key, param, &value); 945 1022 if (!W_ERROR_IS_OK(werr)) { 1023 err = SBC_ERR_NOMEM; 946 1024 goto done; 947 1025 } 948 1026 949 1027 *valstr = smbconf_format_registry_value(mem_ctx, value); 950 951 1028 if (*valstr == NULL) { 952 werr = WERR_NOMEM;1029 err = SBC_ERR_NOMEM; 953 1030 } 954 1031 … … 956 1033 talloc_free(key); 957 1034 talloc_free(value); 958 return werr;1035 return err; 959 1036 } 960 1037 … … 962 1039 * delete a parameter from configuration 963 1040 */ 964 static WERRORsmbconf_reg_delete_parameter(struct smbconf_ctx *ctx,1041 static sbcErr smbconf_reg_delete_parameter(struct smbconf_ctx *ctx, 965 1042 const char *service, 966 1043 const char *param) 967 1044 { 968 1045 struct registry_key *key = NULL; 969 WERROR werr = WERR_OK; 1046 WERROR werr; 1047 sbcErr err; 970 1048 TALLOC_CTX *mem_ctx = talloc_stackframe(); 971 1049 972 werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,973 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)) { 975 1053 goto done; 976 1054 } 977 1055 978 1056 if (!smbconf_reg_valname_valid(param)) { 979 werr = WERR_INVALID_PARAM;1057 err = SBC_ERR_INVALID_PARAM; 980 1058 goto done; 981 1059 } 982 1060 983 1061 if (!smbconf_value_exists(key, param)) { 984 werr = WERR_INVALID_PARAM;1062 err = SBC_ERR_OK; 985 1063 goto done; 986 1064 } 987 1065 988 1066 werr = reg_deletevalue(key, param); 1067 if (!W_ERROR_IS_OK(werr)) { 1068 err = SBC_ERR_ACCESS_DENIED; 1069 } 989 1070 990 1071 done: 991 1072 talloc_free(mem_ctx); 992 return werr;993 } 994 995 static WERRORsmbconf_reg_get_includes(struct smbconf_ctx *ctx,1073 return err; 1074 } 1075 1076 static sbcErr smbconf_reg_get_includes(struct smbconf_ctx *ctx, 996 1077 TALLOC_CTX *mem_ctx, 997 1078 const char *service, … … 999 1080 char ***includes) 1000 1081 { 1001 WERROR werr;1082 sbcErr err; 1002 1083 struct registry_key *key = NULL; 1003 1084 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 1004 1085 1005 werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,1006 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, 1012 1093 includes); 1094 if (!SBC_ERROR_IS_OK(err)) { 1095 goto done; 1096 } 1013 1097 1014 1098 done: 1015 1099 talloc_free(tmp_ctx); 1016 return werr;1017 } 1018 1019 static WERRORsmbconf_reg_set_includes(struct smbconf_ctx *ctx,1100 return err; 1101 } 1102 1103 static sbcErr smbconf_reg_set_includes(struct smbconf_ctx *ctx, 1020 1104 const char *service, 1021 1105 uint32_t num_includes, … … 1023 1107 { 1024 1108 WERROR werr = WERR_OK; 1109 sbcErr err; 1025 1110 struct registry_key *key = NULL; 1026 1111 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 1027 1112 1028 werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,1029 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)) { 1031 1116 goto done; 1032 1117 } … … 1034 1119 if (num_includes == 0) { 1035 1120 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) { 1121 err = SBC_ERR_OK; 1036 1122 goto done; 1037 1123 } 1038 1124 werr = reg_deletevalue(key, INCLUDES_VALNAME); 1125 if (!W_ERROR_IS_OK(werr)) { 1126 err = SBC_ERR_ACCESS_DENIED; 1127 goto done; 1128 } 1039 1129 } else { 1040 werr = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME,1130 err = smbconf_reg_set_multi_sz_value(key, INCLUDES_VALNAME, 1041 1131 num_includes, includes); 1042 1132 } … … 1044 1134 done: 1045 1135 talloc_free(tmp_ctx); 1046 return werr;1047 } 1048 1049 static WERRORsmbconf_reg_delete_includes(struct smbconf_ctx *ctx,1136 return err; 1137 } 1138 1139 static sbcErr smbconf_reg_delete_includes(struct smbconf_ctx *ctx, 1050 1140 const char *service) 1051 1141 { 1052 WERROR werr = WERR_OK; 1142 WERROR werr; 1143 sbcErr err; 1053 1144 struct registry_key *key = NULL; 1054 1145 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 1055 1146 1056 werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,1057 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)) { 1059 1150 goto done; 1060 1151 } 1061 1152 1062 1153 if (!smbconf_value_exists(key, INCLUDES_VALNAME)) { 1154 err = SBC_ERR_OK; 1063 1155 goto done; 1064 1156 } 1065 1157 1066 1158 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; 1069 1165 done: 1070 1166 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 1170 static 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 1182 static 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 1194 static 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; 1087 1204 } 1088 1205 … … 1117 1234 * the only function that is exported from this module 1118 1235 */ 1119 WERRORsmbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,1236 sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, 1120 1237 const char *path) 1121 1238 { -
trunk/server/source3/lib/smbconf/smbconf_reg.h
r414 r745 27 27 */ 28 28 29 WERRORsmbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,29 sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx, 30 30 const char *path); 31 31 -
trunk/server/source3/lib/smbconf/testsuite.c
r414 r745 19 19 20 20 #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" 21 26 22 27 static void print_strings(const char *prefix, … … 36 41 static bool test_get_includes(struct smbconf_ctx *ctx) 37 42 { 38 WERROR werr;43 sbcErr err; 39 44 bool ret = false; 40 45 uint32_t num_includes = 0; … … 43 48 44 49 printf("TEST: get_includes\n"); 45 werr = smbconf_get_global_includes(ctx, mem_ctx,46 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)); 49 54 goto done; 50 55 } … … 64 69 static bool test_set_get_includes(struct smbconf_ctx *ctx) 65 70 { 66 WERROR werr;71 sbcErr err; 67 72 uint32_t count; 68 73 bool ret = false; … … 78 83 printf("TEST: set_get_includes\n"); 79 84 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)) { 82 87 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 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)) { 90 95 printf("FAIL: get_set_includes (getting includes) - %s\n", 91 win_errstr(werr));96 sbcErrorString(err)); 92 97 goto done; 93 98 } … … 121 126 static bool test_delete_includes(struct smbconf_ctx *ctx) 122 127 { 123 WERROR werr;128 sbcErr err; 124 129 bool ret = false; 125 130 const char *set_includes[] = { … … 133 138 printf("TEST: delete_includes\n"); 134 139 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)) { 137 142 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)) { 144 149 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 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)) { 152 157 printf("FAIL: delete_includes (getting includes) - %s\n", 153 win_errstr(werr));158 sbcErrorString(err)); 154 159 goto done; 155 160 } … … 160 165 } 161 166 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)) { 164 169 printf("FAIL: delete_includes (delete empty includes) - " 165 "%s\n", win_errstr(werr));170 "%s\n", sbcErrorString(err)); 166 171 goto done; 167 172 } … … 199 204 static bool torture_smbconf_txt(void) 200 205 { 201 WERROR werr;206 sbcErr err; 202 207 bool ret = true; 203 208 const char *filename = "/tmp/smb.conf.smbconf_testsuite"; … … 213 218 214 219 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)); 218 223 ret = false; 219 224 goto done; … … 241 246 static bool torture_smbconf_reg(void) 242 247 { 243 WERROR werr;248 sbcErr err; 244 249 bool ret = true; 245 250 struct smbconf_ctx *conf_ctx = NULL; … … 249 254 250 255 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)); 254 259 ret = false; 255 260 goto done; … … 290 295 291 296 load_case_tables(); 292 dbf = x_stderr;297 setup_logging(argv[0], DEBUG_STDERR); 293 298 294 299 /* parse options */ -
trunk/server/source3/lib/smbldap.c
r620 r745 25 25 #include "includes.h" 26 26 #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" 31 29 32 30 /* Try not to hit the up or down server forever */ … … 508 506 ***********************************************************************/ 509 507 510 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value)508 static void smbldap_set_mod_internal(LDAPMod *** modlist, int modop, const char *attribute, const char *value, const DATA_BLOB *blob) 511 509 { 512 510 LDAPMod **mods; … … 559 557 } 560 558 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) { 562 580 char *utf8_value = NULL; 563 581 size_t converted_size; … … 586 604 } 587 605 *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); 588 616 } 589 617 … … 593 621 *********************************************************************/ 594 622 595 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing, 596 LDAPMod ***mods, 597 const char *attribute, const char *newval) 623 static 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) 598 628 { 599 629 char oldval[2048]; /* current largest allowed value is mungeddial */ 600 630 bool existed; 631 DATA_BLOB oldblob = data_blob_null; 601 632 602 633 if (attribute == NULL) { … … 607 638 608 639 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 } 610 645 } else { 611 646 existed = False; … … 613 648 } 614 649 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 and620 an add at the same time if the values are the621 same... */622 DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute));623 return;624 }625 626 650 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 627 667 /* There has been no value before, so don't delete it. 628 668 * Here's a possible race: We might end up with … … 636 676 * you could add new value */ 637 677 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 } 640 685 } 641 686 … … 644 689 the old value, should it exist. */ 645 690 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); 650 718 } 651 719 … … 745 813 *******************************************************************/ 746 814 747 int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri)815 static int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri) 748 816 { 749 817 int rc; … … 849 917 *******************************************************************/ 850 918 851 int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version) 919 static int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version) 852 920 { 853 921 int version; … … 962 1030 { 963 1031 struct smbldap_state *ldap_state = arg; 1032 struct timespec ts; 964 1033 965 1034 /** @TODO Should we be doing something to check what servers we rebind to? … … 994 1063 } 995 1064 996 GetTimeOfDay(&ldap_state->last_rebind); 1065 clock_gettime_mono(&ts); 1066 ldap_state->last_rebind = convert_timespec_to_timeval(ts); 997 1067 998 1068 return 0; … … 1014 1084 (struct smbldap_state *)arg; 1015 1085 int rc; 1086 struct timespec ts; 1016 1087 int version; 1017 1088 … … 1046 1117 "setting last_rebind timestamp " 1047 1118 "(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); 1049 1121 break; 1050 1122 default: … … 1179 1251 static void smbldap_idle_fn(struct event_context *event_ctx, 1180 1252 struct timed_event *te, 1181 struct timeval now ,1253 struct timeval now_abs, 1182 1254 void *private_data); 1183 1255 … … 1191 1263 SMB_ASSERT(ldap_state); 1192 1264 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))) { 1194 1266 1195 1267 #ifdef HAVE_UNIXSOCKET … … 1215 1287 ldap_state->last_ping = (time_t)0; 1216 1288 } else { 1217 ldap_state->last_ping = time (NULL);1289 ldap_state->last_ping = time_mono(NULL); 1218 1290 } 1219 1291 } … … 1233 1305 1234 1306 1235 ldap_state->last_ping = time (NULL);1307 ldap_state->last_ping = time_mono(NULL); 1236 1308 ldap_state->pid = sys_getpid(); 1237 1309 … … 1285 1357 int *attempts, time_t endtime) 1286 1358 { 1287 time_t now = time (NULL);1359 time_t now = time_mono(NULL); 1288 1360 int open_rc = LDAP_SERVER_DOWN; 1289 1361 … … 1358 1430 int attempts = 0; 1359 1431 char *utf8_filter; 1360 time_t endtime = time (NULL)+lp_ldap_timeout();1432 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1361 1433 struct timeval timeout; 1362 1434 size_t converted_size; … … 1369 1441 if (ldap_state->last_rebind.tv_sec > 0) { 1370 1442 struct timeval tval; 1443 struct timespec ts; 1371 1444 int64_t tdiff = 0; 1372 1445 int sleep_time = 0; 1373 1446 1374 ZERO_STRUCT(tval);1375 GetTimeOfDay(&tval);1447 clock_gettime_mono(&ts); 1448 tval = convert_timespec_to_timeval(ts); 1376 1449 1377 1450 tdiff = usec_time_diff(&tval, &ldap_state->last_rebind); … … 1407 1480 1408 1481 got_alarm = 0; 1409 CatchSignal(SIGALRM, SIGNAL_CASTgotalarm_sig);1482 CatchSignal(SIGALRM, gotalarm_sig); 1410 1483 alarm(lp_ldap_timeout()); 1411 1484 /* End setup timeout. */ … … 1442 1515 1443 1516 /* Teardown timeout. */ 1444 CatchSignal(SIGALRM, SIG NAL_CAST SIG_IGN);1517 CatchSignal(SIGALRM, SIG_IGN); 1445 1518 alarm(0); 1446 1519 … … 1556 1629 int attempts = 0; 1557 1630 char *utf8_dn; 1558 time_t endtime = time (NULL)+lp_ldap_timeout();1631 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1559 1632 size_t converted_size; 1560 1633 … … 1600 1673 int attempts = 0; 1601 1674 char *utf8_dn; 1602 time_t endtime = time (NULL)+lp_ldap_timeout();1675 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1603 1676 size_t converted_size; 1604 1677 … … 1644 1717 int attempts = 0; 1645 1718 char *utf8_dn; 1646 time_t endtime = time (NULL)+lp_ldap_timeout();1719 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1647 1720 size_t converted_size; 1648 1721 … … 1690 1763 int rc = LDAP_SERVER_DOWN; 1691 1764 int attempts = 0; 1692 time_t endtime = time (NULL)+lp_ldap_timeout();1765 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1693 1766 1694 1767 if (!ldap_state) … … 1737 1810 static void smbldap_idle_fn(struct event_context *event_ctx, 1738 1811 struct timed_event *te, 1739 struct timeval now ,1812 struct timeval now_abs, 1740 1813 void *private_data) 1741 1814 { … … 1749 1822 } 1750 1823 1751 if ((state->last_use+SMBLDAP_IDLE_TIME) > now.tv_sec) {1824 if ((state->last_use+SMBLDAP_IDLE_TIME) > time_mono(NULL)) { 1752 1825 DEBUG(10,("ldap connection not idle...\n")); 1753 1826 1827 /* this needs to be made monotonic clock aware inside tevent: */ 1754 1828 state->idle_event = event_add_timed( 1755 1829 event_ctx, state, 1756 timeval_add(&now , SMBLDAP_IDLE_TIME, 0),1830 timeval_add(&now_abs, SMBLDAP_IDLE_TIME, 0), 1757 1831 smbldap_idle_fn, 1758 1832 private_data); -
trunk/server/source3/lib/smbldap_util.c
r414 r745 25 25 #include "includes.h" 26 26 #include "smbldap.h" 27 #include "passdb.h" 27 28 28 29 /********************************************************************** -
trunk/server/source3/lib/substitute.c
r414 r745 4 4 Copyright (C) Andrew Tridgell 1992-2000 5 5 Copyright (C) Gerald Carter 2006 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 21 21 22 22 #include "includes.h" 23 #include "system/passwd.h" 24 #include "secrets.h" 25 #include "auth.h" 26 27 static char *alloc_sub_basic(const char *smb_name, const char *domain_name, 28 const char *str); 23 29 24 30 userdom_struct current_user_info; … … 42 48 static bool already_perm = false; 43 49 char *tmp_local_machine = NULL; 44 char addr[INET6_ADDRSTRLEN];45 50 size_t len; 51 52 if (already_perm) { 53 return true; 54 } 46 55 47 56 tmp_local_machine = SMB_STRDUP(local_name); … … 50 59 } 51 60 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 }70 61 71 62 SAFE_FREE(local_machine); … … 202 193 smb_user_name[len-1] = '$'; 203 194 } 195 } 196 197 static char sub_peeraddr[INET6_ADDRSTRLEN]; 198 static const char *sub_peername = ""; 199 static char sub_sockaddr[INET6_ADDRSTRLEN]; 200 201 void 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)); 204 222 } 205 223 … … 277 295 r = p + 3; 278 296 copylen = q - r; 279 297 280 298 /* reserve space for use later add %$() chars */ 281 299 if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) { 282 300 return NULL; 283 301 } 284 302 285 303 strncpy(envname,r,copylen); 286 304 envname[copylen] = '\0'; … … 302 320 r = realloc_string_sub(str, envname, envval); 303 321 SAFE_FREE(envname); 304 322 305 323 return r; 306 324 } … … 311 329 static char *longvar_domainsid( void ) 312 330 { 313 DOM_SIDsid;331 struct dom_sid sid; 314 332 fstring tmp; 315 333 char *sid_string; 316 334 317 335 if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) { 318 336 return NULL; 319 337 } 320 338 321 339 sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) ); 322 340 323 341 if ( !sid_string ) { 324 342 DEBUG(0,("longvar_domainsid: failed to dup SID string!\n")); 325 343 } 326 344 327 345 return sid_string; 328 346 } … … 344 362 { 345 363 int i; 346 364 347 365 DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname)); 348 366 349 367 for ( i=0; longvar_table[i].name; i++ ) { 350 368 if ( strequal( longvar_table[i].name, varname ) ) { … … 352 370 } 353 371 } 354 372 355 373 return NULL; 356 374 } … … 516 534 { 517 535 char *s; 518 536 519 537 if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) { 520 538 strncpy( str, s, len ); 521 539 } 522 540 523 541 SAFE_FREE( s ); 524 525 542 } 526 543 … … 534 551 { 535 552 char *a, *t; 536 553 537 554 if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) { 538 555 return NULL; … … 546 563 ****************************************************************************/ 547 564 548 char *alloc_sub_basic(const char *smb_name, const char *domain_name,549 565 static char *alloc_sub_basic(const char *smb_name, const char *domain_name, 566 const char *str) 550 567 { 551 568 char *b, *p, *s, *r, *a_string; 552 569 fstring pidstr, vnnstr; 553 char addr[INET6_ADDRSTRLEN];554 570 const char *local_machine_name = get_local_machine_name(); 555 571 TALLOC_CTX *tmp_ctx = NULL; 556 572 557 573 /* workaround to prevent a crash while looking at bug #687 */ 558 574 559 575 if (!str) { 560 576 DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n")); 561 577 return NULL; 562 578 } 563 579 564 580 a_string = SMB_STRDUP(str); 565 581 if (a_string == NULL) { … … 606 622 break; 607 623 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"); 615 627 break; 616 628 } 617 629 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"); 620 633 break; 621 634 case 'L' : … … 633 646 break; 634 647 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); 636 650 break; 637 651 case 'R' : … … 723 737 goto done; 724 738 } 725 739 726 740 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { 727 741 728 742 b = a_string; 729 743 730 744 switch (*(p+1)) { 731 745 case 'U' : … … 803 817 return NULL; 804 818 } 805 819 806 820 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { 807 821 808 822 b = a_string; 809 823 810 824 switch (*(p+1)) { 811 825 case 'N' : … … 831 845 a_string = realloc_string_sub(a_string, "%u", user); 832 846 break; 833 847 834 848 /* Patch from jkf@soton.ac.uk Left the %N (NIS 835 849 * server name) in standard_sub_basic as it is … … 843 857 automount_path(servicename)); 844 858 break; 845 859 846 860 default: 847 861 break; … … 906 920 return talloc_sub_advanced(ctx, 907 921 lp_servicename(SNUM(conn)), 908 conn->se rver_info->unix_name,922 conn->session_info->unix_name, 909 923 conn->connectpath, 910 conn->se rver_info->utok.gid,924 conn->session_info->utok.gid, 911 925 get_smb_user_name(), 912 926 "", -
trunk/server/source3/lib/sysacls.c
r414 r745 21 21 22 22 #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 23 44 24 45 #undef DBGC_CLASS -
trunk/server/source3/lib/sysquotas.c
r414 r745 178 178 {"xfs", sys_get_xfs_quota, sys_set_xfs_quota}, 179 179 #endif /* HAVE_XFS_QUOTAS */ 180 #ifdef HAVE_NFS_QUOTAS 181 {"nfs", sys_get_nfs_quota, sys_set_nfs_quota}, 182 #endif /* HAVE_NFS_QUOTAS */ 180 183 {NULL, NULL, NULL} 181 184 }; … … 301 304 DEBUG (3, ("Parsed output of get_quota, ...\n")); 302 305 303 #ifdef LARGE_SMB_OFF_T304 306 DEBUGADD (5,( 305 307 "qflags:%u curblocks:%llu softlimit:%llu hardlimit:%llu\n" … … 310 312 (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit, 311 313 (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 */322 314 return 0; 323 315 } … … 360 352 } 361 353 362 #ifdef LARGE_SMB_OFF_T363 354 if (asprintf(&syscmd, 364 355 "%s \"%s\" %d %d " … … 371 362 return -1; 372 363 } 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 */385 364 386 365 DEBUG (3, ("get_quota: Running command %s\n", syscmd)); -
trunk/server/source3/lib/system.c
r590 r745 22 22 23 23 #include "includes.h" 24 #include "system/syslog.h" 25 #include "system/capability.h" 26 #include "system/passwd.h" 27 #include "system/filesys.h" 24 28 25 29 #ifdef HAVE_SYS_PRCTL_H 26 30 #include <sys/prctl.h> 31 #endif 32 #ifdef __OS2__ 33 #define pipe(A) os2_pipe(A) 27 34 #endif 28 35 … … 124 131 do { 125 132 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 127 138 return ret; 128 139 } … … 138 149 do { 139 150 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 141 156 return ret; 142 157 } … … 163 178 do { 164 179 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 166 185 return ret; 167 186 } … … 208 227 209 228 /******************************************************************* 210 A send wrapper that will deal with EINTR .229 A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK. 211 230 ********************************************************************/ 212 231 … … 217 236 do { 218 237 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 /******************************************************************* 247 A sendto wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK. 225 248 ********************************************************************/ 226 249 … … 231 254 do { 232 255 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 /******************************************************************* 265 A recv wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK. 239 266 ********************************************************************/ 240 267 … … 245 272 do { 246 273 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 248 279 return ret; 249 280 } … … 259 290 do { 260 291 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 262 297 return ret; 263 298 } … … 637 672 #elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE) 638 673 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; 639 699 #else 640 700 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 712 int 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; 641 736 #endif 642 737 } … … 743 838 } 744 839 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 745 849 746 850 /******************************************************************* … … 778 882 #else 779 883 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 893 SMB_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; 780 902 #endif 781 903 } … … 1033 1155 } 1034 1156 1157 #ifndef NGROUPS_MAX 1158 #define NGROUPS_MAX 32 /* Guess... */ 1159 #endif 1160 1035 1161 /************************************************************************** 1036 1162 Returns equivalent to NGROUPS_MAX - using sysconf if needed. … … 1053 1179 1054 1180 #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 1055 1188 static int sys_broken_getgroups(int setlen, gid_t *gidset) 1056 1189 { … … 1232 1365 1233 1366 /************************************************************************** 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 /**************************************************************************1278 1367 Extract a command into an arg list. 1279 1368 ****************************************************************************/ … … 1442 1531 1443 1532 SAFE_FREE(entry); 1444 SAFE_FREE(argl);1533 TALLOC_FREE(argl); 1445 1534 close(pipe_fds[0]); 1446 1535 close(pipe_fds[1]); … … 1774 1863 } 1775 1864 /* 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); 1777 1866 1778 1867 for(i = 0; i < list_size; i += len + 1) { … … 2583 2672 } 2584 2673 #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 #else2606 errno = ENOSYS;2607 return -1;2608 #endif2609 }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 the2621 * 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 #endif2631 }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 #endif2649 2650 return connect(fd, addr, salen);2651 } -
trunk/server/source3/lib/system_smbd.c
r599 r745 25 25 26 26 #include "includes.h" 27 #include "system/passwd.h" 28 #include "nsswitch/winbind_client.h" 27 29 28 30 #ifndef HAVE_GETGROUPLIST … … 120 122 } 121 123 122 if (initgroups(user, gid) != 0) {124 if (initgroups(user, gid) == -1) { 123 125 DEBUG(0, ("getgrouplist_internals: initgroups() failed!\n")); 124 126 SAFE_FREE(gids_saved); … … 206 208 bool getgroups_unix_user(TALLOC_CTX *mem_ctx, const char *user, 207 209 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; 211 213 int max_grp; 212 214 gid_t *temp_groups; -
trunk/server/source3/lib/talloc_dict.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "dbwrap.h" 22 #include "talloc_dict.h" 23 #include "util_tdb.h" 21 24 22 25 struct talloc_dict { -
trunk/server/source3/lib/tallocmsg.c
r414 r745 2 2 samba -- Unix SMB/CIFS implementation. 3 3 Copyright (C) 2001, 2002 by Martin Pool 4 4 5 5 This program is free software; you can redistribute it and/or modify 6 6 it under the terms of the GNU General Public License as published by 7 7 the Free Software Foundation; either version 3 of the License, or 8 8 (at your option) any later version. 9 9 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU General Public License for more details. 14 14 15 15 You should have received a copy of the GNU General Public License 16 16 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 18 18 19 19 #include "includes.h" 20 #include "messages.h" 20 21 21 22 /** … … 52 53 } 53 54 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 54 72 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen, 55 73 "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n", … … 74 92 75 93 SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE); 76 94 77 95 DEBUG(2,("Got POOL_USAGE\n")); 78 96 … … 91 109 return; 92 110 } 93 111 94 112 messaging_send_buf(msg_ctx, src, MSG_POOL_USAGE, 95 113 (uint8 *)state.s, strlen(state.s)+1); -
trunk/server/source3/lib/tdb_validate.c
r590 r745 20 20 */ 21 21 22 #include "includes.h" 23 #include "system/filesys.h" 24 #include "util_tdb.h" 22 25 #include "tdb_validate.h" 23 #include "includes.h"24 26 25 27 /* … … 282 284 283 285 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 284 291 unlink(tmp_path); 285 292 dst_tdb = tdb_open_log(tmp_path, … … 356 363 357 364 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 } 358 369 359 370 ret = (rename(path, dst_path) != 0); … … 395 406 char *rotate_path = talloc_asprintf(ctx, "%s%s", dst_path, 396 407 rotate_suffix); 408 if (rotate_path == NULL) { 409 DEBUG(10, ("talloc fail\n")); 410 return -1; 411 } 397 412 DEBUG(10, ("backup of %s failed due to lack of space\n", 398 413 src_path)); … … 451 466 452 467 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 } 453 472 454 473 ret = tdb_validate_open(tdb_path, validate_fn); -
trunk/server/source3/lib/tdb_validate.h
r414 r745 24 24 25 25 #include "lib/replace/replace.h" 26 #include "tdb.h"26 #include <tdb.h> 27 27 28 28 /** -
trunk/server/source3/lib/time.c
r480 r745 37 37 #endif 38 38 39 /*******************************************************************40 create a 16 bit dos packed date41 ********************************************************************/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 time52 ********************************************************************/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 parameters63 This takes a GMT time and returns a packed localtime structure64 ********************************************************************/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 }86 39 87 40 /** … … 98 51 **************************************************************/ 99 52 100 uint32_t convert_time_t_to_uint32 (time_t t)53 uint32_t convert_time_t_to_uint32_t(time_t t) 101 54 { 102 55 #if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8)) … … 111 64 } 112 65 113 time_t convert_uint32_t o_time_t(uint32_t u)66 time_t convert_uint32_t_to_time_t(uint32_t u) 114 67 { 115 68 #if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8)) … … 177 130 } 178 131 179 /****************************************************************************180 Return the date and time as a string181 ****************************************************************************/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_STRFTIME206 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 #else216 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 #endif228 }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 takes265 GMT and converts it to LOCAL time before putting it (most SMBs assume266 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 278 132 /*************************************************************************** 279 133 Server versions of the above functions. … … 282 136 void srv_put_dos_date(char *buf,int offset,time_t unixdate) 283 137 { 284 pu t_dos_date(buf, offset, unixdate, server_zone_offset);138 push_dos_date((uint8_t *)buf, offset, unixdate, server_zone_offset); 285 139 } 286 140 287 141 void srv_put_dos_date2(char *buf,int offset, time_t unixdate) 288 142 { 289 pu t_dos_date2(buf, offset, unixdate, server_zone_offset);143 push_dos_date2((uint8_t *)buf, offset, unixdate, server_zone_offset); 290 144 } 291 145 292 146 void srv_put_dos_date3(char *buf,int offset,time_t unixdate) 293 147 { 294 pu t_dos_date3(buf, offset, unixdate, server_zone_offset);148 push_dos_date3((uint8_t *)buf, offset, unixdate, server_zone_offset); 295 149 } 296 150 … … 343 197 ********************************************************************/ 344 198 345 statictime_t make_unix_date(const void *date_ptr, int zone_offset)199 time_t make_unix_date(const void *date_ptr, int zone_offset) 346 200 { 347 201 uint32_t dos_date=0; … … 389 243 { 390 244 time_t t = (time_t)IVAL(date_ptr,0); 391 if (!null_ mtime(t)) {245 if (!null_time(t)) { 392 246 t += zone_offset; 393 247 } … … 440 294 struct timespec timespec_current(void) 441 295 { 442 struct timeval tv;443 296 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); 447 298 return ts; 448 299 } … … 496 347 struct timeval tv = convert_timespec_to_timeval(*ts); 497 348 *ts = convert_timeval_to_timespec(tv); 349 while (ts->tv_nsec > 1000000000) { 350 ts->tv_sec += 1; 351 ts->tv_nsec -= 1000000000; 352 } 498 353 } 499 354 … … 517 372 } 518 373 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 562 374 /******************************************************************* 563 375 Re-read the smb serverzone value. … … 598 410 } 599 411 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 */ 418 void 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 600 425 /**************************************************************************** 601 426 Convert a NTTIME structure to a time_t. … … 740 565 741 566 /**************************************************************************** 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 /****************************************************************************753 567 Utility function that always returns a const string even if localtime 754 568 and asctime fail. -
trunk/server/source3/lib/tldap.c
r414 r745 19 19 20 20 #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 26 static int tldap_simple_recv(struct tevent_req *req); 21 27 22 28 bool tevent_req_is_ldap_error(struct tevent_req *req, int *perr) … … 419 425 } 420 426 421 state->iov.iov_base = blob.data;427 state->iov.iov_base = (void *)blob.data; 422 428 state->iov.iov_len = blob.length; 423 429 … … 506 512 507 513 /* 508 * We're the first one s, add the read_ldap request that waits for the514 * We're the first one, add the read_ldap request that waits for the 509 515 * answer from the server 510 516 */ … … 555 561 struct tevent_req *req; 556 562 struct tldap_msg_state *state; 557 struct tevent_context *ev;558 563 struct asn1_data *data; 559 564 uint8_t *inbuf; … … 614 619 state->data = talloc_move(state, &data); 615 620 616 ev = state->ev;617 618 621 talloc_set_destructor(req, NULL); 619 622 tldap_msg_unset_pending(req); … … 734 737 { 735 738 char *result = talloc_array(mem_ctx, char, blob.length+1); 739 740 if (result == NULL) { 741 return NULL; 742 } 743 736 744 memcpy(result, blob.data, blob.length); 737 745 result[blob.length] = '\0'; … … 741 749 static bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx, 742 750 struct asn1_data *data, 743 char ** result)751 char **presult) 744 752 { 745 753 DATA_BLOB string; 754 char *result; 746 755 if (!asn1_read_OctetString(data, mem_ctx, &string)) 747 756 return false; 748 *result = blob2string_talloc(mem_ctx, string); 757 758 result = blob2string_talloc(mem_ctx, string); 759 749 760 data_blob_free(&string); 761 762 if (result == NULL) { 763 return false; 764 } 765 *presult = result; 750 766 return true; 751 767 } … … 869 885 int tldap_sasl_bind_recv(struct tevent_req *req) 870 886 { 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); 877 888 } 878 889 … … 957 968 /*****************************************************************************/ 958 969 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 972 static bool tldap_is_alpha(char c) 973 { 974 return (((c >= 'a') && (c <= 'z')) || \ 975 ((c >= 'A') && (c <= 'Z'))); 976 } 977 978 static 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. 962 1003 */ 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 { 1004 static bool tldap_is_attrdesc(const char *s, int len, bool no_tagopts) 1005 { 1006 bool is_oid = false; 1007 bool dot = false; 970 1008 int i; 971 1009 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 */ 980 1042 return false; 981 1043 } 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. */ 1067 static 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 1090 static 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 1110 static 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 1149 static 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 1200 static bool tldap_push_filter_basic(struct tldap_context *ld, 1201 struct asn1_data *data, 1202 const char **_s); 1203 static bool tldap_push_filter_substring(struct tldap_context *ld, 1204 struct asn1_data *data, 1205 const char *val, 1206 const char **_s); 1207 static 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; 982 1243 } 983 1244 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) { 989 1261 return false; 990 1262 } 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 */ 991 1271 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 */ 1023 1283 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 1288 done: 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 1305 static 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 } 1032 1388 } else { 1033 ctx = 1; 1389 if (rule == e) { 1390 rule = NULL; 1391 } else { 1392 rule++; 1393 } 1034 1394 } 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 1083 1402 /* 1084 1403 MatchingRuleAssertion ::= SEQUENCE { 1085 1404 matchingRule [1] MatchingRuleID OPTIONAL, 1086 type 1405 type [2] AttributeDescription OPTIONAL, 1087 1406 matchValue [3] AssertionValue, 1088 1407 dnAttributes [4] BOOLEAN DEFAULT FALSE 1089 1408 } 1090 1409 */ 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 } 1093 1417 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); 1095 1419 asn1_pop_tag(data); 1096 1420 } 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 } 1098 1428 asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(2)); 1099 asn1_write _LDAPString(data, tree->u.extended.attr);1429 asn1_write(data, type, type_len); 1100 1430 asn1_pop_tag(data); 1101 1431 } 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 1102 1443 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); 1104 1445 asn1_pop_tag(data); 1446 1105 1447 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); 1107 1449 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 1514 static 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); 1108 1594 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 */ 1612 static 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"); 1112 1623 return false; 1113 1624 } 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);1128 1625 return ret; 1129 1626 } … … 1166 1663 asn1_write_BOOLEAN(state->out, attrsonly); 1167 1664 1168 if (!tldap_push_filter( state->out, filter)) {1665 if (!tldap_push_filter(ld, state->out, filter)) { 1169 1666 goto encoding_error; 1170 1667 } … … 1345 1842 tevent_req_set_callback(req, tldap_search_cb, &state); 1346 1843 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 1347 1851 while (tevent_req_is_in_progress(req) 1348 1852 && (state.rc == TLDAP_SUCCESS)) { … … 1455 1959 } 1456 1960 1457 bool tldap_entry_attributes(struct tldap_message *msg, int *num_attributes, 1458 struct tldap_attribute **attributes) 1961 bool tldap_entry_attributes(struct tldap_message *msg, 1962 struct tldap_attribute **attributes, 1963 int *num_attributes) 1459 1964 { 1460 1965 if ((msg->dn == NULL) && (!tldap_parse_search_entry(msg))) { … … 1628 2133 1629 2134 int 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, 1631 2136 struct tldap_control *sctrls, int num_sctrls, 1632 2137 struct tldap_control *cctrls, int num_cctrls) … … 1668 2173 struct tldap_context *ld, 1669 2174 const char *dn, 1670 int num_mods, struct tldap_mod *mods,2175 struct tldap_mod *mods, int num_mods, 1671 2176 struct tldap_control *sctrls, 1672 2177 int num_sctrls, … … 1728 2233 1729 2234 int 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, 1731 2236 struct tldap_control *sctrls, int num_sctrls, 1732 2237 struct tldap_control *cctrls, int num_cctrls) … … 1743 2248 } 1744 2249 1745 req = tldap_modify_send(frame, ev, ld, dn, num_mods,mods,2250 req = tldap_modify_send(frame, ev, ld, dn, mods, num_mods, 1746 2251 sctrls, num_sctrls, cctrls, num_cctrls); 1747 2252 if (req == NULL) { … … 1878 2383 *sctrls = NULL; 1879 2384 *num_sctrls = 0; 2385 return; 1880 2386 } 1881 2387 *sctrls = msg->res_sctrls; -
trunk/server/source3/lib/tldap_util.c
r414 r745 19 19 20 20 #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" 21 26 22 27 bool tldap_entry_values(struct tldap_message *msg, const char *attribute, 23 int *num_values, DATA_BLOB **values)28 DATA_BLOB **values, int *num_values) 24 29 { 25 30 struct tldap_attribute *attributes; 26 31 int i, num_attributes; 27 32 28 if (!tldap_entry_attributes(msg, & num_attributes, &attributes)) {33 if (!tldap_entry_attributes(msg, &attributes, &num_attributes)) { 29 34 return false; 30 35 } … … 52 57 return NULL; 53 58 } 54 if (!tldap_entry_values(msg, attribute, & num_values, &values)) {59 if (!tldap_entry_values(msg, attribute, &values, &num_values)) { 55 60 return NULL; 56 61 } … … 104 109 105 110 static 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) 107 112 { 108 113 int num_values = talloc_array_length(mod->values); … … 129 134 } 130 135 131 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods, 136 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, 137 struct tldap_mod **pmods, int *pnum_mods, 132 138 int mod_op, const char *attrib, 133 int num_newvals, DATA_BLOB *newvals)139 DATA_BLOB *newvals, int num_newvals) 134 140 { 135 141 struct tldap_mod new_mod; … … 145 151 } 146 152 147 num_mods = talloc_array_length(mods);153 num_mods = *pnum_mods; 148 154 149 155 for (i=0; i<num_mods; i++) { … … 167 173 168 174 if ((num_newvals != 0) 169 && !tldap_add_blob_vals(mods, mod, n um_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)) { 174 180 mods = talloc_realloc(talloc_tos(), mods, struct tldap_mod, 175 181 num_mods+1); … … 181 187 182 188 *pmods = mods; 189 *pnum_mods += 1; 183 190 return true; 184 191 } 185 192 186 bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods, 193 bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, 194 struct tldap_mod **pmods, int *pnum_mods, 187 195 int mod_op, const char *attrib, const char *str) 188 196 { … … 196 204 } 197 205 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); 199 208 TALLOC_FREE(utf8.data); 200 209 return ret; … … 203 212 static bool tldap_make_mod_blob_int(struct tldap_message *existing, 204 213 TALLOC_CTX *mem_ctx, 205 int *pnum_mods, struct tldap_mod **pmods,214 struct tldap_mod **pmods, int *pnum_mods, 206 215 const char *attrib, DATA_BLOB newval, 207 216 int (*comparison)(const DATA_BLOB *d1, … … 213 222 214 223 if ((existing != NULL) 215 && tldap_entry_values(existing, attrib, & num_values, &values)) {224 && tldap_entry_values(existing, attrib, &values, &num_values)) { 216 225 217 226 if (num_values > 1) { … … 229 238 an add at the same time if the values are the 230 239 same... */ 231 DEBUG(10,(" smbldap_make_mod_blob: attribute |%s| not "240 DEBUG(10,("tldap_make_mod_blob_int: attribute |%s| not " 232 241 "changed.\n", attrib)); 233 242 return true; … … 243 252 * then you could add new value */ 244 253 245 DEBUG(10, (" smbldap_make_mod_blob: deleting attribute |%s|\n",254 DEBUG(10, ("tldap_make_mod_blob_int: deleting attribute |%s|\n", 246 255 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)) { 249 259 return false; 250 260 } … … 256 266 257 267 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 " 259 269 "%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)) { 262 273 return false; 263 274 } 264 275 } 265 *pnum_mods = talloc_array_length(*pmods);266 276 return true; 267 277 } 268 278 269 279 bool 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, 271 281 const char *attrib, DATA_BLOB newval) 272 282 { 273 return tldap_make_mod_blob_int(existing, mem_ctx, p num_mods, pmods,283 return tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods, 274 284 attrib, newval, data_blob_cmp); 275 285 } … … 299 309 300 310 bool 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, 302 312 const char *attrib, const char *fmt, ...) 303 313 { … … 319 329 blob.data = CONST_DISCARD(uint8_t *, newval); 320 330 } 321 ret = tldap_make_mod_blob_int(existing, mem_ctx, p num_mods, pmods,331 ret = tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods, 322 332 attrib, blob, compare_utf8_blobs); 323 333 TALLOC_FREE(newval); … … 330 340 char *res; 331 341 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 } 333 345 res = talloc_asprintf(mem_ctx, "LDAP error %d (%s), %s", rc, 334 346 tldap_err2string(rc), … … 540 552 DATA_BLOB *values; 541 553 542 if (!tldap_entry_values(msg, attribute, & num_values, &values)) {554 if (!tldap_entry_values(msg, attribute, &values, &num_values)) { 543 555 return false; 544 556 } -
trunk/server/source3/lib/username.c
r414 r745 4 4 Copyright (C) Andrew Tridgell 1992-1998 5 5 Copyright (C) Jeremy Allison 1997-2001. 6 6 Copyright (C) Andrew Bartlett 2002 7 7 8 This program is free software; you can redistribute it and/or modify 8 9 it under the terms of the GNU General Public License as published by 9 10 the Free Software Foundation; either version 3 of the License, or 10 11 (at your option) any later version. 11 12 12 13 This program is distributed in the hope that it will be useful, 13 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 16 GNU General Public License for more details. 16 17 17 18 You should have received a copy of the GNU General Public License 18 19 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 20 21 21 22 #include "includes.h" 23 #include "system/passwd.h" 24 #include "memcache.h" 25 #include "../lib/util/util_pw.h" 22 26 23 27 /* internal functions */ … … 29 33 int N); 30 34 35 static 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 65 void flush_pwnam_cache(void) 66 { 67 memcache_flush(NULL, GETPWNAM_CACHE); 68 } 69 31 70 /**************************************************************************** 32 71 Get a users home directory. … … 76 115 strlower_m(user2); 77 116 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); 79 118 if(ret) 80 119 goto done; … … 84 123 DEBUG(5,("Trying _Get_Pwnam(), username as given is %s\n", 85 124 user)); 86 ret = getpwnam_alloc (mem_ctx, user);125 ret = getpwnam_alloc_cached(mem_ctx, user); 87 126 if(ret) 88 127 goto done; … … 94 133 DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n", 95 134 user2)); 96 ret = getpwnam_alloc (mem_ctx, user2);135 ret = getpwnam_alloc_cached(mem_ctx, user2); 97 136 if(ret) 98 137 goto done; … … 103 142 DEBUG(5,("Checking combinations of %d uppercase letters in %s\n", 104 143 lp_usernamelevel(), user2)); 105 ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc ,144 ret = uname_string_combinations(user2, mem_ctx, getpwnam_alloc_cached, 106 145 lp_usernamelevel()); 107 146 … … 122 161 { 123 162 fstring user2; 124 struct passwd *ret;125 163 126 164 if ( *user == '\0' ) { … … 133 171 DEBUG(5,("Finding user %s\n", user)); 134 172 135 ret = Get_Pwnam_internals(mem_ctx, user, user2); 136 137 return ret; 173 return Get_Pwnam_internals(mem_ctx, user, user2); 138 174 } 139 175 … … 161 197 for (i=offset;i<(len-(N-1));i++) { 162 198 char c = s[i]; 163 if (!islower_ ascii((int)c))199 if (!islower_m((int)c)) 164 200 continue; 165 s[i] = toupper_ ascii(c);201 s[i] = toupper_m(c); 166 202 ret = uname_string_combinations2(s, mem_ctx, i+1, fn, N-1); 167 203 if(ret) -
trunk/server/source3/lib/util.c
r599 r745 12 12 the Free Software Foundation; either version 3 of the License, or 13 13 (at your option) any later version. 14 14 15 15 This program is distributed in the hope that it will be useful, 16 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 18 GNU General Public License for more details. 19 19 20 20 You should have received a copy of the GNU General Public License 21 21 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 23 23 24 24 #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" 25 31 26 32 extern char *global_clobber_region_function; … … 74 80 ***********************************************************************/ 75 81 76 static char *smb_myname;77 static char *smb_myworkgroup;78 82 static char *smb_scope; 79 83 static int smb_num_netbios_names; 80 84 static 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 }119 85 120 86 /*********************************************************************** … … 185 151 void gfree_names(void) 186 152 { 187 SAFE_FREE( smb_myname ); 188 SAFE_FREE( smb_myworkgroup ); 153 gfree_netbios_names(); 189 154 SAFE_FREE( smb_scope ); 190 155 free_netbios_names_array(); … … 262 227 if (global_myname() == NULL || *global_myname() == '\0') { 263 228 if (!set_global_myname(myhostname())) { 264 DEBUG( 0, ( "init_ structs: malloc fail.\n" ) );229 DEBUG( 0, ( "init_names: malloc fail.\n" ) ); 265 230 return False; 266 231 } … … 268 233 269 234 if (!set_netbios_aliases(lp_netbios_aliases())) { 270 DEBUG( 0, ( "init_ structs: malloc fail.\n" ) );235 DEBUG( 0, ( "init_names: malloc fail.\n" ) ); 271 236 return False; 272 237 } … … 281 246 282 247 return( True ); 283 }284 285 /**************************************************************************n286 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);534 248 } 535 249 … … 596 310 attrstr[0] = 0; 597 311 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"); 604 318 605 319 return talloc_strdup(talloc_tos(), attrstr); … … 617 331 if (!DEBUGLVL(5)) 618 332 return; 619 333 620 334 DEBUG(5,("size=%d\nsmb_com=0x%x\nsmb_rcls=%d\nsmb_reh=%d\nsmb_err=%d\nsmb_flg=%d\nsmb_flg2=%d\n", 621 335 smb_len(buf), … … 636 350 DEBUGADD(5,("smb_vwv[%2d]=%5d (0x%X)\n",i, 637 351 SVAL(buf,smb_vwv+2*i),SVAL(buf,smb_vwv+2*i))); 638 352 639 353 bcc = (int)SVAL(buf,smb_vwv+2*(CVAL(buf,smb_wct))); 640 354 … … 863 577 } 864 578 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 #else883 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 #endif913 }914 579 915 580 NTSTATUS 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) 918 584 { 919 585 NTSTATUS status = NT_STATUS_OK; … … 932 598 } 933 599 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"); 936 602 } 937 603 … … 941 607 * fork 942 608 */ 943 status = messaging_reinit(msg_ctx );609 status = messaging_reinit(msg_ctx, id); 944 610 if (!NT_STATUS_IS_OK(status)) { 945 611 DEBUG(0,("messaging_reinit() failed: %s\n", … … 949 615 done: 950 616 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);969 617 } 970 618 … … 1208 856 if (strequal(str,"CORE+")) 1209 857 return(PROTOCOL_COREPLUS); 1210 858 1211 859 DEBUG(0,("Unrecognised protocol level %s\n",str)); 1212 860 1213 861 return(def); 1214 862 } … … 1353 1001 1354 1002 #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); 1357 1005 #else 1358 1006 return False; … … 1411 1059 uid_t u; 1412 1060 1413 pass = Get_Pwnam_alloc(talloc_ autofree_context(), name);1061 pass = Get_Pwnam_alloc(talloc_tos(), name); 1414 1062 if (pass) { 1415 1063 u = pass->pw_uid; … … 1571 1219 DEBUG(0, ("BACKTRACE: %lu stack frames:\n", 1572 1220 (unsigned long)backtrace_size)); 1573 1221 1574 1222 if (backtrace_strings) { 1575 1223 int i; … … 1635 1283 if (!p) 1636 1284 return(NULL); 1637 1285 1638 1286 ptr = (SMB_STRUCT_DIRENT *)sys_readdir(p); 1639 1287 if (!ptr) … … 1709 1357 if possible. 1710 1358 ********************************************************************/ 1711 1359 1712 1360 void set_namearray(name_compare_entry **ppname_array, const char *namelist) 1713 1361 { … … 1785 1433 i++; 1786 1434 } 1787 1435 1788 1436 (*ppname_array)[i].name = NULL; 1789 1437 … … 1845 1493 *pcount = lock.l_len; 1846 1494 *ppid = lock.l_pid; 1847 1495 1848 1496 DEBUG(3,("fcntl_getlock: fd %d is returned info %d pid %u\n", 1849 1497 fd, (int)lock.l_type, (unsigned int)lock.l_pid)); … … 1963 1611 remote_arch_str = "CIFSFS"; 1964 1612 break; 1613 case RA_OSX: 1614 remote_arch_str = "OSX"; 1615 break; 1965 1616 default: 1966 1617 ra_type = RA_UNKNOWN; … … 2002 1653 { 2003 1654 TDB_DATA key = string_tdb_data(s); 2004 return jenkins_hash(&key);1655 return tdb_jenkins_hash(&key); 2005 1656 } 2006 1657 … … 2146 1797 static char *ret; 2147 1798 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); 2151 1800 } 2152 1801 return ret; … … 2295 1944 char *p; 2296 1945 ptrdiff_t len; 2297 1946 2298 1947 p = strrchr_m(dir, '/'); /* Find final '/', if any */ 2299 1948 … … 2371 2020 bool mask_match(const char *string, const char *pattern, bool is_case_sensitive) 2372 2021 { 2373 if ( strcmp(string,"..") == 0)2022 if (ISDOTDOT(string)) 2374 2023 string = "."; 2375 if ( strcmp(pattern,".") == 0)2024 if (ISDOT(pattern)) 2376 2025 return False; 2377 2026 2378 2027 return ms_fnmatch(pattern, string, Protocol <= PROTOCOL_LANMAN2, is_case_sensitive) == 0; 2379 2028 } … … 2387 2036 bool mask_match_search(const char *string, const char *pattern, bool is_case_sensitive) 2388 2037 { 2389 if ( strcmp(string,"..") == 0)2038 if (ISDOTDOT(string)) 2390 2039 string = "."; 2391 if ( strcmp(pattern,".") == 0)2040 if (ISDOT(pattern)) 2392 2041 return False; 2393 2042 2394 2043 return ms_fnmatch(pattern, string, True, is_case_sensitive) == 0; 2395 2044 } … … 2660 2309 } 2661 2310 2311 static uint64_t my_unique_id = 0; 2312 2313 void set_my_unique_id(uint64_t unique_id) 2314 { 2315 my_unique_id = unique_id; 2316 } 2317 2662 2318 struct server_id pid_to_procid(pid_t pid) 2663 2319 { 2664 2320 struct server_id result; 2665 2321 result.pid = pid; 2666 #ifdef CLUSTER_SUPPORT 2322 result.unique_id = my_unique_id; 2667 2323 result.vnn = my_vnn; 2668 #endif2669 2324 return result; 2670 2325 } … … 2673 2328 { 2674 2329 return pid_to_procid(sys_getpid()); 2675 }2676 2677 struct server_id server_id_self(void)2678 {2679 return procid_self();2680 2330 } 2681 2331 … … 2684 2334 if (p1->pid != p2->pid) 2685 2335 return False; 2686 #ifdef CLUSTER_SUPPORT2687 2336 if (p1->vnn != p2->vnn) 2688 2337 return False; 2689 #endif2690 2338 return True; 2691 2339 } … … 2701 2349 if (pid->pid != sys_getpid()) 2702 2350 return False; 2703 #ifdef CLUSTER_SUPPORT2704 2351 if (pid->vnn != my_vnn) 2705 2352 return False; 2706 #endif2707 2353 return True; 2708 2354 } … … 2712 2358 struct server_id result; 2713 2359 int pid; 2714 #ifdef CLUSTER_SUPPORT2715 2360 unsigned int vnn; 2716 2361 if (sscanf(pid_string, "%u:%d", &vnn, &pid) == 2) { … … 2726 2371 result.pid = -1; 2727 2372 } 2728 #else2729 if (sscanf(pid_string, "%d", &pid) != 1) {2730 result.pid = -1;2731 } else {2732 result.pid = pid;2733 }2734 #endif2735 2373 /* Assigning to result.pid may have overflowed 2736 2374 Map negative pid to -1: i.e. error */ … … 2738 2376 result.pid = -1; 2739 2377 } 2378 result.unique_id = 0; 2740 2379 return result; 2741 2380 } … … 2743 2382 char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid) 2744 2383 { 2745 #ifdef CLUSTER_SUPPORT2746 2384 if (pid->vnn == NONCLUSTER_VNN) { 2747 2385 return talloc_asprintf(mem_ctx, … … 2755 2393 (int)pid->pid); 2756 2394 } 2757 #else2758 return talloc_asprintf(mem_ctx,2759 "%d",2760 (int)pid->pid);2761 #endif2762 2395 } 2763 2396 … … 2774 2407 bool procid_is_local(const struct server_id *pid) 2775 2408 { 2776 #ifdef CLUSTER_SUPPORT2777 2409 return pid->vnn == my_vnn; 2778 #else2779 return True;2780 #endif2781 }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 #else2792 return 0;2793 #endif2794 2795 #else2796 return 0;2797 #endif2798 2410 } 2799 2411 … … 3029 2641 #endif 3030 2642 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 3048 2643 /**************************************************************** 3049 2644 strip off leading '\\' from a hostname … … 3076 2671 return ret; 3077 2672 } 2673 2674 bool 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 2687 int 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 2696 char *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 20 20 #include "includes.h" 21 21 22 #ifdef HAVE_LIBNSCD 23 #include <libnscd.h> 24 #endif 25 22 26 static void smb_nscd_flush_cache(const char *service) 23 27 { -
trunk/server/source3/lib/util_nttoken.c
r414 r745 27 27 28 28 #include "includes.h" 29 #include "../libcli/security/security.h" 29 30 30 31 /**************************************************************************** … … 32 33 ****************************************************************************/ 33 34 34 NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN*ptoken)35 struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken) 35 36 { 36 NT_USER_TOKEN*token;37 struct security_token *token; 37 38 38 39 if (!ptoken) 39 40 return NULL; 40 41 41 token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);42 token = TALLOC_ZERO_P(mem_ctx, struct security_token); 42 43 if (token == NULL) { 43 44 DEBUG(0, ("talloc failed\n")); … … 45 46 } 46 47 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 ); 50 51 51 if (token-> user_sids == NULL) {52 if (token->sids == NULL) { 52 53 DEBUG(0, ("talloc_memdup failed\n")); 53 54 TALLOC_FREE(token); … … 57 58 } 58 59 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; 65 62 66 63 return token; … … 72 69 73 70 NTSTATUS 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) 77 74 { 78 struct nt_user_token *token = NULL;75 struct security_token *token = NULL; 79 76 NTSTATUS status; 80 77 int i; … … 84 81 } 85 82 86 token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token);83 token = TALLOC_ZERO_P(mem_ctx, struct security_token); 87 84 NT_STATUS_HAVE_NO_MEMORY(token); 88 85 89 86 for (i=0; i < token_1->num_sids; i++) { 90 87 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, 93 90 &token->num_sids); 94 91 if (!NT_STATUS_IS_OK(status)) { … … 100 97 for (i=0; i < token_2->num_sids; i++) { 101 98 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, 104 101 &token->num_sids); 105 102 if (!NT_STATUS_IS_OK(status)) { … … 109 106 } 110 107 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; 113 113 114 114 *token_out = token; … … 118 118 119 119 /******************************************************************* 120 Check if this ACEhas a SID in common with the token.120 Check if this struct security_ace has a SID in common with the token. 121 121 ********************************************************************/ 122 122 123 bool token_sid_in_ace(const NT_USER_TOKEN*token, const struct security_ace *ace)123 bool token_sid_in_ace(const struct security_token *token, const struct security_ace *ace) 124 124 { 125 125 size_t i; 126 126 127 127 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])) 129 129 return true; 130 130 } -
trunk/server/source3/lib/util_sid.c
r583 r745 8 8 Copyright (C) Simo Sorce 2002 9 9 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005 10 10 11 11 This program is free software; you can redistribute it and/or modify 12 12 it under the terms of the GNU General Public License as published by 13 13 the Free Software Foundation; either version 3 of the License, or 14 14 (at your option) any later version. 15 15 16 16 This program is distributed in the hope that it will be useful, 17 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 19 GNU General Public License for more details. 20 20 21 21 You should have received a copy of the GNU General Public License 22 22 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 24 24 25 25 #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 170 30 171 31 /***************************************************************** … … 173 33 *****************************************************************/ 174 34 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); 35 char *sid_to_fstring(fstring sidstr_out, const struct dom_sid *sid) 36 { 37 dom_sid_string_buf(sid, sidstr_out, sizeof(fstring)); 180 38 return sidstr_out; 181 39 } 182 40 183 41 /***************************************************************** 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 46 char *sid_string_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid) 192 47 { 193 48 char *result = dom_sid_string(mem_ctx, sid); … … 200 55 *****************************************************************/ 201 56 202 char *sid_string_dbg(const DOM_SID*sid)57 char *sid_string_dbg(const struct dom_sid *sid) 203 58 { 204 59 return sid_string_talloc(talloc_tos(), sid); … … 209 64 *****************************************************************/ 210 65 211 char *sid_string_tos(const DOM_SID*sid)66 char *sid_string_tos(const struct dom_sid *sid) 212 67 { 213 68 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 sid289 *****************************************************************/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 sid308 *****************************************************************/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 sid322 *****************************************************************/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 sid338 and check the sid against the exp_dom_sid339 *****************************************************************/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 sid360 *****************************************************************/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];375 69 } 376 70 … … 379 73 *****************************************************************/ 380 74 381 bool sid_linearize(char *outbuf, size_t len, const DOM_SID*sid)75 bool sid_linearize(char *outbuf, size_t len, const struct dom_sid *sid) 382 76 { 383 77 size_t i; 384 78 385 if (len < ndr_size_dom_sid(sid, NULL,0))79 if (len < ndr_size_dom_sid(sid, 0)) 386 80 return False; 387 81 … … 396 90 397 91 /***************************************************************** 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 domain475 this just compares the leading sub-auths476 *****************************************************************/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 /*****************************************************************501 92 Returns true if SID is internal (and non-mappable). 502 93 *****************************************************************/ 503 94 504 bool non_mappable_sid(DOM_SID *sid) 505 { 506 DOM_SID dom; 507 uint32 rid; 95 bool non_mappable_sid(struct dom_sid *sid) 96 { 97 struct dom_sid dom; 508 98 509 99 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)) 513 103 return True; 514 104 515 if ( sid_equal(&dom, &global_sid_NT_Authority))105 if (dom_sid_equal(&dom, &global_sid_NT_Authority)) 516 106 return True; 517 107 … … 520 110 521 111 /***************************************************************** 522 Return the binary string representation of a DOM_SID.112 Return the binary string representation of a struct dom_sid. 523 113 Caller must free. 524 114 *****************************************************************/ 525 115 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) 116 char *sid_binstring_hex(const struct dom_sid *sid) 547 117 { 548 118 char *buf, *s; 549 int len = ndr_size_dom_sid(sid, NULL,0);119 int len = ndr_size_dom_sid(sid, 0); 550 120 buf = (char *)SMB_MALLOC(len); 551 121 if (!buf) 552 122 return NULL; 553 123 sid_linearize(buf, len, sid); 554 s = binary_string(buf, len);124 hex_encode((const unsigned char *)buf, len, &s); 555 125 free(buf); 556 126 return s; 557 127 } 558 128 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 SIDs579 ********************************************************************/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 there600 ********************************************************************/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 array617 ********************************************************************/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 count627 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 array636 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 683 129 NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx, 684 130 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, 687 133 bool include_user_group_rid, 688 134 bool skip_ressource_groups) 689 135 { 690 136 NTSTATUS status; 691 DOM_SIDsid;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; 694 140 int i; 695 141 -
trunk/server/source3/lib/util_sock.c
r599 r745 21 21 22 22 #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" 173 30 174 31 const char *client_name(int fd) … … 180 37 { 181 38 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);187 39 } 188 40 … … 285 137 #ifdef TCP_QUICKACK 286 138 {"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}, 287 145 #endif 288 146 {NULL,0,0,0,0}}; … … 437 295 size_t *size_ret) 438 296 { 439 fd_set fds; 440 int selrtn; 297 int pollrtn; 441 298 ssize_t readret; 442 299 size_t nread = 0; 443 struct timeval timeout;444 char addr[INET6_ADDRSTRLEN];445 int save_errno;446 300 447 301 /* just checking .... */ … … 465 319 466 320 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); 481 322 } 482 323 nread += readret; … … 491 332 select always returns true on disk files */ 492 333 493 /* Set initial timeout */494 timeout.tv_sec = (time_t)(time_out / 1000);495 timeout.tv_usec = (long)(1000 * (time_out % 1000));496 497 334 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); 507 339 508 340 /* 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); 525 343 } 526 344 527 345 /* Did we timeout ? */ 528 if (selrtn == 0) { 346 if ((pollrtn == 0) || 347 ((revents & (POLLIN|POLLHUP|POLLERR)) == 0)) { 529 348 DEBUG(10,("read_fd_with_timeout: timeout read. " 530 349 "select timed out.\n")); … … 542 361 543 362 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 message548 * 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 }558 363 return map_nt_error_from_unix(errno); 559 364 } … … 660 465 ssize_t write_data(int fd, const char *buffer, size_t N) 661 466 { 662 ssize_t ret;663 467 struct iovec iov; 664 468 665 469 iov.iov_base = CONST_DISCARD(void *, buffer); 666 470 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); 687 472 } 688 473 … … 730 515 731 516 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 will739 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));762 517 763 518 return NT_STATUS_OK; … … 782 537 783 538 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))); 785 541 return status; 786 542 } … … 801 557 802 558 if (!NT_STATUS_IS_OK(status)) { 559 DEBUG(0, ("read_fd_with_timeout failed, read error = " 560 "%s.\n", nt_errstr(status))); 803 561 return status; 804 562 } … … 876 634 } 877 635 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 878 662 /* now we've got a socket - we need to bind it */ 879 663 if (bind(res, (struct sockaddr *)&sock, slen) == -1 ) { … … 1072 856 } 1073 857 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 */ 1074 868 NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port, 1075 869 int timeout, int *pfd) … … 1197 991 } 1198 992 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 host1203 or for simultatneous connection attempts to multiple DCs at once. We return1204 a socket fd of the first successful connection.1205 1206 @param[in] addrs list of Internet addresses and ports to connect to1207 @param[in] num_addrs number of address/port pairs in the addrs list1208 @param[in] timeout time after which we stop waiting for a socket connection1209 to succeed, given in milliseconds1210 @param[out] fd_index the entry in addrs which we successfully connected to1211 @param[out] fd fd of the open and connected socket1212 @return true on a successful connection, false if all connection attempts1213 failed or we timed out1214 *******************************************************************/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 it1260 * might actually happen. */1261 resulting_index = i;1262 goto done;1263 }1264 1265 if (errno == EINPROGRESS || errno == EALREADY ||1266 #ifdef EISCONN1267 errno == EISCONN ||1268 #endif1269 errno == EAGAIN || errno == EINTR) {1270 /* These are the error messages that something is1271 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 a1321 * successful connect, the socket is only writable. Upon an1322 * 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 }1368 993 /**************************************************************************** 1369 994 Open a connected UDP socket to host on port … … 1438 1063 1439 1064 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))); 1442 1068 return addr_buf; 1443 1069 } … … 1731 1357 #ifdef __OS2__ 1732 1358 if (asprintf(&path, "\\socket\\samba\\%s\\%s", socket_dir, socket_name) == -1) { 1733 #else 1359 #else 1734 1360 if (asprintf(&path, "%s/%s", socket_dir, socket_name) == -1) { 1735 1361 #endif … … 1863 1489 } 1864 1490 1865 if (is_zero_addr( (struct sockaddr *)&ss) ||1491 if (is_zero_addr(&ss) || 1866 1492 is_loopback_addr((struct sockaddr *)&ss)) { 1867 1493 return false; … … 1933 1559 } 1934 1560 1561 /* Maybe its an IP address? */ 1562 if (is_ipaddress(servername)) { 1563 return is_my_ipaddr(servername); 1564 } 1565 1935 1566 /* Handle possible CNAME records - convert to an IP addr. list. */ 1936 if (!is_ipaddress(servername)){1567 { 1937 1568 /* Use DNS to resolve the name, check all addresses. */ 1938 1569 struct addrinfo *p = NULL; … … 1962 1593 } 1963 1594 1964 /* Maybe its an IP address? */1965 if (is_ipaddress(servername)) {1966 return is_my_ipaddr(servername);1967 }1968 1969 1595 /* No match */ 1970 1596 return false; … … 2052 1678 return state->ret; 2053 1679 } 1680 1681 int 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 1708 int 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 244 244 while (isspace((int)*psz2)) 245 245 psz2++; 246 if (toupper_ ascii(*psz1) != toupper_ascii(*psz2) ||246 if (toupper_m(*psz1) != toupper_m(*psz2) || 247 247 *psz1 == '\0' || *psz2 == '\0') 248 248 break; … … 827 827 for (i=0;i<li;i++) { 828 828 switch (insert[i]) { 829 case '`':830 case '"':831 case '\'':832 case ';':833 829 case '$': 834 830 /* allow a trailing $ … … 838 834 break; 839 835 } 836 case '`': 837 case '"': 838 case '\'': 839 case ';': 840 840 case '%': 841 841 case '\r': … … 909 909 for (i=0;i<li;i++) { 910 910 switch (in[i]) { 911 case '`':912 case '"':913 case '\'':914 case ';':915 911 case '$': 916 912 /* allow a trailing $ … … 919 915 break; 920 916 } 917 case '`': 918 case '"': 919 case '\'': 920 case ';': 921 921 case '%': 922 922 case '\r': … … 1004 1004 for (i=0;i<li;i++) { 1005 1005 switch (in[i]) { 1006 case '`':1007 case '"':1008 case '\'':1009 case ';':1010 1006 case '$': 1011 1007 /* allow a trailing $ … … 1014 1010 break; 1015 1011 } 1012 case '`': 1013 case '"': 1014 case '\'': 1015 case ';': 1016 1016 case '%': 1017 1017 case '\r': … … 1407 1407 1408 1408 while (*s && !(((unsigned char)s[0]) & 0x80)) { 1409 *s = tolower_ ascii((unsigned char)*s);1409 *s = tolower_m((unsigned char)*s); 1410 1410 s++; 1411 1411 } … … 1463 1463 * Calculate the number of units (8 or 16-bit, depending on the 1464 1464 * destination charset), that would be needed to convert the input 1465 * string which is expected to be in in CH_UNIXencoding to the1465 * string which is expected to be in in src_charset encoding to the 1466 1466 * destination charset (which should be a unicode charset). 1467 1467 */ 1468 size_t strlen_m_ext(const char *s, const charset_t dst_charset) 1468 1469 size_t strlen_m_ext(const char *s, const charset_t src_charset, 1470 const charset_t dst_charset) 1469 1471 { 1470 1472 size_t count = 0; … … 1485 1487 while (*s) { 1486 1488 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); 1488 1490 s += c_size; 1489 1491 1490 switch (dst_charset) {1492 switch (dst_charset) { 1491 1493 case CH_UTF16LE: 1492 1494 case CH_UTF16BE: … … 1528 1530 } 1529 1531 1530 size_t strlen_m_ext_term(const char *s, const charset_t dst_charset) 1532 size_t strlen_m_ext_term(const char *s, const charset_t src_charset, 1533 const charset_t dst_charset) 1531 1534 { 1532 1535 if (!s) { 1533 1536 return 0; 1534 1537 } 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 */ 1543 1548 1544 1549 size_t strlen_m(const char *s) 1545 1550 { 1546 return strlen_m_ext(s, CH_U TF16LE);1551 return strlen_m_ext(s, CH_UNIX, CH_UTF16LE); 1547 1552 } 1548 1553 … … 1577 1582 1578 1583 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;1620 1584 } 1621 1585 … … 2022 1986 { 2023 1987 2024 uint64_t val = -1;1988 uint64_t val = (uint64_t)-1; 2025 1989 const char *p = nptr; 2026 1990 … … 2058 2022 SMB_OFF_T conv_str_size(const char * str) 2059 2023 { 2024 SMB_OFF_T lval_orig; 2060 2025 SMB_OFF_T lval; 2061 2026 char * end; … … 2067 2032 #ifdef HAVE_STRTOULL 2068 2033 if (sizeof(SMB_OFF_T) == 8) { 2069 2034 lval = strtoull(str, &end, 10 /* base */); 2070 2035 } else { 2071 2036 lval = strtoul(str, &end, 10 /* base */); 2072 2037 } 2073 2038 #else … … 2079 2044 } 2080 2045 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 } 2110 2078 2111 2079 return lval; … … 2118 2086 if (*left == NULL) { 2119 2087 *left = (char *)SMB_MALLOC(new_len); 2088 if (*left == NULL) { 2089 return; 2090 } 2120 2091 *left[0] = '\0'; 2121 2092 } else { … … 2301 2272 { 2302 2273 int i; 2274 2275 if (!name) { 2276 return false; 2277 } 2303 2278 2304 2279 for ( i=0; i<max_len && name[i]; i++ ) { … … 2548 2523 return list; 2549 2524 } 2525 2526 char *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 21 21 22 22 #include "includes.h" 23 #include "system/filesys.h" 24 #include "util_tdb.h" 25 23 26 #undef malloc 24 27 #undef realloc … … 35 38 ****************************************************************/ 36 39 37 static void gotalarm_sig( void)40 static void gotalarm_sig(int signum) 38 41 { 39 42 gotalarm = 1; … … 51 54 52 55 if (timeout) { 53 CatchSignal(SIGALRM, SIGNAL_CASTgotalarm_sig);56 CatchSignal(SIGALRM, gotalarm_sig); 54 57 tdb_setalarm_sigptr(tdb, &gotalarm); 55 58 alarm(timeout); … … 64 67 alarm(0); 65 68 tdb_setalarm_sigptr(tdb, NULL); 66 CatchSignal(SIGALRM, SIG NAL_CAST SIG_IGN);69 CatchSignal(SIGALRM, SIG_IGN); 67 70 if (gotalarm && (ret == -1)) { 68 71 DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n", … … 482 485 } 483 486 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 database538 to close just talloc_free() the tdb_wrap pointer539 */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 want555 * here. Otherwise we would have to implement our own556 * 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 597 487 NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err) 598 488 { 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; 632 539 } 633 540 -
trunk/server/source3/lib/util_transfer_file.c
r414 r745 22 22 23 23 #include <includes.h> 24 #include "transfer_file.h" 24 25 25 26 /**************************************************************************** -
trunk/server/source3/lib/util_tsock.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "../lib/tsocket/tsocket.h" 22 #include "../lib/util/tevent_unix.h" 21 23 22 24 struct tstream_read_packet_state { … … 52 54 return tevent_req_post(req, ev); 53 55 } 54 state->iov.iov_base = state->buf;56 state->iov.iov_base = (void *)state->buf; 55 57 state->iov.iov_len = initial; 56 58 … … 115 117 state->buf = tmp; 116 118 117 state->iov.iov_base = state->buf + total;119 state->iov.iov_base = (void *)(state->buf + total); 118 120 state->iov.iov_len = more; 119 121 -
trunk/server/source3/lib/util_unistr.c
r414 r745 22 22 #include "includes.h" 23 23 24 #ifndef MAXUNI25 #define MAXUNI 102426 #endif27 28 24 /* these 3 tables define the unicode case handling. They are loaded 29 25 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;32 26 static uint8 *valid_table; 33 static bool upcase_table_use_unmap;34 static bool lowcase_table_use_unmap;35 static bool valid_table_use_unmap;36 27 static bool initialized; 37 28 … … 41 32 void gfree_case_tables(void) 42 33 { 43 if ( upcase_table ) {44 if ( upcase_table_use_unmap )45 unmap_file(upcase_table, 0x20000);46 else47 SAFE_FREE(upcase_table);48 }49 50 if ( lowcase_table ) {51 if ( lowcase_table_use_unmap )52 unmap_file(lowcase_table, 0x20000);53 else54 SAFE_FREE(lowcase_table);55 }56 57 34 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; 62 37 } 63 38 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 any70 * 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_SETLOCALE95 /* 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 #endif106 107 /* we would like Samba to limp along even if these tables are108 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_SETLOCALE140 /* Restore the old locale. */141 if (saved_locale) {142 setlocale (LC_ALL, saved_locale);143 SAFE_FREE(saved_locale);144 }145 #endif146 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);164 39 } 165 40 … … 173 48 **/ 174 49 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 */ 50 static void init_valid_table(void) 51 { 52 if (valid_table) { 184 53 return; 185 54 } 186 55 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"); 192 59 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 can198 * 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);217 60 } 218 61 } … … 236 79 } 237 80 238 239 /*******************************************************************240 Skip past a unicode string, but not more than len. Always move241 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 }258 81 259 82 /* Converts a string from internal samba format to unicode … … 279 102 280 103 /******************************************************************* 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 /*******************************************************************317 104 Determine if a character is valid in a 8.3 name. 318 105 ********************************************************************/ … … 320 107 bool isvalid83_w(smb_ucs2_t c) 321 108 { 109 init_valid_table(); 322 110 return valid_table[SVAL(&c,0)] != 0; 323 111 } … … 457 245 Convert a string to lower case. 458 246 return True if any char is converted 247 248 This is unsafe for any string involving a UTF16 character 459 249 ********************************************************************/ 460 250 … … 478 268 Convert a string to upper case. 479 269 return True if any char is converted 270 271 This is unsafe for any string involving a UTF16 character 480 272 ********************************************************************/ 481 273 … … 816 608 } 817 609 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 } 610 smb_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 621 bool isupper_w(smb_ucs2_t v) 622 { 623 codepoint_t cp = SVAL(&v,0); 624 return isupper_m(cp); 625 } 626 627 smb_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 638 bool 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 20 20 21 21 #include "includes.h" 22 #include "../libcli/security/security.h" 23 #include "../lib/util/util_pw.h" 24 #include "nsswitch/libwbclient/wbclient.h" 22 25 23 26 #if defined(WITH_WINBIND) 24 27 25 #include " nsswitch/libwbclient/wbclient.h"28 #include "lib/winbind_util.h" 26 29 27 30 struct passwd * winbind_getpwnam(const char * name) … … 42 45 } 43 46 44 struct passwd * winbind_getpwsid(const DOM_SID*sid)47 struct passwd * winbind_getpwsid(const struct dom_sid *sid) 45 48 { 46 49 wbcErr result; … … 64 67 /* Call winbindd to convert a name to a sid */ 65 68 66 bool winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid,69 bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid *sid, 67 70 enum lsa_SidType *name_type) 68 71 { … … 75 78 return false; 76 79 77 memcpy(sid, &dom_sid, sizeof( DOM_SID));80 memcpy(sid, &dom_sid, sizeof(struct dom_sid)); 78 81 *name_type = (enum lsa_SidType)type; 79 82 … … 83 86 /* Call winbindd to convert sid to name */ 84 87 85 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,88 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, 86 89 const char **domain, const char **name, 87 90 enum lsa_SidType *name_type) … … 135 138 /* Call winbindd to convert SID to uid */ 136 139 137 bool winbind_sid_to_uid(uid_t *puid, const DOM_SID*sid)140 bool winbind_sid_to_uid(uid_t *puid, const struct dom_sid *sid) 138 141 { 139 142 struct wbcDomainSid dom_sid; … … 149 152 /* Call winbindd to convert uid to sid */ 150 153 151 bool winbind_uid_to_sid( DOM_SID*sid, uid_t uid)154 bool winbind_uid_to_sid(struct dom_sid *sid, uid_t uid) 152 155 { 153 156 struct wbcDomainSid dom_sid; … … 156 159 result = wbcUidToSid(uid, &dom_sid); 157 160 if (result == WBC_ERR_SUCCESS) { 158 memcpy(sid, &dom_sid, sizeof( DOM_SID));161 memcpy(sid, &dom_sid, sizeof(struct dom_sid)); 159 162 } else { 160 163 sid_copy(sid, &global_sid_NULL); … … 166 169 /* Call winbindd to convert SID to gid */ 167 170 168 bool winbind_sid_to_gid(gid_t *pgid, const DOM_SID*sid)171 bool winbind_sid_to_gid(gid_t *pgid, const struct dom_sid *sid) 169 172 { 170 173 struct wbcDomainSid dom_sid; … … 180 183 /* Call winbindd to convert gid to sid */ 181 184 182 bool winbind_gid_to_sid( DOM_SID*sid, gid_t gid)185 bool winbind_gid_to_sid(struct dom_sid *sid, gid_t gid) 183 186 { 184 187 struct wbcDomainSid dom_sid; … … 187 190 result = wbcGidToSid(gid, &dom_sid); 188 191 if (result == WBC_ERR_SUCCESS) { 189 memcpy(sid, &dom_sid, sizeof( DOM_SID));192 memcpy(sid, &dom_sid, sizeof(struct dom_sid)); 190 193 } else { 191 194 sid_copy(sid, &global_sid_NULL); … … 214 217 215 218 bool winbind_lookup_rids(TALLOC_CTX *mem_ctx, 216 const DOM_SID*domain_sid,219 const struct dom_sid *domain_sid, 217 220 int num_rids, uint32 *rids, 218 221 const char **domain_name, … … 296 299 297 300 bool 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, 300 303 size_t num_members, 301 304 uint32_t **pp_alias_rids, … … 347 350 } 348 351 349 struct passwd * winbind_getpwsid(const DOM_SID*sid)352 struct passwd * winbind_getpwsid(const struct dom_sid *sid) 350 353 { 351 354 return NULL; 352 355 } 353 356 354 bool winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid,357 bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid *sid, 355 358 enum lsa_SidType *name_type) 356 359 { … … 360 363 /* Call winbindd to convert sid to name */ 361 364 362 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,365 bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, 363 366 const char **domain, const char **name, 364 367 enum lsa_SidType *name_type) … … 376 379 /* Call winbindd to convert SID to uid */ 377 380 378 bool winbind_sid_to_uid(uid_t *puid, const DOM_SID*sid)381 bool winbind_sid_to_uid(uid_t *puid, const struct dom_sid *sid) 379 382 { 380 383 return false; … … 383 386 /* Call winbindd to convert uid to sid */ 384 387 385 bool winbind_uid_to_sid( DOM_SID*sid, uid_t uid)388 bool winbind_uid_to_sid(struct dom_sid *sid, uid_t uid) 386 389 { 387 390 return false; … … 390 393 /* Call winbindd to convert SID to gid */ 391 394 392 bool winbind_sid_to_gid(gid_t *pgid, const DOM_SID*sid)395 bool winbind_sid_to_gid(gid_t *pgid, const struct dom_sid *sid) 393 396 { 394 397 return false; … … 397 400 /* Call winbindd to convert gid to sid */ 398 401 399 bool winbind_gid_to_sid( DOM_SID*sid, gid_t gid)402 bool winbind_gid_to_sid(struct dom_sid *sid, gid_t gid) 400 403 { 401 404 return false; … … 412 415 413 416 bool winbind_lookup_rids(TALLOC_CTX *mem_ctx, 414 const DOM_SID*domain_sid,417 const struct dom_sid *domain_sid, 415 418 int num_rids, uint32 *rids, 416 419 const char **domain_name, … … 440 443 441 444 bool 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, 444 447 size_t num_members, 445 448 uint32_t **pp_alias_rids,
Note:
See TracChangeset
for help on using the changeset viewer.