LCOV - code coverage report
Current view: top level - lib/param - loadparm_server_role.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 40 52 76.9 %
Date: 2021-09-23 10:06:22 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Parameter loading functions
       4             :    Copyright (C) Karl Auer 1993-1998
       5             : 
       6             :    Largely re-written by Andrew Tridgell, September 1994
       7             : 
       8             :    Copyright (C) Simo Sorce 2001
       9             :    Copyright (C) Alexander Bokovoy 2002
      10             :    Copyright (C) Stefan (metze) Metzmacher 2002
      11             :    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
      12             :    Copyright (C) Michael Adam 2008
      13             :    Copyright (C) Andrew Bartlett 2010
      14             : 
      15             :    This program is free software; you can redistribute it and/or modify
      16             :    it under the terms of the GNU General Public License as published by
      17             :    the Free Software Foundation; either version 3 of the License, or
      18             :    (at your option) any later version.
      19             : 
      20             :    This program is distributed in the hope that it will be useful,
      21             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      22             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      23             :    GNU General Public License for more details.
      24             : 
      25             :    You should have received a copy of the GNU General Public License
      26             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      27             : */
      28             : #include "includes.h"
      29             : #include "lib/param/loadparm.h"
      30             : #include "libds/common/roles.h"
      31             : 
      32             : /*******************************************************************
      33             :  Set the server type we will announce as via nmbd.
      34             : ********************************************************************/
      35             : 
      36             : static const struct srv_role_tab {
      37             :         uint32_t role;
      38             :         const char *role_str;
      39             : } srv_role_tab [] = {
      40             :         { ROLE_STANDALONE, "ROLE_STANDALONE" },
      41             :         { ROLE_DOMAIN_MEMBER, "ROLE_DOMAIN_MEMBER" },
      42             :         { ROLE_DOMAIN_BDC, "ROLE_DOMAIN_BDC" },
      43             :         { ROLE_DOMAIN_PDC, "ROLE_DOMAIN_PDC" },
      44             :         { ROLE_ACTIVE_DIRECTORY_DC, "ROLE_ACTIVE_DIRECTORY_DC" },
      45             :         { 0, NULL }
      46             : };
      47             : 
      48         681 : const char* server_role_str(uint32_t role)
      49             : {
      50         681 :         int i = 0;
      51        1338 :         for (i=0; srv_role_tab[i].role_str; i++) {
      52        1338 :                 if (role == srv_role_tab[i].role) {
      53         676 :                         return srv_role_tab[i].role_str;
      54             :                 }
      55             :         }
      56           0 :         return NULL;
      57             : }
      58             : 
      59             : /**
      60             :  * Set the server role based on security, domain logons and domain master
      61             :  */
      62     1832421 : int lp_find_server_role(int server_role, int security, int domain_logons, int domain_master)
      63             : {
      64             :         int role;
      65             : 
      66     1832421 :         if (server_role != ROLE_AUTO) {
      67      595650 :                 if (lp_is_security_and_server_role_valid(server_role, security)) {
      68      580501 :                         return server_role;
      69             :                 }
      70             :         }
      71             : 
      72             :         /* If server_role is set to ROLE_AUTO, or conflicted with the
      73             :          * chosen security setting, figure out the correct role */
      74     1236771 :         role = ROLE_STANDALONE;
      75             : 
      76     1236771 :         switch (security) {
      77      748398 :                 case SEC_DOMAIN:
      78             :                 case SEC_ADS:
      79      748398 :                         role = ROLE_DOMAIN_MEMBER;
      80      748398 :                         break;
      81      488371 :                 case SEC_AUTO:
      82             :                 case SEC_USER:
      83      488371 :                         if (domain_logons) {
      84             : 
      85      240427 :                                 if (domain_master) {
      86      240411 :                                         role = ROLE_DOMAIN_PDC;
      87             :                                 } else {
      88           1 :                                         role = ROLE_DOMAIN_BDC;
      89             :                                 }
      90             :                         }
      91      488205 :                         break;
      92           0 :                 default:
      93           0 :                         DEBUG(0, ("Server's Role undefined due to unknown security mode\n"));
      94           0 :                         break;
      95             :         }
      96             : 
      97     1236603 :         return role;
      98             : }
      99             : 
     100             : /**
     101             :  * Set the server role based on security, domain logons and domain master
     102             :  */
     103      154856 : int lp_find_security(int server_role, int security)
     104             : {
     105      154856 :         if (security != SEC_AUTO) {
     106        9184 :                 return security;
     107             :         }
     108             : 
     109      145645 :         switch (server_role) {
     110         568 :         case ROLE_DOMAIN_MEMBER:
     111         568 :                 return SEC_ADS;
     112      145076 :         default:
     113      145076 :                 return SEC_USER;
     114             :         }
     115             : }
     116             : 
     117             : 
     118             : /**
     119             :  * Check if server role and security parameters are contradictory
     120             :  */
     121      595650 : bool lp_is_security_and_server_role_valid(int server_role, int security)
     122             : {
     123      595650 :         bool valid = false;
     124             : 
     125      595650 :         if (security == SEC_AUTO) {
     126      580501 :                 return true;
     127             :         }
     128             : 
     129          13 :         switch (server_role) {
     130           0 :         case ROLE_AUTO:
     131           0 :                 valid = true;
     132           0 :                 break;
     133           2 :         case ROLE_DOMAIN_MEMBER:
     134           2 :                 if (security == SEC_ADS || security == SEC_DOMAIN) {
     135           2 :                         valid = true;
     136             :                 }
     137           0 :                 break;
     138             : 
     139          11 :         case ROLE_STANDALONE:
     140             :         case ROLE_DOMAIN_PDC:
     141             :         case ROLE_DOMAIN_BDC:
     142             :         case ROLE_ACTIVE_DIRECTORY_DC:
     143          11 :                 if (security == SEC_USER) {
     144          11 :                         valid = true;
     145             :                 }
     146           0 :                 break;
     147             : 
     148           0 :         default:
     149           0 :                 break;
     150             :         }
     151             : 
     152           0 :         return valid;
     153             : }

Generated by: LCOV version 1.13