History

Updates to Unix based UserInfo implementation.

ritchiecarroll committed 12 years ago

Commit bf22ae21 parent 2ab4c339 files · +284 −43Browse files

Showing the changes to Source/Tools/UnixTools (6 of 9 files). Show all

Unified · Split

6 files
  1. Source/Tools/UnixTools/GSF.POSIX.c +15 −18
  2. Source/Tools/UnixTools/GSF.POSIX.h +73 −0
  3. Source/Tools/UnixTools/UnixTools.vcxproj +5 −0
  4. Source/Tools/UnixTools/UnixTools.vcxproj.filters +11 −0
  5. Source/Tools/UnixTools/gsf.c +84 −0
  6. Source/Tools/UnixTools/test.c +63 −0
Source/Tools/UnixTools/GSF.POSIX.c+15−18
@@ -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// Compiling for Linux:26// Compiling for Linux:
25//27//
26// Get PAM development libraries, e.g., for Ubuntu: apt-get install libpam0g-dev28// Get PAM development libraries, e.g., for Ubuntu: apt-get install libpam0g-dev
27//29//
30// To compile to an object library
28// gcc -c -Wall -Werror -fpic GSF.POSIX.c31// gcc -c -Wall -Werror -fpic GSF.POSIX.c
29// gcc -shared -o GSF.POSIX.so GSF.POSIX.o -lpam -lpam_misc32//
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#include <security/pam_appl.h>41#include <security/pam_appl.h>
33#include <security/pam_misc.h>42#include <security/pam_misc.h>
34#include <sys/types.h>43#include <sys/types.h>
@@ -39,26 +48,14 @@ · 4 unmodified lines
39#include <grp.h>48#include <grp.h>
40#include <shadow.h>49#include <shadow.h>
41#include <crypt.h>50#include <crypt.h>
42 51#include "GSF.POSIX.h"
43// Structure used to return key spwd information
44struct 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};
55 52
56// Define custom PAM conversation function for authentication53// Define custom PAM conversation function for authentication
57int AuthenticateConveration(int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr)54int AuthenticateConveration(int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr)
58{55{
59 const struct pam_message* message = *msg;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 // Provide password for the PAM conversation response that was passed into appdata_ptr60 // Provide password for the PAM conversation response that was passed into appdata_ptr
64 struct pam_response* reply = (struct pam_response*)malloc(sizeof(struct pam_response));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 pam_handle_t* pamh; 136 pam_handle_t* pamh;
140 int retval;137 int retval;
141 138
142 // Start PAM - just associate with something simple like the "whoami" command139 // Start PAM - just associate with something simple like the "passwd" command
143 retval = pam_start("whoami", userName, &pamc, &pamh);140 retval = pam_start("gsf", userName, &pamc, &pamh);
144 141
145 if (retval == PAM_SUCCESS)142 if (retval == PAM_SUCCESS)
146 {143 {
Source/Tools/UnixTools/GSF.POSIX.h+73−0
@@ -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
25struct 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
37int AuthenticateUser(const char* userName, const char* password);
38
39int ChangeUserPassword(const char* userName, const char* oldPassword, const char* newPassword);
40
41int GetLocalUserID(const char* userName, /*out*/ unsigned int* uid);
42
43// Preallocate outbound userName to 256 characters
44int GetLocalUserName(unsigned int uid, /*out*/ char* userName);
45
46char* GetLocalUserHomeDirectory(const char* userName);
47
48char* 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)
57int GetLocalUserPasswordInformation(const char* userName, struct UserPasswordInformation* userPasswordInfo, /*out*/ int* status);
58
59int SetLocalUserPassword(const char* userName, const char* password, const char* salt);
60
61char* GetPasswordHash(const char* password, const char* salt);
62
63int GetLocalUserGroupCount(const char* userName);
64
65// Preallocate outbound groupIDs as an unsigned integer array sized from GetLocalUserGroupCount
66int GetLocalUserGroupIDs(const char* userName, int groupCount, /*out*/ gid_t** groupIDs);
67
68int GetLocalGroupID(const char* groupName, /*out*/ unsigned int* gid);
69
70// Preallocate outbound groupName to 256 characters
71int GetLocalGroupName(unsigned int gid, /*out*/ char* groupName);
72
73char** GetLocalGroupMembers(const char* groupName);
Source/Tools/UnixTools/UnixTools.vcxproj+5−0
@@ -11,9 +11,14 @@ · 10 unmodified lines
11 </ProjectConfiguration>11 </ProjectConfiguration>
12 </ItemGroup>12 </ItemGroup>
13 <ItemGroup>13 <ItemGroup>
14 <ClCompile Include="gsf.c" />
14 <ClCompile Include="GSF.POSIX.c">15 <ClCompile Include="GSF.POSIX.c">
15 <DeploymentContent>false</DeploymentContent>16 <DeploymentContent>false</DeploymentContent>
16 </ClCompile>17 </ClCompile>
18 <ClCompile Include="test.c" />
19 </ItemGroup>
20 <ItemGroup>
21 <ClInclude Include="GSF.POSIX.h" />
17 </ItemGroup>22 </ItemGroup>
18 <PropertyGroup Label="Globals">23 <PropertyGroup Label="Globals">
19 <ProjectGuid>{63AF9800-2CDE-41F7-9706-76EF0AE181CE}</ProjectGuid>24 <ProjectGuid>{63AF9800-2CDE-41F7-9706-76EF0AE181CE}</ProjectGuid>
Source/Tools/UnixTools/UnixTools.vcxproj.filters+11−0
@@ -18,5 +18,16 @@ · 17 unmodified lines
18 <ClCompile Include="GSF.POSIX.c">18 <ClCompile Include="GSF.POSIX.c">
19 <Filter>Source Files</Filter>19 <Filter>Source Files</Filter>
20 </ClCompile>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 </ItemGroup>32 </ItemGroup>
22</Project>33</Project>
Source/Tools/UnixTools/gsf.c+84−0
@@ -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
42int 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}
Source/Tools/UnixTools/test.c+63−0
@@ -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
36int 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}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t