| OLD | NEW |
| (Empty) |
| 1 /* Licensed to the Apache Software Foundation (ASF) under one or more | |
| 2 * contributor license agreements. See the NOTICE file distributed with | |
| 3 * this work for additional information regarding copyright ownership. | |
| 4 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| 5 * (the "License"); you may not use this file except in compliance with | |
| 6 * the License. You may obtain a copy of the License at | |
| 7 * | |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 * | |
| 10 * Unless required by applicable law or agreed to in writing, software | |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 * See the License for the specific language governing permissions and | |
| 14 * limitations under the License. | |
| 15 */ | |
| 16 | |
| 17 /* | |
| 18 * | |
| 19 * @author Mladen Turk | |
| 20 * @version $Id: user.c 1442587 2013-02-05 13:49:48Z rjung $ | |
| 21 */ | |
| 22 | |
| 23 #include "tcn.h" | |
| 24 #include "apr_user.h" | |
| 25 #include "apr_network_io.h" | |
| 26 | |
| 27 TCN_IMPLEMENT_CALL(jlong, User, uidCurrent)(TCN_STDARGS, jlong pool) | |
| 28 { | |
| 29 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 30 apr_uid_t uid; | |
| 31 apr_gid_t gid; | |
| 32 | |
| 33 UNREFERENCED(o); | |
| 34 TCN_THROW_IF_ERR(apr_uid_current(&uid, &gid, p), uid); | |
| 35 | |
| 36 cleanup: | |
| 37 return (jlong)uid; | |
| 38 } | |
| 39 | |
| 40 TCN_IMPLEMENT_CALL(jlong, User, gidCurrent)(TCN_STDARGS, jlong pool) | |
| 41 { | |
| 42 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 43 apr_uid_t uid; | |
| 44 apr_gid_t gid; | |
| 45 | |
| 46 UNREFERENCED(o); | |
| 47 TCN_THROW_IF_ERR(apr_uid_current(&uid, &gid, p), gid); | |
| 48 | |
| 49 cleanup: | |
| 50 return (jlong)gid; | |
| 51 } | |
| 52 | |
| 53 TCN_IMPLEMENT_CALL(jlong, User, uid)(TCN_STDARGS, jstring uname, jlong pool) | |
| 54 { | |
| 55 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 56 apr_uid_t uid; | |
| 57 apr_gid_t gid; | |
| 58 TCN_ALLOC_CSTRING(uname); | |
| 59 | |
| 60 UNREFERENCED(o); | |
| 61 TCN_THROW_IF_ERR(apr_uid_get(&uid, &gid, J2S(uname), p), uid); | |
| 62 | |
| 63 cleanup: | |
| 64 TCN_FREE_CSTRING(uname); | |
| 65 return (jlong)uid; | |
| 66 } | |
| 67 | |
| 68 TCN_IMPLEMENT_CALL(jlong, User, usergid)(TCN_STDARGS, jstring uname, | |
| 69 jlong pool) | |
| 70 { | |
| 71 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 72 apr_uid_t uid; | |
| 73 apr_gid_t gid; | |
| 74 TCN_ALLOC_CSTRING(uname); | |
| 75 | |
| 76 UNREFERENCED(o); | |
| 77 TCN_THROW_IF_ERR(apr_uid_get(&uid, &gid, J2S(uname), p), gid); | |
| 78 | |
| 79 cleanup: | |
| 80 TCN_FREE_CSTRING(uname); | |
| 81 return (jlong)gid; | |
| 82 } | |
| 83 | |
| 84 TCN_IMPLEMENT_CALL(jlong, User, gid)(TCN_STDARGS, jstring gname, jlong pool) | |
| 85 { | |
| 86 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 87 apr_gid_t gid; | |
| 88 TCN_ALLOC_CSTRING(gname); | |
| 89 | |
| 90 UNREFERENCED(o); | |
| 91 TCN_THROW_IF_ERR( apr_gid_get(&gid, J2S(gname), p), gid); | |
| 92 | |
| 93 cleanup: | |
| 94 TCN_FREE_CSTRING(gname); | |
| 95 return (jlong)gid; | |
| 96 } | |
| 97 | |
| 98 TCN_IMPLEMENT_CALL(jstring, User, username)(TCN_STDARGS, jlong userid, jlong poo
l) | |
| 99 { | |
| 100 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 101 apr_uid_t uid = (apr_uid_t)userid; | |
| 102 char *uname = NULL; | |
| 103 | |
| 104 UNREFERENCED(o); | |
| 105 TCN_THROW_IF_ERR(apr_uid_name_get(&uname, uid, p), uname); | |
| 106 | |
| 107 cleanup: | |
| 108 if (uname) | |
| 109 return AJP_TO_JSTRING(uname); | |
| 110 else | |
| 111 return NULL; | |
| 112 } | |
| 113 | |
| 114 TCN_IMPLEMENT_CALL(jstring, User, groupname)(TCN_STDARGS, jlong grpid, jlong poo
l) | |
| 115 { | |
| 116 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 117 apr_gid_t gid = (apr_uid_t)grpid; | |
| 118 char *gname = NULL; | |
| 119 | |
| 120 UNREFERENCED(o); | |
| 121 TCN_THROW_IF_ERR(apr_gid_name_get(&gname, gid, p), gname); | |
| 122 | |
| 123 cleanup: | |
| 124 if (gname) | |
| 125 return AJP_TO_JSTRING(gname); | |
| 126 else | |
| 127 return NULL; | |
| 128 } | |
| 129 | |
| 130 TCN_IMPLEMENT_CALL(jint, User,uidcompare)(TCN_STDARGS, jlong left, jlong right) | |
| 131 { | |
| 132 | |
| 133 UNREFERENCED_STDARGS; | |
| 134 return (int)apr_uid_compare((apr_uid_t)left, | |
| 135 (apr_uid_t)right); | |
| 136 } | |
| 137 | |
| 138 TCN_IMPLEMENT_CALL(jint, User,gidcompare)(TCN_STDARGS, jlong left, jlong right) | |
| 139 { | |
| 140 | |
| 141 UNREFERENCED_STDARGS; | |
| 142 return (int)apr_gid_compare((apr_gid_t)left, | |
| 143 (apr_gid_t)right); | |
| 144 } | |
| 145 | |
| 146 TCN_IMPLEMENT_CALL(jstring, User, homepath)(TCN_STDARGS, jstring uname, jlong po
ol) | |
| 147 { | |
| 148 apr_pool_t *p = J2P(pool, apr_pool_t *); | |
| 149 char *dirname = NULL; | |
| 150 TCN_ALLOC_CSTRING(uname); | |
| 151 | |
| 152 UNREFERENCED(o); | |
| 153 TCN_THROW_IF_ERR(apr_uid_homepath_get(&dirname, J2S(uname), | |
| 154 p), dirname); | |
| 155 | |
| 156 cleanup: | |
| 157 TCN_FREE_CSTRING(uname); | |
| 158 if (dirname) | |
| 159 return AJP_TO_JSTRING(dirname); | |
| 160 else | |
| 161 return NULL; | |
| 162 } | |
| 163 | |
| OLD | NEW |