Showing the changes to Source/Tools/UnixTools (6 of 9 files). Show all
Unified · Split
| @@ -21,14 +21,23 @@ · 20 unmodified lines | ||
| 21 | 21 | // |
| 22 | 22 | //****************************************************************************************************** |
| 23 | 23 | |
| 24 | +// This will create a shared object for needed GSF functions | |
| 25 | + | |
| 24 | 26 | // Compiling for Linux: |
| 25 | 27 | // |
| 26 | −// Get PAM development libraries, e.g., for Ubuntu: apt-get install libpam0g-dev | |
| 28 | +// Get PAM development libraries, e.g., for Ubuntu: apt-get install libpam0g-dev | |
| 27 | 29 | // |
| 30 | +// To compile to an object library | |
| 28 | 31 | // gcc -c -Wall -Werror -fpic GSF.POSIX.c |
| 29 | −// gcc -shared -o GSF.POSIX.so GSF.POSIX.o -lpam -lpam_misc | |
| 32 | +// | |
| 33 | +// To compile as a shared object | |
| 34 | +// gcc -shared -o GSF.POSIX.so GSF.POSIX.o -lpam -lpam_misc -lcrypt | |
| 35 | +// | |
| 36 | +// To deploy, copy to user libraries folder | |
| 37 | +// sudo cp GSF.POSIX.so /usr/lib/ | |
| 30 | 38 | // |
| 31 | 39 | |
| 40 | +#include <stdlib.h> | |
| 32 | 41 | #include <security/pam_appl.h> |
| 33 | 42 | #include <security/pam_misc.h> |
| 34 | 43 | #include <sys/types.h> |
| @@ -39,26 +48,14 @@ · 4 unmodified lines | ||
| 39 | 48 | #include <grp.h> |
| 40 | 49 | #include <shadow.h> |
| 41 | 50 | #include <crypt.h> |
| 42 | − | |
| 43 | −// Structure used to return key spwd information | |
| 44 | −struct UserPasswordInformation | |
| 45 | −{ | |
| 46 | − // Do not include any pointer types in this structure | |
| 47 | − // to keep marshaling into .NET simple | |
| 48 | − long lastChangeDate; | |
| 49 | − long minDaysForChange; | |
| 50 | − long maxDaysForChange; | |
| 51 | − long warningDays; | |
| 52 | − long inactivityDays; | |
| 53 | − long accountExpirationDate; | |
| 54 | −}; | |
| 51 | +#include "GSF.POSIX.h" | |
| 55 | 52 | |
| 56 | 53 | // Define custom PAM conversation function for authentication |
| 57 | 54 | int AuthenticateConveration(int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr) |
| 58 | 55 | { |
| 59 | 56 | const struct pam_message* message = *msg; |
| 60 | 57 | |
| 61 | − if (num_msg == 1 && message->msg != NULL && message->msg_style == PAM_PROMPT_ECHO_ON) | |
| 58 | + if (num_msg == 1 && message->msg != NULL && message->msg_style == PAM_PROMPT_ECHO_OFF) | |
| 62 | 59 | { |
| 63 | 60 | // Provide password for the PAM conversation response that was passed into appdata_ptr |
| 64 | 61 | struct pam_response* reply = (struct pam_response*)malloc(sizeof(struct pam_response)); |
| @@ -139,8 +136,8 @@ int AuthenticateUser(const char* userName, const char* password) · 74 unmodified lines | ||
| 139 | 136 | pam_handle_t* pamh; |
| 140 | 137 | int retval; |
| 141 | 138 | |
| 142 | − // Start PAM - just associate with something simple like the "whoami" command | |
| 143 | − retval = pam_start("whoami", userName, &pamc, &pamh); | |
| 139 | + // Start PAM - just associate with something simple like the "passwd" command | |
| 140 | + retval = pam_start("gsf", userName, &pamc, &pamh); | |
| 144 | 141 | |
| 145 | 142 | if (retval == PAM_SUCCESS) |
| 146 | 143 | { |
| @@ -0,0 +1,73 @@ | ||
| 1 | +//****************************************************************************************************** | |
| 2 | +// GSF.POSIX.h - Gbtc | |
| 3 | +// | |
| 4 | +// Copyright � 2014, Grid Protection Alliance. All Rights Reserved. | |
| 5 | +// | |
| 6 | +// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | |
| 7 | +// the NOTICE file distributed with this work for additional information regarding copyright ownership. | |
| 8 | +// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may | |
| 9 | +// not use this file except in compliance with the License. You may obtain a copy of the License at: | |
| 10 | +// | |
| 11 | +// http://www.opensource.org/licenses/eclipse-1.0.php | |
| 12 | +// | |
| 13 | +// Unless agreed to in writing, the subject software distributed under the License is distributed on an | |
| 14 | +// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | |
| 15 | +// License for the specific language governing permissions and limitations. | |
| 16 | +// | |
| 17 | +// Code Modification History: | |
| 18 | +// ---------------------------------------------------------------------------------------------------- | |
| 19 | +// 09/14/2014 - J. Ritchie Carroll | |
| 20 | +// Generated original version of source code. | |
| 21 | +// | |
| 22 | +//****************************************************************************************************** | |
| 23 | + | |
| 24 | +// Structure used to return key spwd information | |
| 25 | +struct UserPasswordInformation | |
| 26 | +{ | |
| 27 | + // Do not include any pointer types in this structure | |
| 28 | + // to keep marshaling into .NET simple | |
| 29 | + long lastChangeDate; | |
| 30 | + long minDaysForChange; | |
| 31 | + long maxDaysForChange; | |
| 32 | + long warningDays; | |
| 33 | + long inactivityDays; | |
| 34 | + long accountExpirationDate; | |
| 35 | +}; | |
| 36 | + | |
| 37 | +int AuthenticateUser(const char* userName, const char* password); | |
| 38 | + | |
| 39 | +int ChangeUserPassword(const char* userName, const char* oldPassword, const char* newPassword); | |
| 40 | + | |
| 41 | +int GetLocalUserID(const char* userName, /*out*/ unsigned int* uid); | |
| 42 | + | |
| 43 | +// Preallocate outbound userName to 256 characters | |
| 44 | +int GetLocalUserName(unsigned int uid, /*out*/ char* userName); | |
| 45 | + | |
| 46 | +char* GetLocalUserHomeDirectory(const char* userName); | |
| 47 | + | |
| 48 | +char* GetLocalUserGecos(const char* userName); | |
| 49 | + | |
| 50 | +// Values for status parameter: | |
| 51 | +// 1 -- "*" Account is disabled | |
| 52 | +// 2 -- "!<...>" The account locked out (e.g., with passwd -l <username>) | |
| 53 | +// 2 -- "!" The password expired / never set - effectively locked out | |
| 54 | +// 2 -- "!!" The password expired / never set - effectively locked out | |
| 55 | +// 3 -- "" No password defined | |
| 56 | +// 0 -- "<else>" Account assumed normal (encrypted password) | |
| 57 | +int GetLocalUserPasswordInformation(const char* userName, struct UserPasswordInformation* userPasswordInfo, /*out*/ int* status); | |
| 58 | + | |
| 59 | +int SetLocalUserPassword(const char* userName, const char* password, const char* salt); | |
| 60 | + | |
| 61 | +char* GetPasswordHash(const char* password, const char* salt); | |
| 62 | + | |
| 63 | +int GetLocalUserGroupCount(const char* userName); | |
| 64 | + | |
| 65 | +// Preallocate outbound groupIDs as an unsigned integer array sized from GetLocalUserGroupCount | |
| 66 | +int GetLocalUserGroupIDs(const char* userName, int groupCount, /*out*/ gid_t** groupIDs); | |
| 67 | + | |
| 68 | +int GetLocalGroupID(const char* groupName, /*out*/ unsigned int* gid); | |
| 69 | + | |
| 70 | +// Preallocate outbound groupName to 256 characters | |
| 71 | +int GetLocalGroupName(unsigned int gid, /*out*/ char* groupName); | |
| 72 | + | |
| 73 | +char** GetLocalGroupMembers(const char* groupName); | |
| @@ -11,9 +11,14 @@ · 10 unmodified lines | ||
| 11 | 11 | </ProjectConfiguration> |
| 12 | 12 | </ItemGroup> |
| 13 | 13 | <ItemGroup> |
| 14 | + <ClCompile Include="gsf.c" /> | |
| 14 | 15 | <ClCompile Include="GSF.POSIX.c"> |
| 15 | 16 | <DeploymentContent>false</DeploymentContent> |
| 16 | 17 | </ClCompile> |
| 18 | + <ClCompile Include="test.c" /> | |
| 19 | + </ItemGroup> | |
| 20 | + <ItemGroup> | |
| 21 | + <ClInclude Include="GSF.POSIX.h" /> | |
| 17 | 22 | </ItemGroup> |
| 18 | 23 | <PropertyGroup Label="Globals"> |
| 19 | 24 | <ProjectGuid>{63AF9800-2CDE-41F7-9706-76EF0AE181CE}</ProjectGuid> |
| @@ -18,5 +18,16 @@ · 17 unmodified lines | ||
| 18 | 18 | <ClCompile Include="GSF.POSIX.c"> |
| 19 | 19 | <Filter>Source Files</Filter> |
| 20 | 20 | </ClCompile> |
| 21 | + <ClCompile Include="gsf.c"> | |
| 22 | + <Filter>Source Files</Filter> | |
| 23 | + </ClCompile> | |
| 24 | + <ClCompile Include="test.c"> | |
| 25 | + <Filter>Source Files</Filter> | |
| 26 | + </ClCompile> | |
| 27 | + </ItemGroup> | |
| 28 | + <ItemGroup> | |
| 29 | + <ClInclude Include="GSF.POSIX.h"> | |
| 30 | + <Filter>Header Files</Filter> | |
| 31 | + </ClInclude> | |
| 21 | 32 | </ItemGroup> |
| 22 | 33 | </Project> |
| @@ -0,0 +1,84 @@ | ||
| 1 | +//****************************************************************************************************** | |
| 2 | +// gsf.c - Gbtc | |
| 3 | +// | |
| 4 | +// Copyright � 2014, Grid Protection Alliance. All Rights Reserved. | |
| 5 | +// | |
| 6 | +// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | |
| 7 | +// the NOTICE file distributed with this work for additional information regarding copyright ownership. | |
| 8 | +// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may | |
| 9 | +// not use this file except in compliance with the License. You may obtain a copy of the License at: | |
| 10 | +// | |
| 11 | +// http://www.opensource.org/licenses/eclipse-1.0.php | |
| 12 | +// | |
| 13 | +// Unless agreed to in writing, the subject software distributed under the License is distributed on an | |
| 14 | +// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | |
| 15 | +// License for the specific language governing permissions and limitations. | |
| 16 | +// | |
| 17 | +// Code Modification History: | |
| 18 | +// ---------------------------------------------------------------------------------------------------- | |
| 19 | +// 08/29/2014 - J. Ritchie Carroll | |
| 20 | +// Generated original version of source code. | |
| 21 | +// | |
| 22 | +//****************************************************************************************************** | |
| 23 | + | |
| 24 | +// This will create a hosted Mono service that contains needed GSF functions | |
| 25 | + | |
| 26 | +// Compiling for Linux: | |
| 27 | +// | |
| 28 | +// Get PAM development libraries, e.g., for Ubuntu: apt-get install libpam0g-dev | |
| 29 | +// | |
| 30 | +// Compile GSF.POSIX.o object library first, then... | |
| 31 | +// | |
| 32 | +// To compile as a mono hosted executable: | |
| 33 | +// gcc -o gsf gsf.c `pkg-config --cflags --libs mono-2` GSF.POSIX.o -lm -lpam -lpam_misc -lcrypt -rdynamic | |
| 34 | +// | |
| 35 | +// To export symbols for DllImport("__Internal") use gcc parameter -rdynamic | |
| 36 | +// | |
| 37 | + | |
| 38 | +#include <mono/jit/jit.h> | |
| 39 | +#include <mono/metadata/environment.h> | |
| 40 | +#include <stdlib.h> | |
| 41 | + | |
| 42 | +int main(int argc, char* argv[]) | |
| 43 | +{ | |
| 44 | + MonoDomain *domain; | |
| 45 | + MonoAssembly *assembly; | |
| 46 | + const char *file; | |
| 47 | + int retval; | |
| 48 | + | |
| 49 | + if (argc < 2) | |
| 50 | + { | |
| 51 | + fprintf(stderr, "Please provide name of .NET assembly to load.\n"); | |
| 52 | + return 1; | |
| 53 | + } | |
| 54 | + | |
| 55 | + file = argv[1]; | |
| 56 | + | |
| 57 | + // Load the default Mono configuration file, this is needed | |
| 58 | + // if you are planning on using the dllmaps defined on the | |
| 59 | + // system configuration | |
| 60 | + mono_config_parse(NULL); | |
| 61 | + | |
| 62 | + // Create mono AppDomain | |
| 63 | + domain = mono_jit_init(file); | |
| 64 | + | |
| 65 | + // Open entry assembly in new AppDomain | |
| 66 | + assembly = mono_domain_assembly_open(domain, file); | |
| 67 | + | |
| 68 | + if (assembly != NULL) | |
| 69 | + { | |
| 70 | + // mono_jit_exec runs the Main() method in the assembly | |
| 71 | + mono_jit_exec(domain, assembly, argc - 1, argv + 1); | |
| 72 | + | |
| 73 | + // Get exit code from entry assembly | |
| 74 | + retval = mono_environment_exitcode_get(); | |
| 75 | + } | |
| 76 | + else | |
| 77 | + { | |
| 78 | + retval = 2; | |
| 79 | + } | |
| 80 | + | |
| 81 | + mono_jit_cleanup(domain); | |
| 82 | + | |
| 83 | + return retval; | |
| 84 | +} | |
| @@ -0,0 +1,63 @@ | ||
| 1 | +//****************************************************************************************************** | |
| 2 | +// test.c - Gbtc | |
| 3 | +// | |
| 4 | +// Copyright � 2014, Grid Protection Alliance. All Rights Reserved. | |
| 5 | +// | |
| 6 | +// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | |
| 7 | +// the NOTICE file distributed with this work for additional information regarding copyright ownership. | |
| 8 | +// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may | |
| 9 | +// not use this file except in compliance with the License. You may obtain a copy of the License at: | |
| 10 | +// | |
| 11 | +// http://www.opensource.org/licenses/eclipse-1.0.php | |
| 12 | +// | |
| 13 | +// Unless agreed to in writing, the subject software distributed under the License is distributed on an | |
| 14 | +// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | |
| 15 | +// License for the specific language governing permissions and limitations. | |
| 16 | +// | |
| 17 | +// Code Modification History: | |
| 18 | +// ---------------------------------------------------------------------------------------------------- | |
| 19 | +// 08/29/2014 - J. Ritchie Carroll | |
| 20 | +// Generated original version of source code. | |
| 21 | +// | |
| 22 | +//****************************************************************************************************** | |
| 23 | + | |
| 24 | +// Compiling for Linux: | |
| 25 | +// | |
| 26 | +// Compile GSF.POSIX.o object library first, then... | |
| 27 | +// | |
| 28 | +// To compile as a mono hosted executable: | |
| 29 | +// gcc -o test test.c GSF.POSIX.o -lpam -lpam_misc -lcrypt | |
| 30 | +// | |
| 31 | + | |
| 32 | +#include <stdlib.h> | |
| 33 | +#include <stdio.h> | |
| 34 | +#include "GSF.POSIX.h" | |
| 35 | + | |
| 36 | +int main(int argc, char* argv[]) | |
| 37 | +{ | |
| 38 | + int retval; | |
| 39 | + | |
| 40 | + if (argc != 2) | |
| 41 | + { | |
| 42 | + fprintf(stderr, "Specify user name as an argument.\n"); | |
| 43 | + retval = 1; | |
| 44 | + } | |
| 45 | + else | |
| 46 | + { | |
| 47 | + struct UserPasswordInformation info; | |
| 48 | + int status; | |
| 49 | + int retval = GetLocalUserPasswordInformation(argv[1], &info, &status); | |
| 50 | + | |
| 51 | + fprintf(stdout, "retval = %d\n", retval); | |
| 52 | + | |
| 53 | + if (retval == 0) | |
| 54 | + { | |
| 55 | + fprintf(stdout, "lastChangeDate = %ld\n", info.lastChangeDate); | |
| 56 | + fprintf(stdout, "minDaysForChange = %ld\n", info.minDaysForChange); | |
| 57 | + fprintf(stdout, "maxDaysForChange = %ld\n", info.maxDaysForChange); | |
| 58 | + fprintf(stdout, "status = %d\n", status); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + return retval; | |
| 63 | +} | |