reindent-20030715
[openafs.git] / src / sia / siad.c
index ef7c129..01aa8e0 100644 (file)
@@ -14,7 +14,8 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #include <afs/stds.h>
 #include <sys/types.h>
@@ -58,7 +59,8 @@ extern char *ktc_tkt_string();
  * To make SIA recognize a new library, touch /etc/sia/matrix.conf.
  */
 #define VERS "AFS3"
-static void afs_siad_debug(char *fmt, ...)
+static void
+afs_siad_debug(char *fmt, ...)
 {
     struct stat sbuf;
     FILE *fp;
@@ -68,13 +70,13 @@ static void afs_siad_debug(char *fmt, ...)
     va_list args;
 
     /* Only print if file exists. */
-    if (stat(DEBUG_FILE, &sbuf)<0)
+    if (stat(DEBUG_FILE, &sbuf) < 0)
        return;
 
-    if ((fp=fopen(DEBUG_FILE, "a")) == NULL)
+    if ((fp = fopen(DEBUG_FILE, "a")) == NULL)
        return;
 
-    (void) time(&now);
+    (void)time(&now);
     when = ctime(&now);
     when[24] = '\0';
 
@@ -89,13 +91,15 @@ static void afs_siad_debug(char *fmt, ...)
 }
 
 /* siad_init - Once per reboot processing goes here. */
-int siad_init(void)
+int
+siad_init(void)
 {
     return SIADSUCCESS;
 }
 
 /* malloc any needed space required over the authentication session here. */
-int siad_ses_init(SIAENTITY *entity, int pkgind)
+int
+siad_ses_init(SIAENTITY * entity, int pkgind)
 {
     return SIADSUCCESS;
 }
@@ -103,38 +107,42 @@ int siad_ses_init(SIAENTITY *entity, int pkgind)
 /* We set the pwd entry in siad_ses_authent if we succeed in authenticating. 
  * Otherwise the BSD mechanism will incur a core dump.
  */
-int siad_ses_estab(sia_collect_func_t *collect, SIAENTITY *entity, int pkgind)
+int
+siad_ses_estab(sia_collect_func_t * collect, SIAENTITY * entity, int pkgind)
 {
     return SIASUCCESS;
 }
 
-int siad_ses_launch(sia_collect_func_t *collect, SIAENTITY *entity, int pkgind)
+int
+siad_ses_launch(sia_collect_func_t * collect, SIAENTITY * entity, int pkgind)
 {
     return SIADSUCCESS;
 }
 
 /* Free up space malloc'd in siad_ses_init() */
-int siad_ses_release(SIAENTITY *entity, int pkgind)
+int
+siad_ses_release(SIAENTITY * entity, int pkgind)
 {
     return SIADSUCCESS;
 }
 
-int siad_get_groups(struct sia_context *context, const char *username,
-                   gid_t *buf, int *numgroups, int maxgroups)
+int
+siad_get_groups(struct sia_context *context, const char *username,
+               gid_t * buf, int *numgroups, int maxgroups)
 {
     afs_siad_debug("siad_get_groups returning failure.\n");
     return SIADFAIL;
 }
 
 /* Print the reason we failed to authenticate. */
-static void afs_siad_authent_print_reason(sia_collect_func_t *collect,
-                                         char *reason)
+static void
+afs_siad_authent_print_reason(sia_collect_func_t * collect, char *reason)
 {
     unsigned char err_msg[128];
 
     if (collect) {
-       (void) sprintf(err_msg, "Unable to authenticate to AFS because %s",
-                      reason);
+       (void)sprintf(err_msg, "Unable to authenticate to AFS because %s",
+                     reason);
        sia_warning(collect, err_msg);
     }
 }
