windows porting changes
[csql.git] / src / server / UserManagerImpl.cxx
blob1163d6aa74b57cb1a187d8913cf34b3c6155acf6
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<UserManagerImpl.h>
17 #include<CatalogTables.h>
18 #include<Debug.h>
19 int UserManagerImpl::createUser(const char *name, const char *password)
21 if (!isDba)
23 printError(ErrNoPrivilege,
24 "Only DBA privileged schema can create users");
25 return ErrNoPrivilege;
27 int ret = 0;
28 //add entry to USER table
29 CatalogTableUSER cUser(systemDatabase_);
30 cUser.insert(name, password);
31 if (0 != ret)
33 printError(ErrSysInternal,
34 "Catalog table insert failed for the user %s",name);
35 return ErrSysInternal;
37 return OK;
40 int UserManagerImpl::deleteUser(const char *name)
42 if (!isDba)
44 printError(ErrNoPrivilege,
45 "Only DBA privileged schema can delete users");
46 return ErrNoPrivilege;
48 int ret = 0;
49 CatalogTableUSER cUser(systemDatabase_);
50 ret = cUser.remove(name);
51 if (0 != ret)
53 printError(ErrNotExists,
54 "User %s not exists",name);
55 return ErrNotExists;
57 return OK;
60 int UserManagerImpl::changePassword(const char *usrName, const char* newPasswd)
62 if (!isDba)
64 printError(ErrNoPrivilege,
65 "Only DBA privileged schema can change password for other users");
66 return ErrNoPrivilege;
68 int ret = 0;
69 CatalogTableUSER cUser(systemDatabase_);
70 ret = cUser.changePass(usrName, newPasswd );
71 if (0 != ret)
73 printError(ErrSysInternal,
74 "Catalog table updation failed for user %s",usrName);
75 return ErrSysInternal;
77 return OK;
81 int UserManagerImpl::changePassword(const char* newPasswd)
83 int ret = 0;
84 CatalogTableUSER cUser(systemDatabase_);
85 ret = cUser.changePass(userName, newPasswd );
86 if (0 != ret)
88 printError(ErrSysInternal,
89 "Catalog table updation failed");
90 return ErrSysInternal;
92 return OK;