r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[kai/samba.git] / source3 / rpc_server / srv_lsa_ds_nt.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell               1992-1997.
5  *  Copyright (C) Luke Kenneth Casson Leighton  1996-1997.
6  *  Copyright (C) Paul Ashton                        1997.
7  *  Copyright (C) Jeremy Allison                     2001.
8  *  Copyright (C) Gerald Carter                      2002.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 3 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
22  */
23
24 /* Implementation of registry functions. */
25
26 #include "includes.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_SRV
30
31 /********************************************************************
32  Fill in a DS_DOMINFO_CTR structure
33  ********************************************************************/
34
35 static NTSTATUS fill_dsrole_dominfo_basic(TALLOC_CTX *ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **info) 
36 {
37         DSROLE_PRIMARY_DOMAIN_INFO_BASIC *basic;
38         const char *netbios_domain = "";
39         fstring dnsdomain;
40
41         DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
42
43         if ( !(basic = TALLOC_ZERO_P(ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC)) ) {
44                 DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error!  talloc_xero() failed\n"));
45                 return NT_STATUS_NO_MEMORY;
46         }
47
48         switch ( lp_server_role() ) {
49                 case ROLE_STANDALONE:
50                         basic->machine_role = DSROLE_STANDALONE_SRV;
51                         basic->netbios_ptr = 1;
52                         netbios_domain = get_global_sam_name();
53                         break;
54                 case ROLE_DOMAIN_MEMBER:
55                         basic->netbios_ptr = 1;
56                         netbios_domain = lp_workgroup();
57                         basic->machine_role = DSROLE_DOMAIN_MEMBER_SRV;
58                         break;
59                 case ROLE_DOMAIN_BDC:
60                         basic->netbios_ptr = 1;
61                         netbios_domain = get_global_sam_name();
62                         basic->machine_role = DSROLE_BDC;
63                         break;
64                 case ROLE_DOMAIN_PDC:
65                         basic->netbios_ptr = 1;
66                         netbios_domain = get_global_sam_name();
67                         basic->machine_role = DSROLE_PDC;
68                         break;
69         }
70
71         /* always set netbios name */
72
73         init_unistr2( &basic->netbios_domain, netbios_domain, UNI_STR_TERMINATE);
74
75         if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
76                 basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;
77
78         /* fill in some additional fields if we are a member of an AD domain */
79
80         if ( lp_security() == SEC_ADS ) {
81                 fstrcpy( dnsdomain, lp_realm() );
82                 strlower_m( dnsdomain );
83                 
84                 basic->dnsname_ptr = 1;
85                 init_unistr2( &basic->dns_domain, dnsdomain, UNI_STR_TERMINATE);
86
87                 /* FIXME!! We really should fill in the correct forest
88                    name.  Should get this information from winbindd.  */
89                 basic->forestname_ptr = 1;
90                 init_unistr2( &basic->forest_domain, dnsdomain, UNI_STR_TERMINATE);
91         } else {
92                 /* security = domain should not fill in the dns or
93                    forest name */
94                 basic->dnsname_ptr = 0;
95                 basic->forestname_ptr = 0;
96         }
97
98         *info = basic;
99
100         return NT_STATUS_OK;
101 }
102
103 /********************************************************************
104  Implement the DsroleGetPrimaryDomainInfo() call
105  ********************************************************************/
106
107 NTSTATUS _dsrole_get_primary_dominfo(pipes_struct *p, DS_Q_GETPRIMDOMINFO *q_u, DS_R_GETPRIMDOMINFO *r_u)
108 {
109         NTSTATUS result = NT_STATUS_OK;
110         uint32 level = q_u->level;
111
112         switch ( level ) {
113
114                 case DsRolePrimaryDomainInfoBasic:
115                         r_u->level = DsRolePrimaryDomainInfoBasic;
116                         r_u->ptr = 1;
117                         result = fill_dsrole_dominfo_basic( p->mem_ctx, &r_u->info.basic );
118                         break;
119
120                 default:
121                         DEBUG(0,("_dsrole_get_primary_dominfo: Unsupported info level [%d]!\n",
122                                 level));
123                         result = NT_STATUS_INVALID_LEVEL;
124         }
125
126         return result;
127 }
128
129
130