@@ -156,8 +164,8 @@ static void afs_siad_authent_print_reason(sia_collect_func_t *collect,
  * SIADFAIL | SIADSTOP - calling routine should return.
  */
 int
-afs_siad_get_name_password(sia_collect_func_t *collect,SIAENTITY * entity,
-                          int* got_pass)
+afs_siad_get_name_password(sia_collect_func_t * collect, SIAENTITY * entity,
+                          int *got_pass)
 {
     int need_name = 0;
     int need_pass = 0;
@@ -168,21 +176,23 @@ afs_siad_get_name_password(sia_collect_func_t *collect,SIAENTITY * entity,
     *got_pass = 0;
 
     if ((!entity->name) || (!(*entity->name))) {
-       entity->name = malloc(SIANAMEMIN+1);
-       if(entity->name == NULL) {
-         afs_siad_debug("afs_siad_get_name_password: failed to malloc name.\n");
-         code = SIADFAIL;
-         goto fail_free;
-        }
+       entity->name = malloc(SIANAMEMIN + 1);
+       if (entity->name == NULL) {
+           afs_siad_debug
+               ("afs_siad_get_name_password: failed to malloc name.\n");
+           code = SIADFAIL;
+           goto fail_free;
+       }
        *(entity->name) = '\0';
        need_name = 1;
     }
     if ((!entity->password) || (!(*entity->password))) {
-       entity->password = malloc(SIAMXPASSWORD+1);
-       if(entity->password == NULL) {
-         afs_siad_debug("afs_siad_get_name_password: failed to malloc password.\n");
-         code = SIADFAIL;
-         goto fail_free;
+       entity->password = malloc(SIAMXPASSWORD + 1);
+       if (entity->password == NULL) {
+           afs_siad_debug
+               ("afs_siad_get_name_password: failed to malloc password.\n");
+           code = SIADFAIL;
+           goto fail_free;
        }
        *(entity->password) = '\0';
        need_pass = 1;
@@ -194,25 +204,26 @@ afs_siad_get_name_password(sia_collect_func_t *collect,SIAENTITY * entity,
            goto fail_free;
        }
        if (need_name) {
-           prompts[0].prompt = (unsigned char*)"login: ";
-           prompts[0].result = (unsigned char*)entity->name;
+           prompts[0].prompt = (unsigned char *)"login: ";
+           prompts[0].result = (unsigned char *)entity->name;
            prompts[0].min_result_length = 1;
            prompts[0].max_result_length = SIANAMEMIN;
            prompts[0].control_flags = SIAPRINTABLE;
            n_prompts = 1;
        }
        if (need_pass) {
-           prompts[n_prompts].prompt = (unsigned char*)"Password:";
-           prompts[n_prompts].result = (unsigned char*)entity->password;
+           prompts[n_prompts].prompt = (unsigned char *)"Password:";
+           prompts[n_prompts].result = (unsigned char *)entity->password;
            prompts[n_prompts].min_result_length = 0;
            prompts[n_prompts].max_result_length = SIAMXPASSWORD;
            prompts[n_prompts].control_flags = SIARESINVIS;
            n_prompts++;
        }
-       if (n_prompts>1)
-           code = (*collect)(0, SIAFORM, (uchar_t *)"", n_prompts, prompts);
+       if (n_prompts > 1)
+           code =
+               (*collect) (0, SIAFORM, (uchar_t *) "", n_prompts, prompts);
        else
-           code = (*collect)(240, SIAONELINER, (uchar_t *)"", 1, prompts);
+           code = (*collect) (240, SIAONELINER, (uchar_t *) "", 1, prompts);
        if (code != SIACOLSUCCESS) {
            code = SIADFAIL | SIADSTOP;
            goto fail_free;
@@ -221,14 +232,14 @@ afs_siad_get_name_password(sia_collect_func_t *collect,SIAENTITY * entity,
     *got_pass = need_pass;
     return SIADSUCCESS;
 
- fail_free:
+  fail_free:
     if (need_name) {
        free(entity->name);
-       entity->name = (char*)0;
+       entity->name = (char *)0;
     }
     if (need_pass) {
        free(entity->password);
-       entity->password = (char*)0;
+       entity->password = (char *)0;
     }
     return code;
 }
@@ -262,14 +273,15 @@ afs_siad_get_name_password(sia_collect_func_t *collect,SIAENTITY * entity,
  * if some other mechanism succeeds in authenticating it will probably want to
  * set the entity->pwd field to something other than /etc/passwd. 
  */
-int siad_ses_authent(sia_collect_func_t *collect, SIAENTITY *entity,
-                    int siastat, int pkgind)
+int
+siad_ses_authent(sia_collect_func_t * collect, SIAENTITY * entity,
+                int siastat, int pkgind)
 {
     int got_pass = 0;
     int code = 0;
-    char *reason; /* returned by authenticate. */
+    char *reason;              /* returned by authenticate. */
     int password_expires = -1;
-    struct passwd *pwd = (struct passwd*)0;
+    struct passwd *pwd = (struct passwd *)0;
     extern struct passwd *getpwnam();
 
     code = afs_siad_get_name_password(collect, entity, &got_pass);
@@ -288,14 +300,10 @@ int siad_ses_authent(sia_collect_func_t *collect, SIAENTITY *entity,
        goto authent_fail;
     }
 
-    code = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION | KA_USERAUTH_DOSETPAG,
-                                     entity->name,
-                                     (char*)0, /* instance */
-                                     (char*)0, /* realm */
-                                     entity->password,
-                                     0, /* lifetime */
-                                     &password_expires,
-                                     0 /* spare2 */,
+    code = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION | KA_USERAUTH_DOSETPAG, entity->name, (char *)0,     /* instance */
+                                     (char *)0,        /* realm */
+                                     entity->password, 0,      /* lifetime */
+                                     &password_expires, 0 /* spare2 */ ,
                                      &reason);
 
     if (code) {
@@ -308,12 +316,12 @@ int siad_ses_authent(sia_collect_func_t *collect, SIAENTITY *entity,
     }
 
     if (!entity->pwd) {
-       entity->pwd = (struct passwd*)malloc(sizeof(struct passwd));
+       entity->pwd = (struct passwd *)malloc(sizeof(struct passwd));
        if (!entity->pwd) {
            code = SIADFAIL;
            goto authent_fail;
        }
-       memset((void*)entity->pwd, '\0', sizeof(struct passwd));
+       memset((void *)entity->pwd, '\0', sizeof(struct passwd));
        if (sia_make_entity_pwd(pwd, entity) != SIASUCCESS) {
            afs_siad_debug("siad_ses_authent: Can't set pwd into entity.\n");
            code = SIADFAIL;
@@ -323,15 +331,13 @@ int siad_ses_authent(sia_collect_func_t *collect, SIAENTITY *entity,
 
     /* Set PASSWORD_EXPIRES env variable if necessary */
     if (password_expires >= 0 && password_expires < 255) {
-        char sbuffer[10];
-        sprintf(sbuffer, "%d", password_expires);
-        (void)setenv("PASSWORD_EXPIRES", sbuffer, 1);
+       char sbuffer[10];
+       sprintf(sbuffer, "%d", password_expires);
+       (void)setenv("PASSWORD_EXPIRES", sbuffer, 1);
     }
-
 #if defined(AFS_KERBEROS_ENV)
-    if (pwd)
-    {
-        if ( chown(ktc_tkt_string(), pwd->pw_uid, pwd->pw_gid) < 0 )
+    if (pwd) {
+       if (chown(ktc_tkt_string(), pwd->pw_uid, pwd->pw_gid) < 0)
            afs_siad_debug("siad_ses_authent fails - krb chown.\n");
     }
 #endif
@@ -340,7 +346,7 @@ int siad_ses_authent(sia_collect_func_t *collect, SIAENTITY *entity,
     afs_sia_log("siad_ses_authent returning success.\n");
     return SIADSUCCESS;
 
- authent_fail:
+  authent_fail:
     afs_sia_log("siad_ses_authent fails, code=%d.\n", code);
     afs_siad_debug("siad_ses_authent fails, code=%d.\n", code);
     return code;
@@ -357,13 +363,14 @@ int siad_ses_authent(sia_collect_func_t *collect, SIAENTITY *entity,
  * in. Also, colinput is typically false in this case as well as collect
  * being null.
  */
-int siad_ses_reauthent(sia_collect_func_t *collect, SIAENTITY *entity,
-                                int siastat, int pkgind)
+int
+siad_ses_reauthent(sia_collect_func_t * collect, SIAENTITY * entity,
+                  int siastat, int pkgind)
 {
     int got_pass = 0;
     int code = 0;
-    char *reason; /* returned by authenticate. */
-    struct passwd *pwd = (struct passwd*)0;
+    char *reason;              /* returned by authenticate. */
+    struct passwd *pwd = (struct passwd *)0;
     extern struct passwd *getpwnam();
 
     if (siastat == SIADSUCCESS)
@@ -379,11 +386,9 @@ int siad_ses_reauthent(sia_collect_func_t *collect, SIAENTITY *entity,
        goto reauthent_fail;
     }
 
-    code = ka_VerifyUserPassword(KA_USERAUTH_VERSION, entity->name,
-                                (char*)0, /* instance */
-                                (char*)0, /* realm */
-                                entity->password,
-                                0 /* spare2 */,
+    code = ka_VerifyUserPassword(KA_USERAUTH_VERSION, entity->name, (char *)0, /* instance */
+                                (char *)0,     /* realm */
+                                entity->password, 0 /* spare2 */ ,
                                 &reason);
 
     if (code) {
@@ -396,14 +401,15 @@ int siad_ses_reauthent(sia_collect_func_t *collect, SIAENTITY *entity,
     }
 
     if (!entity->pwd) {
-       entity->pwd = (struct passwd*)malloc(sizeof(struct passwd));
+       entity->pwd = (struct passwd *)malloc(sizeof(struct passwd));
        if (!entity->pwd) {
            code = SIADFAIL;
            goto reauthent_fail;
        }
-       memset((void*)entity->pwd, '\0', sizeof(struct passwd));
+       memset((void *)entity->pwd, '\0', sizeof(struct passwd));
        if (sia_make_entity_pwd(pwd, entity) != SIASUCCESS) {
-           afs_siad_debug("siad_ses_reauthent: Can't set pwd into entity.\n");
+           afs_siad_debug
+               ("siad_ses_reauthent: Can't set pwd into entity.\n");
            code = SIADFAIL;
            goto reauthent_fail;
        }
@@ -413,115 +419,131 @@ int siad_ses_reauthent(sia_collect_func_t *collect, SIAENTITY *entity,
     afs_sia_log("siad_ses_reauthent returning success.\n");
     return SIADSUCCESS;
 
- reauthent_fail:
+  reauthent_fail:
     afs_sia_log("siad_ses_reauthent fails, code=%d.\n", code);
     afs_siad_debug("siad_ses_reauthent fails, code=%d.\n", code);
     return code;
 }
 
-int siad_chk_invoker(void)
+int
+siad_chk_invoker(void)
 {
     afs_siad_debug("siad_chk_invoker returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_ses_suauthent(sia_collect_func_t *collect, SIAENTITY *entity,
-                      int siastat, int pkgind)
+int
+siad_ses_suauthent(sia_collect_func_t * collect, SIAENTITY * entity,
+                  int siastat, int pkgind)
 {
     afs_siad_debug("siad_ses_suauthent returning failure.\n");
     return SIADFAIL;
 }
 
 
-int siad_chg_finger(sia_collect_func_t *collect, const char *username,
-                   int argc, char *argv[])
+int
+siad_chg_finger(sia_collect_func_t * collect, const char *username, int argc,
+               char *argv[])
 {
     afs_siad_debug("siad_chg_finger returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_chg_password(sia_collect_func_t *collect, const char *username,
-                     int argc, char *argv[])
+int
+siad_chg_password(sia_collect_func_t * collect, const char *username,
+                 int argc, char *argv[])
 {
     afs_siad_debug("siad_chg_passwd returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_chg_shell(sia_collect_func_t *collect, const char *username,
-                  int argc, char *argv[])
+int
+siad_chg_shell(sia_collect_func_t * collect, const char *username, int argc,
+              char *argv[])
 {
     afs_siad_debug("siad_chg_shell returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_getpwent(struct passwd *result, char *buf, int bufsize,
-                 struct sia_context *context)
+int
+siad_getpwent(struct passwd *result, char *buf, int bufsize,
+             struct sia_context *context)
 {
     afs_siad_debug("siad_getpwent returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_getpwuid(uid_t uid, struct passwd *result, char *buf, int bufsize,
-                 struct sia_context *context)
+int
+siad_getpwuid(uid_t uid, struct passwd *result, char *buf, int bufsize,
+             struct sia_context *context)
 {
-    
+
     afs_siad_debug("siad_getpwuid returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_getpwnam(const char *name, struct passwd *result, char *buf,
-                 int bufsize, struct sia_context *context)
+int
+siad_getpwnam(const char *name, struct passwd *result, char *buf, int bufsize,
+             struct sia_context *context)
 {
     afs_siad_debug("siad_ses_getpwnam returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_setpwent(struct sia_context *context)
+int
+siad_setpwent(struct sia_context *context)
 {
     afs_siad_debug("siad_ses_setpwent returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_endpwent(struct sia_context *context)
+int
+siad_endpwent(struct sia_context *context)
 {
     afs_siad_debug("siad_ses_endpwent returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_getgrent(struct group *result, char *buf, int bufsize,
-                 struct sia_context *context)
+int
+siad_getgrent(struct group *result, char *buf, int bufsize,
+             struct sia_context *context)
 {
     afs_siad_debug("siad_ses_getgrent returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_getgrgid(gid_t gid, struct group *result, char *buf, int bufsize,
-                 struct sia_context *context)
+int
+siad_getgrgid(gid_t gid, struct group *result, char *buf, int bufsize,
+             struct sia_context *context)
 {
     afs_siad_debug("siad_ses_getgrgid returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_getgrnam(const char *name, struct group *result, char *buf, 
-                 int bufsize, struct sia_context *context)
+int
+siad_getgrnam(const char *name, struct group *result, char *buf, int bufsize,
+             struct sia_context *context)
 {
     afs_siad_debug("siad_ses_getgrnam returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_setgrent(struct sia_context *context)
+int
+siad_setgrent(struct sia_context *context)
 {
     afs_siad_debug("siad_ses_setgrent returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_endgrent(struct sia_context *context)
+int
+siad_endgrent(struct sia_context *context)
 {
     afs_siad_debug("siad_ses_endgrent returning failure.\n");
     return SIADFAIL;
 }
 
-int siad_chk_user(const char *logname, int checkflag)
+int
+siad_chk_user(const char *logname, int checkflag)
 {
     afs_siad_debug("siad_ses_chk_user returning success.\n");
     return SIADFAIL;
@@ -530,16 +552,18 @@ int siad_chk_user(const char *logname, int checkflag)
 
 #ifdef notdef
 /* These are not in the current implementation. */
-void siad_ses_toggle_privs(SIAENTITY *entity, int pkgind, int elevate)
+void
+siad_ses_toggle_privs(SIAENTITY * entity, int pkgind, int elevate)
 {
     afs_siad_debug("siad_ses_toggle_privs.\n");
     return;
 }
 
 
-void siad_ses_update_audit_record(SIAENTITY *entity, int pkgind, int event,
-                                 char *tokenp, char **datap, int *used,
-                                 int maxused)
+void
+siad_ses_update_audit_record(SIAENTITY * entity, int pkgind, int event,
+                            char *tokenp, char **datap, int *used,
+                            int maxused)
 {
     afs_siad_debug("siad_ses_update_audit_record.\n");
     return;