xref: /illumos-gate/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision e38a713ad4e0a9c42f8cccd9350412b2c6ccccdb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <unistd.h>
29 #include <pthread.h>
30 #include <smbsrv/libmlsvc.h>
31 
32 void dssetup_initialize(void);
33 void srvsvc_initialize(void);
34 void wkssvc_initialize(void);
35 void lsarpc_initialize(void);
36 void logr_initialize(void);
37 void netr_initialize(void);
38 void samr_initialize(void);
39 void svcctl_initialize(void);
40 void winreg_initialize(void);
41 int srvsvc_gettime(unsigned long *);
42 
43 static void *mlsvc_keepalive(void *);
44 
45 static pthread_t mlsvc_keepalive_thr;
46 #define	MLSVC_KEEPALIVE_INTERVAL	(10 * 60)	/* 10 minutes */
47 
48 /*
49  * All mlrpc initialization is invoked from here.
50  * Returns 0 upon success.  Otherwise, returns -1.
51  */
52 int
53 mlsvc_init(void)
54 {
55 	pthread_attr_t tattr;
56 	int rc;
57 
58 	srvsvc_initialize();
59 	wkssvc_initialize();
60 	lsarpc_initialize();
61 	netr_initialize();
62 	dssetup_initialize();
63 	samr_initialize();
64 	svcctl_initialize();
65 	winreg_initialize();
66 	logr_initialize();
67 
68 	(void) lsa_query_primary_domain_info();
69 
70 	(void) pthread_attr_init(&tattr);
71 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
72 	rc = pthread_create(&mlsvc_keepalive_thr, &tattr,
73 	    mlsvc_keepalive, 0);
74 	(void) pthread_attr_destroy(&tattr);
75 	return (rc);
76 }
77 
78 /*ARGSUSED*/
79 static void *
80 mlsvc_keepalive(void *arg)
81 {
82 	unsigned long t;
83 	nt_domain_t *domain;
84 
85 	for (;;) {
86 		(void) sleep(MLSVC_KEEPALIVE_INTERVAL);
87 
88 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN) {
89 			domain = nt_domain_lookupbytype(NT_DOMAIN_PRIMARY);
90 			if (domain == NULL)
91 				(void) lsa_query_primary_domain_info();
92 		}
93 
94 		(void) srvsvc_gettime(&t);
95 	}
96 
97 	/*NOTREACHED*/
98 	return (NULL);
99 }
100