xref: /titanic_41/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision ddee57fa6897d2e39c7a9c3ea4247b298ac7da48)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/errno.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <strings.h>
30 #include <string.h>
31 #include <rpc/xdr.h>
32 #include <synch.h>
33 #include <pthread.h>
34 #include <smbsrv/smb_door_svc.h>
35 #include <smbsrv/smb_common_door.h>
36 #include <smbsrv/libsmb.h>
37 #include <smbsrv/libmlsvc.h>
38 #include <mlsvc.h>
39 
40 static void *mlsvc_keepalive(void *);
41 
42 static pthread_t mlsvc_keepalive_thr;
43 #define	MLSVC_KEEPALIVE_INTERVAL	(10 * 60)	/* 10 minutes */
44 
45 /*
46  * All NDR RPC service initialization is invoked from here.
47  * Returns 0 upon success.  Otherwise, returns -1.
48  */
49 int
50 mlsvc_init(void)
51 {
52 	pthread_attr_t tattr;
53 	int rc;
54 
55 	if (smb_logon_init() != NT_STATUS_SUCCESS)
56 		return (-1);
57 
58 	if ((rc = smb_dclocator_init()) != 0)
59 		return (rc);
60 
61 	srvsvc_initialize();
62 	wkssvc_initialize();
63 	lsarpc_initialize();
64 	netr_initialize();
65 	dssetup_initialize();
66 	samr_initialize();
67 	svcctl_initialize();
68 	winreg_initialize();
69 	logr_initialize();
70 	msgsvcsend_initialize();
71 	spoolss_initialize();
72 
73 	(void) pthread_attr_init(&tattr);
74 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
75 	rc = pthread_create(&mlsvc_keepalive_thr, &tattr,
76 	    mlsvc_keepalive, 0);
77 	(void) pthread_attr_destroy(&tattr);
78 	return (rc);
79 }
80 
81 void
82 mlsvc_fini(void)
83 {
84 	smb_logon_fini();
85 	svcctl_finalize();
86 	logr_finalize();
87 }
88 
89 /*ARGSUSED*/
90 static void *
91 mlsvc_keepalive(void *arg)
92 {
93 	unsigned long t;
94 
95 	for (;;) {
96 		(void) sleep(MLSVC_KEEPALIVE_INTERVAL);
97 
98 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN)
99 			(void) srvsvc_gettime(&t);
100 	}
101 
102 	/*NOTREACHED*/
103 	return (NULL);
104 }
105