root/source3/rpc_server/srv_wkssvc_nt.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. create_wks_info_100
  2. _wkssvc_NetWkstaGetInfo
  3. _wkssvc_NetWkstaSetInfo
  4. _wkssvc_NetWkstaEnumUsers
  5. _wkssvc_NetrWkstaUserGetInfo
  6. _wkssvc_NetrWkstaUserSetInfo
  7. _wkssvc_NetWkstaTransportEnum
  8. _wkssvc_NetrWkstaTransportAdd
  9. _wkssvc_NetrWkstaTransportDel
  10. _wkssvc_NetrUseAdd
  11. _wkssvc_NetrUseGetInfo
  12. _wkssvc_NetrUseDel
  13. _wkssvc_NetrUseEnum
  14. _wkssvc_NetrMessageBufferSend
  15. _wkssvc_NetrWorkstationStatisticsGet
  16. _wkssvc_NetrLogonDomainNameAdd
  17. _wkssvc_NetrLogonDomainNameDel
  18. _wkssvc_NetrJoinDomain
  19. _wkssvc_NetrUnjoinDomain
  20. _wkssvc_NetrRenameMachineInDomain
  21. _wkssvc_NetrValidateName
  22. _wkssvc_NetrGetJoinInformation
  23. _wkssvc_NetrGetJoinableOus
  24. _wkssvc_NetrJoinDomain2
  25. _wkssvc_NetrUnjoinDomain2
  26. _wkssvc_NetrRenameMachineInDomain2
  27. _wkssvc_NetrValidateName2
  28. _wkssvc_NetrGetJoinableOus2
  29. _wkssvc_NetrAddAlternateComputerName
  30. _wkssvc_NetrRemoveAlternateComputerName
  31. _wkssvc_NetrSetPrimaryComputername
  32. _wkssvc_NetrEnumerateComputerNames

   1 /* 
   2  *  Unix SMB/CIFS implementation.
   3  *  RPC Pipe client / server routines
   4  *
   5  *  Copyright (C) Andrew Tridgell               1992-1997,
   6  *  Copyright (C) Gerald (Jerry) Carter         2006.
   7  *  Copyright (C) Guenther Deschner             2007-2008.
   8  *
   9  *  This program is free software; you can redistribute it and/or modify
  10  *  it under the terms of the GNU General Public License as published by
  11  *  the Free Software Foundation; either version 3 of the License, or
  12  *  (at your option) any later version.
  13  *  
  14  *  This program is distributed in the hope that it will be useful,
  15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17  *  GNU General Public License for more details.
  18  *  
  19  *  You should have received a copy of the GNU General Public License
  20  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  21  */
  22 
  23 /* This is the implementation of the wks interface. */
  24 
  25 #include "includes.h"
  26 #include "libnet/libnet.h"
  27 
  28 #undef DBGC_CLASS
  29 #define DBGC_CLASS DBGC_RPC_SRV
  30 
  31 /*******************************************************************
  32  Fill in the values for the struct wkssvc_NetWkstaInfo100.
  33  ********************************************************************/
  34 
  35 static void create_wks_info_100(struct wkssvc_NetWkstaInfo100 *info100)
     /* [<][>][^][v][top][bottom][index][help] */
  36 {
  37         info100->platform_id     = PLATFORM_ID_NT;      /* unknown */
  38         info100->version_major   = lp_major_announce_version();
  39         info100->version_minor   = lp_minor_announce_version();
  40 
  41         info100->server_name = talloc_asprintf_strupper_m(
  42                 info100, "%s", global_myname());
  43         info100->domain_name = talloc_asprintf_strupper_m(
  44                 info100, "%s", lp_workgroup());
  45 
  46         return;
  47 }
  48 
  49 /********************************************************************
  50  only supports info level 100 at the moment.
  51  ********************************************************************/
  52 
  53 WERROR _wkssvc_NetWkstaGetInfo(pipes_struct *p, struct wkssvc_NetWkstaGetInfo *r)
     /* [<][>][^][v][top][bottom][index][help] */
  54 {
  55         struct wkssvc_NetWkstaInfo100 *wks100 = NULL;
  56         
  57         /* We only support info level 100 currently */
  58         
  59         if ( r->in.level != 100 ) {
  60                 return WERR_UNKNOWN_LEVEL;
  61         }
  62 
  63         if ( (wks100 = TALLOC_ZERO_P(p->mem_ctx, struct wkssvc_NetWkstaInfo100)) == NULL ) {
  64                 return WERR_NOMEM;
  65         }
  66 
  67         create_wks_info_100( wks100 );
  68         
  69         r->out.info->info100 = wks100;
  70 
  71         return WERR_OK;
  72 }
  73 
  74 /********************************************************************
  75  ********************************************************************/
  76 
  77 WERROR _wkssvc_NetWkstaSetInfo(pipes_struct *p, struct wkssvc_NetWkstaSetInfo *r)
     /* [<][>][^][v][top][bottom][index][help] */
  78 {
  79         /* FIXME: Add implementation code here */
  80         p->rng_fault_state = True;
  81         return WERR_NOT_SUPPORTED;
  82 }
  83 
  84 /********************************************************************
  85  ********************************************************************/
  86 
  87 WERROR _wkssvc_NetWkstaEnumUsers(pipes_struct *p, struct wkssvc_NetWkstaEnumUsers *r)
     /* [<][>][^][v][top][bottom][index][help] */
  88 {
  89         /* FIXME: Add implementation code here */
  90         p->rng_fault_state = True;
  91         return WERR_NOT_SUPPORTED;
  92 }
  93 
  94 /********************************************************************
  95  ********************************************************************/
  96 
  97 WERROR _wkssvc_NetrWkstaUserGetInfo(pipes_struct *p, struct wkssvc_NetrWkstaUserGetInfo *r)
     /* [<][>][^][v][top][bottom][index][help] */
  98 {
  99         /* FIXME: Add implementation code here */
 100         p->rng_fault_state = True;
 101         return WERR_NOT_SUPPORTED;
 102 }
 103 
 104 /********************************************************************
 105  ********************************************************************/
 106 
 107 WERROR _wkssvc_NetrWkstaUserSetInfo(pipes_struct *p, struct wkssvc_NetrWkstaUserSetInfo *r)
     /* [<][>][^][v][top][bottom][index][help] */
 108 {
 109         /* FIXME: Add implementation code here */
 110         p->rng_fault_state = True;
 111         return WERR_NOT_SUPPORTED;
 112 }
 113 
 114 /********************************************************************
 115  ********************************************************************/
 116 
 117 WERROR _wkssvc_NetWkstaTransportEnum(pipes_struct *p, struct wkssvc_NetWkstaTransportEnum *r)
     /* [<][>][^][v][top][bottom][index][help] */
 118 {
 119         /* FIXME: Add implementation code here */
 120         p->rng_fault_state = True;
 121         return WERR_NOT_SUPPORTED;
 122 }
 123 
 124 /********************************************************************
 125  ********************************************************************/
 126 
 127 WERROR _wkssvc_NetrWkstaTransportAdd(pipes_struct *p, struct wkssvc_NetrWkstaTransportAdd *r)
     /* [<][>][^][v][top][bottom][index][help] */
 128 {
 129         /* FIXME: Add implementation code here */
 130         p->rng_fault_state = True;
 131         return WERR_NOT_SUPPORTED;
 132 }
 133 
 134 /********************************************************************
 135  ********************************************************************/
 136 
 137 WERROR _wkssvc_NetrWkstaTransportDel(pipes_struct *p, struct wkssvc_NetrWkstaTransportDel *r)
     /* [<][>][^][v][top][bottom][index][help] */
 138 {
 139         /* FIXME: Add implementation code here */
 140         p->rng_fault_state = True;
 141         return WERR_NOT_SUPPORTED;
 142 }
 143 
 144 /********************************************************************
 145  ********************************************************************/
 146 
 147 WERROR _wkssvc_NetrUseAdd(pipes_struct *p, struct wkssvc_NetrUseAdd *r)
     /* [<][>][^][v][top][bottom][index][help] */
 148 {
 149         /* FIXME: Add implementation code here */
 150         p->rng_fault_state = True;
 151         return WERR_NOT_SUPPORTED;
 152 }
 153 
 154 /********************************************************************
 155  ********************************************************************/
 156 
 157 WERROR _wkssvc_NetrUseGetInfo(pipes_struct *p, struct wkssvc_NetrUseGetInfo *r)
     /* [<][>][^][v][top][bottom][index][help] */
 158 {
 159         /* FIXME: Add implementation code here */
 160         p->rng_fault_state = True;
 161         return WERR_NOT_SUPPORTED;
 162 }
 163 
 164 /********************************************************************
 165  ********************************************************************/
 166 
 167 WERROR _wkssvc_NetrUseDel(pipes_struct *p, struct wkssvc_NetrUseDel *r)
     /* [<][>][^][v][top][bottom][index][help] */
 168 {
 169         /* FIXME: Add implementation code here */
 170         p->rng_fault_state = True;
 171         return WERR_NOT_SUPPORTED;
 172 }
 173 
 174 /********************************************************************
 175  ********************************************************************/
 176 
 177 WERROR _wkssvc_NetrUseEnum(pipes_struct *p, struct wkssvc_NetrUseEnum *r)
     /* [<][>][^][v][top][bottom][index][help] */
 178 {
 179         /* FIXME: Add implementation code here */
 180         p->rng_fault_state = True;
 181         return WERR_NOT_SUPPORTED;
 182 }
 183 
 184 /********************************************************************
 185  ********************************************************************/
 186 
 187 WERROR _wkssvc_NetrMessageBufferSend(pipes_struct *p, struct wkssvc_NetrMessageBufferSend *r)
     /* [<][>][^][v][top][bottom][index][help] */
 188 {
 189         /* FIXME: Add implementation code here */
 190         p->rng_fault_state = True;
 191         return WERR_NOT_SUPPORTED;
 192 }
 193 
 194 /********************************************************************
 195  ********************************************************************/
 196 
 197 WERROR _wkssvc_NetrWorkstationStatisticsGet(pipes_struct *p, struct wkssvc_NetrWorkstationStatisticsGet *r) 
     /* [<][>][^][v][top][bottom][index][help] */
 198 {
 199         /* FIXME: Add implementation code here */
 200         p->rng_fault_state = True;
 201         return WERR_NOT_SUPPORTED;
 202 }
 203 
 204 /********************************************************************
 205  ********************************************************************/
 206 
 207 WERROR _wkssvc_NetrLogonDomainNameAdd(pipes_struct *p, struct wkssvc_NetrLogonDomainNameAdd *r)
     /* [<][>][^][v][top][bottom][index][help] */
 208 {
 209         /* FIXME: Add implementation code here */
 210         p->rng_fault_state = True;
 211         return WERR_NOT_SUPPORTED;
 212 }
 213 
 214 /********************************************************************
 215  ********************************************************************/
 216 
 217 WERROR _wkssvc_NetrLogonDomainNameDel(pipes_struct *p, struct wkssvc_NetrLogonDomainNameDel *r)
     /* [<][>][^][v][top][bottom][index][help] */
 218 {
 219         /* FIXME: Add implementation code here */
 220         p->rng_fault_state = True;
 221         return WERR_NOT_SUPPORTED;
 222 }
 223 
 224 /********************************************************************
 225  ********************************************************************/
 226 
 227 WERROR _wkssvc_NetrJoinDomain(pipes_struct *p, struct wkssvc_NetrJoinDomain *r)
     /* [<][>][^][v][top][bottom][index][help] */
 228 {
 229         /* FIXME: Add implementation code here */
 230         p->rng_fault_state = True;
 231         return WERR_NOT_SUPPORTED;
 232 }
 233 
 234 /********************************************************************
 235  ********************************************************************/
 236 
 237 WERROR _wkssvc_NetrUnjoinDomain(pipes_struct *p, struct wkssvc_NetrUnjoinDomain *r)
     /* [<][>][^][v][top][bottom][index][help] */
 238 {
 239         /* FIXME: Add implementation code here */
 240         p->rng_fault_state = True;
 241         return WERR_NOT_SUPPORTED;
 242 }
 243 
 244 /********************************************************************
 245  ********************************************************************/
 246 
 247 WERROR _wkssvc_NetrRenameMachineInDomain(pipes_struct *p, struct wkssvc_NetrRenameMachineInDomain *r)
     /* [<][>][^][v][top][bottom][index][help] */
 248 {
 249         /* FIXME: Add implementation code here */
 250         p->rng_fault_state = True;
 251         return WERR_NOT_SUPPORTED;
 252 }
 253 
 254 /********************************************************************
 255  ********************************************************************/
 256 
 257 WERROR _wkssvc_NetrValidateName(pipes_struct *p, struct wkssvc_NetrValidateName *r)
     /* [<][>][^][v][top][bottom][index][help] */
 258 {
 259         /* FIXME: Add implementation code here */
 260         p->rng_fault_state = True;
 261         return WERR_NOT_SUPPORTED;
 262 }
 263 
 264 /********************************************************************
 265  ********************************************************************/
 266 
 267 WERROR _wkssvc_NetrGetJoinInformation(pipes_struct *p, struct wkssvc_NetrGetJoinInformation *r)
     /* [<][>][^][v][top][bottom][index][help] */
 268 {
 269         /* FIXME: Add implementation code here */
 270         p->rng_fault_state = True;
 271         return WERR_NOT_SUPPORTED;
 272 }
 273 
 274 /********************************************************************
 275  ********************************************************************/
 276 
 277 WERROR _wkssvc_NetrGetJoinableOus(pipes_struct *p, struct wkssvc_NetrGetJoinableOus *r)
     /* [<][>][^][v][top][bottom][index][help] */
 278 {
 279         /* FIXME: Add implementation code here */
 280         p->rng_fault_state = True;
 281         return WERR_NOT_SUPPORTED;
 282 }
 283 
 284 /********************************************************************
 285  _wkssvc_NetrJoinDomain2
 286  ********************************************************************/
 287 
 288 WERROR _wkssvc_NetrJoinDomain2(pipes_struct *p,
     /* [<][>][^][v][top][bottom][index][help] */
 289                                struct wkssvc_NetrJoinDomain2 *r)
 290 {
 291         struct libnet_JoinCtx *j = NULL;
 292         char *cleartext_pwd = NULL;
 293         char *admin_domain = NULL;
 294         char *admin_account = NULL;
 295         WERROR werr;
 296         struct nt_user_token *token = p->server_info->ptok;
 297 
 298         if (!r->in.domain_name) {
 299                 return WERR_INVALID_PARAM;
 300         }
 301 
 302         if (!r->in.admin_account || !r->in.encrypted_password) {
 303                 return WERR_INVALID_PARAM;
 304         }
 305 
 306         if (!user_has_privileges(token, &se_machine_account) &&
 307             !nt_token_check_domain_rid(token, DOMAIN_GROUP_RID_ADMINS) &&
 308             !nt_token_check_domain_rid(token, BUILTIN_ALIAS_RID_ADMINS)) {
 309                 DEBUG(5,("_wkssvc_NetrJoinDomain2: account doesn't have "
 310                         "sufficient privileges\n"));
 311                 return WERR_ACCESS_DENIED;
 312         }
 313 
 314         if ((r->in.join_flags & WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED) ||
 315             (r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_UNSECURE)) {
 316                 return WERR_NOT_SUPPORTED;
 317         }
 318 
 319         werr = decode_wkssvc_join_password_buffer(
 320                 p->mem_ctx, r->in.encrypted_password,
 321                 &p->server_info->user_session_key, &cleartext_pwd);
 322         if (!W_ERROR_IS_OK(werr)) {
 323                 return werr;
 324         }
 325 
 326         split_domain_user(p->mem_ctx,
 327                           r->in.admin_account,
 328                           &admin_domain,
 329                           &admin_account);
 330 
 331         werr = libnet_init_JoinCtx(p->mem_ctx, &j);
 332         if (!W_ERROR_IS_OK(werr)) {
 333                 return werr;
 334         }
 335 
 336         j->in.domain_name       = r->in.domain_name;
 337         j->in.account_ou        = r->in.account_ou;
 338         j->in.join_flags        = r->in.join_flags;
 339         j->in.admin_account     = admin_account;
 340         j->in.admin_password    = cleartext_pwd;
 341         j->in.debug             = true;
 342         j->in.modify_config     = lp_config_backend_is_registry();
 343         j->in.msg_ctx           = smbd_messaging_context();
 344 
 345         become_root();
 346         werr = libnet_Join(p->mem_ctx, j);
 347         unbecome_root();
 348 
 349         if (!W_ERROR_IS_OK(werr)) {
 350                 DEBUG(5,("_wkssvc_NetrJoinDomain2: libnet_Join failed with: %s\n",
 351                         j->out.error_string ? j->out.error_string :
 352                         win_errstr(werr)));
 353         }
 354 
 355         TALLOC_FREE(j);
 356         return werr;
 357 }
 358 
 359 /********************************************************************
 360  _wkssvc_NetrUnjoinDomain2
 361  ********************************************************************/
 362 
 363 WERROR _wkssvc_NetrUnjoinDomain2(pipes_struct *p,
     /* [<][>][^][v][top][bottom][index][help] */
 364                                  struct wkssvc_NetrUnjoinDomain2 *r)
 365 {
 366         struct libnet_UnjoinCtx *u = NULL;
 367         char *cleartext_pwd = NULL;
 368         char *admin_domain = NULL;
 369         char *admin_account = NULL;
 370         WERROR werr;
 371         struct nt_user_token *token = p->server_info->ptok;
 372 
 373         if (!r->in.account || !r->in.encrypted_password) {
 374                 return WERR_INVALID_PARAM;
 375         }
 376 
 377         if (!user_has_privileges(token, &se_machine_account) &&
 378             !nt_token_check_domain_rid(token, DOMAIN_GROUP_RID_ADMINS) &&
 379             !nt_token_check_domain_rid(token, BUILTIN_ALIAS_RID_ADMINS)) {
 380                 DEBUG(5,("_wkssvc_NetrUnjoinDomain2: account doesn't have "
 381                         "sufficient privileges\n"));
 382                 return WERR_ACCESS_DENIED;
 383         }
 384 
 385         werr = decode_wkssvc_join_password_buffer(
 386                 p->mem_ctx, r->in.encrypted_password,
 387                 &p->server_info->user_session_key, &cleartext_pwd);
 388         if (!W_ERROR_IS_OK(werr)) {
 389                 return werr;
 390         }
 391 
 392         split_domain_user(p->mem_ctx,
 393                           r->in.account,
 394                           &admin_domain,
 395                           &admin_account);
 396 
 397         werr = libnet_init_UnjoinCtx(p->mem_ctx, &u);
 398         if (!W_ERROR_IS_OK(werr)) {
 399                 return werr;
 400         }
 401 
 402         u->in.domain_name       = lp_realm();
 403         u->in.unjoin_flags      = r->in.unjoin_flags |
 404                                   WKSSVC_JOIN_FLAGS_JOIN_TYPE;
 405         u->in.admin_account     = admin_account;
 406         u->in.admin_password    = cleartext_pwd;
 407         u->in.debug             = true;
 408         u->in.modify_config     = lp_config_backend_is_registry();
 409         u->in.msg_ctx           = smbd_messaging_context();
 410 
 411         become_root();
 412         werr = libnet_Unjoin(p->mem_ctx, u);
 413         unbecome_root();
 414 
 415         if (!W_ERROR_IS_OK(werr)) {
 416                 DEBUG(5,("_wkssvc_NetrUnjoinDomain2: libnet_Unjoin failed with: %s\n",
 417                         u->out.error_string ? u->out.error_string :
 418                         win_errstr(werr)));
 419         }
 420 
 421         TALLOC_FREE(u);
 422         return werr;
 423 }
 424 
 425 /********************************************************************
 426  ********************************************************************/
 427 
 428 WERROR _wkssvc_NetrRenameMachineInDomain2(pipes_struct *p, struct wkssvc_NetrRenameMachineInDomain2 *r)
     /* [<][>][^][v][top][bottom][index][help] */
 429 {
 430         /* for now just return not supported */
 431         return WERR_NOT_SUPPORTED;
 432 }
 433 
 434 /********************************************************************
 435  ********************************************************************/
 436 
 437 WERROR _wkssvc_NetrValidateName2(pipes_struct *p, struct wkssvc_NetrValidateName2 *r)
     /* [<][>][^][v][top][bottom][index][help] */
 438 {
 439         /* FIXME: Add implementation code here */
 440         p->rng_fault_state = True;
 441         return WERR_NOT_SUPPORTED;
 442 }
 443 
 444 /********************************************************************
 445  ********************************************************************/
 446 
 447 WERROR _wkssvc_NetrGetJoinableOus2(pipes_struct *p, struct wkssvc_NetrGetJoinableOus2 *r)
     /* [<][>][^][v][top][bottom][index][help] */
 448 {
 449         /* FIXME: Add implementation code here */
 450         p->rng_fault_state = True;
 451         return WERR_NOT_SUPPORTED;
 452 }
 453 
 454 /********************************************************************
 455  ********************************************************************/
 456 
 457 WERROR _wkssvc_NetrAddAlternateComputerName(pipes_struct *p, struct wkssvc_NetrAddAlternateComputerName *r)
     /* [<][>][^][v][top][bottom][index][help] */
 458 {
 459         /* FIXME: Add implementation code here */
 460         p->rng_fault_state = True;
 461         return WERR_NOT_SUPPORTED;
 462 }
 463 
 464 /********************************************************************
 465  ********************************************************************/
 466 
 467 WERROR _wkssvc_NetrRemoveAlternateComputerName(pipes_struct *p, struct wkssvc_NetrRemoveAlternateComputerName *r)
     /* [<][>][^][v][top][bottom][index][help] */
 468 {
 469         /* FIXME: Add implementation code here */
 470         p->rng_fault_state = True;
 471         return WERR_NOT_SUPPORTED;
 472 }
 473 
 474 /********************************************************************
 475  ********************************************************************/
 476 
 477 WERROR _wkssvc_NetrSetPrimaryComputername(pipes_struct *p, struct wkssvc_NetrSetPrimaryComputername *r)
     /* [<][>][^][v][top][bottom][index][help] */
 478 {
 479         /* FIXME: Add implementation code here */
 480         p->rng_fault_state = True;
 481         return WERR_NOT_SUPPORTED;
 482 }
 483 
 484 /********************************************************************
 485  ********************************************************************/
 486 
 487 WERROR _wkssvc_NetrEnumerateComputerNames(pipes_struct *p, struct wkssvc_NetrEnumerateComputerNames *r)
     /* [<][>][^][v][top][bottom][index][help] */
 488 {
 489         /* FIXME: Add implementation code here */
 490         p->rng_fault_state = True;
 491         return WERR_NOT_SUPPORTED;
 492 }
 493 

/* [<][>][^][v][top][bottom][index][help] */