xref: /titanic_44/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision 21bf64a78855d076f09716ea1c06175d954e934c)
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) pthread_attr_init(&tattr);
69 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
70 	rc = pthread_create(&mlsvc_keepalive_thr, &tattr,
71 	    mlsvc_keepalive, 0);
72 	(void) pthread_attr_destroy(&tattr);
73 	return (rc);
74 }
75 
76 /*ARGSUSED*/
77 static void *
78 mlsvc_keepalive(void *arg)
79 {
80 	unsigned long t;
81 	nt_domain_t *domain;
82 
83 	for (;;) {
84 		(void) sleep(MLSVC_KEEPALIVE_INTERVAL);
85 
86 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN) {
87 			domain = nt_domain_lookupbytype(NT_DOMAIN_PRIMARY);
88 			if (domain == NULL)
89 				(void) lsa_query_primary_domain_info();
90 		}
91 
92 		(void) srvsvc_gettime(&t);
93 	}
94 
95 	/*NOTREACHED*/
96 	return (NULL);
97 }
98