1 /*****************************************************************************\
2  *  user_functions.c - Interface to functions dealing with users
3  *                        in the database.
4  ******************************************************************************
5  *  Copyright (C) 2010 Lawrence Livermore National Security.
6  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7  *  Written by Danny Auble da@llnl.gov, et. al.
8  *  CODE-OCEC-09-009. All rights reserved.
9  *
10  *  This file is part of Slurm, a resource management program.
11  *  For details, see <https://slurm.schedmd.com/>.
12  *  Please also read the included file: DISCLAIMER.
13  *
14  *  Slurm is free software; you can redistribute it and/or modify it under
15  *  the terms of the GNU General Public License as published by the Free
16  *  Software Foundation; either version 2 of the License, or (at your option)
17  *  any later version.
18  *
19  *  In addition, as a special exception, the copyright holders give permission
20  *  to link the code of portions of this program with the OpenSSL library under
21  *  certain conditions as described in each individual source file, and
22  *  distribute linked combinations including the two. You must obey the GNU
23  *  General Public License in all respects for all of the code used other than
24  *  OpenSSL. If you modify file(s) with this exception, you may extend this
25  *  exception to your version of the file(s), but you are not obligated to do
26  *  so. If you do not wish to do so, delete this exception statement from your
27  *  version.  If you delete this exception statement from all source files in
28  *  the program, then also delete it here.
29  *
30  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
31  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
32  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
33  *  details.
34  *
35  *  You should have received a copy of the GNU General Public License along
36  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
37  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
38 \*****************************************************************************/
39 
40 #include "slurm/slurm.h"
41 #include "slurm/slurm_errno.h"
42 #include "slurm/slurmdb.h"
43 
44 #include "src/common/slurm_accounting_storage.h"
45 
46 /*
47  * add users to accounting system
48  * IN:  user_list List of slurmdb_user_rec_t *
49  * RET: SLURM_SUCCESS on success SLURM_ERROR else
50  */
slurmdb_users_add(void * db_conn,List user_list)51 extern int slurmdb_users_add(void *db_conn, List user_list)
52 {
53 	if (db_api_uid == -1)
54 		db_api_uid = getuid();
55 
56 	return acct_storage_g_add_users(db_conn, db_api_uid, user_list);
57 }
58 
59 /*
60  * get info from the storage
61  * IN:  slurmdb_user_cond_t *
62  * IN:  params void *
63  * returns List of slurmdb_user_rec_t *
64  * note List needs to be freed with slurm_list_destroy() when called
65  */
slurmdb_users_get(void * db_conn,slurmdb_user_cond_t * user_cond)66 extern List slurmdb_users_get(void *db_conn, slurmdb_user_cond_t *user_cond)
67 {
68 	if (db_api_uid == -1)
69 		db_api_uid = getuid();
70 
71 	return acct_storage_g_get_users(db_conn, db_api_uid, user_cond);
72 }
73 
74 /*
75  * modify existing users in the accounting system
76  * IN:  slurmdb_user_cond_t *user_cond
77  * IN:  slurmdb_user_rec_t *user
78  * RET: List containing (char *'s) else NULL on error
79  * note List needs to be freed with slurm_list_destroy() when called
80  */
slurmdb_users_modify(void * db_conn,slurmdb_user_cond_t * user_cond,slurmdb_user_rec_t * user)81 extern List slurmdb_users_modify(void *db_conn,
82 				 slurmdb_user_cond_t *user_cond,
83 				 slurmdb_user_rec_t *user)
84 {
85 	if (db_api_uid == -1)
86 		db_api_uid = getuid();
87 
88 	return acct_storage_g_modify_users(db_conn, db_api_uid,
89 					   user_cond, user);
90 }
91 
92 /*
93  * remove users from accounting system
94  * IN:  slurmdb_user_cond_t *user_cond
95  * RET: List containing (char *'s) else NULL on error
96  * note List needs to be freed with slurm_list_destroy() when called
97  */
slurmdb_users_remove(void * db_conn,slurmdb_user_cond_t * user_cond)98 extern List slurmdb_users_remove(void *db_conn,
99 				 slurmdb_user_cond_t *user_cond)
100 {
101 	if (db_api_uid == -1)
102 		db_api_uid = getuid();
103 
104 	return acct_storage_g_remove_users(db_conn, db_api_uid, user_cond);
105 }
106